Skip to content

Commit 25a1314

Browse files
committed
fix(studio): address timeline PR review — drop dead code, add fadeIn keyframes, compSrc test
1 parent b6862ed commit 25a1314

5 files changed

Lines changed: 80 additions & 30 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { describe, expect, it } from "vitest";
2+
import { normalizeCompositionSrc } from "./useRenderClipContent";
3+
4+
describe("normalizeCompositionSrc", () => {
5+
const origin = "http://localhost:5190";
6+
const pid = "my-project";
7+
8+
it("strips absolute preview URL to relative path", () => {
9+
const result = normalizeCompositionSrc(
10+
"http://localhost:5190/api/projects/my-project/preview/compositions/intro.html",
11+
pid,
12+
origin,
13+
);
14+
expect(result).toBe("compositions/intro.html");
15+
});
16+
17+
it("preserves already-relative paths", () => {
18+
const result = normalizeCompositionSrc("compositions/intro.html", pid, origin);
19+
expect(result).toBe("compositions/intro.html");
20+
});
21+
22+
it("preserves absolute URLs from different origins", () => {
23+
const result = normalizeCompositionSrc(
24+
"https://cdn.example.com/compositions/intro.html",
25+
pid,
26+
origin,
27+
);
28+
expect(result).toBe("https://cdn.example.com/compositions/intro.html");
29+
});
30+
31+
it("preserves absolute URLs for different projects", () => {
32+
const result = normalizeCompositionSrc(
33+
"http://localhost:5190/api/projects/other-project/preview/compositions/intro.html",
34+
pid,
35+
origin,
36+
);
37+
expect(result).toBe(
38+
"http://localhost:5190/api/projects/other-project/preview/compositions/intro.html",
39+
);
40+
});
41+
42+
it("handles nested composition paths", () => {
43+
const result = normalizeCompositionSrc(
44+
"http://localhost:5190/api/projects/my-project/preview/compositions/scenes/hero.html",
45+
pid,
46+
origin,
47+
);
48+
expect(result).toBe("compositions/scenes/hero.html");
49+
});
50+
});

packages/studio/src/hooks/useRenderClipContent.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@ import type { TimelineElement } from "../player";
55
import { AudioWaveform } from "../player/components/AudioWaveform";
66
import { getTimelineElementLabel } from "../utils/studioHelpers";
77

8+
export function normalizeCompositionSrc(
9+
compSrc: string,
10+
projectId: string,
11+
origin: string,
12+
): string {
13+
try {
14+
const parsed = new URL(compSrc, origin);
15+
const previewPrefix = `/api/projects/${projectId}/preview/`;
16+
if (parsed.pathname.startsWith(previewPrefix)) {
17+
return parsed.pathname.slice(previewPrefix.length);
18+
}
19+
} catch {
20+
// already relative
21+
}
22+
return compSrc;
23+
}
24+
825
interface UseRenderClipContentOptions {
926
projectIdRef: { current: string | null };
1027
compIdToSrc: Map<string, string>;
@@ -25,15 +42,7 @@ export function useRenderClipContent({
2542

2643
let compSrc = el.compositionSrc;
2744
if (compSrc) {
28-
try {
29-
const parsed = new URL(compSrc, window.location.origin);
30-
const previewPrefix = `/api/projects/${pid}/preview/`;
31-
if (parsed.pathname.startsWith(previewPrefix)) {
32-
compSrc = parsed.pathname.slice(previewPrefix.length);
33-
}
34-
} catch {
35-
// already relative
36-
}
45+
compSrc = normalizeCompositionSrc(compSrc, pid, window.location.origin);
3746
}
3847
if (compSrc && compIdToSrc.size > 0) {
3948
const resolved =
@@ -50,7 +59,7 @@ export function useRenderClipContent({
5059
previewUrl: `/api/projects/${pid}/preview/comp/${compSrc}`,
5160
label: getTimelineElementLabel(el),
5261
labelColor: style.label,
53-
accentColor: style.clip,
62+
5463
seekTime: 0,
5564
duration: el.duration,
5665
});
@@ -63,7 +72,7 @@ export function useRenderClipContent({
6372
previewUrl: activePreviewUrl,
6473
label: getTimelineElementLabel(el),
6574
labelColor: style.label,
66-
accentColor: style.clip,
75+
6776
selector: el.selector,
6877
selectorIndex: el.selectorIndex,
6978
seekTime: el.start,
@@ -119,7 +128,7 @@ export function useRenderClipContent({
119128
previewUrl: `/api/projects/${pid}/preview`,
120129
label: getTimelineElementLabel(el),
121130
labelColor: style.label,
122-
accentColor: style.clip,
131+
123132
selector: el.selector,
124133
selectorIndex: el.selectorIndex,
125134
seekTime: el.start,

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ interface CompositionThumbnailProps {
55
previewUrl: string;
66
label: string;
77
labelColor: string;
8-
accentColor?: string;
98
selector?: string;
109
selectorIndex?: number;
1110
seekTime?: number;
@@ -52,7 +51,6 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
5251
previewUrl,
5352
label,
5453
labelColor,
55-
accentColor: _accentColor = "#6B7280",
5654
selector,
5755
selectorIndex,
5856
seekTime = 2,
@@ -112,7 +110,7 @@ export const CompositionThumbnail = memo(function CompositionThumbnail({
112110
{loaded && (
113111
<div
114112
className="absolute inset-0 flex"
115-
style={{ animation: "fadeIn 200ms ease-out", mixBlendMode: "lighten" }}
113+
style={{ animation: "hf-thumb-fade 200ms ease-out", mixBlendMode: "lighten" }}
116114
>
117115
{Array.from({ length: frameCount }).map((_, i) => (
118116
<div

packages/studio/src/player/components/timelineTheme.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ export interface TimelineTheme {
3535
clipRadius: string;
3636
}
3737

38-
const UNIFIED_STYLE: TimelineTrackStyle = {
38+
const TRACK_STYLE: TimelineTrackStyle = {
3939
clip: "#1c2028",
4040
accent: "#3CE6AC",
4141
label: "#dde1e8",
4242
iconBackground: "rgba(255,255,255,0.06)",
4343
};
4444

45-
function createTrackStyle(_tag: string): TimelineTrackStyle {
46-
return UNIFIED_STYLE;
47-
}
48-
4945
export const defaultTimelineTheme: TimelineTheme = {
5046
shellBackground: "#0A0A0B",
5147
shellBorder: "rgba(255,255,255,0.05)",
@@ -74,16 +70,8 @@ export const defaultTimelineTheme: TimelineTheme = {
7470
clipRadius: "6px",
7571
};
7672

77-
export function getTimelineTrackStyle(tag: string): TimelineTrackStyle {
78-
const normalized = tag.toLowerCase();
79-
if (
80-
normalized.startsWith("h") &&
81-
normalized.length === 2 &&
82-
"123456".includes(normalized[1] ?? "")
83-
) {
84-
return createTrackStyle("h1");
85-
}
86-
return createTrackStyle(normalized);
73+
export function getTimelineTrackStyle(_tag: string): TimelineTrackStyle {
74+
return TRACK_STYLE;
8775
}
8876

8977
export function getClipHandleOpacity({

packages/studio/src/styles/studio.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ body {
152152
background: rgba(255, 255, 255, 0.1);
153153
}
154154

155+
@keyframes hf-thumb-fade {
156+
from { opacity: 0; }
157+
to { opacity: 1; }
158+
}
159+
155160
.hf-loader-progress__fill {
156161
width: 100%;
157162
height: 100%;

0 commit comments

Comments
 (0)