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": "window-trail",
"title": "Window Trail",
"description": "An orange window sweeps over 'Old look.' and leaves 'New look, same product.' behind it.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"files": [
{
"path": "registry/remocn/window-trail/index.tsx",
"content": "\"use client\";\n\nimport { loadFont as loadFamiljen } from \"@remotion/google-fonts/FamiljenGrotesk\";\nimport type React from \"react\";\nimport { useEffect, useId, useRef, useState } from \"react\";\nimport {\n AbsoluteFill,\n continueRender,\n delayRender,\n Easing,\n interpolate,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\n\nconst familjen = loadFamiljen(\"normal\", {\n weights: [\"400\", \"500\"],\n subsets: [\"latin\"],\n});\n\nexport interface WindowTrailProps {\n from?: string;\n text?: string;\n tagline?: string;\n accent?: string;\n background?: string;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst ORANGE = \"#FF4F00\";\n\nconst THEMES = {\n dark: { field: \"#1E1E1E\", ink: \"#FFE7D6\", inkOnAccent: \"#1E1E1E\" },\n light: { field: \"#FFE7D6\", ink: \"#1E1E1E\", inkOnAccent: \"#1E1E1E\" },\n} as const;\n\nconst TRACK = -0.03;\nconst OUT_AT = 8;\nconst OUT_LEN = 18;\nconst IN_AT = 28;\nconst IN_LEN = 30;\nconst TAIL = 4;\nconst RETRACT = 2;\nconst GAP = 1.12;\nconst TAG_DELAY = 6;\n\nconst EASE_DRAG = Easing.bezier(0.2, 0.85, 0.25, 1);\nconst EASE_THROW = Easing.bezier(0.55, 0, 0.85, 0.35);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ninterface TrailState {\n front: number;\n stamps: { y: number; id: number }[];\n}\n\nfunction trail(\n f: number,\n len: number,\n ease: (u: number) => number,\n y0: number,\n y1: number,\n gap: number,\n rest: number | null,\n): TrailState {\n const pos = (g: number) =>\n y0 + (y1 - y0) * ease(Math.max(0, Math.min(1, g / len)));\n const front = pos(f);\n const all: { y: number; id: number }[] = [];\n let last: number | null = null;\n for (let g = 0; g <= Math.min(f, len); g += 0.25) {\n const q = pos(g);\n if (rest !== null && Math.abs(q - rest) < gap) continue;\n if (last === null || Math.abs(q - last) >= gap) {\n all.push({ y: q, id: all.length });\n last = q;\n }\n }\n const clear = all.filter((s) => Math.abs(s.y - front) >= gap);\n const retract = f > len ? Math.floor((f - len) / RETRACT) + 1 : 0;\n const keep = Math.max(0, Math.min(clear.length, TAIL) - retract);\n return { front, stamps: clear.slice(clear.length - keep) };\n}\n\ninterface Metrics {\n from: number;\n text: number;\n tag: number;\n}\n\nfunction measure(from: string, text: string, tag: string): Metrics {\n const canvas = document.createElement(\"canvas\");\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) throw new Error(\"window-trail: no 2d context\");\n const fam = `\"${familjen.fontFamily}\"`;\n ctx.font = `500 100px ${fam}`;\n const w = (s: string) =>\n s ? ctx.measureText(s).width / 100 + TRACK * Array.from(s).length : 0;\n const textW = w(text);\n const fromW = w(from);\n ctx.font = `400 100px ${fam}`;\n const tagW = tag ? ctx.measureText(tag).width / 100 : 0;\n return { from: fromW, text: textW, tag: tagW };\n}\n\nfunction useMetrics(from: string, text: string, tag: string) {\n const key = `${from}\\u0001${text}\\u0001${tag}`;\n const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n const [handle] = useState(() => delayRender(\"window-trail: measuring\"));\n const released = useRef(false);\n useEffect(() => {\n let live = true;\n const [a, b, d] = key.split(\"\\u0001\");\n Promise.all([\n familjen.waitUntilDone(),\n document.fonts.load(`500 100px \"${familjen.fontFamily}\"`),\n document.fonts.load(`400 100px \"${familjen.fontFamily}\"`),\n ])\n .catch(() => undefined)\n .then(() => {\n if (!live) return;\n setState({ key, m: measure(a, b, d) });\n if (!released.current) {\n released.current = true;\n continueRender(handle);\n }\n });\n return () => {\n live = false;\n };\n }, [key, handle]);\n return state && state.key === key ? state.m : null;\n}\n\nfunction mix(a: string, b: string, k: number) {\n const pct = Math.round(Math.max(0, Math.min(1, 1 - k)) * 100);\n return `color-mix(in srgb, ${a} ${pct}%, ${b})`;\n}\n\nexport function WindowTrail({\n from = \"Old look.\",\n text = \"New look, same product.\",\n tagline = \"Repainted in one render.\",\n accent,\n background,\n speed = 1,\n theme = \"dark\",\n}: WindowTrailProps) {\n const t = useCurrentFrame() * speed;\n const { width: W, height: H } = useVideoConfig();\n const c = THEMES[theme];\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n const m = useMetrics(from, text, tagline);\n\n const transparent = background === \"transparent\";\n const hot = accent ?? ORANGE;\n const fieldA = transparent ? c.field : (background ?? c.field);\n\n if (!m) {\n return (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: transparent ? \"transparent\" : fieldA,\n }}\n />\n );\n }\n\n const portrait = H > W * 1.1;\n const s = portrait ? W / 1080 : Math.min(W / 1280, H / 720);\n const marginX = W * (portrait ? 0.08 : 0.065);\n const measureW = W - marginX * 2;\n\n const fit = (w: number) =>\n Math.min(measureW / Math.max(w, 0.01), H * (portrait ? 0.09 : 0.2));\n const F = fit(m.text);\n const F0 = m.from ? fit(m.from) : F;\n const splitY = H * (portrait ? 0.54 : 0.5);\n const baseY = splitY;\n const baseY0 = splitY;\n\n const hasFrom = from.length > 0;\n const inAt = hasFrom ? IN_AT : 0;\n const tagAt = inAt + IN_LEN + TAG_DELAY;\n\n const inTrail = trail(\n t - inAt,\n IN_LEN,\n EASE_DRAG,\n H + F * 0.4,\n baseY,\n F * GAP,\n baseY,\n );\n const outTrail = hasFrom\n ? trail(t - OUT_AT, OUT_LEN, EASE_THROW, baseY0, -F0 * 0.4, F0 * GAP, null)\n : null;\n\n const paints = [\n {\n key: \"a\",\n y: 0,\n h: splitY,\n ink: c.ink,\n stamp: (rank: number) => mix(hot, fieldA, 0.12 + rank * 0.2),\n },\n {\n key: \"b\",\n y: splitY,\n h: H - splitY,\n ink: transparent ? c.ink : c.inkOnAccent,\n stamp: (rank: number) =>\n transparent\n ? mix(hot, fieldA, 0.12 + rank * 0.2)\n : mix(c.inkOnAccent, hot, 0.3 + rank * 0.16),\n },\n ];\n\n const textProps = (size: number) => ({\n fontFamily: familjen.fontFamily,\n fontWeight: 500,\n fontSize: size,\n letterSpacing: `${TRACK}em`,\n });\n\n const layer = (\n tr: TrailState,\n str: string,\n size: number,\n key: string,\n showFront: boolean,\n p: (typeof paints)[number],\n ) => (\n <g key={key}>\n {tr.stamps.map((q, j) => (\n <text\n key={`${key}${q.id}`}\n {...textProps(size)}\n x={marginX}\n y={q.y}\n style={{ fill: p.stamp(tr.stamps.length - 1 - j) }}\n >\n {str}\n </text>\n ))}\n {showFront ? (\n <text {...textProps(size)} x={marginX} y={tr.front} fill={p.ink}>\n {str}\n </text>\n ) : null}\n </g>\n );\n\n const tagFs = (portrait ? 42 : 34) * s;\n const tagWords = tagline ? tagline.split(\" \") : [];\n const tagTop = baseY + F * 0.62;\n const tagW = Math.min(measureW, m.tag * tagFs * 1.04);\n\n const nodes: React.ReactNode[] = paints.map((p) => (\n <g key={p.key} clipPath={`url(#${uid}${p.key})`}>\n {outTrail\n ? layer(outTrail, from, F0, `o${p.key}`, t < OUT_AT + OUT_LEN, p)\n : null}\n {t >= inAt ? layer(inTrail, text, F, `i${p.key}`, true, p) : null}\n </g>\n ));\n\n return (\n <AbsoluteFill\n style={{\n background: transparent ? \"transparent\" : fieldA,\n overflow: \"hidden\",\n }}\n >\n {transparent ? null : (\n <div\n style={{\n position: \"absolute\",\n left: 0,\n top: splitY,\n width: W,\n height: H - splitY,\n background: hot,\n }}\n />\n )}\n <svg\n width={W}\n height={H}\n style={{ position: \"absolute\", inset: 0 }}\n aria-hidden\n >\n <defs>\n {paints.map((p) => (\n <clipPath key={p.key} id={`${uid}${p.key}`}>\n <rect x={0} y={p.y} width={W} height={p.h} />\n </clipPath>\n ))}\n </defs>\n {nodes}\n </svg>\n\n {tagline ? (\n <div\n style={{\n position: \"absolute\",\n left: marginX,\n width: tagW,\n top: tagTop,\n fontFamily: familjen.fontFamily,\n fontWeight: 400,\n fontSize: tagFs,\n lineHeight: 1.25,\n letterSpacing: \"-0.005em\",\n color: paints[1].ink,\n whiteSpace: \"nowrap\",\n }}\n >\n {tagWords.map((w, k) => {\n const q = interpolate(\n t,\n [tagAt + k * 2, tagAt + k * 2 + 16],\n [0, 1],\n { ...CLAMP, easing: EASE_OUT },\n );\n return (\n <span\n key={`${w}-${k}`}\n style={{\n display: \"inline-block\",\n marginRight: k < tagWords.length - 1 ? \"0.26em\" : 0,\n opacity: q,\n transform: `translateY(${((1 - q) * tagFs * 0.7).toFixed(2)}px)`,\n }}\n >\n {w}\n </span>\n );\n })}\n </div>\n ) : null}\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/window-trail.tsx"
}
],
"type": "registry:component"
}