Skip to content

Open source CapCut alternative.

TypeScript

feat(site): audio assets render as the timeline emerald waveform pill everywhere

David Leabc86e1528ee
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsx
index 8a95b649..68864e9f 100644
--- a/site/src/cut/components/AiPanel.tsx
+++ b/site/src/cut/components/AiPanel.tsx
@@ -636,7 +636,14 @@ function MessageAssetCard({ asset }: { asset: AssetRef }) {
const clickTimer = useRef<number | undefined>(undefined);
useEffect(() => () => window.clearTimeout(clickTimer.current), []);
return (
- <div className="ai-msg-asset group relative w-16">
+ <div
+ className={cn(
+ "ai-msg-asset group relative",
+ // Audio gets the wide timeline-pill treatment; the row still wraps
+ // inside the message's max width.
+ asset.kind === "audio" ? "w-44 max-w-full" : "w-16"
+ )}
+ >
<button
className="flex w-full flex-col gap-1 text-left"
title={`${asset.name} — click to show · drag to the timeline`}
@@ -657,7 +664,13 @@ function MessageAssetCard({ asset }: { asset: AssetRef }) {
useLightbox.getState().open(lightboxItemFromRef(asset));
}}
>
- <RefThumb item={asset} className="size-16 transition-colors group-hover:border-input" />
+ <RefThumb
+ item={asset}
+ className={cn(
+ asset.kind === "audio" ? "h-12 w-full" : "size-16",
+ "transition-colors group-hover:border-input"
+ )}
+ />
<span className="w-full truncate text-[10px] text-muted-foreground">{asset.name}</span>
</button>
<DropdownMenu>
diff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsx
index 5fecccfe..f4a9d5c6 100644
--- a/site/src/cut/components/AssetRefs.tsx
+++ b/site/src/cut/components/AssetRefs.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useMemo, useRef, useState } from "react";
-import { Check, Copy, FileText, Music, X } from "lucide-react";
+import { Check, Copy, FileText, X } from "lucide-react";
import {
highlightMentions,
mentionToken,
@@ -11,6 +11,8 @@ import {
import { useRefFor, useRefCandidates } from "@/cut/lib/assetRef";
import { revealRef } from "@/cut/lib/refReveal";
import { formatTime } from "@/cut/lib/time";
+import { useEditor } from "@/cut/lib/store";
+import { AudioPillSurface } from "@/cut/components/AudioPanel";
import { cn } from "@/lib/utils";
// Shared UI for asset references: the preview thumbnail, attachment chips,
@@ -19,9 +21,17 @@ import { cn } from "@/lib/utils";
// Every surface that takes references (AI chat, image/video creators)
// composes these.
-/** Square media preview for a ref: video poster frame, image, or a glyph for
- * audio and text files. */
+/** Media preview for a ref: video poster frame, image, a glyph for text
+ * files, or the timeline-style emerald waveform pill for audio. Audio reads
+ * best wide — give it a wide box where the layout has room. */
export function RefThumb({ item, className }: { item: AssetRef; className?: string }) {
+ // Project audio has real waveform peaks in the store; the pill draws a
+ // stand-in for everything else.
+ const peaks = useEditor((s) =>
+ item.kind === "audio" && item.scope === "project"
+ ? s.assets.find((a) => a.id === item.id)?.peaks
+ : undefined
+ );
return (
<div
className={cn(
@@ -45,9 +55,7 @@ export function RefThumb({ item, className }: { item: AssetRef; className?: stri
<FileText className="size-4.5" />
</div>
) : (
- <div className="grid size-full place-items-center bg-gradient-to-br from-emerald-100 to-emerald-50 text-emerald-600">
- <Music className="size-4.5" />
- </div>
+ <AudioPillSurface peaks={peaks} className="size-full rounded-none" />
)}
{item.duration !== undefined && item.kind !== "image" && (
<span className="absolute right-1 bottom-1 rounded-[5px] bg-black/65 px-1 py-px font-mono text-[8.5px] text-white tabular-nums">
@@ -100,7 +108,10 @@ function RefPeek({ item, side = "top" }: { item: AssetRef; side?: "top" | "botto
{item.kind === "video" ? (
<PeekVideo item={item} />
) : (
- <RefThumb item={item} className="aspect-square w-full" />
+ <RefThumb
+ item={item}
+ className={item.kind === "audio" ? "h-14 w-full" : "aspect-square w-full"}
+ />
)}
</div>
);
@@ -234,7 +245,12 @@ function RefChip({
className="block text-left"
onClick={() => revealRef(item)}
>
- <RefThumb item={item} className={thumbClassName} />
+ {/* Audio stretches to the timeline-pill shape; the chip row wraps, so
+ the wide chip stays within the composer. */}
+ <RefThumb
+ item={item}
+ className={item.kind === "audio" ? "h-12 w-44 max-w-full" : thumbClassName}
+ />
</button>
{item.handle && <RefHandleBadge handle={item.handle} className="absolute bottom-1 left-1" />}
{peek && <RefPeek item={item} side={peekSide} />}
diff --git a/site/src/cut/components/AudioPanel.tsx b/site/src/cut/components/AudioPanel.tsx
index d37f3917..e172766e 100644
--- a/site/src/cut/components/AudioPanel.tsx
+++ b/site/src/cut/components/AudioPanel.tsx
@@ -1,6 +1,13 @@
"use client";
-import { type DragEventHandler, type ReactNode, useEffect, useRef, useState } from "react";
+import {
+ type DragEventHandler,
+ type HTMLAttributes,
+ type ReactNode,
+ useEffect,
+ useRef,
+ useState,
+} from "react";
import {
AudioLines,
Check,
@@ -44,7 +51,7 @@ import { DUCK_DEFAULT } from "@/cut/lib/voiceover";
import { useSpeakerVoice, useSpeechLanguage, VoicePicker } from "@/cut/components/VoicePicker";
import { GeneratedAssetMenu } from "@/cut/components/GeneratedAssetMenu";
import { cn } from "@/lib/utils";
-import { cardIconButton } from "@/cut/components/iconButton";
+import { scrimIconButton } from "@/cut/components/iconButton";
/** Starting points for the direction prompt — picking one fills the input so
* it can be tweaked before generating. */
@@ -307,6 +314,36 @@ export function PeakStrip({ peaks, className }: { peaks: number[]; className?: s
);
}
+/** Stand-in peaks while an asset's real ones haven't landed — the same gentle
+ * wave the timeline drag ghost draws, so the pill still reads as audio. */
+const STAND_IN_PEAKS = Array.from({ length: 48 }, (_, i) => 0.32 + 0.26 * Math.abs(Math.sin(i / 2)));
+
+/** The emerald audio surface, mirroring a timeline audio clip: gradient pill
+ * with a white waveform. Panel rows, chat cards, and attachment tiles draw on
+ * it so audio looks like the timeline everywhere it appears. */
+export function AudioPillSurface({
+ peaks,
+ className,
+ children,
+ ...rest
+}: { peaks?: number[] } & HTMLAttributes<HTMLDivElement>) {
+ return (
+ <div
+ className={cn(
+ "relative overflow-hidden rounded-[7px] bg-gradient-to-b from-emerald-500 to-emerald-600 shadow-[inset_0_0_0_1px_rgba(0,0,0,0.1)]",
+ className
+ )}
+ {...rest}
+ >
+ <PeakStrip
+ peaks={peaks?.length ? peaks : STAND_IN_PEAKS}
+ className="absolute inset-x-0 inset-y-1 mt-0 h-[calc(100%-8px)] text-white/85"
+ />
+ {children}
+ </div>
+ );
+}
+
/** Off-screen drag image that mirrors an audio clip on the timeline — an
* emerald pill with the name and a white waveform — so the drag reads as the
* thing that will land, not the panel row. Lives just long enough for the
@@ -351,8 +388,9 @@ function buildAudioDragGhost(name: string, width: number, peaks?: number[]): HTM
return el;
}
-/** One audio asset as a playable row — the shared audio preview (panels and
- * the chat's audio cards): play button, name, duration, waveform, and a
+/** One audio asset as a playable pill — the shared audio preview (panels and
+ * the chat's audio cards), styled like its timeline clip: emerald gradient,
+ * white waveform, name overlaid, plus a play button, duration badge, and a
* hover-revealed menu + add button. */
export function AudioRow({
name,
@@ -378,8 +416,9 @@ export function AudioRow({
onDragStart?: DragEventHandler<HTMLDivElement>;
}) {
return (
- <div
- className="audio-row group relative flex items-center gap-2 rounded-lg border border-border p-1.5 pr-2 transition-colors hover:border-input hover:bg-muted/50"
+ <AudioPillSurface
+ peaks={peaks}
+ className="audio-row group h-10 shrink-0 cursor-grab"
draggable={!!onDragStart}
onDragStart={
onDragStart &&
@@ -399,42 +438,37 @@ export function AudioRow({
onDragEnd={onDragStart ? clearAssetDrag : undefined}
title={onDragStart ? "Drag onto the timeline, or click + to add" : undefined}
>
+ <span className="pointer-events-none absolute top-[3px] right-14 left-8 truncate text-[9.5px] font-medium text-white/90 [text-shadow:0_1px_2px_rgba(0,0,0,0.35)]">
+ {name}
+ </span>
<button
type="button"
className={cn(
- "grid size-8 shrink-0 place-items-center rounded-full text-foreground transition-colors",
- playing ? "bg-primary text-primary-foreground" : "bg-muted hover:bg-muted-foreground/20"
+ "absolute top-1/2 left-1.5 grid size-6 shrink-0 -translate-y-1/2 place-items-center rounded-full transition-colors",
+ playing ? "bg-white text-emerald-600" : "bg-black/30 text-white hover:bg-black/50"
)}
title={playing ? "Pause" : "Play"}
aria-label={playing ? "Pause" : "Play"}
onClick={() => onTogglePlay(url)}
>
- {playing ? <Pause className="size-3.5" /> : <Play className="size-3.5" />}
+ {playing ? <Pause className="size-3" /> : <Play className="size-3" />}
</button>
- {/* The name and waveform run the full width; the trailing controls scrim
- over the right edge only on hover, so nothing is reserved for them. */}
- <div className="min-w-0 flex-1">
- <div className="flex items-baseline justify-between gap-2">
- <span className="truncate text-[11.5px] font-medium">{name}</span>
- <span className="shrink-0 font-mono text-[10px] text-muted-foreground tabular-nums">
- {formatTime(duration)}
- </span>
- </div>
- {peaks && peaks.length > 0 && <PeakStrip peaks={peaks} />}
- </div>
- <div className="absolute inset-y-0 right-0 flex items-center gap-1 rounded-r-lg from-card via-card bg-gradient-to-l to-transparent pr-2 pl-8 opacity-0 transition-opacity group-hover:opacity-100 has-data-popup-open:opacity-100">
+ <span className="pointer-events-none absolute right-1.5 bottom-1 rounded-[5px] bg-black/40 px-1 py-px font-mono text-[9px] text-white tabular-nums">
+ {formatTime(duration)}
+ </span>
+ <div className="absolute top-1 right-1 flex items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100 has-data-popup-open:opacity-100">
{menu}
<button
type="button"
title="Add at the playhead"
aria-label="Add at the playhead"
- className={cardIconButton}
+ className={scrimIconButton}
onClick={onAdd}
>
- <Plus className="size-3.5" />
+ <Plus className="size-3" />
</button>
</div>
- </div>
+ </AudioPillSurface>
);
}
@@ -474,7 +508,7 @@ function ProjectAudio({
<GeneratedAssetMenu
asset={a}
projectId={projectId}
- triggerClassName={cardIconButton}
+ triggerClassName={scrimIconButton}
after={
<DropdownMenuItem
variant="destructive"
diff --git a/site/src/cut/components/ChatAssets.tsx b/site/src/cut/components/ChatAssets.tsx
index 5db2b2f4..b17c904d 100644
--- a/site/src/cut/components/ChatAssets.tsx
+++ b/site/src/cut/components/ChatAssets.tsx
@@ -23,7 +23,7 @@ import { cn } from "@/lib/utils";
import { AudioRow } from "./AudioPanel";
import { DocText, useDocText } from "./DocText";
import { GeneratedAssetMenu } from "./GeneratedAssetMenu";
-import { cardIconButton } from "./iconButton";
+import { scrimIconButton } from "./iconButton";
// Assets rendered inside chat messages. Anything the assistant makes previews
// here as a media-first card and stays in the chat until the user moves it:
@@ -174,8 +174,7 @@ function ChatCardMenu({ asset, triggerClassName }: { asset: MediaAsset; triggerC
);
}
-const scrimButton =
- "grid size-5 place-items-center rounded-full bg-black/45 text-white hover:bg-black/65";
+const scrimButton = scrimIconButton;
/** Image / video tile: the preview fills the card at the media's own aspect,
* sized so portrait and landscape both sit comfortably in the chat column. */
@@ -248,10 +247,7 @@ function AudioCard({ item, asset }: ChatCardProps) {
return () => usePreviewAudio.getState().stop(url);
}, [ref.url]);
return (
- <div
- className="ai-chat-asset w-full max-w-[280px] bg-card"
- onDoubleClick={() => expandRef(item, asset)}
- >
+ <div className="ai-chat-asset w-full" onDoubleClick={() => expandRef(item, asset)}>
<AudioRow
name={ref.name}
duration={ref.duration ?? 0}
@@ -260,7 +256,7 @@ function AudioCard({ item, asset }: ChatCardProps) {
playing={playing}
onTogglePlay={(url) => usePreviewAudio.getState().toggle(url)}
onAdd={() => asset && useEditor.getState().addAudioFromAsset(asset.id)}
- menu={asset && <ChatCardMenu asset={asset} triggerClassName={cardIconButton} />}
+ menu={asset && <ChatCardMenu asset={asset} triggerClassName={scrimIconButton} />}
onDragStart={(e) => {
if (asset) setAssetDragData(e, asset.id);
else setRefDragData(e, item);
diff --git a/site/src/cut/components/iconButton.ts b/site/src/cut/components/iconButton.ts
index 6d39d7b3..d342ea59 100644
--- a/site/src/cut/components/iconButton.ts
+++ b/site/src/cut/components/iconButton.ts
@@ -4,3 +4,8 @@
* use the dark `bg-black/45 text-white` scrim pill instead. */
export const cardIconButton =
"grid size-6 shrink-0 place-items-center rounded-full bg-muted text-foreground transition-all hover:bg-muted-foreground/20";
+
+/** The dark scrim pill for controls floating over media — image/video tiles
+ * and the emerald audio pill. */
+export const scrimIconButton =
+ "grid size-5 shrink-0 place-items-center rounded-full bg-black/45 text-white transition-colors hover:bg-black/65";