Skip to content

Commit 06340f6

Browse files
fix(studio): clip pictures at full strength and a seam where touching clips meet (#4309)
* fix(studio): composition and text clips show their frame at full strength CompositionThumbnail drew its frames at 0.7 opacity with a lighten blend, the only timeline picture dimmed that way; on a light theme the frame nearly vanished into the clip. Opacity and blend are now theme tokens, untinted by default like video and image clips. * fix(studio): touching clips show a hairline seam where they meet Two clips that meet end to start used to read as one long bar. Each exact join on a row now gets a 1px line in the row colour, drawn over the clips. Clip positions, widths and keyframe diamonds do not move, so the timeline still tells the truth about time. * fix(studio): hide clip join seams while a clip is being moved A moved clip is drawn by the drag overlay, not at its element position, so its join line stayed behind at the old boundary until the drop. Rows draw no join lines during a move or multi-clip drag; they come back on drop. The join math now reuses the lane helpers for sort order and the touching tolerance. * refactor(studio): drop a multi-drag check the move-drag check already covers A multi-clip drag preview only exists once a move drag has started, so the join lines only need the move-drag check.
1 parent 29378b6 commit 06340f6

9 files changed

Lines changed: 172 additions & 22 deletions

‎packages/studio/src/player/components/CompositionThumbnail.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ describe("CompositionThumbnail", () => {
137137
const tiles = [...host.querySelectorAll("img")];
138138
expect(tiles.length).toBeGreaterThan(0);
139139
expect(tiles.every((tile) => !tile.classList.contains("hidden"))).toBe(true);
140+
// Pictures read untinted by default, like video filmstrips; the theme tokens own any dimming.
141+
expect(
142+
tiles.every((tile) => tile.style.opacity === "var(--timeline-composition-thumbnail-opacity)"),
143+
).toBe(true);
144+
expect(tiles[0]?.parentElement?.parentElement?.style.mixBlendMode).toBe(
145+
"var(--timeline-composition-thumbnail-blend)",
146+
);
140147
});
141148

142149
it("aborts its scheduled off-DOM image probe when unmounted", async () => {

‎packages/studio/src/player/components/CompositionThumbnail.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { memo, useCallback, useMemo, useRef, useState } from "react";
1+
import { memo, useCallback, useMemo, useRef, useState, type CSSProperties } from "react";
22
import { useMountEffect } from "../../hooks/useMountEffect";
33
import { useThumbnailLease } from "../../hooks/useThumbnailLease";
44
import { createThumbnailKey, type ThumbnailPriority } from "../lib/thumbnailScheduler";
@@ -153,7 +153,11 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
153153
{value && (
154154
<div
155155
className="absolute inset-0 flex"
156-
style={{ animation: "hf-thumb-fade 200ms ease-out", mixBlendMode: "lighten" }}
156+
style={{
157+
animation: "hf-thumb-fade 200ms ease-out",
158+
mixBlendMode:
159+
"var(--timeline-composition-thumbnail-blend)" as CSSProperties["mixBlendMode"],
160+
}}
157161
>
158162
{Array.from({ length: frameCount }, (_, index) => (
159163
<div
@@ -166,7 +170,7 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
166170
alt=""
167171
draggable={false}
168172
className="absolute inset-0 h-full w-full object-cover"
169-
style={{ opacity: 0.7 }}
173+
style={{ opacity: "var(--timeline-composition-thumbnail-opacity)" }}
170174
/>
171175
</div>
172176
))}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it } from "vitest";
2+
import { deriveTimelineClipJoins } from "./TimelineClipJoins";
3+
import type { TimelineElement } from "../store/playerStore";
4+
5+
const clip = (id: string, start: number, duration: number): TimelineElement => ({
6+
id,
7+
tag: "video",
8+
start,
9+
duration,
10+
track: 0,
11+
});
12+
13+
describe("deriveTimelineClipJoins", () => {
14+
it("finds joins in time order, whatever order the clips arrive in", () => {
15+
expect(
16+
deriveTimelineClipJoins([clip("c", 3, 1), clip("a", 0, 1.5), clip("b", 1.5, 1.5)]),
17+
).toEqual([1.5, 3]);
18+
});
19+
20+
it("treats float noise as a join and a one-frame gap or an overlap as none", () => {
21+
expect(deriveTimelineClipJoins([clip("a", 0, 0.1 + 0.2), clip("b", 0.3, 1)])).toEqual([
22+
0.1 + 0.2,
23+
]);
24+
expect(deriveTimelineClipJoins([clip("a", 0, 1), clip("b", 1 + 1 / 60, 1)])).toEqual([]);
25+
expect(deriveTimelineClipJoins([clip("a", 0, 1), clip("b", 0.8, 1)])).toEqual([]);
26+
});
27+
});
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { CLIP_Y } from "./timelineLayout";
2+
import { sortedLaneClips, TRACK_GAP_EPSILON_S } from "./timelineGaps";
3+
import type { TimelineElement } from "../store/playerStore";
4+
5+
/** Times where one clip on a row ends exactly where the next begins. */
6+
export function deriveTimelineClipJoins(elements: readonly TimelineElement[]): number[] {
7+
const sorted = sortedLaneClips(elements);
8+
const joins: number[] = [];
9+
for (let index = 1; index < sorted.length; index += 1) {
10+
const previous = sorted[index - 1]!;
11+
const end = previous.start + previous.duration;
12+
if (Math.abs(sorted[index]!.start - end) < TRACK_GAP_EPSILON_S) joins.push(end);
13+
}
14+
return joins;
15+
}
16+
17+
interface TimelineClipJoinsProps {
18+
elements: readonly TimelineElement[];
19+
pixelsPerSecond: number;
20+
rowHeight: number;
21+
clipBarHeight?: number;
22+
color: string;
23+
}
24+
25+
/** A hairline in the row colour over each join, so touching clips read as two without moving either. */
26+
export function TimelineClipJoins({
27+
elements,
28+
pixelsPerSecond,
29+
rowHeight,
30+
clipBarHeight,
31+
color,
32+
}: TimelineClipJoinsProps) {
33+
const height = clipBarHeight ?? rowHeight - 2 * CLIP_Y;
34+
return deriveTimelineClipJoins(elements).map((time) => (
35+
<div
36+
key={time}
37+
data-timeline-clip-join=""
38+
aria-hidden="true"
39+
className="absolute pointer-events-none"
40+
style={{
41+
left: time * pixelsPerSecond,
42+
top: CLIP_Y,
43+
width: 1,
44+
height,
45+
transform: "translateX(-50%)",
46+
background: color,
47+
// Over an idle or hovered clip, under the diamonds (6) and a selected clip (10).
48+
zIndex: 5,
49+
}}
50+
/>
51+
));
52+
}

‎packages/studio/src/player/components/TimelineLanes.test.tsx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,38 @@ describe("TimelineLanes clip thumbnails", () => {
462462
act(() => view.root.unmount());
463463
});
464464
});
465+
466+
describe("TimelineLanes clip joins", () => {
467+
const at = (id: string, start: number, duration: number): TimelineElement => ({
468+
...element(id, TRACK_A),
469+
start,
470+
duration,
471+
});
472+
473+
it("draws one row-coloured hairline where clips touch, and leaves the clips where they are", () => {
474+
const view = renderLanes({
475+
elements: [at("clip-a", 0, 2), at("clip-b", 2, 1.5), at("clip-c", 4, 1)],
476+
});
477+
478+
const joins = view.host.querySelectorAll<HTMLElement>("[data-timeline-clip-join]");
479+
expect(joins).toHaveLength(1);
480+
expect(joins[0]?.style.left).toBe("200px");
481+
expect(joins[0]?.style.width).toBe("1px");
482+
expect(joins[0]?.style.background).toBe(defaultTimelineTheme.rowBackground);
483+
const clipB = view.host.querySelector<HTMLElement>('[data-el-id="clip-b"]');
484+
expect(clipB?.style.left).toBe("200px");
485+
expect(clipB?.style.width).toBe("150px");
486+
act(() => view.root.unmount());
487+
});
488+
489+
it("draws no join while a clip is being moved, since the moved clip is drawn elsewhere", () => {
490+
const clipA = at("clip-a", 0, 2);
491+
const view = renderLanes({
492+
elements: [clipA, at("clip-b", 2, 1.5)],
493+
draggedClip: { element: clipA, started: true } as DraggedClipState,
494+
});
495+
496+
expect(view.host.querySelectorAll("[data-timeline-clip-join]")).toHaveLength(0);
497+
act(() => view.root.unmount());
498+
});
499+
});

‎packages/studio/src/player/components/TimelineLanes.tsx‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { queryTimelineClipIndex } from "../lib/timelineClipIndex";
3232
import { getTimelineElementIdentity } from "../lib/timelineElementHelpers";
3333
import { timelineClipFocusId } from "./timelineNavigationIdentity";
3434
import { useTimelineKeyboardActor } from "./useTimelineKeyboardActor";
35-
import { deriveTimelineTransitionSeams } from "./timelineTransitionSeams";
3635
import { TimelineTransitionOverlays } from "./TimelineTransitionOverlays";
3736

3837
export function TimelineLanes({
@@ -224,9 +223,6 @@ export function TimelineLanes({
224223
// right only while it is collapsed and the row is nothing but bar.
225224
const clipBarHeight = rowExpanded ? TRACK_H - 2 * CLIP_Y : undefined;
226225
const automationElements = els.map(getPreviewElement);
227-
const transitionSeams = deriveTimelineTransitionSeams(allTransitionElements).filter(
228-
(seam) => seam.incoming.track === trackNum,
229-
);
230226
// Minted here because this is the only place that sees BOTH ends of
231227
// the disclosure: the caret in the sticky header and the diamond lanes
232228
// on the canvas. Keyed by display row, not by `trackNum`, which is a
@@ -555,7 +551,10 @@ export function TimelineLanes({
555551
})
556552
}
557553
<TimelineTransitionOverlays
558-
seams={transitionSeams}
554+
transitionElements={allTransitionElements}
555+
track={trackNum}
556+
rowElements={draggedClip?.started ? [] : automationElements}
557+
rowBackground={rowBackground}
559558
pixelsPerSecond={pps}
560559
rowHeight={rowHeight}
561560
clipBarHeight={clipBarHeight}
Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
import { CLIP_Y } from "./timelineLayout";
22
import { getTimelineElementIdentity } from "../lib/timelineElementHelpers";
3-
import type { TimelineTransitionSeam } from "./timelineTransitionSeams";
3+
import type { TimelineElement } from "../store/playerStore";
4+
import { deriveTimelineTransitionSeams } from "./timelineTransitionSeams";
45
import { TimelineTransitionBadge } from "./TimelineTransitionBadge";
6+
import { TimelineClipJoins } from "./TimelineClipJoins";
57

68
interface TimelineTransitionOverlaysProps {
7-
seams: readonly TimelineTransitionSeam[];
9+
transitionElements: readonly TimelineElement[];
10+
track: number;
11+
rowElements: readonly TimelineElement[];
12+
rowBackground: string;
813
pixelsPerSecond: number;
914
rowHeight: number;
1015
clipBarHeight?: number;
1116
}
1217

18+
/** What a row draws where its clips meet: a hairline at an exact join, a badge over a transition. */
1319
export function TimelineTransitionOverlays({
14-
seams,
20+
transitionElements,
21+
track,
22+
rowElements,
23+
rowBackground,
1524
pixelsPerSecond,
1625
rowHeight,
1726
clipBarHeight,
1827
}: TimelineTransitionOverlaysProps) {
1928
const top = CLIP_Y + (clipBarHeight ?? rowHeight - 2 * CLIP_Y) / 2;
20-
return seams.map((seam) => (
21-
<TimelineTransitionBadge
22-
key={`${getTimelineElementIdentity(seam.outgoing)}-${getTimelineElementIdentity(seam.incoming)}`}
23-
centerPx={seam.centerTime * pixelsPerSecond}
24-
top={top}
25-
widthPx={Math.min(Math.max(seam.duration * pixelsPerSecond, 24), 32)}
26-
outgoingSrc={seam.outgoing.src}
27-
incomingSrc={seam.incoming.src}
28-
/>
29-
));
29+
const seams = deriveTimelineTransitionSeams(transitionElements).filter(
30+
(seam) => seam.incoming.track === track,
31+
);
32+
return (
33+
<>
34+
<TimelineClipJoins
35+
elements={rowElements}
36+
pixelsPerSecond={pixelsPerSecond}
37+
rowHeight={rowHeight}
38+
clipBarHeight={clipBarHeight}
39+
color={rowBackground}
40+
/>
41+
{seams.map((seam) => (
42+
<TimelineTransitionBadge
43+
key={`${getTimelineElementIdentity(seam.outgoing)}-${getTimelineElementIdentity(seam.incoming)}`}
44+
centerPx={seam.centerTime * pixelsPerSecond}
45+
top={top}
46+
widthPx={Math.min(Math.max(seam.duration * pixelsPerSecond, 24), 32)}
47+
outgoingSrc={seam.outgoing.src}
48+
incomingSrc={seam.incoming.src}
49+
/>
50+
))}
51+
</>
52+
);
3053
}

‎packages/studio/src/player/components/timelineGaps.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const round3 = (v: number) => Math.round(v * 1000) / 1000;
2525
const endOf = (e: TimelineElement) => e.start + e.duration;
2626

2727
/** Lane clips sorted by start (key as a deterministic tie-break). */
28-
function sortedLaneClips(elements: readonly TimelineElement[]): TimelineElement[] {
28+
export function sortedLaneClips(elements: readonly TimelineElement[]): TimelineElement[] {
2929
return [...elements].sort((a, b) => a.start - b.start || keyOf(a).localeCompare(keyOf(b)));
3030
}
3131

‎packages/studio/src/styles/theme.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
--timeline-clip-chip-audio-bg: rgba(25, 16, 38, 0.7);
8181
--timeline-clip-chip-text: #ffffff;
8282
--timeline-shortcut-bg: rgba(17, 23, 35, 0.84);
83+
/* Composition and text clips draw their frame as it is, like video filmstrips; a host may dim them. */
84+
--timeline-composition-thumbnail-opacity: 1;
85+
--timeline-composition-thumbnail-blend: normal;
8386
--timeline-thumbnail-shimmer: linear-gradient(
8487
90deg,
8588
rgba(255, 255, 255, 0.02) 0%,

0 commit comments

Comments
 (0)