Open source CapCut alternative.
TypeScript
feat(site): square swatch tiles and a two-per-row shapes grid
David Lee024056fe217
diff --git a/site/src/cut/components/EffectsPanel.tsx b/site/src/cut/components/EffectsPanel.tsxindex badcd0fd..4305ca6c 100644--- a/site/src/cut/components/EffectsPanel.tsx+++ b/site/src/cut/components/EffectsPanel.tsx@@ -12,11 +12,11 @@ import {type EffectId,} from "@donkeycut/effects-kit";import { PICKED_RING, pickGridNav, useAssetPick } from "@/cut/lib/assetPick";-import { clearElementDrag, setElementDragData } from "@/cut/lib/assetDrag";+import { clearElementDrag, setElementDragData, setObjectDragImage } from "@/cut/lib/assetDrag";import { SubTabs } from "@/cut/components/SubTabs";import { getPreviewCanvas } from "@/cut/lib/previewCanvas";import { useEditor } from "@/cut/lib/store";-import { frameOf, isEffectOverlay, type EffectOverlay } from "@/cut/lib/types";+import { isEffectOverlay, type EffectOverlay } from "@/cut/lib/types";import { useLocalPref } from "@/cut/lib/uiState";import { cn } from "@/lib/utils";import { ScrollArea } from "@/components/ui/scroll-area";@@ -187,7 +187,10 @@ function EffectTile({data-pick-id={`effect:${id}`}aria-pressed={marked}draggable- onDragStart={(e) => setElementDragData(e, { kind: "effect", effect: id })}+ onDragStart={(e) => {+ setElementDragData(e, { kind: "effect", effect: id });+ setObjectDragImage(e);+ }}onDragEnd={clearElementDrag}onPointerEnter={() => setHover(true)}onPointerLeave={() => setHover(false)}@@ -268,22 +271,12 @@ export function useSwatchClock(running: boolean, loop = LOOP_S, resetKey = 0): nreturn t;}-/** The tile swatch's shape: the project frame's own, so the sampled preview- * fills the tile with the whole picture in view. Clamped between 9:16 and 2:1- * so a custom extreme keeps the grid readable. Shared with the Transitions- * tab. */-export function useSwatchRatio(): number {- return useEditor((s) => {- const f = frameOf(s.aspect);- return Math.min(2, Math.max(9 / 16, f.w / f.h));- });-}--/** The picture a swatch treats: the given frame when there is one, and a small- * colored landscape as the stand-in, so every treatment reads at tile size.- * The stand-in comes in two casts — day (sun over green hills) and dusk (moon- * over dark ones) — so a transition tile can hand over between two scenes that- * read as different shots. Shared with the Transitions tab. */+/** The picture a swatch treats: the given frame when there is one, fit whole+ * inside the square tile, and a small colored landscape as the stand-in, so+ * every treatment reads at tile size. The stand-in comes in two casts — day+ * (sun over green hills) and dusk (moon over dark ones) — so a transition+ * tile can hand over between two scenes that read as different shots. Shared+ * with the Transitions tab. */export function SwatchScene({frame,variant = "day",@@ -294,19 +287,18 @@ export function SwatchScene({if (frame) {return (// eslint-disable-next-line @next/next/no-img-element -- a transient data URL or filmstrip thumb; the image optimizer has no role- <img src={frame} alt="" draggable={false} className="absolute inset-0 size-full object-cover" />+ <img src={frame} alt="" draggable={false} className="absolute inset-0 size-full object-contain" />);}if (variant === "dusk") {return (<><span className="absolute inset-0 bg-[linear-gradient(165deg,#2b3f77_0%,#5a4a8a_55%,#c26d4a_100%)]" />- <span className="absolute top-[14%] right-[16%] size-[22%] rounded-full bg-[#f3ead0]" />+ <span className="absolute top-[14%] right-[16%] aspect-square w-[15%] rounded-full bg-[#f3ead0]" /><svgviewBox="0 0 100 56"- preserveAspectRatio="none"aria-hidden- className="absolute inset-x-0 bottom-0 h-[62%] w-full"+ className="absolute inset-x-0 bottom-0 h-[56%] w-full"><polygon points="0,56 30,8 60,56" fill="#17293c" /><polygon points="38,56 70,22 100,52 100,56" fill="#1f3a4d" />@@ -317,12 +309,11 @@ export function SwatchScene({return (<><span className="absolute inset-0 bg-[linear-gradient(165deg,#6ea8f5_0%,#a97ee0_55%,#f0a12e_100%)]" />- <span className="absolute top-[12%] left-[14%] size-[34%] rounded-full bg-[#fdf0c2]" />+ <span className="absolute top-[12%] left-[14%] aspect-square w-[22%] rounded-full bg-[#fdf0c2]" /><svgviewBox="0 0 100 56"- preserveAspectRatio="none"aria-hidden- className="absolute inset-x-0 bottom-0 h-[62%] w-full"+ className="absolute inset-x-0 bottom-0 h-[56%] w-full"><polygon points="0,56 30,8 60,56" fill="#255c3f" /><polygon points="38,56 70,22 100,52 100,56" fill="#3a7a52" />@@ -345,7 +336,6 @@ export function EffectSwatch({frame?: string | null;className?: string;}) {- const ratio = useSwatchRatio();// The leak wanders at a pace tuned to a clip's seconds; the tile doubles its// clock so the roaming reads without a long watch.const st = effectPreviewState(id, 0.9, id === "lightleak" ? t * 2 : t);@@ -386,8 +376,8 @@ export function EffectSwatch({: [];return (<span- className={cn("relative block overflow-hidden rounded-md bg-black", className)}- style={{ aspectRatio: ratio }}+ data-drag-object+ className={cn("relative block aspect-square overflow-hidden rounded-md bg-black", className)}>{!!st.ghostFrac && (<spandiff --git a/site/src/cut/components/ElementsPanel.tsx b/site/src/cut/components/ElementsPanel.tsxindex cc3d1ac5..9c8a9e89 100644--- a/site/src/cut/components/ElementsPanel.tsx+++ b/site/src/cut/components/ElementsPanel.tsx@@ -1,8 +1,8 @@"use client";-import { Tile } from "@/cut/components/PanelTile";+import { lineLikeShape, shapePathD } from "@donkeycut/effects-kit";import { SubTabs } from "@/cut/components/SubTabs";-import { clearElementDrag, setElementDragData } from "@/cut/lib/assetDrag";+import { clearElementDrag, setElementDragData, setObjectDragImage } from "@/cut/lib/assetDrag";import { PICKED_RING, pickGridNav, useAssetPick } from "@/cut/lib/assetPick";import { useEditor } from "@/cut/lib/store";import { SHAPE_LABELS, type ShapeKind } from "@/cut/lib/types";@@ -41,7 +41,10 @@ export function ElementsPanel({ projectId }: { projectId: string }) {<SubTabs tabs={CATEGORIES} value={view} onChange={setView} /></div>- <ScrollArea className="min-h-0 flex-1" contentClassName="flex flex-col gap-4 px-3.5 pb-4">+ {/* The top pad is the selected tile's ring and its offset: the grid starts+ at the scroll edge, and a ring drawn outside a tile would be cut off+ there. */}+ <ScrollArea className="min-h-0 flex-1" contentClassName="flex flex-col gap-4 px-3.5 pt-1 pb-4">{view === "stickers" && (<>{!readOnly && <CreateSticker projectId={projectId} />}@@ -66,7 +69,7 @@ export function ElementsPanel({ projectId }: { projectId: string }) {)}{view === "shapes" && (- <div className="grid shrink-0 grid-cols-3 gap-1.5" onKeyDown={pickGridNav}>+ <div className="grid shrink-0 grid-cols-2 gap-2" onKeyDown={pickGridNav}>{SHAPE_KINDS.map((k) => (<ShapeTile key={k} shape={k} />))}@@ -77,43 +80,60 @@ export function ElementsPanel({ projectId }: { projectId: string }) {);}-/** A shape in the Shapes grid: a click picks it, a drag onto the timeline- * places it. */+/** A shape in the Shapes grid — a square swatch sized like the effect tiles+ * with its name under it. A click picks it, a drag onto the timeline places+ * it. */function ShapeTile({ shape }: { shape: ShapeKind }) {const { picked, pick } = useAssetPick(`shape:${shape}`);return (- <Tile- selected={picked}- pickId={`shape:${shape}`}- label={SHAPE_LABELS[shape]}- className={cn(picked && PICKED_RING)}- onClick={pick}+ <button+ type="button"+ data-pick-id={`shape:${shape}`}+ aria-pressed={picked}draggable- onDragStart={(e) => setElementDragData(e, { kind: "shape", shape })}+ onDragStart={(e) => {+ setElementDragData(e, { kind: "shape", shape });+ setObjectDragImage(e);+ }}onDragEnd={clearElementDrag}+ onClick={pick}+ className="flex flex-col items-center gap-1.5 text-[11px] font-medium text-muted-foreground outline-none transition-colors hover:text-foreground">- <ShapeSwatch shape={shape} className="size-7" />- </Tile>+ <span+ className={cn(+ "flex aspect-video w-full items-center justify-center rounded-lg border border-border",+ picked && PICKED_RING+ )}+ >+ <ShapeSwatch shape={shape} className="size-16" />+ </span>+ <span className="leading-none">{SHAPE_LABELS[shape]}</span>+ </button>);}-/** A shape's silhouette, drawn the way the painter lays it out. */+/** A shape's silhouette, drawn the way the painter lays it out; lines and+ * arrows sit diagonally, pointing up and to the right. */function ShapeSwatch({ shape, className }: { shape: ShapeKind; className?: string }) {return (<svgviewBox="0 0 24 24"fill="currentColor"aria-hidden- className={cn("text-foreground", className)}+ data-drag-object+ className={cn("text-foreground/70", className)}>{shape === "rect" && <rect x="3" y="6" width="18" height="12" rx="2" />}{shape === "ellipse" && <ellipse cx="12" cy="12" rx="9.5" ry="7" />}- {shape === "line" && <rect x="2" y="11" width="20" height="2" rx="1" />}+ {shape === "line" && <rect x="2" y="11" width="20" height="2" rx="1" transform="rotate(-45 12 12)" />}{shape === "arrow" && (- <>+ <g transform="rotate(-45 12 12)"><rect x="2" y="11" width="14" height="2" rx="1" /><polygon points="22,12 14,7.5 14,16.5" />- </>+ </g>+ )}+ {!lineLikeShape(shape) && shape !== "rect" && shape !== "ellipse" && (+ <path d={shapePathD(shape, 18, 18)} transform="translate(3 3)" />)}</svg>);diff --git a/site/src/cut/components/TransitionsPanel.tsx b/site/src/cut/components/TransitionsPanel.tsxindex e4c6b546..07da4d87 100644--- a/site/src/cut/components/TransitionsPanel.tsx+++ b/site/src/cut/components/TransitionsPanel.tsx@@ -1,9 +1,9 @@"use client";import { useEffect, useMemo, useRef, useState } from "react";-import { SwatchScene, useSwatchClock, useSwatchRatio } from "@/cut/components/EffectsPanel";+import { SwatchScene, useSwatchClock } from "@/cut/components/EffectsPanel";import { SectionTitle } from "@/cut/components/SectionTitle";-import { clearElementDrag, setElementDragData } from "@/cut/lib/assetDrag";+import { clearElementDrag, setElementDragData, setObjectDragImage } from "@/cut/lib/assetDrag";import { peekEdgeFrame, requestEdgeFrame } from "@/cut/lib/media";import { PICKED_RING, pickGridNav, useAssetPick } from "@/cut/lib/assetPick";import { getClipSpans, resolveTransitions, useEditor } from "@/cut/lib/store";@@ -187,7 +187,10 @@ function TransitionTile({data-pick-id={`transition:${style}`}aria-pressed={marked}draggable- onDragStart={(e) => setElementDragData(e, { kind: "transition", style })}+ onDragStart={(e) => {+ setElementDragData(e, { kind: "transition", style });+ setObjectDragImage(e);+ }}onDragEnd={clearElementDrag}onPointerEnter={() => setRunEpoch((n) => n + 1)}onFocus={() => setRunEpoch((n) => n + 1)}@@ -247,7 +250,6 @@ function TransitionSwatch({t: number;className?: string;}) {- const ratio = useSwatchRatio();const p0 = Math.min(1, Math.max(0, (t - X_HOLD) / X_RUN));const p = p0 * p0 * (3 - 2 * p0);const pc = (n: number) => `${(n * 100).toFixed(1)}%`;@@ -393,8 +395,8 @@ function TransitionSwatch({}return (<span- className={cn("relative block overflow-hidden rounded-md bg-black", className)}- style={{ aspectRatio: ratio }}+ data-drag-object+ className={cn("relative block aspect-square overflow-hidden rounded-md bg-black", className)}>{layers}</span>