Open source CapCut alternative.
TypeScript
feat(site): uniform Library tiles with add in the actions menu
David Lee14f43622752
diff --git a/site/src/cut/components/FontSpecimen.tsx b/site/src/cut/components/FontSpecimen.tsxindex 41ca5485..3b0b9a66 100644--- a/site/src/cut/components/FontSpecimen.tsx+++ b/site/src/cut/components/FontSpecimen.tsx@@ -1,39 +1,38 @@"use client";import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";-import { isCurrentSpecimen, SPECIMEN_LINES } from "@/cut/lib/fontSpecimen";+import { isCurrentSpecimen, SPECIMEN_TEXT } from "@/cut/lib/fontSpecimen";import { linkIdForAsset, onLinkedChanged } from "@/cut/lib/linkedLibrary";import { MEDIA_CORS } from "@/cut/lib/mediaCors";import { fontStack, hasFont, onFontsChanged } from "@/cut/lib/types";import { cn } from "@/lib/utils";-// A font drawn in itself. The library card carries a line of it and the big-// view the whole alphabet, both from here, so the two read as the same object.+// A font drawn in itself. The library card and the big view both set the+// pangram from here, wrapped and left-aligned, so the two read as the same+// object at two sizes.//-// Live text in the installed face is what it draws. The picture the shelf baked-// at upload is the standby, for a face the page does not have — a shelf that-// did not answer, a listing that has not synced.+// Live text in the installed face is what it draws, and only that face: the+// picture the shelf baked at upload stands in for a face the page does not have+// — a shelf that did not answer, a listing that has not synced — and is set the+// same way. With neither, the sheet stays blank.-/** Measured at one size and scaled; large enough that rounding doesn't show. */-const PROBE_PX = 100;-/** The share of the room a line is allowed to take. Text measures by advance- * width, and a swash or an italic leans past that, so the fit leaves a little- * back rather than setting every face flush to the edge. */+/** The share of the room the words are allowed to take. Text measures by+ * advance width, and a swash or an italic leans past that, so the fit leaves a+ * little back rather than setting every face flush to the edge. */const SAFETY = 0.97;/**- * The specimen, set to the width it is given.+ * The specimen, wrapped to fill the box it is given.** The size is measured rather than computed because a script face runs three* times the width of a grotesque at the same point size, and every card in a- * grid should carry the same weight of line.+ * grid should carry the same weight of type: the largest size at which no word+ * is wider than the box and the lines fit its height.*/export function FontSpecimen({assetId,src,poster,- lines: LINES = SPECIMEN_LINES,- fitHeight = false,pad = 16,className,}: {@@ -43,14 +42,7 @@ export function FontSpecimen({src?: string;/** The specimen the shelf keeps for this file. */poster?: string;- /** What to set in the face. A card takes one line, the big view the whole- * alphabet. */- lines?: readonly string[];- /** The box has a height of its own — a card — so the line is held inside it- * as well as inside its width. Where the box grows with the text (the big- * view), width alone sets the size. */- fitHeight?: boolean;- /** Room left either side of the widest line, px. */+ /** Room left either side of the words, px. */pad?: number;className?: string;}) {@@ -64,8 +56,11 @@ export function FontSpecimen({const id = linkIdForAsset(assetId) ?? "";const localId = useId();const [loadedFont, setLoadedFont] = useState<{ src: string; family: string } | null>(null);+ const registered = hasFont(id);useEffect(() => {- if (!src) return;+ // The card loads its own file when the shelf's sync has not installed the+ // face yet, so it never waits on the listing.+ if (!src || registered) return;let live = true;const face = new FontFace(`shared-${localId}`, `url(${JSON.stringify(src)})`);void face.load().then(() => {@@ -74,29 +69,30 @@ export function FontSpecimen({setLoadedFont({ src, family: face.family });}).catch(() => {});return () => { live = false; document.fonts.delete(face); };- }, [src, localId]);+ }, [src, localId, registered]);const localFamily = loadedFont?.src === src ? loadedFont?.family : undefined;- const family = localFamily ? JSON.stringify(localFamily) : fontStack(id);- const installed = !!localFamily || hasFont(id);+ const family = registered ? fontStack(id) : localFamily ? JSON.stringify(localFamily) : fontStack(id);+ const installed = registered || !!localFamily;const box = useRef<HTMLDivElement>(null);const probe = useRef<HTMLSpanElement>(null);const [size, setSize] = useState(0);useLayoutEffect(() => {const fit = () => {- // The probe holds every line, so its width is the widest of them: on- // most faces that is the capitals, on some the figures.- const line = probe.current?.getBoundingClientRect().width;+ const measure = probe.current;const width = box.current?.clientWidth;- const height = box.current?.clientHeight ?? 0;- if (!line || !width) return;- // Width sets the size, until the box is short enough that the line would- // be clipped — a card in a narrow panel column. SAFETY keeps the ends of- // a line off the edge: a face whose glyphs overhang their advance widths- // measures narrower than it draws.- const byWidth = (PROBE_PX * Math.max(0, width - pad * 2) * SAFETY) / line;- const byHeight =- fitHeight && height ? (height * SAFETY) / (1.35 * LINES.length) : byWidth;- setSize(Math.min(byWidth, byHeight));+ const height = box.current?.clientHeight;+ if (!measure || !width || !height) return;+ const room = Math.max(0, width - pad * 2) * SAFETY;+ measure.style.width = `${room}px`;+ let lo = 4;+ let hi = 400;+ for (let i = 0; i < 14; i++) {+ const mid = (lo + hi) / 2;+ measure.style.fontSize = `${mid}px`;+ if (measure.scrollWidth <= room + 0.5 && measure.scrollHeight <= height * SAFETY) lo = mid;+ else hi = mid;+ }+ setSize(lo);};fit();// The face arrives after the box does, and the box is resized by the grid.@@ -113,7 +109,7 @@ export function FontSpecimen({ro.disconnect();fonts?.removeEventListener?.("loadingdone", fit);};- }, [family, gen, pad, LINES, fitHeight]);+ }, [family, gen, pad]);if (poster && isCurrentSpecimen(poster) && !broken && !installed)return (// eslint-disable-next-line @next/next/no-img-element -- library media file, not Next-optimizable@@ -129,31 +125,32 @@ export function FontSpecimen({return (<divref={box}- className={cn("grid place-items-center overflow-hidden", className)}+ className={cn("relative grid items-center overflow-hidden", className)}style={{ fontFamily: family }}><spanref={probe}aria-hidden- className="pointer-events-none invisible fixed top-0 left-0"- style={{ fontSize: PROBE_PX }}+ className="pointer-events-none invisible fixed top-0 left-0 leading-[1.2]">- {LINES.map((line) => (- <span key={line} className="block whitespace-nowrap">- {line}- </span>- ))}+ {SPECIMEN_TEXT}</span><span- className="text-center leading-[1.35] whitespace-nowrap"- style={{ fontSize: size || undefined, opacity: size ? 1 : 0 }}+ className="leading-[1.2]"+ // Words set in a stand-in face say nothing about the font, so the+ // sheet stays blank until the face itself is in.+ style={{ fontSize: size || undefined, opacity: size && installed ? 1 : 0, paddingInline: pad }}>- {LINES.map((line) => (- <span key={line} className="block">- {line}- </span>- ))}+ {SPECIMEN_TEXT}</span>+ {!installed && (+ // Lines of type-shaped shimmer while the face loads.+ <span aria-hidden className="absolute inset-0 flex flex-col justify-center gap-[9%]" style={{ paddingInline: pad }}>+ {["88%", "72%", "46%"].map((w) => (+ <span key={w} className="h-[12%] animate-pulse rounded-md bg-white/10" style={{ width: w }} />+ ))}+ </span>+ )}</div>);}diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 9d0d2041..3615b3fc 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -158,7 +158,7 @@ import {import { getPreviewCanvas } from "@/cut/lib/previewCanvas";import { cn } from "@/lib/utils";import { ScrollArea } from "@/components/ui/scroll-area";-import { Field, ResetButton, Row, Section, SegGroup, SegToggle, useSliderCheckpoint, Value } from "@/cut/components/panelBits";+import { Field, ResetButton, Row, Section, SegGroup, SegToggle, Tip, useSliderCheckpoint, Value } from "@/cut/components/panelBits";import { ColorPanel } from "@/cut/components/ColorPanel";import { GroupPanel } from "@/cut/components/GroupPanel";import { RemovalPanel } from "@/cut/components/RemovalPanel";@@ -445,22 +445,23 @@ function RailButton({children?: React.ReactNode;}) {return (- <button- type="button"- title={label}- aria-label={label}- aria-pressed={active}- className={cn(- `panel-tab-${id} relative grid size-8 shrink-0 place-items-center rounded-lg transition-colors`,- active- ? "bg-neutral-900 text-white"- : "text-muted-foreground hover:bg-foreground/5 hover:text-foreground"- )}- onClick={onClick}- >- <Icon className="size-4" strokeWidth={active ? 2.25 : 2} />- {children}- </button>+ <Tip label={label} side="left">+ <button+ type="button"+ aria-label={label}+ aria-pressed={active}+ className={cn(+ `panel-tab-${id} relative grid size-8 shrink-0 place-items-center rounded-lg transition-colors`,+ active+ ? "bg-neutral-900 text-white"+ : "text-muted-foreground hover:bg-foreground/5 hover:text-foreground"+ )}+ onClick={onClick}+ >+ <Icon className="size-4" strokeWidth={active ? 2.25 : 2} />+ {children}+ </button>+ </Tip>);}@@ -1910,7 +1911,7 @@ function AudioPanel({ clip }: { clip: AudioClip }) {* chevron; any value in range can still be typed or dragged. */export const LINE_HEIGHTS = [0.9, 1, 1.15, 1.25, 1.5, 1.75, 2];export const LETTER_SPACINGS = [-2, 0, 2, 5, 10, 20];-/** Glyph stretch stops, percent of the face's own width or height. */+/** Preset text box widths in percent of the frame width; 0 means no wrap. */export const TEXT_WIDTHS = [0, 25, 50, 75, 100];function TextPanel({ overlay: o }: { overlay: TextOverlay }) {diff --git a/site/src/cut/components/LibraryCard.tsx b/site/src/cut/components/LibraryCard.tsxindex b7e2dfe5..3bb853c6 100644--- a/site/src/cut/components/LibraryCard.tsx+++ b/site/src/cut/components/LibraryCard.tsx@@ -1,6 +1,7 @@"use client";import { useState, type ReactNode } from "react";+import { isLinkedAssetType } from "@/cut/lib/types";import { Download, Ellipsis, ExternalLink, Film, Image as ImageIcon, Music, Plus, Share2, Trash2, Type } from "lucide-react";import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";import { Skeleton } from "@/components/ui/skeleton";@@ -16,7 +17,8 @@ import { setLibraryDragData } from "@/cut/lib/assetDrag";import { refFromLibrary } from "@/cut/lib/assetRef";import { openExternal } from "@/cut/lib/hostBridge";import { fileKind } from "@/cut/lib/media";-import { libraryMediaUrl, libraryPosterUrl, downloadLibraryAsset, type LibraryAsset } from "@/cut/lib/library";+import { libraryAssetName, libraryMediaUrl, libraryPosterUrl, downloadLibraryAsset, type LibraryAsset } from "@/cut/lib/library";+import { LUT_FILE_ICON, LUT_MARK_ICON } from "@/cut/lib/linkedLibrary";import { lightboxItemFromLibrary, type LightboxItem } from "@/cut/lib/lightbox";import { availableResidencies } from "@/cut/lib/residency";import { SPECIMEN_BG, SPECIMEN_INK, SPECIMEN_META } from "@/cut/lib/fontSpecimen";@@ -27,6 +29,9 @@ import { cn } from "@/lib/utils";export const LIBRARY_TILE_AREA = 180 * 320;export const LIBRARY_AUDIO_TILE_AREA = LIBRARY_TILE_AREA * 0.7 ** 2;+/** The side of the square every Library file other than a picture takes:+ * sounds, LUTs, fonts, notes and templates. */+export const LIBRARY_SQUARE = Math.round(Math.sqrt(LIBRARY_AUDIO_TILE_AREA));type SharedMedia = { src: string; poster?: string; downloadHref: string };@@ -77,7 +82,7 @@ export function LibraryCard({// at.const refs = () => sharedMedia ? [] :(selected && dragGroup?.length ? dragGroup : [a])- .filter((x) => x.type !== "font")+ .filter((x) => !isLinkedAssetType(x.type)).map(refFromLibrary);// With one shelf listed, every card is on it — the badge would say nothing.// Phone recordings all come up from the cloud, so they carry none either.@@ -90,7 +95,7 @@ export function LibraryCard({const src = sharedMedia?.src ?? libraryMediaUrl(a.fileName, a.residency);const poster = sharedMedia ? sharedMedia.poster : libraryPosterUrl(a);const view = (): LightboxItem => sharedMedia ? {- kind: a.type, src, name: a.title || a.name, prompt: "", assetId: null, bare: true,+ kind: a.type, src, name: libraryAssetName(a), prompt: "", assetId: null, bare: true,duration: a.duration, poster, ...(a.width && a.height ? { ratio: a.width / a.height } : {}),} : lightboxItemFromLibrary(a, !onUse);@@ -107,6 +112,8 @@ export function LibraryCard({// into view.const [hovered, setHovered] = useState(false);const font = a.type === "font";+ // A LUT tile is the file icon; its facts (CUBE · 33³) ride the footer.+ const lut = a.type === "lut";const sizeBytes = useMediaFileSize(offline ? "" : src,hovered || (font && seen),@@ -118,12 +125,12 @@ export function LibraryCard({].filter(Boolean).join(" · ");+ // Pictures take their own aspect at the shared area; every other file is+ // the same square the sound tile is.const frame =- area && a.type !== "audio" && a.width && a.height+ area && (a.type === "video" || a.type === "image") && a.width && a.height? { w: a.width, h: a.height }- : font- ? { w: 16, h: 6 }- : { w: 1, h: 1 };+ : { w: 1, h: 1 };const tileStyle = {...(area? {@@ -139,7 +146,7 @@ export function LibraryCard({scope="library"id={a.id}refs={refs}- // Without a + button there is no project to add it to, so the viewer+ // Without an "Add to timeline" item there is no project to add it to, so the viewer// opens bare.view={offline ? undefined : view}restTime={posterT}@@ -158,8 +165,10 @@ export function LibraryCard({<divref={tileRef}data-drag-object+ data-drag-ghost={lut ? LUT_MARK_ICON : undefined}className={cn(- "relative max-w-full cursor-grab overflow-hidden rounded-xl border bg-muted transition-shadow group-hover:shadow-[0_4px_20px_rgba(0,0,0,0.1)] active:cursor-grabbing",+ "relative max-w-full cursor-grab overflow-hidden rounded-xl border shadow-sm transition-shadow active:cursor-grabbing",+ lut ? "bg-background" : "bg-muted group-hover:shadow-[0_4px_20px_rgba(0,0,0,0.1)]",!area && (font ? "aspect-[16/7]" : "aspect-square"),// The sheet is the card, so nothing is drawn around it; the type// scales with the tile, which runs from a panel column to a full row.@@ -183,8 +192,7 @@ export function LibraryCard({) : (<FontSpecimenassetId={a.id}- src={sharedMedia && seen ? src : undefined}- fitHeight+ src={seen ? src : undefined}pad={0}className="size-full"/>@@ -209,6 +217,11 @@ export function LibraryCard({)}</div></div>+ ) : lut ? (+ // The tile is the square: the cube with its LUT wordmark under the+ // name, the way a sound tile sets its own.+ // eslint-disable-next-line @next/next/no-img-element -- static icon+ <img src={LUT_FILE_ICON} alt="" aria-hidden className="size-full object-contain px-2 pt-8 pb-2" />) : offline ? (// Nothing to load from a shelf that isn't answering, so the card// shows what it knows: the kind of file, its name, its length.@@ -271,16 +284,9 @@ export function LibraryCard({onError={() => setPainted(true)}/>) : (- <AudioCardFace- url={src}- duration={a.duration}- // On hover the + button takes the pill's corner.- durationClassName={- !!onUse && "transition-opacity group-hover:opacity-0"- }- />+ <AudioCardFace url={src} duration={a.duration} />)}- {!offline && !font && a.type !== "audio" && !painted && (+ {!offline && !font && !lut && a.type !== "audio" && !painted && (<Skeletondata-drag-omitaria-hidden@@ -289,10 +295,11 @@ export function LibraryCard({)}{a.type !== "audio" &&!font &&+ !lut &&(a.type === "video" || sizeBytes != null) && (// Length and size share one pill in the corner: on a card this narrow// two of them collide. The length reads at rest, the size takes over- // on hover, where the + button is what the pointer is there for.+ // on hover.<spandata-drag-omitclassName={cn(@@ -323,29 +330,6 @@ export function LibraryCard({{formatBytes(sizeBytes)}</span>)}- {onUse && (- <button- aria-label="Add to timeline"- title="Add to timeline"- className={cn(- "absolute grid size-6 place-items-center rounded-full bg-primary text-primary-foreground opacity-0 shadow transition-all group-hover:opacity-100 hover:scale-110",- // Audio keeps play bottom-left; + swaps in where the badge hides.- // A font's bottom edge is its footer, so its + takes the corner- // the name used to sit in.- a.type === "audio"- ? "right-1.5 bottom-1.5"- : font- ? "top-1.5 left-1.5"- : "bottom-1.5 left-1.5",- )}- onClick={(e) => {- e.stopPropagation();- onUse();- }}- >- <Plus className="size-3.5" />- </button>- )}{bothShelves && (<ShelfBadgeresidency={a.residency}@@ -361,7 +345,6 @@ export function LibraryCard({<DropdownMenu><DropdownMenuTriggeraria-label="More actions"- title="More actions"className={cn("absolute top-1.5 right-1.5 grid size-6 place-items-center rounded-full text-white opacity-0 transition-opacity group-hover:opacity-100 data-[state=open]:opacity-100",// A black scrim disappears into the charcoal sheet.@@ -381,6 +364,14 @@ export function LibraryCard({className="w-44"onClick={(e) => e.stopPropagation()}>+ {onUse && (+ <>+ <DropdownMenuItem onClick={onUse}>+ <Plus /> Add to timeline+ </DropdownMenuItem>+ <DropdownMenuSeparator />+ </>+ )}{onShare && <DropdownMenuItem disabled={offline} onClick={onShare}><Share2 /> Share</DropdownMenuItem>}{sharedMedia ? (<DropdownMenuItem render={<a href={sharedMedia.downloadHref} />}>@@ -410,14 +401,15 @@ export function LibraryCard({</DropdownMenu>{!font && (<CopyNameLabel- name={a.name}- label={a.title}+ name={lut ? libraryAssetName(a) : a.name}+ label={lut ? undefined : a.title}dark={a.type === "audio"}mention={mention}className={cn("absolute top-1.5 left-1.5 max-w-[70%] px-2 py-1 text-[11px] font-medium text-white transition-[max-width] group-hover:max-w-[calc(100%-2.75rem)]",// The emerald fill is its own backdrop; thumbnails need the scrim pill.- a.type !== "audio" && "rounded-lg bg-black/55 backdrop-blur-sm",+ a.type !== "audio" && !lut && "rounded-lg bg-black/55 backdrop-blur-sm",+ lut && "text-foreground",)}/>)}diff --git a/site/src/cut/components/LibraryImportCard.tsx b/site/src/cut/components/LibraryImportCard.tsxindex 7cf8d9d2..08c29ae4 100644--- a/site/src/cut/components/LibraryImportCard.tsx+++ b/site/src/cut/components/LibraryImportCard.tsx@@ -83,7 +83,7 @@ export function LibraryImportCard({event.dataTransfer.effectAllowed = "copy";} : undefined}className={cn(- "relative max-w-full overflow-hidden rounded-xl border",+ "relative max-w-full overflow-hidden rounded-xl border shadow-sm",canPreview && "cursor-pointer",item.error ? "border-destructive/50 bg-muted" : "border-border",)}@@ -118,7 +118,7 @@ export function LibraryImportCard({// eslint-disable-next-line @next/next/no-img-element -- local file preview<img src={previewUrl} alt={item.name} className="size-full object-cover" />) : previewUrl && mediaType === "font" ? (- <FontSpecimen assetId={item.id} src={previewUrl} fitHeight className="size-full" />+ <FontSpecimen assetId={item.id} src={previewUrl} className="size-full" />) : file && mediaType === "video" ? (<ImportVideoPoster file={file} size={Math.ceil(Math.sqrt(area))} />) : file && mediaType !== "image" && mediaType !== "audio" ? (diff --git a/site/src/cut/components/Lightbox.tsx b/site/src/cut/components/Lightbox.tsxindex a60fb58e..396c4a3f 100644--- a/site/src/cut/components/Lightbox.tsx+++ b/site/src/cut/components/Lightbox.tsx@@ -1,6 +1,8 @@"use client";import { useEffect, useRef, useState } from "react";+import { LUT_FILE_ICON } from "@/cut/lib/linkedLibrary";+import { isLinkedAssetType } from "@/cut/lib/types";import { Check, Copy, FileText, Loader2, Music, Plus, X } from "lucide-react";import { Button } from "@/components/ui/button";import { MEDIA_CORS } from "@/cut/lib/mediaCors";@@ -12,7 +14,6 @@ import { useEditor } from "@/cut/lib/store";import { DocText, useDocText } from "./DocText";import { FontSpecimen } from "./FontSpecimen";import {- SPECIMEN_ALPHABET,SPECIMEN_BG,SPECIMEN_INK,} from "@/cut/lib/fontSpecimen";@@ -89,7 +90,7 @@ export function Lightbox() {const canAdd =!item.bare &&item.kind !== "text" &&- item.kind !== "font" &&+ !isLinkedAssetType(item.kind) &&(item.kind !== "audio" ||item.assetId !== null ||item.libraryId !== undefined);@@ -103,7 +104,9 @@ export function Lightbox() {item.kind === "audio"? "min(92vw, 480px)": item.kind === "font"- ? "min(92vw, 1000px)"+ ? "min(92vw, 72vh)"+ : item.kind === "lut"+ ? "min(92vw, 360px)": item.kind === "text"? "min(92vw, 720px)": ratio@@ -201,6 +204,7 @@ function LightboxMedia({if (item.kind === "audio") return <AudioBody item={item} />;if (item.kind === "text") return <TextBody item={item} />;if (item.kind === "font") return <FontBody item={item} />;+ if (item.kind === "lut") return <LutBody item={item} />;const mediaClass = ratio? "block w-full rounded-2xl bg-black object-cover shadow-2xl"@@ -363,27 +367,36 @@ function AudioBody({ item }: { item: LightboxItem }) {);}-/** A font, big: the sheet a font file previews on, the alphabet filling it. */+/** A font, big: the card's square sheet, the pangram wrapped across it. */function FontBody({ item }: { item: LightboxItem }) {return (- // The sheet keeps its margin whichever way the alphabet arrives: the baked+ // The sheet keeps its margin whichever way the specimen arrives: the baked// picture is the same charcoal, so padding it reads as more sheet.<div- className="overflow-hidden rounded-2xl px-10 py-12 shadow-2xl"+ className="aspect-square w-full overflow-hidden rounded-2xl p-10 shadow-2xl"style={{ backgroundColor: SPECIMEN_BG, color: SPECIMEN_INK }}><FontSpecimenassetId={item.libraryId ?? ""}src={!item.libraryId ? item.src : undefined}poster={item.poster}- lines={SPECIMEN_ALPHABET}pad={0}- className="w-full"+ className="size-full"/></div>);}+function LutBody({ item }: { item: LightboxItem }) {+ return (+ <div className="flex flex-col items-center gap-3 rounded-2xl bg-card p-8 shadow-2xl">+ {/* eslint-disable-next-line @next/next/no-img-element -- static icon */}+ <img src={LUT_FILE_ICON} alt="" aria-hidden className="size-40" />+ <span className="truncate text-[12.5px] font-medium">{item.name}</span>+ </div>+ );+}+function TextBody({ item }: { item: LightboxItem }) {const { text, failed } = useDocText(item.src);return (diff --git a/site/src/cut/components/MediaCardShell.tsx b/site/src/cut/components/MediaCardShell.tsxindex ac347b46..527b13a8 100644--- a/site/src/cut/components/MediaCardShell.tsx+++ b/site/src/cut/components/MediaCardShell.tsx@@ -67,7 +67,7 @@ export function MediaCardShell({onDoubleClick={view? (e) => {- // The + button and the actions menu answer their own clicks; a+ // The actions menu and its items answer their own clicks; a// fast double press on one is two of those, and opens nothing.if ((e.target as HTMLElement).closest(diff --git a/site/src/cut/components/NotesView.tsx b/site/src/cut/components/NotesView.tsxindex bb5c8f58..058cd560 100644--- a/site/src/cut/components/NotesView.tsx+++ b/site/src/cut/components/NotesView.tsx@@ -27,6 +27,7 @@ import { cn } from "@/lib/utils";import { setObjectDragImage } from "@/cut/lib/assetDrag";import { PICKED_RING } from "@/cut/lib/assetPick";import { FolderCrumb, FolderShelf, Marquee } from "./desktopFolders";+import { LIBRARY_SQUARE } from "./LibraryCard";import { NoteComposer, noteChanged, type NoteDraft } from "./NoteComposer";// The note paper's ink, matching the iOS app.@@ -601,7 +602,10 @@ export function NotesView({ library, ref }: Props = {}) {</button>) : (<Marquee- className="grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-3"+ className="flex flex-wrap items-start gap-4"+ // In the Library the notes are one row among the files, sized to+ // what they hold; the page's own sweep area is below them.+ {...(library ? { rootClassName: "relative" } : {})}selected={selected}setSelected={setSelected}>@@ -617,14 +621,22 @@ export function NotesView({ library, ref }: Props = {}) {onDragStart={(e) => onCardDragStart(e, n.id)}onDragEnd={clearRefDrag}className={cn(- "flex min-h-40 cursor-pointer flex-col gap-1.5 rounded-2xl p-4 text-left shadow-sm transition-transform hover:-translate-y-0.5",+ "flex cursor-pointer flex-col gap-1.5 text-left shadow-sm transition-transform hover:-translate-y-0.5",+ // A note is a file like the rest: the same square a sound+ // tile is, here and in the Library.+ "overflow-hidden rounded-xl p-3",selected.has(n.id) && PICKED_RING,)}- style={{ backgroundColor: noteColor(n.colorIndex).background, color: NOTE_INK }}+ style={{+ backgroundColor: noteColor(n.colorIndex).background,+ color: NOTE_INK,+ width: LIBRARY_SQUARE,+ height: LIBRARY_SQUARE,+ }}onClick={() => openNote(n)}>- {n.title && <div className="font-semibold">{n.title}</div>}- <div className="line-clamp-6 text-sm whitespace-pre-wrap opacity-80">{n.body}</div>+ {n.title && <div className="truncate text-[13px] font-semibold">{n.title}</div>}+ <div className="line-clamp-5 text-[12px] whitespace-pre-wrap opacity-80">{n.body}</div>{worn.length > 0 && (<div className="mt-auto flex flex-wrap gap-1 pt-1.5">{worn.map((name) => (diff --git a/site/src/cut/components/TemplateCard.tsx b/site/src/cut/components/TemplateCard.tsxindex 587c2a50..77e4769e 100644--- a/site/src/cut/components/TemplateCard.tsx+++ b/site/src/cut/components/TemplateCard.tsx@@ -29,11 +29,19 @@ import {type TemplateDrag,} from "@/cut/lib/assetDrag";import { MEDIA_CORS } from "@/cut/lib/mediaCors";-import { refFromTemplate, useAssetDrop, type AssetRef } from "@/cut/lib/assetRef";+import {+ refFromTemplate,+ useAssetDrop,+ type AssetRef,+} from "@/cut/lib/assetRef";import { useRefCopy } from "@/cut/lib/refCopy";import { cardIconButton } from "@/cut/components/iconButton";import { formatTime } from "@/cut/lib/time";-import { EFFECT_LABELS, retimeOf, type SpeedNode } from "@donkeycut/effects-kit";+import {+ EFFECT_LABELS,+ retimeOf,+ type SpeedNode,+} from "@donkeycut/effects-kit";import { SHAPE_LABELS } from "@/cut/lib/types";import type { LibraryTemplate, TemplateMedia } from "@/cut/lib/types";import { cn } from "@/lib/utils";@@ -60,13 +68,14 @@ export function TemplateCard({extraMenu,selectId,selected = false,+ tile,}: {template: LibraryTemplate;/** Resolve a template media file to a playable URL (project or library). */mediaSrc: (fileName: string) => string;/** The payload this card drags; omit to make it undraggable. */drag?: TemplateDrag;- /** The "+" action; omit to drop the button (e.g. no open project). */+ /** The menu's add action, named by `addTitle`; omit it with no open project. */onAdd?: () => void;addTitle?: string;/** Rename and delete; omit both on a shelf that can't be written to right@@ -84,6 +93,9 @@ export function TemplateCard({* files into folders in the same selection as the media around it. */selectId?: string;selected?: boolean;+ /** Draw as a square file tile, the way every file is set: of this side, or+ * filling its grid cell with "fill". Absent, the card is a row. */+ tile?: number | "fill";}) {const refDrop = useAssetDrop((r) => onRefDrop?.(r));// ⌘C over the card copies its mention token, so a saved arrangement can be@@ -106,8 +118,13 @@ export function TemplateCard({// The contents, one row per item, in save order: clips and stills, sounds,// titles, then a caption count.- const speedLen = (x: { in: number; out: number; speed?: number; speedCurve?: SpeedNode[]; reverse?: boolean }) =>- retimeOf(x).len;+ const speedLen = (x: {+ in: number;+ out: number;+ speed?: number;+ speedCurve?: SpeedNode[];+ reverse?: boolean;+ }) => retimeOf(x).len;const parts: {icon: typeof Film;label: string;@@ -148,6 +165,87 @@ export function TemplateCard({: []),];+ const nameEl = (+ <>+ {renaming ? (+ <Input+ autoFocus+ value={draft}+ className="h-6 w-full text-[12px]"+ onChange={(e) => setDraft(e.target.value)}+ onBlur={() => setRenaming(false)}+ onKeyDown={(e) => {+ if (e.key === "Enter" && draft.trim()) {+ onRename?.(draft.trim());+ setRenaming(false);+ } else if (e.key === "Escape") setRenaming(false);+ }}+ />+ ) : (+ <div className="truncate text-[12px] font-medium">{t.name}</div>+ )}+ </>+ );+ const metaEl = (+ <div className="flex items-center gap-0.5 text-[10.5px] whitespace-nowrap text-muted-foreground">+ {formatTime(t.duration)} · {itemCount} item+ {itemCount === 1 ? "" : "s"}+ <ChevronDown+ className={cn("size-3 transition-transform", expanded && "rotate-180")}+ />+ </div>+ );+ const actionsEl = (+ <div className={cn("flex shrink-0 items-center gap-1", tile && "absolute top-1.5 right-1.5")}>+ {(onAdd || onRename || onDelete) && (+ <DropdownMenu>+ <DropdownMenuTrigger+ render={+ <button+ aria-label="Template options"+ className={cn(+ cardIconButton,+ "opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100",+ )}+ />+ }+ >+ <MoreHorizontal className="size-3.5" />+ </DropdownMenuTrigger>+ <DropdownMenuContent align="end" className="min-w-40">+ {onAdd && (+ <>+ <DropdownMenuItem onClick={onAdd}>+ <Plus /> {addTitle ?? "Add"}+ </DropdownMenuItem>+ {(onRename || onDelete) && <DropdownMenuSeparator />}+ </>+ )}+ {onRename && (+ <DropdownMenuItem+ onClick={() => {+ setDraft(t.name);+ setRenaming(true);+ }}+ >+ <Pencil /> Rename+ </DropdownMenuItem>+ )}+ {extraMenu}+ {onDelete && (+ <>+ <DropdownMenuSeparator />+ <DropdownMenuItem variant="destructive" onClick={onDelete}>+ <Trash2 /> Delete+ </DropdownMenuItem>+ </>+ )}+ </DropdownMenuContent>+ </DropdownMenu>+ )}+ </div>+ );+return (<divref={(el) => {@@ -156,8 +254,11 @@ export function TemplateCard({}}{...(onRefDrop ? refDrop.targetProps : {})}data-sel-id={selectId}+ style={typeof tile === "number" ? { width: tile, height: tile } : undefined}className={cn(- "group flex flex-col rounded-lg border bg-background px-2.5 py-1.5",+ "group flex flex-col border bg-background",+ tile ? "relative overflow-hidden rounded-xl p-2.5 shadow-sm" : "rounded-lg px-2.5 py-1.5",+ tile === "fill" && "aspect-square w-full",selected ? PICKED_RING : "border-border",drag ? "cursor-grab active:cursor-grabbing" : "cursor-pointer",onRefDrop && refDrop.active && "border-primary bg-primary/10",@@ -176,89 +277,33 @@ export function TemplateCard({setExpanded((v) => !v);}}>- <div className="flex items-center gap-2">- <Layers className="size-3.5 shrink-0 text-violet-500" />- <div className="min-w-0 flex-1">- {renaming ? (- <Input- autoFocus- value={draft}- className="h-6 w-full text-[12px]"- onChange={(e) => setDraft(e.target.value)}- onBlur={() => setRenaming(false)}- onKeyDown={(e) => {- if (e.key === "Enter" && draft.trim()) {- onRename?.(draft.trim());- setRenaming(false);- } else if (e.key === "Escape") setRenaming(false);- }}- />- ) : (- <div className="truncate text-[12px] font-medium">{t.name}</div>- )}- <div className="flex items-center gap-0.5 text-[10.5px] text-muted-foreground">- {formatTime(t.duration)} · {itemCount} item- {itemCount === 1 ? "" : "s"}- <ChevronDown- className={cn(- "size-3 transition-transform",- expanded && "rotate-180",- )}- />+ {tile ? (+ <>+ <div className="min-w-0 pt-0.5">{nameEl}</div>+ {actionsEl}+ </>+ ) : (+ <div className="flex items-center gap-2">+ <Layers className="size-3.5 shrink-0 text-violet-500" />+ <div className="min-w-0 flex-1">+ {nameEl}+ {metaEl}</div>+ {actionsEl}</div>- <div className="flex shrink-0 items-center gap-1">- {onAdd && (- <button- title={addTitle}- className="grid size-6 shrink-0 place-items-center rounded-full bg-primary text-primary-foreground opacity-0 hover:brightness-110 group-hover:opacity-100"- onClick={onAdd}- >- <Plus className="size-3.5" />- </button>- )}- {(onRename || onDelete) && (- <DropdownMenu>- <DropdownMenuTrigger- render={- <button- title="Template options"- className={cn(- cardIconButton,- "opacity-0 group-hover:opacity-100 data-[state=open]:opacity-100",- )}- />- }- >- <MoreHorizontal className="size-3.5" />- </DropdownMenuTrigger>- <DropdownMenuContent align="end" className="min-w-40">- {onRename && (- <DropdownMenuItem- onClick={() => {- setDraft(t.name);- setRenaming(true);- }}- >- <Pencil /> Rename- </DropdownMenuItem>- )}- {extraMenu}- {onDelete && (- <>- <DropdownMenuSeparator />- <DropdownMenuItem variant="destructive" onClick={onDelete}>- <Trash2 /> Delete- </DropdownMenuItem>- </>- )}- </DropdownMenuContent>- </DropdownMenu>- )}+ )}+ {tile && !(expanded && parts.length > 0) && (+ <div className="grid min-h-0 flex-1 place-items-center">+ <Layers className="size-[80%] text-violet-500" strokeWidth={1.5} /></div>- </div>+ )}{expanded && parts.length > 0 && (- <div className="mt-1.5 flex flex-col gap-1 border-t border-border pt-1.5">+ <div+ className={cn(+ "mt-1.5 flex flex-col gap-1 border-t border-border pt-1.5",+ tile && "min-h-0 flex-1 overflow-y-auto",+ )}+ >{parts.map(({ icon: Icon, label, time, media }, i) => (<divkey={i}@@ -312,6 +357,7 @@ export function TemplateCard({))}</div>)}+ {tile && <div className="pt-1">{metaEl}</div>}{preview && (<divclassName="pointer-events-none fixed z-50"diff --git a/site/src/cut/components/desktopFolders.tsx b/site/src/cut/components/desktopFolders.tsxindex 07495a03..559bf76c 100644--- a/site/src/cut/components/desktopFolders.tsx+++ b/site/src/cut/components/desktopFolders.tsx@@ -531,17 +531,14 @@ export function FolderShelf<F extends DeskFolder>({const editGlyphClass = rows ? "size-7 shrink-0" : "size-[40px]";return (- <div- className={cn(rows ? "mb-4 flex flex-col" : "-ml-2 mb-7 flex flex-wrap gap-2")}- data-no-marquee- >+ <div className={cn(rows ? "mb-4 flex flex-col" : "-ml-2 mb-7 flex flex-wrap gap-2")}>{folders.map((f) => {const s = statOf(f.id);const isOver = over === f.id;if (editingId === f.id) {const text = draftFor === f.id ? draft : f.name;return (- <div key={f.id} className={editRowClass}>+ <div key={f.id} className={editRowClass} data-no-marquee><FolderGlyph className={editGlyphClass} /><InputautoFocus@@ -569,7 +566,11 @@ export function FolderShelf<F extends DeskFolder>({// folders, with the items riding under their own MIME.const carried = isPicked ? splitPick(picked) : { folders: [], items: [] };const carriedFolders = [f.id, ...carried.folders.filter((id) => id !== f.id)];+ // The tile, never the shelf around it, holds off the marquee: the+ // space between and beside tiles is page, where a press sweeps and a+ // right-click opens the page menu.const interact = {+ "data-no-marquee": "",...(pickable ? { "data-sel-id": sel } : {}),onClick: (e: React.MouseEvent) => {if (pickable && additiveClick(e)) {@@ -726,7 +727,7 @@ export function FolderShelf<F extends DeskFolder>({})}{creating && (- <div className={editRowClass}>+ <div className={editRowClass} data-no-marquee><FolderGlyph className={cn(editGlyphClass, "opacity-60")} /><InputautoFocusdiff --git a/site/src/cut/components/panelBits.tsx b/site/src/cut/components/panelBits.tsxindex 5cbb61b9..0a916496 100644--- a/site/src/cut/components/panelBits.tsx+++ b/site/src/cut/components/panelBits.tsx@@ -88,24 +88,46 @@ export const Value = ({ children, className }: { children: React.ReactNode; clas<span className={cn("font-mono text-[11.5px] tabular-nums", className)}>{children}</span>);+/** A hover label in the house style, on a control that has no text. The+ * control is the trigger, so it keeps its own element and props. */+export function Tip({+ label,+ side,+ children,+}: {+ label: string;+ side?: "top" | "bottom" | "left" | "right";+ children: React.ReactElement;+}) {+ return (+ <TooltipProvider>+ <Tooltip>+ <TooltipTrigger render={children} />+ <TooltipContent side={side}>{label}</TooltipContent>+ </Tooltip>+ </TooltipProvider>+ );+}+/** Sits at the right end of a row, visible once its value has moved off the* default. Always occupies its slot so the row doesn't shift when it appears. */export function ResetButton({ title, show, onClick }: { title: string; show: boolean; onClick: () => void }) {return (- <button- type="button"- title={title}- aria-label={title}- aria-hidden={!show}- tabIndex={show ? undefined : -1}- className={cn(- "grid size-5 shrink-0 place-items-center rounded text-muted-foreground transition-colors hover:text-foreground",- !show && "invisible",- )}- onClick={onClick}- >- <RotateCcw className="size-3" />- </button>+ <Tip label={title}>+ <button+ type="button"+ aria-label={title}+ aria-hidden={!show}+ tabIndex={show ? undefined : -1}+ className={cn(+ "grid size-5 shrink-0 place-items-center rounded text-muted-foreground transition-colors hover:text-foreground",+ !show && "invisible",+ )}+ onClick={onClick}+ >+ <RotateCcw className="size-3" />+ </button>+ </Tip>);}diff --git a/site/src/cut/lib/fontSpecimen.ts b/site/src/cut/lib/fontSpecimen.tsindex bc7276d0..cd111358 100644--- a/site/src/cut/lib/fontSpecimen.ts+++ b/site/src/cut/lib/fontSpecimen.ts@@ -1,6 +1,6 @@/**- * The picture a font shows of itself, on a warm charcoal sheet: a pangram on- * the card, the alphabet in the big view.+ * The picture a font shows of itself: a pangram on a warm charcoal sheet,+ * wrapped and left-aligned.** Drawing the line in a live face depends on that face being installed in* whatever page is looking at it, which is a thing that can be true one minute@@ -12,16 +12,9 @@import { createRasterCanvas, rasterCanvasToPng } from "./raster";-/** What a card shows: one line, enough of the face to recognise it by. */-export const SPECIMEN_LINES = ["Pack my box with five dozen jugs"];--/** What the big view shows, and what the cover is baked from: every letter and- * figure, the way a font file previews anywhere else. */-export const SPECIMEN_ALPHABET = [- "ABCDEFGHIJKLMNOPQRSTUVWXYZ",- "abcdefghijklmnopqrstuvwxyz",- "1234567890",-];+/** What a font shows of itself, wrapped and left-aligned, on the card and in+ * the big view alike. */+export const SPECIMEN_TEXT = "Pack my box with five dozen jugs";/** The sheet the specimen is set on, shared by the baked picture and the card* that draws the face live, so the two read as one object. */@@ -31,42 +24,61 @@ export const SPECIMEN_INK = "#F1EFE8";/** The card's footnote beside the name: file kind and size. */export const SPECIMEN_META = "#8A877E";-/** What a baked specimen is called. The name carries the sheet's colours, so a- * cover baked before this one is spotted by its name and passed over: an old- * white sheet inside the charcoal card would read as a hole in it. */-export const SPECIMEN_FILE_SUFFIX = ".specimen-dark.png";+/** What a baked specimen is called. The name carries the sheet's layout, so a+ * cover baked before this one — a centred alphabet on a wide sheet — is spotted+ * by its name and passed over. */+export const SPECIMEN_FILE_SUFFIX = ".specimen-square.png";export const isCurrentSpecimen = (url: string) =>url.split("?")[0].endsWith(SPECIMEN_FILE_SUFFIX);-const W = 1600;-const H = 900;+const S = 1200;const PAD = 90;-/** Measured at one size and scaled; large enough that rounding doesn't show. */-const PROBE = 100;+const LEADING = 1.2;++/** The pangram broken into lines at `size`, greedily, the way the card's+ * text wraps. */+function wrapLines(ctx: CanvasRenderingContext2D, size: number, family: string, room: number): string[] | null {+ ctx.font = `${size}px "${family}"`;+ const lines: string[] = [];+ let line = "";+ for (const word of SPECIMEN_TEXT.split(" ")) {+ if (ctx.measureText(word).width > room) return null;+ const next = line ? `${line} ${word}` : word;+ if (line && ctx.measureText(next).width > room) {+ lines.push(line);+ line = word;+ } else line = next;+ }+ if (line) lines.push(line);+ return lines;+}/**- * A 16:9 specimen of an installed family.- *- * One size for all three lines: the capitals are the widest, so fitting them- * sets the size and the rest fall where the face puts them.+ * A square specimen of an installed family, set the way the card sets it: the+ * largest size at which the wrapped words fit the sheet.*/export async function specimenPng(family: string): Promise<Blob> {- const canvas = createRasterCanvas(W, H);+ const canvas = createRasterCanvas(S, S);const ctx = canvas.getContext("2d") as CanvasRenderingContext2D | null;if (!ctx) throw new Error("No 2D context for the specimen.");+ const room = S - PAD * 2;+ let lo = 8;+ let hi = 600;+ for (let i = 0; i < 16; i++) {+ const mid = (lo + hi) / 2;+ const lines = wrapLines(ctx, mid, family, room);+ if (lines && lines.length * mid * LEADING <= room) lo = mid;+ else hi = mid;+ }+ const lines = wrapLines(ctx, lo, family, room) ?? [SPECIMEN_TEXT];ctx.fillStyle = SPECIMEN_BG;- ctx.fillRect(0, 0, W, H);+ ctx.fillRect(0, 0, S, S);ctx.fillStyle = SPECIMEN_INK;- ctx.textAlign = "center";+ ctx.textAlign = "left";ctx.textBaseline = "middle";- ctx.font = `${PROBE}px "${family}"`;- const widest = ctx.measureText(SPECIMEN_ALPHABET[0]).width;- const size = widest > 0 ? (PROBE * (W - PAD * 2)) / widest : PROBE;- ctx.font = `${size}px "${family}"`;- const step = size * 1.35;- const mid = (SPECIMEN_ALPHABET.length - 1) / 2;- SPECIMEN_ALPHABET.forEach((line, i) => {- ctx.fillText(line, W / 2, H / 2 + (i - mid) * step);- });+ ctx.font = `${lo}px "${family}"`;+ const step = lo * LEADING;+ const top = S / 2 - ((lines.length - 1) * step) / 2;+ lines.forEach((line, i) => ctx.fillText(line, PAD, top + i * step));return rasterCanvasToPng(canvas);}