Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(timeline): rebuild the timeline from the v4 design (V4Timeline)

Etienne Lescot4564d979e9d6
diff --git a/src/components/ai-edition/NewEditorShell.tsx b/src/components/ai-edition/NewEditorShell.tsx
index 2e94604f7..8f790a1d6 100644
--- a/src/components/ai-edition/NewEditorShell.tsx
+++ b/src/components/ai-edition/NewEditorShell.tsx
@@ -13,7 +13,6 @@ import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";
import { PLACEHOLDER_DURATION_SEC, useTimeline } from "@/lib/ai-edition/store/useTimeline";
import { nativeBridgeClient } from "@/native";
import type { AiEditionProjectSummary } from "@/native/contracts";
-import { Bottombar } from "./Bottombar";
import { ExportDialog } from "./ExportDialog";
import { LeftPanel } from "./LeftPanel";
import {
@@ -31,6 +30,7 @@ import { type Facet, FloatingInspector } from "./v4/FloatingInspector";
import { FloatingTransport } from "./v4/FloatingTransport";
import { MediaStage } from "./v4/MediaStage";
import { RecStage } from "./v4/RecStage";
+import { V4Timeline } from "./v4/V4Timeline";
interface SeekTarget {
timeSec: number;
@@ -84,15 +84,6 @@ export function NewEditorShell() {
const [captionsMaxW, setCaptionsMaxW] = useState(7);
const [copiedClipId, setCopiedClipId] = useState<string | null>(null);
const [projectSummaries, setProjectSummaries] = useState<AiEditionProjectSummary[]>([]);
- // T15 — Place-skip mode is owned by Bottombar (it owns the
- // body-class effect, the Esc-to-cancel, the preview-pin). The
- // keyboard shortcut ("T") here needs to toggle the same state, so
- // we expose it as a ref. Refs are used (not state) so the keyboard
- // handler doesn't need to re-bind on every change.
- const togglePlaceSkipRef = useRef<() => void>(() => undefined);
- const setTogglePlaceSkip = useCallback((fn: () => void) => {
- togglePlaceSkipRef.current = fn;
- }, []);
const seekSeqRef = useRef(0);
const initRef = useRef(false);
@@ -927,7 +918,7 @@ export function NewEditorShell() {
break;
case "t":
e.preventDefault();
- togglePlaceSkipRef.current();
+ void tl.addSkip();
break;
case "a":
e.preventDefault();
@@ -1079,36 +1070,27 @@ export function NewEditorShell() {
</section>
</div>
- {/* Timeline footer (hidden in Rec mode) */}
+ {/* Timeline footer (hidden in Rec mode) — rebuilt from the v4 design. */}
{showTimeline ? (
- <Bottombar
- clips={clips}
- videoSources={videoSources}
- currentTimeSec={currentTimeSec}
- onSeek={handleSeek}
- zoomRegions={tl.zoomRegions}
- skipRanges={tl.skipRanges}
- annotationRegions={tl.annotationRegions}
- speedRegions={tl.speedRegions}
- selection={tl.selection}
- multiSelection={tl.multiSelection}
- hasDoc={tl.hasDoc}
- onAddZoom={() => void tl.addZoom()}
- onAddAnnotation={() => void tl.addAnnotation()}
- onAddSpeed={() => void tl.addSpeed()}
- setTogglePlaceSkip={setTogglePlaceSkip}
- onSelectRegion={(kind, id, additive) => tl.selectRegion(kind, id, { additive })}
- onCaptions={handleCaptions}
- playing={playing}
- loop={loop}
- onTogglePlay={togglePlay}
- onPrevClip={handlePrevClip}
- onNextClip={handleNextClip}
- onToggleLoop={handleToggleLoop}
- onExpand={handleExpand}
- hideTransport={mode === "edit"}
- timelineVariant={mode === "media" ? "media" : "edit"}
- />
+ <div
+ style={{
+ gridRow: 3,
+ minHeight: 0,
+ background: "var(--surface)",
+ borderTop: "1px solid var(--border)",
+ }}
+ >
+ <V4Timeline
+ tl={tl}
+ currentTimeSec={currentTimeSec}
+ setCurrentTime={(sec) => {
+ handleSeek(sec);
+ }}
+ variant={mode === "media" ? "media" : "edit"}
+ onDropAsset={(assetId) => void tl.insertClipAt(assetId, clips.length)}
+ videoSources={videoSources}
+ />
+ </div>
) : null}
{/* Modals */}
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.css
index 8f6c9889f..636b13b09 100644
--- a/src/components/ai-edition/v4/EditorShellV4.module.css
+++ b/src/components/ai-edition/v4/EditorShellV4.module.css
@@ -709,3 +709,401 @@
border-radius: 50%;
background: #fff;
}
+
+/* ─── V4Timeline — from-design timeline (footer of the v4 .dc.html) ─── */
+.tl {
+ display: flex;
+ flex-direction: column;
+ min-height: 0;
+ height: 100%;
+ overflow: hidden;
+}
+.tlToolbar {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 0 16px;
+ height: 40px;
+ flex-shrink: 0;
+ border-bottom: 1px solid var(--border-soft);
+}
+.tlTools {
+ display: flex;
+ align-items: center;
+ gap: 1px;
+}
+.tlToolBtn {
+ width: 28px;
+ height: 28px;
+ display: grid;
+ place-items: center;
+ border: 0;
+ background: transparent;
+ color: var(--muted);
+ border-radius: 6px;
+ cursor: pointer;
+ transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
+}
+.tlToolBtn:hover {
+ background: var(--surface-3);
+ color: var(--fg);
+}
+.tlToolBtn.on {
+ background: var(--accent-wash);
+ color: var(--accent);
+}
+.tlHints {
+ margin-left: auto;
+ display: flex;
+ align-items: center;
+ gap: 10px;
+}
+.tlHint {
+ display: inline-flex;
+ align-items: center;
+ gap: 7px;
+ height: 26px;
+ padding: 0 10px;
+ background: var(--surface-1);
+ border: 1px solid var(--border);
+ border-radius: 7px;
+ font-size: 11px;
+ font-weight: 500;
+ color: var(--muted);
+}
+.tlKbd {
+ font-family: var(--font-mono);
+ font-size: 10.5px;
+ font-weight: 600;
+ color: var(--fg-2);
+}
+.tlTracks {
+ position: relative;
+ flex: 1;
+ min-height: 0;
+ padding: 8px 20px 0;
+ overflow: hidden;
+ cursor: text;
+}
+.tlCanvas {
+ position: relative;
+ min-width: 100%;
+ will-change: transform, width;
+}
+.tlPlayhead {
+ position: absolute;
+ top: 2px;
+ bottom: 66px;
+ width: 2px;
+ background: var(--accent);
+ border-radius: 1px;
+ z-index: 6;
+ box-shadow: 0 0 10px var(--accent-soft);
+ pointer-events: none;
+}
+.tlPlayheadDiamond {
+ position: absolute;
+ top: -5px;
+ left: 50%;
+ transform: translateX(-50%) rotate(45deg);
+ width: 9px;
+ height: 9px;
+ background: var(--accent);
+ border-radius: 2px;
+ box-shadow: 0 0 8px var(--accent-soft);
+}
+.tlRuler {
+ display: flex;
+ justify-content: space-between;
+ height: 15px;
+ margin-bottom: 7px;
+ padding-inline: 2px;
+}
+.tlRuler span {
+ font-family: var(--font-mono);
+ font-size: 10px;
+ color: var(--meta);
+}
+.tlLane {
+ position: relative;
+ height: 24px;
+ margin-bottom: 5px;
+ border-radius: 6px;
+ background: var(--surface-1);
+}
+.laneEmpty {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 11px;
+ color: var(--meta);
+ pointer-events: none;
+}
+.lanePill {
+ position: absolute;
+ top: 1px;
+ height: 22px;
+ display: inline-flex;
+ align-items: center;
+ gap: 5px;
+ padding: 0 8px 0 7px;
+ border-radius: 6px;
+ border: 1.5px solid var(--accent);
+ background: var(--accent-soft);
+ color: var(--fg);
+ font-size: 11px;
+ font-weight: 600;
+ white-space: nowrap;
+ overflow: hidden;
+ box-sizing: border-box;
+ cursor: grab;
+ z-index: 2;
+}
+.lanePill:active {
+ cursor: grabbing;
+}
+.lanePillSel {
+ box-shadow: 0 0 0 3px var(--accent-ring);
+}
+.lanePillLabel {
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+.laneAnnotation {
+ border-color: var(--annotation);
+ background: var(--annotation-wash);
+}
+.laneSpeed {
+ border-color: var(--speed);
+ background: var(--speed-wash);
+}
+.laneSkip {
+ border-color: var(--danger);
+ background: var(--danger-soft);
+}
+.laneZoom {
+ border-color: var(--accent);
+ background: var(--accent-soft);
+}
+.tlClips {
+ position: relative;
+ display: flex;
+ gap: 6px;
+ height: 66px;
+ width: 100%;
+ padding: 0;
+ border: 0;
+ background: transparent;
+ text-align: left;
+ cursor: default;
+}
+.tlClipsDrag::after {
+ content: "";
+ position: absolute;
+ inset: 0;
+ border: 2px dashed var(--accent);
+ border-radius: 11px;
+ background: var(--accent-wash);
+ pointer-events: none;
+}
+.tlClip {
+ position: relative;
+ flex: 1 0 0;
+ min-width: 0;
+ border-radius: 11px;
+ border: 1.5px solid var(--border);
+ background: var(--surface-1);
+ overflow: hidden;
+ cursor: pointer;
+ box-sizing: border-box;
+ box-shadow: inset 0 1px 8px rgba(255, 255, 255, 0.06);
+}
+.tlClipSel {
+ border-color: var(--accent);
+}
+.tlWave {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 1px;
+ padding: 0 2px;
+ pointer-events: none;
+}
+.tlWave span {
+ flex: 1 1 0;
+ align-self: center;
+ min-height: 2px;
+ max-width: 2px;
+ border-radius: 2px;
+ background: var(--accent);
+}
+.tlClipLabel {
+ position: absolute;
+ left: 10px;
+ top: 8px;
+ z-index: 2;
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+ max-width: calc(100% - 50px);
+ padding: 3px 9px 3px 6px;
+ border-radius: 8px;
+ background: color-mix(in srgb, #080a0d 55%, transparent);
+ border: 1px solid rgba(255, 255, 255, 0.08);
+ backdrop-filter: blur(8px);
+ -webkit-backdrop-filter: blur(8px);
+}
+.tlClipIcon {
+ width: 16px;
+ height: 16px;
+ display: grid;
+ place-items: center;
+ border-radius: 5px;
+ background: var(--surface);
+ color: var(--fg);
+ flex-shrink: 0;
+}
+.tlClipName {
+ font-size: 11px;
+ font-weight: 500;
+ color: #fff;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+.tlClipDelete {
+ position: absolute;
+ right: 8px;
+ top: 8px;
+ z-index: 2;
+ width: 26px;
+ height: 26px;
+ display: grid;
+ place-items: center;
+ border-radius: 7px;
+ color: var(--muted);
+ background: color-mix(in srgb, #080a0d 55%, transparent);
+ border: 1px solid rgba(255, 255, 255, 0.08);
+ backdrop-filter: blur(8px);
+ -webkit-backdrop-filter: blur(8px);
+ cursor: pointer;
+ transition: background var(--motion-fast) var(--ease), color var(--motion-fast) var(--ease);
+}
+.tlClipDelete:hover {
+ background: var(--danger-soft);
+ color: var(--danger);
+}
+.tlDropHint {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ border: 2px dashed var(--accent);
+ border-radius: 11px;
+ background: var(--accent-wash);
+ color: var(--accent);
+ font-size: 12.5px;
+ font-weight: 600;
+ pointer-events: none;
+}
+.tlNav {
+ position: relative;
+ height: 20px;
+ margin: 8px 20px 12px;
+ flex-shrink: 0;
+}
+.tlNavTrack {
+ position: absolute;
+ top: 7px;
+ left: 0;
+ right: 0;
+ height: 6px;
+ border-radius: 3px;
+ background: var(--surface-3);
+}
+.tlNavWindow {
+ position: absolute;
+ top: 5px;
+ height: 10px;
+ border-radius: 5px;
+ background: var(--surface-hi);
+ border: 1px solid var(--border-hi);
+ box-sizing: border-box;
+ cursor: grab;
+}
+.tlNavWindow:active {
+ cursor: grabbing;
+}
+.tlNavHandle {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ width: 12px;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ cursor: ew-resize;
+ z-index: 3;
+}
+.tlNavHandle span {
+ width: 4px;
+ height: 14px;
+ border-radius: 2px;
+ background: var(--fg-2);
+ box-shadow: 0 0 0 2px var(--surface);
+}
+
+/* V4Timeline — region resize handles, toolbar aspect control */
+.lanePillHandle {
+ position: absolute;
+ top: 0;
+ bottom: 0;
+ width: 6px;
+ cursor: ew-resize;
+ z-index: 3;
+}
+.tlToolSep {
+ width: 1px;
+ height: 20px;
+ background: var(--border);
+ margin: 0 4px;
+}
+.tlAspect {
+ display: inline-flex;
+ align-items: center;
+ gap: 6px;
+ height: 28px;
+ padding: 0 9px;
+ border: 0;
+ background: transparent;
+ color: var(--fg-2);
+ font-size: 11.5px;
+ font-weight: 500;
+ border-radius: 7px;
+ cursor: pointer;
+ transition: background var(--motion-fast) var(--ease);
+}
+.tlAspect:hover {
+ background: var(--surface-3);
+}
+.tlAspect svg {
+ color: var(--muted);
+}
+
+/* V4Timeline — snap guide during region drag/resize */
+.tlSnapGuide {
+ position: absolute;
+ top: 0;
+ bottom: 66px;
+ width: 2px;
+ background: var(--danger);
+ box-shadow: 0 0 6px color-mix(in oklch, var(--danger) 60%, transparent);
+ pointer-events: none;
+ z-index: 14;
+}
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
new file mode 100644
index 000000000..70f18729a
--- /dev/null
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -0,0 +1,616 @@
+import {
+ ChevronDown,
+ Clock,
+ MessageSquare,
+ MousePointer2,
+ Scissors,
+ Sparkles,
+ SplitSquareHorizontal,
+ Trash2,
+ ZoomIn,
+} from "lucide-react";
+import {
+ type PointerEvent as ReactPointerEvent,
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
+import type { AxcutClip } from "@/lib/ai-edition/schema";
+import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";
+import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";
+import { ASPECT_RATIOS, type AspectRatio } from "@/utils/aspectRatioUtils";
+import { EditClipModal } from "../Modals";
+import type { VideoSource } from "../VirtualPreview";
+import styles from "./EditorShellV4.module.css";
+
+type TimelineApi = ReturnType<typeof useTimeline>;
+
+const ASSET_MIME = "application/x-axcut-asset";
+
+type ToolId = "select" | "frame" | "cut" | "comment" | "speed" | "enhance";
+
+function fmt(sec: number): string {
+ if (!Number.isFinite(sec) || sec < 0) sec = 0;
+ const m = Math.floor(sec / 60);
+ const s = (sec % 60).toFixed(1);
+ return `${m}:${s.padStart(4, "0")}`;
+}
+
+// Deterministic pseudo-random waveform bar heights (0..1), seeded per clip —
+// ported verbatim from the v4 design's `waveformFor`.
+function waveformFor(seed: number, count: number): number[] {
+ let x = seed * 9301 + 49297;
+ const rand = () => {
+ x = (x * 9301 + 49297) % 233280;
+ return x / 233280;
+ };
+ const bars: number[] = [];
+ let v = 0.55;
+ for (let i = 0; i < count; i++) {
+ v = v * 0.6 + rand() * 0.4;
+ bars.push(0.3 + v * 0.7);
+ }
+ return bars;
+}
+
+// Map a skip's source-time range to timeline seconds through the clip that
+// carries it (skips are stored in asset source-time, everything else on the
+// lane is timeline-time).
+function skipToTimeline(
+ skip: { assetId: string; startSec: number; endSec: number },
+ clips: AxcutClip[],
+): { start: number; end: number } | null {
+ for (const c of clips) {
+ if (c.assetId !== skip.assetId) continue;
+ const srcEnd = c.sourceEndSec ?? c.sourceStartSec;
+ if (skip.startSec >= c.sourceStartSec && skip.startSec <= srcEnd) {
+ const map = (s: number) =>
+ c.timelineStartSec + (Math.min(Math.max(s, c.sourceStartSec), srcEnd) - c.sourceStartSec);
+ return { start: map(skip.startSec), end: map(skip.endSec) };
+ }
+ }
+ return null;
+}
+
+interface LanePill {
+ id: string;
+ kind: "annotation" | "speed" | "skip" | "zoom";
+ start: number;
+ end: number;
+ label: string;
+}
+
+export function V4Timeline({
+ tl,
+ currentTimeSec,
+ setCurrentTime,
+ variant = "edit",
+ onDropAsset,
+ videoSources = [],
+}: {
+ tl: TimelineApi;
+ currentTimeSec: number;
+ setCurrentTime: (sec: number) => void;
+ variant?: "edit" | "media";
+ onDropAsset?: (assetId: string) => void;
+ videoSources?: VideoSource[];
+}) {
+ const tracksRef = useRef<HTMLDivElement | null>(null);
+ const navRef = useRef<HTMLDivElement | null>(null);
+ const [nav, setNav] = useState({ start: 0, end: 1 });
+ const [dragOver, setDragOver] = useState(false);
+ const [placingSkip, setPlacingSkip] = useState(false);
+ const [snapPct, setSnapPct] = useState<number | null>(null);
+ const [editClipTarget, setEditClipTarget] = useState<AxcutClip | null>(null);
+ const { settings, set: setSettings } = useEditorSettings();
+
+ // Esc cancels the arm-place-skip tool (parity with the old Bottombar).
+ useEffect(() => {
+ if (!placingSkip) return;
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === "Escape") setPlacingSkip(false);
+ };
+ window.addEventListener("keydown", onKey);
+ return () => window.removeEventListener("keydown", onKey);
+ }, [placingSkip]);
+ const cycleAspect = () => {
+ const i = ASPECT_RATIOS.indexOf(settings.aspectRatio as AspectRatio);
+ void setSettings({ aspectRatio: ASPECT_RATIOS[(i + 1) % ASPECT_RATIOS.length] });
+ };
+
+ const clips = tl.clips;
+ const total = useMemo(
+ () =>
+ Math.max(
+ 1,
+ clips.reduce((m, c) => Math.max(m, c.timelineEndSec), 0),
+ ),
+ [clips],
+ );
+ const pctOf = useCallback((sec: number) => (sec / total) * 100, [total]);
+ const showLanes = variant === "edit";
+
+ // ── region lanes ────────────────────────────────────────────────
+ const annPills: LanePill[] = tl.annotationRegions.map((a) => ({
+ id: a.id,
+ kind: "annotation",
+ start: a.startMs / 1000,
+ end: a.endMs / 1000,
+ label: "New annotation",
+ }));
+ const speedPills: LanePill[] = tl.speedRegions.map((s) => ({
+ id: s.id,
+ kind: "speed",
+ start: s.startMs / 1000,
+ end: s.endMs / 1000,
+ label: `${(s as { speed?: number }).speed ?? 1.5}×`,
+ }));
+ const zoomPills: LanePill[] = tl.zoomRegions.map((z) => ({
+ id: z.id,
+ kind: "zoom",
+ start: z.startMs / 1000,
+ end: z.endMs / 1000,
+ label: `${(((z as { depth?: number }).depth ?? 3) / 2 + 0.5).toFixed(1)}×`,
+ }));
+ const skipPills: LanePill[] = tl.skipRanges
+ .map((sk): LanePill | null => {
+ const mapped = skipToTimeline(sk, clips);
+ if (!mapped) return null;
+ return {
+ id: sk.id,
+ kind: "skip",
+ start: mapped.start,
+ end: mapped.end,
+ label: fmt(mapped.end - mapped.start),
+ };
+ })
+ .filter((p): p is LanePill => p !== null);
+
+ const rulerTicks = useMemo(() => {
+ const out: string[] = [];
+ for (let t = 0; t <= total; t += 15) out.push(fmt(t));
+ return out;
+ }, [total]);
+
+ // ── interactions ────────────────────────────────────────────────
+ const seekToClientX = useCallback(
+ (clientX: number) => {
+ const el = tracksRef.current;
+ if (!el) return;
+ const r = el.getBoundingClientRect();
+ const pct = Math.min(1, Math.max(0, (clientX - r.left) / r.width));
+ setCurrentTime(pct * total);
+ },
+ [setCurrentTime, total],
+ );
+
+ // Drag a lane pill to move it (mode "move", keeps duration) or resize one
+ // edge (mode "l"/"r"). Zoom/speed/annotation are timeline-ms; skips map
+ // back to source-seconds through their carrying clip.
+ const startPillDrag = useCallback(
+ (e: ReactPointerEvent, pill: LanePill, dragMode: "move" | "l" | "r") => {
+ e.preventDefault();
+ e.stopPropagation();
+ tl.selectRegion(pill.kind, pill.id, { additive: e.shiftKey });
+ const el = tracksRef.current;
+ if (!el) return;
+ const r = el.getBoundingClientRect();
+ const startX = e.clientX;
+ const dur = pill.end - pill.start;
+ // Snap targets: clip boundaries + timeline ends. Within ~1% of total,
+ // an edge snaps and a vertical guide is shown (Bottombar parity).
+ const snapTargets = [
+ 0,
+ total,
+ ...clips.map((c) => c.timelineStartSec),
+ ...clips.map((c) => c.timelineEndSec),
+ ];
+ const snapThresh = total * 0.012;
+ const snap = (v: number): number => {
+ let best = v;
+ let bestD = snapThresh;
+ for (const t of snapTargets) {
+ const d = Math.abs(t - v);
+ if (d < bestD) {
+ bestD = d;
+ best = t;
+ }
+ }
+ setSnapPct(best === v ? null : (best / total) * 100);
+ return best;
+ };
+ const apply = (start: number, end: number) => {
+ const s = Math.max(0, Math.min(end - 0.2, start));
+ const en = Math.min(total, Math.max(s + 0.2, end));
+ if (pill.kind === "zoom") void tl.updateZoomSpan(pill.id, s * 1000, en * 1000);
+ else if (pill.kind === "speed") void tl.updateSpeedSpan(pill.id, s * 1000, en * 1000);
+ else if (pill.kind === "annotation")
+ void tl.updateAnnotationSpan(pill.id, s * 1000, en * 1000);
+ else {
+ const clip = clips.find((c) => {
+ const se = c.sourceEndSec ?? c.sourceStartSec;
+ return s >= c.timelineStartSec && s <= c.timelineStartSec + (se - c.sourceStartSec);
+ });
+ if (clip) {
+ const toSrc = (t: number) => clip.sourceStartSec + (t - clip.timelineStartSec);
+ void tl.updateSkipRange(pill.id, toSrc(s), toSrc(en));
+ }
+ }
+ };
+ const move = (ev: PointerEvent) => {
+ const dxSec = ((ev.clientX - startX) / r.width) * total;
+ if (dragMode === "move") {
+ const ns = Math.max(0, Math.min(total - dur, snap(pill.start + dxSec)));
+ apply(ns, ns + dur);
+ } else if (dragMode === "l") {
+ apply(snap(pill.start + dxSec), pill.end);
+ } else {
+ apply(pill.start, snap(pill.end + dxSec));
+ }
+ };
+ const up = () => {
+ setSnapPct(null);
+ window.removeEventListener("pointermove", move);
+ window.removeEventListener("pointerup", up);
+ };
+ window.addEventListener("pointermove", move);
+ window.addEventListener("pointerup", up);
+ },
+ [tl, total, clips],
+ );
+
+ const startNavDrag = useCallback(
+ (mode: "left" | "right" | "pan", e: ReactPointerEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+ const r = navRef.current?.getBoundingClientRect();
+ if (!r) return;
+ const startX = e.clientX;
+ const s0 = nav.start;
+ const e0 = nav.end;
+ const move = (ev: PointerEvent) => {
+ const dx = (ev.clientX - startX) / r.width;
+ let start = s0;
+ let end = e0;
+ if (mode === "left") start = Math.min(e0 - 0.05, Math.max(0, s0 + dx));
+ else if (mode === "right") end = Math.max(s0 + 0.05, Math.min(1, e0 + dx));
+ else {
+ const w = e0 - s0;
+ start = Math.max(0, Math.min(1 - w, s0 + dx));
+ end = start + w;
+ }
+ setNav({ start, end });
+ };
+ const up = () => {
+ window.removeEventListener("pointermove", move);
+ window.removeEventListener("pointerup", up);
+ };
+ window.addEventListener("pointermove", move);
+ window.addEventListener("pointerup", up);
+ },
+ [nav],
+ );
+
+ // zoom/pan: the tracks canvas is widened by 1/(navEnd-navStart) and shifted.
+ const navSpan = Math.max(0.02, nav.end - nav.start);
+ const canvasStyle = {
+ width: `${(100 / navSpan).toFixed(3)}%`,
+ transform: `translateX(${(-nav.start * (100 / navSpan)).toFixed(3)}%)`,
+ } as const;
+
+ const laneOf = (kind: LanePill["kind"]) =>
+ kind === "annotation"
+ ? styles.laneAnnotation
+ : kind === "speed"
+ ? styles.laneSpeed
+ : kind === "skip"
+ ? styles.laneSkip
+ : styles.laneZoom;
+ const pillIcon = (kind: LanePill["kind"]) =>
+ kind === "annotation" ? (
+ <MessageSquare size={11} />
+ ) : kind === "speed" ? (
+ <Clock size={11} />
+ ) : kind === "skip" ? (
+ <Scissors size={11} />
+ ) : (
+ <ZoomIn size={11} />
+ );
+
+ // Place a 1s skip at the clicked timeline position, mapped to its clip's
+ // source-time (Bottombar's arm-place-skip tool).
+ const placeSkipAtClientX = useCallback(
+ (clientX: number) => {
+ const el = tracksRef.current;
+ if (!el) return;
+ const r = el.getBoundingClientRect();
+ const t = Math.min(1, Math.max(0, (clientX - r.left) / r.width)) * total;
+ const clip = clips.find((c) => t >= c.timelineStartSec && t <= c.timelineEndSec);
+ if (!clip) return;
+ const src = clip.sourceStartSec + (t - clip.timelineStartSec);
+ const srcEnd = clip.sourceEndSec ?? clip.sourceStartSec;
+ void tl.addSkipAt(clip.assetId, src, Math.min(srcEnd, src + 1));
+ setPlacingSkip(false);
+ },
+ [tl, total, clips],
+ );
+
+ const tools: Array<{ id: ToolId; label: string; icon: React.ReactNode; on?: boolean }> = [
+ { id: "select", label: "Select", icon: <MousePointer2 size={15} />, on: !placingSkip },
+ {
+ id: "cut",
+ label: "Place skip (click the timeline)",
+ icon: <SplitSquareHorizontal size={15} />,
+ on: placingSkip,
+ },
+ { id: "comment", label: "Comment", icon: <MessageSquare size={15} /> },
+ { id: "speed", label: "Speed", icon: <Clock size={15} /> },
+ { id: "enhance", label: "Auto-enhance", icon: <Sparkles size={15} /> },
+ ];
+
+ const isPillSelected = (id: string) =>
+ tl.selection?.id === id || tl.multiSelection.some((m) => m.id === id);
+ const renderPills = (pills: LanePill[], emptyLabel: string) => (
+ <>
+ {pills.length === 0 ? <span className={styles.laneEmpty}>{emptyLabel}</span> : null}
+ {pills.map((p) => (
+ <div
+ // biome-ignore lint/a11y/useKeyWithClickEvents: pointer-driven region drag/resize
+ // biome-ignore lint/a11y/noStaticElementInteractions: lane pill is a draggable region control
+ key={p.id}
+ role="button"
+ tabIndex={0}
+ className={`${styles.lanePill} ${laneOf(p.kind)}${
+ isPillSelected(p.id) ? ` ${styles.lanePillSel}` : ""
+ }`}
+ style={{ left: `${pctOf(p.start)}%`, width: `${Math.max(1.5, pctOf(p.end - p.start))}%` }}
+ onPointerDown={(e) => startPillDrag(e, p, "move")}
+ title={p.label}
+ >
+ <span
+ className={styles.lanePillHandle}
+ style={{ left: 0 }}
+ onPointerDown={(e) => startPillDrag(e, p, "l")}
+ />
+ {pillIcon(p.kind)}
+ <span className={styles.lanePillLabel}>{p.label}</span>
+ <span
+ className={styles.lanePillHandle}
+ style={{ right: 0 }}
+ onPointerDown={(e) => startPillDrag(e, p, "r")}
+ />
+ </div>
+ ))}
+ </>
+ );
+
+ return (
+ <div className={styles.tl}>
+ <div className={styles.tlToolbar}>
+ {showLanes ? (
+ <div className={styles.tlTools} role="toolbar" aria-label="Timeline tools">
+ {tools.map((t) => (
+ <button
+ type="button"
+ key={t.id}
+ className={`${styles.tlToolBtn}${t.on ? ` ${styles.on}` : ""}`}
+ title={t.label}
+ aria-label={t.label}
+ onClick={() => {
+ if (t.id === "speed") void tl.addSpeed();
+ if (t.id === "comment") void tl.addAnnotation();
+ if (t.id === "cut") setPlacingSkip((v) => !v);
+ }}
+ >
+ {t.icon}
+ </button>
+ ))}
+ <button
+ type="button"
+ className={styles.tlToolBtn}
+ title="Add zoom"
+ aria-label="Add zoom"
+ onClick={() => void tl.addZoom()}
+ >
+ <ZoomIn size={15} />
+ </button>
+ <span className={styles.tlToolSep} aria-hidden />
+ <button
+ type="button"
+ className={styles.tlAspect}
+ title="Cycle aspect ratio"
+ aria-label="Cycle aspect ratio"
+ onClick={cycleAspect}
+ >
+ {settings.aspectRatio}
+ <ChevronDown size={10} />
+ </button>
+ </div>
+ ) : (
+ <div style={{ display: "flex", flexDirection: "column", gap: 2 }}>
+ <span style={{ fontSize: 12.5, fontWeight: 600, color: "var(--fg-2)" }}>
+ Arrange clips
+ </span>
+ <span style={{ fontSize: 11.5, color: "var(--meta)" }}>
+ Drag clips below to reorder or drop new ones in
+ </span>
+ </div>
+ )}
+ <div className={styles.tlHints}>
+ <span className={styles.tlHint}>
+ <span className={styles.tlKbd}>Scroll</span> Pan
+ </span>
+ <span className={styles.tlHint}>
+ <span className={styles.tlKbd}>Ctrl+Scroll</span> Zoom
+ </span>
+ </div>
+ </div>
+
+ <div
+ ref={tracksRef}
+ className={styles.tlTracks}
+ style={placingSkip ? { cursor: "crosshair" } : undefined}
+ // biome-ignore lint/a11y/useKeyWithClickEvents: ruler scrubbing is pointer-only
+ onClick={(e) => {
+ if (placingSkip) placeSkipAtClientX(e.clientX);
+ else seekToClientX(e.clientX);
+ }}
+ >
+ <div className={styles.tlCanvas} style={canvasStyle}>
+ <div
+ aria-hidden
+ className={styles.tlPlayhead}
+ style={{ left: `${pctOf(currentTimeSec)}%` }}
+ >
+ <span className={styles.tlPlayheadDiamond} />
+ </div>
+ {snapPct !== null ? (
+ <div aria-hidden className={styles.tlSnapGuide} style={{ left: `${snapPct}%` }} />
+ ) : null}
+
+ <div className={styles.tlRuler}>
+ {rulerTicks.map((t, i) => (
+ <span key={`${t}-${i}`}>{t}</span>
+ ))}
+ </div>
+
+ {showLanes ? (
+ <>
+ <div className={styles.tlLane}>{renderPills(annPills, "No annotations yet")}</div>
+ <div className={styles.tlLane}>{renderPills(speedPills, "Constant speed")}</div>
+ <div className={styles.tlLane}>{renderPills(skipPills, "No skips")}</div>
+ <div className={styles.tlLane}>{renderPills(zoomPills, "")}</div>
+ </>
+ ) : null}
+
+ <div
+ className={`${styles.tlClips}${dragOver ? ` ${styles.tlClipsDrag}` : ""}`}
+ onDragOver={(e) => {
+ e.preventDefault();
+ e.dataTransfer.dropEffect = "copy";
+ if (!dragOver) setDragOver(true);
+ }}
+ onDragLeave={() => setDragOver(false)}
+ onDrop={(e) => {
+ e.preventDefault();
+ setDragOver(false);
+ const id = e.dataTransfer.getData(ASSET_MIME);
+ if (id && onDropAsset) onDropAsset(id);
+ }}
+ >
+ {clips.map((c, i) => {
+ const dur = c.timelineEndSec - c.timelineStartSec;
+ const bars = waveformFor(i + 1, Math.max(12, Math.round(dur * 0.6)));
+ const selected = tl.clipSelection === c.id;
+ return (
+ // biome-ignore lint/a11y/useKeyWithClickEvents: clip selection is pointer-driven
+ <div
+ key={c.id}
+ className={`${styles.tlClip}${selected ? ` ${styles.tlClipSel}` : ""}`}
+ style={{ flex: `${dur} 0 0` }}
+ onClick={(e) => {
+ e.stopPropagation();
+ tl.selectClip(c.id);
+ }}
+ onDoubleClick={(e) => {
+ e.stopPropagation();
+ setEditClipTarget(c);
+ }}
+ title="Double-click to edit in/out points"
+ >
+ <div aria-hidden className={styles.tlWave}>
+ {bars.map((h, bi) => (
+ <span
+ key={bi}
+ style={{
+ height: `${Math.round(h * 100)}%`,
+ opacity: (0.5 + h * 0.5).toFixed(2),
+ }}
+ />
+ ))}
+ </div>
+ <div className={styles.tlClipLabel}>
+ <span className={styles.tlClipIcon}>
+ <Scissors size={9} />
+ </span>
+ <span className={styles.tlClipName}>
+ {tl.assets.find((a) => a.id === c.assetId)?.label ?? c.assetId}
+ </span>
+ </div>
+ {selected ? (
+ <button
+ type="button"
+ className={styles.tlClipDelete}
+ title="Delete clip"
+ aria-label="Delete clip"
+ onClick={(e) => {
+ e.stopPropagation();
+ void tl.removeClip(c.id);
+ }}
+ >
+ <Trash2 size={13} />
+ </button>
+ ) : null}
+ </div>
+ );
+ })}
+ {dragOver ? (
+ <div aria-hidden className={styles.tlDropHint}>
+ Drop to add to timeline
+ </div>
+ ) : null}
+ </div>
+ </div>
+ </div>
+
+ <div ref={navRef} className={styles.tlNav}>
+ <div className={styles.tlNavTrack} />
+ <div
+ className={styles.tlNavWindow}
+ style={{
+ left: `${(nav.start * 100).toFixed(2)}%`,
+ width: `${((nav.end - nav.start) * 100).toFixed(2)}%`,
+ }}
+ onPointerDown={(e) => startNavDrag("pan", e)}
+ />
+ <div
+ className={styles.tlNavHandle}
+ style={{ left: `calc(${(nav.start * 100).toFixed(2)}% - 6px)` }}
+ onPointerDown={(e) => startNavDrag("left", e)}
+ >
+ <span />
+ </div>
+ <div
+ className={styles.tlNavHandle}
+ style={{ left: `calc(${(nav.end * 100).toFixed(2)}% - 6px)` }}
+ onPointerDown={(e) => startNavDrag("right", e)}
+ >
+ <span />
+ </div>
+ </div>
+
+ <EditClipModal
+ open={editClipTarget !== null}
+ onClose={() => setEditClipTarget(null)}
+ clip={editClipTarget}
+ assetMeta={
+ editClipTarget
+ ? {
+ label:
+ tl.assets.find((a) => a.id === editClipTarget.assetId)?.label ??
+ editClipTarget.assetId,
+ durationSec: tl.assets.find((a) => a.id === editClipTarget.assetId)?.durationSec,
+ }
+ : null
+ }
+ videoSources={videoSources}
+ onApply={(sStart, sEnd) => {
+ if (editClipTarget) void tl.updateClipSourceRange(editClipTarget.id, sStart, sEnd);
+ setEditClipTarget(null);
+ }}
+ />
+ </div>
+ );
+}