Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): a video's sound reads on its clip like an audio row (#5015)
Miguel Ángeled5c1000b1f1
diff --git a/packages/studio/src/player/components/AudibleVideoClipContent.test.tsx b/packages/studio/src/player/components/AudibleVideoClipContent.test.tsxnew file mode 100644index 0000000000..2d48f4e421--- /dev/null+++ b/packages/studio/src/player/components/AudibleVideoClipContent.test.tsx@@ -0,0 +1,67 @@+// @vitest-environment happy-dom+import { createRequire } from "node:module";+import { readFileSync } from "node:fs";+import path from "node:path";+import { act, type ReactNode } from "react";+import { compile } from "tailwindcss";+import { describe, expect, it } from "vitest";+import { createHappyDomRootHarness } from "./testRootHarness";+import { AudibleVideoClipContent } from "./AudibleVideoClipContent";++const harness = createHappyDomRootHarness();+const STYLES_DIR = path.resolve(__dirname, "../../styles");+const TAILWIND_DIR = path.dirname(+ createRequire(import.meta.url).resolve("tailwindcss/package.json"),+);++async function studioCss() {+ const load = async (id: string, base: string) => {+ const file =+ id === "tailwindcss" ? path.join(TAILWIND_DIR, "index.css") : path.resolve(base, id);+ return { path: file, base: path.dirname(file), content: readFileSync(file, "utf8") };+ };+ const compiled = await compile(readFileSync(path.join(STYLES_DIR, "studio.css"), "utf8"), {+ base: STYLES_DIR,+ loadStylesheet: load,+ });+ return compiled.build([]);+}++async function renderStrip(wave: ReactNode) {+ const host = document.createElement("div");+ document.body.appendChild(host);+ await act(async () => {+ harness+ .mount(host)+ .render(<AudibleVideoClipContent thumbnail={<span>frames</span>} waveform={wave} />);+ });+ return host;+}++describe("AudibleVideoClipContent", () => {+ it("draws the sound on the audio clip's own surface, under half the clip", async () => {+ const host = await renderStrip(<span>wave</span>);+ const strip = host.querySelector<HTMLElement>('[data-testid="audible-video-wave"]');+ expect(strip?.textContent).toBe("wave");+ expect(strip?.style.backgroundColor).toBe("var(--timeline-clip-audio-bg)");+ expect(strip?.style.height).toBe("50%");+ expect(strip?.previousElementSibling?.getAttribute("style")).toContain("bottom: 50%");+ });++ it("keeps only the peak mark in the strip, above the waveform canvas layer", async () => {+ const style = document.createElement("style");+ style.textContent = await studioCss();+ document.head.appendChild(style);+ const host = await renderStrip(+ <span data-peak-badge>+ ▲<span data-peak-text> peaks +0.7 dBFS</span>+ </span>,+ );+ const badge = host.querySelector<HTMLElement>("[data-peak-badge]")!;+ const text = host.querySelector<HTMLElement>("[data-peak-text]")!;+ expect(getComputedStyle(text).display).toBe("none");+ // The waveform canvas sits in a z-index 10 layer (AudioWaveform).+ expect(Number(getComputedStyle(badge).zIndex)).toBeGreaterThan(10);+ style.remove();+ });+});diff --git a/packages/studio/src/player/components/AudibleVideoClipContent.tsx b/packages/studio/src/player/components/AudibleVideoClipContent.tsxindex cbfcc59aa0..1381f82919 100644--- a/packages/studio/src/player/components/AudibleVideoClipContent.tsx+++ b/packages/studio/src/player/components/AudibleVideoClipContent.tsx@@ -1,7 +1,8 @@import type { ReactNode } from "react";-/** Share of the clip height the sound strip takes under a video's thumbnails. */-const AUDIBLE_VIDEO_WAVE_SHARE = 0.38;+/** Share of the clip height the sound strip takes under a video's thumbnails: tall enough for the bars to read. */+const AUDIBLE_VIDEO_WAVE_SHARE = 0.5;+const AUDIO_CLIP_SURFACE = "var(--timeline-clip-audio-bg)";/** A video that carries sound: thumbnails on top, its waveform strip along the bottom. */export function AudibleVideoClipContent({@@ -18,9 +19,9 @@ export function AudibleVideoClipContent({{thumbnail}</div><div- className="absolute inset-x-0 bottom-0 bg-black/30"+ className="audible-video-wave absolute inset-x-0 bottom-0"data-testid="audible-video-wave"- style={{ height: waveHeight }}+ style={{ height: waveHeight, backgroundColor: AUDIO_CLIP_SURFACE }}>{waveform}</div>diff --git a/packages/studio/src/player/components/ClipPeakMarks.tsx b/packages/studio/src/player/components/ClipPeakMarks.tsxindex 064a436866..73d5bc6c80 100644--- a/packages/studio/src/player/components/ClipPeakMarks.tsx+++ b/packages/studio/src/player/components/ClipPeakMarks.tsx@@ -49,8 +49,11 @@ export function ClipPeakMarks({}}/>))}- <span className="absolute top-0 right-1 font-mono text-[9px] leading-none text-red-400">- ▲ peaks {dbText(peakDbfs)}+ <span+ className="absolute top-0 right-1 font-mono text-[9px] leading-none text-red-400"+ data-peak-badge+ >+ ▲<span data-peak-text> peaks {dbText(peakDbfs)}</span></span></div>)}diff --git a/packages/studio/src/styles/components.css b/packages/studio/src/styles/components.cssindex 3b997b5167..fe27c4db22 100644--- a/packages/studio/src/styles/components.css+++ b/packages/studio/src/styles/components.css@@ -308,6 +308,22 @@}}+/* A video's sound strip is too short for the peak readout: only the mark stays, on a chip clear of the clip's+ rounded corner and above the waveform canvas layer (z 10), below the fade handles (z 30). */+.audible-video-wave [data-peak-text] {+ display: none;+}++.audible-video-wave [data-peak-badge] {+ top: 50%;+ right: var(--timeline-clip-radius);+ translate: 0 -50%;+ padding: 1px 3px;+ border-radius: 3px;+ background: var(--timeline-clip-chip-audio-bg);+ z-index: 20;+}+.timeline-clip.is-audio.is-hovered {background-color: var(--timeline-clip-audio-bg-hover);}