Skip to content

Commit b9fe13a

Browse files
feat(studio): export AudioWaveform, ImageThumbnail, useRenderClipContent (#4301)
@hyperframes/studio's public index doesn't export the clip-content thumbnail primitives, forcing a deep import. Desktop's Canva timeline lane needs to draw audio waveforms and image thumbnails from a host app without reaching into the package's internals. Adds a test that mounts each export through the package name the way a host app would (not a relative import), so a future removal or accidental un-export fails a test instead of a downstream deep-import workaround.
1 parent b73df35 commit b9fe13a

5 files changed

Lines changed: 67 additions & 3 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// @vitest-environment happy-dom
2+
// Imports the clip-content thumbnail primitives the way a host app does: by package name.
3+
// Desktop's timeline lane draws audio waveforms and image thumbnails without a deep import.
4+
import { act } from "react";
5+
import { afterEach, describe, expect, it, vi } from "vitest";
6+
import { installReactActEnvironment, mountReactHarness } from "./hooks/domSelectionTestHarness";
7+
8+
const { leaseSpy } = vi.hoisted(() => ({
9+
leaseSpy: vi.fn((_request: unknown) => ({ status: "loading" as const })),
10+
}));
11+
12+
vi.mock("./hooks/useThumbnailLease", () => ({
13+
useThumbnailLease: leaseSpy,
14+
}));
15+
16+
import { AudioWaveform, ImageThumbnail, useRenderClipContent } from "@hyperframes/studio";
17+
18+
installReactActEnvironment();
19+
20+
afterEach(() => {
21+
leaseSpy.mockClear();
22+
document.body.innerHTML = "";
23+
});
24+
25+
describe("clip content package exports", () => {
26+
it("mounts AudioWaveform and leases waveform decoding", async () => {
27+
const root = mountReactHarness(
28+
<AudioWaveform
29+
audioUrl="/media/voice.wav"
30+
label=""
31+
labelColor="#fff"
32+
projectId="project-a"
33+
sessionEpoch={9}
34+
priority="interaction"
35+
/>,
36+
);
37+
38+
expect(leaseSpy).toHaveBeenCalledWith(expect.objectContaining({ kind: "waveform" }));
39+
await act(async () => root.unmount());
40+
});
41+
42+
it("mounts ImageThumbnail and leases the still frame", async () => {
43+
const root = mountReactHarness(
44+
<ImageThumbnail imageSrc="/media/frame.png" label="" labelColor="#fff" />,
45+
);
46+
47+
expect(leaseSpy).toHaveBeenCalledWith(expect.objectContaining({ kind: "image" }));
48+
await act(async () => root.unmount());
49+
});
50+
51+
it("exposes useRenderClipContent as a hook a host can call", () => {
52+
expect(typeof useRenderClipContent).toBe("function");
53+
});
54+
});

‎packages/studio/src/hooks/useRenderClipContent.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function renderAudioClip(
9797
});
9898
}
9999

100-
interface UseRenderClipContentOptions {
100+
export interface UseRenderClipContentOptions {
101101
projectIdRef: { current: string | null };
102102
compIdToSrc: Map<string, string>;
103103
activePreviewUrl: string | null;

‎packages/studio/src/index.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ export {
7777
export { TimelineProvider, useTimelineContext } from "./player/components/TimelineProvider";
7878
export type { TimelineTheme } from "./player/components/timelineTheme";
7979

80+
// Clip content thumbnails: used by a host rendering its own timeline lane.
81+
export { AudioWaveform } from "./player/components/AudioWaveform";
82+
export type { AudioWaveformProps } from "./player/components/AudioWaveform";
83+
export { ImageThumbnail } from "./player/components/ImageThumbnail";
84+
export type { ImageThumbnailProps } from "./player/components/ImageThumbnail";
85+
export { useRenderClipContent } from "./hooks/useRenderClipContent";
86+
export type { UseRenderClipContentOptions } from "./hooks/useRenderClipContent";
87+
export type { ThumbnailPriority } from "./player/lib/thumbnailScheduler";
88+
export type { TimelineClipRenderContext } from "./player/components/TimelineTypes";
89+
8090
// Host overlays: draw over the preview in composition coordinates (see EditorShellProps.gestureOverlay)
8191
export { usePreviewCompositionRect } from "./components/editor/usePreviewCompositionRect";
8292
export type { PreviewCompositionRect } from "./components/editor/usePreviewCompositionRect";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useThumbnailLease } from "../../hooks/useThumbnailLease";
44
import { createThumbnailKey, type ThumbnailPriority } from "../lib/thumbnailScheduler";
55
import { decimatePeaks, loudnessToOpacity } from "./audioWaveformPeaks";
66

7-
interface AudioWaveformProps {
7+
export interface AudioWaveformProps {
88
audioUrl: string;
99
waveformUrl?: string;
1010
label: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { createThumbnailKey, type ThumbnailPriority } from "../lib/thumbnailSche
55
import { TIMELINE_VIEWPORT_BUDGETS } from "../lib/timelineViewportBudgets";
66
import { computeThumbnailStrip, probeImageAspect } from "./thumbnailUtils";
77

8-
interface ImageThumbnailProps {
8+
export interface ImageThumbnailProps {
99
imageSrc: string;
1010
label: string;
1111
labelColor: string;

0 commit comments

Comments
 (0)