Open source CapCut alternative.
TypeScript
feat(site): the viewer opens media at its own shape
David Le5f8e10462d79
diff --git a/site/src/cut/components/AssetRefs.tsx b/site/src/cut/components/AssetRefs.tsxindex bb90ac7f..35ea561d 100644--- a/site/src/cut/components/AssetRefs.tsx+++ b/site/src/cut/components/AssetRefs.tsx@@ -802,15 +802,23 @@ export function CopyNameLabel({name,className,dark,+ mention = true,}: {name: string;className?: string;/** On a dark/filled surface (audio cards): white badge and copied text. */dark?: boolean;+ /** Whether a prompt is within reach. A mention token is only worth copying+ * where it can be pasted, so surfaces outside the editor — the library and+ * projects homes — show the name and nothing more. */+ mention?: boolean;}) {const [copied, copy] = useCopied();const ref = useRefFor(name);const token = ref ? refToken(ref) : mentionToken(name);+ if (!mention) {+ return <span className={cn("block min-w-0 truncate text-left", className)}>{name}</span>;+ }return (<buttontype="button"diff --git a/site/src/cut/components/Lightbox.tsx b/site/src/cut/components/Lightbox.tsxindex 4eb47ae7..4e4cdcb5 100644--- a/site/src/cut/components/Lightbox.tsx+++ b/site/src/cut/components/Lightbox.tsx@@ -14,13 +14,12 @@ import { PeakStrip } from "./AudioPanel";// The asset lightbox: the big version of a stock, generated, or chat asset// floating straight on the backdrop — media on top, name and prompt below,-// plus a button to drop it onto the timeline. Mounted once in the editor.+// plus a button to drop it onto the timeline. Mounted once in the editor and+// once on the library page, which opens it bare — media alone.// Video and images size the dialog from a known aspect before the media// loads; audio gets a waveform player and text files render formatted// (markdown, CSV table, plain text).-const ASPECT_RATIO: Record<string, number> = { "16:9": 16 / 9, "9:16": 9 / 16, "1:1": 1 };-export function Lightbox() {const item = useLightbox((s) => s.item);const [adding, setAdding] = useState(false);@@ -75,6 +74,7 @@ export function Lightbox() {// Text never rides the timeline; audio needs a project or library home to// land from.const canAdd =+ !item.bare &&item.kind !== "text" &&(item.kind !== "audio" || item.assetId !== null || item.libraryId !== undefined);@@ -82,7 +82,7 @@ export function Lightbox() {// stays within 68vh tall and 860px/92vw wide — and the media box carries the// same ratio, so nothing shifts when the file loads. Audio and text use// fixed reading widths instead.- const ratio = item.aspect ? ASPECT_RATIO[item.aspect] : undefined;+ const ratio = item.ratio;const width =item.kind === "audio"? "min(92vw, 480px)"@@ -112,51 +112,53 @@ export function Lightbox() {<LightboxMedia item={item} ratio={ratio} />- <div className="flex min-h-0 flex-col gap-3 overflow-y-auto">- <div className="flex items-start justify-between gap-3">- <div className="min-w-0 text-[15px] leading-snug font-semibold tracking-tight break-words text-white">- {item.name}+ {!item.bare && (+ <div className="flex min-h-0 flex-col gap-3 overflow-y-auto">+ <div className="flex items-start justify-between gap-3">+ <div className="min-w-0 text-[15px] leading-snug font-semibold tracking-tight break-words text-white">+ {item.name}+ </div>+ {canAdd && (+ <Button className="shrink-0" disabled={adding} onClick={add}>+ {adding ? (+ <Loader2 data-icon="inline-start" className="animate-spin" />+ ) : added ? (+ <Check data-icon="inline-start" />+ ) : (+ <Plus data-icon="inline-start" />+ )}+ {added ? "Added" : "Use"}+ </Button>+ )}</div>- {canAdd && (- <Button className="shrink-0" disabled={adding} onClick={add}>- {adding ? (- <Loader2 data-icon="inline-start" className="animate-spin" />- ) : added ? (- <Check data-icon="inline-start" />- ) : (- <Plus data-icon="inline-start" />- )}- {added ? "Added" : "Use"}- </Button>- )}- </div>- {item.prompt && item.prompt !== item.name && (- <div className="flex flex-col gap-1">- <div className="flex items-center justify-between">- <span className="text-[11px] font-semibold tracking-wide text-white/60 uppercase">- Prompt- </span>- <button- title="Copy prompt"- className="inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10.5px] font-medium text-white/60 transition-colors hover:bg-white/10 hover:text-white"- onClick={() => {- void navigator.clipboard.writeText(item.prompt).then(() => {- setCopied(true);- setTimeout(() => setCopied(false), 1500);- });- }}- >- {copied ? <Check className="size-3 text-emerald-400" /> : <Copy className="size-3" />}- {copied ? "Copied" : "Copy"}- </button>+ {item.prompt && item.prompt !== item.name && (+ <div className="flex flex-col gap-1">+ <div className="flex items-center justify-between">+ <span className="text-[11px] font-semibold tracking-wide text-white/60 uppercase">+ Prompt+ </span>+ <button+ title="Copy prompt"+ className="inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 text-[10.5px] font-medium text-white/60 transition-colors hover:bg-white/10 hover:text-white"+ onClick={() => {+ void navigator.clipboard.writeText(item.prompt).then(() => {+ setCopied(true);+ setTimeout(() => setCopied(false), 1500);+ });+ }}+ >+ {copied ? <Check className="size-3 text-emerald-400" /> : <Copy className="size-3" />}+ {copied ? "Copied" : "Copy"}+ </button>+ </div>+ <p className="rounded-lg bg-white/10 px-3 py-2 text-[12.5px] leading-relaxed text-white/90">+ {item.prompt}+ </p></div>- <p className="rounded-lg bg-white/10 px-3 py-2 text-[12.5px] leading-relaxed text-white/90">- {item.prompt}- </p>- </div>- )}- </div>+ )}+ </div>+ )}</div></div>);@@ -178,6 +180,7 @@ function LightboxMedia({ item, ratio }: { item: LightboxItem; ratio?: number })autoPlayloopplaysInline+ poster={item.poster}src={item.src}className={mediaClass}style={mediaStyle}diff --git a/site/src/cut/components/SidePanel.tsx b/site/src/cut/components/SidePanel.tsxindex 9d46378b..8fae7b33 100644--- a/site/src/cut/components/SidePanel.tsx+++ b/site/src/cut/components/SidePanel.tsx@@ -1425,6 +1425,7 @@ function LibraryPanel({ projectId }: { projectId: string }) {<LibraryCardkey={a.id}asset={a}+ mentiononUse={() => void addLibraryAssetToProject(projectId, a)}onDelete={() => setDeleting(a)}onDragStartExtra={(e) => onCardDragExtra(e, a)}diff --git a/site/src/cut/components/StockImagesPanel.tsx b/site/src/cut/components/StockImagesPanel.tsxindex 368a1ad6..d810b227 100644--- a/site/src/cut/components/StockImagesPanel.tsx+++ b/site/src/cut/components/StockImagesPanel.tsx@@ -7,7 +7,7 @@ import { setObjectDragImage } from "@/cut/lib/assetDrag";import { useLightbox } from "@/cut/lib/lightbox";import { useRevealEffect, useRevealFlash } from "@/cut/lib/refReveal";import { useImageGen } from "@/cut/lib/imageGen";-import { STOCK_CATEGORIES, type StockCategory, type StockImage } from "@/cut/lib/stock";+import { aspectRatio, STOCK_CATEGORIES, type StockCategory, type StockImage } from "@/cut/lib/stock";import { STOCK_IMAGES } from "@/cut/lib/stockManifest";import { cn } from "@/lib/utils";import { CopyRefButton, RefHandlePill } from "./AssetRefs";@@ -191,7 +191,7 @@ function StockTile({ item }: { item: StockImage }) {useLightbox.getState().open({kind: "image",src: item.file,- aspect: item.aspect,+ ratio: aspectRatio(item.aspect),name: titleFromId(item.id),prompt: item.prompt,assetId: null,diff --git a/site/src/cut/components/StockVideosPanel.tsx b/site/src/cut/components/StockVideosPanel.tsxindex 98b6448e..fb21f26e 100644--- a/site/src/cut/components/StockVideosPanel.tsx+++ b/site/src/cut/components/StockVideosPanel.tsx@@ -7,7 +7,7 @@ import { setObjectDragImage } from "@/cut/lib/assetDrag";import { useLightbox } from "@/cut/lib/lightbox";import { useRevealEffect, useRevealFlash } from "@/cut/lib/refReveal";import { useVideoGen } from "@/cut/lib/videoGen";-import { STOCK_CATEGORIES, stockTitle, type StockCategory, type StockVideo } from "@/cut/lib/stock";+import { aspectRatio, STOCK_CATEGORIES, stockTitle, type StockCategory, type StockVideo } from "@/cut/lib/stock";import { STOCK_VIDEOS } from "@/cut/lib/stockVideoManifest";import { cn } from "@/lib/utils";import { CopyRefButton, RefHandlePill } from "./AssetRefs";@@ -279,7 +279,7 @@ function StockTile({ item }: { item: StockVideo }) {useLightbox.getState().open({kind: "video",src: item.file,- aspect: item.aspect,+ ratio: aspectRatio(item.aspect),name: stockTitle(item.id),prompt: item.prompt,assetId: null,diff --git a/site/src/cut/lib/assetRef.ts b/site/src/cut/lib/assetRef.tsindex 0af5812b..c29ca6f4 100644--- a/site/src/cut/lib/assetRef.ts+++ b/site/src/cut/lib/assetRef.ts@@ -2,7 +2,7 @@import { useCallback, useEffect, useMemo, useRef, useState } from "react";import type React from "react";-import { fetchLibrary, libraryMediaUrl, type LibraryAsset } from "./library";+import { fetchLibrary, libraryMediaUrl, libraryPosterUrl, type LibraryAsset } from "./library";import { stockAspectDims, stockTitle, type StockImage, type StockMusic, type StockVideo } from "./stock";import { STOCK_IMAGES } from "./stockManifest";import { STOCK_VIDEOS } from "./stockVideoManifest";@@ -114,6 +114,7 @@ export const refFromLibrary = (a: LibraryAsset): AssetRef => ({duration: a.duration,...(a.width !== undefined ? { width: a.width } : {}),...(a.height !== undefined ? { height: a.height } : {}),+ ...(libraryPosterUrl(a) ? { thumb: libraryPosterUrl(a) } : {}),});export const refFromStock = (i: StockImage): AssetRef => ({diff --git a/site/src/cut/lib/lightbox.ts b/site/src/cut/lib/lightbox.tsindex 9d37630c..f34723e6 100644--- a/site/src/cut/lib/lightbox.ts+++ b/site/src/cut/lib/lightbox.ts@@ -4,8 +4,8 @@ import { create } from "zustand";import type { AssetRef } from "./assetRef";// The asset lightbox: a full-screen viewer opened from stock tiles, generated-// media, and chat asset cards. Held in its own store so any surface can open-// it and a single overlay (mounted once in the editor) renders it.+// media, chat asset cards, and library cards. Held in its own store so any+// surface can open it and a single mounted overlay renders it.export interface LightboxItem {kind: "video" | "image" | "audio" | "text";@@ -14,15 +14,22 @@ export interface LightboxItem {name: string;/** The generation prompt, when known. */prompt: string;- /** Catalog aspect ("16:9" | "9:16" | "1:1"), when known — sizes the dialog- * up front so it opens at its final size instead of growing on media load. */- aspect?: "16:9" | "9:16" | "1:1";+ /** Width ÷ height, when known — sizes the viewer up front so it opens at the+ * media's own shape instead of collapsing until the file's metadata loads. */+ ratio?: number;+ /** A cover image to show while the media loads: the source's own thumbnail+ * for an imported clip. */+ poster?: string;/** For a project asset, its id (add straight to the timeline); null for a* stock or library item, which the lightbox imports first. */assetId: string | null;/** For a library asset, its id — "Use" copies it in through the library* route so it files like any other library use, not as stock. */libraryId?: string;+ /** Show the media alone, without the name, prompt, or "Use" button. The+ * library page opens this way: outside the editor there is no project to+ * add anything to. */+ bare?: boolean;}/** The lightbox view of an asset ref — how chat cards and attachment chips@@ -32,6 +39,8 @@ export const lightboxItemFromRef = (ref: AssetRef): LightboxItem => ({src: ref.url,name: ref.name,prompt: "",+ ...(ref.width && ref.height ? { ratio: ref.width / ref.height } : {}),+ ...(ref.thumb ? { poster: ref.thumb } : {}),assetId: ref.scope === "project" ? ref.id : null,...(ref.scope === "library" ? { libraryId: ref.id } : {}),});diff --git a/site/src/cut/lib/stock.ts b/site/src/cut/lib/stock.tsindex 7579e289..c449c663 100644--- a/site/src/cut/lib/stock.ts+++ b/site/src/cut/lib/stock.ts@@ -71,6 +71,11 @@ export interface StockMusic {export const stockAspectDims = (aspect: StockVideoAspect): { width: number; height: number } =>aspect === "9:16" ? { width: 1080, height: 1920 } : { width: 1920, height: 1080 };+/** Width ÷ height behind a catalog aspect label, for surfaces that size+ * themselves from the ratio alone. */+export const aspectRatio = (aspect: StockAspect): number =>+ aspect === "9:16" ? 9 / 16 : aspect === "1:1" ? 1 : 16 / 9;+export const STOCK_MUSIC_CATEGORIES = ["Songs","Cinematic",