Open source CapCut alternative.
TypeScript
feat(site): honor base-track gaps in playback, drops, and new projects
David Le3efc874b3c79
diff --git a/site/src/cut/components/Editor.tsx b/site/src/cut/components/Editor.tsxindex 4aa34f3f..760eab4a 100644--- a/site/src/cut/components/Editor.tsx+++ b/site/src/cut/components/Editor.tsx@@ -10,7 +10,7 @@ import { useExport } from "@/cut/lib/exportStore";import { fileZoneAt, hasRefDrag } from "@/cut/lib/assetRef";import { enrichAsset, importFileToProject } from "@/cut/lib/media";import { backTarget, useCutBase } from "@/cut/lib/nav";-import { getClipSpans, projectDuration, serializeDoc, useEditor } from "@/cut/lib/store";+import { projectDuration, serializeDoc, useEditor } from "@/cut/lib/store";import type { MediaAsset } from "@/cut/lib/types";import { AiPanel } from "./AiPanel";import { ExportDialog } from "./ExportDialog";@@ -19,7 +19,7 @@ import { Inspector } from "./Inspector";import { Lightbox } from "./Lightbox";import { Preview } from "./Preview";import { SidePanel } from "./SidePanel";-import { Timeline, videoInsertIndex } from "./Timeline";+import { Timeline } from "./Timeline";import { TopBar } from "./TopBar";export function Editor({@@ -205,19 +205,10 @@ export function Editor({const s = useEditor.getState();s.addAsset(asset);if (asset.type === "video" || asset.type === "image") {- // A drop on the timeline inserts at the pointer's slot; anywhere- // else appends at the end. A still rides the base track like footage.- if (at == null) {- s.addClipFromAsset(asset.id);- } else {- const spans = getClipSpans(s.clips, s.assets);- const spanIndex = videoInsertIndex(spans, at);- const clipsIndex =- spanIndex < spans.length- ? s.clips.findIndex((c) => c.id === spans[spanIndex].clip.id)- : s.clips.length;- s.addClipFromAsset(asset.id, clipsIndex);- }+ // A drop on the timeline lands at the pointer (sliding to the base+ // track's next free slot); anywhere else appends at the end. A+ // still rides the base track like footage.+ s.addClipFromAsset(asset.id, at ?? undefined);} else {// A timeline drop lands at the pointer; anywhere else drops at the// playhead (the store slides it right only if that spot is taken).diff --git a/site/src/cut/hooks/usePlayback.ts b/site/src/cut/hooks/usePlayback.tsindex 3ca48632..830a4270 100644--- a/site/src/cut/hooks/usePlayback.ts+++ b/site/src/cut/hooks/usePlayback.ts@@ -639,12 +639,14 @@ class Engine {t = Math.max(span.start, Math.min(t, span.start + span.len));atEnd = el.currentTime >= span.clip.out - 0.02 || el.ended;}- // Clip boundary: hand off to the next clip, or (if the base is done but an- // upper/lower track runs on) fall through to the wall-clock tail.+ // Clip boundary: hand off to the next clip when it abuts (or dissolves),+ // fall into the gap when it doesn't — the base plays black there and the+ // wall clock advances — or (if the base is done but an upper/lower track+ // runs on) fall through to the wall-clock tail.if (atEnd) {const idx = spans.indexOf(span);const next = spans[idx + 1];- if (next) {+ if (next && next.start <= span.start + span.len + 0.001) {// Jump past the finished clip's whole footprint (including any// cross-dissolve overlap), not back to next.start — which still sits// inside the outgoing clip's footprint, so find() would re-pick the@@ -653,6 +655,12 @@ class Engine {t = Math.max(next.start + 0.0001, span.start + span.len);span = next;el = this.composite(next, spans, t, true);+ } else if (next) {+ // A gap before the next clip: step just past this clip's footprint+ // so the next tick's find() sees no active span and the wall-clock+ // path carries time (and the soundtrack) across the black stretch.+ t = Math.max(t, span.start + span.len + 0.0001);+ pauseEl(el);} else if (t >= total - 0.001) {// Base and every other track finished.useEditor.setState({ playing: false, currentTime: total });diff --git a/site/src/cut/lib/media.ts b/site/src/cut/lib/media.tsindex ed7495bf..5ffb1eef 100644--- a/site/src/cut/lib/media.ts+++ b/site/src/cut/lib/media.ts@@ -54,7 +54,7 @@ export async function createProjectFromFile(};if (asset.type === "video" || asset.type === "image") {const out = asset.type === "image" ? IMAGE_CLIP_SECONDS : asset.duration;- doc.clips = [{ id: uid(), assetId: asset.id, in: 0, out, muted: false }];+ doc.clips = [{ id: uid(), assetId: asset.id, start: 0, in: 0, out, muted: false }];} else {doc.audioClips = [{ id: uid(), assetId: asset.id, start: 0, in: 0, out: asset.duration, volume: 1 },