Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(desktop): timeline ruler scrub, minimap, split snapping, and zoom multi-select

Richie McIlroy0c2410100d6d
diff --git a/apps/desktop/src/routes/editor/Timeline/AudioTrack.tsx b/apps/desktop/src/routes/editor/Timeline/AudioTrack.tsx
index d35fa3f75..455164e10 100644
--- a/apps/desktop/src/routes/editor/Timeline/AudioTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/AudioTrack.tsx
@@ -10,6 +10,7 @@ import { useTimelineContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSetPreviewTime,
@@ -456,6 +457,7 @@ export function AudioTrack(props: {
!segment.enabled && "opacity-50",
)}
innerClass="ring-emerald-8"
+ title={segment.name || "Audio"}
segment={segment}
onMouseDown={(e) => {
e.stopPropagation();
@@ -527,12 +529,24 @@ export function AudioTrack(props: {
},
)}
>
- <div class="flex z-10 gap-1.5 items-center w-full min-w-0 text-xs text-white/95 drop-shadow-sm">
- <IconLucideMusic class="size-3 shrink-0 opacity-90" />
- <span class="max-w-full font-medium truncate">
- {segment.name || "Audio"}
- </span>
- </div>
+ <SegmentLabel
+ compactAt={24}
+ full={() => (
+ <div class="flex z-10 gap-1.5 items-center max-w-full text-xs text-white/95 drop-shadow-sm">
+ <IconLucideMusic class="size-3 shrink-0 opacity-90" />
+ <span class="max-w-full font-medium truncate">
+ {segment.name || "Audio"}
+ </span>
+ </div>
+ )}
+ compact={() => (
+ <div class="flex z-10 items-center max-w-full text-xs text-white/95 drop-shadow-sm">
+ <span class="max-w-full font-medium truncate">
+ {segment.name || "Audio"}
+ </span>
+ </div>
+ )}
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/CaptionsTrack.tsx b/apps/desktop/src/routes/editor/Timeline/CaptionsTrack.tsx
index c50fc63b4..e5e5f130d 100644
--- a/apps/desktop/src/routes/editor/Timeline/CaptionsTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/CaptionsTrack.tsx
@@ -4,7 +4,13 @@ import { createMemo, createRoot, For } from "solid-js";
import { useEditorContext } from "../context";
import { useTimelineContext } from "./context";
-import { SegmentContent, SegmentHandle, SegmentRoot, TrackRoot } from "./Track";
+import {
+ SegmentContent,
+ SegmentHandle,
+ SegmentLabel,
+ SegmentRoot,
+ TrackRoot,
+} from "./Track";
export type CaptionSegmentDragState =
| { type: "idle" }
@@ -164,6 +170,16 @@ export function CaptionsTrack(props: {
const segmentWidth = () =>
Math.min(segment.end, totalDuration()) - segment.start;
+ // Truncation degrades gracefully, so the same row serves both the
+ // full and compact tiers; it just clips against a smaller box.
+ const captionLabel = () => (
+ <div class="flex gap-1 justify-center items-center text-[10px] text-gray-1 dark:text-gray-12">
+ <span class="truncate max-w-full opacity-80">
+ {segment.text || "Caption"}
+ </span>
+ </div>
+ );
+
return (
<SegmentRoot
data-caption-segment
@@ -174,6 +190,7 @@ export function CaptionsTrack(props: {
isSelected() ? "border-green-7" : "border-transparent",
)}
innerClass="ring-green-6"
+ title={segment.text || "Caption"}
segment={{
start: segment.start,
end: Math.min(segment.end, totalDuration()),
@@ -248,13 +265,11 @@ export function CaptionsTrack(props: {
},
)}
>
- <div class="flex flex-col gap-0.5 justify-center items-center text-xs text-gray-1 dark:text-gray-12 w-full min-w-0 overflow-hidden">
- <div class="flex gap-1 items-center text-[10px] w-full min-w-0 justify-center">
- <span class="truncate max-w-full opacity-80">
- {segment.text || "Caption"}
- </span>
- </div>
- </div>
+ <SegmentLabel
+ compactAt={24}
+ full={captionLabel}
+ compact={captionLabel}
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx
index 2b7a6e2f1..0d02e9301 100644
--- a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx
@@ -8,6 +8,7 @@ import {
createMemo,
createRoot,
createSignal,
+ For,
Index,
Match,
onCleanup,
@@ -17,7 +18,7 @@ import {
} from "solid-js";
import { produce } from "solid-js/store";
-import type { TimelineSegment } from "~/utils/tauri";
+import type { ClipSpeedAudioMode, TimelineSegment } from "~/utils/tauri";
import {
clampTransitionDuration,
clipTimelineDuration,
@@ -29,11 +30,14 @@ import {
maxTransitionDuration,
} from "../clip-transitions";
import { useEditorContext } from "../context";
+import { effectiveToOutput, holdWindows } from "../timeline-holds";
import { useSegmentContext, useTimelineContext } from "./context";
import { getSectionMarker } from "./sectionMarker";
+import { SPLIT_SNAP_PX, snapSplitTime } from "./split-snapping";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSegmentTranslateX,
@@ -59,15 +63,19 @@ function gainToScale(gain?: number) {
const MAX_WAVEFORM_SAMPLES = 6000;
+// `range` is in output (timeline) time; `sourceTimeAt` maps an output time to
+// recording time, or null while a fullscreen-text hold has the clock paused —
+// the mixer renders silence there, so the waveform drops to the baseline.
function createWaveformPath(
- segment: { start: number; end: number },
+ range: { start: number; end: number },
waveform: number[] | undefined,
targetSamples: number,
+ sourceTimeAt: (outputTime: number) => number | null,
) {
if (typeof Path2D === "undefined") return;
if (!waveform || waveform.length === 0) return;
- const duration = Math.max(segment.end - segment.start, WAVEFORM_SAMPLE_STEP);
+ const duration = Math.max(range.end - range.start, WAVEFORM_SAMPLE_STEP);
if (!Number.isFinite(duration) || duration <= 0) return;
const nativeSamples = Math.ceil(duration / WAVEFORM_SAMPLE_STEP) + 1;
@@ -82,7 +90,9 @@ function createWaveformPath(
const path = new Path2D();
path.moveTo(0, 1);
- const amplitudeAt = (time: number) => {
+ const amplitudeAt = (outputTime: number) => {
+ const time = sourceTimeAt(outputTime);
+ if (time === null) return 0;
const index = Math.floor(time * 10);
const sample = waveform[index];
const db =
@@ -97,10 +107,10 @@ function createWaveformPath(
const controlStep = Math.min(WAVEFORM_CONTROL_STEP / duration, 0.25);
for (let i = 0; i <= numSamples; i++) {
- const time = segment.start + i * timeStep;
- const normalizedX = (time - segment.start) / duration;
+ const time = range.start + i * timeStep;
+ const normalizedX = (time - range.start) / duration;
const prevTime = time - timeStep;
- const prevX = Math.max(0, (prevTime - segment.start) / duration);
+ const prevX = Math.max(0, (prevTime - range.start) / duration);
const y = 1 - amplitudeAt(time);
const prevY = 1 - amplitudeAt(prevTime);
const cpX1 = prevX + controlStep / 2;
@@ -109,7 +119,7 @@ function createWaveformPath(
}
const closingX =
- (segment.end + WAVEFORM_PADDING_SECONDS - segment.start) / duration;
+ (range.end + WAVEFORM_PADDING_SECONDS - range.start) / duration;
path.lineTo(closingX, 1);
path.closePath();
@@ -138,6 +148,7 @@ function WaveformCanvas(props: {
micWaveform?: number[];
segment: { start: number; end: number };
segmentOffset: number;
+ holds: ReadonlyArray<[number, number]>;
}) {
const { project, editorState } = useEditorContext();
const { width } = useSegmentContext();
@@ -153,19 +164,40 @@ function WaveformCanvas(props: {
const ctx = canvas.getContext("2d");
if (!ctx) return;
- const segmentDuration = props.segment.end - props.segment.start;
+ // Hold windows relative to the clip's box; the box is stretched across
+ // them, so the canvas spans output time, not source time.
+ const holds = props.holds.map(([start, end]): [number, number] => [
+ start - props.segmentOffset,
+ end - props.segmentOffset,
+ ]);
+ const heldDuration = holds.reduce(
+ (sum, [start, end]) => sum + end - start,
+ 0,
+ );
+ const outputDuration =
+ props.segment.end - props.segment.start + heldDuration;
const fullSegmentWidth = width();
- if (fullSegmentWidth < 1 || segmentDuration <= 0) {
+ if (fullSegmentWidth < 1 || outputDuration <= 0) {
return;
}
+ const sourceTimeAt = (outputTime: number): number | null => {
+ let held = 0;
+ for (const [start, end] of holds) {
+ if (outputTime >= end) held += end - start;
+ else if (outputTime > start) return null;
+ else break;
+ }
+ return props.segment.start + outputTime - held;
+ };
+
const useVirtualization = fullSegmentWidth > MAX_CANVAS_WIDTH;
let canvasWidth: number;
let leftOffsetPx: number;
let renderWidth: number;
- let renderSegment: { start: number; end: number };
+ let renderRange: { start: number; end: number };
if (useVirtualization) {
const viewportWidth = timelineBounds.width ?? 800;
@@ -174,7 +206,7 @@ function WaveformCanvas(props: {
const viewEnd = viewStart + transform.zoom;
const segStart = props.segmentOffset;
- const segEnd = segStart + segmentDuration;
+ const segEnd = segStart + outputDuration;
const visibleStart = Math.max(viewStart, segStart);
const visibleEnd = Math.min(viewEnd, segEnd);
@@ -189,7 +221,7 @@ function WaveformCanvas(props: {
const visibleStartInSegment = visibleStart - segStart;
const visibleEndInSegment = visibleEnd - segStart;
- const pxPerSec = fullSegmentWidth / segmentDuration;
+ const pxPerSec = fullSegmentWidth / outputDuration;
const visibleWidthPx = Math.min(
(visibleEndInSegment - visibleStartInSegment) * pxPerSec,
viewportWidth + 200,
@@ -201,24 +233,24 @@ function WaveformCanvas(props: {
);
leftOffsetPx = visibleStartInSegment * pxPerSec;
renderWidth = visibleWidthPx;
- renderSegment = {
- start: props.segment.start + visibleStartInSegment,
- end: props.segment.start + visibleEndInSegment,
+ renderRange = {
+ start: visibleStartInSegment,
+ end: visibleEndInSegment,
};
} else {
canvasWidth = Math.max(Math.ceil(fullSegmentWidth), 1);
leftOffsetPx = 0;
renderWidth = fullSegmentWidth;
- renderSegment = {
- start: props.segment.start,
- end: props.segment.end,
- };
+ renderRange = { start: 0, end: outputDuration };
}
const micScale = gainToScale(project.audio.micVolumeDb);
const systemScale = gainToScale(project.audio.systemVolumeDb);
- const renderKey = `${canvasWidth}-${renderSegment.start.toFixed(2)}-${renderSegment.end.toFixed(2)}-${micScale.toFixed(2)}-${systemScale.toFixed(2)}`;
+ const holdsKey = holds
+ .map(([start, end]) => `${start.toFixed(2)}:${end.toFixed(2)}`)
+ .join(",");
+ const renderKey = `${canvasWidth}-${props.segment.start.toFixed(2)}-${renderRange.start.toFixed(2)}-${renderRange.end.toFixed(2)}-${holdsKey}-${micScale.toFixed(2)}-${systemScale.toFixed(2)}`;
if (renderKey === lastRenderKey) {
return;
}
@@ -241,7 +273,12 @@ function WaveformCanvas(props: {
color: string,
gain?: number,
) => {
- const path = createWaveformPath(renderSegment, waveform, numSamples);
+ const path = createWaveformPath(
+ renderRange,
+ waveform,
+ numSamples,
+ sourceTimeAt,
+ );
if (!path) return;
const scale = gainToScale(gain);
if (scale <= 0) return;
@@ -272,6 +309,8 @@ function WaveformCanvas(props: {
editorState.timeline.transform.zoom;
props.segment.start;
props.segment.end;
+ props.segmentOffset;
+ props.holds;
props.micWaveform;
props.systemWaveform;
project.audio.micVolumeDb;
@@ -311,6 +350,89 @@ function WaveformCanvas(props: {
);
}
+// The speed chip is rendered once per label tier so an open popover survives
+// the segment shrinking past a tier boundary; the menu itself lives here so
+// it isn't duplicated per tier.
+function ClipSpeedControl(props: {
+ timescale: number;
+ speedAudioMode?: ClipSpeedAudioMode | null;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ triggerClass?: string;
+ onSetTimescale: (timescale: number) => void;
+ onSetSpeedAudioMode: (mode: ClipSpeedAudioMode) => void;
+}) {
+ return (
+ <Popover
+ placement="top"
+ gutter={8}
+ open={props.open}
+ onOpenChange={props.onOpenChange}
+ >
+ <Popover.Trigger
+ class={cx(
+ "pointer-events-auto flex items-center gap-0.5 rounded-full bg-black/30 px-1.5 py-0.5 text-[10px] font-medium text-white transition-colors hover:bg-black/50",
+ props.triggerClass,
+ )}
+ aria-label={`Clip speed: ${props.timescale}x`}
+ onMouseDown={(event) => event.stopPropagation()}
+ >
+ <IconLucideFastForward class="size-2.5" />
+ {props.timescale}x
+ </Popover.Trigger>
+ <Popover.Portal>
+ <Popover.Content
+ onMouseDown={(event) => event.stopPropagation()}
+ class="z-50 flex w-max flex-col gap-1.5 rounded-xl border border-gray-3 bg-gray-1 p-2 text-gray-12 shadow-xl outline-hidden animate-in fade-in slide-in-from-bottom-2"
+ >
+ <div class="flex items-center gap-1 rounded-lg bg-gray-2 p-1">
+ {[0.25, 0.5, 1, 1.5, 2, 4, 8].map((mult) => (
+ <button
+ type="button"
+ aria-pressed={props.timescale === mult}
+ class={cx(
+ "rounded-md px-2 py-1 text-xs whitespace-nowrap transition-colors",
+ props.timescale === mult
+ ? "bg-gray-4 text-gray-12"
+ : "text-gray-10 hover:text-gray-12",
+ )}
+ onClick={() => props.onSetTimescale(mult)}
+ >
+ {mult}x
+ </button>
+ ))}
+ </div>
+ <Show when={props.timescale !== 1}>
+ <div class="flex items-center gap-1 rounded-lg bg-gray-2 p-1">
+ {(
+ [
+ ["mute", "Mute"],
+ ["maintainPitch", "Maintain pitch"],
+ ["matchSpeed", "Match speed"],
+ ] as const
+ ).map(([value, label]) => (
+ <button
+ type="button"
+ aria-pressed={(props.speedAudioMode ?? "mute") === value}
+ class={cx(
+ "flex-1 rounded-md px-2 py-1 text-xs whitespace-nowrap transition-colors",
+ (props.speedAudioMode ?? "mute") === value
+ ? "bg-gray-4 text-gray-12"
+ : "text-gray-10 hover:text-gray-12",
+ )}
+ onClick={() => props.onSetSpeedAudioMode(value)}
+ >
+ {label}
+ </button>
+ ))}
+ </div>
+ </Show>
+ </Popover.Content>
+ </Popover.Portal>
+ </Popover>
+ );
+}
+
export function ClipTrack(
props: Pick<ComponentProps<"div">, "ref"> & {
handleUpdatePlayhead: (e: MouseEvent) => void;
@@ -381,15 +503,42 @@ export function ClipTrack(
};
};
+ // Fullscreen text segments pause the recording clock, stretching the clip
+ // that contains them across the held window on the output timeline.
+ const heldWindows = createMemo(() =>
+ holdWindows(project.timeline?.textSegments),
+ );
+
+ const selectedHoldWindows = createMemo(() => {
+ const selection = editorState.timeline.selection;
+ if (selection?.type !== "text") return null;
+ const texts = project.timeline?.textSegments;
+ if (!texts) return null;
+ const windows = selection.indices
+ .map((index) => texts[index])
+ .filter(
+ (segment) =>
+ segment &&
+ segment.enabled !== false &&
+ segment.layout === "fullscreen",
+ )
+ .map((segment): [number, number] => [segment.start, segment.end]);
+ return windows.length > 0 ? windows : null;
+ });
+
const visibleSegmentIndices = createMemo(() => {
const segs = segments();
const offsets = segmentOffsets();
+ const holds = heldWindows();
const draggedIndex = transitionDrag()?.index;
const visible: number[] = [];
for (let i = 0; i < segs.length; i++) {
const seg = segs[i];
- const segStart = offsets[i];
- const segEnd = segStart + (seg.end - seg.start) / seg.timescale;
+ const segStart = effectiveToOutput(holds, offsets[i]);
+ const segEnd = effectiveToOutput(
+ holds,
+ offsets[i] + (seg.end - seg.start) / seg.timescale,
+ );
if (i === draggedIndex || isSegmentVisible(segStart, segEnd)) {
visible.push(i);
}
@@ -414,6 +563,10 @@ export function ClipTrack(
const split = () => editorState.timeline.interactMode === "split";
+ createEffect(() => {
+ if (!split()) setEditorState("timeline", "splitPreview", null);
+ });
+
function selectClip(currentIndex: number, event: MouseEvent) {
const selection = editorState.timeline.selection;
const isMac = navigator.platform.toUpperCase().includes("MAC");
@@ -450,12 +603,29 @@ export function ClipTrack(
<TrackRoot
ref={props.ref}
onMouseEnter={() => setEditorState("timeline", "hoveredTrack", "clip")}
- onMouseLeave={() => setEditorState("timeline", "hoveredTrack", null)}
+ onMouseLeave={() => {
+ setEditorState("timeline", "hoveredTrack", null);
+ setEditorState("timeline", "splitPreview", null);
+ }}
>
<Index each={visibleSegmentIndices()}>
{(segmentIndex) => {
const i = segmentIndex;
const segment = () => segments()[i()];
+ const [speedOpen, setSpeedOpen] = createSignal(false);
+
+ const clipName = () =>
+ hasMultipleRecordingSegments()
+ ? `Clip ${segment().recordingSegment}`
+ : "Clip";
+
+ const clipTitle = () => {
+ const seg = segment();
+ const parts = [clipName(), formatTime(seg.end - seg.start)];
+ if (seg.timescale !== 1) parts.push(`${seg.timescale}x`);
+ return parts.join(" · ");
+ };
+
const [startHandleDrag, setStartHandleDrag] = createSignal<null | {
offset: number;
initialStart: number;
@@ -467,20 +637,56 @@ export function ClipTrack(
const ds = startHandleDrag();
const offset = ds?.offset ?? 0;
const seg = segment();
+ const holds = heldWindows();
return {
- start: Math.max(prevDuration() + offset, 0),
- end:
+ start: Math.max(
+ effectiveToOutput(holds, prevDuration() + offset),
+ 0,
+ ),
+ end: effectiveToOutput(
+ holds,
prevDuration() +
- (offset + (seg.end - seg.start)) / seg.timescale,
+ (offset + (seg.end - seg.start)) / seg.timescale,
+ ),
timescale: seg.timescale,
recordingSegment: seg.recordingSegment,
};
});
+ // Held (paused) windows inside this clip's on-screen box.
+ const segmentHolds = createMemo(() => {
+ const { start, end } = relativeSegment();
+ return heldWindows()
+ .map(([holdStart, holdEnd]): [number, number] => [
+ Math.max(holdStart, start),
+ Math.min(holdEnd, end),
+ ])
+ .filter(([holdStart, holdEnd]) => holdEnd > holdStart);
+ });
+
const segmentX = useSegmentTranslateX(relativeSegment);
const segmentWidth = useSegmentWidth(relativeSegment);
+ const splitTimeAt = (e: {
+ clientX: number;
+ altKey: boolean;
+ currentTarget: HTMLDivElement;
+ }) => {
+ const rect = e.currentTarget.getBoundingClientRect();
+ const seg = relativeSegment();
+ const raw = seg.start + (e.clientX - rect.left) * secsPerPixel();
+ if (e.altKey) return { time: raw, snapped: null };
+ return snapSplitTime(
+ raw,
+ seg.start,
+ seg.end,
+ SPLIT_SNAP_PX * secsPerPixel(),
+ project.timeline,
+ editorState.playbackTime,
+ );
+ };
+
const segmentRecording = (s = i()) =>
editorInstance.recordings.segments[
segments()[s].recordingSegment ?? 0
@@ -617,7 +823,20 @@ export function ClipTrack(
isSelected() ? "border-gray-12" : "border-transparent",
)}
innerClass="ring-blue-9"
+ title={clipTitle()}
segment={relativeSegment()}
+ onMouseMove={(e) => {
+ if (editorState.timeline.interactMode !== "split") return;
+ const result = splitTimeAt(e);
+ setEditorState("timeline", "splitPreview", {
+ time: result.time,
+ snapped: result.snapped !== null,
+ });
+ }}
+ onMouseLeave={() => {
+ if (editorState.timeline.splitPreview)
+ setEditorState("timeline", "splitPreview", null);
+ }}
onMouseDown={(e) => {
e.stopPropagation();
if (e.button !== 0) return;
@@ -629,17 +848,10 @@ export function ClipTrack(
return;
if (editorState.timeline.interactMode === "split") {
- const rect = e.currentTarget.getBoundingClientRect();
- const fraction = (e.clientX - rect.left) / rect.width;
- const seg = segment();
-
- const splitTime =
- (fraction * (seg.end - seg.start)) / seg.timescale;
-
- projectActions.splitClipSegment(
- prevDuration() + splitTime,
- i(),
- );
+ // The box is in output time (it stretches across any
+ // held windows); splitClipSegment converts back to the
+ // recording-flow domain itself.
+ projectActions.splitClipSegment(splitTimeAt(e).time, i());
} else {
const index = i();
const initialTransition = getClipTransition(
@@ -733,11 +945,61 @@ export function ClipTrack(
micWaveform={micWaveform()}
systemWaveform={systemAudioWaveform()}
segment={segment()}
- segmentOffset={prevDuration()}
+ segmentOffset={relativeSegment().start}
+ holds={segmentHolds()}
/>
)}
- <Markings segment={segment()} prevDuration={prevDuration()} />
+ <Markings
+ segment={segment()}
+ prevDuration={relativeSegment().start}
+ holds={segmentHolds()}
+ />
+
+ <For each={segmentHolds()}>
+ {(hold) => {
+ // Light up when the fullscreen text causing this hold
+ // is selected, so cause and effect read as one thing.
+ const causeSelected = () =>
+ selectedHoldWindows()?.some(
+ ([start, end]) => start < hold[1] && end > hold[0],
+ ) ?? false;
+ const holdWidth = () =>
+ (hold[1] - hold[0]) / secsPerPixel();
+ return (
+ <div
+ class={cx(
+ "absolute inset-y-0 z-[3] flex items-center justify-center gap-1 overflow-hidden bg-black/45 backdrop-saturate-50 border-x transition-colors",
+ causeSelected() ? "border-blue-9" : "border-white/25",
+ )}
+ style={{
+ left: `${(hold[0] - relativeSegment().start) / secsPerPixel()}px`,
+ width: `${holdWidth()}px`,
+ "background-image":
+ "repeating-linear-gradient(-45deg, rgba(255,255,255,0.07) 0px, rgba(255,255,255,0.07) 4px, transparent 4px, transparent 8px)",
+ }}
+ title="Video paused while the fullscreen text is shown"
+ >
+ <IconLucidePause
+ class={cx(
+ "size-3 shrink-0",
+ causeSelected() ? "text-blue-9" : "text-white/70",
+ )}
+ />
+ <Show when={holdWidth() >= 64}>
+ <span
+ class={cx(
+ "text-[10px] font-medium whitespace-nowrap",
+ causeSelected() ? "text-blue-9" : "text-white/70",
+ )}
+ >
+ Paused
+ </span>
+ </Show>
+ </div>
+ );
+ }}
+ </For>
<Show when={i() > 0 && !transitionAt(i())}>
<button
@@ -971,28 +1233,50 @@ export function ClipTrack(
/>
<SegmentContent class="relative justify-center items-center">
{(() => {
- const ctx = useSegmentContext();
const seg = segment();
+ const speedControl = (triggerClass?: string) => (
+ <ClipSpeedControl
+ timescale={seg.timescale}
+ speedAudioMode={seg.speedAudioMode}
+ open={speedOpen()}
+ onOpenChange={setSpeedOpen}
+ triggerClass={triggerClass}
+ onSetTimescale={(mult) =>
+ projectActions.setClipSegmentTimescale(i(), mult)
+ }
+ onSetSpeedAudioMode={(mode) =>
+ projectActions.setClipSegmentSpeedAudioMode(i(), mode)
+ }
+ />
+ );
+
return (
- <Show when={ctx.width() > 100}>
- <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-12">
- <span class="text-white/70">
- {hasMultipleRecordingSegments()
- ? `Clip ${seg.recordingSegment}`
- : "Clip"}
- </span>
- <div class="flex gap-1 items-center text-md dark:text-gray-12 text-gray-1">
- <IconLucideClock class="size-3.5" />{" "}
- {formatTime(seg.end - seg.start)}
- <Show when={seg.timescale !== 1}>
- <div class="w-0.5" />
- <IconLucideFastForward class="size-3" />
- {seg.timescale}x
- </Show>
+ <SegmentLabel
+ full={() => (
+ <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-12">
+ <span class="text-white/70">{clipName()}</span>
+ <div class="flex gap-1 items-center text-md dark:text-gray-12 text-gray-1">
+ <IconLucideClock class="size-3.5" />{" "}
+ {formatTime(seg.end - seg.start)}
+ {speedControl()}
+ </div>
+ </div>
+ )}
+ compact={() => (
+ <div class="flex gap-1 items-center text-[10px] whitespace-nowrap dark:text-gray-12 text-gray-1">
+ {speedControl("shrink-0")}
+ <span class="truncate">
+ {formatTime(seg.end - seg.start)}
+ </span>
</div>
- </div>
- </Show>
+ )}
+ glyph={
+ seg.timescale !== 1
+ ? () => speedControl("shrink-0")
+ : undefined
+ }
+ />
);
})()}
</SegmentContent>
@@ -1138,7 +1422,11 @@ export function ClipTrack(
);
}
-function Markings(props: { segment: TimelineSegment; prevDuration: number }) {
+function Markings(props: {
+ segment: TimelineSegment;
+ prevDuration: number;
+ holds: ReadonlyArray<[number, number]>;
+}) {
const { editorState } = useEditorContext();
const { secsPerPixel, markingResolution } = useTimelineContext();
@@ -1163,8 +1451,16 @@ function Markings(props: { segment: TimelineSegment; prevDuration: number }) {
<Index each={Array.from({ length: markingParams().count })}>
{(_, index) => {
const marking = () => getMarkingTime(index);
- const translateX = () =>
- (marking() - props.segment.start) / secsPerPixel();
+ // Markings live in recording time; push each past the holds the
+ // stretched box inserts before it.
+ const translateX = () => {
+ const holdsRel = props.holds.map(([start, end]): [number, number] => [
+ start - props.prevDuration,
+ end - props.prevDuration,
+ ]);
+ const effective = marking() - props.segment.start;
+ return effectiveToOutput(holdsRel, effective) / secsPerPixel();
+ };
return (
<div
diff --git a/apps/desktop/src/routes/editor/Timeline/KeyboardTrack.tsx b/apps/desktop/src/routes/editor/Timeline/KeyboardTrack.tsx
index c8e8cd083..33f9ab02c 100644
--- a/apps/desktop/src/routes/editor/Timeline/KeyboardTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/KeyboardTrack.tsx
@@ -4,7 +4,13 @@ import { createMemo, createRoot, For } from "solid-js";
import { useEditorContext } from "../context";
import { useTimelineContext } from "./context";
-import { SegmentContent, SegmentHandle, SegmentRoot, TrackRoot } from "./Track";
+import {
+ SegmentContent,
+ SegmentHandle,
+ SegmentLabel,
+ SegmentRoot,
+ TrackRoot,
+} from "./Track";
export type KeyboardSegmentDragState =
| { type: "idle" }
@@ -156,6 +162,16 @@ export function KeyboardTrack(props: {
const segmentWidth = () =>
Math.min(segment.end, totalDuration()) - segment.start;
+ // Truncation degrades gracefully, so the same row serves both the
+ // full and compact tiers; it just clips against a smaller box.
+ const keysLabel = () => (
+ <div class="flex gap-1 justify-center items-center font-mono text-[10px] text-gray-1 dark:text-gray-12">
+ <span class="truncate max-w-full opacity-80">
+ {segment.displayText || "⌨"}
+ </span>
+ </div>
+ );
+
return (
<SegmentRoot
data-keyboard-segment
@@ -166,6 +182,7 @@ export function KeyboardTrack(props: {
isSelected() ? "border-sky-7" : "border-transparent",
)}
innerClass="ring-sky-6"
+ title={segment.displayText || "Keyboard"}
segment={{
start: segment.start,
end: Math.min(segment.end, totalDuration()),
@@ -240,13 +257,16 @@ export function KeyboardTrack(props: {
},
)}
>
- <div class="flex flex-col gap-0.5 justify-center items-center text-xs text-gray-1 dark:text-gray-12 w-full min-w-0 overflow-hidden">
- <div class="flex gap-1 items-center text-[10px] w-full min-w-0 justify-center font-mono">
- <span class="truncate max-w-full opacity-80">
- {segment.displayText || "⌨"}
+ <SegmentLabel
+ compactAt={24}
+ full={keysLabel}
+ compact={keysLabel}
+ glyph={() => (
+ <span class="font-mono text-[10px] text-gray-1 opacity-80 dark:text-gray-12">
+ ⌨
</span>
- </div>
- </div>
+ )}
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/MaskTrack.tsx b/apps/desktop/src/routes/editor/Timeline/MaskTrack.tsx
index f8ea79507..668ece38c 100644
--- a/apps/desktop/src/routes/editor/Timeline/MaskTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/MaskTrack.tsx
@@ -10,6 +10,7 @@ import { useTimelineContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSetPreviewTime,
@@ -362,6 +363,7 @@ export function MaskTrack(props: {
: "border border-transparent",
)}
innerClass="ring-red-5"
+ title={`Mask · ${contentLabel()}`}
segment={segment}
onMouseEnter={(e) => {
setHoveredSegmentState(e, index, segment);
@@ -476,16 +478,21 @@ export function MaskTrack(props: {
},
)}
>
- {(() => {
- return (
+ <SegmentLabel
+ full={() => (
<div class="flex flex-col gap-0.5 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
<span class="opacity-70">Mask</span>
<div class="flex gap-1 items-center text-md">
<span>{contentLabel()}</span>
</div>
</div>
- );
- })()}
+ )}
+ compact={() => (
+ <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
+ <span class="truncate">{contentLabel()}</span>
+ </div>
+ )}
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/Minimap.tsx b/apps/desktop/src/routes/editor/Timeline/Minimap.tsx
new file mode 100644
index 000000000..408e9a3dc
--- /dev/null
+++ b/apps/desktop/src/routes/editor/Timeline/Minimap.tsx
@@ -0,0 +1,135 @@
+import { createElementBounds } from "@solid-primitives/bounds";
+import { createEventListenerMap } from "@solid-primitives/event-listener";
+import { cx } from "cva";
+import { createMemo, createRoot, createSignal, For, onCleanup } from "solid-js";
+
+import { clipTimelineOffsets } from "../clip-transitions";
+import { useEditorContext } from "../context";
+
+const MIN_CHIP_WIDTH = 20;
+
+export function Minimap() {
+ const { project, editorState, setEditorState, totalDuration } =
+ useEditorContext();
+ const transform = () => editorState.timeline.transform;
+
+ const [barRef, setBarRef] = createSignal<HTMLDivElement>();
+ const barBounds = createElementBounds(barRef);
+
+ const total = () => Math.max(totalDuration(), 0.001);
+ const barWidth = () => Math.max(barBounds.width ?? 0, 1);
+ const pxPerSec = () => barWidth() / total();
+ const zoomedIn = () => total() - transform().zoom > 0.01;
+
+ const chipWidth = () =>
+ Math.min(
+ Math.max(transform().zoom * pxPerSec(), MIN_CHIP_WIDTH),
+ barWidth(),
+ );
+ const chipLeft = () => {
+ const maxPosition = Math.max(total() - transform().zoom, 0.001);
+ const fraction = Math.min(transform().position / maxPosition, 1);
+ return fraction * Math.max(barWidth() - chipWidth(), 0);
+ };
+
+ const clipBoundaries = createMemo(() => {
+ const timeline = project.timeline;
+ if (!timeline || timeline.segments.length < 2) return [];
+ return clipTimelineOffsets(timeline.segments, timeline.transitions ?? [])
+ .slice(1)
+ .filter((offset) => offset > 0 && offset < total());
+ });
+
+ function beginDrag(downEvent: MouseEvent, mode: "move" | "left" | "right") {
+ if (downEvent.button !== 0) return;
+ downEvent.stopPropagation();
+
+ const startX = downEvent.clientX;
+ const startPosition = transform().position;
+ const startZoom = transform().zoom;
+ const anchorStart = startPosition;
+ const anchorEnd = startPosition + startZoom;
+ const moveScale =
+ (total() - startZoom) / Math.max(barWidth() - chipWidth(), 1);
+
+ createRoot((dispose) => {
+ const previousCursor = document.body.style.cursor;
+ document.body.style.cursor = mode === "move" ? "grabbing" : "col-resize";
+ onCleanup(() => {
+ document.body.style.cursor = previousCursor;
+ });
+
+ createEventListenerMap(window, {
+ mousemove: (event) => {
+ setEditorState("previewTime", null);
+ const deltaX = event.clientX - startX;
+ if (mode === "move") {
+ transform().setPosition(startPosition + deltaX * moveScale);
+ } else if (mode === "left") {
+ // Anchoring the zoom at the opposite edge keeps that edge
+ // pinned exactly: updateZoom's origin math resolves to
+ // originPercentage 1 (left handle) or 0 (right handle).
+ transform().updateZoom(startZoom - deltaX / pxPerSec(), anchorEnd);
+ } else {
+ transform().updateZoom(
+ startZoom + deltaX / pxPerSec(),
+ anchorStart,
+ );
+ }
+ },
+ mouseup: () => dispose(),
+ blur: () => dispose(),
+ });
+ });
+ }
+
+ function handleBarMouseDown(downEvent: MouseEvent) {
+ if (downEvent.button !== 0) return;
+ downEvent.stopPropagation();
+
+ const bar = barRef();
+ if (!bar) return;
+ const rect = bar.getBoundingClientRect();
+ const clickTime = ((downEvent.clientX - rect.left) / barWidth()) * total();
+ transform().setPosition(clickTime - transform().zoom / 2);
+ beginDrag(downEvent, "move");
+ }
+
+ return (
+ <div
+ ref={setBarRef}
+ class={cx(
+ "relative w-full h-full overflow-hidden rounded-full border border-gray-4 bg-gray-3/80 transition-opacity duration-200",
+ zoomedIn() ? "opacity-100" : "pointer-events-none opacity-0",
+ )}
+ onMouseDown={handleBarMouseDown}
+ onMouseMove={(e) => {
+ e.stopPropagation();
+ setEditorState("previewTime", null);
+ }}
+ >
+ <For each={clipBoundaries()}>
+ {(offset) => (
+ <div
+ class="absolute inset-y-0 w-px bg-gray-6/50"
+ style={{ left: `${(offset / total()) * 100}%` }}
+ />
+ )}
+ </For>
+ <div
+ class="absolute inset-y-0 rounded-full border border-gray-7/80 bg-gray-6/70 transition-colors duration-150 cursor-grab hover:bg-gray-7/70 active:cursor-grabbing"
+ style={{ left: `${chipLeft()}px`, width: `${chipWidth()}px` }}
+ onMouseDown={(e) => beginDrag(e, "move")}
+ >
+ <div
+ class="absolute inset-y-0 left-0 w-2 cursor-col-resize"
+ onMouseDown={(e) => beginDrag(e, "left")}
+ />
+ <div
+ class="absolute inset-y-0 right-0 w-2 cursor-col-resize"
+ onMouseDown={(e) => beginDrag(e, "right")}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/desktop/src/routes/editor/Timeline/SceneTrack.tsx b/apps/desktop/src/routes/editor/Timeline/SceneTrack.tsx
index 9850bfab0..22e996585 100644
--- a/apps/desktop/src/routes/editor/Timeline/SceneTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/SceneTrack.tsx
@@ -15,14 +15,11 @@ import {
import { produce } from "solid-js/store";
import { useEditorContext } from "../context";
-import {
- useSegmentContext,
- useTimelineContext,
- useTrackContext,
-} from "./context";
+import { useTimelineContext, useTrackContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSetPreviewTime,
@@ -424,6 +421,7 @@ export function SceneTrack(props: {
isSelected() ? "border-gray-12" : "border-transparent",
)}
innerClass="ring-blue-5"
+ title={`Scene · ${getSceneLabel(segment.mode)}`}
segment={segment}
onMouseEnter={() => {
setHoveringSegment(true);
@@ -542,25 +540,30 @@ export function SceneTrack(props: {
},
)}
>
- {(() => {
- const ctx = useSegmentContext();
-
- return (
- <Show when={ctx.width() > 80}>
- <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
- <span class="opacity-70">Scene</span>
- <div class="flex gap-1 items-center text-md">
- {getSceneIcon(segment.mode)}
- {ctx.width() > 120 && (
- <span class="text-xs">
- {getSceneLabel(segment.mode)}
- </span>
- )}
- </div>
+ <SegmentLabel
+ full={() => (
+ <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
+ <span class="opacity-70">Scene</span>
+ <div class="flex gap-1 items-center text-md">
+ {getSceneIcon(segment.mode)}
+ <span class="text-xs">
+ {getSceneLabel(segment.mode)}
+ </span>
</div>
- </Show>
- );
- })()}
+ </div>
+ )}
+ compact={() => (
+ <div class="flex gap-1 items-center text-md whitespace-nowrap text-gray-1 dark:text-gray-12">
+ {getSceneIcon(segment.mode)}
+ <span class="text-xs">{getSceneLabel(segment.mode)}</span>
+ </div>
+ )}
+ glyph={() => (
+ <div class="flex justify-center items-center text-gray-1 dark:text-gray-12">
+ {getSceneIcon(segment.mode)}
+ </div>
+ )}
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/TextTrack.tsx b/apps/desktop/src/routes/editor/Timeline/TextTrack.tsx
index 7d4856c7e..57ec6af42 100644
--- a/apps/desktop/src/routes/editor/Timeline/TextTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/TextTrack.tsx
@@ -3,6 +3,7 @@ import { cx } from "cva";
import { createMemo, createRoot, createSignal, For, Show } from "solid-js";
import { produce } from "solid-js/store";
+import { cssFontFamily } from "~/utils/fonts";
import { useEditorContext } from "../context";
import { autoTextColorAt, defaultTextSegment } from "../text";
import { getSegmentTrack, sortTrackSegments } from "../timelineTracks";
@@ -10,6 +11,7 @@ import { useTimelineContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSetPreviewTime,
@@ -322,6 +324,36 @@ export function TextTrack(props: {
const segmentWidth = () => segment.end - segment.start;
+ const textContentRow = () => (
+ <div class="flex gap-1.5 justify-center items-center max-w-full text-md">
+ <span
+ class="size-2 shrink-0 rounded-full border border-white/40"
+ style={{
+ "background-color": segment.color ?? "#ffffff",
+ }}
+ />
+ <span
+ class="truncate max-w-full"
+ style={{
+ "font-family": cssFontFamily(
+ segment.fontFamily ?? "sans-serif",
+ ),
+ "font-style": segment.italic ? "italic" : "normal",
+ "font-weight": segment.fontWeight ?? 700,
+ }}
+ >
+ {segment.content || "Label"}
+ </span>
+ </div>
+ );
+
+ const textTitle = () => {
+ const base = `Text · ${segment.content || "Label"}`;
+ return segment.layout === "fullscreen"
+ ? `${base} · Fullscreen: pauses the video while shown`
+ : base;
+ };
+
return (
<SegmentRoot
data-text-segment
@@ -333,6 +365,7 @@ export function TextTrack(props: {
!segment.enabled && "opacity-60",
)}
innerClass="ring-blue-6"
+ title={textTitle()}
segment={segment}
onMouseDown={(e) => {
e.stopPropagation();
@@ -423,14 +456,31 @@ export function TextTrack(props: {
},
)}
>
- <div class="flex flex-col gap-0.5 justify-center items-center text-xs text-gray-1 dark:text-gray-12 w-full min-w-0 overflow-hidden">
- <span class="opacity-70">Text</span>
- <div class="flex gap-1 items-center text-md w-full min-w-0 justify-center">
- <span class="truncate max-w-full">
- {segment.content || "Label"}
- </span>
- </div>
- </div>
+ <SegmentLabel
+ full={() => (
+ <div class="flex flex-col gap-0.5 justify-center items-center text-xs text-gray-1 dark:text-gray-12">
+ <span class="flex gap-1 items-center opacity-70">
+ Text
+ <Show when={segment.layout === "fullscreen"}>
+ <IconLucidePause class="size-2.5" />
+ </Show>
+ </span>
+ {textContentRow()}
+ </div>
+ )}
+ compact={() => (
+ <div class="flex justify-center items-center text-xs text-gray-1 dark:text-gray-12">
+ {textContentRow()}
+ </div>
+ )}
+ glyph={
+ segment.layout === "fullscreen"
+ ? () => (
+ <IconLucidePause class="size-2.5 text-gray-1 opacity-70 dark:text-gray-12" />
+ )
+ : undefined
+ }
+ />
</SegmentContent>
<SegmentHandle
position="end"
diff --git a/apps/desktop/src/routes/editor/Timeline/ThreeDTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ThreeDTrack.tsx
index 59b18d882..8fa01ff53 100644
--- a/apps/desktop/src/routes/editor/Timeline/ThreeDTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/ThreeDTrack.tsx
@@ -7,9 +7,7 @@ import {
createRoot,
createSignal,
Index,
- Match,
Show,
- Switch,
} from "solid-js";
import { produce } from "solid-js/store";
import { useEditorContext } from "../context";
@@ -19,17 +17,15 @@ import {
fitCamera3DMotionToSegment,
hasCamera3DMotion,
} from "../three-d";
-import {
- useSegmentContext,
- useTimelineContext,
- useTrackContext,
-} from "./context";
+import { useTimelineContext, useTrackContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
useSegmentTranslateX,
+ useSegmentVisibleBox,
useSegmentWidth,
useSetPreviewTime,
} from "./Track";
@@ -367,6 +363,9 @@ export function ThreeDTrack(props: {
const camera3dSegments = () =>
project.timeline?.camera3dSegments ?? [];
+ const motionLabel = () =>
+ hasCamera3DMotion(segment()) ? "Motion" : "Still";
+
// Double-clicking a handle expands the segment as far as it can go
// in that direction (up to the neighbouring segment / timeline edge).
const fillStart = () => {
@@ -541,6 +540,7 @@ export function ThreeDTrack(props: {
isSelected() ? "border-gray-12" : "border-transparent",
)}
innerClass="ring-red-5"
+ title={`3D Perspective · ${motionLabel()}`}
segment={segment()}
onMouseDown={(e) => {
e.stopPropagation();
@@ -649,33 +649,20 @@ export function ThreeDTrack(props: {
)}
>
{(() => {
- const ctx = useSegmentContext();
+ const visibleBox = useSegmentVisibleBox();
return (
- <Switch>
- <Match when={ctx.width() < 40}>
- <div class="flex justify-center items-center">
- <IconLucideRotate3d class="size-3.5 text-gray-1 dark:text-gray-12" />
- </div>
- </Match>
- <Match when={ctx.width() < 100}>
- <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
- <IconLucideRotate3d class="size-3" />
- <span>3D</span>
- </div>
- </Match>
- <Match when={true}>
+ <SegmentLabel
+ full={() => (
<div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
<span class="opacity-70">
- {ctx.width() >= 140 ? "3D Perspective" : "3D"}
+ {visibleBox().width >= 140
+ ? "3D Perspective"
+ : "3D"}
</span>
<div class="flex gap-1 items-center text-md">
<IconLucideRotate3d class="size-3.5" />
- <span>
- {hasCamera3DMotion(segment())
- ? "Motion"
- : "Still"}
- </span>
+ <span>{motionLabel()}</span>
{/* Presentation only: the arrow says the shot
moves from its start pose to its end pose. */}
<Show when={hasCamera3DMotion(segment())}>
@@ -683,8 +670,19 @@ export function ThreeDTrack(props: {
</Show>
</div>
</div>
- </Match>
- </Switch>
+ )}
+ compact={() => (
+ <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
+ <IconLucideRotate3d class="size-3" />
+ <span>3D</span>
+ </div>
+ )}
+ glyph={() => (
+ <div class="flex justify-center items-center">
+ <IconLucideRotate3d class="size-3.5 text-gray-1 dark:text-gray-12" />
+ </div>
+ )}
+ />
);
})()}
</SegmentContent>
diff --git a/apps/desktop/src/routes/editor/Timeline/Track.tsx b/apps/desktop/src/routes/editor/Timeline/Track.tsx
index c1778ae2a..ebc13fc6e 100644
--- a/apps/desktop/src/routes/editor/Timeline/Track.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/Track.tsx
@@ -1,10 +1,14 @@
import { mergeRefs } from "@solid-primitives/refs";
import { cx } from "cva";
import {
+ type Accessor,
type ComponentProps,
createMemo,
createSignal,
+ type JSX,
+ Match,
Show,
+ Switch,
splitProps,
} from "solid-js";
import { useEditorContext } from "../context";
@@ -95,7 +99,7 @@ export function SegmentRoot(
return (
<Show when={visible()}>
- <SegmentContextProvider width={width}>
+ <SegmentContextProvider width={width} segment={() => local.segment}>
<div
{...rest}
class={cx(
@@ -133,6 +137,88 @@ export function SegmentRoot(
);
}
+export const SEGMENT_LABEL_FULL_PX = 100;
+export const SEGMENT_LABEL_COMPACT_PX = 48;
+
+// Pixel box of the segment's intersection with the viewport, in
+// segment-local coordinates, with a clamped center for label anchoring.
+// A zoomed-in segment can extend well past the viewport, so its true
+// centre is often off-screen; labels anchor to this instead.
+export function useSegmentVisibleBox(): Accessor<{
+ width: number;
+ centerX: number;
+}> {
+ const { width, segment } = useSegmentContext();
+ const { secsPerPixel } = useTrackContext();
+ const { editorState } = useEditorContext();
+
+ return createMemo(() => {
+ const segmentWidth = width();
+ const { transform } = editorState.timeline;
+
+ const leftPx = (segment().start - transform.position) / secsPerPixel();
+ const viewportPx = transform.zoom / secsPerPixel();
+
+ const visibleStart = Math.max(0, -leftPx);
+ const visibleEnd = Math.min(segmentWidth, viewportPx - leftPx);
+ const visibleWidth = Math.max(0, visibleEnd - visibleStart);
+
+ // Keep the label inside the segment box, but when only a small slice
+ // of a wide segment is on screen the margin must shrink with it, or
+ // the clamp would push the label out of view past the viewport edge.
+ const margin = Math.min(
+ 60,
+ segmentWidth / 2,
+ Math.max(visibleWidth / 2, 4),
+ );
+ const centerX = Math.min(
+ Math.max((visibleStart + visibleEnd) / 2, margin),
+ segmentWidth - margin,
+ );
+
+ return { width: visibleWidth, centerX };
+ });
+}
+
+// Progressive disclosure for segment labels: the label degrades from its
+// full form down to a compact row and then to a state glyph as the visible
+// slice of the segment shrinks, rather than vanishing at a hard cliff.
+export function SegmentLabel(props: {
+ full: () => JSX.Element;
+ compact?: () => JSX.Element;
+ glyph?: () => JSX.Element;
+ fullAt?: number;
+ compactAt?: number;
+}) {
+ const visibleBox = useSegmentVisibleBox();
+
+ const fullAt = () => props.fullAt ?? SEGMENT_LABEL_FULL_PX;
+ const compactAt = () => props.compactAt ?? SEGMENT_LABEL_COMPACT_PX;
+
+ return (
+ <div
+ class="absolute pointer-events-none"
+ style={{
+ left: `${visibleBox().centerX}px`,
+ top: "50%",
+ transform: "translate(-50%, -50%)",
+ "max-width": `${Math.max(0, visibleBox().width - 8)}px`,
+ overflow: "hidden",
+ }}
+ >
+ <Switch>
+ <Match when={visibleBox().width >= fullAt()}>{props.full()}</Match>
+ <Match when={visibleBox().width >= compactAt() && !!props.compact}>
+ {props.compact?.()}
+ </Match>
+ <Match when={visibleBox().width >= 16 && !!props.glyph}>
+ {props.glyph?.()}
+ </Match>
+ </Switch>
+ </div>
+ );
+}
+
export function SegmentContent(props: ComponentProps<"div">) {
const ctx = useSegmentContext();
return (
diff --git a/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
index 7f815c0dc..3f9c347c5 100644
--- a/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
@@ -10,23 +10,20 @@ import {
createRoot,
createSignal,
Index,
- Match,
Show,
- Switch,
} from "solid-js";
import { produce } from "solid-js/store";
+import { generalSettingsStore } from "~/store";
import { commands } from "~/utils/tauri";
import { useEditorContext } from "../context";
-import {
- useSegmentContext,
- useTimelineContext,
- useTrackContext,
-} from "./context";
+import { useTimelineContext, useTrackContext } from "./context";
import {
SegmentContent,
SegmentHandle,
+ SegmentLabel,
SegmentRoot,
TrackRoot,
+ useSegmentVisibleBox,
useSetPreviewTime,
} from "./Track";
@@ -56,6 +53,7 @@ export function ZoomTrack(props: {
const { duration, secsPerPixel } = useTimelineContext();
const setPreviewTime = useSetPreviewTime();
+ const generalSettings = generalSettingsStore.createQuery();
const [creatingSegmentViaDrag, setCreatingSegmentViaDrag] =
createSignal(false);
@@ -225,7 +223,7 @@ export function ZoomTrack(props: {
zoomSegments.splice(index, 0, {
start: baseSegment.start,
end: Math.max(minEndTime, endTime),
- amount: 1.5,
+ amount: generalSettings.data?.defaultZoomAmount ?? 1.5,
mode: "auto",
});
@@ -347,6 +345,9 @@ export function ZoomTrack(props: {
return `${amount.toFixed(1)}x`;
};
+ const zoomModeLabel = () =>
+ segment().mode === "auto" ? "Automatic Zoom" : "Manual Zoom";
+
const zoomSegments = () => project.timeline?.zoomSegments ?? [];
// Double-clicking a handle expands the segment as far as it can go
@@ -525,6 +526,7 @@ export function ZoomTrack(props: {
isSelected() ? "border-gray-12" : "border-transparent",
)}
innerClass="ring-red-5"
+ title={`${zoomModeLabel()} · ${zoomPercentage()}`}
segment={segment()}
onMouseDown={(e) => {
e.stopPropagation();
@@ -539,6 +541,58 @@ export function ZoomTrack(props: {
projectActions.splitZoomSegment(i, splitTime);
}
}}
+ onContextMenu={async (e: MouseEvent) => {
+ e.preventDefault();
+ e.stopPropagation();
+
+ // Right-clicking an unselected segment selects it first,
+ // so the menu always acts on what's highlighted.
+ const selection = editorState.timeline.selection;
+ const targetIndices =
+ selection?.type === "zoom" && selection.indices.includes(i)
+ ? [...selection.indices]
+ : [i];
+ if (
+ targetIndices.length === 1 &&
+ !selectedZoomIndices()?.has(i)
+ )
+ setEditorState("timeline", "selection", {
+ type: "zoom",
+ indices: [i],
+ });
+
+ // `Array` here is effect's module, so derive the index
+ // list from the segments themselves.
+ const allIndices = (project.timeline?.zoomSegments ?? []).map(
+ (_, idx) => idx,
+ );
+
+ const menu = await Menu.new({
+ id: "zoom-segment-options",
+ items: [
+ {
+ id: "selectAllZoomSegments",
+ text: "Select all zoom segments",
+ enabled: allIndices.length > 1,
+ action: () =>
+ setEditorState("timeline", "selection", {
+ type: "zoom",
+ indices: allIndices,
+ }),
+ },
+ {
+ id: "deleteZoomSegments",
+ text:
+ targetIndices.length > 1
+ ? `Delete ${targetIndices.length} zoom segments`
+ : "Delete zoom segment",
+ action: () =>
+ projectActions.deleteZoomSegments(targetIndices),
+ },
+ ],
+ });
+ menu.popup();
+ }}
>
<SegmentHandle
position="start"
@@ -637,28 +691,15 @@ export function ZoomTrack(props: {
)}
>
{(() => {
- const ctx = useSegmentContext();
+ const visibleBox = useSegmentVisibleBox();
return (
- <Switch>
- <Match when={ctx.width() < 40}>
- <div class="flex justify-center items-center">
- <IconLucideSearch class="size-3.5 text-gray-1 dark:text-gray-12" />
- </div>
- </Match>
- <Match when={ctx.width() < 100}>
- <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
- <IconLucideSearch class="size-3" />
- <span>{zoomPercentage()}</span>
- </div>
- </Match>
- <Match when={true}>
+ <SegmentLabel
+ full={() => (
<div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
<span class="opacity-70">
- {ctx.width() >= 140
- ? segment().mode === "auto"
- ? "Automatic Zoom"
- : "Manual Zoom"
+ {visibleBox().width >= 140
+ ? zoomModeLabel()
: "Zoom"}
</span>
<div class="flex gap-1 items-center text-md">
@@ -666,8 +707,19 @@ export function ZoomTrack(props: {
{zoomPercentage()}
</div>
</div>
- </Match>
- </Switch>
+ )}
+ compact={() => (
+ <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
+ <IconLucideSearch class="size-3" />
+ <span>{zoomPercentage()}</span>
+ </div>
+ )}
+ glyph={() => (
+ <div class="flex justify-center items-center">
+ <IconLucideSearch class="size-3.5 text-gray-1 dark:text-gray-12" />
+ </div>
+ )}
+ />
);
})()}
</SegmentContent>
diff --git a/apps/desktop/src/routes/editor/Timeline/context.ts b/apps/desktop/src/routes/editor/Timeline/context.ts
index 2d614db66..c35f44ad8 100644
--- a/apps/desktop/src/routes/editor/Timeline/context.ts
+++ b/apps/desktop/src/routes/editor/Timeline/context.ts
@@ -35,6 +35,7 @@ type TrackContextValue = {
type SegmentContextValue = {
width: Accessor<number>;
+ segment: Accessor<{ start: number; end: number }>;
};
export const [TimelineContextProvider, useTimelineContext] =
@@ -102,7 +103,10 @@ export const [TrackContextProvider, useTrackContext] = createContextProvider(
export const [SegmentContextProvider, useSegmentContext] =
createContextProvider(
- (props: { width: Accessor<number> }) => {
+ (props: {
+ width: Accessor<number>;
+ segment: Accessor<{ start: number; end: number }>;
+ }) => {
return props;
},
null as unknown as SegmentContextValue,
diff --git a/apps/desktop/src/routes/editor/Timeline/index.tsx b/apps/desktop/src/routes/editor/Timeline/index.tsx
index 4cd4af158..240c52021 100644
--- a/apps/desktop/src/routes/editor/Timeline/index.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/index.tsx
@@ -1,5 +1,8 @@
import { createElementBounds } from "@solid-primitives/bounds";
-import { createEventListener } from "@solid-primitives/event-listener";
+import {
+ createEventListener,
+ createEventListenerMap,
+} from "@solid-primitives/event-listener";
import { LogicalPosition } from "@tauri-apps/api/dpi";
import { Menu, MenuItem } from "@tauri-apps/api/menu";
import { platform } from "@tauri-apps/plugin-os";
@@ -49,6 +52,7 @@ import { ClipTrack } from "./ClipTrack";
import { TimelineContextProvider, useTimelineContext } from "./context";
import { type KeyboardSegmentDragState, KeyboardTrack } from "./KeyboardTrack";
import { type MaskSegmentDragState, MaskTrack } from "./MaskTrack";
+import { Minimap } from "./Minimap";
import { type SceneSegmentDragState, SceneTrack } from "./SceneTrack";
import { type TextSegmentDragState, TextTrack } from "./TextTrack";
import { type ThreeDSegmentDragState, ThreeDTrack } from "./ThreeDTrack";
@@ -812,8 +816,44 @@ export function Timeline(props: {
};
}
- async function handleUpdatePlayhead(e: MouseEvent) {
+ function timelineTimeFromClientX(clientX: number) {
const metrics = getTimelineContentMetrics();
+ if (!metrics) return null;
+ const rawTime =
+ secsPerPixel() * (clientX - metrics.left) + transform().position;
+ // Snap to the very start when the cursor lands within a few pixels
+ // of the timeline origin so hitting exactly 0:00 isn't a battle
+ const snappedTime = rawTime / secsPerPixel() <= START_SNAP_PX ? 0 : rawTime;
+ return Math.min(Math.max(0, snappedTime), totalDuration());
+ }
+
+ async function seekPlayheadTo(newTime: number) {
+ // If playing, some backends require restart to seek reliably
+ if (editorState.playing) {
+ try {
+ await commands.stopPlayback();
+
+ // Round to nearest frame to prevent off-by-one drift
+ const targetFrame = Math.round(newTime * FPS);
+ await commands.seekTo(targetFrame);
+
+ // If the user paused during these async ops, bail out without restarting
+ if (!editorState.playing) {
+ setEditorState("playbackTime", newTime);
+ return;
+ }
+
+ await commands.startPlayback(FPS, previewResolutionBase());
+ setEditorState("playing", true);
+ } catch (err) {
+ console.error("Failed to seek during playback:", err);
+ }
+ }
+
+ setEditorState("playbackTime", newTime);
+ }
+
+ async function handleUpdatePlayhead(e: MouseEvent) {
if (
zoomSegmentDragState.type !== "moving" &&
sceneSegmentDragState.type !== "moving" &&
@@ -824,39 +864,100 @@ export function Timeline(props: {
keyboardSegmentDragState.type !== "moving" &&
threeDSegmentDragState.type !== "moving"
) {
- if (!metrics) return;
- const rawTime =
- secsPerPixel() * (e.clientX - metrics.left) + transform().position;
- // Snap to the very start when the cursor lands within a few pixels
- // of the timeline origin so hitting exactly 0:00 isn't a battle
- const snappedTime =
- rawTime / secsPerPixel() <= START_SNAP_PX ? 0 : rawTime;
- const newTime = Math.min(Math.max(0, snappedTime), totalDuration());
-
- // If playing, some backends require restart to seek reliably
- if (editorState.playing) {
- try {
- await commands.stopPlayback();
-
- // Round to nearest frame to prevent off-by-one drift
- const targetFrame = Math.round(newTime * FPS);
- await commands.seekTo(targetFrame);
-
- // If the user paused during these async ops, bail out without restarting
- if (!editorState.playing) {
- setEditorState("playbackTime", newTime);
- return;
- }
+ const newTime = timelineTimeFromClientX(e.clientX);
+ if (newTime === null) return;
+ await seekPlayheadTo(newTime);
+ }
+ }
- await commands.startPlayback(FPS, previewResolutionBase());
- setEditorState("playing", true);
- } catch (err) {
- console.error("Failed to seek during playback:", err);
- }
+ function beginRulerScrub(downEvent: MouseEvent) {
+ if (downEvent.button !== 0) return;
+ downEvent.stopPropagation();
+
+ let lastClientX = downEvent.clientX;
+ let seekInFlight = false;
+ let seekQueued = false;
+ let panRafId: number | null = null;
+
+ const contentEdges = () => {
+ const metrics = getTimelineContentMetrics();
+ if (!metrics || metrics.width <= 0) return null;
+ return { left: metrics.left, right: metrics.left + metrics.width };
+ };
+
+ // While playing, each seek is a stop/seek/restart round-trip, so scrub
+ // updates are coalesced to one in-flight seek with the latest position
+ // applied once it settles.
+ const applyScrub = () => {
+ const edges = contentEdges();
+ const clientX = edges
+ ? Math.min(Math.max(lastClientX, edges.left), edges.right)
+ : lastClientX;
+ const newTime = timelineTimeFromClientX(clientX);
+ if (newTime === null) return;
+ if (seekInFlight) {
+ seekQueued = true;
+ return;
}
+ seekInFlight = true;
+ void seekPlayheadTo(newTime).finally(() => {
+ seekInFlight = false;
+ if (seekQueued) {
+ seekQueued = false;
+ applyScrub();
+ }
+ });
+ };
- setEditorState("playbackTime", newTime);
- }
+ const stepEdgePan = () => {
+ panRafId = null;
+ const edges = contentEdges();
+ if (!edges) return;
+ const overshoot =
+ lastClientX < edges.left
+ ? lastClientX - edges.left
+ : lastClientX > edges.right
+ ? lastClientX - edges.right
+ : 0;
+ if (overshoot === 0) return;
+ const panPx =
+ Math.sign(overshoot) * Math.min(Math.abs(overshoot) * 0.2, 12);
+ transform().setPosition(transform().position + panPx * secsPerPixel());
+ applyScrub();
+ panRafId = requestAnimationFrame(stepEdgePan);
+ };
+
+ const ensureEdgePan = () => {
+ if (panRafId === null) panRafId = requestAnimationFrame(stepEdgePan);
+ };
+
+ applyScrub();
+ ensureEdgePan();
+
+ createRoot((dispose) => {
+ onCleanup(() => {
+ if (panRafId !== null) {
+ cancelAnimationFrame(panRafId);
+ panRafId = null;
+ }
+ });
+ createEventListenerMap(window, {
+ mousemove: (event) => {
+ lastClientX = event.clientX;
+ applyScrub();
+ ensureEdgePan();
+ },
+ mouseup: () => {
+ batch(() => {
+ setEditorState("timeline", "selection", null);
+ setEditorState("timeline", "audioPicker", null);
+ setEditorState("timeline", "camera3dSetup", null);
+ });
+ dispose();
+ },
+ blur: () => dispose(),
+ });
+ });
}
createEventListener(window, "keydown", (e) => {
@@ -915,6 +1016,36 @@ export function Timeline(props: {
setEditorState("timeline", "selection", null);
setEditorState("timeline", "audioPicker", null);
setEditorState("timeline", "camera3dSetup", null);
+ } else if (
+ e.code === "KeyA" &&
+ (e.metaKey || e.ctrlKey) &&
+ !e.shiftKey &&
+ !e.altKey
+ ) {
+ // Cmd/Ctrl+A expands the current selection to every segment on the
+ // same track.
+ const selection = editorState.timeline.selection;
+ if (!selection || selection.type === "transition") return;
+
+ const timeline = project.timeline;
+ const segmentCount = {
+ clip: timeline?.segments.length ?? 0,
+ zoom: timeline?.zoomSegments?.length ?? 0,
+ scene: timeline?.sceneSegments?.length ?? 0,
+ mask: timeline?.maskSegments?.length ?? 0,
+ caption: timeline?.captionSegments?.length ?? 0,
+ keyboard: timeline?.keyboardSegments?.length ?? 0,
+ text: timeline?.textSegments?.length ?? 0,
+ audio: timeline?.audioSegments?.length ?? 0,
+ "3d": timeline?.camera3dSegments?.length ?? 0,
+ }[selection.type];
+ if (!segmentCount) return;
+
+ e.preventDefault();
+ setEditorState("timeline", "selection", {
+ type: selection.type,
+ indices: Array.from({ length: segmentCount }, (_, i) => i),
+ });
}
});
@@ -1075,6 +1206,17 @@ export function Timeline(props: {
}
}}
>
+ <div
+ class="absolute z-30"
+ style={{
+ top: "2px",
+ left: `${TIMELINE_PADDING + TRACK_GUTTER}px`,
+ right: `${TIMELINE_PADDING}px`,
+ height: "12px",
+ }}
+ >
+ <Minimap />
+ </div>
<div
class="relative z-20"
style={{ height: `${TIMELINE_HEADER_HEIGHT}px` }}
@@ -1092,10 +1234,20 @@ export function Timeline(props: {
onAdd={handleAddTrack}
/>
</div>
+ {/* Scrub surface for the ruler. It reaches START_SNAP_PX left of
+ the timeline origin so the snap-to-zero zone always places the
+ playhead instead of hitting the "Add track" trigger beneath. */}
+ <div
+ class="absolute inset-y-0 right-0 z-40"
+ style={{ left: `${TRACK_GUTTER - START_SNAP_PX}px` }}
+ onMouseDown={beginRulerScrub}
+ />
</div>
<Show
when={
- !editorState.playing && editorState.previewTime !== null
+ !editorState.playing &&
+ editorState.previewTime !== null &&
+ editorState.timeline.splitPreview === null
? { time: editorState.previewTime }
: null
}
@@ -1141,6 +1293,27 @@ export function Timeline(props: {
>
<div class="size-3 bg-[rgb(226,64,64)] rounded-full -mt-2 -ml-[calc(0.37rem-0.5px)]" />
</div>
+ <Show when={split() ? editorState.timeline.splitPreview : null}>
+ {(preview) => (
+ <div
+ class={cx(
+ "absolute bottom-0 z-20 w-px pointer-events-none",
+ preview().snapped ? "bg-blue-9" : "bg-gray-10/70",
+ )}
+ style={{
+ left: `${TIMELINE_PADDING + TRACK_GUTTER}px`,
+ top: `${PLAYHEAD_TOP_OFFSET}px`,
+ transform: `translateX(${
+ (preview().time - transform().position) / secsPerPixel()
+ }px)`,
+ }}
+ >
+ <Show when={preview().snapped}>
+ <div class="absolute top-0 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rotate-45 rounded-[1px] bg-blue-9" />
+ </Show>
+ </div>
+ )}
+ </Show>
<div
class="relative flex-1 min-h-0"
style={{
diff --git a/apps/desktop/src/routes/editor/Timeline/split-snapping.ts b/apps/desktop/src/routes/editor/Timeline/split-snapping.ts
new file mode 100644
index 000000000..1e2326382
--- /dev/null
+++ b/apps/desktop/src/routes/editor/Timeline/split-snapping.ts
@@ -0,0 +1,66 @@
+// Pure geometry for split-mode snapping on the timeline. All times are in
+// output (rendered) time, the domain every non-clip track stores directly and
+// the clip track draws in; the caller converts the pixel snap radius via
+// secsPerPixel. Targets within EDGE_EPSILON of the hovered clip's edges are
+// rejected — snapping there would cut off a near-zero-length piece.
+
+import type { TimelineConfiguration } from "~/utils/tauri";
+
+export const SPLIT_SNAP_PX = 7;
+export const SPLIT_EDGE_EPSILON = 0.05;
+
+export type SplitSnapResult = {
+ time: number;
+ snapped: { time: number } | null;
+};
+
+const BOUNDARY_TRACKS = [
+ "zoomSegments",
+ "sceneSegments",
+ "camera3dSegments",
+ "textSegments",
+ "maskSegments",
+ "captionSegments",
+ "keyboardSegments",
+ "audioSegments",
+] as const;
+
+export function snapSplitTime(
+ raw: number,
+ clipStart: number,
+ clipEnd: number,
+ radius: number,
+ timeline: TimelineConfiguration | null | undefined,
+ playhead: number,
+): SplitSnapResult {
+ const min = clipStart + SPLIT_EDGE_EPSILON;
+ const max = clipEnd - SPLIT_EDGE_EPSILON;
+ let best: number | null = null;
+ let bestDist = Number.POSITIVE_INFINITY;
+
+ const consider = (t: number) => {
+ if (t < min || t > max) return;
+ const dist = Math.abs(t - raw);
+ if (dist > radius) return;
+ if (dist < bestDist || (dist === bestDist && best !== null && t < best)) {
+ bestDist = dist;
+ best = t;
+ }
+ };
+
+ consider(playhead);
+ if (timeline) {
+ for (const key of BOUNDARY_TRACKS) {
+ const segments = timeline[key];
+ if (!segments) continue;
+ for (const segment of segments) {
+ consider(segment.start);
+ consider(segment.end);
+ }
+ }
+ }
+
+ return best === null
+ ? { time: raw, snapped: null }
+ : { time: best, snapped: { time: best } };
+}
diff --git a/apps/desktop/src/routes/editor/context.ts b/apps/desktop/src/routes/editor/context.ts
index c12d244a1..ccdc51e33 100644
--- a/apps/desktop/src/routes/editor/context.ts
+++ b/apps/desktop/src/routes/editor/context.ts
@@ -1437,6 +1437,7 @@ export const [EditorContextProvider, useEditorContext] = createContextProvider(
},
timeline: {
interactMode: "seek" as "seek" | "split",
+ splitPreview: null as null | { time: number; snapped: boolean },
selection: null as
| null
| { type: "zoom"; indices: number[] }