Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
"name": "photo-caret",
"title": "Photo Caret",
"description": "A three-line headline types out with a caret while product photos float around it.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/photo-caret/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadFigtree } from \"@remotion/google-fonts/Figtree\";\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n Img,\n interpolate,\n spring,\n staticFile,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround, gshParams } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst figtree = loadFigtree(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\nconst serif = loadSerif(\"italic\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport interface PhotoCaretProps {\n text?: string;\n accentWord?: string;\n src?: string;\n images?: string[];\n accent?: string;\n ink?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n firstStep?: number;\n}\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n kind: \"mist\",\n background: \"#ecebe8\",\n colors: [\"#ffffff\", \"#f7f6f3\", \"#dcdcdf\", \"#c4c6cf\"],\n blur: 0.8,\n warp: 0.3,\n seed: 4,\n grain: 0.16,\n};\n\nconst THEMES = {\n dark: {\n ink: \"#f4f2ee\",\n accent: \"#a3b2ff\",\n ground: \"riptide\" as GshPresetId | undefined,\n groundParams: undefined as Partial<GradientParams> | undefined,\n groundOffset: 5,\n scrim: \"4,5,12\",\n scrimAlpha: 0.55,\n border: \"rgba(255,255,255,0.16)\",\n shadow:\n \"0 1px 2px rgba(1,2,8,0.45), 0 10px 24px rgba(1,2,8,0.45), 0 36px 72px rgba(1,2,8,0.5)\",\n },\n light: {\n ink: \"#151515\",\n accent: \"#3B5BFD\",\n ground: undefined as GshPresetId | undefined,\n groundParams: LIGHT_GROUND as Partial<GradientParams> | undefined,\n groundOffset: 2,\n scrim: \"240,239,236\",\n scrimAlpha: 0.5,\n border: \"rgba(20,20,24,0.08)\",\n shadow:\n \"0 1px 2px rgba(30,30,40,0.12), 0 8px 20px rgba(30,30,40,0.12), 0 28px 56px rgba(30,30,40,0.14)\",\n },\n};\n\nconst DEFAULT_IMAGES = [\n \"templates/brand-guidelines/chair.jpg\",\n \"templates/product-showcase/sculpture.jpg\",\n \"templates/launch-anything/desk.jpg\",\n \"templates/brand-guidelines/materials.jpg\",\n \"templates/product-showcase/courtyard.jpg\",\n \"templates/product-showcase/gallery.jpg\",\n \"reel/reel-4.jpg\",\n];\n\nconst BEAT = {\n intro: 12,\n decay: 0.88,\n minStep: 6,\n breath: 9,\n reveal: 8,\n settle: 12,\n hold: 45,\n};\n\nconst FONT_PX = 200;\nconst TRACK = -0.03;\nconst SERIF_SCALE = 1.14;\nconst LH = 1.08;\nconst TILE_H = 1.15;\nconst TILE_W = 0.86;\nconst STAGGER = [0.62, 0, 1];\nconst TYPE_IN = Easing.bezier(0.32, 0.72, 0, 1);\nconst PUSH = Easing.bezier(0.87, 0, 0.13, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\nconst CAMERA = { mass: 1, damping: 26, stiffness: 120 };\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst CHIP = { mass: 0.5, damping: 12, stiffness: 200 };\n\ninterface Metrics {\n width: (s: string, accent: boolean) => number;\n cap: number;\n}\n\nfunction buildMetrics(_version: number): Metrics {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n const sansFont = `400 ${FONT_PX}px \"${figtree.fontFamily}\"`;\n const serifFont = `italic 400 ${FONT_PX * SERIF_SCALE}px \"${serif.fontFamily}\"`;\n const cache: Record<string, number> = {};\n let cap = 0.7;\n if (ctx) {\n ctx.font = sansFont;\n const box = ctx.measureText(\"H\").actualBoundingBoxAscent / FONT_PX;\n if (box > 0.3) cap = box;\n }\n return {\n width: (s: string, accent: boolean) => {\n const k = `${accent ? 1 : 0}${s}`;\n if (cache[k] === undefined) {\n if (!ctx) return s.length * 0.52;\n ctx.font = accent ? serifFont : sansFont;\n const track = accent ? 0 : TRACK * Array.from(s).length;\n cache[k] = ctx.measureText(s).width / FONT_PX + track;\n }\n return cache[k];\n },\n cap,\n };\n}\n\nfunction useMetrics() {\n const [version, setVersion] = useState(0);\n const [handle] = useState(() => delayRender(\"photo-caret: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n const bump = () => {\n if (live) setVersion((v) => v + 1);\n };\n document.fonts.addEventListener(\"loadingdone\", bump);\n Promise.all([\n figtree.waitUntilDone(),\n serif.waitUntilDone(),\n document.fonts.load(`400 ${FONT_PX}px \"${figtree.fontFamily}\"`),\n document.fonts.load(`italic 400 ${FONT_PX}px \"${serif.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n bump();\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n document.fonts.removeEventListener(\"loadingdone\", bump);\n };\n }, [handle]);\n return useMemo(() => buildMetrics(version), [version]);\n}\n\nconst parseLines = (text: string) =>\n text\n .split(\"/\")\n .map((l) => l.trim().split(/\\s+/).filter(Boolean))\n .filter((l) => l.length > 0);\n\nconst hopTimes = (count: number, firstStep: number) => {\n const out: number[] = [];\n let t = BEAT.intro;\n for (let k = 0; k < count; k++) {\n if (k === count - 1) t += BEAT.breath;\n out.push(t);\n const g = Math.max(\n BEAT.minStep,\n Math.round((firstStep * BEAT.decay ** k) / 3) * 3,\n );\n t += g;\n }\n return out;\n};\n\nexport const photoCaretLength = (\n text = \"Your launch, / your name / on it.\",\n firstStep = 12,\n) => {\n const n = parseLines(text).flat().length;\n const hops = hopTimes(n, firstStep);\n return hops[hops.length - 1] + BEAT.settle + BEAT.hold;\n};\n\ntype Sat = { x: number; y: number; s: number; far: boolean; r: number };\n\nconst SATS_WIDE: Sat[] = [\n { x: 0.065, y: 0.22, s: 0.17, far: false, r: -3 },\n { x: 0.27, y: 0.87, s: 0.16, far: false, r: 2 },\n { x: 0.92, y: 0.64, s: 0.2, far: false, r: 3 },\n { x: 0.42, y: 0.06, s: 0.17, far: true, r: 0 },\n { x: 0.74, y: 0.95, s: 0.18, far: true, r: 0 },\n { x: 0.04, y: 0.66, s: 0.2, far: true, r: 0 },\n { x: 0.96, y: 0.18, s: 0.18, far: true, r: 0 },\n];\n\nconst SATS_TALL: Sat[] = [\n { x: 0.2, y: 0.17, s: 0.15, far: false, r: -3 },\n { x: 0.78, y: 0.8, s: 0.17, far: false, r: 3 },\n { x: 0.24, y: 0.86, s: 0.12, far: false, r: 2 },\n { x: 0.66, y: 0.08, s: 0.12, far: true, r: 0 },\n { x: 0.92, y: 0.26, s: 0.12, far: true, r: 0 },\n { x: 0.06, y: 0.7, s: 0.12, far: true, r: 0 },\n { x: 0.56, y: 0.95, s: 0.11, far: true, r: 0 },\n];\n\nexport function PhotoCaret({\n text = \"Your launch, / your name / on it.\",\n accentWord = \"it.\",\n src,\n images,\n accent,\n ink,\n theme = \"dark\",\n ground,\n groundParams,\n firstStep = 12,\n}: PhotoCaretProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, fps } = useVideoConfig();\n const c = THEMES[theme];\n const inkC = ink ?? c.ink;\n const hi = accent ?? c.accent;\n const preset = ground ?? (groundParams ? undefined : c.ground);\n const gParams = groundParams ?? (ground ? undefined : c.groundParams);\n const bg = gshParams(preset, gParams).background;\n const portrait = H > W * 1.1;\n const m = useMetrics();\n const tileSrc = src ?? staticFile(\"templates/brand-guidelines/ceramics.jpg\");\n const satSrc = (images ?? DEFAULT_IMAGES.map((p) => staticFile(p))).filter(\n Boolean,\n );\n\n const lines = useMemo(() => parseLines(text), [text]);\n\n const layout = useMemo(() => {\n const space = m.width(\" \", false) + 0.02;\n const rows = lines.map((ws) => {\n const widths = ws.map((w) => m.width(w, w === accentWord));\n const total = widths.reduce((a, b) => a + b, 0) + space * (ws.length - 1);\n return { ws, widths, total };\n });\n const maxW = Math.max(...rows.map((r) => r.total));\n const parkGap = 0.24;\n const spanW = portrait ? maxW : maxW + parkGap + TILE_W;\n const spanH = rows.length * LH + (portrait ? TILE_H + 0.5 : 0.3);\n const F = portrait\n ? Math.min((W * 0.84) / spanW, (H * 0.42) / spanH)\n : Math.min((W * 0.7) / spanW, (H * 0.68) / spanH);\n const cap = m.cap * F;\n const words: {\n text: string;\n accent: boolean;\n x: number;\n w: number;\n base: number;\n line: number;\n }[] = [];\n rows.forEach((r, li) => {\n const ox = (maxW - r.total) * STAGGER[li % STAGGER.length] * F;\n let x = ox;\n r.ws.forEach((w, wi) => {\n words.push({\n text: w,\n accent: w === accentWord,\n x,\n w: r.widths[wi] * F,\n base: li * LH * F,\n line: li,\n });\n x += (r.widths[wi] + space) * F;\n });\n });\n const tw = TILE_W * F;\n const th = TILE_H * F;\n const slotY = (base: number) => base - cap * 0.42 - th / 2;\n const slots = words.map((w) => ({ x: w.x, y: slotY(w.base) }));\n const park = portrait\n ? { x: maxW * F - tw, y: -cap - 0.34 * F - th }\n : { x: maxW * F + parkGap * F, y: slotY(0) - cap * 0.35 };\n slots.push(park);\n const minY = Math.min(park.y, -cap - 0.04 * F);\n const maxY = (rows.length - 1) * LH * F + 0.06 * F;\n const right = Math.max(maxW * F, park.x + tw);\n const cx = right / 2;\n const cy = (minY + maxY) / 2;\n return {\n F,\n cap,\n tw,\n th,\n cx,\n cy,\n words,\n slots,\n bbox: { x0: 0, x1: right, y0: minY, y1: maxY },\n };\n }, [m, lines, accentWord, portrait, W, H]);\n\n const { F, cap, tw, th, words, slots } = layout;\n const n = words.length;\n const hops = useMemo(() => hopTimes(n, firstStep), [n, firstStep]);\n const payoff = hops[n - 1];\n\n const states = useMemo(() => {\n const out: { cx: number; cy: number; s: number }[] = [];\n for (let k = 0; k <= n; k++) {\n let x0 = slots[k].x;\n let x1 = slots[k].x + tw;\n let y0 = slots[k].y;\n let y1 = slots[k].y + th;\n for (let i = 0; i < k; i++) {\n x0 = Math.min(x0, words[i].x);\n x1 = Math.max(x1, words[i].x + words[i].w);\n y0 = Math.min(y0, words[i].base - cap);\n y1 = Math.max(y1, words[i].base + 0.1 * F);\n }\n const bw = x1 - x0;\n const bh = y1 - y0;\n const fit = Math.min(\n (W * (portrait ? 0.84 : 0.7)) / bw,\n (H * (portrait ? 0.42 : 0.68)) / bh,\n );\n const s = k === n ? 1 : Math.min(portrait ? 1.08 : 1.2, Math.max(1, fit));\n const w = k === n ? 1 : 0.85;\n out.push({\n cx: layout.cx + ((x0 + x1) / 2 - layout.cx) * w,\n cy: layout.cy + ((y0 + y1) / 2 - layout.cy) * w,\n s,\n });\n }\n return out;\n }, [n, slots, tw, th, words, cap, F, W, H, portrait, layout]);\n\n const camAt = (t: number) => {\n let cx = states[0].cx;\n let cy = states[0].cy;\n let ls = Math.log(states[0].s);\n for (let k = 0; k < n; k++) {\n const p = spring({\n frame: t - hops[k],\n fps,\n config: CAMERA,\n });\n cx += (states[k + 1].cx - states[k].cx) * p;\n cy += (states[k + 1].cy - states[k].cy) * p;\n ls += (Math.log(states[k + 1].s) - Math.log(states[k].s)) * p;\n }\n return { cx, cy, s: Math.exp(ls) };\n };\n const cam = camAt(frame);\n const push =\n 1 +\n 0.03 *\n interpolate(\n frame,\n [payoff + BEAT.settle, payoff + BEAT.settle + BEAT.hold - 12],\n [0, 1],\n { ...CLAMP, easing: PUSH },\n );\n const scale = cam.s * push;\n const ox = W / 2 - cam.cx * scale;\n const oy = H / 2 - cam.cy * scale;\n const toX = (x: number) => ox + x * scale;\n const toY = (y: number) => oy + y * scale;\n\n let tx = slots[0].x;\n let ty = slots[0].y;\n let squash = 0;\n let lead = 0;\n for (let k = 0; k < n; k++) {\n const f = frame - hops[k];\n if (f < 0) break;\n const p = spring({ frame: f, fps, config: CARD });\n const a = slots[k];\n const b = slots[k + 1];\n const sameLine = k < n - 1 && words[k].line === words[k + 1].line;\n const lift = sameLine ? 0.16 * F : 0.06 * F;\n tx = a.x + (b.x - a.x) * p;\n ty = a.y + (b.y - a.y) * p - lift * Math.sin(Math.PI * Math.min(1, p));\n const pPrev = spring({ frame: f - 1, fps, config: CARD });\n lead = Math.max(\n lead,\n Math.abs(p - pPrev) * Math.hypot(b.x - a.x, b.y - a.y),\n );\n squash = interpolate(f, [0, 3, 9], [0, 1, 0], CLAMP);\n }\n\n const intro = spring({ frame, fps, config: CAMERA, durationInFrames: 16 });\n const bigH = H * (portrait ? 0.36 : 0.56);\n const bigW = bigH * 0.78;\n const bigX = W / 2 - bigW / 2;\n const bigY = H / 2 - bigH / 2;\n const sx = toX(tx);\n const sy = toY(ty);\n const sw = tw * scale;\n const sh = th * scale;\n const tileW = bigW + (sw - bigW) * intro;\n const tileH = bigH + (sh - bigH) * intro;\n const tileX = bigX + (sx - bigX) * intro;\n const tileY = bigY + (sy - bigY) * intro;\n const introBlur = Math.abs(\n intro -\n spring({ frame: frame - 1, fps, config: CAMERA, durationInFrames: 16 }),\n );\n const moveBlur = Math.min(8, lead * scale * 0.09 + introBlur * 40);\n const tileScale = 1 + 0.04 * squash;\n\n const hopProgressRight = tx + tw;\n const accentHit = interpolate(frame, [payoff, payoff + 10], [0, 1], {\n ...CLAMP,\n easing: TYPE_IN,\n });\n\n const sats = portrait ? SATS_TALL : SATS_WIDE;\n const satStart = (i: number, far: boolean) => {\n if (far) return i * 4 - 2;\n return payoff + 2 + i * 3;\n };\n\n const renderWord = (w: (typeof words)[number], i: number) => {\n const start = hops[i];\n const f = frame - start;\n if (f < 0) return null;\n const timeP = interpolate(f, [0, BEAT.reveal], [0, 1], {\n ...CLAMP,\n easing: TYPE_IN,\n });\n const sweep = i < n - 1 ? hopProgressRight - w.x : 0;\n const reveal = Math.min(w.w + 0.2 * F, Math.max(sweep, w.w * timeP * 1.04));\n const rise = (1 - timeP) * 0.06 * F;\n const blur = (1 - timeP) * 5;\n const color = w.accent\n ? accentHit >= 1\n ? hi\n : `color-mix(in oklab, ${hi} ${accentHit * 100}%, ${inkC})`\n : inkC;\n const clipId = `pc-clip-${i}`;\n const filtId = `pc-blur-${i}`;\n return (\n <g key={`${w.text}-${i}`}>\n <defs>\n <clipPath id={clipId}>\n <rect\n x={w.x - 0.1 * F}\n y={w.base - 1.3 * F}\n width={reveal + 0.1 * F}\n height={1.7 * F}\n />\n </clipPath>\n {blur > 0.1 ? (\n <filter id={filtId} x=\"-20%\" y=\"-50%\" width=\"140%\" height=\"200%\">\n <feGaussianBlur stdDeviation={`${blur / scale} 0`} />\n </filter>\n ) : null}\n </defs>\n <g clipPath={`url(#${clipId})`}>\n <text\n x={w.x}\n y={w.base + rise}\n fill={color}\n filter={blur > 0.1 ? `url(#${filtId})` : undefined}\n fontFamily={w.accent ? serif.fontFamily : figtree.fontFamily}\n fontStyle={w.accent ? \"italic\" : \"normal\"}\n fontWeight={400}\n fontSize={w.accent ? F * SERIF_SCALE : F}\n letterSpacing={w.accent ? \"0em\" : `${TRACK}em`}\n opacity={interpolate(f, [0, 4], [0, 1], CLAMP)}\n style={{ fontKerning: \"normal\" }}\n >\n {w.text}\n </text>\n </g>\n </g>\n );\n };\n\n const renderSat = (st: Sat, i: number, layer: \"far\" | \"near\") => {\n if ((layer === \"far\") !== st.far) return null;\n const img = satSrc[(i + 1) % Math.max(1, satSrc.length)];\n if (!img) return null;\n const start = satStart(\n sats.filter((q) => q.far === st.far).indexOf(st),\n st.far,\n );\n const p = spring({ frame: frame - start, fps, config: CHIP });\n if (frame < start) return null;\n const size = Math.min(W, H) * st.s * (portrait ? 1.6 : 1);\n const wv = size * 0.8;\n const hv = size;\n const par = (push - 1) * (st.far ? -0.6 : 1.4);\n const x = W * st.x + (W * st.x - W / 2) * par;\n const y = H * st.y + (H * st.y - H / 2) * par;\n const dy = (1 - Math.min(1, p)) * size * 0.25;\n return (\n <div\n key={`sat-${i}`}\n style={{\n position: \"absolute\",\n left: x - wv / 2,\n top: y - hv / 2 + dy,\n width: wv,\n height: hv,\n borderRadius: wv * 0.06,\n overflow: \"hidden\",\n transform: `scale(${0.4 + 0.6 * p}) rotate(${st.r}deg)`,\n opacity: interpolate(p, [0, 0.35], [0, st.far ? 0.5 : 1], CLAMP),\n filter: st.far ? `blur(${6 * (Math.min(W, H) / 720)}px)` : undefined,\n boxShadow: st.far ? undefined : c.shadow,\n border: `1px solid ${c.border}`,\n }}\n >\n <Img\n src={img}\n style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\n />\n </div>\n );\n };\n\n return (\n <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n <GshGround\n preset={preset}\n params={gParams}\n timeOffset={c.groundOffset}\n timeScale={0.5}\n />\n <AbsoluteFill\n style={{\n background: `radial-gradient(${portrait ? \"90% 46%\" : \"62% 70%\"} at 50% 50%, rgba(${c.scrim},${c.scrimAlpha}) 0%, rgba(${c.scrim},0) 100%)`,\n }}\n />\n {sats.map((st, i) => renderSat(st, i, \"far\"))}\n <svg\n width={W}\n height={H}\n viewBox={`0 0 ${W} ${H}`}\n style={{ position: \"absolute\", inset: 0, overflow: \"visible\" }}\n aria-hidden\n >\n <g transform={`translate(${ox} ${oy}) scale(${scale})`}>\n {words.map((w, i) => renderWord(w, i))}\n </g>\n </svg>\n {sats.map((st, i) => renderSat(st, i, \"near\"))}\n <div\n style={{\n position: \"absolute\",\n left: tileX,\n top: tileY,\n width: tileW,\n height: tileH,\n borderRadius: Math.max(6, tileW * 0.07),\n overflow: \"hidden\",\n boxShadow: c.shadow,\n border: `1px solid ${c.border}`,\n transform: `scale(${tileScale})`,\n filter: moveBlur > 0.3 ? `blur(${moveBlur * 0.35}px)` : undefined,\n }}\n >\n <Img\n src={tileSrc}\n style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\n />\n </div>\n </AbsoluteFill>\n );\n}\n\nexport default PhotoCaret;\n",
"type": "registry:component",
"target": "components/remocn/photo-caret.tsx"
}
],
"type": "registry:component"
}