Open source CapCut alternative.
TypeScript
feat(site): transitions become free bars and clips never overlap [rebuild]
David Lebfdf5dddd9f7
diff --git a/site/src/cut/components/Timeline.tsx b/site/src/cut/components/Timeline.tsxindex 9c57a471..73223696 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, useReducer, 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, Fullscreen, Loader2, Moon, MoreHorizontal, Pause, Play, Scissors, SkipBack, Sun, Target, Trash2, Type, UnfoldHorizontal, Volume2, VolumeX, type LucideIcon } from "lucide-react";+import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, type ReactNode } from "react";+import { ArrowDown, ArrowDownToLine, ArrowLeft, ArrowLeftToLine, ArrowRight, ArrowRightToLine, ArrowUp, ArrowUpToLine, AudioLines, Blend, Check, Circle, Clapperboard, Copy, Diamond, Droplets, EllipsisVertical, Expand, Eye, EyeOff, FolderOpen, FolderPlus, FoldHorizontal, Fullscreen, Loader2, Minus, Moon, MoreHorizontal, MoveRight, Pause, Play, Scissors, SkipBack, Sparkles, Square, Sticker, Sun, Target, Trash2, Type, UnfoldHorizontal, Volume2, VolumeX, type LucideIcon } from "lucide-react";import { Button } from "@/components/ui/button";import {DropdownMenu,@@ -13,17 +13,21 @@ import {import { Slider } from "@/components/ui/slider";import {clearAssetDrag,+ clearElementDrag,draggedAssetId,draggedLibraryId,draggingAssetId,+ draggingElement,draggingLibrary,draggingTemplate,hasAssetDrag,+ hasElementDrag,hasLibraryDrag,hasTemplateDrag,} from "@/cut/lib/assetDrag";import { audioClipRefs, draggingRef, hasRefDrag, refFromAsset, type AssetRef } from "@/cut/lib/assetRef";import { sendFrameToChat, type FrameGrabOrigin } from "@/cut/lib/chatIntake";+import { copyRefImage } from "@/cut/lib/refMedia";import { useCutCaps } from "@/cut/lib/backend/hooks";import {addProjectTemplateToTimeline,@@ -37,13 +41,15 @@ import { useExports } from "@/cut/lib/exportStore";import { isDragActive, startDrag, subscribeDragActive } from "@/cut/lib/drag";import { CLIP_GAP, startLaneMove, startLaneTrim, type LaneDrag } from "@/cut/lib/laneTracks";import { ensurePeaks, importImage, importStockMusic, importStockVideo, peekEdgeFrame, requestEdgeFrame, revealMedia } from "@/cut/lib/media";-import { track0Clips, trackGapAt, clipLen, clipSpeed, footprints, getClipSpans, nextFreeStart, overlayLayers, projectDuration, rippleInsert, TIMELINE_H_MAX, useEditor } from "@/cut/lib/store";+import { track0Clips, laneGapAt, sameLane, type LaneRef, clipLen, clipSpeed, footprints, getClipSpans, nextFreeStart, overlayLaneOrder, overlayLayers, projectDuration, resolveTransitions, rippleInsert, TIMELINE_H_MAX, useEditor } from "@/cut/lib/store";import type { VideoTrackPlacement } from "@/cut/lib/store";import { laneHidden, subtitleLaneCount } from "@/cut/lib/subtitles";import { formatTime, formatTimecode } from "@/cut/lib/time";-import { emptySubtitles, IMAGE_CLIP_SECONDS, TRANSITION_STYLE_LABELS } from "@/cut/lib/types";-import type { AudioClip, ClipSpan, ColorGrade, MediaAsset, SubtitleCue, TextOverlay, TransitionStyle, VideoClip } from "@/cut/lib/types";-import { gradeTint, gradeToCssFilter } from "@/cut/lib/colorGrade";+import { EFFECT_LABELS } from "@donkeycut/effects-kit";+import { emptySubtitles, IMAGE_CLIP_SECONDS, SHAPE_LABELS, TRANSITION_DEFAULT_SECONDS, TRANSITION_MAX, TRANSITION_STYLE_LABELS } from "@/cut/lib/types";+import type { AudioClip, ClipSpan, ColorGrade, MediaAsset, Overlay, StickerOverlay, SubtitleCue, TimelineTransition, TransitionStyle, VideoClip } from "@/cut/lib/types";+import { isLottieAsset } from "@/cut/lib/lottieAssets";+import { gradeTint, gradeToCssFilter } from "@donkeycut/effects-kit";import { cn } from "@/lib/utils";const TRANSITION_ICONS: Record<TransitionStyle, LucideIcon> = {@@ -108,11 +114,13 @@ const ZOOM_MAX = 800;/** px/sec at which `dur` seconds fill a `width`-px viewport, with room spared* for the side padding. */const fitZoom = (width: number, dur: number) => Math.max((width - 60) / dur, 0.01);-/** The slider's left end. ZOOM_MIN suits short projects, but a long one still- * overflows there, so the floor drops with duration until full-left always- * means the whole project in view. */+/** The slider's left end: zoomed all the way out, the project still fills at+ * least 70% of the viewport, so the timeline never shrinks into a corner. A+ * very short project caps at half of ZOOM_MAX to keep the slider some travel. */const zoomFloor = (width: number, dur: number) =>- dur > 0 ? Math.min(ZOOM_MIN, fitZoom(width, dur)) : ZOOM_MIN;+ dur > 0+ ? Math.min(Math.max((width * 0.7) / dur, 0.01), ZOOM_MAX / 2)+ : ZOOM_MIN;/*** Zoom reads as a ratio — doubling px/sec feels like one step whether you start* at 20 or at 400 — so the slider travels in log space. A linear track would@@ -132,6 +140,70 @@ const sliderToZoom = (pos: number, min: number) => min * (ZOOM_MAX / min) ** (poconst SELECTED_SHADOW ="z-10 shadow-[0_0_0_2px_#0a84ff,0_2px_11px_rgba(10,132,255,0.6)]";+/**+ * Element bars carry their family's color: text purple, elements (shapes and+ * stickers) magenta, effects teal — the three places they come from, so a row+ * reads as what it holds before any label does. The drag highlights take the+ * carried item's color too, so a move keeps the same identity the whole way.+ *+ * Written out rather than composed, since Tailwind reads whole class names.+ */+type OverlayFamily = "text" | "element" | "effect";++/**+ * A place on the transition track a transition can sit: a cut between two+ * clips that touch, or an open edge — a clip's head or tail with nothing+ * against it, where the picture arrives from or leaves to nothing.+ *+ * `at` is the boundary itself (the cut, the head, the tail) and `len` the room+ * a transition takes there.+ */+type Anchor = { kind: "cut" | "in" | "out"; clipId: string; at: number; len: number };++/** One transition bar drawn on the row: the store object itself, the place it+ * resolved to (null while it sits inert), and how it reads. */+type XBar = {+ t: TimelineTransition;+ role: { kind: Anchor["kind"]; clipId: string } | null;+ label: string;+};++/** How far an anchor reaches while a bar is in flight, px. Inside it the drop+ * aligns to the anchor; outside it the bar lands exactly where it is. */+const XBAR_MAGNET_PX = 16;+++const overlayFamily = (o: Overlay): OverlayFamily =>+ o.kind === "effect" ? "effect" : o.kind === "shape" || o.kind === "sticker" ? "element" : "text";++const FAMILY_STYLE: Record<+ OverlayFamily,+ { bar: string; row: string; rowIdle: string; slot: string }+> = {+ text: {+ bar: "bg-[#7B4BD1]",+ row: "border-[#7B4BD1]/70 bg-[#7B4BD1]/5",+ rowIdle: "border-[#7B4BD1]/25",+ slot: "bg-[#7B4BD1]/10 shadow-[inset_0_0_0_1.5px_rgba(123,75,209,0.5)]",+ },+ element: {+ bar: "bg-[#C43C87]",+ row: "border-[#C43C87]/70 bg-[#C43C87]/5",+ rowIdle: "border-[#C43C87]/25",+ slot: "bg-[#C43C87]/10 shadow-[inset_0_0_0_1.5px_rgba(196,60,135,0.5)]",+ },+ effect: {+ bar: "bg-[#0D8577]",+ row: "border-[#0D8577]/70 bg-[#0D8577]/5",+ rowIdle: "border-[#0D8577]/25",+ slot: "bg-[#0D8577]/10 shadow-[inset_0_0_0_1.5px_rgba(13,133,119,0.5)]",+ },+};++/** Width of the trim grab zone at each end of a bar — paired with the `w-`+ * in `trimHandle` below; anything else drawn on a bar keeps clear of it. */+const TRIM_W = 10;+const trimHandle ="tl-trim absolute top-0 bottom-0 z-3 w-[10px] cursor-ew-resize after:absolute after:top-1/2 after:left-[3px] after:h-[calc(100%-10px)] after:w-1 after:-translate-y-1/2 after:rounded-full after:bg-white after:opacity-0 after:shadow-[0_0_0_1px_rgba(0,0,0,0.35)] after:transition-opacity group-hover:after:opacity-90 hover:after:opacity-100";@@ -154,9 +226,20 @@ const laneRail = (top: number, key?: React.Key) => (* the overscroll underlay so both paint the identical picture. */const REST_RAILS = `repeating-linear-gradient(to bottom, transparent 0 ${VIDEO_H + 4}px, var(--border) ${VIDEO_H + 4}px ${VIDEO_H + 5}px, transparent ${VIDEO_H + 5}px ${VIDEO_H + 6}px)`;-/** The timeline with nothing on it: the card-white ruler band over the track- * gray, a hairline under each occupied row, and the resting rails where a- * project has no rows yet.+/** The card-white ruler band with its baseline. Pinned wherever it paints —+ * the ruler stays put while the rows scroll, so its surface never follows the+ * vertical scroll either. */+function RulerBand() {+ return (+ <div+ className="pointer-events-none absolute inset-x-0 top-0 border-b border-border bg-card"+ style={{ height: RULER_H }}+ />+ );+}++/** The timeline with nothing on it: a hairline under each occupied row, and+ * the resting rails where a project has no rows yet.** Painted twice, in the two places the tracks are not. Behind the scroller it* is what a rubber-band bounce reveals; in the pinned gutter it is what the@@ -173,10 +256,6 @@ function RestingSurface({}) {return (<>- <div- className="absolute inset-x-0 top-0 border-b border-border bg-card"- style={{ height: RULER_H }}- />{railYs.map((y, i) => (<div key={i} className="absolute inset-x-0 h-px bg-border" style={{ top: y }} />))}@@ -194,6 +273,17 @@ function RestingSurface({const isClipMedia = (t: string | undefined): t is "video" | "image" =>t === "video" || t === "image";+/** A sticker asset lands as a sticker element, never as a clip: it is a+ * cut-out to lay over the picture, so a drop on the timeline goes to the+ * element rows however it arrives. */+const stickerOf = (a: MediaAsset | undefined | null): MediaAsset | null =>+ a && a.origin === "sticker" ? a : null;++const draggedSticker = (): MediaAsset | null => {+ const id = draggingAssetId();+ return stickerOf(id ? useEditor.getState().assets.find((a) => a.id === id) : null);+};+/** The image ref being dragged (a stock tile), null for any other drag —* asset and library drags carry the ref MIME too but with video/audio kinds.* On the timeline it lands on video track 0 as a still image. */@@ -240,10 +330,10 @@ export function Timeline() {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- // band is uniform across the full width.)+ // The rail copies behind the scroller follow vertical scroll so they stay+ // glued under the live rails; overscroll can't move them, so the surface+ // runs unbroken through the bounce. (Horizontal position is moot — every+ // line is uniform across the full width.)const rulerUnderlayRef = useRef<HTMLDivElement>(null);// The left gutter paints that same surface out in front of the scroller, and// is glued to the content the same way — it is held out of the horizontal@@ -384,7 +474,7 @@ export function Timeline() {if (!m.has(c.track)) m.set(c.track, getClipSpans(clips, assets, c.track));return m;}, [overlayClips, clips, assets]);- const total = projectDuration({ clips, audioClips });+ const total = projectDuration({ clips, audioClips, overlays });const zoomMin = zoomFloor(viewportW, total);// Fill the viewport at minimum so a wide window never leaves the ruler/tracks// cut off; grow past it once the content is longer. While a trim/slide drag@@ -487,12 +577,12 @@ export function Timeline() {// landing slot, and grow its row stack while a new row is hovered.const [laneDrag, setLaneDrag] = useState<LaneDrag | null>(null);- // Right-click on a video row's empty space: a small popover offering to- // close that track's gap under the cursor. The cut is track-local — only- // the clicked track's later clips slide left — so the menu carries the gap- // it would cut and the row tints it red while the menu is open.+ // Right-click on any row's empty space — video, audio, or title: a small+ // popover offering to close that row's gap under the cursor. The cut is+ // row-local — only that row's later items slide left — so the menu carries+ // the gap it would cut and the row tints it red while the menu is open.const [gapMenu, setGapMenu] = useState<- { x: number; y: number; track: number; gap: { start: number; len: number } } | null+ { x: number; y: number; lane: LaneRef; gap: { start: number; len: number } } | null>(null);useEffect(() => {if (!gapMenu) return;@@ -503,6 +593,20 @@ export function Timeline() {return () => window.removeEventListener("keydown", close);}, [gapMenu]);+ // Right-click on an element bar: a small popover to hide or show it — and,+ // when the click landed on a keyframe diamond, to remove that key.+ const [barMenu, setBarMenu] = useState<+ { x: number; y: number; id: string; key?: number } | null+ >(null);+ useEffect(() => {+ if (!barMenu) return;+ const close = (e: KeyboardEvent) => {+ if (e.key === "Escape") setBarMenu(null);+ };+ window.addEventListener("keydown", close);+ return () => window.removeEventListener("keydown", close);+ }, [barMenu]);+// 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@@ -556,13 +660,20 @@ export function Timeline() {// 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.+ // Element rows: overlays carry a `lane`; used lanes compact to contiguous+ // display rows, so an emptied row disappears on its own. The order is the+ // store's, shared with the lane drags so a drop lands where it was aimed.const overlayLanes = useMemo(() => {- const used = [...new Set(overlays.map((o) => o.lane ?? 0))].sort((a, b) => a - b);+ const used = overlayLaneOrder(overlays);const rowOf = new Map(used.map((l, i) => [l, i]));return { used, rowOf, count: used.length };}, [overlays]);+ // The color an element drag paints its landing rows with: the carried item's+ // own, so the move reads as one thing from grab to drop.+ const draggedFamily = useMemo<OverlayFamily>(() => {+ const held = laneDrag?.kind === "overlay" ? overlays.find((o) => o.id === laneDrag.id) : null;+ return held ? overlayFamily(held) : "text";+ }, [laneDrag, overlays]);// Video tracks above track 0 (PiP / composited layers), listed highest-first// so the top row is the frontmost layer and track 0 sits at the bottom of@@ -582,6 +693,7 @@ export function Timeline() {// (one past the end = new track), at what time, for how long.const [audioDrop, setAudioDrop] = useState<{ row: number; t: number; len: number } | null>(null);const audioRef = useRef<HTMLDivElement>(null);+ const overlayRef = useRef<HTMLDivElement>(null);const audioLanes = useMemo(() => {const used = [...new Set(audioClips.map((a) => a.lane ?? 0))].sort((a, b) => a - b);const rowOf = new Map(used.map((l, i) => [l, i]));@@ -663,6 +775,200 @@ export function Timeline() {[audioLanes.count]);+ // The element row under the pointer, or undefined for a point outside the+ // band — a drop there takes the element's home row.+ const overlayRowAt = useCallback(+ (clientY: number): number | undefined => {+ const el = overlayRef.current;+ if (!el || overlayLanes.count === 0) return undefined;+ const r = el.getBoundingClientRect();+ if (clientY < r.top || clientY > r.bottom) return undefined;+ return Math.min(overlayLanes.count - 1, Math.max(0, Math.floor((clientY - r.top) / TEXT_H)));+ },+ [overlayLanes]+ );+ const overlayLaneAt = (clientY: number): number | undefined => {+ const row = overlayRowAt(clientY);+ return row === undefined ? undefined : overlayLanes.used[row];+ };+ // Every place on every video track a transition can sit: the cuts, where one+ // clip hands over to the next, and the open edges — a clip's head with+ // nothing before it, its tail with nothing after — where it arrives from or+ // leaves to nothing. Each boundary offers exactly one: two clips that touch+ // make a cut, and anything else is an edge. `len` is the room a transition+ // takes there, so a drop can show its footprint before it lands.+ const anchors = useMemo(() => {+ const out: Anchor[] = [];+ const collect = (list: ClipSpan[]) =>+ list.forEach((sp, i) => {+ const prev = list[i - 1];+ const next = list[i + 1];+ const end = sp.start + sp.len;+ // The same touch tolerance the blend goes live with, so an anchor is+ // a cut exactly when a transition dropped there would play.+ const openHead = !prev || prev.start + prev.len < sp.start - 0.02;+ const touchesNext = next && next.start <= end + 0.02;+ if (openHead) {+ out.push({+ kind: "in",+ clipId: sp.clip.id,+ at: sp.start,+ len: sp.clip.animIn?.seconds || TRANSITION_DEFAULT_SECONDS,+ });+ }+ if (touchesNext) {+ out.push({+ kind: "cut",+ clipId: sp.clip.id,+ at: end,+ len: sp.clip.transition || TRANSITION_DEFAULT_SECONDS,+ });+ } else {+ out.push({+ kind: "out",+ clipId: sp.clip.id,+ at: end,+ len: sp.clip.animOut?.seconds || TRANSITION_DEFAULT_SECONDS,+ });+ }+ });+ collect(spans);+ overlayTrackSpans.forEach(collect);+ return out;+ }, [spans, overlayTrackSpans]);+ const nearestAnchor = (t: number) =>+ anchors.reduce<Anchor | null>(+ (best, a) => (!best || Math.abs(a.at - t) < Math.abs(best.at - t) ? a : best),+ null+ );++ // Every transition bar in the doc, live or parked. A bar is its own object+ // on the row: the clips it happens to line up with decide whether it plays,+ // and moving or deleting clips leaves it exactly where it is.+ const bars = useEditor((s) => s.transitions);+ const barRoles = useMemo(() => resolveTransitions(clips, bars), [clips, bars]);+ const transitions = useMemo<XBar[]>(+ () =>+ bars+ .map((t) => {+ const role = barRoles.get(t.id) ?? null;+ const base = TRANSITION_STYLE_LABELS[t.style];+ const label =+ role?.kind === "in" ? `${base} in` : role?.kind === "out" ? `${base} out` : base;+ return { t, role, label };+ })+ .sort((a, b) => a.t.start - b.t.start),+ [bars, barRoles]+ );++ /** Where a bar of `len` seconds sits when it lands on this anchor: an+ * entrance starts at the clip's head, everything else ends on its edge. */+ const anchorBarStart = (a: Anchor, len: number) => (a.kind === "in" ? a.at : a.at - len);++ /** The bar already playing this anchor's boundary, if any. */+ const barAt = (a: Anchor) =>+ transitions.find((x) => x.role && x.role.kind === a.kind && x.role.clipId === a.clipId)?.t ??+ null;++ /** Land a new bar from the panel: it takes the nearest anchor when one is+ * around, replacing whatever played there, and sits free anywhere else. */+ const dropTransitionAt = (time: number, style: TransitionStyle) => {+ const st = useEditor.getState();+ if (st.readOnly) return;+ const a = nearestAnchor(time);+ const len = a?.len ?? TRANSITION_DEFAULT_SECONDS;+ st.beginHistoryBatch();+ const incumbent = a ? barAt(a) : null;+ if (incumbent) st.removeTransition(incumbent.id);+ const id = st.addTransition({+ start: a ? anchorBarStart(a, len) : time,+ seconds: len,+ style,+ });+ st.endHistoryBatch();+ st.select({ kind: "transition", id });+ };++ // Drag a bar anywhere along the row. An anchor within reach pulls the drop+ // onto itself and lights the room it takes; released anywhere else the bar+ // stays exactly there — parked, playing nothing until a cut or a clip edge+ // lines up with it. A press that never moved selects the bar.+ const moveTransition = (e: React.PointerEvent, x: XBar) => {+ if (e.button !== 0) return;+ e.stopPropagation();+ const s = useEditor.getState();+ if (s.readOnly) return;+ let landing: { start: number; anchor: Anchor | null } | null = null;+ startDrag(e, {+ onMove: (dx) => {+ const free = Math.max(-x.t.seconds + 0.1, x.t.start + dx / pps);+ const near = anchors.reduce<{ a: Anchor; gap: number } | null>((best, a) => {+ const gap = Math.abs(anchorBarStart(a, x.t.seconds) - free);+ return !best || gap < best.gap ? { a, gap } : best;+ }, null);+ const snapped = near && near.gap <= XBAR_MAGNET_PX / pps ? near.a : null;+ landing = snapped+ ? { start: anchorBarStart(snapped, x.t.seconds), anchor: snapped }+ : { start: free, anchor: null };+ setSnapX(snapped ? snapped.at * pps : null);+ setJointDrop(snapped ? { ...snapped, len: x.t.seconds } : null);+ setTransitionDrag({ ...x, t: { ...x.t, start: landing.start } });+ },+ onUp: (_dx, _dy, moved) => {+ setSnapX(null);+ setJointDrop(null);+ setTransitionDrag(null);+ const st = useEditor.getState();+ if (!moved || !landing) return st.select({ kind: "transition", id: x.t.id });+ st.beginHistoryBatch();+ const incumbent = landing.anchor ? barAt(landing.anchor) : null;+ if (incumbent && incumbent.id !== x.t.id) st.removeTransition(incumbent.id);+ st.updateTransition(x.t.id, { start: landing.start });+ st.endHistoryBatch();+ },+ });+ };++ // Drag the loose edge to retime. A playing bar keeps the boundary end still —+ // an entrance grows forward from its start, everything else backward from+ // its end — so retiming never un-aligns it.+ const trimTransition = (e: React.PointerEvent, x: XBar) => {+ if (e.button !== 0) return;+ e.stopPropagation();+ const st0 = useEditor.getState();+ if (st0.readOnly) return;+ const growsForward = x.role?.kind === "in";+ const fixed = growsForward ? x.t.start : x.t.start + x.t.seconds;+ st0.beginHistoryBatch();+ startDrag(e, {+ onMove: (dx) => {+ const loose = (growsForward ? x.t.start + x.t.seconds : x.t.start) + dx / pps;+ const seconds = Math.max(0.1, Math.min(TRANSITION_MAX, Math.abs(loose - fixed)));+ useEditor.getState().updateTransitionTransient(x.t.id, {+ seconds,+ start: growsForward ? fixed : fixed - seconds,+ });+ },+ onUp: () => useEditor.getState().endHistoryBatch(),+ });+ };++ // The row a shape or effect dragged out of a panel would land on, so the+ // band shows where it is going.+ const [elementDropRow, setElementDropRow] = useState<number | null>(null);+ // The place a dragged transition would land on, marked with the footprint it+ // would take while it is in flight.+ const [jointDrop, setJointDrop] = useState<Anchor | null>(null);+ // A transition tile from the panel is over the timeline: the row lights+ // every place a drop could play, the same as a bar drag does.+ const [xTileDrag, setXTileDrag] = useState(false);+ // A transition bar mid-drag, drawn where the pointer has it.+ const [transitionDrag, setTransitionDrag] = useState<XBar | null>(null);+ // A drag past the top edge opens a row there, pushing the stack down by one+ // for as long as it is aimed that way.+ const topRowShift =+ laneDrag?.kind === "overlay" && laneDrag.targetRow < 0 ? TEXT_H : 0;+// 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.@@ -686,7 +992,7 @@ export function Timeline() {});};- // Clicking empty track space deselects AND moves the playhead (iMovie).+ // Clicking empty track space deselects AND moves the playhead.const deselectIfSelf = (e: React.PointerEvent) => {if (e.target === e.currentTarget) {useEditor.getState().select(null);@@ -811,9 +1117,21 @@ export function Timeline() {type: "video" | "audio" | "image",t: number,audioRow = 0,- place: TrackTarget = TRACK_ZERO+ place: TrackTarget = TRACK_ZERO,+ /** The element row the pointer came down on, when it was over the band. */+ elementLane?: number) => {const s = useEditor.getState();+ const sticker = stickerOf(s.assets.find((a) => a.id === assetId));+ if (sticker) {+ s.addSticker({+ assetId,+ ...(isLottieAsset(sticker) ? { lottie: true } : {}),+ at: t,+ ...(elementLane !== undefined ? { lane: elementLane } : {}),+ });+ return;+ }if (isClipMedia(type)) {if (place.kind === "insert") s.addVideoFromAsset(assetId, place, t);// Drop at the pointer, rippling later clips right — so a drop into a@@ -838,7 +1156,7 @@ export function Timeline() {const id = draggingAssetId();if (id) {const asset = useEditor.getState().assets.find((a) => a.id === id);- if (!asset || !isClipMedia(asset.type)) return null;+ if (!asset || stickerOf(asset) || !isClipMedia(asset.type)) return null;return { duration: asset.type === "image" ? STILL_SECONDS : asset.duration };}const stockVideo = draggingStockVideo(e);@@ -864,6 +1182,9 @@ export function Timeline() {if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setOverlayDrop(null);},onDrop: (e: React.DragEvent) => {+ // A sticker crossing a video row is still headed for the element rows;+ // leave it to the timeline's own drop rather than swallowing it here.+ if (draggedSticker()) return;e.preventDefault();e.stopPropagation();const t = Math.max(0, timeAt(e.clientX));@@ -883,7 +1204,7 @@ export function Timeline() {}const id = draggedAssetId(e);const asset = id ? useEditor.getState().assets.find((a) => a.id === id) : null;- if (id && isClipMedia(asset?.type)) {+ if (id && !stickerOf(asset) && isClipMedia(asset?.type)) {useEditor.getState().addVideoFromAsset(id, place, t);return;}@@ -933,25 +1254,37 @@ export function Timeline() {/>) : null;- // Only empty space gets the menu: a right-click on a clip sits on a+ // Only empty space gets the menu: a right-click on an item sits on a// footprint, so the gap lookup misses and the event falls through to the// browser.- const openGapMenu = (track: number) => (e: React.MouseEvent) => {- const gap = trackGapAt(useEditor.getState().clips, track, timeAt(e.clientX));+ const openGapMenu = (lane: LaneRef) => (e: React.MouseEvent) => {+ const gap = laneGapAt(useEditor.getState(), lane, timeAt(e.clientX));if (!gap) return;e.preventDefault();- setGapMenu({ x: e.clientX, y: e.clientY, track, gap });+ setGapMenu({ x: e.clientX, y: e.clientY, lane, gap });};- // The span the open gap menu would cut, tinted red on its own track.- const gapHighlight = (track: number, h: number) =>- gapMenu?.track === track ? (+ // Audio and title rows stack inside one container, so the row comes from+ // where the pointer landed and the display row maps back to the lane the+ // items actually carry.+ const openStackedGapMenu =+ (kind: "audio" | "overlay", rowH: number, used: number[]) => (e: React.MouseEvent) => {+ const top = e.currentTarget.getBoundingClientRect().top;+ const index = used[Math.floor((e.clientY - top) / rowH)];+ if (index === undefined) return;+ openGapMenu({ kind, index })(e);+ };++ // The span the open gap menu would cut, tinted red on its own row.+ const gapHighlight = (lane: LaneRef, h: number, top = 0) =>+ gapMenu && sameLane(gapMenu.lane, lane) ? (<div- className="pointer-events-none absolute top-0.5 z-10 rounded-lg bg-red-500/15"+ className="pointer-events-none absolute z-10 rounded-lg bg-red-500/15"style={{left: gapMenu.gap.start * pps,width: Math.max(2, gapMenu.gap.len * pps - CLIP_GAP),height: h,+ top: top + 2,}}/>) : null;@@ -993,9 +1326,32 @@ export function Timeline() {const still = draggingStill(e);const stockVideo = draggingStockVideo(e);const stockMusic = draggingStockMusic(e);- if (!hasAssetDrag(e) && !isLib && !still && !stockVideo && !stockMusic) return;+ const element = hasElementDrag(e) ? draggingElement() : null;+ if (!hasAssetDrag(e) && !isLib && !still && !stockVideo && !stockMusic && !element)+ return;e.preventDefault();e.dataTransfer.dropEffect = "copy";+ // An element — a sticker, or a shape or effect from a panel — lands on+ // the element rows, so none of the clip previews apply to it.+ if (element || draggedSticker()) {+ setAssetDrop(null);+ setOverlayDrop(null);+ setAudioDrop(null);+ setDropType(null);+ setElementDropRow(+ element && element.kind !== "transition" ? overlayRowAt(e.clientY) ?? null : null+ );+ setXTileDrag(element?.kind === "transition");+ setJointDrop(+ element?.kind === "transition"+ ? nearestAnchor(Math.max(0, timeAt(e.clientX)))+ : null+ );+ return;+ }+ setElementDropRow(null);+ setJointDrop(null);+ setXTileDrag(false);// Preview where a video would land; audio drops free-form. Library and// stock drags carry their own shape since they aren't in the project yet.let type: "video" | "audio" | "image" | undefined;@@ -1035,9 +1391,9 @@ export function Timeline() {} else {const id = draggingAssetId();const asset = id ? useEditor.getState().assets.find((a) => a.id === id) : null;- type = asset?.type;+ type = asset && asset.type !== "font" ? asset.type : undefined;duration = asset?.type === "image" ? STILL_SECONDS : asset?.duration ?? 0;- if (asset && isClipMedia(asset.type)) {+ if (asset && !stickerOf(asset) && isClipMedia(asset.type)) {ghost =asset.type === "image"? { url: asset.url, kind: "image" }@@ -1090,11 +1446,18 @@ export function Timeline() {setOverlayDrop(null);setAudioDrop(null);setDropType(null);+ setElementDropRow(null);+ setJointDrop(null);+ setXTileDrag(false);}}}onDrop={(e) => {// Resolve the hovered rows before the previews (and their rows) clear.const audioRow = audioRowAt(e.clientY);+ const elementLane = overlayLaneAt(e.clientY);+ setElementDropRow(null);+ setJointDrop(null);+ setXTileDrag(false);const videoPlace = resolveDropTrack(e.clientX, e.clientY);setAssetDrop(null);setOverlayDrop(null);@@ -1109,8 +1472,18 @@ export function Timeline() {const stockVideo = draggingStockVideo(e);const stockMusic = draggingStockMusic(e);const tpl = draggingTemplate();+ const element = hasElementDrag(e) ? draggingElement() : null;const projectId = useEditor.getState().projectId;clearAssetDrag();+ clearElementDrag();+ if (element) {+ e.preventDefault();+ const aim = { at: t, ...(elementLane !== undefined ? { lane: elementLane } : {}) };+ if (element.kind === "shape") useEditor.getState().addShape(element.shape, aim);+ else if (element.kind === "effect") useEditor.getState().addEffect(element.effect, aim);+ else dropTransitionAt(t, element.style);+ return;+ }if (tpl && projectId) {e.preventDefault();if (tpl.scope === "project") addProjectTemplateToTimeline(projectId, tpl.template, t);@@ -1120,7 +1493,9 @@ export function Timeline() {if (libId && lib && projectId) {e.preventDefault();void importLibraryAsset(projectId, lib)- .then((asset) => placeAssetAt(asset.id, asset.type, t, audioRow, videoPlace))+ .then((asset) => {+ if (asset.type !== "font") placeAssetAt(asset.id, asset.type, t, audioRow, videoPlace);+ }).catch(() => {});return;}@@ -1129,7 +1504,8 @@ export function Timeline() {if (id) {e.preventDefault();const asset = useEditor.getState().assets.find((a) => a.id === id);- if (asset) placeAssetAt(id, asset.type, t, audioRow, videoPlace);+ if (asset && asset.type !== "font")+ placeAssetAt(id, asset.type, t, audioRow, videoPlace, elementLane);return;}@@ -1274,9 +1650,12 @@ export function Timeline() {onPointerEnter={() => setTrackHover(true)}onPointerLeave={() => setTrackHover(false)}>- <div ref={rulerUnderlayRef} className="pointer-events-none absolute inset-x-0 top-0">- <RestingSurface railYs={railYs} empty={total <= 0} timelineH={timelineH} />+ <div className="pointer-events-none absolute inset-0 overflow-hidden">+ <div ref={rulerUnderlayRef} className="absolute inset-x-0 top-0">+ <RestingSurface railYs={railYs} empty={total <= 0} timelineH={timelineH} />+ </div></div>+ <RulerBand /><divref={scrollRef}data-tl-scroll@@ -1309,7 +1688,210 @@ export function Timeline() {}}/>)}- <Ruler pps={pps} width={contentW} onScrub={scrub} />+ {/* Pinned over the vertical scroll: the rows slide under the band,+ the way the timeline runs under the gutter. The band paints its+ own surface pad to pad, and the playhead cap rides in it so the+ time being pointed at can always be grabbed. */}+ <div className="sticky top-0 z-50" style={{ height: RULER_H }}>+ <div+ className="absolute top-0 border-b border-border bg-card"+ style={{ height: RULER_H, left: -PAD_SIDE, width: contentW + PAD_SIDE * 2 }}+ />+ <Ruler pps={pps} width={contentW} onScrub={scrub} />+ <PlayheadCap pps={pps} onScrub={scrub} />+ </div>++ {/* Elements ride above the clip stack, the way they sit over the+ picture. New effects open the top row; a drag moves any of them+ to any row. */}+ {overlays.length > 0 && (+ <div+ ref={overlayRef}+ data-tl-trows=""+ className="relative mt-1.5"+ style={{+ height:+ Math.max(+ overlayLanes.count,+ // An in-flight element drag shows the whole landing area,+ // the would-be new row below included.+ laneDrag?.kind === "overlay" ? overlayLanes.count + 1 : 0+ ) *+ TEXT_H ++ topRowShift,+ }}+ onPointerDown={deselectIfSelf}+ onContextMenu={openStackedGapMenu("overlay", TEXT_H, overlayLanes.used)}+ >+ {Array.from({ length: overlayLanes.count }, (_, r) =>+ laneRail((r + 1) * TEXT_H - 4 + topRowShift, r)+ )}+ {overlayLanes.used.map((lane, r) => (+ <Fragment key={`tgap-${lane}`}>+ {gapHighlight(+ { kind: "overlay", index: lane },+ TEXT_H - 6,+ r * TEXT_H + topRowShift+ )}+ </Fragment>+ ))}+ {elementDropRow !== null && (+ <div+ className={cn(+ "pointer-events-none absolute inset-x-0 rounded-md border border-dashed",+ FAMILY_STYLE[+ draggingElement()?.kind === "effect" ? "effect" : "element"+ ].row+ )}+ style={{ top: elementDropRow * TEXT_H + 2, height: TEXT_H - 6 }}+ />+ )}+ {/* The new row above, revealed once the drag heads past the top+ edge — showing it any earlier would push every row down+ under a freshly grabbed bar. */}+ {topRowShift > 0 && (+ <div+ className={cn(+ "pointer-events-none absolute inset-x-0 rounded-md border border-dashed",+ FAMILY_STYLE[draggedFamily].row+ )}+ style={{ top: 2, height: TEXT_H - 6 }}+ />+ )}+ {laneDrag?.kind === "overlay" &&+ Array.from({ length: overlayLanes.count + 1 }, (_, r) => (+ <div+ key={r}+ className={cn(+ "pointer-events-none absolute inset-x-0 rounded-md border border-dashed transition-colors",+ r === laneDrag.targetRow+ ? FAMILY_STYLE[draggedFamily].row+ : FAMILY_STYLE[draggedFamily].rowIdle+ )}+ style={{ top: r * TEXT_H + 2 + topRowShift, height: TEXT_H - 6 }}+ />+ ))}+ {laneDrag?.kind === "overlay" && (+ <LaneSlot+ drag={laneDrag}+ pps={pps}+ rowH={TEXT_H}+ barH={TEXT_H - 6}+ shift={topRowShift}+ className={cn("rounded-md", FAMILY_STYLE[draggedFamily].slot)}+ />+ )}+ {overlays.map((o) => {+ const homeRow = overlayLanes.rowOf.get(o.lane ?? 0) ?? 0;+ const drag = laneDrag?.kind === "overlay" && laneDrag.id === o.id ? laneDrag : null;+ return (+ <TextBar+ key={o.id}+ overlay={o}+ pps={pps}+ top={homeRow * TEXT_H + topRowShift}+ homeRow={homeRow}+ laneCount={overlayLanes.count}+ selected={selKeys.has(`overlay:${o.id}`)}+ drag={drag}+ parting={laneDrag?.kind === "overlay" && laneDrag.id !== o.id}+ onDrag={setLaneDrag}+ onSnap={setSnapX}+ onMenu={setBarMenu}+ />+ );+ })}+ </div>+ )}++ {/* Transitions: free bars on their own row. Each plays the cut or+ clip edge it lines up with, and sits parked anywhere else. */}+ {(transitions.length > 0 || jointDrop !== null || xTileDrag) && (+ <div+ data-tl-xrows=""+ className="relative mt-1.5"+ style={{ height: TEXT_H }}+ onPointerDown={deselectIfSelf}+ >+ {laneRail(TEXT_H - 4, "xrail")}+ {(transitionDrag !== null || xTileDrag) &&+ // While a transition is in flight, every place it could play+ // lights up in the timeline's usual drop-zone dress: one slot+ // per cut and open edge, each the size the bar would take+ // there.+ anchors.map((a) => {+ const len = transitionDrag ? transitionDrag.t.seconds : a.len;+ return (+ <div+ key={`xzone-${a.kind}-${a.clipId}`}+ className="pointer-events-none absolute rounded-md bg-[#0a84ff]/10 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.4)]"+ style={{+ left: anchorBarStart(a, len) * pps,+ top: 2,+ width: Math.max(14, len * pps - CLIP_GAP),+ height: TEXT_H - 6,+ }}+ />+ );+ })}+ {jointDrop && (+ // The zone the drop is aimed at burns brighter than the rest.+ <div+ className="pointer-events-none absolute rounded-md bg-[#0a84ff]/25 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.85)]"+ style={{+ left: anchorBarStart(jointDrop, jointDrop.len) * pps,+ top: 2,+ width: Math.max(14, jointDrop.len * pps - CLIP_GAP),+ height: TEXT_H - 6,+ }}+ />+ )}+ {transitions.map((live) => {+ const x = transitionDrag?.t.id === live.t.id ? transitionDrag : live;+ const Icon = TRANSITION_ICONS[x.t.style];+ const playing = !!x.role;+ return (+ <div+ key={x.t.id}+ role="button"+ tabIndex={0}+ title={`${x.label} ${x.t.seconds.toFixed(1)}s — drag it anywhere along the row; it plays where it lines up with a cut or a clip edge`}+ className={cn(+ "tl-xfade-bar group absolute flex cursor-grab items-center gap-1 overflow-hidden rounded-md px-1.5 text-[10.5px] font-medium text-white shadow-[inset_0_0_0_1px_rgba(0,0,0,0.1)]",+ // A parked bar reads muted: it is on the row but playing+ // nothing until a boundary lines up with it.+ playing ? "bg-[#2B6FD4]" : "bg-muted-foreground/50",+ selKeys.has(`transition:${x.t.id}`) && SELECTED_SHADOW,+ // Mid-drag it rides over the zone it would land on, so+ // the marked room stays readable underneath.+ x === transitionDrag && "opacity-75"+ )}+ style={{+ left: x.t.start * pps,+ top: 2,+ width: Math.max(14, x.t.seconds * pps - CLIP_GAP),+ height: TEXT_H - 6,+ }}+ onPointerDown={(e) => moveTransition(e, x)}+ >+ <Icon className="size-2.5 shrink-0" />+ <span className="truncate">{x.label}</span>+ {/* Retiming pulls the loose end: an entrance runs forward+ from the clip's head, everything else backward from the+ boundary it sits on. */}+ <span+ title="Drag to retime"+ className={cn(+ trimHandle,+ x.role?.kind === "in" ? "tl-trim-r right-0" : "tl-trim-l left-0"+ )}+ onPointerDown={(e) => trimTransition(e, x)}+ />+ </div>+ );+ })}+ </div>+ )}{/* The top-side new track reveals once the drag heads past thestack's upper edge; mounting it earlier would shift every row@@ -1325,11 +1907,11 @@ export function Timeline() {data-tl-vrow={track}data-drop={placementAttr({ kind: "track", track })}onPointerDown={deselectIfSelf}- onContextMenu={openGapMenu(track)}+ onContextMenu={openGapMenu({ kind: "video", index: track })}{...overlayDropHandlers({ kind: "track", track })}>{laneRail(OVERLAY_H - 2)}- {gapHighlight(track, OVERLAY_H - 4)}+ {gapHighlight({ kind: "video", index: track }, OVERLAY_H - 4)}{draggedOverlayTrack === track && laneDrag && (<LaneSlotdrag={laneDrag}@@ -1339,13 +1921,11 @@ export function Timeline() {className="rounded-lg bg-[#0a84ff]/10 shadow-[inset_0_0_0_1.5px_rgba(10,132,255,0.4)]"/>)}- {(overlayTrackSpans.get(track) ?? []).map((span, i, tSpans) => (+ {(overlayTrackSpans.get(track) ?? []).map((span) => (<OverlayClipViewkey={span.clip.id}clip={span.clip}asset={span.asset}- prevOverlap={tSpans[i - 1]?.transitionOut ?? 0}- overlap={span.transitionOut}pps={pps}selected={selKeys.has(`clip:${span.clip.id}`)}drag={@@ -1363,13 +1943,6 @@ export function Timeline() {onFrameMenu={openFrameMenu}/>))}- {laneDrag?.kind !== "overlayClip" && (- <TransitionBadges- spans={overlayTrackSpans.get(track) ?? []}- pps={pps}- rowH={OVERLAY_H}- />- )}{trackSlot({ kind: "track", track }, OVERLAY_H - 4)}</div>))}@@ -1389,10 +1962,10 @@ export function Timeline() {data-tl-vrow={0}data-drop={placementAttr(TRACK_ZERO)}onPointerDown={deselectIfSelf}- onContextMenu={openGapMenu(0)}+ onContextMenu={openGapMenu({ kind: "video", index: 0 })}>{spans.length > 0 && laneRail(VIDEO_H - 2)}- {gapHighlight(0, VIDEO_H - 4)}+ {gapHighlight({ kind: "video", index: 0 }, VIDEO_H - 4)}{trackSlot(TRACK_ZERO, VIDEO_H - 4)}{laneDrag?.kind === "clip" && !laneDrag.away && (<LaneSlot@@ -1432,7 +2005,6 @@ export function Timeline() {<ClipViewkey={span.clip.id}span={span}- prevOverlap={spans[i - 1]?.transitionOut ?? 0}mention={`@c${i + 1}`}pps={pps}selected={selKeys.has(`clip:${span.clip.id}`)}@@ -1447,9 +2019,6 @@ export function Timeline() {onFrameMenu={openFrameMenu}/>))}- {laneDrag?.kind !== "clip" && (- <TransitionBadges spans={spans} pps={pps} rowH={VIDEO_H} />- )}</div>)}@@ -1475,10 +2044,16 @@ export function Timeline() {) * AUDIO_H,}}onPointerDown={deselectIfSelf}+ onContextMenu={openStackedGapMenu("audio", AUDIO_H, audioLanes.used)}>{Array.from({ length: audioLanes.count }, (_, r) =>laneRail((r + 1) * AUDIO_H - 2, r))}+ {audioLanes.used.map((lane, r) => (+ <Fragment key={`agap-${lane}`}>+ {gapHighlight({ kind: "audio", index: lane }, AUDIO_H - 4, r * AUDIO_H)}+ </Fragment>+ ))}{laneDrag?.kind === "audio" &&Array.from({ length: audioLanes.count + 1 }, (_, r) => (<div@@ -1536,68 +2111,6 @@ export function Timeline() {</div>)}- {overlays.length > 0 && (- <div- data-tl-trows=""- className="relative mt-1.5"- style={{- height:- Math.max(- overlayLanes.count,- // An in-flight title drag shows the whole landing area,- // the would-be new track included.- laneDrag?.kind === "text" ? overlayLanes.count + 1 : 0- ) * TEXT_H,- }}- onPointerDown={deselectIfSelf}- >- {Array.from({ length: overlayLanes.count }, (_, r) =>- laneRail((r + 1) * TEXT_H - 4, r)- )}- {laneDrag?.kind === "text" &&- Array.from({ length: overlayLanes.count + 1 }, (_, r) => (- <div- key={r}- className={cn(- "pointer-events-none absolute inset-x-0 rounded-md border border-dashed transition-colors",- r === laneDrag.targetRow- ? "border-purple-500/70 bg-purple-500/5"- : "border-purple-500/25"- )}- style={{ top: r * TEXT_H + 2, height: TEXT_H - 6 }}- />- ))}- {laneDrag?.kind === "text" && (- <LaneSlot- drag={laneDrag}- pps={pps}- rowH={TEXT_H}- barH={TEXT_H - 6}- className="rounded-md bg-purple-500/10 shadow-[inset_0_0_0_1.5px_rgba(168,85,247,0.5)]"- />- )}- {overlays.map((o) => {- const homeRow = overlayLanes.rowOf.get(o.lane ?? 0) ?? 0;- const drag = laneDrag?.kind === "text" && laneDrag.id === o.id ? laneDrag : null;- return (- <TextBar- key={o.id}- overlay={o}- pps={pps}- top={homeRow * TEXT_H}- homeRow={homeRow}- laneCount={overlayLanes.count}- selected={selKeys.has(`text:${o.id}`)}- drag={drag}- parting={laneDrag?.kind === "text" && laneDrag.id !== o.id}- onDrag={setLaneDrag}- onSnap={setSnapX}- />- );- })}- </div>- )}-{subtitles.showOnTimeline && subtitles.cues.length > 0 && (<divdata-tl-srows=""@@ -1666,8 +2179,8 @@ export function Timeline() {It is the width of the content's left pad, so at rest it sits overempty surface and the timeline looks no different — but the columnis now a fixed place on screen, which is what per-track controls- need. It paints the resting surface (following vertical scroll, so- its ruler band and rails stay glued to the live ones) and passes+ need. It paints the resting surface (rails following vertical+ scroll, the ruler band pinned like the live one) and passespresses through to the scrubbing surface beneath; controls will taketheir own pointer events when they land. Its face shows only oncethe timeline has scrolled: at rest the underlay behind the scroller@@ -1681,6 +2194,7 @@ export function Timeline() {<div ref={gutterRef} className="absolute inset-0"><RestingSurface railYs={railYs} empty={total <= 0} timelineH={timelineH} /></div>+ <RulerBand /></div>{/* Cast off the gutter's right edge alone, once the timeline has scrolled— that shadow is the whole tell that clips are running underneath@@ -1698,10 +2212,12 @@ export function Timeline() {one whose track has anything off stays visible so the strip reads asthe enabled/disabled readout. */}<div- className="pointer-events-none absolute inset-y-0 left-0 z-50"- style={{ width: PAD_SIDE }}+ // Clipped below the ruler band, so a toggle scrolled to the top slides+ // under the band instead of riding up over it and the toolbar.+ className="pointer-events-none absolute bottom-0 left-0 z-50 overflow-hidden"+ style={{ width: PAD_SIDE, top: RULER_H }}>- <div ref={gutterCtlRef} className="absolute inset-0">+ <div ref={gutterCtlRef} className="absolute inset-x-0 bottom-0" style={{ top: -RULER_H }}>{gutterYs.video.map(({ track, y }) => {const t = trackState.get(track);if (!t) return null;@@ -1814,7 +2330,7 @@ export function Timeline() {<buttonclassName="flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground"onClick={() => {- useEditor.getState().removeGap(gapMenu.track, gapMenu.gap.start);+ useEditor.getState().removeLaneGap(gapMenu.lane, gapMenu.gap.start);setGapMenu(null);}}>@@ -1823,6 +2339,60 @@ export function Timeline() {</div></div>)}+ {barMenu &&+ (() => {+ const o = overlays.find((x) => x.id === barMenu.id);+ if (!o) return null;+ const item =+ "flex w-full items-center gap-2 rounded-sm px-2 py-1.5 text-sm hover:bg-accent hover:text-accent-foreground";+ return (+ <div+ className="fixed inset-0 z-50"+ onPointerDown={() => setBarMenu(null)}+ onContextMenu={(e) => {+ e.preventDefault();+ setBarMenu(null);+ }}+ >+ <div+ className="absolute min-w-44 rounded-md border bg-popover p-1 text-popover-foreground shadow-md"+ style={{ left: barMenu.x, top: barMenu.y }}+ onPointerDown={(e) => e.stopPropagation()}+ >+ {barMenu.key !== undefined && (+ <button+ className={item}+ onClick={() => {+ const s = useEditor.getState();+ s.pushHistory();+ s.removeOverlayKey(barMenu.id, barMenu.key!);+ setBarMenu(null);+ }}+ >+ <Diamond className="size-3.5 text-muted-foreground" /> Remove keyframe+ </button>+ )}+ <button+ className={item}+ onClick={() => {+ useEditor.getState().updateOverlay(barMenu.id, { hidden: !o.hidden });+ setBarMenu(null);+ }}+ >+ {o.hidden ? (+ <>+ <Eye className="size-3.5 text-muted-foreground" /> Show+ </>+ ) : (+ <>+ <EyeOff className="size-3.5 text-muted-foreground" /> Hide+ </>+ )}+ </button>+ </div>+ </div>+ );+ })()}{frameMenu && (<divclassName="fixed inset-0 z-50"@@ -1840,10 +2410,7 @@ export function Timeline() {const flip = frameMenu.x + 240 > window.innerWidth;return (<div- className={cn(- "group absolute -translate-y-1/2",- flip ? "pr-[6px]" : "pl-[6px]"- )}+ className={cn("absolute -translate-y-1/2", flip ? "pr-[6px]" : "pl-[6px]")}style={{top: frameMenu.y,...(flip@@ -1852,23 +2419,37 @@ export function Timeline() {}}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>+ <div className="rounded-lg border bg-popover p-1 text-popover-foreground shadow-md">+ <button+ className="flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm whitespace-nowrap hover:bg-accent 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>+ <button+ className="flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left text-sm whitespace-nowrap hover:bg-accent hover:text-accent-foreground"+ onClick={() => {+ void copyRefImage({+ ...refFromAsset(frameMenu.asset),+ t: frameMenu.srcT,+ }).catch(() => {});+ setFrameMenu(null);+ }}+ >+ <Copy className="size-3.5 text-muted-foreground" /> Copy frame+ </button>+ </div>{/* Drawn after the bubble so the diamond's inner half coversits border along the notch, leaving one seamless outline. */}<divclassName={cn(- "pointer-events-none absolute top-1/2 size-2.5 -translate-y-1/2 rotate-45 bg-popover group-hover:bg-accent",+ "pointer-events-none absolute top-1/2 size-2.5 -translate-y-1/2 rotate-45 bg-popover",flip? "right-[2px] rounded-tr-[2px] border-t border-r": "left-[2px] rounded-bl-[2px] border-b border-l"@@ -1884,7 +2465,7 @@ export function Timeline() {}/**- * iMovie skimmer: a line that follows the mouse over the timeline. It marks+ * The skimmer: a line that follows the mouse over the timeline. It marks* where Split (⌘B / S) will cut; clicking still moves the playhead itself.*/function HoverLine({@@ -2237,66 +2818,38 @@ function Playhead({return (<div// Over the gutter as well as the clips: at 0 the playhead stands on the- // gutter's own edge, and the side padding is there so its cap is never- // clipped. The clips pass under the gutter; the time it is showing does- // not.+ // gutter's own edge. The clips pass under the gutter; the time it is+ // showing does not. The grab cap lives in the pinned ruler.className="pointer-events-none absolute top-0 bottom-0 left-0 z-50 w-[1.5px] bg-[#0a84ff] shadow-[0_0_8px_rgba(10,132,255,0.6)]"style={{ transform: `translateX(${x}px)` }}- >- <div- className="tl-playhead-cap pointer-events-auto absolute -top-0 -left-[7px] h-5 w-4 cursor-ew-resize"- onPointerDown={onScrub}- >- <div className="mx-auto h-3 w-2.5 rounded-t-[3px] bg-[#0a84ff] [clip-path:polygon(0_0,100%_0,100%_58%,50%_100%,0_58%)]" />- </div>- </div>+ />);}-/** Transition badges for one track row, floating in the gutter where each- * pair meets (the overlap midpoint; a hard cut for edge styles), vertically- * centered on the row. Shared by track 0 and the upper tracks. */-function TransitionBadges({- spans,+/** The playhead's grab cap, riding the pinned ruler band — the side padding+ * is there so it is never clipped at 0. */+function PlayheadCap({pps,- rowH,+ onScrub,}: {- spans: ClipSpan[];pps: number;- rowH: number;+ onScrub: (e: React.PointerEvent) => void;}) {+ const t = useEditor((s) => s.currentTime);return (- <>- {spans.map((span, i) => {- const d = span.clip.transition ?? 0;- if (!spans[i + 1] || d <= 0) return null;- const style = span.clip.transitionStyle ?? "crossfade";- const Icon = TRANSITION_ICONS[style];- return (- <div- key={`xf-${span.clip.id}`}- // Above SELECTED_SHADOW's z-10: the badge marks the joint even- // when a selected clip's ring runs under it.- className="tl-xfade pointer-events-none absolute z-11 flex -translate-x-1/2 items-center justify-center rounded-full bg-[#0a84ff] text-white shadow-[0_0_0_2px_rgba(255,255,255,0.9)]"- style={{- left: (span.start + span.len - span.transitionOut / 2) * pps - CLIP_GAP / 2,- top: 2 + (rowH - 4) / 2 - 8,- width: 16,- height: 16,- }}- title={`${TRANSITION_STYLE_LABELS[style]} ${d.toFixed(1)}s`}- >- <Icon className="size-2.5" />- </div>- );- })}- </>+ <div+ className="tl-playhead-cap absolute top-0 left-[-7px] h-5 w-4 cursor-ew-resize"+ style={{ transform: `translateX(${t * pps}px)` }}+ onPointerDown={onScrub}+ >+ <div className="mx-auto h-3 w-2.5 rounded-t-[3px] bg-[#0a84ff] [clip-path:polygon(0_0,100%_0,100%_58%,50%_100%,0_58%)]" />+ </div>);}+function ClipView({span,- prevOverlap,mention,pps,selected,@@ -2311,10 +2864,6 @@ function ClipView({onFrameMenu,}: {span: ClipSpan;- /** Cross-dissolve overlap of the previous clip into this one, timeline- * seconds — the room the incoming transition block claims on this clip's- * left. This clip's own `span.transitionOut` claims the right. */- prevOverlap: number;/** The clip's chat mention token ("@c2"), shown on hover so the user can* point the assistant at this exact segment. */mention: string;@@ -2342,18 +2891,12 @@ function ClipView({}) {const { clip, asset } = span;const speed = clipSpeed(clip);- // 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 as a- // hard cut (the dissolve badge floats in that gap).- const leftXf = prevOverlap / 2;- const rightXf = span.transitionOut / 2;- const visStart = span.start + leftXf;- const visLen = Math.max(0, span.len - leftXf - rightXf);- const w = visLen * pps;- // Frames start where the box does: skip the source seconds the left dissolve- // consumed so the filmstrip stays aligned under the inset edge.- const filmIn = clip.in + leftXf * speed;- const filmOut = filmIn + (w / pps) * speed;+ // Every box is its clip's whole footprint. Clips never overlap — a+ // transition is a render-time blend at the cut, drawn as the bar above the+ // tracks — so a box's width is the clip's own length, whatever joins it.+ const w = span.len * pps;+ const filmIn = clip.in;+ const filmOut = filmIn + span.len * speed;const startFrame = useEdgeFrame(asset, filmIn, `${clip.id}:in`);const endFrame = useEdgeFrame(asset, filmOut, `${clip.id}:out`);@@ -2374,9 +2917,7 @@ function ClipView({rowH: VIDEO_H,laneCount: 0,homeRow: 0,- // The box is inset by half the incoming dissolve; click-to-seek anchors- // on where the box is drawn, not the clip's footprint start.- visStart,+ visStart: span.start,onDrag,onSnap,vertical: {@@ -2400,8 +2941,7 @@ function ClipView({: parting && "transition-[left] duration-150 ease-out")}style={{- // The ghost keeps the box's dissolve insets, offset to follow the pointer.- left: drag ? drag.ghostX + leftXf * pps : visStart * pps,+ left: drag ? drag.ghostX : span.start * pps,top: drag ? 2 + drag.ghostY : undefined,width: Math.max(10, w - CLIP_GAP),height: VIDEO_H - 4,@@ -2835,10 +3375,13 @@ function HideChip({hidden,onToggle,className,+ small,}: {hidden: boolean;onToggle: () => void;className?: string;+ /** The element bars are low; the chip steps down to fit them. */+ small?: boolean;}) {return (<button@@ -2846,14 +3389,19 @@ function HideChip({title={hidden ? "Enable clip" : "Disable clip"}aria-label={hidden ? "Enable clip" : "Disable clip"}className={cn(- "tl-hide-chip absolute z-4 grid size-[18px] place-items-center rounded-[5px] bg-black/55 text-white transition-opacity hover:bg-black/75",+ "tl-hide-chip absolute z-4 grid place-items-center rounded-[5px] bg-black/55 text-white transition-opacity hover:bg-black/75",+ small ? "size-[13px]" : "size-[18px]",hidden ? "opacity-100" : "opacity-0 group-hover:opacity-100",className)}onPointerDown={(e) => e.stopPropagation()}onClick={onToggle}>- {hidden ? <EyeOff className="size-3" /> : <Eye className="size-3" />}+ {hidden ? (+ <EyeOff className={small ? "size-2" : "size-3"} />+ ) : (+ <Eye className={small ? "size-2" : "size-3"} />+ )}</button>);}@@ -3034,8 +3582,6 @@ function overlayLen(c: VideoClip) {function OverlayClipView({clip,asset,- prevOverlap,- overlap,pps,selected,drag,@@ -3050,11 +3596,6 @@ function OverlayClipView({}: {clip: VideoClip;asset: MediaAsset | undefined;- /** Cross-dissolve overlap of the previous same-track clip into this one —- * the room the incoming transition claims on this clip's left. */- prevOverlap: number;- /** This clip's own dissolve into the next same-track clip (its right). */- overlap: number;pps: number;selected: boolean;/** This clip's live drag when it is the one being carried (ghost mode). */@@ -3073,17 +3614,11 @@ function OverlayClipView({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- // as a hard cut — identical to the track-0 boxes.+ // Its whole footprint, like a track-0 box: clips never overlap, and a+ // transition is the bar above the tracks, never a bite out of a box.const speed = clip.speed && clip.speed > 0 ? clip.speed : 1;- const leftXf = prevOverlap / 2;- const rightXf = overlap / 2;- const visStart = clip.start + leftXf;- const w = Math.max(10, Math.max(0, overlayLen(clip) - leftXf - rightXf) * pps);- // Frames start where the box does: skip the source seconds the left- // dissolve consumed so the filmstrip stays aligned under the inset edge.- const filmIn = clip.in + leftXf * speed;+ const w = Math.max(10, overlayLen(clip) * pps);+ const filmIn = clip.in;const filmOut = filmIn + (w / pps) * speed;// Same filmstrip as a track-0 clip so an overlay reads as a video, not a@@ -3109,9 +3644,7 @@ function OverlayClipView({rowH: OVERLAY_H,laneCount: 0,homeRow: 0,- // The box is inset by half the incoming dissolve; click-to-seek anchors- // on where the box is drawn, not the clip's footprint start.- visStart,+ visStart: clip.start,onDrag,onSnap,vertical: {@@ -3135,8 +3668,7 @@ function OverlayClipView({: parting && "transition-[left] duration-150 ease-out")}style={{- // The ghost keeps the box's dissolve insets, offset to follow the pointer.- left: drag ? drag.ghostX + leftXf * pps : visStart * pps,+ left: drag ? drag.ghostX : clip.start * pps,top: drag ? 2 + drag.ghostY : undefined,width: Math.max(10, w - CLIP_GAP),height: OVERLAY_H - 4,@@ -3191,6 +3723,102 @@ function OverlayClipView({);}+/** The keyframe diamond's grab square — wider than the diamond itself, since+ * a 6px target is not one. Paired with the `size-` on the marker below. */+const KEY_HIT = 14;++/**+ * One keyframe on an element's bar: a diamond where the key falls, dragged+ * left and right to retime it. The grab is kept off the bar underneath, so+ * moving a key never moves the element it belongs to.+ */+function KeyMarker({+ overlay: o,+ t,+ pps,+ width,+ onMenu,+}: {+ overlay: Overlay;+ t: number;+ pps: number;+ width: number;+ /** The bar's right-click menu; a key click carries its time, so the menu+ * offers to remove it. */+ onMenu: (m: { x: number; y: number; id: string; key?: number }) => void;+}) {+ const picked = useEditor(+ (s) => !!s.selectedKey && s.selectedKey.overlayId === o.id && s.selectedKey.t === t+ );+ // Park clear of the trim handles: a key dragged to the very end would+ // otherwise sit under one and stop being grabbable. Those last few pixels+ // cost some positional accuracy, which the bar's own edge already conveys.+ const inset = Math.min(TRIM_W + KEY_HIT / 2, Math.max(3, (width - 8) / 2));+ return (+ <span+ className="tl-key absolute top-1/2 z-3 grid size-3.5 cursor-ew-resize place-items-center"+ style={{+ left: Math.min(width - inset, Math.max(inset, t * pps)),+ transform: "translate(-50%, -50%)",+ }}+ title="Drag to retime, Delete to remove"+ onContextMenu={(e) => {+ e.preventDefault();+ e.stopPropagation();+ onMenu({ x: e.clientX, y: e.clientY, id: o.id, key: t });+ }}+ onPointerDown={(e) => {+ const s = useEditor.getState();+ s.selectOverlayKey(o.id, t);+ let live = t;+ // The undo step opens on the first movement, so a click that only+ // seeks does not leave one behind.+ let checkpointed = false;+ startDrag(e, {+ onMove: (dx) => {+ if (!checkpointed) {+ checkpointed = true;+ s.pushHistory();+ }+ const next = Math.max(0, t + dx / pps);+ s.moveOverlayKey(o.id, live, next, { transient: true });+ live = Math.max(0, Math.min(next, Math.max(0.1, o.end - o.start)));+ },+ // A click that never moved reads as "show me this key": the playhead+ // goes there, and the inspector's rows follow it.+ onUp: (_dx, _dy, moved) => {+ if (!moved) s.seek(o.start + live);+ },+ });+ }}+ >+ <span+ className={cn(+ "pointer-events-none rotate-45 bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.35)] transition-[width,height]",+ picked ? "size-[9px] ring-[1.5px] ring-[#0a84ff]" : "size-[6px]"+ )}+ />+ </span>+ );+}++/** The sticker itself, small, at the head of its bar — a row of stickers reads+ * as which stickers they are. A Lottie has no still to show, so it keeps the+ * glyph. */+function StickerThumb({ overlay: o }: { overlay: StickerOverlay }) {+ const asset = useEditor((s) => (o.assetId ? s.assets.find((a) => a.id === o.assetId) : undefined));+ if (!asset || o.lottie) return <Sticker className="mr-1 size-2.5 shrink-0" />;+ return (+ // eslint-disable-next-line @next/next/no-img-element -- project media URL+ <img+ src={asset.url}+ alt=""+ loading="lazy"+ className="mr-1 size-4 shrink-0 object-contain"+ />+ );+}+function TextBar({overlay: o,pps,@@ -3202,8 +3830,9 @@ function TextBar({parting,onDrag,onSnap,+ onMenu,}: {- overlay: TextOverlay;+ overlay: Overlay;pps: number;top: number;homeRow: number;@@ -3217,14 +3846,48 @@ function TextBar({onDrag: (d: LaneDrag | null) => void;/** Paint (or clear) the snap guide at this stage-x pixel. */onSnap: (x: number | null) => void;+ /** Open the bar's right-click menu; `key` set when it landed on a keyframe. */+ onMenu: (m: { x: number; y: number; id: string; key?: number }) => void;}) {const w = Math.max(8, (o.end - o.start) * pps);- const ui = { pps, rowH: TEXT_H, laneCount, homeRow, onDrag, onSnap };+ // Element rows are a z-order, so the top of the stack is a place a drag+ // can reach: past the top edge opens a row there.+ const ui = { pps, rowH: TEXT_H, laneCount, homeRow, topInsert: true, onDrag, onSnap };+ // Per-kind chip content: a title shows its text, a shape its name behind a+ // shape glyph, a sticker its glyph and name.+ const chip =+ o.kind === "shape" ? (+ <>+ {o.shape === "ellipse" ? (+ <Circle className="mr-1 size-2.5 shrink-0" />+ ) : o.shape === "line" ? (+ <Minus className="mr-1 size-2.5 shrink-0" />+ ) : o.shape === "arrow" ? (+ <MoveRight className="mr-1 size-2.5 shrink-0" />+ ) : (+ <Square className="mr-1 size-2.5 shrink-0" />+ )}+ {SHAPE_LABELS[o.shape]}+ </>+ ) : o.kind === "sticker" ? (+ <>+ <StickerThumb overlay={o} />+ Sticker+ </>+ ) : o.kind === "effect" ? (+ <>+ <Sparkles className="mr-1 size-2.5 shrink-0" />+ {EFFECT_LABELS[o.effect]}+ </>+ ) : (+ o.text.replace(/\n/g, " ")+ );return (<divclassName={cn(- "tl-text-bar group absolute flex cursor-grab items-center overflow-hidden rounded-md bg-gradient-to-b from-purple-500 to-purple-600 shadow-[inset_0_0_0_1px_rgba(0,0,0,0.1)]",+ "tl-text-bar group absolute flex cursor-grab items-center overflow-hidden rounded-md shadow-[inset_0_0_0_1px_rgba(0,0,0,0.1)]",+ FAMILY_STYLE[overlayFamily(o)].bar,o.hidden && "opacity-40 grayscale",selected && SELECTED_SHADOW,drag@@ -3239,18 +3902,33 @@ function TextBar({// Inline so it beats SELECTED_SHADOW's z-10 class on the same element.zIndex: drag ? 20 : undefined,}}- onPointerDown={(e) => startLaneMove(e, "text", o.id, ui)}+ onPointerDown={(e) => startLaneMove(e, "overlay", o.id, ui)}+ onContextMenu={(e) => {+ e.preventDefault();+ onMenu({ x: e.clientX, y: e.clientY, id: o.id });+ }}>- <span className="pointer-events-none truncate px-2 text-[10.5px] font-medium text-white">- {o.text.replace(/\n/g, " ")}+ <span className="pointer-events-none flex min-w-0 items-center truncate px-2 text-[10.5px] font-medium text-white">+ {chip}</span>+ {/* Keys sit on the bar where they fall, so a track is visible without+ opening the inspector. */}+ {(o.kf ?? []).map((k) => (+ <KeyMarker key={k.t} overlay={o} t={k.t} pps={pps} width={w} onMenu={onMenu} />+ ))}+ <HideChip+ hidden={!!o.hidden}+ small+ className="top-1/2 right-2 -translate-y-1/2"+ onToggle={() => useEditor.getState().updateOverlay(o.id, { hidden: !o.hidden })}+ /><spanclassName={cn(trimHandle, "tl-trim-l left-0")}- onPointerDown={(e) => startLaneTrim(e, "text", o.id, "l", ui)}+ onPointerDown={(e) => startLaneTrim(e, "overlay", o.id, "l", ui)}/><spanclassName={cn(trimHandle, "tl-trim-r right-0")}- onPointerDown={(e) => startLaneTrim(e, "text", o.id, "r", ui)}+ onPointerDown={(e) => startLaneTrim(e, "overlay", o.id, "r", ui)}/></div>);@@ -3331,12 +4009,15 @@ function LaneSlot({pps,rowH,barH,+ shift = 0,className,}: {drag: LaneDrag;pps: number;rowH: number;barH: number;+ /** Rows pushed down by a new row opening above them. */+ shift?: number;className?: string;}) {return (@@ -3347,7 +4028,7 @@ function LaneSlot({)}style={{left: drag.slotStart * pps,- top: drag.targetRow * rowH + 2,+ top: drag.targetRow * rowH + 2 + shift,width: Math.max(8, drag.len * pps - CLIP_GAP),height: barH,}}diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.tsindex 157d42fc..b07988c9 100644--- a/site/src/cut/hooks/usePlayback.ts+++ b/site/src/cut/hooks/usePlayback.ts@@ -4,6 +4,7 @@ import { useEffect, type RefObject } from "react";import { clipSpeed, getClipSpans, overlayLayers, projectDuration, useEditor } from "@/cut/lib/store";import { isFullRect, projectFadeSeconds, rectOf } from "@/cut/lib/types";import type { ClipSpan, MediaAsset, VideoClip } from "@/cut/lib/types";+import { BehindCompositor } from "@/cut/lib/behindPass";import { FrameCompositor, MISSING_FRAME, PENDING_FRAME, type Frame } from "@/cut/lib/composite";import { duckGainAt, overlayPlan, prerollLead, trackZeroPlan } from "@/cut/lib/framePlan";import { reportMediaElementError } from "@/cut/lib/mediaLinks";@@ -280,11 +281,18 @@ class Engine {* start-ordered, so we can stop once one is past the horizon. */private warmAhead(spans: ClipSpan[], t: number) {let warmed = 0;- for (const span of spans) {+ for (let i = 0; i < spans.length; i++) {+ const span = spans[i];if (span.start <= t) continue; // current or past — not ours to warmif (span.start > t + WARM_HORIZON_S) break;const speed = clipSpeed(span.clip);- const lead = prerollLead(span.clip.in, speed);+ // A clip a transition blends in shows its entrance frame for the whole+ // blend window, so it parks exactly there, as early as possible — a+ // seek at window-open would leave the frame undecodable mid-blend, and+ // the push/wipe geometry would carve a black region where the picture+ // belongs. It never pre-rolls: the blend is its warm-up.+ const blended = (spans[i - 1]?.transitionOut ?? 0) > 0;+ const lead = blended ? 0 : prerollLead(span.clip.in, speed);// The imminent clip inside its own pre-roll window is `warmNext`'s to// play hot; a parking seek here would fight it, so leave it alone. A clip// with no roll to give (an untrimmed one) has no such window, and stays@@ -364,6 +372,19 @@ class Engine {if (el.readyState >= 2 && !el.seeking) void el.play().catch(() => {});}+ /** Park a clip's element on its entrance frame, paused and silent — the+ * picture a transition blends in before the clip starts playing. */+ private holdAtEntrance(span: ClipSpan): MediaEl {+ const el = this.videoFor(span.clip, span.asset);+ if (isImageEl(el)) return el;+ el.muted = true;+ if (!el.paused) el.pause();+ else if (!el.seeking && Math.abs(el.currentTime - span.clip.in) > 0.05) {+ el.currentTime = span.clip.in;+ }+ return el;+ }+/** Seek/rate/play one clip's element toward its frame at timeline time `t`,* without touching any other element (the caller pauses stale ones). */private prepare(span: ClipSpan, t: number, play: boolean, muted: boolean): MediaEl {@@ -436,15 +457,24 @@ class Engine {// Prime the next clip's decoder+audio pipeline shortly before its entrance// (the dissolve start, or the hard cut) so the handoff `play()` resumes hot// — no cold-start spin-up freezing the picture and playhead at the cut.- if (plan.upcoming) {- this.warmNext(plan.upcoming, t, play);+ // A transitioned cut holds its incoming clip on the entrance frame instead+ // of rolling it: the blend draws that exact frame for the whole window, and+ // a pre-roll would park the decoder on the wrong one — the seek at+ // window-open then leaves the push/wipe geometry a black region until the+ // frame decodes.+ if (plan.upcoming && plan.upcoming !== plan.incoming) {+ if (masterSpan.transitionOut > 0) this.holdAtEntrance(plan.upcoming);+ else this.warmNext(plan.upcoming, t, play);keep.add(plan.upcoming.clip.id);}// Each clip owns its element, so a transition's two clips decode side by- // side — a true blend even when they are trims of the same source.+ // side — a true blend even when they are trims of the same source. The+ // incoming clip has not started yet (the blend window sits before its+ // footprint), so it holds parked on its entrance frame; it starts playing+ // when the cut lands and it becomes the master.let incEl: MediaEl | null = null;if (plan.incoming) {- incEl = this.prepare(plan.incoming, t, play, true); // the outgoing clip keeps the audio+ incEl = this.holdAtEntrance(plan.incoming);keep.add(plan.incoming.clip.id);}// A live voiceover ducks the master clip's sound under it. The clip's own@@ -490,6 +520,20 @@ class Engine {return this.elFor(this.overlayEls, clip.id, asset);}+ // Text-behind-speaker: behind-tagged titles leave the DOM overlay path and+ // composite here — video, then the text raster, then the segmented person+ // back on top (see behindPass.ts). Cheap no-op when nothing is tagged.+ private behind = new BehindCompositor();++ private drawBehind(t: number) {+ const s = useEditor.getState();+ this.behind.draw(this.canvas, s.overlays, s.assets, t);+ }++ // Effect elements are not a canvas pass: they filter the finished picture,+ // elements included, so the stage applies them over everything (see+ // StageEffects) exactly as the export does.+/** Draw a neighbor clip's held frame full-frame beneath an edge animation.* A paused element parks on the wanted frame (the previous clip already* rests at its out point after the handoff; warm-ahead parks the next one@@ -735,11 +779,17 @@ class Engine {// soundtrack) is still reachable while scrubbing and playing.const total = projectDuration(s);- // Nothing anywhere — no track-0 clip, no overlay layer, no soundtrack —- // resets to a black frame at 0. An empty track 0 with an overlay clip or- // audio still plays: the tick body draws those layers and advances the wall- // clock, so the guard must not bail on `spans.length === 0` alone.- if (spans.length === 0 && overlayLayers(s.clips).length === 0 && s.audioClips.length === 0) {+ // Nothing anywhere — no track-0 clip, no overlay layer, no soundtrack, no+ // title or sticker — resets to a black frame at 0. An empty track 0 with+ // any one of those still plays: the tick body draws those layers and+ // advances the wall clock, so the guard must not bail on+ // `spans.length === 0` alone.+ if (+ spans.length === 0 &&+ overlayLayers(s.clips).length === 0 &&+ s.audioClips.length === 0 &&+ s.overlays.length === 0+ ) {this.pauseExcept(new Set());this.comp.drawLayer(MISSING_FRAME, undefined, true, 1, 0);this.syncSoundtrack(0, false);@@ -749,7 +799,7 @@ class Engine {let t = Math.min(s.currentTime, total);- // iMovie skimming: while paused with the mouse over the timeline, the+ // Skimming: while paused with the mouse over the timeline, the// frame on screen lives at the skim point, not the playhead. The playhead// (currentTime) is never touched.const pt =@@ -805,6 +855,7 @@ class Engine {if (span) this.composite(span, spans, Math.min(pt, span.start + span.len), false);else this.pauseExcept(new Set());this.drawOverlays(pt, false, active, overlaysLive);+ this.drawBehind(pt);this.comp.drawProjectFade(this.projectFadeGain(pt, total));this.cleanupOverlays(active);this.syncSoundtrack(t, false);@@ -886,6 +937,7 @@ class Engine {useEditor.setState({ playing: false, currentTime: total, previewStopAt: null });pauseEl(el);this.drawOverlays(t, true, active);+ this.drawBehind(t);this.comp.drawProjectFade(this.projectFadeGain(total, total));this.cleanupOverlays(active);this.syncSoundtrack(total, false);@@ -904,6 +956,7 @@ class Engine {if (t >= total - 0.001) {useEditor.setState({ playing: false, currentTime: total, previewStopAt: null });this.drawOverlays(t, true, active);+ this.drawBehind(t);this.comp.drawProjectFade(this.projectFadeGain(total, total));this.cleanupOverlays(active);this.syncSoundtrack(total, false);@@ -912,6 +965,7 @@ class Engine {}this.drawOverlays(t, true, active);+ this.drawBehind(t);// The whole-video fade veils the finished frame and dims the sound —// the master's element volume (set by composite) and the soundtrack.const fadeGain = this.projectFadeGain(t, total);diff --git a/site/src/cut/lib/aiContext.ts b/site/src/cut/lib/aiContext.tsindex a39a2f55..f62b5585 100644--- a/site/src/cut/lib/aiContext.ts+++ b/site/src/cut/lib/aiContext.ts@@ -1,10 +1,11 @@"use client";+import { hasOverlayAnim } from "@donkeycut/effects-kit";import { chatOwner } from "./chatAssets";import { useGenerate } from "./generate";import { getClipSpans, overlayLayers, totalDuration, useEditor } from "./store";import { laneCues, subtitleLaneCount } from "./subtitles";-import { frameOf, rectOf, regionLabel, type ClipSpan, type VideoClip } from "./types";+import { frameOf, rectOf, regionLabel, type ClipSpan, type Overlay, type VideoClip } from "./types";const r = (n: number) => Math.round(n * 100) / 100;@@ -102,8 +103,12 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu? { kind, id, text: c.text, start: r(c.start), end: r(c.end), track: c.lane ?? 0 }: { kind, id };}+ // The selection's kind stays "overlay" (what select/delete take); the+ // element's own kind rides in from describeOverlay as `element`.const o = s.overlays.find((x) => x.id === id);- return o ? { kind, id, ...describeOverlay(o) } : { kind, id };+ if (!o) return { kind, id };+ const { kind: element, ...rest } = describeOverlay(o);+ return { kind, id, element, ...rest };})();return {@@ -208,7 +213,9 @@ export function buildAiContext(opts?: { fullCues?: boolean; chatId?: string | nu}));}),soundtrack: s.audioClips.map((a) => ({ id: a.id, ...describeAudio(a, assetById) })),- titles: s.overlays.map((o) => ({ id: o.id, ...describeOverlay(o) })),+ // Every overlay element on the title lanes: titles, shapes, stickers —+ // each entry carries its `kind`.+ overlays: s.overlays.map((o) => ({ id: o.id, ...describeOverlay(o) })),subtitles: {count: s.subtitles.cues.length,showOnVideo: s.subtitles.showOnVideo,@@ -289,25 +296,58 @@ function describeOverlayClip(c: VideoClip, assets: Map<string, { name: string }>};}-function describeOverlay(o: {- text: string; start: number; end: number; x: number; y: number;- size: number; font: string; weight: number; color: string; shadow: boolean; plate: boolean;- plateRadius?: number; lane?: number; hidden?: boolean;-}) {- return {- text: o.text,+function describeOverlay(o: Overlay) {+ const base = {+ kind: o.kind ?? "text",start: r(o.start),end: r(o.end),x: r(o.x),y: r(o.y),+ ...(o.rotation ? { rotation: o.rotation } : {}),+ ...(o.opacity !== undefined ? { opacity: r(o.opacity) } : {}),+ ...(hasOverlayAnim(o.anim) ? { anim: o.anim } : {}),+ ...(o.kf?.length+ ? { keyframes: o.kf.map((k) => ({ ...k, t: r(k.t), x: r(k.x), y: r(k.y) })) }+ : {}),+ ...(o.lane ? { lane: o.lane } : {}),+ ...(o.hidden ? { hidden: true } : {}),+ };+ if (o.kind === "shape") {+ return {+ ...base,+ shape: o.shape,+ w: r(o.w),+ h: r(o.h),+ fill: o.fill,+ ...(o.fillOpacity !== undefined ? { fillOpacity: r(o.fillOpacity) } : {}),+ ...(o.radius ? { radius: o.radius } : {}),+ ...(o.stroke ? { stroke: o.stroke } : {}),+ };+ }+ if (o.kind === "sticker") {+ return { ...base, assetId: o.assetId, w: r(o.w) };+ }+ if (o.kind === "effect") {+ return {+ ...base,+ effect: o.effect,+ amount: r(o.amount ?? 0.5),+ ...(o.effect === "zoom"+ ? { focus: { x: r(o.focus?.x ?? 0.5), y: r(o.focus?.y ?? 0.5) } }+ : {}),+ };+ }+ return {+ ...base,+ text: o.text,size: o.size,font: o.font,weight: o.weight,color: o.color,shadow: o.shadow,plate: o.plate,+ ...(o.behindSubject ? { behindSubject: true } : {}),+ ...(o.groupId ? { groupId: o.groupId } : {}),...(o.plateRadius !== undefined && { plateRadius: r(o.plateRadius) }),- ...(o.lane ? { lane: o.lane } : {}),- ...(o.hidden ? { hidden: true } : {}),};}diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex 7001f312..3a2c0327 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -1,5 +1,19 @@"use client";+import {+ autoGradeFromImageData,+ EFFECT_IDS,+ normalizeGrade,+ type EffectId,+ OVERLAY_ANIM_DEFAULT_SECONDS,+ OVERLAY_ANIM_MAX_SECONDS,+ OVERLAY_ANIM_MIN_SECONDS,+ OVERLAY_ANIM_STYLE_IDS,+ OVERLAY_LOOP_STYLE_IDS,+ type OverlayAnim,+ type OverlayAnimStyle,+ type OverlayLoopStyle,+} from "@donkeycut/effects-kit";import { apiFetch, apiJson, getBackend } from "./backend";import { refFromAsset, refFromStockVideo, type AssetRef } from "./assetRef";import { chatOwner, tagChatAsset } from "./chatAssets";@@ -30,15 +44,15 @@ import {makeStillSheetClientSide,renderAudioSpanWav,} from "./media";+import { isLottieAsset } from "./lottieAssets";import { BREATH, REACH, refineEdge, type SilenceSpan } from "./cutRefine";import { requestSidePanel, SIDE_PANEL_TABS } from "./panelRequest";import { blobToInlineAudio, refToInlineAudio, visualRefs, type InlineImage } from "./refMedia";import { characterPrompt, stockAspectDims, stockTitle } from "./stock";import { STOCK_IMAGES } from "./stockManifest";import { STOCK_VIDEOS } from "./stockVideoManifest";-import { applyOverlayPatchSettled, track0Clips, trackGapAt, getClipSpans, nextFreeStart, overlayLayers, TIMELINE_H_MAX, TIMELINE_H_MIN, totalDuration, useEditor } from "./store";+import { applyOverlayPatchSettled, track0Clips, laneGapAt, getClipSpans, nextFreeStart, overlayLayers, TIMELINE_H_MAX, TIMELINE_H_MIN, totalDuration, useEditor } from "./store";import { buildAiContext } from "./aiContext";-import { autoGradeFromImageData, normalizeGrade } from "./colorGrade";import { sampleClipFrameData } from "./previewCanvas";import { laneCues, subtitleLaneCount } from "./subtitles";import { synthesizeMusic } from "./audioGen";@@ -48,12 +62,13 @@ import { resolveVoice, synthesizeSpeech, SPEECH_VOICES } from "./tts";import { defaultVideoAspects } from "./videoModels";import { DUCK_DEFAULT, generateSubtitlesReadout } from "./voiceover";import {+ allFonts,ANIM_DEFAULT_SECONDS,ANIM_STYLE_IDS,frameOf,IMAGE_CLIP_SECONDS,+ isTextOverlay,LAYOUTS,- LOOK_IDS,MAX_SUBTITLE_LANES,mediaUrl,nearestAspect,@@ -61,6 +76,7 @@ import {overlayAnimStyle,rectOf,regionLabel,+ SHAPE_LABELS,SPEED_FLOOR,TRANSITION_STYLE_IDS,type AnimStyle,@@ -69,6 +85,7 @@ import {type FontId,type MediaAsset,type Selection,+ type ShapeKind,type SidePanelTab,type TransitionStyle,type VideoClip,@@ -333,18 +350,19 @@ export async function runAiTool(}const id = String(input.id ?? "");// A video clip on any track selects as "clip"; "overlayClip" is accepted- // as a legacy alias for a layer clip and resolves the same way.+ // as a legacy alias for a layer clip and "text" for an overlay element.const pool =kind === "clip" || kind === "overlayClip"? s.clips: kind === "audio"? s.audioClips- : kind === "text"+ : kind === "overlay" || kind === "text"? s.overlays: null;if (!pool) throw new ToolError(`Unknown kind: ${kind}`);if (!pool.some((x) => x.id === id)) throw new ToolError(`No ${kind} with id ${id}.`);- const selKind = kind === "overlayClip" ? "clip" : (kind as "clip" | "audio" | "text");+ const selKind =+ kind === "overlayClip" ? "clip" : kind === "text" ? "overlay" : (kind as "clip" | "audio" | "overlay");s.select({ kind: selKind, id });return { selection: { kind: selKind, id } };}@@ -709,7 +727,7 @@ export async function runAiTool(}case "delete_item": {- const kind = String(input.kind) as "clip" | "overlayClip" | "audio" | "text";+ const kind = String(input.kind) as "clip" | "overlayClip" | "audio" | "overlay" | "text";const id = String(input.id ?? "");const pool =kind === "clip" || kind === "overlayClip"@@ -718,7 +736,8 @@ export async function runAiTool(? s.audioClips: s.overlays;if (!pool.some((x) => x.id === id)) throw new ToolError(`No ${kind} with id ${id}.`);- const selKind = kind === "overlayClip" ? "clip" : (kind as "clip" | "audio" | "text");+ const selKind =+ kind === "overlayClip" ? "clip" : kind === "text" ? "overlay" : (kind as "clip" | "audio" | "overlay");s.select({ kind: selKind, id });s.deleteSelection();return { deleted: { kind: selKind, id } };@@ -727,9 +746,10 @@ export async function runAiTool(case "remove_gap": {if (!isNum(input.at)) throw new ToolError("at (seconds) is required.");const track = isNum(input.track) ? input.track : 0;- const gap = trackGapAt(s.clips, track, input.at);+ const lane = { kind: "video", index: track } as const;+ const gap = laneGapAt(s, lane, input.at);if (!gap) throw new ToolError(`No track-${track} gap at ${input.at}s — pass a time inside the empty span.`);- s.removeGap(track, input.at);+ s.removeLaneGap(lane, input.at);return { closed: { track, ...gap } };}@@ -738,19 +758,165 @@ export async function runAiTool(throw new ToolError("text is required.");if (isNum(input.start)) s.seek(input.start);s.addOverlay();- const cur = useEditor.getState();- const sel = cur.selection;- if (sel?.kind !== "text") throw new ToolError("Could not create the title.");- applyOverlayPatchSettled(sel.id, titlePatch({ ...input, id: sel.id }));+ const sel = useEditor.getState().selection;+ if (sel?.kind !== "overlay") throw new ToolError("Could not create the title.");+ applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "text"));+ const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;+ return { id: o.id, ...(isTextOverlay(o) ? { text: o.text } : {}), start: o.start, end: o.end };+ }++ case "add_shape": {+ const shape = String(input.shape) as ShapeKind;+ if (!(shape in SHAPE_LABELS)) throw new ToolError("shape must be rect, ellipse, line, or arrow.");+ if (isNum(input.start)) s.seek(input.start);+ s.addShape(shape);+ const sel = useEditor.getState().selection;+ if (sel?.kind !== "overlay") throw new ToolError("Could not create the shape.");+ applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "shape"));+ const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;+ return { id: o.id, shape, start: round2(o.start), end: round2(o.end) };+ }++ case "add_sticker": {+ const assetId = typeof input.asset_id === "string" && input.asset_id ? input.asset_id : undefined;+ if (!assetId) throw new ToolError("Pass asset_id.");+ const stickerAsset = s.assets.find((a) => a.id === assetId);+ if (stickerAsset?.type !== "image") throw new ToolError(`No image asset with id ${assetId}.`);+ if (isNum(input.start)) s.seek(input.start);+ s.addSticker({ assetId, ...(isLottieAsset(stickerAsset) ? { lottie: true } : {}) });+ const sel = useEditor.getState().selection;+ if (sel?.kind !== "overlay") throw new ToolError("Could not create the sticker.");+ applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "sticker"));+ const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;+ return { id: o.id, assetId, start: round2(o.start), end: round2(o.end) };+ }++ case "add_effect": {+ const effect = String(input.effect ?? "");+ if (!(EFFECT_IDS as string[]).includes(effect))+ throw new ToolError(`effect must be one of ${EFFECT_IDS.join(", ")}.`);+ if (isNum(input.start)) s.seek(input.start);+ s.addEffect(effect as EffectId);+ const sel = useEditor.getState().selection;+ if (sel?.kind !== "overlay") throw new ToolError("Could not create the effect.");+ applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "effect"));+ // Where a zoom holds: the rest of the effects fill the frame, so the+ // point only means anything for this one.+ if (effect === "zoom" && (isNum(input.focus_x) || isNum(input.focus_y))) {+ useEditor.getState().updateOverlay(sel.id, {+ focus: {+ x: clamp(isNum(input.focus_x) ? input.focus_x : 0.5, 0, 1),+ y: clamp(isNum(input.focus_y) ? input.focus_y : 0.5, 0, 1),+ },+ });+ }const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;- return { id: o.id, text: o.text, start: o.start, end: o.end };+ return { id: o.id, effect, start: round2(o.start), end: round2(o.end) };}- case "update_title": {- const o = requireItem(s.overlays, input.id, "title");- s.updateOverlay(o.id, titlePatch(input));+ case "create_sticker": {+ const idea = String(input.idea ?? "").trim();+ if (!idea) throw new ToolError("idea is required.");+ if (!s.projectId) throw new ToolError("No project open.");+ const { createCustomSticker } = await import("./stickerCreate");+ const asset = await createCustomSticker(s.projectId, idea);+ if (isNum(input.start)) s.seek(input.start);+ useEditor.getState().addSticker({ assetId: asset.id });+ const sel = useEditor.getState().selection;+ if (sel?.kind !== "overlay") throw new ToolError("Could not place the sticker.");+ applyOverlayPatchSettled(sel.id, overlayPatch({ ...input, id: sel.id }, "sticker"));+ const o = useEditor.getState().overlays.find((x) => x.id === sel.id)!;+ return { id: o.id, assetId: asset.id, start: round2(o.start), end: round2(o.end) };+ }++ case "set_overlay_animation": {+ const o = requireItem(s.overlays, input.id, "overlay element");+ const anim: OverlayAnim = { ...(o.anim ?? {}) };+ const edge = (slot: "in" | "out", styleKey: string, secondsKey: string) => {+ const raw = input[styleKey];+ const secs = isNum(input[secondsKey])+ ? clamp(input[secondsKey], OVERLAY_ANIM_MIN_SECONDS, OVERLAY_ANIM_MAX_SECONDS)+ : undefined;+ if (typeof raw === "string") {+ if (raw === "none") {+ delete anim[slot];+ return;+ }+ if (!(OVERLAY_ANIM_STYLE_IDS as string[]).includes(raw))+ throw new ToolError(`Unknown ${slot} style: ${raw}`);+ if (raw === "typewriter" && (o.kind ?? "text") !== "text")+ throw new ToolError("typewriter animates titles only.");+ anim[slot] = {+ style: raw as OverlayAnimStyle,+ seconds: secs ?? anim[slot]?.seconds ?? OVERLAY_ANIM_DEFAULT_SECONDS,+ };+ } else if (secs !== undefined && anim[slot]) {+ anim[slot] = { ...anim[slot]!, seconds: secs };+ }+ };+ edge("in", "in_style", "in_seconds");+ edge("out", "out_style", "out_seconds");+ const rawLoop = input.loop_style;+ const speed = isNum(input.loop_speed) ? clamp(input.loop_speed, 0.25, 4) : undefined;+ if (typeof rawLoop === "string") {+ if (rawLoop === "none") delete anim.loop;+ else if (!(OVERLAY_LOOP_STYLE_IDS as string[]).includes(rawLoop))+ throw new ToolError(`Unknown loop style: ${rawLoop}`);+ else anim.loop = { style: rawLoop as OverlayLoopStyle, speed: speed ?? anim.loop?.speed ?? 1 };+ } else if (speed !== undefined && anim.loop) {+ anim.loop = { ...anim.loop, speed };+ }+ s.updateOverlay(o.id, { anim: anim.in || anim.out || anim.loop ? anim : undefined });const next = useEditor.getState().overlays.find((x) => x.id === o.id)!;- return { id: next.id, text: next.text, color: next.color, size: next.size };+ return { id: next.id, anim: next.anim ?? null };+ }++ case "set_overlay_keyframes": {+ const o = requireItem(s.overlays, input.id, "overlay element");+ const raw = input.keys;+ if (!Array.isArray(raw)) throw new ToolError("keys must be a list.");+ const dur = Math.max(0.1, o.end - o.start);+ let kf = o.kf;+ if (raw.length === 0) {+ s.clearOverlayKeys(o.id);+ kf = undefined;+ } else {+ // Each key builds on the pose already at its time, so a key that only+ // names `x` keeps whatever the element was doing otherwise.+ s.pushHistory();+ for (const k of raw as Record<string, unknown>[]) {+ if (!isNum(k.t)) throw new ToolError("Every key needs a time `t`.");+ s.setOverlayKey(+ o.id,+ clamp(k.t, 0, dur),+ {+ ...(isNum(k.x) ? { x: clamp(k.x, 0.02, 0.98) } : {}),+ ...(isNum(k.y) ? { y: clamp(k.y, 0.02, 0.98) } : {}),+ ...(isNum(k.scale) ? { scale: clamp(k.scale, 0.1, 4) } : {}),+ ...(isNum(k.rotation) ? { rotation: clamp(Math.round(k.rotation), -180, 180) } : {}),+ ...(isNum(k.opacity) ? { opacity: clamp(k.opacity, 0, 1) } : {}),+ },+ { transient: true }+ );+ }+ kf = useEditor.getState().overlays.find((x) => x.id === o.id)?.kf;+ }+ return { id: o.id, keys: (kf ?? []).map((k) => ({ ...k, t: round2(k.t) })) };+ }++ // "update_title" stays as an alias so older threads keep working.+ case "update_title":+ case "update_overlay": {+ const o = requireItem(s.overlays, input.id, "overlay element");+ s.updateOverlay(o.id, overlayPatch(input, o.kind ?? "text"));+ const next = useEditor.getState().overlays.find((x) => x.id === o.id)!;+ return {+ id: next.id,+ kind: next.kind ?? "text",+ ...(isTextOverlay(next) ? { text: next.text, color: next.color, size: next.size } : {}),+ start: round2(next.start),+ end: round2(next.end),+ };}case "update_audio": {@@ -1382,7 +1548,7 @@ export async function runAiTool(const sels = ids.map((id): NonNullable<Selection> => {if (s.clips.some((c) => c.id === id)) return { kind: "clip", id };if (s.audioClips.some((c) => c.id === id)) return { kind: "audio", id };- if (s.overlays.some((o) => o.id === id)) return { kind: "text", id };+ if (s.overlays.some((o) => o.id === id)) return { kind: "overlay", id };if (s.subtitles.cues.some((c) => c.id === id)) return { kind: "cue", id };throw new ToolError(`No timeline item with id ${id}. Call get_state for current ids.`);});@@ -1884,20 +2050,6 @@ export async function runAiTool(return { id: next.id, which, style: anim?.style ?? "none", seconds: anim?.seconds ?? 0 };}- case "set_look": {- const clip = requireItem(s.clips, input.clipId, "video clip");- if (input.style === "none") {- s.setClipLook(clip.id, null);- return { id: clip.id, look: "none" };- }- const style = LOOK_IDS.find((x) => x === input.style);- if (!style)- throw new ToolError(`Unknown look. Use one of: ${LOOK_IDS.join(", ")}, none.`);- s.setClipLook(clip.id, style, isNum(input.amount) ? input.amount : undefined);- const next = useEditor.getState().clips.find((c) => c.id === clip.id)!;- return { id: next.id, look: next.look ?? "none", amount: next.lookAmount ?? 1 };- }-case "merge_cue": {const cue = requireItem(s.subtitles.cues, input.id, "subtitle cue");const mates = laneCues(s.subtitles, cue.lane ?? 0);@@ -2348,21 +2500,75 @@ async function launchVideoJob(};}-function titlePatch(input: Record<string, unknown>) {+/** Sanitize an overlay-element patch from tool input: shared fields (timing,+ * position, rotation, opacity, hidden) plus the target kind's own fields.+ * Outline width is em for text (scales with the type) and design px for+ * shapes, so the interpretation follows the element being patched. */+function overlayPatch(input: Record<string, unknown>, kind: "text" | "shape" | "sticker" | "effect") {const patch: Record<string, unknown> = {};- if (typeof input.text === "string" && input.text.trim()) patch.text = input.text;if (isNum(input.start)) patch.start = Math.max(0, input.start);if (isNum(input.end)) patch.end = input.end;if (isNum(input.x)) patch.x = clamp(input.x, 0.02, 0.98);if (isNum(input.y)) patch.y = clamp(input.y, 0.02, 0.98);- if (isNum(input.size)) patch.size = clamp(Math.round(input.size), 16, 320);- if (typeof input.color === "string") patch.color = input.color;- if (["sf", "serif", "rounded", "mono", "impact"].includes(String(input.font)))- patch.font = input.font as FontId;- if (input.weight === 400 || input.weight === 700) patch.weight = input.weight;- if (typeof input.shadow === "boolean") patch.shadow = input.shadow;- if (typeof input.plate === "boolean") patch.plate = input.plate;- if (isNum(input.plateRadius)) patch.plateRadius = clamp(input.plateRadius, 0, 1);+ if (isNum(input.rotation))+ patch.rotation = Math.round(clamp(input.rotation, -180, 180)) || undefined;+ if (isNum(input.opacity))+ patch.opacity = input.opacity >= 0.995 ? undefined : clamp(input.opacity, 0, 1);if (typeof input.hidden === "boolean") patch.hidden = input.hidden || undefined;++ if (kind === "text") {+ if (typeof input.text === "string" && input.text.trim()) patch.text = input.text;+ if (isNum(input.size)) patch.size = clamp(Math.round(input.size), 16, 320);+ if (typeof input.color === "string") patch.color = input.color;+ // Only ids the registry knows: an unknown one resolves to the default+ // face, so storing it would silently render a font the user never chose+ // and leave the Inspector's font menu blank.+ if (typeof input.font === "string" && allFonts().some((f) => f.id === input.font))+ patch.font = input.font as FontId;+ if (input.weight === 400 || input.weight === 700) patch.weight = input.weight;+ if (typeof input.italic === "boolean") patch.italic = input.italic || undefined;+ if (["left", "center", "right"].includes(String(input.align)))+ patch.align = input.align === "center" ? undefined : input.align;+ if (isNum(input.letter_spacing))+ patch.letterSpacing = Math.abs(input.letter_spacing) < 0.0025 ? undefined : clamp(input.letter_spacing, -0.05, 0.5);+ if (isNum(input.line_height))+ patch.lineHeight = Math.abs(input.line_height - 1.25) < 0.01 ? undefined : clamp(input.line_height, 0.7, 2.5);+ if (typeof input.shadow === "boolean") patch.shadow = input.shadow;+ if (typeof input.plate === "boolean") patch.plate = input.plate;+ if (typeof input.behind_subject === "boolean") patch.behindSubject = input.behind_subject || undefined;+ if (isNum(input.plateRadius)) patch.plateRadius = clamp(input.plateRadius, 0, 1);+ if (typeof input.stroke_color === "string" || isNum(input.stroke_width)) {+ const width = isNum(input.stroke_width) ? clamp(input.stroke_width, 0, 0.3) : 0.04;+ patch.stroke =+ width > 0+ ? { color: typeof input.stroke_color === "string" ? input.stroke_color : "#111114", width }+ : undefined;+ }+ return patch;+ }++ if (kind === "shape") {+ if (isNum(input.w)) patch.w = clamp(input.w, 0.01, 2);+ if (isNum(input.h)) patch.h = clamp(input.h, 0.002, 2);+ if (typeof input.fill === "string") patch.fill = input.fill;+ if (isNum(input.fill_opacity))+ patch.fillOpacity = input.fill_opacity >= 0.995 ? undefined : clamp(input.fill_opacity, 0, 1);+ if (isNum(input.radius)) patch.radius = clamp(input.radius, 0, 200) || undefined;+ if (typeof input.stroke_color === "string" || isNum(input.stroke_width)) {+ const width = isNum(input.stroke_width) ? clamp(input.stroke_width, 0, 60) : 6;+ patch.stroke =+ width > 0+ ? { color: typeof input.stroke_color === "string" ? input.stroke_color : "#111114", width }+ : undefined;+ }+ return patch;+ }++ if (kind === "effect") {+ if (isNum(input.amount)) patch.amount = clamp(input.amount, 0.05, 1);+ return patch;+ }++ if (isNum(input.w)) patch.w = clamp(input.w, 0.02, 1.5);return patch;}diff --git a/site/src/cut/lib/audioMix.test.ts b/site/src/cut/lib/audioMix.test.tsindex 6d18a0b3..afc334d4 100644--- a/site/src/cut/lib/audioMix.test.ts+++ b/site/src/cut/lib/audioMix.test.ts@@ -25,20 +25,19 @@ describe("foldClips", () => {expect(geo.every((g) => g.fadeIn === 0 && g.fadeOut === 0)).toBe(true);});- test("pulls a clip back by the dissolve it inherits", () => {+ test("fades the outgoing clip across the blend and joins hard at the cut", () => {const geo = foldClips([clip({ transition: 1 }), clip()]);expect(geo[0].at).toBe(0);- // The second clip starts a second early so the two overlap.- expect(geo[1].at).toBe(3);+ // The second clip starts exactly at the cut — a transition claims no layout.+ expect(geo[1].at).toBe(4);expect(geo[0].fadeOut).toBe(1);- expect(geo[1].fadeIn).toBe(1);+ expect(geo[1].fadeIn).toBe(0);});- test("scales a dissolve down so it cannot swallow its clips", () => {- // A two-second overlap between one-second clips would run past both.+ test("scales a blend down so it cannot swallow its clip", () => {const geo = foldClips([clip({ out: 1, transition: 2 }), clip({ out: 1 })]);expect(geo[0].fadeOut).toBeLessThanOrEqual(0.9);- expect(geo[1].at).toBeGreaterThan(0);+ expect(geo[1].at).toBe(1);});test("counts a speed change against the footprint, not the source span", () => {diff --git a/site/src/cut/lib/audioMix.ts b/site/src/cut/lib/audioMix.tsindex 069dd489..f5738dde 100644--- a/site/src/cut/lib/audioMix.ts+++ b/site/src/cut/lib/audioMix.ts@@ -79,19 +79,18 @@ const itemDur = (a: MixItem) => Math.max(0, (a.out - a.in) / speedOf(a.speed));/*** Where the sequential fold puts each track-0 clip, and how long its- * cross-dissolve edges are. Each dissolve pulls the next clip back by the- * (clamped) overlap, exactly like the engine's acrossfade chain.+ * transition edges are. Clips abut — a transition claims no layout — and its+ * sound is the outgoing clip fading across the blend window while the next+ * enters clean at the cut, exactly like the engine's tail-fade + hard join.*/export function foldClips(clips: MixClip[]) {const geo = clips.map((clip) => ({ clip, at: 0, dur: clipDur(clip), fadeIn: 0, fadeOut: 0 }));let acc = 0;geo.forEach((g, j) => {- const overlap = j > 0 ? Math.min(clips[j - 1].transition ?? 0, acc * 0.9, g.dur * 0.9) : 0;- const fade = overlap > 0.01 ? overlap : 0;- g.at = j === 0 ? 0 : acc - fade;- g.fadeIn = fade;- if (j > 0) geo[j - 1].fadeOut = fade;- acc = g.at + g.dur;+ g.at = acc;+ acc += g.dur;+ const fade = geo[j + 1] ? Math.min(g.clip.transition ?? 0, g.dur * 0.9) : 0;+ if (fade > 0.01) g.fadeOut = fade;});return geo;}diff --git a/site/src/cut/lib/composite.ts b/site/src/cut/lib/composite.tsindex 1d2ca9bf..459f94b3 100644--- a/site/src/cut/lib/composite.ts+++ b/site/src/cut/lib/composite.ts@@ -19,8 +19,7 @@* it was reached by playing there or by rendering the 135th frame.*/-import { gradeTint, gradeToCssFilter, isNeutralGrade } from "./colorGrade";-import { grainTile, lookCssFilter, lookPost } from "./looks";+import { gradeTint, gradeToCssFilter, grainTile, isNeutralGrade, lookCssFilter, lookPost } from "@donkeycut/effects-kit";import { isFullRect, rectOf } from "./types";import type { FrameRect, TransitionStyle, VideoClip } from "./types";@@ -454,15 +453,25 @@ export class FrameCompositor {ctx.restore();};// Only the absence of an incoming clip cancels the transition. One whose- // picture merely hasn't decoded yet still runs its style: the geometry —- // a dip's veil, a circle's clip path — is what the frame should look like- // mid-transition, and skipping it flashes the outgoing clip at full- // brightness for as long as the decoder lags. `drawLayer` declines to draw- // the pending picture itself.+ // picture merely hasn't decoded yet still runs the layered styles: a dip's+ // veil and a fade's ramp sit over the master, so the geometry is what the+ // frame should look like mid-transition. The region styles are different —+ // a push shoves the master aside and a circle carves it away, and with no+ // incoming picture yet the vacated region renders black — so those hold+ // the master in place until the frame decodes.if (d.incFrame.kind === "missing" || p <= 0) {drawMaster();return;}+ const carves =+ style.startsWith("push") ||+ style.startsWith("wipe") ||+ style.startsWith("circle") ||+ style.startsWith("split");+ if (carves && d.incFrame.kind === "pending") {+ drawMaster();+ return;+ }switch (style) {case "dipblack":case "dipwhite": {diff --git a/site/src/cut/lib/drag.ts b/site/src/cut/lib/drag.tsindex 0cb02630..fb1d0fff 100644--- a/site/src/cut/lib/drag.ts+++ b/site/src/cut/lib/drag.ts@@ -5,6 +5,10 @@ import type React from "react";interface DragOpts {onMove: (dx: number, dy: number, ev: PointerEvent) => void;onUp?: (dx: number, dy: number, moved: boolean) => void;+ /** Cursor to hold for the whole gesture, wherever the pointer travels. Read+ * again after every move, so a cursor that turns with what it is dragging+ * keeps up. */+ cursor?: () => string;}// Live count of in-flight pointer drags, so layout that depends on clip@@ -42,16 +46,35 @@ export function startDrag(e: React.PointerEvent, opts: DragOpts) {activeDrags++;dragListeners.forEach((fn) => fn());+ // A drag pulls the pointer off the handle within a few pixels, and from there+ // the cursor belongs to whatever it happens to be over. One document-wide+ // rule outranks all of them until the gesture ends.+ const pin = opts.cursor ? document.createElement("style") : null;+ let pinned = "";+ const holdCursor = () => {+ if (!pin || !opts.cursor) return;+ const next = opts.cursor();+ if (next === pinned) return;+ pinned = next;+ pin.textContent = `*, *::before, *::after { cursor: ${next} !important; }`;+ };+ if (pin) {+ holdCursor();+ document.head.append(pin);+ }+const move = (ev: PointerEvent) => {const dx = ev.clientX - startX;const dy = ev.clientY - startY;if (Math.abs(dx) > 3 || Math.abs(dy) > 3) moved = true;opts.onMove(dx, dy, ev);+ holdCursor();};const up = (ev: PointerEvent) => {window.removeEventListener("pointermove", move);window.removeEventListener("pointerup", up);window.removeEventListener("pointercancel", up);+ pin?.remove();activeDrags--;dragListeners.forEach((fn) => fn());opts.onUp?.(ev.clientX - startX, ev.clientY - startY, moved);diff --git a/site/src/cut/lib/framePlan.test.ts b/site/src/cut/lib/framePlan.test.tsindex 5f2a8f95..2a013010 100644--- a/site/src/cut/lib/framePlan.test.ts+++ b/site/src/cut/lib/framePlan.test.ts@@ -31,13 +31,13 @@ function spansOf(count: number, len = 4, transitions: number[] = []): ClipSpan[]for (let i = 0; i < count; i++) {const transitionOut = transitions[i] ?? 0;spans.push({- clip: videoClip({ start: at, out: len }),+ clip: videoClip({ start: at, out: len, transitionStyle: undefined }),asset,start: at,len,transitionOut,});- at += len - transitionOut;+ at += len; // clips abut — a transition is a blend at the cut, never overlap}return spans;}@@ -52,26 +52,38 @@ describe("trackZeroPlan", () => {expect(plan.masterZoom).toBe(1);});- test("ramps a dissolve from 0 to 1 across the overlap", () => {+ test("ramps a dissolve from 0 to 1 across the blend window before the cut", () => {const spans = spansOf(2, 4, [2]);- const start = spans[1].start;- expect(trackZeroPlan(spans[0], spans, start).p).toBeCloseTo(0, 5);- expect(trackZeroPlan(spans[0], spans, start + 1).p).toBeCloseTo(0.5, 5);- expect(trackZeroPlan(spans[0], spans, start + 2).p).toBeCloseTo(1, 5);+ const cut = spans[1].start;+ expect(trackZeroPlan(spans[0], spans, cut - 2).p).toBeCloseTo(0, 5);+ expect(trackZeroPlan(spans[0], spans, cut - 1).p).toBeCloseTo(0.5, 5);+ expect(trackZeroPlan(spans[0], spans, cut - 0.001).p).toBeCloseTo(1, 2);});- test("names the incoming clip only while its overlap is live", () => {+ test("names the incoming clip only while its blend window is live", () => {const spans = spansOf(2, 4, [2]);- expect(trackZeroPlan(spans[0], spans, spans[1].start - 0.1).incoming).toBe(null);- expect(trackZeroPlan(spans[0], spans, spans[1].start + 0.1).incoming).toBe(spans[1]);+ const cut = spans[1].start;+ expect(trackZeroPlan(spans[0], spans, cut - 2.1).incoming).toBe(null);+ expect(trackZeroPlan(spans[0], spans, cut - 0.1).incoming).toBe(spans[1]);});- test("pushes the outgoing clip in and settles the incoming one on a cross zoom", () => {+ test("fades the outgoing sound across the blend window", () => {+ const spans = spansOf(2, 4, [2]);+ const cut = spans[1].start;+ expect(trackZeroPlan(spans[0], spans, cut - 2).gain).toBeCloseTo(1, 5);+ expect(trackZeroPlan(spans[0], spans, cut - 1).gain).toBeCloseTo(0.5, 5);+ });++ test("pushes the outgoing clip in, holds the incoming one pushed, settles it after the cut", () => {const spans = spansOf(2, 4, [2]);spans[0].clip.transitionStyle = "crosszoom";- const mid = trackZeroPlan(spans[0], spans, spans[1].start + 1);+ const cut = spans[1].start;+ const mid = trackZeroPlan(spans[0], spans, cut - 1);expect(mid.masterZoom).toBeCloseTo(1 + (TRANSITION_ZOOM - 1) * 0.5, 5);- expect(mid.incZoom).toBeCloseTo(TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * 0.5, 5);+ expect(mid.incZoom).toBeCloseTo(TRANSITION_ZOOM, 5);+ // Past the cut the incoming clip is the master, settling over its head.+ const after = trackZeroPlan(spans[1], spans, cut + 1);+ expect(after.masterZoom).toBeCloseTo(TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * 0.5, 5);});test("veils a fade-in from black at the head of the timeline", () => {diff --git a/site/src/cut/lib/framePlan.ts b/site/src/cut/lib/framePlan.tsindex 7006caf4..a61a153b 100644--- a/site/src/cut/lib/framePlan.ts+++ b/site/src/cut/lib/framePlan.ts@@ -46,7 +46,9 @@ export function overlayTransitionFx(let gain = 1;const style = span.clip.transitionStyle ?? "crossfade";const prevStyle = prev?.clip.transitionStyle ?? "crossfade";- // Incoming side of the previous clip's transition: blend in.+ // Incoming side of the previous clip's transition: the clip blends in over+ // its own head — upper tracks composite through alpha, so the arrival is an+ // alpha ramp against whatever is beneath.if (prev && prev.transitionOut > 0) {const rel = t - span.start;if (rel < prev.transitionOut) {@@ -56,12 +58,14 @@ export function overlayTransitionFx(if (prevStyle === "crosszoom") zoom = TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * p;}}- // Outgoing side of this clip's own cross zoom: the picture pushes in while- // the incoming clip settles back (it stays opaque — the blend is the- // incoming clip's alpha).- if (next && span.transitionOut > 0 && t >= next.start && style === "crosszoom") {- const p = Math.min(1, (t - next.start) / span.transitionOut);- zoom = 1 + (TRANSITION_ZOOM - 1) * p;+ // Outgoing side of this clip's own cross zoom: the picture pushes in across+ // its last blend-window seconds, handing over at the cut.+ if (next && span.transitionOut > 0 && style === "crosszoom") {+ const from = span.start + span.len - span.transitionOut;+ if (t >= from) {+ const p = Math.min(1, (t - from) / span.transitionOut);+ zoom = 1 + (TRANSITION_ZOOM - 1) * p;+ }}// The clip's own entrance/exit animations. A transitioned joint owns its// edges: the transition plays there and the adjacent animation is held@@ -257,19 +261,30 @@ export function trackZeroPlan(master: ClipSpan, spans: ClipSpan[], t: number): Tlet masterZoom = 1;let incZoom = 1;let incoming: ClipSpan | null = null;- // Once the incoming footprint starts, blend it in over the master.- if (master.transitionOut > 0 && next && t >= next.start) {- p = Math.min(1, (t - next.start) / master.transitionOut);+ const rel = t - master.start;+ // The blend window is the master's last `transitionOut` seconds: the next+ // clip's held first frame arrives over the live tail, fully there at the+ // cut, where the next clip starts playing. Clips never intersect — the+ // window claims no layout.+ if (master.transitionOut > 0 && next && t >= next.start - master.transitionOut) {+ p = Math.min(1, (t - (next.start - master.transitionOut)) / master.transitionOut);incAlpha = p;incoming = next;if (style === "crosszoom") {- // The outgoing picture pushes in while the incoming one settles back.+ // The outgoing picture pushes in; the incoming one waits pushed in and+ // settles back over its own head once it starts (mirroring the export's+ // head ramp on the incoming segment).masterZoom = 1 + (TRANSITION_ZOOM - 1) * p;- incZoom = TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * p;+ incZoom = TRANSITION_ZOOM;+ }+ }+ // The incoming side of the previous clip's cross zoom: settle back to 1+ // over this clip's own head.+ if (prev && prev.transitionOut > 0 && (prev.clip.transitionStyle ?? "crossfade") === "crosszoom") {+ if (rel < prev.transitionOut) {+ masterZoom *= TRANSITION_ZOOM - (TRANSITION_ZOOM - 1) * Math.max(0, rel / prev.transitionOut);}}-- const rel = t - master.start;const abutPrev =!!prev &&!prev.clip.hidden &&@@ -310,7 +325,10 @@ export function trackZeroPlan(master: ClipSpan, spans: ClipSpan[], t: number): TincAlpha,incZoom,veil: anim.veil,- gain: anim.gain,+ // The outgoing sound leaves with the picture: it fades across the blend+ // window and the incoming clip enters clean at the cut, matching the+ // export's tail fade + hard join.+ gain: anim.gain * (1 - p),backdrop,upcoming: next && t < next.start && t >= next.start - PREROLL_LEAD_S ? next : null,};diff --git a/site/src/cut/lib/laneTracks.ts b/site/src/cut/lib/laneTracks.tsindex fa648bee..33c67ba2 100644--- a/site/src/cut/lib/laneTracks.ts+++ b/site/src/cut/lib/laneTracks.ts@@ -30,13 +30,13 @@import type React from "react";import { refFromAsset, startPointerRefDrag } from "./assetRef";import { startDrag } from "./drag";-import { track0Clips, clipLen, getClipSpans, overlayLayers, projectDuration, transitionOverlap, useEditor } from "./store";+import { track0Clips, clipLen, getClipSpans, moveOverlayGroup, overlayLaneOrder, overlayLayers, projectDuration, useEditor } from "./store";import type {AudioClip,MediaAsset,+ Overlay,Selection,SubtitleCue,- TextOverlay,VideoClip,} from "./types";@@ -44,14 +44,15 @@ type S = ReturnType<typeof useEditor.getState>;// A drag lane. "clip" is track 0, "overlayClip" a layer track —// distinct adapters, but both select as a plain video-clip selection.-export type LaneKind = "clip" | "audio" | "text" | "overlayClip" | "cue";+// "overlay" is the title lanes: every overlay element kind rides one adapter.+export type LaneKind = "clip" | "audio" | "overlay" | "overlayClip" | "cue";/** The Selection kind a lane maps to. Track-0 and layer video lanes both select* as `"clip"` — a video clip is a video clip whatever track it sits on. */const laneSelectionKind = (kind: LaneKind): NonNullable<Selection>["kind"] =>kind === "overlayClip" ? "clip" : kind;-/** Visual gutter between adjacent clips (iMovie); time math stays exact. */+/** Visual gutter between adjacent clips; time math stays exact. */export const CLIP_GAP = 4;/** Pull a dragged or resized edge to a logical time within this many px. */export const SNAP_PX = 6;@@ -94,10 +95,9 @@ interface LaneAdapter<T> {assetOf?(s: S, raw: T): MediaAsset | undefined;/** After a committed move (e.g. keep cues sorted). */onMoved?(): void;- /** Legal physical overlap (seconds) of `raw` into the same-lane item after- * it — a video cross-dissolve's declared width. Gestures treat overlap up- * to this as contact, not intrusion. Absent = footprints are solid. */- overlapInto?(raw: T, next: T): number;+ /** After a committed move, shift companions that ride along — a grouped+ * overlay's peers keep their relative timing. Same undo step. */+ afterMove?(raw: T, delta: number): void;}const speedOf = (c: { speed?: number }) => (c.speed && c.speed > 0 ? c.speed : 1);@@ -128,7 +128,6 @@ const clipAdapter: LaneAdapter<VideoClip> = {},assetOf: (s, c) => s.assets.find((x) => x.id === c.assetId),onMoved: () => useEditor.getState().sortClips(),- overlapInto: (c, next) => transitionOverlap(c, next),};const audioAdapter: LaneAdapter<AudioClip> = {@@ -153,7 +152,7 @@ const audioAdapter: LaneAdapter<AudioClip> = {assetOf: (s, a) => s.assets.find((x) => x.id === a.assetId),};-const textAdapter: LaneAdapter<TextOverlay> = {+const textAdapter: LaneAdapter<Overlay> = {minLen: 0.2,multiLane: true,raws: (s) => s.overlays,@@ -165,6 +164,7 @@ const textAdapter: LaneAdapter<TextOverlay> = {leftFloor: () => 0,maxLen: () => Infinity,lanePatch: (o, lane) => ({ id: o.id, patch: { lane } }),+ afterMove: (o, delta) => moveOverlayGroup(o, delta),};const overlayClipAdapter: LaneAdapter<VideoClip> = {@@ -188,7 +188,6 @@ const overlayClipAdapter: LaneAdapter<VideoClip> = {maxLen: (s, c) =>((s.assets.find((x) => x.id === c.assetId)?.duration ?? c.out) - c.in) / speedOf(c),assetOf: (s, c) => s.assets.find((x) => x.id === c.assetId),- overlapInto: (c, next) => transitionOverlap(c, next),};const cueAdapter: LaneAdapter<SubtitleCue> = {@@ -216,13 +215,13 @@ const cueAdapter: LaneAdapter<SubtitleCue> = {onMoved: () => useEditor.getState().sortCues(),};-type LaneRaw = VideoClip | AudioClip | TextOverlay | SubtitleCue;+type LaneRaw = VideoClip | AudioClip | Overlay | SubtitleCue;// The generic parameter is erased at the registry boundary; each gesture only// feeds an adapter values that came out of that same adapter, so this is safe.const ADAPTERS: Record<LaneKind, LaneAdapter<LaneRaw>> = {clip: clipAdapter as unknown as LaneAdapter<LaneRaw>,audio: audioAdapter as unknown as LaneAdapter<LaneRaw>,- text: textAdapter as unknown as LaneAdapter<LaneRaw>,+ overlay: textAdapter as unknown as LaneAdapter<LaneRaw>,overlayClip: overlayClipAdapter as unknown as LaneAdapter<LaneRaw>,cue: cueAdapter as unknown as LaneAdapter<LaneRaw>,};@@ -233,9 +232,9 @@ const ADAPTERS: Record<LaneKind, LaneAdapter<LaneRaw>> = {function snapTargets(s: S, kind: LaneKind, selfId: string): number[] {const pts = new Set<number>([0]);for (const sp of getClipSpans(s.clips, s.assets)) {- // The visible joint: a dissolved pair meets at the overlap midpoint (where- // the clip boxes are inset to), a hard cut at the footprint end.- pts.add(sp.start + sp.len - sp.transitionOut / 2);+ // The joint: every pair meets at the footprint end — a transition is a+ // blend at that cut, never an overlap.+ pts.add(sp.start + sp.len);}pts.add(projectDuration(s));pts.add(s.currentTime);@@ -300,7 +299,9 @@ function settleSnapBack() {export interface LaneDrag {kind: LaneKind;id: string;- targetRow: number; // hovered display row (one past the end = new track)+ /** Hovered display row. One past the end opens a new row below; -1 opens+ * one above the top, for a stack whose order is z-order. */+ targetRow: number;ghostX: number; // ghost left in px — follows the pointerghostY: number; // ghost vertical offset in px from its resting row — follows the pointerslotStart: number; // resolved landing start, seconds@@ -315,6 +316,9 @@ export interface LaneMoveUI<V = unknown> {rowH: number;/** Display rows currently in use; targetRow may go one past to open a new track. */laneCount: number;+ /** Dragging above the top row opens a new one there. On for stacks where a+ * row's place is its z-order — the element rows — so the top is reachable. */+ topInsert?: boolean;/** The grabbed item's current display row. */homeRow: number;/** Timeline second the item's box is rendered at, when it differs from the@@ -391,12 +395,9 @@ export function startLaneMove<V = unknown>(.raws(s).filter((r) => ad.view(r).id !== id).map((r) => ({ raw: r, view: ad.view(r) }));- const usedLanes = [...new Set([...rest.map((x) => x.view.lane), self.lane])].sort(- (a, b) => a - b- );+ const usedLanes = laneOrder(kind, s, [...rest.map((x) => x.view.lane), self.lane]);const targets = snapTargets(s, kind, id);const tol = SNAP_PX / ui.pps;- const allow = (a: LaneRaw, b: LaneRaw) => ad.overlapInto?.(a, b) ?? 0;// Dragging a media-backed item can also hand its asset to a reference drop// zone (AI chat, the image/video creators).const asset = ad.assetOf?.(s, raw0);@@ -480,16 +481,21 @@ export function startLaneMove<V = unknown>(// Vertical drag retracks the item; one row past the end opens a new one.targetRow = ad.multiLane- ? Math.min(ui.laneCount, Math.max(0, ui.homeRow + Math.round(dy / ui.rowH)))+ ? Math.min(+ ui.laneCount,+ Math.max(ui.topInsert ? -1 : 0, ui.homeRow + Math.round(dy / ui.rowH))+ ): ui.homeRow;// Which lane to part/collide on: multi-lane rows are display indexes// into the compacted used-lane list (a row past the end is a brand-new// lane with no neighbors); single-lane kinds stay on their own lane —// their row number is not an index into that list.const lane = ad.multiLane- ? targetRow < usedLanes.length- ? usedLanes[targetRow]- : Infinity+ ? targetRow < 0+ ? -Infinity+ : targetRow < usedLanes.length+ ? usedLanes[targetRow]+ : Infinity: self.lane;// Snap whichever edge of the moving item lands nearest a logical time.@@ -529,14 +535,14 @@ export function startLaneMove<V = unknown>(? Math.max(0,...before.slice(0, -1).map((b) => b.view.start + b.view.len),- prev.view.start + prev.view.len - allow(prev.raw, raw0)+ prev.view.start + prev.view.len): 0;const clamped = Math.max(start, clampFloor);if (clamped !== start) guide = null;slotStart = clamped;const delta = after.length- ? Math.max(0, clamped + len - allow(raw0, after[0].raw) - after[0].view.start)+ ? Math.max(0, clamped + len - after[0].view.start): 0;const pushed = new Set(after.map((x) => x.view.id));ui.onSnap(guide);@@ -559,6 +565,7 @@ export function startLaneMove<V = unknown>(}if (!live || !moved) return;ad.apply([ad.movePatch(raw0, slotStart)]);+ ad.afterMove?.(raw0, slotStart - start0);commitRow(kind, id, targetRow);ad.onMoved?.();},@@ -569,16 +576,31 @@ export function startLaneMove<V = unknown>(* brand-new track after the current max, then lanes renumber to stay* contiguous so empty tracks collapse. The move's pointer-down already* checkpointed history, so the whole gesture is one undo step. */+/** The display rows a kind shows, top first — the same order the timeline+ * paints, so a row index means one thing to both. Overlay rows lead with the+ * effect rows; every other kind is plain lane order. */+function laneOrder(kind: LaneKind, s: S, lanes: number[]): number[] {+ if (kind === "overlay") return overlayLaneOrder(s.overlays);+ return [...new Set(lanes)].sort((a, b) => a - b);+}+function commitRow(kind: LaneKind, id: string, targetRow: number) {const s = useEditor.getState();const ad = ADAPTERS[kind];if (!ad.multiLane || !ad.lanePatch) return;const raws = ad.raws(s);const views = raws.map((r) => ad.view(r));- const used = [...new Set(views.map((v) => v.lane))].sort((a, b) => a - b);+ const used = laneOrder(kind, s, views.map((v) => v.lane));const cur = views.find((v) => v.id === id);if (!cur || targetRow === used.indexOf(cur.lane)) return;- const lane = targetRow < used.length ? used[targetRow] : (used[used.length - 1] ?? -1) + 1;+ // A row past either end opens a brand-new lane, clear of the ones in use;+ // the remap below renumbers everything back to 0..n-1.+ const lane =+ targetRow < 0+ ? Math.min(0, ...used) - 1+ : targetRow < used.length+ ? used[targetRow]+ : Math.max(-1, ...used) + 1;const moved = views.map((v) => (v.id === id ? lane : v.lane));const usedNext = [...new Set(moved)].sort((a, b) => a - b);const remap = new Map(usedNext.map((l, i) => [l, i]));@@ -616,7 +638,6 @@ export function startLaneTrim(s.pushHistory();const targets = snapTargets(s, kind, id);const tol = SNAP_PX / ui.pps;- const allow = (a: LaneRaw, b: LaneRaw) => ad.overlapInto?.(a, b) ?? 0;const sameLane = ad.raws(s).map((r) => ({ raw: r, view: ad.view(r) }))@@ -629,23 +650,12 @@ export function startLaneTrim(// edge grows freely into the open gap; past the neighbor it shoves the// run left, closing gap after gap until everything sits flush against 0 —// plus a media item's own floor: the edge can't reveal earlier than its- // first sample. The nearest leader may be a cross-dissolve partner whose- // footprint crosses this item's start: it yields its declared overlap- // before the edge starts pushing it.+ // first sample.const leaders = sameLane.filter((x) => x.view.start < start0 - 1e-3).sort((a, b) => a.view.start - b.view.start);- const last = leaders[leaders.length - 1];- const lastAllow = last ? allow(last.raw, raw0) : 0;- // Each leader's declared dissolve into the item after it (the last one's- // into the trimmed item itself): packing the run keeps those overlaps, so- // they come off the floor and stay in the re-lay.- const pairAllow = leaders.map((l, i) =>- i + 1 < leaders.length ? allow(l.raw, leaders[i + 1].raw) : lastAllow- );- const prevEnd =- leaders.reduce((m, l) => Math.max(m, l.view.start + l.view.len), 0) - lastAllow;- const runFloor = leaders.reduce((sum, l, i) => sum + l.view.len - pairAllow[i], 0);+ const prevEnd = leaders.reduce((m, l) => Math.max(m, l.view.start + l.view.len), 0);+ const runFloor = leaders.reduce((sum, l) => sum + l.view.len, 0);const floor = Math.max(runFloor, ad.leftFloor(raw0));const free = Math.max(prevEnd, ad.leftFloor(raw0));const moved = new Map<string, number>();@@ -675,11 +685,10 @@ export function startLaneTrim(}// Re-lay the leaders right-to-left from their resting spots: each one// slides only as far as the pushed edge (or the item it now abuts)- // forces it, so a retreating drag lets the run flow back — and a- // cross-dissolved pair keeps its overlap while it slides. Unmoved+ // forces it, so a retreating drag lets the run flow back. Unmoved// leaders get no patch (they'd re-render for nothing).const patches = [ad.trimLeftPatch(raw0, start)];- let limit = Math.max(start, runFloor) + lastAllow;+ let limit = Math.max(start, runFloor);for (let i = leaders.length - 1; i >= 0; i--) {const l = leaders[i];const end = Math.min(l.view.start + l.view.len, limit);@@ -690,8 +699,7 @@ export function startLaneTrim(if (Math.abs(ns - l.view.start) > 1e-9) moved.set(l.view.id, ns);else moved.delete(l.view.id);}- // The leader before this one may keep its dissolve overlap into it.- limit = ns + (i > 0 ? pairAllow[i - 1] : 0);+ limit = ns;}ad.apply(patches);},@@ -725,15 +733,11 @@ export function startLaneTrim(const ceil = self.start + ad.maxLen(s, raw0);// Items after this one, at their original spots: extending the edge past// the first of them pushes the whole run right (their gaps preserved);- // pulling back lets them return. A cross-dissolve into the first follower- // is contact, not intrusion — the edge only pushes once the overlap- // exceeds the declared transition, so grabbing a dissolved clip's handle- // never shoves its partner.+ // pulling back lets them return.const followers = sameLane.filter((x) => x.view.start >= self.start).sort((a, b) => a.view.start - b.view.start);const nextStart = followers.length ? followers[0].view.start : Infinity;- const nextAllow = followers.length ? allow(raw0, followers[0].raw) : 0;let lastDelta = 0;startDrag(e, {onMove: (dx, _dy, ev) => {@@ -756,7 +760,7 @@ export function startLaneTrim(// Followers respond only to growth up to the ceiling, so the overshoot// gives visually without shoving the run — and springing back needs no// re-lay, just as packed leaders hold at the floor on the left edge.- const delta = Math.max(0, Math.min(end, ceil) - nextAllow - nextStart);+ const delta = Math.max(0, Math.min(end, ceil) - nextStart);const run =delta === lastDelta? []diff --git a/site/src/cut/lib/store.test.ts b/site/src/cut/lib/store.test.tsindex 1564221d..1d85d128 100644--- a/site/src/cut/lib/store.test.ts+++ b/site/src/cut/lib/store.test.ts@@ -1,14 +1,15 @@import { beforeEach, describe, expect, test } from "bun:test";-import { clipLen, placeInRun, useEditor } from "./store";+import { groupRemap } from "@donkeycut/effects-kit";+import { adoptTransitionFields, clipLen, deriveTransitionFields, docOverlays, getClipSpans, liftClipLooks, moveOverlayGroup, overlayLaneOrder, normalizeElementLanes, placeInRun, projectDuration, separateOverlaps, serializeDoc, useEditor } from "./store";import { emptySubtitles } from "./types";import type { AudioClip, MediaAsset, SubtitleCue, TextOverlay, VideoClip } from "./types";/**- * The lane invariant: segments never overlap. Every placement and committed- * update — user drops, AI-chat tools, inspector edits — must land items on a- * free stretch of their lane (video per track, audio/title/cue per lane); the- * one sanctioned exception is a declared cross-dissolve on track 0, which- * physically overlaps its pair by the declared transition.+ * The lane invariant: segments never overlap, with no exceptions. Every+ * placement and committed update — user drops, AI-chat tools, inspector+ * edits — must land items on a free stretch of their lane (video per track,+ * audio/title/cue per lane). A transition is a render-time blend at the cut,+ * never a physical overlap.*/let n = 0;@@ -87,6 +88,7 @@ const videoLane = (track: number) =>beforeEach(() => {useEditor.setState({clips: [],+ transitions: [],audioClips: [],overlays: [],assets: [],@@ -96,6 +98,39 @@ beforeEach(() => {});});+describe("the document projection", () => {+ // Autosave tells an edit from a re-read by comparing this projection's+ // identity. A projection that rebuilt itself on every read would mark the+ // document dirty forever — and, since saving sets state, feed itself.+ test("re-reading an unchanged document hands back the same arrays", () => {+ useEditor.setState({+ overlays: [title({ kind: "text" }), title({ kind: "text", start: 3, end: 5 })],+ });+ const a = serializeDoc(s() as Parameters<typeof serializeDoc>[0]);+ const b = serializeDoc(s() as Parameters<typeof serializeDoc>[0]);+ expect(b.overlays).toBe(a.overlays!);+ expect(b.clips).toBe(a.clips!);+ expect(docOverlays(s().overlays)).toBe(a.overlays!);+ });++ test("an edit gives a new projection, and the stamp still comes off", () => {+ useEditor.setState({ overlays: [title({ kind: "text" })] });+ const before = serializeDoc(s() as Parameters<typeof serializeDoc>[0]);+ s().updateOverlay(s().overlays[0].id, { x: 0.2 });+ const after = serializeDoc(s() as Parameters<typeof serializeDoc>[0]);+ expect(after.overlays).not.toBe(before.overlays!);+ // Text elements still serialize without the loader's stamp.+ expect("kind" in after.overlays![0]).toBe(false);+ });++ test("a document with nothing to strip is passed straight through", () => {+ const overlays = [+ { id: "s1", kind: "shape", shape: "rect", start: 0, end: 2, x: 0.5, y: 0.5, w: 0.2, h: 0.2, fill: "#fff" },+ ] as unknown as Parameters<typeof docOverlays>[0];+ expect(docOverlays(overlays)).toBe(overlays);+ });+});+describe("video placement", () => {test("adding onto an occupied upper track slides to the next free slot", () => {const a = asset(2);@@ -199,16 +234,34 @@ describe("committed video updates (AI chat / inspector)", () => {expect(clipById(c2.id).start).toBeCloseTo(2);});- test("a declared cross-dissolve is contact, not intrusion", () => {+ test("separateOverlaps pulls an old physically-overlapped doc apart", () => {+ // A doc saved when a transition slid clips into each other: b starts+ // inside a, c rides 1s behind b across a gap.const a = vclip({ track: 0, start: 0, out: 4, transition: 1 });const b = vclip({ track: 0, start: 3, out: 4 });+ const c = vclip({ track: 0, start: 8, out: 2 });+ const other = vclip({ track: 1, start: 3, out: 2 });+ const out = separateOverlaps([a, b, c, other]);+ const by = (id: string) => out.find((x) => x.id === id)!;+ expect(by(b.id).start).toBeCloseTo(4); // pushed out to the cut+ expect(by(c.id).start).toBeCloseTo(9); // the run keeps its gap+ expect(by(other.id).start).toBeCloseTo(3); // other tracks untouched+ // A doc with nothing intruding passes through as the same array.+ const clean = [vclip({ start: 0, out: 2 }), vclip({ start: 2, out: 2 })];+ expect(separateOverlaps(clean)).toBe(clean);+ });++ test("clips never overlap, transition or not", () => {+ const a = vclip({ track: 0, start: 0, out: 4, transition: 1 });+ const b = vclip({ track: 0, start: 4, out: 4 });useEditor.setState({ clips: [a, b] });- // Re-committing the dissolved start must not evict the pair's overlap.- s().updateClip(b.id, { start: 3 });- expect(clipById(b.id).start).toBeCloseTo(3);- // Moving deeper than the declared overlap slides back to contact.+ // Re-committing the abutting start moves nothing.+ s().updateClip(b.id, { start: 4 });+ expect(clipById(b.id).start).toBeCloseTo(4);+ // A move into the leading clip settles back out to contact — a+ // transition is a blend at the cut, never a licence to intrude.s().updateClip(b.id, { start: 1 });- expect(clipById(b.id).start).toBeCloseTo(3);+ expect(clipById(b.id).start).toBeCloseTo(4);});});@@ -288,6 +341,130 @@ describe("title lanes", () => {s().updateOverlay(t2.id, { start: 0.5 });expect(overlayById(t2.id).start).toBeCloseTo(0.5);});++ describe("group moves", () => {+ test("peers ride along keeping their length and spacing", () => {+ const a = title({ start: 5, end: 7, groupId: "g" });+ const b = title({ start: 9, end: 13, lane: 1, groupId: "g" });+ useEditor.setState({ overlays: [a, b] });+ // The dragged element lands first; the group follows it.+ s().updateOverlaysTransient([{ id: a.id, patch: { start: 6, end: 8 } }]);+ moveOverlayGroup(a, 1);+ expect(overlayById(b.id).start).toBeCloseTo(10);+ expect(overlayById(b.id).end).toBeCloseTo(14); // 4s long, still+ });++ test("a shift past zero moves the whole group, never squashing one", () => {+ const a = title({ start: 5, end: 7, groupId: "g" });+ const b = title({ start: 1, end: 4, lane: 1, groupId: "g" });+ useEditor.setState({ overlays: [a, b] });+ s().updateOverlaysTransient([{ id: a.id, patch: { start: 0, end: 2 } }]);+ moveOverlayGroup(a, -5);+ // b would have gone to -4; the group lands 4 later instead.+ expect(overlayById(b.id).start).toBeCloseTo(0);+ expect(overlayById(b.id).end).toBeCloseTo(3); // 3s long, still+ expect(overlayById(a.id).start).toBeCloseTo(4);+ });++ test("unrelated elements are pushed clear of where the group lands", () => {+ const a = title({ start: 0, end: 2, groupId: "g" });+ const b = title({ start: 0, end: 2, lane: 1, groupId: "g" });+ const resident = title({ start: 4, end: 6, lane: 1 });+ const far = title({ start: 20, end: 21, lane: 1 });+ useEditor.setState({ overlays: [a, b, resident, far] });+ s().updateOverlaysTransient([{ id: a.id, patch: { start: 3.5, end: 5.5 } }]);+ moveOverlayGroup(a, 3.5);+ expect(overlayById(b.id).start).toBeCloseTo(3.5); // rigid+ expect(overlayById(resident.id).start).toBeCloseTo(5.5); // pushed clear+ expect(overlayById(far.id).start).toBeCloseTo(20); // untouched+ expectLaneSound(+ s()+ .overlays.filter((o) => (o.lane ?? 0) === 1)+ .map((o) => ({ start: o.start, end: o.end }))+ );+ });+ });++ describe("keyframes", () => {+ test("a key captures the pose and the track drops when the last one goes", () => {+ const t1 = title({ start: 2, end: 6, x: 0.4, rotation: 30, opacity: 0.5 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 1);+ const [k] = overlayById(t1.id).kf!;+ expect(k).toEqual({ t: 1, x: 0.4, y: 0.5, scale: 1, rotation: 30, opacity: 0.5 });+ s().removeOverlayKey(t1.id, 1);+ expect(overlayById(t1.id).kf).toBe(undefined);+ });++ test("a key past the element's end clamps into it, and re-keying replaces", () => {+ const t1 = title({ start: 0, end: 3 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 99, { x: 0.9 });+ expect(overlayById(t1.id).kf![0].t).toBeCloseTo(3);+ s().setOverlayKey(t1.id, 3, { x: 0.1 });+ expect(overlayById(t1.id).kf!.length).toBe(1);+ expect(overlayById(t1.id).kf![0].x).toBeCloseTo(0.1);+ });++ test("a picked key is what Delete takes, and the element stays", () => {+ const t1 = title({ start: 0, end: 4 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 1, { x: 0.1 });+ s().setOverlayKey(t1.id, 3, { x: 0.9 });+ s().selectOverlayKey(t1.id, 3);+ s().deleteSelection();+ expect(s().overlays.length).toBe(1); // the element is untouched+ expect(overlayById(t1.id).kf!.map((k) => k.t)).toEqual([1]);+ expect(s().selectedKey).toBe(null);+ // With no key picked, Delete goes back to taking the element.+ s().deleteSelection();+ expect(s().overlays.length).toBe(0);+ });++ test("retiming a key carries the pick with it", () => {+ const t1 = title({ start: 0, end: 4 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 1);+ s().selectOverlayKey(t1.id, 1);+ s().moveOverlayKey(t1.id, 1, 2.5, { transient: true });+ expect(s().selectedKey).toEqual({ overlayId: t1.id, t: 2.5 });+ s().deleteSelection();+ expect(overlayById(t1.id).kf).toBe(undefined);+ });++ test("selecting anything else drops the pick", () => {+ const t1 = title({ start: 0, end: 4 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 1);+ s().selectOverlayKey(t1.id, 1);+ s().select({ kind: "overlay", id: t1.id });+ expect(s().selectedKey).toBe(null);+ });++ test("clearing returns the element to its resting pose", () => {+ const t1 = title({ start: 0, end: 4 });+ useEditor.setState({ overlays: [t1] });+ s().setOverlayKey(t1.id, 0, { x: 0.1 });+ s().setOverlayKey(t1.id, 2, { x: 0.9 });+ expect(overlayById(t1.id).kf!.length).toBe(2);+ s().clearOverlayKeys(t1.id);+ expect(overlayById(t1.id).kf).toBe(undefined);+ expect(overlayById(t1.id).x).toBeCloseTo(0.5); // never moved the element itself+ });+ });++ test("copies get their own group, and members copied together stay together", () => {+ let seq = 0;+ const remap = groupRemap(() => `g${++seq}`);+ const a = title({ groupId: "g" });+ const b = title({ groupId: "g" });+ const loner = title({});+ expect(remap(a).groupId).toBe(remap(b).groupId!);+ expect(remap(a).groupId).not.toBe("g");+ expect(remap(loner).groupId).toBe(undefined);+ // A second operation is a second group.+ expect(groupRemap(() => `g${++seq}`)(a).groupId).not.toBe(remap(a).groupId!);+ });});describe("subtitle cues", () => {@@ -347,36 +524,82 @@ describe("delete ripple and gaps", () => {expect(clipById(layer.id).start).toBeCloseTo(1);});- test("removeGap closes the gap on its own track only", () => {+ test("shortening the project pulls the playhead back to the new end", () => {+ // The playhead placed past the end stretched the timeline's scroll area+ // into empty space, because it is positioned with a transform.+ const keep = vclip({ track: 0, start: 0, out: 4 });+ const far = vclip({ track: 0, start: 30, out: 4 });+ useEditor.setState({ clips: [keep, far] });+ s().seek(32);+ expect(s().currentTime).toBeCloseTo(32);+ s().select({ kind: "clip", id: far.id });+ s().deleteSelection();+ expect(s().currentTime).toBeCloseTo(projectDuration(s()));+ expect(s().currentTime).toBeLessThanOrEqual(4);+ });++ test("an overlay left standing keeps the playhead reachable", () => {+ const clip = vclip({ track: 0, start: 0, out: 2 });+ const late = title({ start: 6, end: 9 });+ useEditor.setState({ clips: [clip], overlays: [late], audioClips: [] });+ s().seek(8);+ expect(s().currentTime).toBeCloseTo(8);+ });++ test("removeLaneGap closes the gap on its own track only", () => {const b = vclip({ track: 0, start: 2, out: 2 });const layer = vclip({ track: 1, start: 2.5, out: 2 });const au = aclip({ start: 3, out: 2 });useEditor.setState({ clips: [b, layer], audioClips: [au] });- s().removeGap(0, 1);+ s().removeLaneGap({ kind: "video", index: 0 }, 1);expect(clipById(b.id).start).toBeCloseTo(0);expect(clipById(layer.id).start).toBeCloseTo(2.5);expect(audioById(au.id).start).toBeCloseTo(3);});- test("removeGap between clips on an upper track slides only that track", () => {+ test("removeLaneGap between clips on an upper track slides only that track", () => {const base = vclip({ track: 0, start: 0, out: 2 });const l1 = vclip({ track: 1, start: 0, out: 1 });const l2 = vclip({ track: 1, start: 3, out: 1 });useEditor.setState({ clips: [base, l1, l2] });- s().removeGap(1, 2);+ s().removeLaneGap({ kind: "video", index: 1 }, 2);expect(clipById(l2.id).start).toBeCloseTo(1);expect(clipById(base.id).start).toBeCloseTo(0);});- test("removeGap outside a gap is a no-op", () => {+ test("removeLaneGap outside a gap is a no-op", () => {const a = vclip({ track: 0, start: 0, out: 2 });const b = vclip({ track: 0, start: 3, out: 2 });useEditor.setState({ clips: [a, b] });- s().removeGap(0, 1); // on a clip- s().removeGap(0, 6); // past the end+ s().removeLaneGap({ kind: "video", index: 0 }, 1); // on a clip+ s().removeLaneGap({ kind: "video", index: 0 }, 6); // past the endexpect(clipById(a.id).start).toBeCloseTo(0);expect(clipById(b.id).start).toBeCloseTo(3);});++ test("removeLaneGap closes an audio row without moving its neighbours", () => {+ const keep = aclip({ start: 0, out: 1 });+ const late = aclip({ start: 3, out: 1 });+ const other = aclip({ start: 3, out: 1, lane: 1 });+ const vid = vclip({ track: 0, start: 3, out: 1 });+ useEditor.setState({ clips: [vid], audioClips: [keep, late, other] });+ s().removeLaneGap({ kind: "audio", index: 0 }, 2);+ expect(audioById(late.id).start).toBeCloseTo(1);+ expect(audioById(other.id).start).toBeCloseTo(3);+ expect(clipById(vid.id).start).toBeCloseTo(3);+ });++ test("removeLaneGap slides a title row and keeps each length", () => {+ const byId = (id: string) => s().overlays.find((o) => o.id === id)!;+ const first = title({ start: 0, end: 1 });+ const late = title({ start: 4, end: 6 });+ const other = title({ start: 4, end: 6, lane: 1 });+ useEditor.setState({ clips: [], overlays: [first, late, other] });+ s().removeLaneGap({ kind: "overlay", index: 0 }, 2);+ expect(byId(late.id).start).toBeCloseTo(1);+ expect(byId(late.id).end).toBeCloseTo(3);+ expect(byId(other.id).start).toBeCloseTo(4);+ });});describe("spine grounding", () => {@@ -405,7 +628,7 @@ describe("spine grounding", () => {});describe("upper-track transitions", () => {- test("setClipTransition on an upper track pulls the pair into overlap contact", () => {+ test("setClipTransition on an upper track moves nothing", () => {const av = asset(4);const bv = asset(4);const spine = vclip({ track: 0, start: 0, out: 4 });@@ -414,113 +637,161 @@ describe("upper-track transitions", () => {useEditor.setState({ assets: [av, bv], clips: [spine, a, b] });s().setClipTransition(a.id, 1);expect(clipById(a.id).transition).toBeCloseTo(1);- expect(clipById(b.id).start).toBeCloseTo(3); // slid into the dissolve- expect(clipById(spine.id).start).toBeCloseTo(0); // track 0 untouched+ expect(clipById(b.id).start).toBeCloseTo(4); // layout untouched+ expect(clipById(spine.id).start).toBeCloseTo(0);+ // The blend is live at the cut the pair already makes.+ const spans = getClipSpans(s().clips, s().assets, 1);+ expect(spans[0].transitionOut).toBeCloseTo(1);});- test("setClipTransition slides only its own track's run", () => {+ test("a transition on a gapped pair stays dormant until they touch", () => {const av = asset(4);- const spine1 = vclip({ track: 0, start: 0, out: 4 });- const spine2 = vclip({ track: 0, start: 4, out: 4 });+ const spine = vclip({ track: 0, start: 0, out: 4, assetId: av.id });const a = vclip({ track: 1, start: 0, out: 4, assetId: av.id });- const b = vclip({ track: 1, start: 4, out: 4, assetId: av.id });- useEditor.setState({ assets: [av], clips: [spine1, spine2, a, b] });+ const b = vclip({ track: 1, start: 6, out: 4, assetId: av.id });+ useEditor.setState({ assets: [av], clips: [spine, a, b] });s().setClipTransition(a.id, 1);- expect(clipById(b.id).start).toBeCloseTo(3);- expect(clipById(spine2.id).start).toBeCloseTo(4);+ expect(clipById(b.id).start).toBeCloseTo(6); // no gap-closing, no motion+ expect(getClipSpans(s().clips, s().assets, 1)[0].transitionOut).toBe(0);+ s().updateClip(b.id, { start: 4 });+ expect(getClipSpans(s().clips, s().assets, 1)[0].transitionOut).toBeCloseTo(1);});- test("splitting a layer clip clears the left half's transition", () => {+ test("splitting a layer clip leaves the tail's transition with the right half", () => {const av = asset(8);- const spine = vclip({ track: 0, start: 0, out: 8 });- const a = vclip({ track: 1, start: 0, out: 8, transition: 1, assetId: av.id });- useEditor.setState({- assets: [av],- clips: [spine, a],- selection: { kind: "clip", id: a.id },- currentTime: 4,- });+ const spine = vclip({ track: 0, start: 0, out: 12 });+ const a = vclip({ track: 1, start: 0, out: 8, assetId: av.id });+ const c = vclip({ track: 1, start: 8, out: 4, assetId: av.id });+ useEditor.setState({ assets: [av], clips: [spine, a, c] });+ s().setClipTransition(a.id, 1);+ useEditor.setState({ selection: { kind: "clip", id: a.id }, currentTime: 4 });s().splitAtPlayhead();- const halves = s().clips.filter((c) => c.track === 1);+ const halves = s().clips.filter((x) => x.track === 1 && x.id !== c.id);expect(halves.length).toBe(2);- const left = halves.find((c) => c.start === 0)!;- const right = halves.find((c) => c.start === 4)!;+ const left = halves.find((x) => x.start === 0)!;+ const right = halves.find((x) => x.start === 4)!;+ // The bar sits at the original tail cut, so the right half plays it and+ // the new mid-footage cut stays plain.expect(left.transition).toBeUndefined();expect(right.transition).toBe(1);});});-describe("transitioned joints own their edges", () => {- test("setting a transition clears the animations adjacent to its joint", () => {+describe("bars and clip edges", () => {+ test("a transition and the far-edge animations live together", () => {const av = asset(4);- const a = vclip({- track: 0,- start: 0,- out: 4,- assetId: av.id,- animIn: { style: "fade", seconds: 0.5 },- animOut: { style: "slideleft", seconds: 0.5 },- });- const b = vclip({- track: 0,- start: 4,- out: 4,- assetId: av.id,- animIn: { style: "pop", seconds: 0.5 },- animOut: { style: "fade", seconds: 0.5 },- });+ const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });+ const b = vclip({ track: 0, start: 4, out: 4, assetId: av.id });useEditor.setState({ assets: [av], clips: [a, b] });+ s().setClipAnim(a.id, "in", { style: "fade", seconds: 0.5 });+ s().setClipAnim(b.id, "out", { style: "fade", seconds: 0.5 });s().setClipTransition(a.id, 0.8, "pushdown");- // The joint's own edges clear; the far edges stay.- expect(clipById(a.id).animOut).toBeUndefined();- expect(clipById(b.id).animIn).toBeUndefined();+ expect(clipById(a.id).transition).toBeCloseTo(0.8);expect(clipById(a.id).animIn).toEqual({ style: "fade", seconds: 0.5 });expect(clipById(b.id).animOut).toEqual({ style: "fade", seconds: 0.5 });+ // The joint has no open edges, so nothing else can play there.+ expect(clipById(a.id).animOut).toBeUndefined();+ expect(clipById(b.id).animIn).toBeUndefined();});test("clearing a transition leaves the neighbors' animations alone", () => {const av = asset(4);- const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id, transition: 0.8 });- const b = vclip({- track: 0,- start: 3.2,- out: 4,- assetId: av.id,- animOut: { style: "fade", seconds: 0.5 },- });+ const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });+ const b = vclip({ track: 0, start: 4, out: 4, assetId: av.id });useEditor.setState({ assets: [av], clips: [a, b] });+ s().setClipAnim(b.id, "out", { style: "fade", seconds: 0.5 });+ s().setClipTransition(a.id, 0.8);s().setClipTransition(a.id, 0);expect(clipById(a.id).transition).toBeUndefined();expect(clipById(b.id).animOut).toEqual({ style: "fade", seconds: 0.5 });});-});-describe("last pick wins per edge", () => {- test("an entrance animation on the following clip replaces the joint's transition", () => {+ test("an entrance picked at a joint parks its bar; the transition keeps playing", () => {const av = asset(4);const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });const b = vclip({ track: 0, start: 4, out: 4, assetId: av.id });useEditor.setState({ assets: [av], clips: [a, b] });s().setClipTransition(a.id, 0.8, "pushdown");- expect(clipById(b.id).start).toBeCloseTo(3.2);+ expect(clipById(b.id).start).toBeCloseTo(4); // layout never movess().setClipAnim(b.id, "in", { style: "slideleft", seconds: 0.5 });- expect(clipById(a.id).transition).toBeUndefined();- expect(clipById(b.id).start).toBeCloseTo(4); // back to a hard cut- expect(clipById(b.id).animIn).toEqual({ style: "slideleft", seconds: 0.5 });+ // b's head is a cut, so there is no entrance to make: the bar sits on the+ // row inert and the joint's transition plays on.+ expect(clipById(a.id).transition).toBeCloseTo(0.8);+ expect(clipById(b.id).animIn).toBeUndefined();+ expect(s().transitions.length).toBe(2);});- test("an exit animation on the leading clip replaces the joint's transition", () => {+ test("an exit picked at a joint retunes the joint's bar", () => {const av = asset(4);const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });const b = vclip({ track: 0, start: 4, out: 4, assetId: av.id });useEditor.setState({ assets: [av], clips: [a, b] });s().setClipTransition(a.id, 0.8, "circleopen");s().setClipAnim(a.id, "out", { style: "fade", seconds: 0.4 });- expect(clipById(a.id).transition).toBeUndefined();- expect(clipById(a.id).animOut).toEqual({ style: "fade", seconds: 0.4 });+ // The clip's tail IS the joint, so the pick lands on the same bar: it+ // becomes a 0.4s crossfade there, and no second bar appears.+ expect(clipById(a.id).transition).toBeCloseTo(0.4);+ expect(clipById(a.id).transitionStyle).toBeUndefined();+ expect(clipById(a.id).animOut).toBeUndefined();+ expect(s().transitions.length).toBe(1);expect(clipById(b.id).start).toBeCloseTo(4);});+ test("a pre-bar doc's clip fields become bars once, and derive back unchanged", () => {+ const av = asset(4);+ const a = vclip({+ track: 0,+ start: 0,+ out: 4,+ assetId: av.id,+ transition: 0.8,+ transitionStyle: "pushleft",+ animIn: { style: "fade", seconds: 0.5 },+ });+ const b = vclip({+ track: 0,+ start: 4,+ out: 4,+ assetId: av.id,+ animOut: { style: "zoom", seconds: 0.6 },+ });+ const bars = adoptTransitionFields([a, b], []);+ expect(bars.length).toBe(3);+ const derived = deriveTransitionFields([a, b], bars);+ const da = derived.find((c) => c.id === a.id)!;+ const db = derived.find((c) => c.id === b.id)!;+ expect(da.transition).toBeCloseTo(0.8);+ expect(da.transitionStyle).toBe("pushleft");+ expect(da.animIn).toEqual({ style: "fade", seconds: 0.5 });+ expect(db.animOut).toEqual({ style: "zoom", seconds: 0.6 });+ // A second load adopts nothing new: every field already has its bar.+ expect(adoptTransitionFields(derived, bars)).toBe(bars);+ });++ test("a bar is not tied to a clip: the pair separating turns its cut into an exit, and moving further parks it", () => {+ const av = asset(4);+ const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });+ const b = vclip({ track: 0, start: 4, out: 4, assetId: av.id });+ useEditor.setState({ assets: [av], clips: [a, b] });+ s().setClipTransition(a.id, 0.8, "pushdown");+ // The pair separates: the bar stays put, still ends on a's tail — now an+ // open edge — so it plays as a's exit.+ s().updateClipTransient(b.id, { start: 6 });+ expect(clipById(a.id).transition).toBeUndefined();+ expect(clipById(a.id).animOut).toEqual({ style: "slidedown", seconds: 0.8 });+ expect(s().transitions.length).toBe(1);+ // Back together, the cut outranks the exit and the transition returns.+ s().updateClipTransient(b.id, { start: 4 });+ expect(clipById(a.id).transition).toBeCloseTo(0.8);+ expect(clipById(a.id).animOut).toBeUndefined();+ // Both clips gone, the bar survives, aligned with nothing.+ useEditor.setState({ selection: null, multiSelection: [] });+ s().updateClipTransient(a.id, { start: 20 });+ s().updateClipTransient(b.id, { start: 40 });+ expect(s().transitions.length).toBe(1);+ expect(clipById(a.id).transition).toBeUndefined();+ });+test("an animation on a far edge leaves an unrelated transition alone", () => {const av = asset(4);const a = vclip({ track: 0, start: 0, out: 4, assetId: av.id });@@ -598,3 +869,73 @@ describe("generated-scene placement (placeInRun)", () => {expect(audioById(id).start).toBeCloseTo(4);});});++describe("overlay row order", () => {+ const fx = (id: string, start: number, end: number, lane = 0) =>+ ({ id, kind: "effect", effect: "blur", start, end, x: 0.5, y: 0.5, lane }) as unknown as TextOverlay;++ test("rows read in lane order, so a dragged element stays where it was put", () => {+ expect(overlayLaneOrder([title({ lane: 2 }), fx("e1", 0, 2, 0), title({ lane: 1 })])).toEqual([+ 0, 1, 2,+ ]);+ // An effect dragged below a title keeps that row: nothing about a kind+ // reorders the band.+ expect(overlayLaneOrder([title({ lane: 0 }), fx("e2", 0, 2, 1)])).toEqual([0, 1]);+ });++ test("loading repairs a shared row and leaves a sound one alone", () => {+ // One shared row: the effect lifts off it and the rows renumber to how+ // they show — the effect on top, the title under it.+ const out = normalizeElementLanes([title({ lane: 0 }), fx("e1", 0, 2)]);+ expect(out.map((o) => o.lane)).toEqual([1, 0]);+ // Two effects overlapping in time cannot share a row, so they take two.+ const pair = normalizeElementLanes([title({ lane: 0 }), fx("e3", 0, 2), fx("e4", 1, 3)]);+ expect(pair.map((o) => o.lane)).toEqual([2, 0, 1]);+ // An effect dragged below a title and saved comes back below it: no+ // shared row, so the load has nothing to repair.+ const dragged = [title({ lane: 0 }), fx("e2", 0, 2, 1)];+ expect(normalizeElementLanes(dragged)).toBe(dragged);+ });++ test("a saved clip look opens as an effect covering that clip", () => {+ const a = asset(4);+ const c1 = vclip({ start: 0, out: 4, assetId: a.id, look: "noir" });+ const c2 = vclip({ start: 4, out: 4, assetId: a.id });+ const spans = [+ { clip: c1, start: 0, len: 4 },+ { clip: c2, start: 4, len: 4 },+ ];+ const out = liftClipLooks([c1, c2], [title({ lane: 0 })], spans)!;+ // The grade covers exactly the clip it graded, on the row above the title.+ const fx = out.overlays.find((o) => o.kind === "effect")!;+ expect([fx.effect, fx.start, fx.end, fx.lane]).toEqual(["noir", 0, 4, 0]);+ expect(out.overlays.find((o) => (o.kind ?? "text") === "text")!.lane).toBe(1);+ // …and the clip no longer carries it, so nothing grades twice.+ expect(out.clips[0].look).toBeUndefined();+ // A doc with no looks is left alone.+ expect(liftClipLooks([c2], [], spans)).toBe(null);+ });++ test("an added effect opens the top row, and later ones join it", () => {+ useEditor.setState({ overlays: [title({ lane: 0 })] });+ s().addEffect("blur");+ const held = useEditor.getState().overlays;+ expect(held.find((o) => o.kind === "effect")!.lane).toBe(0);+ expect(held.find((o) => (o.kind ?? "text") === "text")!.lane).toBe(1); // pushed down a row+ s().addEffect("grain");+ const effectLanes = useEditor+ .getState()+ .overlays.filter((o) => o.kind === "effect")+ .map((o) => o.lane);+ expect(effectLanes).toEqual([0, 0]);+ });++ test("a title added onto an effects-only project takes the row below", () => {+ useEditor.setState({ overlays: [] });+ s().addEffect("blur");+ s().addOverlay();+ const text = useEditor.getState().overlays.find((o) => (o.kind ?? "text") === "text")!;+ expect(text.lane).toBe(1);+ expect(overlayLaneOrder(useEditor.getState().overlays)).toEqual([0, 1]);+ });+});diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex ec7ff39f..481d7eb0 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -1,5 +1,14 @@"use client";+import {+ groupRemap,+ KEY_EPSILON,+ keyAt,+ removeKeyAt,+ upsertKey,+ type EffectId,+ type OverlayKey,+} from "@donkeycut/effects-kit";import { create } from "zustand";import type {Aspect,@@ -7,11 +16,14 @@ import type {ClipAnim,ClipSpan,LibraryTemplate,- LookStyle,MediaAsset,+ Overlay,+ OverlayKind,+ OverlayPatch,ProjectDoc,RenderRecord,Selection,+ ShapeKind,ShareFeatures,StoredAsset,SubtitleCue,@@ -21,7 +33,7 @@ import type {TemplateLayer,TemplateMedia,TemplateSaveInput,- TextOverlay,+ TimelineTransition,TransitionStyle,VideoClip,} from "./types";@@ -42,7 +54,7 @@ import { alignCues } from "./cueAlign";import { useGenNotify } from "./genNotify";import { engineTranscribeSamples } from "./localStt";import { trackLocale } from "./subtitles";-import { ANIM_STYLE_IDS, emptySubtitles, IMAGE_CLIP_SECONDS, LOOK_IDS, MAX_SUBTITLE_LANES, mediaUrl, migrateLegacyTransitions, normalizeAspect, SPEED_FLOOR, SPEED_MIN, TRANSITION_MAX } from "./types";+import { ANIM_STYLE_IDS, animStyleOfTransition, emptySubtitles, frameOf, IMAGE_CLIP_SECONDS, isEffectOverlay, isStickerOverlay, MAX_SUBTITLE_LANES, mediaUrl, migrateLegacyTransitions, normalizeAspect, overlayAnimStyle, SPEED_FLOOR, SPEED_MIN, stampOverlayKinds, stripDefaultOverlayKinds, TRANSITION_MAX, TRANSITION_STYLE_IDS, transitionStyleOfAnim } from "./types";import { readTextStyle } from "./textStyle";import { loadUiState, saveUiState, type ProjectUiState } from "./uiState";import { captureTimelineFrames } from "./visualFrames";@@ -97,8 +109,9 @@ export const TIMELINE_H_MAX = 600;interface DocSnapshot {clips: VideoClip[];+ transitions: TimelineTransition[];audioClips: AudioClip[];- overlays: TextOverlay[];+ overlays: Overlay[];subtitles: SubtitlesBlock;}@@ -131,8 +144,13 @@ export interface EditorState {* carries the transition sequence, higher tracks composite in front. A* clip's `track` field is the only thing that places it. */clips: VideoClip[];+ /** Transition bars: free objects on the transitions row, owned by no clip.+ * A bar plays when it lines up with a cut or an open edge (resolveTransitions)+ * and sits inert anywhere else; the per-clip transition/anim fields are+ * caches derived from these in the set wrapper. */+ transitions: TimelineTransition[];audioClips: AudioClip[];- overlays: TextOverlay[];+ overlays: Overlay[];/** Output frame ratio ("W:H", short side 1080), persisted per project. */aspect: Aspect;/** The aspect was chosen deliberately (picker, set_aspect, or saved in the@@ -146,6 +164,11 @@ export interface EditorState {/** Everything selected, including `selection` (the primary that drives the* inspector). Bulk actions — delete, copy — act on this whole set. */multiSelection: Selection[];+ /** The keyframe picked on an element's timeline bar, if any. It rides+ * alongside the element selection rather than inside it: an element is still+ * what the inspector edits, but Delete takes the key. Any other selection+ * clears it. */+ selectedKey: { overlayId: string; t: number } | null;currentTime: number;playing: boolean;/** While playing a scoped effect preview, the time playback auto-pauses at;@@ -154,7 +177,7 @@ export interface EditorState {pxPerSec: number;/** Timeline panel height in px (drag the panel's top border to change). */timelineH: number;- /** Timeline time under the mouse (iMovie skimmer); null when off the timeline. */+ /** Timeline time under the mouse (the skimmer); null when off the timeline. */skimTime: number | null;/** TikTok publishing metadata (caption, hashtags, sound title). */publish: { caption: string; tags: string; soundTitle: string; handle: string };@@ -247,6 +270,17 @@ export interface EditorState {* undo like any other edit. */releaseGenClips: () => void;addOverlay: () => void;+ /** Add a vector shape element on the title lanes at the playhead. */+ /** Place a shape element; a drop passes where it landed. */+ addShape: (shape: ShapeKind, aim?: { at?: number; lane?: number }) => void;+ /** Add a sticker element (a project image asset, a Lottie animation, or an+ * image asset) on the title lanes at the playhead. */+ /** Place a sticker element. A drop passes `at`/`lane` to land where it was+ * released; without them it goes to the playhead on the home row. */+ addSticker: (init: { assetId: string; lottie?: boolean; at?: number; lane?: number }) => void;+ /** Add a time-ranged visual effect element at the playhead. */+ /** Place an effect element; a drop passes where it landed. */+ addEffect: (effect: EffectId, aim?: { at?: number; lane?: number }) => void;updateClip: (id: string, patch: Partial<VideoClip>) => void;/** Set a clip's playback rate (0.25–4). A longer footprint pushes the* following clips right by the overflow; a shorter one opens a gap. */@@ -256,13 +290,21 @@ export interface EditorState {* one opens a gap, and a live dissolve keeps its overlap. */setClipTrim: (id: string, nextIn: number, nextOut: number) => void;/** Set the transition into the next clip (seconds; 0 clears it), optionally- * changing its style; omitting the style keeps the clip's current one. */+ * changing its style; omitting the style keeps the current one. Upserts the+ * bar playing the clip's tail — the clip fields follow by derivation. */setClipTransition: (id: string, seconds: number, style?: TransitionStyle) => void;- /** Set (or clear with null) a clip's own entrance/exit animation. Never- * moves the layout — an animation belongs to one clip's edge. */+ /** Set (or clear with null) a clip's own entrance/exit animation. Upserts+ * the bar on that edge; never moves the layout. */setClipAnim: (id: string, which: "in" | "out", anim: ClipAnim | null) => void;+ /** Put a new transition bar on the row, wherever `start` says. Returns its+ * id. It plays only where it lines up with a cut or an open edge. */+ addTransition: (bar: { start: number; seconds: number; style: TransitionStyle }) => string;+ /** Move, retime or restyle a bar (one undo entry). */+ updateTransition: (id: string, patch: Partial<Omit<TimelineTransition, "id">>) => void;+ /** The same, with no undo checkpoint — for mid-gesture updates. */+ updateTransitionTransient: (id: string, patch: Partial<Omit<TimelineTransition, "id">>) => void;+ removeTransition: (id: string) => void;/** Set (or clear with null) a clip's preset filter look; amount 0..1. */- setClipLook: (id: string, style: LookStyle | null, amount?: number) => void;updateAudio: (id: string, patch: Partial<AudioClip>) => void;/** Hide or show every clip on one video track, in one undo step. Showing a* track also shows its individually hidden clips. */@@ -273,12 +315,39 @@ export interface EditorState {setAudioLaneHidden: (lane: number, hidden: boolean) => void;/** Hide or show every title on one title lane, in one undo step. */setTextLaneHidden: (lane: number, hidden: boolean) => void;- updateOverlay: (id: string, patch: Partial<TextOverlay>) => void;+ updateOverlay: (id: string, patch: OverlayPatch) => void;/** Live-drag updates that should not create undo entries. */- updateOverlayTransient: (id: string, patch: Partial<TextOverlay>) => void;+ updateOverlayTransient: (id: string, patch: OverlayPatch) => void;+ /** Keyframes. `tLocal` is seconds from the element's start; a key already+ * sitting there is replaced rather than doubled. Adding one captures the+ * element's pose at that moment, so the first key never moves anything.+ * `patch` (position, scale, rotation, opacity) edits the key in place —+ * that is how dragging a keyframed element in the preview records. */+ setOverlayKey: (+ id: string,+ tLocal: number,+ patch?: Partial<Omit<OverlayKey, "t">>,+ opts?: { transient?: boolean }+ ) => void;+ /** Delete one element outright — the clip panel taking an effect back off. */+ removeOverlay: (id: string) => void;+ removeOverlayKey: (id: string, tLocal: number) => void;+ /** Pick a keyframe on the timeline: the element becomes the selection and+ * the key rides along, so Delete removes the key rather than the element. */+ selectOverlayKey: (id: string, tLocal: number) => void;+ /** Retime a key, keeping its pose — dragging one along the timeline bar.+ * Dropped onto another key it replaces that one, same as setting a key+ * where one already sits. */+ moveOverlayKey: (+ id: string,+ fromT: number,+ toT: number,+ opts?: { transient?: boolean }+ ) => void;+ clearOverlayKeys: (id: string) => void;/** Patch several items in one commit — the lane coordinator's gestures part* and push whole lanes at a time (one bulk patcher per lane-track kind). */- updateOverlaysTransient: (patches: { id: string; patch: Partial<TextOverlay> }[]) => void;+ updateOverlaysTransient: (patches: { id: string; patch: OverlayPatch }[]) => void;updateAudiosTransient: (patches: { id: string; patch: Partial<AudioClip> }[]) => void;updateCuesTransient: (patches: { id: string; patch: Partial<SubtitleCue> }[]) => void;updateClipsTransient: (patches: { id: string; patch: Partial<VideoClip> }[]) => void;@@ -298,7 +367,7 @@ export interface EditorState {* Inserting a track renumbers the ones above it; dropping onto track 0 lands* free-positioned at the drop time. Owns its own history. */dropVideoClip: (id: string, place: VideoTrackPlacement, start: number) => void;- /** iMovie "Detach Audio": lift the selected clip's sound onto the+ /** "Detach Audio": lift the selected clip's sound onto the* soundtrack track (and mute the clip) so it can be cut independently. */detachAudio: () => void;/** Split at the given time, or the playhead when omitted. */@@ -354,12 +423,12 @@ export interface EditorState {* everything after it — clips, titles, captions, soundtrack — slides left* in sync (see exciseRange). With upper video layers present the slide* would shear them against track 0, so the delete leaves the gap; closing- * it is `removeGap`. Deletes on every other track remove just that item. */+ * it is `removeLaneGap`. Deletes on every other track remove just that item. */deleteSelection: () => void;- /** Close the empty span on `track` containing `at`: that track's later- * clips slide left to shut the gap; every other track, the soundtrack,- * titles, and captions stay put. No-op when `at` isn't inside a gap. */- removeGap: (track: number, at: number) => void;+ /** Close the empty span on `lane` containing `at` — a video track, an audio+ * track, or a title track. Only that row's later items slide left; every+ * other row stays put. No-op when `at` isn't inside a gap. */+ removeLaneGap: (lane: LaneRef, at: number) => void;/** Timeline window [start, end) spanned by the current selection, or null if* nothing selectable is chosen. */selectionRange: () => { start: number; end: number } | null;@@ -378,6 +447,11 @@ export interface EditorState {/** Append a project asset to a template as one more part at its end. */addAssetToTemplate: (templateId: string, assetId: string) => void;select: (sel: Selection) => void;+ /** Group the multi-selected overlay elements (≥2): selecting any member+ * selects them all, and move/resize/rotate/timing act on the set. */+ groupSelectedOverlays: () => void;+ /** Dissolve a group; the members stay, ungrouped. */+ ungroupOverlays: (groupId: string) => void;/** ⌘/⇧-click: add the item to the selection (or remove it if already in),* making it the new primary. */toggleSelect: (sel: NonNullable<Selection>) => void;@@ -441,7 +515,7 @@ const genAudioIds = new Set<string>();type ClipboardItem =| { kind: "clip"; item: VideoClip }| { kind: "audio"; item: AudioClip }- | { kind: "text"; item: TextOverlay };+ | { kind: "overlay"; item: Overlay };let clipboard: ClipboardItem[] = [];/** Bumped whenever subtitle lanes renumber (a track removal). Async work that@@ -459,9 +533,8 @@ const touches = (patch: object, keys: readonly string[]) => keys.some((k) => k i* settle runs after a committed update lands, scoped to the item's own lane.* A move (start / track / lane) re-places the item at the first spot where it* intrudes into no resident; a resize (in / out / speed / end) keeps its start- * and pushes the following same-lane run right by the overflow. For video- * clips a declared cross-dissolve is contact, not intrusion — the pair may- * overlap by the declared transition, exactly as the drag gestures allow.+ * and pushes the following same-lane run right by the overflow. Video clips+ * never overlap — a transition is a render-time blend at the cut, not layout.* Writes are transient: the committed action that calls this owns the history* entry, so the patch and its settle undo as one step.*/@@ -478,9 +551,9 @@ function settleClipFootprint(id: string, patch: Partial<VideoClip>) {if (moved) {let at = clip.start;for (const c of others) {- const blockEnd = c.start + clipLen(c) - transitionOverlap(c, clip);+ const blockEnd = c.start + clipLen(c);if (blockEnd <= at + 1e-3) continue;- if (c.start + transitionOverlap(clip, c) >= at + len - 1e-3) break;+ if (c.start >= at + len - 1e-3) break;at = blockEnd;}if (Math.abs(at - clip.start) > 1e-9) st.updateClipTransient(id, { start: at });@@ -489,7 +562,7 @@ function settleClipFootprint(id: string, patch: Partial<VideoClip>) {}const next = others.find((c) => c.start >= clip.start - 1e-9);if (!next) return;- const delta = clip.start + len - transitionOverlap(clip, next) - next.start;+ const delta = clip.start + len - next.start;if (delta <= 1e-9) return;useEditor.setState((s) => ({clips: s.clips@@ -535,7 +608,7 @@ function settleAudioFootprint(id: string, patch: Partial<AudioClip>) {* resizes in place and pushes the run. Writes are transient: callers own the* history entry (exported for the AI's add_title, which patches inside the* add's own undo step; everything else comes through `updateOverlay`). */-export function applyOverlayPatchSettled(id: string, patch: Partial<TextOverlay>) {+export function applyOverlayPatchSettled(id: string, patch: OverlayPatch) {const st = useEditor.getState();const before = st.overlays.find((o) => o.id === id);if (!before) return;@@ -546,7 +619,7 @@ export function applyOverlayPatchSettled(id: string, patch: Partial<TextOverlay>settleOverlayFootprint(id, p);}-function settleOverlayFootprint(id: string, patch: Partial<TextOverlay>) {+function settleOverlayFootprint(id: string, patch: OverlayPatch) {const moved = touches(patch, ["start", "lane"]);if (!moved && !touches(patch, ["end"])) return;const st = useEditor.getState();@@ -579,32 +652,92 @@ function settleOverlayFootprint(id: string, patch: Partial<TextOverlay>) {}));}+/**+ * Shift a group's other members after one of them has been dragged, keeping+ * the set rigid: everyone moves by the same delta, so durations and the+ * spacing between members survive the move. A shift that would carry a member+ * before zero moves the whole group — the dragged element included — right by+ * the shortfall instead of squashing anyone. Unrelated elements the group+ * lands on are then pushed clear, so no lane ends up with two overlapping+ * overlays.+ *+ * Writes are transient: the caller's gesture already opened the undo step.+ */+export function moveOverlayGroup(anchor: Overlay, delta: number) {+ if (!anchor.groupId || Math.abs(delta) < 1e-9) return;+ const st = useEditor.getState();+ const members = st.overlays.filter((o) => o.groupId === anchor.groupId);+ if (members.length < 2) return;+ // `anchor` is the pre-drag element: it already sits at start + delta, while+ // the peers are still where they were, so both read their target off the+ // original start.+ const startOf = (o: Overlay) => (o.id === anchor.id ? anchor.start : o.start);+ const shortfall = Math.max(0, -Math.min(...members.map((o) => startOf(o) + delta)));+ const d = delta + shortfall;+ st.updateOverlaysTransient(+ members.map((o) => {+ const start = startOf(o) + d;+ return { id: o.id, patch: { start, end: start + (o.end - o.start) } };+ })+ );+ pushOverlaysClearOf(new Set(members.map((o) => o.id)));+}++/** Slide everything that is not in `ids` far enough right, lane by lane, that+ * nothing overlaps the moved set. Shifts only ever grow along a lane, so the+ * elements being pushed keep their own order and spacing. */+function pushOverlaysClearOf(ids: Set<string>) {+ const overlays = useEditor.getState().overlays;+ const moved = overlays.filter((o) => ids.has(o.id));+ const shifted = new Map<string, number>();+ for (const lane of new Set(moved.map((o) => o.lane ?? 0))) {+ const blocks = moved+ .filter((o) => (o.lane ?? 0) === lane)+ .map((o) => ({ start: o.start, end: o.end }));+ const others = overlays+ .filter((o) => !ids.has(o.id) && (o.lane ?? 0) === lane)+ .sort((a, b) => a.start - b.start);+ // Each element takes the first free spot at or after where it was, and+ // never before the one ahead of it — the same slide `nextFreeStart` gives+ // every other placement.+ let floor = -Infinity;+ for (const o of others) {+ const len = o.end - o.start;+ const start = nextFreeStart(blocks, Math.max(o.start, floor), len);+ if (start > o.start + 1e-6) shifted.set(o.id, start - o.start);+ floor = start + len;+ }+ }+ if (shifted.size === 0) return;+ useEditor.setState((s) => ({+ overlays: s.overlays.map((o) => {+ const by = shifted.get(o.id);+ return by ? { ...o, start: o.start + by, end: o.end + by } : o;+ }),+ }));+}+/** Resize a clip's footprint to `newLen` (a trim or speed change), keeping its- * own track sound: a live dissolve into the next clip stays a dissolve (the- * run follows the resize so the pair keeps its overlap); otherwise a longer+ * own track sound: a cut the clip transitions over stays a cut (the run+ * follows the resize so the pair keeps its contact); otherwise a longer* footprint pushes the run right by the overflow and a shorter one just opens* a gap. Everything is scoped to the clip's track — resizing a track-0 clip* never drags the composited layers (or vice versa), so each track's* annotations keep the timing they were placed at. One undo step. */function resizeClipFootprint(clip: VideoClip, patch: Partial<VideoClip>, newLen: number) {useEditor.getState().pushHistory();- useEditor.getState().updateClipTransient(clip.id, patch);const next = useEditor.getState().clips.filter((c) => c.id !== clip.id && c.track === clip.track && c.start >= clip.start).reduce<VideoClip | null>((m, c) => (!m || c.start < m.start ? c : m), null);+ // Whether the pair makes the cut this clip's transition lives on, measured+ // before the resize lands.+ const keepContact = !!next && transitionOverlap(clip, next) > 1e-6;+ useEditor.getState().updateClipTransient(clip.id, patch);const nextStart = next?.start ?? Infinity;- const keep = next- ? Math.min(- transitionOverlap(clip, next),- Math.max(0, clip.start + clipLen(clip) - nextStart),- newLen * 0.9- )- : 0;- const delta =- keep > 1e-6- ? clip.start + newLen - keep - nextStart- : Math.max(0, clip.start + newLen - nextStart);+ const delta = keepContact+ ? clip.start + newLen - nextStart+ : Math.max(0, clip.start + newLen - nextStart);if (Math.abs(delta) > 1e-6) {useEditor.setState((st) => ({clips: st.clips@@ -764,6 +897,7 @@ const DOC_KEYS = ["saveState","assets","clips",+ "transitions","audioClips","overlays","templates",@@ -793,15 +927,39 @@ export const useEditor = create<EditorState>((baseSet, get) => {next = { ...next };for (const k of DOC_KEYS) delete (next as Record<string, unknown>)[k];}- return next.clips ? { ...next, clips: groundTracks(next.clips) } : next;+ if (next.clips) next = { ...next, clips: groundTracks(next.clips) };+ // The per-clip transition/anim fields are caches of the transition bars:+ // any write that moves a clip or a bar re-derives them here, so the two+ // can never disagree.+ if (next.clips || next.transitions) {+ const clips = next.clips ?? prev.clips;+ const derived = deriveTransitionFields(clips, next.transitions ?? prev.transitions);+ if (derived !== clips) next = { ...next, clips: derived };+ }+ // The playhead cannot outlive the timeline. Deleting the last of a long+ // row shortens the project under a playhead standing past the new end,+ // which leaves the readout ahead of the total and — since the playhead is+ // placed with a transform, and transforms count toward scrollable+ // overflow — stretches the scroll area into empty space. Clamping here+ // covers every edit that shortens anything, present and future.+ if (next.clips || next.audioClips || next.overlays) {+ const total = projectDuration({+ clips: next.clips ?? prev.clips,+ audioClips: next.audioClips ?? prev.audioClips,+ overlays: next.overlays ?? prev.overlays,+ });+ if ((next.currentTime ?? prev.currentTime) > total) next = { ...next, currentTime: total };+ }+ return next;}, replace as false | undefined);const snapshot = (): DocSnapshot => {- const { clips, audioClips, overlays, subtitles } = get();+ const { clips, transitions, audioClips, overlays, subtitles } = get();return {// Render-owned clips are excluded — history captures the user's timeline,// not the background run's placements (restoreDoc re-attaches the live ones).clips: clips.filter((c) => !genClipIds.has(c.id)).map((c) => ({ ...c })),+ transitions: transitions.map((t) => ({ ...t })),audioClips: audioClips.filter((c) => !genAudioIds.has(c.id)).map((c) => ({ ...c })),overlays: overlays.map((o) => ({ ...o })),subtitles: {@@ -871,6 +1029,44 @@ export const useEditor = create<EditorState>((baseSet, get) => {});};+ /** Shared add for overlay elements: aim for the playhead, slide to the+ * home lane's next free slot so the new element never lands on an existing+ * one, and select the result. One undo step.+ *+ * Effects keep their own rows. An effect filters the picture under it while+ * the rest draw on top, so they read as separate work and the timeline+ * carries them as separate rows — which is also what lets effect rows lead+ * the band (`overlayLaneOrder`). */+ const addElement = (+ kind: OverlayKind,+ build: (start: number, end: number, lane: number) => Overlay,+ /** A drop aims at where it landed — a time on the timeline and, when it+ * came down on a row, that row. Absent, the playhead and the home row. */+ aim: { at?: number; lane?: number; len?: number } = {}+ ) => {+ push();+ const place =+ aim.lane !== undefined+ ? { lane: aim.lane, shiftDown: false }+ : elementPlacement(get().overlays, kind);+ // A row opening at the top pushes every existing row down one.+ const rest = place.shiftDown+ ? get().overlays.map((o) => ({ ...o, lane: (o.lane ?? 0) + 1 }))+ : get().overlays;+ const t = aim.at ?? get().currentTime;+ const total = totalDuration(get().clips);+ const taken = rest+ .filter((o) => (o.lane ?? 0) === place.lane)+ .map((o) => ({ start: o.start, end: o.end }));+ const len = aim.len ?? 3;+ const start = nextFreeStart(taken, Math.min(t, Math.max(0, total - 0.5)), len);+ const overlay = build(start, Math.min(start + len, Math.max(total, start + len)), place.lane);+ set(() => ({+ overlays: [...rest, overlay],+ ...sole({ kind: "overlay", id: overlay.id }),+ }));+ };+return {projectId: null,projectName: "",@@ -884,6 +1080,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {assets: [],clips: [],+ transitions: [],audioClips: [],overlays: [],templates: [],@@ -893,6 +1090,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {fadeOut: 0,selection: null,multiSelection: [],+ selectedKey: null,currentTime: 0,playing: false,previewStopAt: null,@@ -936,6 +1134,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {resumePush: false,assets: [],clips: [],+ transitions: [],audioClips: [],overlays: [],templates: [],@@ -998,15 +1197,34 @@ export const useEditor = create<EditorState>((baseSet, get) => {const lift = Math.max(0, ...joined.map((c) => -c.track));const lifted = lift ? joined.map((c) => ({ ...c, track: c.track + lift })) : joined;// Docs saved when edge transition styles existed convert them into the- // equivalent clip animations.- const merged = migrateLegacyTransitions(lifted);+ // equivalent clip animations, and docs saved when a transition was a+ // physical overlap pull their intruding clips apart — clips never+ // overlap, whatever wrote the file.+ const merged = separateOverlaps(migrateLegacyTransitions(lifted));+ // Stamp `kind: "text"` on pre-union titles so every in-memory element+ // carries its discriminant; the serializer strips it back. Effects+ // saved onto a shared row move to one of their own, and a clip graded+ // back when a look was a clip property gets that grade as an element+ // over it — so a project made before either rule reads like a new one.+ const stamped = normalizeElementLanes(stampOverlayKinds(doc.overlays ?? []));+ const withLooks =+ liftClipLooks(merged, stamped, getClipSpans(merged, assets)) ?? {+ clips: merged,+ overlays: stamped,+ };hydrating = true;set({projectName: doc.name ?? "",assets,- clips: merged,+ clips: withLooks.clips,+ // Bars from the doc, plus one adopted for each transition/animation+ // a pre-bar doc stored as a clip field.+ transitions: adoptTransitionFields(+ withLooks.clips,+ sanitizeTransitions(doc.transitions)+ ),audioClips: doc.audioClips ?? [],- overlays: doc.overlays ?? [],+ overlays: withLooks.overlays,templates: doc.templates ?? [],aspect: normalizeAspect(doc.aspect) ?? "9:16",aspectTouched: doc.aspect !== undefined,@@ -1548,42 +1766,111 @@ export const useEditor = create<EditorState>((baseSet, get) => {},addOverlay: () => {- push();- const t = get().currentTime;- const total = totalDuration(get().clips);- // Aim for the playhead but slide to the first lane's next free slot so- // the new title never lands on top of an existing one.- const taken = get()- .overlays.filter((o) => (o.lane ?? 0) === 0)- .map((o) => ({ start: o.start, end: o.end }));- const start = nextFreeStart(taken, Math.min(t, Math.max(0, total - 0.5)), 3);// Seed the visual style from the last-used title so repeated titles in a// project share one look; fall back to the built-in defaults.const remembered = readTextStyle();- const overlay: TextOverlay = {+ addElement("text", (start, end, lane) => ({id: uid(),+ kind: "text",text: "Your text",start,- end: Math.min(start + 3, Math.max(total, start + 3)),+ end,x: 0.5,y: 0.42,size: remembered.size ?? 88,font: remembered.font ?? "sf",weight: remembered.weight ?? 700,+ italic: remembered.italic,color: remembered.color ?? "#FFFFFF",+ stroke: remembered.stroke,+ letterSpacing: remembered.letterSpacing,+ lineHeight: remembered.lineHeight,+ align: remembered.align,shadow: remembered.shadow ?? true,plate: remembered.plate ?? false,plateColor: remembered.plateColor,plateOpacity: remembered.plateOpacity,plateRadius: remembered.plateRadius,- lane: 0,- };- set((s) => ({- overlays: [...s.overlays, overlay],- ...sole({ kind: "text", id: overlay.id }),+ lane,}));},+ addShape: (shape, aim) => {+ const frame = frameOf(get().aspect);+ // A square-reading default box whatever the aspect; lines/arrows are a+ // wider box whose height is the stroke thickness.+ const w = shape === "line" || shape === "arrow" ? 0.42 : 0.3;+ const h =+ shape === "line"+ ? 6 / frame.h+ : shape === "arrow"+ ? 10 / frame.h+ : (w * frame.w) / frame.h;+ addElement(+ "shape",+ (start, end, lane) => ({+ id: uid(),+ kind: "shape",+ shape,+ start,+ end,+ x: 0.5,+ y: 0.5,+ w,+ h,+ fill: "#FFFFFF",+ lane,+ }),+ aim+ );+ },++ addSticker: (init) => {+ if (!init.assetId) return;+ addElement(+ "sticker",+ (start, end, lane) => ({+ id: uid(),+ kind: "sticker",+ assetId: init.assetId,+ ...(init.lottie ? { lottie: true } : {}),+ start,+ end,+ x: 0.5,+ y: 0.5,+ w: 0.25,+ lane,+ }),+ { at: init.at, lane: init.lane }+ );+ },++ addEffect: (effect, aim) => {+ // An effect grades a stretch of the picture, and a clip is the stretch+ // people mean: dropped anywhere over one, it opens covering that clip.+ // Off the end of the cut it falls back to the standard length.+ const s0 = get();+ const t = aim?.at ?? s0.currentTime;+ const span = getClipSpans(s0.clips, s0.assets).find(+ (sp) => t >= sp.start - 1e-6 && t < sp.start + sp.len+ );+ const fit = span ? { at: span.start, len: span.len } : { at: aim?.at };+ addElement(+ "effect",+ (start, end, lane) => ({+ id: uid(),+ kind: "effect",+ effect,+ start,+ end,+ x: 0.5,+ y: 0.5,+ lane,+ }),+ { ...fit, lane: aim?.lane }+ );+ },+// The non-transient updaters are just a checkpoint plus the live update.updateClip: (id, patch) => {push();@@ -1608,98 +1895,106 @@ export const useEditor = create<EditorState>((baseSet, get) => {setClipTransition: (id, seconds, style) => {const s = get();- const self = s.clips.find((c) => c.id === id);- if (!self) return;- const spans = getClipSpans(s.clips, s.assets, self.track);- const idx = spans.findIndex((sp) => sp.clip.id === id);- if (idx < 0) return;- const clip = spans[idx].clip;- const next = spans[idx + 1]?.clip;- const value = Math.max(0, Math.min(TRANSITION_MAX, seconds));- const newStyle = value > 0 ? (style ?? clip.transitionStyle ?? "crossfade") : undefined;- const newOverlap = transitionOverlap(- { ...clip, transition: value, transitionStyle: newStyle },- next- );- push();- get().updateClipTransient(id, {- transition: value || undefined,- // "crossfade" is the default — store it as absence to keep docs lean.- transitionStyle: newStyle === "crossfade" ? undefined : newStyle,- // A transitioned joint owns its edges: the transition replaces the- // animations adjacent to it, so stored state always matches what- // plays (the picker disables those edges while the joint is live).- ...(value > 0 ? { animOut: undefined } : {}),+ const clip = s.clips.find((c) => c.id === id);+ if (!clip) return;+ // The bar playing this clip's tail — its cut, or its open end.+ const roles = resolveTransitions(s.clips, s.transitions);+ const existing = s.transitions.find((t) => {+ const r = roles.get(t.id);+ return !!r && r.kind !== "in" && r.clipId === id;});- if (value > 0 && next) get().updateClipTransient(next.id, { animIn: undefined });- // A dissolve is a physical overlap: setting one slides the next clip- // (and the run behind it, gaps preserved) so it starts `newOverlap`- // before this clip ends — closing any gap, since a dissolve needs- // contact. Clearing one pushes the pair back to a hard cut. Edge styles- // overlap nothing: they leave the layout alone. Only the clip's own- // track moves: every other track stays pinned to the absolute times it- // annotates.- if (next) {- const oldOverlap = spans[idx].transitionOut;- const wantStart =- newOverlap > 0 ? clip.start + clipLen(clip) - newOverlap : next.start + oldOverlap;- const delta = wantStart - next.start;- if (Math.abs(delta) > 1e-6) {- set((st) => ({- clips: st.clips- .map((c) =>- c.track === self.track && c.start >= next.start - 1e-6- ? { ...c, start: Math.max(0, c.start + delta) }- : c- )- .sort((a, b) => a.start - b.start),- }));- }+ const value = Math.max(0, Math.min(TRANSITION_MAX, seconds));+ if (value <= 0) {+ if (existing) get().removeTransition(existing.id);+ return;}+ const end = clip.start + clipLen(clip);+ const bar = {+ start: end - value,+ seconds: value,+ style: style ?? existing?.style ?? "crossfade",+ };+ push();+ set((s2) => ({+ transitions: existing+ ? s2.transitions.map((t) => (t.id === existing.id ? { ...t, ...bar } : t))+ : [...s2.transitions, { id: uid(), ...bar }],+ }));},setClipAnim: (id, which, anim) => {const s = get();const clip = s.clips.find((c) => c.id === id);if (!clip) return;- const value =- anim && ANIM_STYLE_IDS.includes(anim.style)- ? { style: anim.style, seconds: Math.max(0.1, Math.min(TRANSITION_MAX, anim.seconds)) }- : undefined;- // Last pick wins per edge: animating an edge a live transition owns- // replaces that transition (the pair slides back to a hard cut), just- // as setting a transition clears the animations adjacent to its joint.- // The clear and the animation land in one undo entry.- let pushed = false;- if (value) {- const row = s.clips- .filter((c) => c.track === clip.track)- .sort((a, b) => a.start - b.start);- const i = row.findIndex((c) => c.id === clip.id);- const lead = which === "in" ? row[i - 1] : row[i];- const follow = which === "in" ? row[i] : row[i + 1];- if (lead && follow && lead.id !== follow.id) {- const physical = lead.start + clipLen(lead) - follow.start;- if (Math.min(transitionOverlap(lead, follow), Math.max(0, physical)) > 1e-6) {- get().setClipTransition(lead.id, 0);- pushed = true;- }- }+ // The bar riding this edge, whichever role it resolved to there.+ const roles = resolveTransitions(s.clips, s.transitions);+ const existing = s.transitions.find((t) => {+ const r = roles.get(t.id);+ return !!r && r.clipId === id && (which === "in" ? r.kind === "in" : r.kind !== "in");+ });+ if (!anim || !ANIM_STYLE_IDS.includes(anim.style)) {+ if (existing) get().removeTransition(existing.id);+ return;}- if (!pushed) push();- get().updateClipTransient(id, { [which === "in" ? "animIn" : "animOut"]: value });+ const seconds = Math.max(0.1, Math.min(TRANSITION_MAX, anim.seconds));+ const edge = which === "in" ? clip.start : clip.start + clipLen(clip);+ const bar = {+ start: which === "in" ? edge : edge - seconds,+ seconds,+ style: transitionStyleOfAnim(anim.style),+ };+ push();+ set((s2) => ({+ transitions: existing+ ? s2.transitions.map((t) => (t.id === existing.id ? { ...t, ...bar } : t))+ : [...s2.transitions, { id: uid(), ...bar }],+ }));},- setClipLook: (id, style, amount) => {- const clip = get().clips.find((c) => c.id === id);- if (!clip) return;- const look = style && LOOK_IDS.includes(style) ? style : undefined;- const k = amount === undefined ? undefined : Math.max(0.05, Math.min(1, amount));+ addTransition: (bar) => {+ const id = uid();push();- get().updateClipTransient(id, {- look,- // Full strength is the default — store it as absence to keep docs lean.- lookAmount: look && k !== undefined && k < 1 ? k : undefined,+ set((s) => ({+ transitions: [+ ...s.transitions,+ { id, start: bar.start, seconds: clampBarSeconds(bar.seconds), style: bar.style },+ ],+ }));+ return id;+ },++ updateTransition: (id, patch) => {+ push();+ get().updateTransitionTransient(id, patch);+ },++ updateTransitionTransient: (id, patch) => {+ set((s) => ({+ transitions: s.transitions.map((t) =>+ t.id === id+ ? {+ ...t,+ ...patch,+ ...(patch.seconds !== undefined ? { seconds: clampBarSeconds(patch.seconds) } : {}),+ }+ : t+ ),+ }));+ },++ removeTransition: (id) => {+ if (!get().transitions.some((t) => t.id === id)) return;+ push();+ set((s) => {+ const keep = (sel: Selection) => !(sel?.kind === "transition" && sel.id === id);+ const multiSelection = s.multiSelection.filter(keep);+ return {+ transitions: s.transitions.filter((t) => t.id !== id),+ multiSelection,+ selection: keep(s.selection)+ ? s.selection+ : multiSelection[multiSelection.length - 1] ?? null,+ };});},@@ -1749,6 +2044,72 @@ export const useEditor = create<EditorState>((baseSet, get) => {applyOverlayPatchSettled(id, patch);},+ setOverlayKey: (id, tLocal, patch, opts) => {+ const o = get().overlays.find((x) => x.id === id);+ if (!o) return;+ const t = Math.max(0, Math.min(tLocal, Math.max(0.1, o.end - o.start)));+ const existing = o.kf?.find((k) => Math.abs(k.t - t) <= KEY_EPSILON);+ // A brand-new key holds the pose the element already had at `t`, so+ // adding one changes nothing until something edits it.+ const next = { ...(existing ?? keyAt(o, t)), ...patch, t };+ if (!opts?.transient) push();+ get().updateOverlayTransient(id, { kf: upsertKey(o.kf, next) });+ },++ removeOverlay: (id) => {+ if (!get().overlays.some((o) => o.id === id)) return;+ push();+ set((s) => ({+ overlays: s.overlays.filter((o) => o.id !== id),+ selection: s.selection?.kind === "overlay" && s.selection.id === id ? null : s.selection,+ multiSelection: s.multiSelection.filter(+ (x) => !(x && x.kind === "overlay" && x.id === id)+ ),+ }));+ },++ removeOverlayKey: (id, tLocal) => {+ const o = get().overlays.find((x) => x.id === id);+ if (!o || !o.kf?.length) return;+ const kf = removeKeyAt(o.kf, tLocal);+ if (kf.length === o.kf.length) return;+ push();+ // The last key going means the element holds its own resting pose+ // again, so the track leaves rather than lingering empty.+ get().updateOverlayTransient(id, { kf: kf.length ? kf : undefined });+ },++ selectOverlayKey: (id, tLocal) => {+ const o = get().overlays.find((x) => x.id === id);+ if (!o) return;+ get().select({ kind: "overlay", id });+ set({ selectedKey: { overlayId: id, t: tLocal } });+ },++ moveOverlayKey: (id, fromT, toT, opts) => {+ const o = get().overlays.find((x) => x.id === id);+ if (!o?.kf?.length) return;+ const key = o.kf.find((k) => Math.abs(k.t - fromT) <= KEY_EPSILON);+ if (!key) return;+ const t = Math.max(0, Math.min(toT, Math.max(0.1, o.end - o.start)));+ if (!opts?.transient) push();+ get().updateOverlayTransient(id, {+ kf: upsertKey(removeKeyAt(o.kf, fromT), { ...key, t }),+ });+ // The pick follows the key it is on, so dragging never drops it.+ const picked = get().selectedKey;+ if (picked && picked.overlayId === id && Math.abs(picked.t - fromT) <= KEY_EPSILON) {+ set({ selectedKey: { overlayId: id, t } });+ }+ },++ clearOverlayKeys: (id) => {+ const o = get().overlays.find((x) => x.id === id);+ if (!o?.kf?.length) return;+ push();+ get().updateOverlayTransient(id, { kf: undefined });+ },+updateOverlayTransient: (id, patch) =>set((s) => ({overlays: s.overlays.map((o) => (o.id === id ? { ...o, ...patch } : o)),@@ -1971,7 +2332,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {const { clips, audioClips, assets, currentTime, selection } = get();const t = at ?? currentTime;- // iMovie-style: with a soundtrack clip selected, ⌘B slices it instead.+ // With a soundtrack clip selected, ⌘B slices it instead.if (selection?.kind === "audio") {const a = audioClips.find((c) => c.id === selection.id);const len = a ? clipLen(a) : 0;@@ -2018,16 +2379,16 @@ export const useEditor = create<EditorState>((baseSet, get) => {}}- // A title selected: both halves keep the full text and style.- if (selection?.kind === "text") {+ // An overlay element selected: both halves keep the full content/style.+ if (selection?.kind === "overlay") {const o = get().overlays.find((x) => x.id === selection.id);if (o && t > o.start + 0.05 && t < o.end - 0.05) {push();- const left: TextOverlay = { ...o, end: t };- const right: TextOverlay = { ...o, id: uid(), start: t };+ const left: Overlay = { ...o, end: t };+ const right: Overlay = { ...o, id: uid(), start: t };set((s) => ({overlays: s.overlays.flatMap((x) => (x.id === o.id ? [left, right] : [x])),- ...sole({ kind: "text", id: right.id }),+ ...sole({ kind: "overlay", id: right.id }),}));}return;@@ -2092,6 +2453,17 @@ export const useEditor = create<EditorState>((baseSet, get) => {deleteSelection: () => {const st = get();+ // A picked keyframe is the smaller thing under the cursor: Delete takes+ // the key and leaves the element it belongs to alone.+ const key = st.selectedKey;+ if (key) {+ set({ selectedKey: null });+ const o = st.overlays.find((x) => x.id === key.overlayId);+ if (o?.kf?.some((k) => Math.abs(k.t - key.t) <= KEY_EPSILON)) {+ st.removeOverlayKey(key.overlayId, key.t);+ return;+ }+ }const sels = st.multiSelection.length? st.multiSelection: st.selection@@ -2107,8 +2479,9 @@ export const useEditor = create<EditorState>((baseSet, get) => {);const clipIds = idsOf("clip");const audioIds = idsOf("audio");- const textIds = idsOf("text");+ const textIds = idsOf("overlay");const cueIds = idsOf("cue");+ const barIds = idsOf("transition");set((s) => {let clips = s.clips.filter((c) => !clipIds.has(c.id));let audioClips = s.audioClips.filter((c) => !audioIds.has(c.id));@@ -2148,6 +2521,9 @@ export const useEditor = create<EditorState>((baseSet, get) => {}return {clips: clips.sort((a, b) => a.start - b.start),+ ...(barIds.size+ ? { transitions: s.transitions.filter((t) => !barIds.has(t.id)) }+ : {}),audioClips,overlays,subtitles: { ...s.subtitles, cues },@@ -2157,19 +2533,41 @@ export const useEditor = create<EditorState>((baseSet, get) => {});},- removeGap: (track, at) => {- const gap = trackGapAt(get().clips, track, at);+ removeLaneGap: (lane, at) => {+ const gap = laneGapAt(get(), lane, at);if (!gap) return;push();- set((s) => ({- clips: s.clips- .map((c) =>- c.track === track && c.start >= gap.start + gap.len - 0.001- ? { ...c, start: c.start - gap.len }- : c- )- .sort((a, b) => a.start - b.start),- }));+ const after = gap.start + gap.len - 0.001;+ const shift = gap.len;+ set((s) => {+ if (lane.kind === "video")+ return {+ clips: s.clips+ .map((c) =>+ c.track === lane.index && c.start >= after ? { ...c, start: c.start - shift } : c+ )+ .sort((a, b) => a.start - b.start),+ };+ if (lane.kind === "audio")+ return {+ audioClips: s.audioClips+ .map((a) =>+ (a.lane ?? 0) === lane.index && a.start >= after+ ? { ...a, start: a.start - shift }+ : a+ )+ .sort((a, b) => a.start - b.start),+ };+ return {+ overlays: s.overlays+ .map((o) =>+ (o.lane ?? 0) === lane.index && o.start >= after+ ? { ...o, start: o.start - shift, end: o.end - shift }+ : o+ )+ .sort((a, b) => a.start - b.start),+ };+ });},selectionRange: () => {@@ -2201,7 +2599,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {} else if (sel.kind === "audio") {const c = s.audioClips.find((x) => x.id === sel.id);if (c) add(c.start, c.start + clipLen(c));- } else if (sel.kind === "text") {+ } else if (sel.kind === "overlay") {const o = s.overlays.find((x) => x.id === sel.id);if (o) add(o.start, o.end);} else if (sel.kind === "cue") {@@ -2237,7 +2635,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {const layers: TemplateLayer[] = [];const audio: TemplateAudio[] = [];- const texts: TextOverlay[] = [];+ const texts: Overlay[] = [];const cues: SubtitleCue[] = [];for (const sel of sels) {if (sel.kind === "clip") {@@ -2261,9 +2659,13 @@ export const useEditor = create<EditorState>((baseSet, get) => {const mi = mediaFor(c.assetId);if (mi == null) continue;audio.push({ media: mi, start: c.start - start0, in: c.in, out: c.out, volume: c.volume, fadeIn: c.fadeIn, fadeOut: c.fadeOut, speed: c.speed, duck: c.duck, lane: c.lane });- } else if (sel.kind === "text") {+ } else if (sel.kind === "overlay") {const o = s.overlays.find((x) => x.id === sel.id);- if (o) texts.push({ ...o, start: o.start - start0, end: o.end - start0 });+ // Asset-backed stickers stay out: a template copies only the media+ // its layers/audio reference, so the sticker's bytes wouldn't travel.+ if (o && !(isStickerOverlay(o) && o.assetId)) {+ texts.push({ ...o, start: o.start - start0, end: o.end - start0 });+ }} else if (sel.kind === "cue") {const c = s.subtitles.cues.find((x) => x.id === sel.id);if (c) cues.push({ ...c, start: c.start - start0, end: c.end - start0 });@@ -2385,11 +2787,17 @@ export const useEditor = create<EditorState>((baseSet, get) => {...(a.duck !== undefined && a.duck < 1 ? { duck: a.duck } : {}),...(a.lane ? { lane: a.lane } : {}),}));- const newTexts: TextOverlay[] = template.texts.map((o) => ({+ // Templates saved before the union carry bare titles — same stamp as+ // the doc loader, so every in-memory element has its discriminant.+ // Groups are remapped per application, so adding the same template+ // twice gives two independent groups instead of one welded set.+ const regroup = groupRemap(uid);+ const newTexts: Overlay[] = stampOverlayKinds(template.texts).map((o) => ({...o,id: uid(),start: o.start + shift,end: o.end + shift,+ ...regroup(o),}));const newCues: SubtitleCue[] = template.cues.map((c) => ({...c,@@ -2408,7 +2816,40 @@ export const useEditor = create<EditorState>((baseSet, get) => {}));},- select: (sel) => set({ selection: sel, multiSelection: sel ? [sel] : [] }),+ select: (sel) => {+ // Selecting one member of a group selects the whole group (shallow, by+ // design): bulk actions — delete, copy, drag — act on all of it, while+ // the clicked member stays the primary the inspector edits.+ if (sel?.kind === "overlay") {+ const o = get().overlays.find((x) => x.id === sel.id);+ if (o?.groupId) {+ const members = get()+ .overlays.filter((x) => x.groupId === o.groupId)+ .map((x): NonNullable<Selection> => ({ kind: "overlay", id: x.id }));+ set({ selection: sel, multiSelection: members, selectedKey: null });+ return;+ }+ }+ set({ selection: sel, multiSelection: sel ? [sel] : [], selectedKey: null });+ },++ groupSelectedOverlays: () => {+ const s = get();+ const ids = s.multiSelection+ .filter((x): x is NonNullable<Selection> => !!x && x.kind === "overlay")+ .map((x) => x.id);+ if (ids.length < 2) return;+ push();+ const groupId = uid();+ get().updateOverlaysTransient(ids.map((id) => ({ id, patch: { groupId } })));+ },++ ungroupOverlays: (groupId) => {+ const members = get().overlays.filter((o) => o.groupId === groupId);+ if (members.length === 0) return;+ push();+ get().updateOverlaysTransient(members.map((o) => ({ id: o.id, patch: { groupId: undefined } })));+ },toggleSelect: (sel) =>set((s) => {@@ -3131,9 +3572,9 @@ export const useEditor = create<EditorState>((baseSet, get) => {} else if (sel?.kind === "audio") {const a = s.audioClips.find((x) => x.id === sel.id);if (a) items.push({ kind: "audio", item: { ...a } });- } else if (sel?.kind === "text") {+ } else if (sel?.kind === "overlay") {const o = s.overlays.find((x) => x.id === sel.id);- if (o) items.push({ kind: "text", item: { ...o } });+ if (o) items.push({ kind: "overlay", item: { ...o } });}}if (items.length === 0) return false;@@ -3144,11 +3585,18 @@ export const useEditor = create<EditorState>((baseSet, get) => {paste: () => {if (clipboard.length === 0) return false;const s = get();- // Every copied clip's media must still exist in this project.+ // Every copied item's media must still exist in this project (asset+ // stickers included; text and shapes reference none).if (- clipboard.some(- (cb) => cb.kind !== "text" && !s.assets.some((a) => a.id === cb.item.assetId)- )+ clipboard.some((cb) => {+ const assetId =+ cb.kind === "overlay"+ ? isStickerOverlay(cb.item)+ ? cb.item.assetId+ : undefined+ : cb.item.assetId;+ return assetId !== undefined && !s.assets.some((a) => a.id === assetId);+ }))return false;push();@@ -3158,6 +3606,9 @@ export const useEditor = create<EditorState>((baseSet, get) => {let clips = cur.clips;let audioClips = cur.audioClips;let overlays = cur.overlays;+ // A copy is its own thing: pasted group members stay grouped with each+ // other and join nothing that was already on the timeline.+ const regroup = groupRemap(uid);// Every item aims for the playhead but respects what already sits on// its lane: an occupied spot slides the paste right to the next gap// that fits. Earlier items of this same paste count too.@@ -3186,9 +3637,15 @@ export const useEditor = create<EditorState>((baseSet, get) => {.filter((o) => (o.lane ?? 0) === (cb.item.lane ?? 0)).map((o) => ({ start: o.start, end: o.end }));const start = nextFreeStart(taken, t, len);- const item: TextOverlay = { ...cb.item, id: uid(), start, end: start + len };+ const item: Overlay = {+ ...cb.item,+ id: uid(),+ start,+ end: start + len,+ ...regroup(cb.item),+ };overlays = [...overlays, item];- newSel.push({ kind: "text", id: item.id });+ newSel.push({ kind: "overlay", id: item.id });}}return { clips, audioClips, overlays, selection: newSel[newSel.length - 1] ?? null, multiSelection: newSel };@@ -3220,6 +3677,7 @@ export const useEditor = create<EditorState>((baseSet, get) => {useEditor.subscribe((s, prev) => {if (s.clips !== prev.clips ||+ s.transitions !== prev.transitions ||s.audioClips !== prev.audioClips ||s.overlays !== prev.overlays ||s.subtitles !== prev.subtitles@@ -3265,6 +3723,21 @@ function docClipFilter<T extends { assetId: string }>() {export const docClips = docClipFilter<VideoClip>();export const docAudioClips = docClipFilter<AudioClip>();+/** The overlay elements as the document stores them — the loader-stamped+ * `kind` dropped off text. Memoized on the live array like `docClips`, because+ * autosave tells an edit from a re-read by comparing this projection's+ * identity: rebuilding it on every read would mark the document dirty forever.+ */+export const docOverlays = (() => {+ let memo: { overlays: Overlay[]; out: Overlay[] } | null = null;+ return (overlays: Overlay[]): Overlay[] => {+ if (memo && memo.overlays === overlays) return memo.out;+ const out = stripDefaultOverlayKinds(overlays);+ memo = { overlays, out };+ return out;+ };+})();+/** The asset fields persisted in project.json — the projection autosave* writes, and the one its change detector compares (runtime fields like* thumbs/peaks must not mark the doc dirty). Assets whose bytes are still@@ -3291,8 +3764,9 @@ export function serializeDoc(s: {projectName: string;assets: MediaAsset[];clips: VideoClip[];+ transitions: TimelineTransition[];audioClips: AudioClip[];- overlays: TextOverlay[];+ overlays: Overlay[];templates: LibraryTemplate[];aspect: Aspect;fadeIn: number;@@ -3308,8 +3782,11 @@ export function serializeDoc(s: {name: s.projectName,assets: storedAssets(s.assets),clips: docClips(s.clips, s.assets),+ transitions: s.transitions.map((t) => ({ ...t })),audioClips: docAudioClips(s.audioClips, s.assets),- overlays: s.overlays,+ // Text elements drop the loader-stamped `kind`, so title-only projects+ // serialize byte-identical to the pre-union shape.+ overlays: docOverlays(s.overlays),templates: s.templates,aspect: s.aspect,fadeIn: s.fadeIn,@@ -3339,15 +3816,228 @@ export function clipLen(c: VideoClip | AudioClip) {return Math.max(MIN_LEN, eff);}-/** Overlap (timeline seconds) between a clip and its successor, clamped so it- * can never swallow either clip whole. 0 when there is no next clip or no- * transition set — every transition style is a physical overlap. */+/** How closely two starts/ends must agree to count as the same cut. */+const TOUCH_EPS = 0.02;++/**+ * The live blend length (timeline seconds) of `a`'s transition into `b`.+ *+ * A transition is a render-time blend at the cut: during the last blend+ * seconds of `a`, the incoming clip's first frame arrives over `a`'s live+ * tail, and at the cut `b` plays from its head. Clips never intersect in+ * time — the blend claims no layout, moves nothing, and resizes nothing.+ * It is live only while the pair actually touches; clips dragged apart+ * keep the declared length and the blend comes back when they meet again.+ * Clamped so it can never swallow either clip whole.+ */export function transitionOverlap(a: VideoClip, b: VideoClip | undefined): number {const d = a.transition ?? 0;if (!b || d <= 0) return 0;+ if (Math.abs(a.start + clipLen(a) - b.start) > TOUCH_EPS) return 0;return Math.min(d, clipLen(a) * 0.9, clipLen(b) * 0.9);}+/** Clamp a bar's blend length to the range every consumer expects. */+const clampBarSeconds = (s: number) => Math.max(0.1, Math.min(TRANSITION_MAX, s));++/** The place a transition bar is playing at: the cut it ends on (`clipId` is+ * the outgoing clip), or the open head/tail it rides. */+export type TransitionRole = { kind: "cut" | "in" | "out"; clipId: string };++type TransitionBoundary = TransitionRole & { at: number };++/** Every place on every video track with a handover to make: a cut where one+ * clip touches the next, and the open edges — a head with nothing before it,+ * a tail with nothing after. */+function transitionBoundaries(clips: VideoClip[]): TransitionBoundary[] {+ const out: TransitionBoundary[] = [];+ const tracks = [...new Set(clips.map((c) => c.track))].sort((a, b) => a - b);+ for (const track of tracks) {+ const row = clips.filter((c) => c.track === track).sort((a, b) => a.start - b.start);+ row.forEach((c, i) => {+ const end = c.start + clipLen(c);+ const prev = row[i - 1];+ const next = row[i + 1];+ if (!prev || prev.start + clipLen(prev) < c.start - TOUCH_EPS)+ out.push({ kind: "in", clipId: c.id, at: c.start });+ if (next && next.start <= end + TOUCH_EPS) out.push({ kind: "cut", clipId: c.id, at: end });+ else out.push({ kind: "out", clipId: c.id, at: end });+ });+ }+ return out;+}++/**+ * Match each transition bar to the boundary it lines up with, by time alone:+ * a bar plays the cut or open tail its end sits on, or the open head its+ * start sits on. A bar aligned with nothing is inert — it stays on the row,+ * does nothing, and starts playing the moment a boundary lines up with it.+ * One bar per boundary; when two claim the same one, the newest wins.+ */+export function resolveTransitions(+ clips: VideoClip[],+ transitions: TimelineTransition[]+): Map<string, TransitionRole> {+ const bounds = transitionBoundaries(clips);+ const rank = { cut: 0, in: 1, out: 2 } as const;+ const taken = new Set<TransitionBoundary>();+ const roles = new Map<string, TransitionRole>();+ for (let i = transitions.length - 1; i >= 0; i--) {+ const t = transitions[i];+ const fit = bounds+ .filter(+ (b) =>+ !taken.has(b) &&+ Math.abs((b.kind === "in" ? t.start : t.start + t.seconds) - b.at) <= TOUCH_EPS+ )+ .sort((a, b) => rank[a.kind] - rank[b.kind])[0];+ if (!fit) continue;+ taken.add(fit);+ roles.set(t.id, { kind: fit.kind, clipId: fit.clipId });+ }+ return roles;+}++const sameAnim = (a: ClipAnim | undefined, b: ClipAnim | undefined) =>+ a === b || (!!a && !!b && a.style === b.style && a.seconds === b.seconds);++/**+ * A clip's `transition`/`animIn`/`animOut` fields are caches of the bars:+ * whichever bar plays a clip's cut, head, or tail writes the matching field,+ * and a clip no bar plays goes plain. Runs inside the store's set wrapper on+ * every clips/transitions write, so the fields can never disagree with the+ * bars. Same array back when nothing changes.+ */+export function deriveTransitionFields(+ clips: VideoClip[],+ transitions: TimelineTransition[]+): VideoClip[] {+ const roles = resolveTransitions(clips, transitions);+ const byBoundary = new Map<string, TimelineTransition>();+ for (const t of transitions) {+ const r = roles.get(t.id);+ if (r) byBoundary.set(`${r.kind}:${r.clipId}`, t);+ }+ let changed = false;+ const next = clips.map((c) => {+ const cut = byBoundary.get(`cut:${c.id}`);+ const transition = cut ? clampBarSeconds(cut.seconds) : undefined;+ const transitionStyle = cut && cut.style !== "crossfade" ? cut.style : undefined;+ const animOf = (t: TimelineTransition | undefined): ClipAnim | undefined => {+ if (!t) return undefined;+ const style = animStyleOfTransition(t.style);+ return {+ // Upper tracks composite through alpha, so their edges render the+ // ramps alpha can express.+ style: c.track > 0 ? overlayAnimStyle(style) : style,+ seconds: clampBarSeconds(t.seconds),+ };+ };+ const animIn = animOf(byBoundary.get(`in:${c.id}`));+ const animOut = animOf(byBoundary.get(`out:${c.id}`));+ if (+ c.transition === transition &&+ c.transitionStyle === transitionStyle &&+ sameAnim(c.animIn, animIn) &&+ sameAnim(c.animOut, animOut)+ )+ return c;+ changed = true;+ return { ...c, transition, transitionStyle, animIn, animOut };+ });+ return changed ? next : clips;+}++/** Bring a stored bar list back to the shape the editor expects. */+function sanitizeTransitions(raw: TimelineTransition[] | undefined): TimelineTransition[] {+ return (raw ?? [])+ .filter((t) => t && typeof t.start === "number" && typeof t.seconds === "number")+ .map((t) => ({+ id: t.id || uid(),+ start: t.start,+ seconds: clampBarSeconds(t.seconds),+ style: TRANSITION_STYLE_IDS.includes(t.style) ? t.style : "crossfade",+ }));+}++/**+ * Docs saved when transitions and edge animations lived on clips: each stored+ * field becomes a bar at its natural window, unless a bar already plays that+ * boundary. Runs at load only — live edits write bars directly, and the+ * derived fields always have a bar behind them.+ */+export function adoptTransitionFields(+ clips: VideoClip[],+ transitions: TimelineTransition[]+): TimelineTransition[] {+ const roles = resolveTransitions(clips, transitions);+ const claimed = new Set([...roles.values()].map((r) => `${r.kind}:${r.clipId}`));+ const out = [...transitions];+ const add = (bar: Omit<TimelineTransition, "id">) => out.push({ id: uid(), ...bar });+ for (const c of clips) {+ const end = c.start + clipLen(c);+ const d = Math.min(c.transition ?? 0, TRANSITION_MAX);+ const tailFree = !claimed.has(`cut:${c.id}`) && !claimed.has(`out:${c.id}`);+ if (d > 0 && tailFree) {+ add({+ start: end - d,+ seconds: clampBarSeconds(d),+ style: TRANSITION_STYLE_IDS.includes(c.transitionStyle as TransitionStyle)+ ? (c.transitionStyle as TransitionStyle)+ : "crossfade",+ });+ } else if (c.animOut && tailFree) {+ const seconds = clampBarSeconds(c.animOut.seconds);+ add({ start: end - seconds, seconds, style: transitionStyleOfAnim(c.animOut.style) });+ }+ if (c.animIn && !claimed.has(`in:${c.id}`)) {+ add({+ start: c.start,+ seconds: clampBarSeconds(c.animIn.seconds),+ style: transitionStyleOfAnim(c.animIn.style),+ });+ }+ }+ return out.length === transitions.length ? transitions : out;+}++/**+ * The invariant every video track keeps: clips never overlap in time.+ *+ * Docs saved when a transition was a physical overlap stored the incoming+ * clip inside the outgoing one's footprint. On load, each intruding clip —+ * and everything after it on its track, gaps preserved — moves right until+ * the pair abuts, so the transition still sits on a cut and nothing plays+ * differently twice. Same array back when nothing intrudes.+ */+export function separateOverlaps(clips: VideoClip[]): VideoClip[] {+ const tracks = new Set(clips.map((c) => c.track));+ let out = clips;+ for (const track of tracks) {+ const row = out+ .filter((c) => c.track === track)+ .sort((a, b) => a.start - b.start);+ let shift = 0;+ const moved = new Map<string, number>();+ for (let i = 0; i < row.length; i++) {+ const start = row[i].start + shift;+ if (i > 0) {+ const prevEnd = moved.get(row[i - 1].id)! + clipLen(row[i - 1]);+ if (start < prevEnd - 1e-3) shift += prevEnd - start;+ }+ moved.set(row[i].id, row[i].start + shift);+ }+ if (shift > 0) {+ out = out.map((c) =>+ c.track === track && moved.get(c.id) !== c.start+ ? { ...c, start: moved.get(c.id)! }+ : c+ );+ }+ }+ return out;+}+export function getClipSpans(clips: VideoClip[],assets: MediaAsset[],@@ -3368,30 +4058,62 @@ export function getClipSpans(const { clip, asset } = present[i];const len = clipLen(clip);const next = present[i + 1]?.clip;- // A dissolve is a physical overlap with the next clip, capped by the- // declared transition; clips dragged apart dissolve into nothing.- const physical = next ? Math.max(0, clip.start + len - next.start) : 0;- const overlap = Math.min(transitionOverlap(clip, next), physical);- spans.push({ clip, asset, start: clip.start, len, transitionOut: overlap });+ // The blend into the next clip, live only at a cut the pair actually+ // makes; clips dragged apart dissolve into nothing.+ spans.push({+ clip,+ asset,+ start: clip.start,+ len,+ transitionOut: transitionOverlap(clip, next),+ });}return spans;}-/** The empty span on `track` containing time `t` — the stretch between two- * clip footprints (or before the first one). Null when `t` sits on a clip or- * past the last one (there is nothing after trailing space to pull left). */-export function trackGapAt(- clips: VideoClip[],- track: number,+/** One row of the timeline, whichever kind of thing sits on it. Video rows are+ * `track`; audio and title rows are the item's `lane`. */+export type LaneRef =+ | { kind: "video"; index: number }+ | { kind: "audio"; index: number }+ | { kind: "overlay"; index: number };++export const sameLane = (a: LaneRef, b: LaneRef) => a.kind === b.kind && a.index === b.index;++/** Every footprint on one row, in play order. */+function laneSpans(+ doc: { clips: VideoClip[]; audioClips: AudioClip[]; overlays: Overlay[] },+ lane: LaneRef+): { start: number; end: number }[] {+ const spans =+ lane.kind === "video"+ ? doc.clips+ .filter((c) => c.track === lane.index)+ .map((c) => ({ start: c.start, end: c.start + clipLen(c) }))+ : lane.kind === "audio"+ ? doc.audioClips+ .filter((a) => (a.lane ?? 0) === lane.index)+ .map((a) => ({ start: a.start, end: a.start + clipLen(a) }))+ : doc.overlays+ .filter((o) => (o.lane ?? 0) === lane.index)+ .map((o) => ({ start: o.start, end: o.end }));+ return spans.sort((a, b) => a.start - b.start);+}++/** The empty span on `lane` containing time `t` — the stretch between two+ * footprints (or before the first one). Null when `t` sits on an item or past+ * the last one (there is nothing after trailing space to pull left). */+export function laneGapAt(+ doc: { clips: VideoClip[]; audioClips: AudioClip[]; overlays: Overlay[] },+ lane: LaneRef,t: number): { start: number; len: number } | null {- const spine = clips.filter((c) => c.track === track).sort((a, b) => a.start - b.start);let prevEnd = 0;- for (const c of spine) {- if (c.start - prevEnd > 0.05 && t >= prevEnd && t < c.start) {- return { start: prevEnd, len: c.start - prevEnd };+ for (const s of laneSpans(doc, lane)) {+ if (s.start - prevEnd > 0.05 && t >= prevEnd && t < s.start) {+ return { start: prevEnd, len: s.start - prevEnd };}- prevEnd = Math.max(prevEnd, c.start + clipLen(c));+ prevEnd = Math.max(prevEnd, s.end);}return null;}@@ -3406,7 +4128,7 @@ function exciseRange(doc: {clips: VideoClip[];audioClips: AudioClip[];- overlays: TextOverlay[];+ overlays: Overlay[];cues: SubtitleCue[];},at: number,@@ -3426,7 +4148,7 @@ function exciseRange(return pieces.filter((p) => (p.out - p.in) / speed >= MIN_LEN);};- const cutText = (o: TextOverlay): TextOverlay[] => {+ const cutText = (o: Overlay): Overlay[] => {if (o.end <= at + EPS) return [o];if (o.start >= end - EPS) return [{ ...o, start: o.start - delta, end: o.end - delta }];const start = Math.min(o.start, at);@@ -3501,15 +4223,14 @@ export function totalDuration(clips: VideoClip[]) {/** A track-0 clip as older docs stored it: packed by array order, no `start`. */type LegacyClip = Omit<VideoClip, "start"> & { start?: number };-/** Assign packed sequential starts (each clip after the previous, dissolves- * overlapping): the layout older docs implied by array order. */+/** Assign packed sequential starts (each clip abutting the previous): the+ * layout older docs implied by array order. */function packStarts(clips: LegacyClip[]): VideoClip[] {let t = 0;const out: VideoClip[] = [];- for (let i = 0; i < clips.length; i++) {- const clip = { ...clips[i], start: t } as VideoClip;- const next = clips[i + 1] ? ({ ...clips[i + 1], start: 0 } as VideoClip) : undefined;- t += clipLen(clip) - transitionOverlap(clip, next);+ for (const c of clips) {+ const clip = { ...c, start: t } as VideoClip;+ t += clipLen(clip);out.push(clip);}return out;@@ -3525,24 +4246,171 @@ export function spanSequence(spans: ClipSpan[]): { gapBefore: number; span: Clipfor (const sp of spans) {const gap = sp.start - cursor;out.push({ gapBefore: gap > 0.05 ? gap : 0, span: sp });- cursor = sp.start + sp.len - sp.transitionOut;+ cursor = sp.start + sp.len;}return out;}+/**+ * Display order of the overlay rows, top row first.+ *+ * The lane number is the order: row 0 is the top row, and used lanes compact+ * to contiguous rows so an emptied one disappears. Nothing about a kind moves+ * a row, which is what lets a drag put any element on any row and have it+ * stay — new effects open a row at the top (`elementPlacement`), and from+ * there the user decides.+ *+ * Rendering and lane drags both order rows through here. If they disagreed, a+ * row index would mean one thing on screen and another to the drop, and an+ * item would land a row away from where it was aimed.+ */+export function overlayLaneOrder(overlays: Overlay[]): number[] {+ return [...new Set(overlays.map((o) => o.lane ?? 0))].sort((a, b) => a - b);+}++/**+ * Move effects off rows they share with titles, shapes or stickers, onto an+ * effect row where their stretch of the timeline is free.+ *+ * Docs written before effects claimed their own rows put every element on+ * lane 0. `normalizeElementLanes` runs this on load, then numbers the rows.+ */+function splitEffectLanes(overlays: Overlay[]): Overlay[] {+ const laneOf = (o: Overlay) => o.lane ?? 0;+ const shared = new Set(+ overlays+ .map(laneOf)+ .filter((l) =>+ overlays.some((o) => laneOf(o) === l && isEffectOverlay(o)) &&+ overlays.some((o) => laneOf(o) === l && !isEffectOverlay(o))+ )+ );+ if (shared.size === 0) return overlays;+ // Placed items decide where the next one fits, so each moved effect sees+ // the ones already moved.+ const placed = overlays.filter((o) => !(isEffectOverlay(o) && shared.has(laneOf(o))));+ return overlays.map((o) => {+ if (!isEffectOverlay(o) || !shared.has(laneOf(o))) return o;+ const lanes = [...new Set(placed.map(laneOf))].sort((a, b) => a - b);+ const free = lanes.find((l) =>+ placed.every(+ (p) => laneOf(p) !== l || (isEffectOverlay(p) && (p.end <= o.start || p.start >= o.end))+ )+ );+ const moved = { ...o, lane: free ?? (lanes.length ? Math.max(...lanes) + 1 : 0) };+ placed.push(moved);+ return moved;+ });+}++/**+ * Repair the element rows of a doc written before effects had rows of their+ * own: every element sat on lane 0 there. The effects lift onto rows of their+ * own, and the rows renumber so those come first — the stack a new project+ * builds.+ *+ * A doc with no shared row comes back untouched, whatever order its rows are+ * in. That order is the user's: they can drag any element to any row, and a+ * load that re-sorted by kind would take it back on the next open.+ */+/**+ * Turn a clip's saved look into an effect element over that clip.+ *+ * A look used to be a property of one clip. It is an effect now — a stretch of+ * the timeline you can trim, move, or run across several clips — so a doc+ * written before that opens with its grades as elements, covering exactly the+ * clips they graded.+ */+export function liftClipLooks(+ clips: VideoClip[],+ overlays: Overlay[],+ spans: { clip: VideoClip; start: number; len: number }[]+): { clips: VideoClip[]; overlays: Overlay[] } | null {+ const graded = clips.filter((c) => c.look);+ if (graded.length === 0) return null;+ const lifted: Overlay[] = [];+ for (const c of graded) {+ const sp = spans.find((x) => x.clip.id === c.id);+ if (!sp) continue;+ // One row per overlapping grade, so two clips graded back to back share a+ // row and a layered pair does not.+ let lane = 0;+ while (lifted.some((o) => (o.lane ?? 0) === lane && o.start < sp.start + sp.len && o.end > sp.start))+ lane += 1;+ lifted.push({+ id: uid(),+ kind: "effect",+ effect: c.look as EffectId,+ amount: c.lookAmount,+ start: sp.start,+ end: sp.start + sp.len,+ x: 0.5,+ y: 0.5,+ lane,+ });+ }+ if (lifted.length === 0) return null;+ // The grades take the top rows, the same place a new effect opens on; the+ // elements that were already there keep their order below them.+ const rows = Math.max(...lifted.map((o) => o.lane ?? 0)) + 1;+ return {+ clips: clips.map((c) => (c.look ? { ...c, look: undefined, lookAmount: undefined } : c)),+ overlays: [...overlays.map((o) => ({ ...o, lane: (o.lane ?? 0) + rows })), ...lifted],+ };+}++export function normalizeElementLanes(overlays: Overlay[]): Overlay[] {+ const split = splitEffectLanes(overlays);+ if (split === overlays) return overlays;+ const laneOf = (o: Overlay) => o.lane ?? 0;+ const effectRow = (l: number) => split.every((o) => laneOf(o) !== l || isEffectOverlay(o));+ const order = [...new Set(split.map(laneOf))].sort(+ (a, b) => Number(effectRow(b)) - Number(effectRow(a)) || a - b+ );+ const row = new Map(order.map((l, i) => [l, i]));+ return split.map((o) => ({ ...o, lane: row.get(laneOf(o))! }));+}++/**+ * Where a new element's row is: the lowest row already holding its side —+ * effects with effects, everything else with everything else.+ *+ * With no such row yet, a title, shape or sticker takes a fresh row at the+ * bottom, while an effect opens one at the top and the rest shift down a row,+ * since an effect filters what plays under it. A drag can move it afterwards;+ * this only decides where it starts.+ */+export function elementPlacement(+ overlays: Overlay[],+ kind: OverlayKind+): { lane: number; shiftDown: boolean } {+ const laneOf = (o: Overlay) => o.lane ?? 0;+ const effect = kind === "effect";+ const lanes = [...new Set(overlays.map(laneOf))].sort((a, b) => a - b);+ const home = lanes.find((l) =>+ overlays.every((o) => laneOf(o) !== l || isEffectOverlay(o) === effect)+ );+ if (home !== undefined) return { lane: home, shiftDown: false };+ if (effect) return { lane: 0, shiftDown: lanes.length > 0 };+ return { lane: lanes.length ? Math.max(...lanes) + 1 : 0, shiftDown: false };+}+/** The playable length of the whole project: video track 0 plus anything that- * runs past it on another video track or the soundtrack. Drives the timeline- * extent, the seek clamp, and export length so content past track 0's end is- * reachable. */+ * runs past it on another video track, the soundtrack, or an element row.+ * Drives the timeline extent, the seek clamp, and export length so content+ * past track 0's end is reachable. */export function projectDuration(s: {clips: VideoClip[];audioClips: AudioClip[];+ overlays: Overlay[];}): number {let end = 0;- // Any clip on any track extends the timeline; a layer running past track 0's- // end is still reachable.+ // Anything on any row extends the timeline: a layer or soundtrack running+ // past track 0's end is still reachable, and so is a title or sticker left+ // standing after the last clip — it plays over black.for (const c of s.clips) end = Math.max(end, c.start + clipLen(c));for (const a of s.audioClips) end = Math.max(end, a.start + clipLen(a));+ for (const o of s.overlays) end = Math.max(end, o.end);return Math.max(0, end);}diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex b8c671cf..3b0c9bea 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -1,7 +1,22 @@+import {+ overlayKind,+ stampOverlayKinds,+ stripDefaultOverlayKinds,+ type ColorGrade,+ type EffectOverlay,+ type LookStyle,+ type OverlayBase,+ type OverlayKind,+ type ShapeKind,+ type ShapeOverlay,+ type StickerOverlay,+ type TextOverlay as KitTextOverlay,+ type WordAccentMode,+} from "@donkeycut/effects-kit";import { getBackend, type CutBackend } from "./backend";import type { VideoProject } from "./genvideo/types";-export type AssetType = "video" | "audio" | "image";+export type AssetType = "video" | "audio" | "image" | "font";/** Default on-timeline length (seconds) a still image occupies when placed —* an image has no intrinsic duration, so the clip carries this as its `out`. */@@ -44,6 +59,12 @@ export function normalizeAspect(a: string | undefined | null): Aspect | null {return `${w}:${h}`;}+/** An overlay's center, held far enough inside the frame that the element it+ * belongs to always has a grabbable piece on screen. Every path that writes a+ * position — dragging in the preview, the inspector's own fields — passes+ * through it, so no route can strand an element off-frame. */+export const clampOverlayPos = (v: number) => Math.min(0.98, Math.max(0.02, v));+/** Output frame in pixels. The short side is pinned to 1080 — the design* short side that text scaling and overlay math assume — and the long side* follows the ratio, rounded to even for the encoder. */@@ -104,7 +125,7 @@ export interface StoredAsset {* drop, or upload), so it belongs in the Media panel. Any value marks media* Cut created or fetched — it lives where it was made (the timeline, a* generation panel, or an AI chat card) and is kept out of the Media panel. */- origin?: "voiceover" | "generated" | "recording" | "stock" | "freeze" | "chat";+ origin?: "voiceover" | "generated" | "recording" | "stock" | "freeze" | "chat" | "sticker";/** BCP-47 of the audio's spoken language, when known (stamped on voiceovers* at synthesis) — what transcription should run its recognizer in. */language?: string;@@ -247,20 +268,10 @@ export interface VideoClip {grade?: ColorGrade;}-/** Per-clip manual color adjustments. Integer sliders, 0 = neutral; the whole- * field is absent when every value is 0, so untouched clips carry nothing. */-export interface ColorGrade {- brightness?: number; // -50..50- contrast?: number; // -50..50- saturation?: number; // -50..50- exposure?: number; // -50..50 (±1 EV)- temperature?: number; // -50..50, positive = warm- hue?: number; // -180..180 degrees-}--/** Slider range for every grade parameter except hue. */-export const GRADE_MAX = 50;-export const GRADE_HUE_MAX = 180;+// Color grading (the dual-renderer math) lives in the effects kit; the model+// types and ranges re-export here so doc-model consumers keep one import.+export { GRADE_HUE_MAX, GRADE_MAX } from "@donkeycut/effects-kit";+export type { ColorGrade } from "@donkeycut/effects-kit";/** Speed slider range. Typed entry and tools may go beyond it; SPEED_FLOOR is* the only hard bound, keeping rates positive so length math stays finite. */@@ -269,6 +280,22 @@ export const SPEED_MAX = 4;export const SPEED_FLOOR = 0.05;/** Longest transition offered; also clamps against the clips it joins. */export const TRANSITION_MAX = 2;+/** What a transition runs for when one is placed on a bare cut. */+export const TRANSITION_DEFAULT_SECONDS = 0.5;++/** A transition as a timeline object of its own: a bar on the transitions row+ * at an absolute time, belonging to no clip. It plays when its window lines up+ * with a place that has a handover to make — a cut it ends on, an open head it+ * starts on, an open tail it ends on — and sits inert anywhere else. Clips+ * moving or deleting leave it exactly where it is. */+export interface TimelineTransition {+ id: string;+ /** Bar start on the timeline, seconds; the window is [start, start+seconds]. */+ start: number;+ /** Blend length, 0.1..TRANSITION_MAX. */+ seconds: number;+ style: TransitionStyle;+}/** Effective whole-video fade length: the stored seconds, capped at half the* project so a fade-in and fade-out never overlap. The one clamp preview and@@ -278,10 +305,12 @@ export function projectFadeSeconds(fade: number | undefined, duration: number):return Math.max(0, Math.min(fade ?? 0, duration / 2));}-/** How a clip hands off to the next one. Every style is a physical overlap:- * the two clips run together for the transition length and the cut shortens- * by it. Directional names describe the motion (pushleft pushes the frame- * leftward; wipeleft's reveal edge travels leftward). */+/** How a clip hands off to the next one. Every style is a render-time blend+ * across the outgoing clip's last transition-length seconds: the incoming+ * clip's first frame arrives over the live tail and playback hands over at+ * the cut. Layout never moves. Directional names describe the motion+ * (pushleft pushes the frame leftward; wipeleft's reveal edge travels+ * leftward). */export type TransitionStyle =| "crossfade"| "crosszoom"@@ -411,46 +440,55 @@ export function overlayAnimStyle(style: AnimStyle): "fade" | "zoom" {return style === "zoom" ? "zoom" : "fade";}-/** Preset filter looks: a named color/effect treatment baked over a clip's- * picture in both preview and export. */-export type LookStyle =- | "vintage"- | "vhs"- | "horror"- | "halation"- | "tech"- | "noir"- | "grain"- | "pastel"- | "blockbuster"- | "dreamy";--export const LOOK_IDS: LookStyle[] = [- "vintage",- "vhs",- "horror",- "halation",- "tech",- "noir",- "grain",- "pastel",- "blockbuster",- "dreamy",-];+/**+ * The entrance/exit a transition style becomes on an open edge.+ *+ * A cut has two pictures to blend; a clip's head or tail has one and nothing+ * against it, so the same drag reads as the clip arriving or leaving. The+ * directional styles keep their direction, the zooms keep their push, and the+ * shaped wipes — which need a second picture to reveal — come through as the+ * ramp closest to them.+ */+const EDGE_ANIM: Record<TransitionStyle, AnimStyle> = {+ crossfade: "fade",+ dipblack: "fade",+ dipwhite: "fade",+ blur: "fade",+ crosszoom: "zoom",+ circleopen: "pop",+ circleclose: "pop",+ splitopen: "pop",+ splitclose: "pop",+ pushleft: "slideleft",+ pushright: "slideright",+ pushup: "slideup",+ pushdown: "slidedown",+ wipeleft: "slideleft",+ wiperight: "slideright",+ wipeup: "slideup",+ wipedown: "slidedown",+};-export const LOOK_LABELS: Record<LookStyle, string> = {- vintage: "Vintage",- vhs: "VHS",- horror: "Analogue horror",- halation: "Halation",- tech: "Modern tech",- noir: "Noir",- grain: "Film grain",- pastel: "Pastel",- blockbuster: "Blockbuster",- dreamy: "Dreamy",+const ANIM_TRANSITION: Record<AnimStyle, TransitionStyle> = {+ fade: "crossfade",+ zoom: "crosszoom",+ pop: "circleopen",+ slideleft: "pushleft",+ slideright: "pushright",+ slideup: "pushup",+ slidedown: "pushdown",};+export const animStyleOfTransition = (style: TransitionStyle): AnimStyle => EDGE_ANIM[style];++export const transitionStyleOfAnim = (style: AnimStyle): TransitionStyle =>+ ANIM_TRANSITION[style] ?? "crossfade";++// Looks (dual preview/export recipes) live in the effects kit; the ids and+// labels re-export here so doc-model consumers keep one import.+export { LOOK_IDS, LOOK_LABELS } from "@donkeycut/effects-kit";+export type { LookStyle } from "@donkeycut/effects-kit";+/** Migrate docs saved before per-clip animations existed: the retired edge* transition styles (fadein/fadeout/zoomin/zoomout ramped one side of a hard* cut) become the equivalent clip animation — fadeout/zoomin on the leading@@ -575,13 +613,15 @@ export interface LibraryTemplate {media: TemplateMedia[];layers: TemplateLayer[];audio: TemplateAudio[];- texts: TextOverlay[];+ texts: Overlay[];cues: SubtitleCue[];}/** What the client sends to save a selection (media are project file names). */export type TemplateSaveInput = Omit<LibraryTemplate, "id" | "addedAt">;-export type FontId = "sf" | "serif" | "rounded" | "mono" | "impact";+/** A font id: one of the base system set, a bundled Google family, or an+ * uploaded font ("asset:<assetId>"). Unknown ids fall back tolerantly. */+export type FontId = string;export interface FontDef {id: FontId;@@ -589,6 +629,7 @@ export interface FontDef {stack: string;}+/** The base system font set, available everywhere with no loading step. */export const FONTS: FontDef[] = [{ id: "sf", label: "SF Pro", stack: '-apple-system, "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif' },{ id: "serif", label: "New York", stack: '"New York", ui-serif, Georgia, "Times New Roman", serif' },@@ -597,43 +638,103 @@ export const FONTS: FontDef[] = [{ id: "impact", label: "Impact", stack: 'Impact, "Arial Black", "Helvetica Neue", sans-serif' },];-export const fontStack = (id: FontId) =>- FONTS.find((f) => f.id === id)?.stack ?? FONTS[0].stack;+// Fonts registered at runtime: the bundled Google families (build-time+// self-hosted via next/font) and per-project uploaded fonts. The page+// registers them before text renders; the engine imports this module but+// never rasterizes, so an empty registry there is fine.+const registeredFonts: FontDef[] = [];+const fontListeners = new Set<() => void>();++export function registerFonts(defs: FontDef[]): void {+ let added = false;+ for (const d of defs) {+ if (FONTS.some((f) => f.id === d.id) || registeredFonts.some((f) => f.id === d.id)) continue;+ registeredFonts.push(d);+ added = true;+ }+ if (added) for (const cb of fontListeners) cb();+}-export interface TextOverlay {- id: string;- text: string;- start: number; // timeline seconds- end: number;- x: number; // center, fraction of frame width 0..1- y: number; // center, fraction of frame height 0..1- size: number; // px at a 1080-wide frame+/** Remove runtime fonts by id (a deleted font asset drops out of the menu). */+export function unregisterFonts(ids: string[]): void {+ let removed = false;+ for (const id of ids) {+ const i = registeredFonts.findIndex((f) => f.id === id);+ if (i >= 0) {+ registeredFonts.splice(i, 1);+ removed = true;+ }+ }+ if (removed) for (const cb of fontListeners) cb();+}++/** Every available font: the base set plus everything registered. */+export function allFonts(): FontDef[] {+ return [...FONTS, ...registeredFonts];+}++/** The registry id an uploaded font asset answers to. */+export const uploadedFontId = (assetId: string) => `asset:${assetId}`;++/** Subscribe to registry changes (UI font menus re-render on registration). */+export function onFontsChanged(cb: () => void): () => void {+ fontListeners.add(cb);+ return () => fontListeners.delete(cb);+}++/** CSS stack for a font id, tolerant of unknown ids (falls back to the first+ * font) so kit-typed elements and older docs always resolve to something. */+export const fontStack = (id: string) =>+ FONTS.find((f) => f.id === id)?.stack ??+ registeredFonts.find((f) => f.id === id)?.stack ??+ FONTS[0].stack;++/** Cut's text element: the kit's, with the font narrowed to the app's ids.+ * `kind` may be absent (docs written before shapes/stickers existed store+ * bare titles); the loader stamps `"text"` and the serializer strips it. */+export interface TextOverlay extends KitTextOverlay {font: FontId;- weight: 400 | 700;- color: string;- shadow: boolean;- plate: boolean; // rounded plate behind the text- plateRadius?: number; // plate corner radius in em (default PLATE_RADIUS)- plateColor?: string; // plate fill color (default black)- plateOpacity?: number; // plate fill opacity 0..1 (default PLATE_OPACITY)- /** Which title track (row) this sits on, 0-based. Tracks are kept- * contiguous: empty ones collapse and dragging past the last adds one. */- lane?: number;- /** Hidden titles stay on the timeline (grayed) but are excluded from the- * played/exported picture. */- hidden?: boolean;- /** Karaoke burn-in: index of the display word (whitespace-split across all- * lines) drawn per the accent treatment — recolored, underlined, or on an- * accent box with a contrast text color. */- highlightWord?: number;- highlightColor?: string;- highlightMode?: WordAccentMode;- highlightText?: string;}-/** How the spoken word lights up in karaoke mode: accent color only, accent- * color plus underline, or an accent box behind the word. */-export type WordAccentMode = "color" | "underline" | "box";+/** Every overlay element kind on the title lanes. Lane order is the single+ * z-order authority, whatever the kind. */+export type Overlay = TextOverlay | ShapeOverlay | StickerOverlay | EffectOverlay;++/** An element's place in the stack: lane 0 is the top row, and a bigger lane+ * number sits further under it. Every renderer stacks by this. */+export const laneOf = (o: { lane?: number }) => o.lane ?? 0;++export const isTextOverlay = (o: Overlay): o is TextOverlay => (o.kind ?? "text") === "text";+export const isShapeOverlay = (o: Overlay): o is ShapeOverlay => o.kind === "shape";+export const isStickerOverlay = (o: Overlay): o is StickerOverlay => o.kind === "sticker";+export const isEffectOverlay = (o: Overlay): o is EffectOverlay => o.kind === "effect";++export const SHAPE_LABELS: Record<ShapeKind, string> = {+ rect: "Rectangle",+ ellipse: "Ellipse",+ line: "Line",+ arrow: "Arrow",+};++/** A patch that may touch any kind's fields (never the discriminant). The+ * kit's shape, narrowed to the app's font ids. */+export type OverlayPatch = Partial<+ Omit<TextOverlay, "kind"> &+ Omit<ShapeOverlay, "kind"> &+ Omit<StickerOverlay, "kind"> &+ Omit<EffectOverlay, "kind">+>;++export { overlayKind, stampOverlayKinds, stripDefaultOverlayKinds };+export type {+ EffectOverlay,+ OverlayBase,+ OverlayKind,+ ShapeKind,+ ShapeOverlay,+ StickerOverlay,+ WordAccentMode,+};/** One subtitle caption, timed against the timeline (not the source files). */export interface SubtitleCue {@@ -724,8 +825,9 @@ export const emptySubtitles = (): SubtitlesBlock => ({export type Selection =| { kind: "clip"; id: string }| { kind: "audio"; id: string }- | { kind: "text"; id: string }+ | { kind: "overlay"; id: string }| { kind: "cue"; id: string }+ | { kind: "transition"; id: string }| null;export interface ClipSpan {@@ -733,8 +835,10 @@ export interface ClipSpan {asset: MediaAsset;start: number; // timeline startlen: number; // own timeline footprint (source length / speed)- /** Cross-dissolve overlap into the next span, in timeline seconds. The next- * span's start already sits `transitionOut` earlier, so the two intersect. */+ /** Blend length into the next span, in timeline seconds: the window+ * `[end - transitionOut, end]` where the next clip's first frame arrives+ * over this clip's live tail. Spans never intersect — the next one starts+ * exactly at this one's end, and plays from its head there. */transitionOut: number;}@@ -753,6 +857,9 @@ export interface ShareFeatures {export type SidePanelTab =| "media"| "library"+ | "elements"+ | "effects"+ | "transitions"| "video"| "image"| "audio"@@ -770,10 +877,14 @@ export interface ProjectDoc {* folds that shape into this one. */clips: VideoClip[];audioClips: AudioClip[];+ /** Transition bars, free objects on the transitions row. Older docs stored+ * transitions and edge animations as clip fields; the loader converts those+ * into bars once. */+ transitions?: TimelineTransition[];/** Legacy: video clips on tracks other than 0, kept a separate array in older* docs. Read on open and merged into `clips`; new saves never write it. */overlayClips?: VideoClip[];- overlays: TextOverlay[];+ overlays: Overlay[];/** Output frame; absent in older projects (which are all 9:16). */aspect?: Aspect;/** Whole-video fades, seconds: in from black at the start, out to black atdiff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.tsindex e4b61a57..34693d73 100644--- a/site/src/cut/server/ai/catalog.ts+++ b/site/src/cut/server/ai/catalog.ts@@ -7,7 +7,7 @@* the exact same state the user sees.*/-import { ANIM_STYLE_IDS, LOOK_IDS, TRANSITION_STYLE_IDS } from "../../lib/types";+import { ANIM_STYLE_IDS, TRANSITION_STYLE_IDS } from "../../lib/types";export interface AiToolDef {name: string;@@ -35,7 +35,7 @@ export const AI_TOOLS: AiToolDef[] = [{name: "get_state",description:- "Read the full current editor state: clips, soundtrack, titles, subtitles, selection, playhead, view settings, publish metadata. Use this whenever the context snapshot is not enough or might be stale.",+ "Read the full current editor state: clips, soundtrack, overlay elements (titles, shapes, stickers), subtitles, selection, playhead, view settings, publish metadata. Use this whenever the context snapshot is not enough or might be stale.",inputSchema: obj({}),},{@@ -93,9 +93,9 @@ export const AI_TOOLS: AiToolDef[] = [{name: "select",description:- "Select a video clip (on any track), soundtrack clip, or title (or clear the selection). Selection drives the inspector panel.",+ "Select a video clip (on any track), soundtrack clip, or overlay element — title, shape, or sticker (or clear the selection). Selection drives the inspector panel.",inputSchema: obj({- kind: { type: "string", enum: ["clip", "audio", "text", "none"], description: "What to select — 'clip' is any video clip, whatever track" },+ kind: { type: "string", enum: ["clip", "audio", "overlay", "none"], description: "What to select — 'clip' is any video clip, whatever track; 'overlay' is any title-lane element" },id: str("The item id (omit for kind=none)"),}, ["kind"]),},@@ -106,7 +106,7 @@ export const AI_TOOLS: AiToolDef[] = [inputSchema: obj({panel: {type: "string",- enum: ["media", "library", "video", "image", "audio", "subtitles", "publish", "none"],+ enum: ["media", "library", "elements", "effects", "transitions", "video", "image", "audio", "subtitles", "publish", "none"],description: "Tab to open, or 'none' to collapse the panel",},}, ["panel"]),@@ -195,15 +195,15 @@ export const AI_TOOLS: AiToolDef[] = [{name: "detach_audio",description:- "iMovie-style Detach Audio: lift a clip's sound onto the soundtrack track (mutes the clip) so it can be edited independently. Select the clip first or pass its id.",+ "Detach Audio: lift a clip's sound onto the soundtrack track (mutes the clip) so it can be edited independently. Select the clip first or pass its id.",inputSchema: obj({ clipId: str("Video clip id (optional if one is selected)") }),},{name: "delete_item",description:- "Delete a video clip (any track), soundtrack clip, or title by id. While track 0 is the only video track, deleting a track-0 clip ripples: its footprint closes and everything after it — clips, titles, captions, soundtrack — slides left in sync; items wholly inside that span are removed with it, straddlers are trimmed. With overlay video tracks present the delete leaves its gap in place (remove_gap closes it). Deletes on other tracks remove just that item.",+ "Delete a video clip (any track), soundtrack clip, or overlay element (title/shape/sticker) by id. While track 0 is the only video track, deleting a track-0 clip ripples: its footprint closes and everything after it — clips, titles, captions, soundtrack — slides left in sync; items wholly inside that span are removed with it, straddlers are trimmed. With overlay video tracks present the delete leaves its gap in place (remove_gap closes it). Deletes on other tracks remove just that item.",inputSchema: obj({- kind: { type: "string", enum: ["clip", "audio", "text"], description: "Item kind — 'clip' is any video clip, whatever track" },+ kind: { type: "string", enum: ["clip", "audio", "overlay"], description: "Item kind — 'clip' is any video clip, whatever track; 'overlay' is any title-lane element" },id: str("Item id"),}, ["kind", "id"]),},@@ -261,7 +261,7 @@ export const AI_TOOLS: AiToolDef[] = [{name: "add_title",description:- "Add a text title overlay. Position is the text center as a fraction of the frame (x,y in 0..1; y=0.42 is the default band). Size is px at 1080-wide.",+ "Add a text title overlay. Position is the text center as a fraction of the frame (x,y in 0..1; y=0.42 is the default band). Size is px at 1080-wide. Font ids come from the graphics skill (system set + the bundled Google families).",inputSchema: obj({text: str("The title text (\\n for line breaks)"),start: num("Start time s (default: playhead)"),@@ -270,32 +270,157 @@ export const AI_TOOLS: AiToolDef[] = [y: num("Center y 0..1 (default 0.42)"),size: num("Font size px at 1080w (default 88)"),color: str("CSS color (default #FFFFFF)"),- font: { type: "string", enum: ["sf", "serif", "rounded", "mono", "impact"], description: "Font family id" },+ font: str("Font id (see the graphics skill; default sf)"),weight: { type: "number", enum: [400, 700], description: "Font weight" },+ italic: bool("Italic"),+ align: { type: "string", enum: ["left", "center", "right"], description: "Multi-line alignment (default center)" },+ letter_spacing: num("Tracking in em (0 = normal, 0.1 = airy)"),+ line_height: num("Line height multiplier (default 1.25)"),+ stroke_color: str("Text outline color"),+ stroke_width: num("Text outline width in em (0..0.15; 0 removes it)"),shadow: bool("Drop shadow (default true)"),plate: bool("Translucent plate behind text (default false)"),+ behind_subject: bool("Sit the text behind the person in the shot (needs a clearly separated speaker)"),+ rotation: num("Degrees clockwise, -180..180"),+ opacity: num("Whole-element opacity 0..1"),}, ["text"]),},{- name: "update_title",+ name: "add_shape",description:- "Update any properties of an existing title overlay (text, timing, position, size, font, weight, color, shadow, plate). This is the tool for 'make this text better' requests — pass the overlay id from the selection or state.",+ "Add a vector shape overlay: rect, ellipse, line, or arrow. Position is the shape center as frame fractions; w/h are frame fractions too (a line/arrow's h is its stroke thickness). Rotation gives lines and arrows their direction.",inputSchema: obj({- id: str("Overlay id"),- text: str("New text"),+ shape: { type: "string", enum: ["rect", "ellipse", "line", "arrow"], description: "Shape kind" },+ start: num("Start time s (default: playhead)"),+ end: num("End time s (default: start+3)"),+ x: num("Center x 0..1 (default 0.5)"),+ y: num("Center y 0..1 (default 0.5)"),+ w: num("Width, fraction of frame width"),+ h: num("Height, fraction of frame height (line/arrow: thickness)"),+ fill: str("CSS color (default #FFFFFF)"),+ fill_opacity: num("Fill opacity 0..1 (rect/ellipse)"),+ radius: num("Rect corner radius, px at 1080 short side"),+ stroke_color: str("Outline color (rect/ellipse)"),+ stroke_width: num("Outline width px at 1080 short side (0 removes it)"),+ rotation: num("Degrees clockwise, -180..180"),+ opacity: num("Whole-element opacity 0..1"),+ }, ["shape"]),+ },+ {+ name: "add_sticker",+ description:+ "Add a sticker overlay from a project image asset (asset ids come from `media`; sticker uploads carry origin \"sticker\"). Width is a frame-width fraction; height follows the source's own aspect.",+ inputSchema: obj({+ asset_id: str("Project image asset id"),+ start: num("Start time s (default: playhead)"),+ end: num("End time s (default: start+3)"),+ x: num("Center x 0..1 (default 0.5)"),+ y: num("Center y 0..1 (default 0.5)"),+ w: num("Width, fraction of frame width (default 0.25)"),+ rotation: num("Degrees clockwise, -180..180"),+ opacity: num("Whole-element opacity 0..1"),+ }),+ },+ {+ name: "update_overlay",+ description:+ "Update any overlay element — title, shape, or sticker — by id (from the selection or state). Titles take text/size/font/weight/color/shadow/plate; shapes take w/h/fill/fill_opacity/radius/stroke; stickers take w. Every kind takes timing, position, rotation, opacity, hidden. This is the tool for 'make this text better' requests too.",+ inputSchema: obj({+ id: str("Overlay element id"),+ text: str("New text (titles)"),start: num("Start s"),end: num("End s"),x: num("Center x 0..1"),y: num("Center y 0..1"),- size: num("Font size px at 1080w"),- color: str("CSS color"),- font: { type: "string", enum: ["sf", "serif", "rounded", "mono", "impact"], description: "Font family id" },- weight: { type: "number", enum: [400, 700], description: "Font weight" },- shadow: bool("Drop shadow"),- plate: bool("Backdrop plate"),- hidden: bool("Hide the title without deleting it"),+ size: num("Font size px at 1080w (titles)"),+ color: str("CSS text color (titles)"),+ font: str("Font id (titles; see the graphics skill)"),+ weight: { type: "number", enum: [400, 700], description: "Font weight (titles)" },+ italic: bool("Italic (titles)"),+ align: { type: "string", enum: ["left", "center", "right"], description: "Multi-line alignment (titles)" },+ letter_spacing: num("Tracking in em (titles; 0 = normal)"),+ line_height: num("Line height multiplier (titles; default 1.25)"),+ shadow: bool("Drop shadow (titles)"),+ plate: bool("Backdrop plate (titles)"),+ behind_subject: bool("Sit the text behind the person in the shot (titles)"),+ w: num("Width, fraction of frame width (shapes/stickers)"),+ h: num("Height, fraction of frame height (shapes)"),+ fill: str("Fill color (shapes)"),+ fill_opacity: num("Fill opacity 0..1 (rect/ellipse)"),+ radius: num("Rect corner radius, px at 1080 short side"),+ stroke_color: str("Outline color — text or shape"),+ stroke_width: num("Outline width: em for titles (0..0.15), px at 1080 for shapes; 0 removes it"),+ rotation: num("Degrees clockwise, -180..180 (0 clears)"),+ opacity: num("Whole-element opacity 0..1 (1 clears)"),+ hidden: bool("Hide the element without deleting it"),+ }, ["id"]),+ },+ {+ name: "create_sticker",+ description:+ "Create a custom sticker from an idea: the hosted image model draws it (signed in, spends credits), the background is removed (people on-device, other subjects via hosted matting), a white die-cut outline is added, and it lands as an origin-\"sticker\" asset placed on the timeline at the playhead. Takes ~10-20s; the tool returns when the sticker is placed.",+ inputSchema: obj({+ idea: str("What the sticker shows, e.g. \"a corgi in sunglasses\""),+ start: num("Start time s (default: playhead)"),+ end: num("End time s (default: start+3)"),+ x: num("Center x 0..1 (default 0.5)"),+ y: num("Center y 0..1 (default 0.5)"),+ w: num("Width, fraction of frame width (default 0.25)"),+ }, ["idea"]),+ },+ {+ name: "add_effect",+ description:+ "Add a time-ranged visual effect element over the video: a zoom into part of the frame, the treatments (grain, vhs, glitch, blur, vignette, lightleak, flash, shake) or a graded look (vintage, horror, halation, tech, noir, pastel, blockbuster, dreamy). It filters everything under it for its window (start..end) and stacks with other effects. Tasteful default: one effect at a time, amount under ~0.5.",+ inputSchema: obj({+ effect: { type: "string", enum: ["zoom", "grain", "vhs", "glitch", "blur", "vignette", "lightleak", "flash", "shake", "vintage", "horror", "halation", "tech", "noir", "pastel", "blockbuster", "dreamy"], description: "Effect id" },+ start: num("Start time s (default: playhead)"),+ end: num("End time s (default: start+3)"),+ amount: num("Strength 0.05..1 (default 0.5). For zoom it is the depth: 0.25 shallow, 0.5 moderate, 1 deep"),+ focus_x: num("Zoom only: the x of the point to zoom into, 0..1 (default 0.5)"),+ focus_y: num("Zoom only: the y of the point to zoom into, 0..1 (default 0.5)"),+ }, ["effect"]),+ },+ {+ name: "set_overlay_animation",+ description:+ "Animate an overlay element (title, shape, or sticker): preset In/Out ramps plus a Loop that runs its whole duration. Omitted slots keep their setting; pass \"none\" to clear one. In/Out styles: fade, pop, zoom, slideleft/slideright/slideup/slidedown (names are the motion direction), typewriter (titles only). Loop styles: pulse, wiggle, spin, float.",+ inputSchema: obj({+ id: str("Overlay element id"),+ in_style: str("Entrance style, or \"none\" to clear"),+ in_seconds: num("Entrance ramp seconds 0.1..2 (default 0.5)"),+ out_style: str("Exit style, or \"none\" to clear"),+ out_seconds: num("Exit ramp seconds 0.1..2 (default 0.5)"),+ loop_style: str("Loop style, or \"none\" to clear"),+ loop_speed: num("Loop rate multiplier 0.25..4 (default 1)"),}, ["id"]),},+ {+ name: "set_overlay_keyframes",+ description:+ "Give an overlay element a keyframed pose track, for motion the presets cannot express (a path across the frame, a slow push in, a hold-then-drift). Each key is a whole pose at a time measured in seconds from the element's own start; the pose moves linearly between keys and holds outside them. Omitted fields on a key take the element's current value. Pass an empty list to clear the track and return the element to its resting pose. Preset In/Out/Loop animation still composes on top, so a keyframed title can also fade in.",+ inputSchema: obj(+ {+ id: str("Overlay element id"),+ keys: {+ type: "array",+ description: "Keys in any order; two at the same time collapse to one",+ items: obj(+ {+ t: num("Seconds from the element's start"),+ x: num("Center x, fraction of frame width 0..1"),+ y: num("Center y, fraction of frame height 0..1"),+ scale: num("Size multiplier, 1 = the element's own size (0.1..4)"),+ rotation: num("Degrees clockwise, -180..180"),+ opacity: num("0..1"),+ },+ ["t"]+ ),+ },+ },+ ["id", "keys"]+ ),+ },{name: "update_audio",description:@@ -698,7 +823,7 @@ export const AI_TOOLS: AiToolDef[] = [{name: "set_transition",description:- "Set the transition from this clip into the next clip on its track (any video track), in seconds (0 clears it, max 2). Every style overlaps the two clips, so the cut shortens by the duration. On upper tracks every style blends as an alpha dissolve (the tracks beneath show through). Only valid when a next same-track clip exists. Each edge holds one effect: setting a transition clears the animations adjacent to its joint (and set_animation on that edge replaces the transition). Read the transitions-and-fades skill before styling cuts.",+ "Set the transition from this clip into the next clip on its track (any video track), in seconds (0 clears it, max 2). A transition is a blend across the cut — it never moves, trims or overlaps clips, and it plays only while the pair touches. On upper tracks every style blends as an alpha dissolve (the tracks beneath show through). Only valid when a next same-track clip exists. Each edge holds one effect: setting a transition clears the animations adjacent to its joint (and set_animation on that edge replaces the transition). Read the transitions-and-fades skill before styling cuts.",inputSchema: obj({clipId: str("Video clip id (the clip the transition starts from)"),seconds: num("Transition length in seconds, 0–2 (0 = hard cut)"),@@ -712,7 +837,7 @@ export const AI_TOOLS: AiToolDef[] = [{name: "set_animation",description:- "Animate one clip's own entrance (which:'in') or exit (which:'out'): fade, zoom, pop, or a slide named by its motion direction. style 'none' clears. Track-0 clips take every style; upper-track clips only fade and zoom. Each edge holds one effect, last pick wins: animating an edge a transition owns replaces that transition (the pair returns to a hard cut), and setting a transition clears the animations adjacent to its joint. At an abutting cut the animation plays over the neighbor's held frame; at the timeline's ends and across gaps it plays against black.",+ "Animate one clip's own entrance (which:'in') or exit (which:'out'): fade, zoom, pop, or a slide named by its motion direction. style 'none' clears. Track-0 clips take every style; upper-track clips only fade and zoom. Each edge holds one effect, last pick wins: animating an edge a transition owns replaces that transition, and setting a transition clears the animations adjacent to its joint. At an abutting cut the animation plays over the neighbor's held frame; at the timeline's ends and across gaps it plays against black.",inputSchema: obj({clipId: str("Video clip id"),which: { type: "string", enum: ["in", "out"], description: "Entrance or exit" },@@ -724,20 +849,6 @@ export const AI_TOOLS: AiToolDef[] = [seconds: num("Ramp length in seconds, 0.1–2 (default 0.5)"),}, ["clipId", "which", "style"]),},- {- name: "set_look",- description:- "Apply a preset filter look to a video clip's picture (any track; stills too): vintage, vhs, horror (analogue horror), halation (highlight bloom), tech, noir, grain, pastel, blockbuster (teal-orange), dreamy. amount 0.05–1 scales the strength (default 1); style 'none' clears. Composes with set_color_grade — the look is the base, the grade rides on top.",- inputSchema: obj({- clipId: str("Video clip id"),- style: {- type: "string",- enum: [...LOOK_IDS, "none"],- description: "Look id, or 'none' to clear",- },- amount: num("Strength 0.05–1 (default 1)"),- }, ["clipId", "style"]),- },{name: "merge_cue",description:@@ -794,13 +905,13 @@ Times are in seconds on the shared timeline. The playhead is currentTime; a skim- Two ways to move a track-0 clip: place_clip sets its start (respects gaps, slides right if the spot is taken); move_clip reorders by index, opening a slot at the landing point — clips after it shift right, every other gap survives. Index-based inserts (freeze_frame, generated clips) open a slot the same way.- add_clip puts a project asset on the timeline the way a drag does: video/image onto track 0 (a \`start\`, an \`index\` insert, or appended at the end), audio onto the soundtrack.- Overlay video: a video/image asset can sit on a track above track 0 (track 1, 2… — topmost wins). A full-frame overlay covers everything below it; give it a layout to share the frame — top/bottom/left/right halves for a split screen, pip for a floating corner box, or a custom region rect. add_overlay_video creates one from a media asset; update_overlay_video moves/trims/regions/mutes/hides it. The user makes them by dragging media above track 0; they drag the region in the preview.-- A clip's timeline length is (out-in)/speed; total duration runs to the last clip's end, gaps included, minus cross-style transition overlaps.+- A clip's timeline length is (out-in)/speed; total duration runs to the last clip's end, gaps included. Transitions blend at cuts and never change layout or length.- trim_clip changes in/out inside the source media. in >= 0, out <= source duration, out-in >= 0.1.- set_speed sets a clip's playback rate; it changes the clip's timeline length, and later titles/captions ripple to stay in sync.-- set_transition joins a clip into the next one (0–2s, 17 styles); set_animation animates one clip's own entrance/exit; set_look grades its picture with a preset filter — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition.+- set_transition joins a clip into the next one (0–2s, 17 styles); set_animation animates one clip's own entrance/exit — read the transitions-and-fades skill before styling cuts. Splitting or deleting clears the affected transition. Grading a clip's picture is add_effect: an effect dropped over a clip opens covering it.- split_at cuts the track-0 clip under that time into two clips at the exact frame. With a soundtrack or overlay clip selected it splits that instead.- The user can multi-select (⌘/⇧-click) and delete several items at once; a hover chip on each video clip toggles its own audio.-- Anything can be hidden instead of deleted: it stays on the timeline (grayed) but drops out of playback and export — a hidden video clip plays black and silent. Per item: set_clip_hidden, or the \`hidden\` field on update_overlay_video/update_title/update_audio. Whole rows: set_track_hidden (video/soundtrack/text/subtitles) and set_track_muted (video) — the eye/speaker toggles on the track headers.+- Anything can be hidden instead of deleted: it stays on the timeline (grayed) but drops out of playback and export — a hidden video clip plays black and silent. Per item: set_clip_hidden, or the \`hidden\` field on update_overlay_video/update_overlay/update_audio. Whole rows: set_track_hidden (video/soundtrack/text/subtitles) and set_track_muted (video) — the eye/speaker toggles on the track headers.- detach_audio lifts a video clip's sound to the soundtrack track (and mutes the clip) so audio can be cut independently of video.- freeze_frame grabs one frame (default: the playhead — what the user currently sees) as a still clip and inserts it, by default at index 0 as a cover/hook frame ("make this the first frame"). The still is baked at the project's current aspect with the clip's framing applied; if the user later switches aspect they should capture a fresh one.- set_framing: per-clip Fit (letterbox) vs Fill (crop to cover the project frame). In Fill, panX/panY position the crop window; the user can also drag the video directly in the preview. The control lives in the Inspector under "Framing" when a video clip is selected. Landscape footage usually wants fill + a pan that keeps the subject.@@ -833,9 +944,8 @@ Cutting speech well: pace is part of the message. Keep a beat of the speaker's o"transitions-and-fades": `# Transitions, animations, looks & fadesRoute the ask to the right feature:-- set_transition: a styled join between one video clip and the next. Every style overlaps the clips, so the cut shortens by the duration.+- set_transition: a styled join between one video clip and the next, blended across the cut. It never moves clips or shortens anything, and it plays only while the pair touches.- set_animation: one clip's own entrance ("in") or exit ("out") — the clip fades/zooms/pops/slides on its own edge. Never moves neighbors. For "fade this clip in", "make it slide in", use this. A wipe is a transition, not an animation.-- set_look: a preset filter over one clip's whole picture (vintage, vhs, horror, halation, tech, noir, grain, pastel, blockbuster, dreamy) with an amount knob.- set_project_fade: the whole video fades in from black at the start and/or out to black at the end — picture and full mix (titles, captions, soundtrack). Survives clip reordering. For "fade in the video", "fade to black at the end", use this.- update_audio fadeIn/fadeOut: audio-only ramps on one soundtrack clip ("fade the music out").@@ -844,11 +954,20 @@ set_animation styles: fade (audio follows), zoom, pop, slideleft/right/up/downPicking for a vibe: "smooth" → crossfade; "punchy/energetic" → crosszoom or a push; "dramatic scene change" → dipblack 0.5–0.8s; "dreamy" → blur (or the dreamy look); "retro" → vhs or vintage look. Between clips 0.4–0.8s reads well; 1s+ is slow and cuts total duration.UI: select a clip → Inspector "Effects" opens the panel (Transition / In / Out / Looks tabs); a blue badge marks each styled joint on the timeline. Preview and export render the same treatment.`,- "titles": `# Titles (text overlays)-Each overlay: text, start/end (seconds visible), x/y center (fractions 0..1 of the project frame), size (frame px; the design short side is 1080), font (sf=SF Pro, serif=New York, rounded, mono, impact), weight (400/700), color (any CSS color), shadow (bool), plate (translucent dark plate behind the text).-Inspector shows these when a title is selected. The color row has fixed swatches, a custom picker, and the last 3 custom colors.+ "graphics": `# Graphics: titles, shapes & stickers+The title lanes hold three overlay element kinds, all sharing timing (start/end), center position (x/y fractions 0..1), rotation (degrees), opacity, and a lane; \`overlays\` in editor_state lists them with their \`kind\`. All burn into the export exactly as previewed.+Titles (add_title / update_overlay): text, size (frame px; the design short side is 1080), font (sf=SF Pro, serif=New York, rounded, mono, impact), weight (400/700), color, shadow, plate (translucent dark backdrop).+Shapes (add_shape): rect, ellipse, line, arrow. w/h are frame fractions; rect/ellipse take fill + fill_opacity, corner radius (rect), and an outline (stroke_color/stroke_width); line/arrow draw in \`fill\` with h as their thickness, and rotation gives them their direction (0° points right, 90° points down).+Stickers (add_sticker): a project image asset (generated cutouts in the Elements panel carry origin "sticker"); w is a frame-width fraction and height follows the source's aspect. Lottie JSON uploads become animated stickers that loop for the element's duration.+Custom stickers (create_sticker): one call generates the image, removes the background, adds the die-cut outline, and places it — use it when the user asks for a sticker of something they don't have (it spends credits like image generation).+Effects (add_effect): time-ranged treatments over the finished picture — the footage and everything laid over it. Two families, one list: the treatments (grain, vhs, glitch, blur, vignette, lightleak, flash, shake) and the graded looks (vintage, horror, halation, tech, noir, pastel, blockbuster, dreamy). Placed like any element and tuned with \`amount\` (update_overlay); an effect added over a clip opens covering that clip, and trims like anything else. One effect at a time reads best, amounts under ~0.5.+Advanced text (update_overlay): italic, align (multi-line), letter_spacing (em), line_height, stroke_color/stroke_width (em outline behind the fill), and richer shadows. Bundled Google families join the system set — inter, montserrat, poppins, oswald, space-grotesk, playfair, caveat, bebas, anton, archivo-black, bangers, lobster, pacifico, permanent-marker, dm-serif — and the user can upload .ttf/.otf fonts (they appear as font ids like "asset:<id>").+Animation (set_overlay_animation): every element takes preset In/Out ramps (fade, pop, zoom, slides, typewriter for titles) and a Loop (pulse, wiggle, spin, float) that runs its whole duration. Entrances 0.3–0.6s read well; one loop per scene, sparingly.+Keyframes (set_overlay_keyframes): for motion no preset covers — a path across the frame, a slow push in, a drift that holds first. A key is a whole pose (position, scale, rotation, opacity) at a time in seconds from the element's start; the pose moves linearly between keys and holds outside them, and presets still compose on top. Two or three keys carry almost everything; reach for a preset first and keyframes when the user describes a specific path or timing. In the UI the diamond in the inspector adds a key at the playhead, and dragging the element then records into it.+Behind the speaker: a title with behind_subject sits behind the person in the shot (on-device person segmentation; preview and export match). It reads well when the speaker is clearly separated from the background; with no detectable person it degrades to a normal front title. Groups: the user can group elements (select several, Group in the inspector) — selecting one selects all, and moves/resize/rotate/timing ride together.Good TikTok titles: short punchy lines, high contrast (white/yellow + shadow or plate), size 72–110, keep inside the middle 80% of the frame (x 0.1..0.9, y 0.1..0.9), avoid the caption band (y≈0.8) when subtitles are on.-Titles burn into the export exactly as previewed.`,+Tasteful graphics: shapes read best as accents (a highlight box behind a stat, an arrow pointing at the subject, a color bar under a title) — semi-transparent fills (fill_opacity 0.2–0.5) sit better over footage than solid blocks. One or two stickers a scene; size 0.15–0.3 of the frame width.+In the UI: the timeline toolbar adds Text; the Elements side-panel tab browses stickers and shapes and creates sticker images, and the Effects tab holds the effects — a click in any panel picks a tile, and dragging one onto the timeline is what places it; dragging in the preview places an element, its corner handle resizes, the top handle rotates; the Inspector edits every field.`,"audio-and-subtitles": `# Audio, voiceover & subtitlesSoundtrack clips: volume 0..1.5, fadeIn/fadeOut seconds (max half the clip), start = timeline position, in/out = trim inside the source; clips can spread across several soundtrack lanes (the \`lane\` field), new sounds slide to free space in their lane. Fades render with ffmpeg afade on export.diff --git a/site/src/cut/server/cloud/projects.ts b/site/src/cut/server/cloud/projects.tsindex 72f28d51..52d3c915 100644--- a/site/src/cut/server/cloud/projects.ts+++ b/site/src/cut/server/cloud/projects.ts@@ -184,6 +184,7 @@ export const projectsCloud = {name: typeof body.name === "string" && body.name.trim() ? body.name.trim() : existing.name,assets: Array.isArray(body.assets) ? body.assets : existing.assets,clips: Array.isArray(body.clips) ? body.clips : existing.clips,+ transitions: Array.isArray(body.transitions) ? body.transitions : existing.transitions,audioClips: Array.isArray(body.audioClips) ? body.audioClips : existing.audioClips,// Same legacy-shape handling as the engine: a merged client saving// `clips` clears the old separate overlay array.diff --git a/site/src/cut/server/exportPipeline.ts b/site/src/cut/server/exportPipeline.tsindex b9fe3e99..72d06256 100644--- a/site/src/cut/server/exportPipeline.ts+++ b/site/src/cut/server/exportPipeline.ts@@ -3,8 +3,7 @@ import { stat, writeFile } from "node:fs/promises";import path from "node:path";import { atempoChain, hasStream, num, videoColorInfo } from "./util";import { projectFadeSeconds, TRANSITION_XFADE, TRANSITION_ZOOM, type ColorGrade, type TransitionStyle } from "../lib/types";-import { gradeToFfmpegFilter } from "../lib/colorGrade";-import { lookFilterLines } from "../lib/looks";+import { effectFilterLines, gradeToFfmpegFilter, lookFilterLines } from "@donkeycut/effects-kit";// The render pipeline itself: spec in, finished mp4 out. Shared by the local// engine's job registry (jobs.ts) and the cloud render worker, which stage@@ -111,7 +110,45 @@ export interface ExportSpec {* this gain (0..1). Ducking clips never duck each other. */duck?: number;}[];- overlays: { file: string; start: number; end: number }[];+ /** Overlay elements. A static element is one full-frame PNG windowed with+ * `enable`. An animated element ships `frames` — a region-cropped slideshow+ * (file + seconds each, repeats allowed) played via the concat demuxer and+ * overlaid at (x, y), with `blank` (a region-sized transparent PNG) padding+ * the timeline before and after its window. */+ overlays: {+ file?: string;+ start: number;+ end: number;+ x?: number;+ y?: number;+ blank?: string;+ frames?: { file: string; duration: number }[];+ /** Text-behind-speaker: composite this element beneath the alphamerged+ * person cutout (needs `behindMask`). */+ behind?: boolean;+ /** Its row: lane 0 is the top of the stack. Elements composite deepest+ * lane first, and effects interleave with them by the same number. */+ lane?: number;+ }[];+ /** The page-rendered person mask video (grayscale, white = person) for the+ * behind-tagged overlays: starts at `from` timeline seconds and covers the+ * union of their windows. */+ behindMask?: { file: string; from: number };+ /** Time-ranged effect elements — the spec carries ids and knobs; the+ * LGPL-safe chains are built here from the kit's recipes. Each one grades+ * what plays under it: the video, the overlay tracks, and every element on+ * a lane below its own. */+ effects?: {+ effect: string;+ amount?: number;+ focus?: { x: number; y: number };+ /** Seconds a zoom takes to reach its depth. */+ ramp?: number;+ /** Its row in the element stack; lane 0 is the top. */+ lane?: number;+ start: number;+ end: number;+ }[];/** Burned-in subtitle stills. Kept apart from `overlays` (titles may* overlap each other): each subtitle track (`lane`, absent = 0) is* non-overlapping and chronological within itself and renders as one@@ -345,9 +382,41 @@ export async function runExport(colorFix.set(f, sdrConvert(await videoColorInfo(paths[i])));}));- for (const o of spec.overlays) {- inputIndex.set(o.file, nInputs++);- inputs.push("-i", path.join(job.tmpDir, path.basename(o.file)));+ // Animated overlays: each is its own concat-demuxer slideshow (region-sized+ // frames with transparent filler around the element's window), the exact+ // mechanism the caption lanes use. Static overlays stay single PNG inputs.+ const animOverlayInput = new Map<number, number>();+ for (let k = 0; k < spec.overlays.length; k++) {+ const o = spec.overlays[k];+ if (o.frames?.length && o.blank) {+ const blank = path.join(job.tmpDir, path.basename(o.blank));+ const lines = ["ffconcat version 1.0"];+ if (o.start > 1e-3) lines.push(`file '${blank}'`, `duration ${num(o.start)}`);+ let cursor = o.start;+ for (const f of o.frames) {+ if (f.duration < 1e-4) continue;+ lines.push(+ `file '${path.join(job.tmpDir, path.basename(f.file))}'`,+ `duration ${num(f.duration)}`+ );+ cursor += f.duration;+ }+ if (spec.duration - cursor > 1e-3) {+ lines.push(`file '${blank}'`, `duration ${num(spec.duration - cursor)}`);+ }+ const list = path.join(job.tmpDir, `overlay_anim_${k}.ffconcat`);+ await writeFile(list, lines.join("\n") + "\n");+ animOverlayInput.set(k, nInputs++);+ inputs.push("-f", "concat", "-safe", "0", "-i", list);+ } else if (o.file) {+ inputIndex.set(o.file, nInputs++);+ inputs.push("-i", path.join(job.tmpDir, path.basename(o.file)));+ }+ }+ let behindMaskInput: number | undefined;+ if (spec.behindMask) {+ behindMaskInput = nInputs++;+ inputs.push("-i", path.join(job.tmpDir, path.basename(spec.behindMask.file)));}// Looped input per still image, sized to the clip's timeline length so the@@ -782,16 +851,20 @@ export async function runExport(}});- // Join the segments. Adjacent clips with a transition cross-dissolve- // (xfade/acrossfade, overlapping by the transition length); the rest hard-cut- // (concat). Fold left so mixed sequences chain correctly.+ // Join the segments. Clips abut — a transition claims no layout — so every+ // join keeps the accumulator's full length. A transitioned join pads the+ // incoming segment's head with its cloned first frame and runs the xfade+ // across the outgoing clip's last blend-window seconds: the held frame+ // arrives over the live tail, and the real segment starts exactly at the+ // cut. Its sound is a tail fade on the outgoing side and a hard join. The+ // rest hard-cut (concat). Fold left so mixed sequences chain correctly.let vAcc = segLabel[0];let aAcc = "a0";let acc = clipDur(spec.clips[0]); // running timeline length of the accumulatorfor (let j = 1; j < spec.clips.length; j++) {const prev = spec.clips[j - 1];const durJ = clipDur(spec.clips[j]);- // The overlap can't exceed most of either clip, matching the editor clamp.+ // The blend can't exceed most of either clip, matching the editor clamp.const d = Math.min(prev.transition ?? 0, acc * 0.9, durJ * 0.9);const vOut = `vj${j}`;const aOut = `aj${j}`;@@ -800,14 +873,15 @@ export async function runExport(// The style id resolves through the allowlist map; anything unknown// (or an old spec without a style) renders as a plain fade.const kind = TRANSITION_XFADE[prev.transitionStyle as TransitionStyle] ?? "fade";- filters.push(`[${vAcc}][${segLabel[j]}]xfade=transition=${kind}:duration=${num(d)}:offset=${num(offset)}[${vOut}]`);- filters.push(`[${aAcc}][a${j}]acrossfade=d=${num(d)}[${aOut}]`);- acc = acc + durJ - d;+ filters.push(`[${segLabel[j]}]tpad=start_duration=${num(d)}:start_mode=clone[vh${j}]`);+ filters.push(`[${vAcc}][vh${j}]xfade=transition=${kind}:duration=${num(d)}:offset=${num(offset)}[${vOut}]`);+ filters.push(`[${aAcc}]afade=t=out:st=${num(offset)}:d=${num(d)}[ah${j}]`);+ filters.push(`[ah${j}][a${j}]concat=n=2:v=0:a=1[${aOut}]`);} else {filters.push(`[${vAcc}][${segLabel[j]}]concat=n=2:v=1:a=0[${vOut}]`);filters.push(`[${aAcc}][a${j}]concat=n=2:v=0:a=1[${aOut}]`);- acc = acc + durJ;}+ acc = acc + durJ;vAcc = vOut;aAcc = aOut;}@@ -926,20 +1000,96 @@ export async function runExport(let vLabel = vAcc;for (const oc of overlayVideos) vLabel = addOverlay(oc, vLabel);- // Burn in text overlays, each windowed to its timeline range. Half-open so- // back-to-back overlays sharing a boundary never composite on the same frame.- spec.overlays.forEach((o, k) => {- const idx = inputIndex.get(o.file)!;+ // Burn in overlay elements. Static ones are full-frame PNGs windowed with+ // `enable` (half-open, so back-to-back overlays sharing a boundary never+ // composite on the same frame); animated ones play their region slideshow+ // at the region's own position — the transparent filler covers the rest of+ // the timeline, so no enable window is needed.+ const compositeOverlayEntry = (k: number, onto: string): string => {+ const o = spec.overlays[k];const next = `vov${k}`;+ const animIdx = animOverlayInput.get(k);+ if (animIdx !== undefined) {+ filters.push(`[${animIdx}:v]fps=${fps},format=yuva420p,setsar=1[oanim${k}]`);+ filters.push(+ `[${onto}][oanim${k}]overlay=${num(o.x ?? 0)}:${num(o.y ?? 0)}:eof_action=pass[${next}]`+ );+ } else if (o.file) {+ const idx = inputIndex.get(o.file)!;+ filters.push(+ `[${onto}][${idx}:v]overlay=0:0:enable='gte(t,${num(o.start)})*lt(t,${num(o.end)})'[${next}]`+ );+ } else {+ return onto;+ }+ return next;+ };++ // Text-behind-speaker: the composite splits, the behind-tagged elements+ // burn onto one branch, and the other branch — alphamerged with the+ // page-rendered person mask (standard LGPL filters) — lays the subject+ // back over them. Front overlays then continue on the merged stream.+ const behindKs = spec.behindMask+ ? spec.overlays.flatMap((o, k) => (o.behind ? [k] : []))+ : [];+ if (spec.behindMask && behindMaskInput !== undefined && behindKs.length > 0) {+ filters.push(`[${vLabel}]split[bh_text][bh_person]`);+ let textLab = "bh_text";+ for (const k of behindKs) textLab = compositeOverlayEntry(k, textLab);filters.push(- `[${vLabel}][${idx}:v]overlay=0:0:enable='gte(t,${num(o.start)})*lt(t,${num(o.end)})'[${next}]`+ `[${behindMaskInput}:v]fps=${fps},scale=${spec.width}:${spec.height},format=gray,` ++ `tpad=start_duration=${num(Math.max(0, spec.behindMask.from))}:color=black[bh_mask]`);- vLabel = next;- });+ filters.push(`[bh_person]format=rgba[bh_rgba]`);+ filters.push(`[bh_rgba][bh_mask]alphamerge[bh_cut]`);+ filters.push(`[${textLab}][bh_cut]overlay=0:0:eof_action=pass[bh_done]`);+ vLabel = "bh_done";+ }+ // The element stack, deepest lane first, with the effects standing in it:+ // an effect grades what plays under it, so everything below its lane is+ // composited before its chain runs, and the elements above it land on the+ // graded picture untouched. Each chain is gated to its own window (the shake+ // recipe swaps in a jittered branch through an overlay instead, so nothing+ // else rescales).+ const laneOfEntry = (k: number) => spec.overlays[k].lane ?? 0;+ const stacked = spec.overlays+ .map((o, k) => k)+ .filter((k) => !(spec.overlays[k].behind && behindKs.includes(k)))+ .sort((a, b) => laneOfEntry(b) - laneOfEntry(a));+ const effects = (spec.effects ?? [])+ .map((e, i) => ({ e, i }))+ .sort((a, b) => (b.e.lane ?? 0) - (a.e.lane ?? 0));+ let placed = 0;+ const compositeDownTo = (lane: number) => {+ while (placed < stacked.length && laneOfEntry(stacked[placed]) > lane) {+ vLabel = compositeOverlayEntry(stacked[placed++], vLabel);+ }+ };+ for (const { e, i } of effects) {+ compositeDownTo(e.lane ?? 0);+ const lines = effectFilterLines(+ vLabel,+ `vfx${i}`,+ e.effect,+ e.amount,+ Math.max(0, e.start),+ Math.min(e.end, spec.duration),+ spec.width,+ spec.height,+ `fx${i}`,+ e.focus,+ e.ramp+ );+ if (!lines) continue;+ filters.push(...lines);+ vLabel = `vfx${i}`;+ }+ compositeDownTo(-Infinity);// Subtitle stills ride one concat-demuxer slideshow per track (transparent// filler in the gaps), so a karaoke cut with hundreds of word windows still- // costs one ffmpeg input per language instead of one per still.+ // costs one ffmpeg input per language instead of one per still. They sit+ // over every element and every effect.captionInputs.forEach((idx, k) => {filters.push(`[${idx}:v]fps=${fps},format=yuva420p,setsar=1[caps${k}]`);filters.push(`[${vLabel}][caps${k}]overlay=0:0:eof_action=pass[vcaps${k}]`);diff --git a/site/src/cut/server/http/projects.ts b/site/src/cut/server/http/projects.tsindex 8578851d..de4b8fde 100644--- a/site/src/cut/server/http/projects.ts+++ b/site/src/cut/server/http/projects.ts@@ -109,6 +109,7 @@ export const projectsApi = {name: typeof body.name === "string" && body.name.trim() ? body.name.trim() : existing.name,assets: Array.isArray(body.assets) ? body.assets : existing.assets,clips: Array.isArray(body.clips) ? body.clips : existing.clips,+ transitions: Array.isArray(body.transitions) ? body.transitions : existing.transitions,audioClips: Array.isArray(body.audioClips) ? body.audioClips : existing.audioClips,// Layer clips now live in `clips` (each with its `track`). A merged// client saves `clips` with no `overlayClips`, which clears the legacy@@ -336,7 +337,8 @@ export const projectsApi = {if (!(file instanceof File)) return err("No image in upload.", 400);const nameField = form.get("name");const name = typeof nameField === "string" && nameField.trim() ? nameField.trim() : file.name;- const origin = form.get("origin") === "generated" ? "generated" : undefined;+ const raw = form.get("origin");+ const origin = raw === "generated" || raw === "sticker" ? raw : undefined;const fileName = await saveMedia(id, file);const dims = await probeDims(mediaPath(id, fileName));return Response.json({diff --git a/site/src/cut/server/transcribe.ts b/site/src/cut/server/transcribe.tsindex cc0f39bb..832be513 100644--- a/site/src/cut/server/transcribe.ts+++ b/site/src/cut/server/transcribe.ts@@ -112,7 +112,8 @@ export async function ensureStt(): Promise<string> {return bin;}-/** Group word timings into short caption-sized cues (CapCut/Opus style). */+/** Group word timings into short caption-sized cues — a few words at a time,+ * the way captions read on a phone. */export function groupWords(words: Word[]): Cue[] {const MAX_CHARS = 38;const MAX_DUR = 3.5;@@ -357,10 +358,10 @@ async function runTranscribe(job: TranscribeJob, spec: TranscribeSpec) {filters.push(`anullsrc=r=16000:cl=mono,atrim=0:${num(dur)},asetpts=PTS-STARTPTS[a${j}]`);}});- // Join clip audio exactly as the timeline (and export) do: adjacent clips- // with a cross-dissolve overlap by the transition length (acrossfade), the- // rest concatenate. A flat concat would run longer than the timeline, so- // every cue after a dissolve would land progressively late.+ // Join clip audio exactly as the timeline (and export) do: clips abut, a+ // transition fades the outgoing clip's tail while the next enters clean at+ // the cut, so the chain is a flat concat with tail fades — the mix runs+ // exactly the timeline's length and every cue lands where it plays.// Skipped entirely for an audio-only cut (no clips) — there is no clip-audio// chain to build, only the soundtrack, mixed below. (`spec.clips[0]` would be// undefined otherwise.)@@ -374,12 +375,12 @@ async function runTranscribe(job: TranscribeJob, spec: TranscribeSpec) {const d = Math.min(prev.transition ?? 0, acc * 0.9, durJ * 0.9);const out = `aj${j}`;if (d > 0.01) {- filters.push(`[${aAcc}][a${j}]acrossfade=d=${num(d)}[${out}]`);- acc = acc + durJ - d;+ filters.push(`[${aAcc}]afade=t=out:st=${num(acc - d)}:d=${num(d)}[af${j}]`);+ filters.push(`[af${j}][a${j}]concat=n=2:v=0:a=1[${out}]`);} else {filters.push(`[${aAcc}][a${j}]concat=n=2:v=0:a=1[${out}]`);- acc = acc + durJ;}+ acc = acc + durJ;aAcc = out;}}