Skip to content

Open source CapCut alternative.

TypeScript

feat(site): float the lightbox on the backdrop, sized by catalog aspect

David Lef408ed0ac34e
diff --git a/site/src/cut/components/Lightbox.tsx b/site/src/cut/components/Lightbox.tsx
index 4b0213be..23ddb567 100644
--- a/site/src/cut/components/Lightbox.tsx
+++ b/site/src/cut/components/Lightbox.tsx
@@ -3,14 +3,17 @@
import { useEffect, useState } from "react";
import { Check, Copy, Loader2, Plus, X } from "lucide-react";
import { Button } from "@/components/ui/button";
-import { SectionTitle } from "@/cut/components/SectionTitle";
import { useLightbox } from "@/cut/lib/lightbox";
import { importImage, importStockVideo } from "@/cut/lib/media";
import { useEditor } from "@/cut/lib/store";
-// The image lightbox: the bigger version of a stock or generated image, with
-// its name, description, and generation prompt below, plus a button to drop it
-// straight onto the timeline. Mounted once in the editor.
+// The media lightbox: the big version of a stock or generated item 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. When the
+// item's aspect is known the dialog is laid out at its final size before the
+// media loads.
+
+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);
@@ -56,13 +59,23 @@ export function Lightbox() {
}
};
+ // With a known aspect the dialog width follows it — capped so the media
+ // stays within 68vh tall and 860px/92vw wide — and the media box carries the
+ // same ratio, so nothing shifts when the file loads.
+ const ratio = item.aspect ? ASPECT_RATIO[item.aspect] : undefined;
+ const mediaClass = ratio
+ ? "block w-full rounded-2xl bg-black object-cover shadow-2xl"
+ : "block max-h-[68vh] w-full rounded-2xl bg-black object-contain shadow-2xl";
+ const mediaStyle = ratio ? { aspectRatio: ratio } : undefined;
+
return (
<div
className="fixed inset-0 z-70 grid place-items-center bg-black/70 p-6 backdrop-blur-sm"
onClick={() => useLightbox.getState().close()}
>
<div
- className="relative flex max-h-[92vh] w-full max-w-[860px] flex-col overflow-hidden rounded-2xl bg-card shadow-2xl"
+ className="relative flex max-h-[92vh] flex-col gap-3"
+ style={{ width: ratio ? `min(92vw, 860px, ${Math.round(68 * ratio * 100) / 100}vh)` : "min(92vw, 860px)" }}
onClick={(e) => e.stopPropagation()}
>
<button
@@ -81,7 +94,8 @@ export function Lightbox() {
loop
playsInline
src={item.src}
- className="block max-h-[75vh] w-full bg-black object-contain"
+ className={mediaClass}
+ style={mediaStyle}
/>
) : (
<video
@@ -89,21 +103,20 @@ export function Lightbox() {
playsInline
preload="metadata"
src={`${item.src}#t=0.1`}
- className="block max-h-[75vh] w-full object-contain"
+ className={mediaClass}
+ style={mediaStyle}
/>
)
) : (
// eslint-disable-next-line @next/next/no-img-element -- static/project image, client-only page
- <img
- src={item.src}
- alt={item.name}
- className="block max-h-[75vh] w-full object-contain"
- />
+ <img src={item.src} alt={item.name} className={mediaClass} style={mediaStyle} />
)}
- <div className="flex flex-col gap-3 overflow-y-auto p-4">
+ <div className="flex min-h-0 flex-col gap-3 overflow-y-auto">
<div className="flex items-center justify-between gap-3">
- <div className="min-w-0 truncate text-[15px] font-semibold tracking-tight">{item.name}</div>
+ <div className="min-w-0 truncate text-[15px] font-semibold tracking-tight text-white">
+ {item.name}
+ </div>
<Button className="shrink-0" disabled={adding} onClick={add}>
{adding ? (
<Loader2 data-icon="inline-start" className="animate-spin" />
@@ -119,10 +132,12 @@ export function Lightbox() {
{item.prompt && item.prompt !== item.name && (
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
- <SectionTitle>Prompt</SectionTitle>
+ <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-muted-foreground transition-colors hover:bg-muted hover:text-foreground"
+ 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);
@@ -130,11 +145,11 @@ export function Lightbox() {
});
}}
>
- {copied ? <Check className="size-3 text-emerald-600" /> : <Copy className="size-3" />}
+ {copied ? <Check className="size-3 text-emerald-400" /> : <Copy className="size-3" />}
{copied ? "Copied" : "Copy"}
</button>
</div>
- <p className="rounded-lg border border-border bg-muted/40 px-3 py-2 text-[12.5px] leading-relaxed">
+ <p className="rounded-lg bg-white/10 px-3 py-2 text-[12.5px] leading-relaxed text-white/90">
{item.prompt}
</p>
</div>
diff --git a/site/src/cut/components/StockImagesPanel.tsx b/site/src/cut/components/StockImagesPanel.tsx
index 2666ee86..e5adfd85 100644
--- a/site/src/cut/components/StockImagesPanel.tsx
+++ b/site/src/cut/components/StockImagesPanel.tsx
@@ -160,7 +160,6 @@ function StockTile({ item }: { item: StockImage }) {
)}
>
<button
- title={item.prompt}
className="block w-full outline-none focus-visible:ring-2 focus-visible:ring-ring"
draggable
onDragStart={(e) => setRefDragData(e, refFromStock(item))}
@@ -187,6 +186,7 @@ function StockTile({ item }: { item: StockImage }) {
useLightbox.getState().open({
src: item.file,
isVideo: false,
+ aspect: item.aspect,
name: titleFromId(item.id),
prompt: item.prompt,
assetId: null,
diff --git a/site/src/cut/lib/lightbox.ts b/site/src/cut/lib/lightbox.ts
index cd01fb40..5907ae33 100644
--- a/site/src/cut/lib/lightbox.ts
+++ b/site/src/cut/lib/lightbox.ts
@@ -17,6 +17,9 @@ 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";
/** For a project asset, its id (add straight to the timeline); null for a
* stock image, which the lightbox bakes into a still first. */
assetId: string | null;