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): playhead and ruler reworked to the reference design

Etienne Lescot7e4197460d53
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.css
index 9c3973930..280408ba6 100644
--- a/src/components/ai-edition/v4/EditorShellV4.module.css
+++ b/src/components/ai-edition/v4/EditorShellV4.module.css
@@ -953,6 +953,26 @@
min-height: 0;
height: 100%;
overflow: hidden;
+ /* The playhead's head sits ENTIRELY above the ruler, its tip landing on the
+ line's top edge — that's what keeps it clear of the tick labels below. It
+ deliberately overshoots the timeline body by --playhead-head-overshoot, so
+ it breaks past the toolbar's bottom rule and reads as floating OVER the
+ timeline rather than as a shape cut off by it. What's left of its height is
+ the gap the ruler needs below the body's top edge (--playhead-head-clear),
+ which .tlRulerRow pads by; .tlPlayheadLayer pads by the full height and is
+ pulled up by the overshoot, so both content boxes still start on the same
+ line. Derive, don't hand-tune: only -w/-h/-overshoot should ever change. */
+ --playhead-head-w: 16px;
+ --playhead-head-h: 18px;
+ --playhead-head-overshoot: 4px;
+ --playhead-head-clear: calc(var(--playhead-head-h) - var(--playhead-head-overshoot));
+ /* The pan/zoom bar's band, kept here (not just on .tlNav) because the playhead
+ layer stretches by exactly this much to run behind it, down to the panel's
+ bottom edge. */
+ --tl-nav-h: 20px;
+ --tl-nav-gap-top: 8px;
+ --tl-nav-gap-bottom: 12px;
+ --tl-nav-band: calc(var(--tl-nav-h) + var(--tl-nav-gap-top) + var(--tl-nav-gap-bottom));
}
.tlToolbar {
display: flex;
@@ -1028,11 +1048,15 @@
so they move with the header (not with the scrolling tracks) when the panel is
resized. overflow:hidden clips the zoom-transformed canvas horizontally. Its
canvas is exactly as wide as .tlTracks' because the tracks scrollbar is hidden
- (takes no width), so ticks stay aligned with the clips + playhead. */
+ (takes no width), so ticks stay aligned with the clips + playhead.
+ The top padding is the playhead head's clearance, not decoration: the head
+ hangs off the top of the line, so this gap is what the ruler content needs to
+ start below it. .tlPlayheadLayer is offset to match, so both content boxes
+ begin on the same line and the tick labels land under the head. */
.tlRulerRow {
position: relative;
flex-shrink: 0;
- padding: 8px 20px 0;
+ padding: var(--playhead-head-clear) 20px 0;
overflow: hidden;
cursor: text;
}
@@ -1077,11 +1101,21 @@
cursor, so it doesn't scroll with the lanes). Same horizontal padding as the
canvases (and the tracks scrollbar is hidden, so equal width) → its transformed
line/head aligns exactly with ticks/clips. pointer-events pass through (except
- the diamond) so scrubbing still works. */
+ the head) so scrubbing still works.
+ It is deliberately LARGER than .tlBody at both ends. Up top by the head's
+ overshoot, so the head isn't clipped where it breaks past the toolbar rule.
+ Down below by the whole pan/zoom band, so the line reaches the panel's bottom
+ edge instead of stopping at the tracks — it runs BEHIND the pan/zoom bar, which
+ lifts itself over the line with a higher z-index. No bottom padding, for the
+ same reason: any inset there leaves the line short of the clips as soon as the
+ lanes are scrolled up. */
.tlPlayheadLayer {
position: absolute;
- inset: 0;
- padding: 8px 20px;
+ top: calc(-1 * var(--playhead-head-overshoot));
+ right: 0;
+ bottom: calc(-1 * var(--tl-nav-band));
+ left: 0;
+ padding: var(--playhead-head-h) 20px 0;
overflow: hidden;
pointer-events: none;
z-index: 6;
@@ -1089,41 +1123,75 @@
.tlPlayheadLayer .tlCanvas {
height: 100%;
}
-/* One continuous line from the ruler down through the clips, stopping just above
- the zoom/nav bar, with the draggable diamond head at the top (in the ruler). */
+/* One continuous line from the ruler down through the clips and on behind the
+ zoom/nav bar to the panel's bottom edge, with the draggable head at the top
+ (hanging above the ruler). */
.tlPlayhead {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
- background: var(--accent);
+ background: var(--playhead);
border-radius: 1px;
- box-shadow: 0 0 10px var(--accent-soft);
+ /* Wide, soft halo: the line is only 2px, and this is what keeps it findable
+ as it crosses dark lanes and pale clip cards alike. */
+ box-shadow: 0 0 18px var(--playhead-glow);
pointer-events: none;
}
-.tlPlayheadDiamond {
+/* Map-pin head: a rounded rectangle that tapers to a point at the bottom, the
+ point landing exactly on the top of the line (translate -100%). It therefore
+ sits wholly ABOVE the ruler and can't cover the tick labels.
+ The shape is border-radius ∩ clip-path: the polygon cuts the bottom into a
+ point while the radius keeps the two TOP corners round — a polygon alone
+ would give four hard corners, a radius alone no point. */
+.tlPlayheadHead {
position: absolute;
- /* Caps the very top of the playhead line (the line runs down from here). */
top: 0;
left: 50%;
- transform: translate(-50%, -50%) rotate(45deg);
- width: 9px;
- height: 9px;
- background: var(--accent);
- border-radius: 2px;
- box-shadow: 0 0 8px var(--accent-soft);
-}
+ transform: translate(-50%, -100%);
+ width: var(--playhead-head-w);
+ height: var(--playhead-head-h);
+ box-sizing: border-box;
+ background: var(--playhead);
+ border-radius: 4px;
+ /* 67% keeps the point ~6px tall whatever --playhead-head-h is; the extra
+ height all goes to the rectangular top. */
+ clip-path: polygon(0% 0%, 100% 0%, 100% 67%, 50% 100%, 0% 67%);
+ filter: drop-shadow(0 1px 3px var(--playhead-shadow));
+}
+/* Ruler ticks are positioned absolutely at their real time, not spread evenly
+ by a flex row — that's what keeps a label under the frame it names once the
+ canvas is zoomed. Tick density is picked per zoom level in
+ V4Timeline#rulerTicks. */
.tlRuler {
- display: flex;
- justify-content: space-between;
- height: 15px;
- margin-bottom: 7px;
- padding-inline: 2px;
+ position: relative;
+ height: 28px;
+ margin-bottom: 6px;
+ border-bottom: 1px solid var(--border-soft);
}
-.tlRuler span {
+/* Ticks hang from the TOP of the band and the label sits under them, so the
+ numbers are below the playhead head rather than behind it. */
+.tlTick {
+ position: absolute;
+ top: 0;
+ width: 1px;
+ height: 5px;
+ background: var(--border);
+}
+.tlTickMajor {
+ height: 9px;
+ background: var(--border-hi);
+}
+.tlTickLabel {
+ position: absolute;
+ top: 12px;
+ left: 50%;
+ transform: translateX(-50%);
font-family: var(--font-mono);
font-size: 10px;
color: var(--meta);
+ white-space: nowrap;
+ pointer-events: none;
}
.tlLane {
position: relative;
@@ -1134,13 +1202,20 @@
}
.laneEmpty {
position: absolute;
- inset: 0;
+ /* left/width come from V4Timeline (the visible window, not the whole zoomed
+ canvas) — see renderPills. */
+ top: 0;
+ bottom: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
- color: var(--muted);
+ font-weight: 500;
+ /* Deliberately quieter than lane content: it's a standing hint on every empty
+ lane, so at --muted five of them shout over the clips. */
+ color: var(--meta);
pointer-events: none;
+ user-select: none;
}
.lanePill {
position: absolute;
@@ -1335,9 +1410,12 @@
}
.tlNav {
position: relative;
- height: 20px;
- margin: 8px 20px 12px;
+ height: var(--tl-nav-h);
+ margin: var(--tl-nav-gap-top) 20px var(--tl-nav-gap-bottom);
flex-shrink: 0;
+ /* Above .tlPlayheadLayer's z-index: the playhead line now runs the full height
+ of the panel, and this bar is meant to sit ON TOP of it, not be crossed. */
+ z-index: 7;
}
.tlNavTrack {
position: absolute;
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 8e53bf75f..883c8500d 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -63,15 +63,41 @@ const ASSET_MIME = "application/x-axcut-asset";
type ToolId = "cut" | "comment" | "speed";
-// Ruler tick labels sit on whole-second "nice" steps, so tenths are always
-// ".0" noise — show clean M:SS (H:MM:SS past an hour) instead.
-function fmtTick(sec: number): string {
+// "Nice" ruler steps, from a 20th of a second up to an hour. The one that gets
+// used depends on the zoom (see rulerTicks), so the ladder has to cover both a
+// 5-second span blown up across the panel and a two-hour recording.
+const TICK_STEPS_SEC = [
+ 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600,
+];
+/** Smallest gap two ruler labels may sit at — the step grows until they clear it. */
+const MIN_LABEL_GAP_PX = 76;
+/** Unlabelled ticks drawn between two labelled ones. */
+const MINOR_PER_MAJOR = 5;
+
+// Ruler tick label. Precision follows the step: whole seconds read as a clean
+// M:SS, but once the ruler is zoomed past one tick per second the fraction is
+// the only thing telling two labels apart.
+function fmtTick(sec: number, stepSec: number): string {
if (!Number.isFinite(sec) || sec < 0) sec = 0;
- const total = Math.round(sec);
- const h = Math.floor(total / 3600);
- const m = Math.floor((total % 3600) / 60);
- const ss = String(total % 60).padStart(2, "0");
- return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${ss}` : `${m}:${ss}`;
+ const digits = stepSec < 0.5 ? 2 : stepSec < 1 ? 1 : 0;
+ const h = Math.floor(sec / 3600);
+ const m = Math.floor((sec % 3600) / 60);
+ const s = sec % 60;
+ if (h > 0) {
+ const mm = String(m).padStart(2, "0");
+ const ss = String(Math.floor(s)).padStart(2, "0");
+ return `${h}:${mm}:${ss}`;
+ }
+ if (digits > 0) {
+ const [whole, frac] = s.toFixed(digits).split(".");
+ return `${m}:${whole.padStart(2, "0")}.${frac}`;
+ }
+ return `${m}:${String(Math.round(s)).padStart(2, "0")}`;
+}
+
+interface RulerTick {
+ sec: number;
+ major: boolean;
}
interface PlayheadOverlayProps {
@@ -114,7 +140,7 @@ const PlayheadOverlay = memo(function PlayheadOverlay({
<div className={styles.tlCanvas} style={canvasStyle}>
<div ref={playheadRef} className={styles.tlPlayhead} style={{ left: `${pct}%` }}>
<span
- className={styles.tlPlayheadDiamond}
+ className={styles.tlPlayheadHead}
style={{ pointerEvents: "auto", cursor: "grab" }}
onPointerDown={(e) => {
e.stopPropagation();
@@ -260,6 +286,10 @@ export function V4Timeline({
// not a select). Reset at the start of each new clip pointerdown.
const didClipDragRef = useRef(false);
const [nav, setNav] = useState({ start: 0, end: 1 });
+ // On-screen width of one full (unzoomed) timeline, in px. The ruler needs it
+ // to pick a tick step that reads at THIS panel size — a step that looks right
+ // on a wide window crams into an unreadable smear on a narrow one.
+ const [viewportWidthPx, setViewportWidthPx] = useState(0);
const [dragOver, setDragOver] = useState(false);
const [snapPct, setSnapPct] = useState<number | null>(null);
// Live clip-reorder drag: the dragged clip follows the pointer directly
@@ -364,15 +394,30 @@ export function V4Timeline({
sourceIds: g.ids,
}));
- const rulerTicks = useMemo(() => {
- // Adaptive interval so a long recording shows ~a dozen labels instead of
- // one every 15s (which crams the ruler unreadably past a few minutes).
- const NICE_STEPS = [1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 900, 1800, 3600];
- const step = NICE_STEPS.find((s) => total / s <= 12) ?? NICE_STEPS[NICE_STEPS.length - 1];
- const out: string[] = [];
- for (let t = 0; t <= total; t += step) out.push(fmtTick(t));
- return out;
- }, [total]);
+ // Ruler ticks are chosen from what is actually ON SCREEN, not from the clip
+ // length: the canvas is widened by 1/navSpan, so the same recording shows one
+ // label per 30s zoomed out and one per tenth of a second zoomed in. The step
+ // is the first "nice" one whose on-screen gap clears MIN_LABEL_GAP_PX, which
+ // is why the labels never collide however narrow the panel gets.
+ const rulerTicks = useMemo((): { step: number; ticks: RulerTick[] } => {
+ const span = Math.max(0.02, nav.end - nav.start);
+ const pxPerSec = viewportWidthPx / span / total;
+ if (!Number.isFinite(pxPerSec) || pxPerSec <= 0) return { step: 1, ticks: [] };
+ const step =
+ TICK_STEPS_SEC.find((s) => s * pxPerSec >= MIN_LABEL_GAP_PX) ??
+ TICK_STEPS_SEC[TICK_STEPS_SEC.length - 1];
+ const minor = step / MINOR_PER_MAJOR;
+ // Emit the visible window only (plus a step of margin so a tick never pops
+ // in at the edge): at a 50× zoom the full timeline would otherwise be
+ // thousands of off-screen nodes re-rendered on every pan.
+ const from = Math.max(0, nav.start * total - step);
+ const to = Math.min(total, nav.end * total + step);
+ const ticks: RulerTick[] = [];
+ for (let i = Math.ceil(from / minor - 1e-6); i * minor <= to + 1e-6; i++) {
+ ticks.push({ sec: i * minor, major: i % MINOR_PER_MAJOR === 0 });
+ }
+ return { step, ticks };
+ }, [total, nav.start, nav.end, viewportWidthPx]);
// Live scrub position. The store write behind it is rAF-throttled (see
// seekToClientX), so this keeps the playhead and the timecode pinned to the
@@ -429,7 +474,7 @@ export function V4Timeline({
);
// Mousedown anywhere on the empty timeline (ruler, lanes background, or
- // the playhead diamond itself) seeks immediately AND arms a scrub drag —
+ // the playhead head itself) seeks immediately AND arms a scrub drag —
// a single pointerdown→pointermove→pointerup replaces the old
// click-only seek, and doubles as the playhead's drag handle since
// dragging from its exact position is the same math as dragging from
@@ -674,11 +719,29 @@ export function V4Timeline({
return () => el.removeEventListener("wheel", onWheelNative);
}, []);
+ // Track the tracks' content width for the ruler. .tlTracks and .tlRulerRow
+ // carry the same horizontal padding and the tracks' scrollbar is hidden, so
+ // this content box is exactly one unzoomed canvas wide.
+ useEffect(() => {
+ const el = tracksRef.current;
+ if (!el) return;
+ setViewportWidthPx(el.clientWidth);
+ const ro = new ResizeObserver((entries) => {
+ for (const entry of entries) setViewportWidthPx(entry.contentRect.width);
+ });
+ ro.observe(el);
+ return () => ro.disconnect();
+ }, []);
+
// zoom/pan: the tracks canvas is widened by 1/(navEnd-navStart) and shifted.
+ // The width % resolves against the CONTAINER, the translate % against the
+ // canvas's own (already widened) box — so scrolling to nav.start is a flat
+ // -nav.start of the canvas. Scaling it by 1/navSpan as well double-counted
+ // the zoom and threw the whole timeline off-screen at any nav.start > 0.
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)}%)`,
+ transform: `translateX(${(-nav.start * 100).toFixed(3)}%)`,
} as const;
const laneOf = (kind: LanePill["kind"]) =>
@@ -954,7 +1017,15 @@ export function V4Timeline({
return (
<>
{effectivePills.length === 0 ? (
- <span className={styles.laneEmpty}>{emptyLabel}</span>
+ // The lane is as wide as the ZOOMED canvas, so centring the hint on it
+ // would slide it off-screen as soon as the timeline is zoomed in. Span
+ // the visible window instead, and the hint stays centred in view.
+ <span
+ className={styles.laneEmpty}
+ style={{ left: `${nav.start * 100}%`, width: `${navSpan * 100}%` }}
+ >
+ {emptyLabel}
+ </span>
) : null}
{effectivePills.flatMap((p) => {
// Eager split preview: the instant a clip is grabbed, a pill that
@@ -1226,8 +1297,16 @@ export function V4Timeline({
<div className={styles.tlRulerRow} onPointerDown={startScrub}>
<div className={styles.tlCanvas} style={canvasStyle}>
<div className={styles.tlRuler}>
- {rulerTicks.map((t, i) => (
- <span key={`${t}-${i}`}>{t}</span>
+ {rulerTicks.ticks.map((tick) => (
+ <div
+ key={tick.sec}
+ className={`${styles.tlTick}${tick.major ? ` ${styles.tlTickMajor}` : ""}`}
+ style={{ left: `${pctOf(tick.sec)}%` }}
+ >
+ {tick.major ? (
+ <span className={styles.tlTickLabel}>{fmtTick(tick.sec, rulerTicks.step)}</span>
+ ) : null}
+ </div>
))}
</div>
</div>
@@ -1241,15 +1320,20 @@ export function V4Timeline({
{showLanes ? (
<>
+ {/* An empty lane advertises the shortcut that fills it ("Press A to add
+ annotation") rather than restating that it is empty — the same hint
+ strings the pre-v4 timeline used, so the keys stay translated. */}
+ <div className={styles.tlLane}>
+ {renderPills(annPills, t("hints.pressAnnotation"))}
+ </div>
<div className={styles.tlLane}>
- {renderPills(annPills, t("toolbar.noAnnotationsYet"))}
+ {renderPills(speedPills, t("hints.pressSpeed"))}
</div>
+ <div className={styles.tlLane}>{renderPills(trimPills, t("hints.pressTrim"))}</div>
+ <div className={styles.tlLane}>{renderPills(zoomPills, t("hints.pressZoom"))}</div>
<div className={styles.tlLane}>
- {renderPills(speedPills, t("toolbar.constantSpeed"))}
+ {renderPills(cameraFullscreenPills, t("hints.pressCameraFullscreen"))}
</div>
- <div className={styles.tlLane}>{renderPills(trimPills, t("toolbar.noTrims"))}</div>
- <div className={styles.tlLane}>{renderPills(zoomPills, "")}</div>
- <div className={styles.tlLane}>{renderPills(cameraFullscreenPills, "")}</div>
</>
) : null}
diff --git a/src/styles/design-tokens.css b/src/styles/design-tokens.css
index 15c88c91c..1f6bf3a56 100644
--- a/src/styles/design-tokens.css
+++ b/src/styles/design-tokens.css
@@ -49,6 +49,15 @@
--accent-ring: rgba(16, 185, 129, 0.28);
--accent-stripe: rgba(16, 185, 129, 0.30);
+ /* timeline playhead — deliberately NOT the mint accent. The scrub cursor
+ crosses every lane, including the accent-coloured zoom pills, so it needs
+ a hue of its own to stay readable on top of them. One value for both
+ themes (the dark block doesn't override it): this violet carries against
+ the light and the dark timeline surfaces alike. */
+ --playhead: #6c55ff;
+ --playhead-glow: rgba(108, 85, 255, 0.68);
+ --playhead-shadow: rgba(108, 85, 255, 0.35);
+
/* legacy shadcn-style aliases → canonical tokens. Referenced by the
TimelinePane / TranscriptEditor / VirtualPreview / NewEditorShell module
CSS that was ported before the token system existed. Defined via var()