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": "word-gap-media",
"title": "Word Gap Media",
"description": "A video tile slots into the gap between \"Launch all\" and \"of this\".",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/word-gap-media/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/InstrumentSans\";\nimport {\n type CSSProperties,\n useEffect,\n useMemo,\n useRef,\n useState,\n} 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 sans = loadFont(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\n\nexport interface WordGapMediaProps {\n before?: string;\n after?: string;\n images?: string[];\n aspects?: number[];\n captions?: string[];\n accent?: string;\n ink?: string;\n background?: string;\n theme?: \"dark\" | \"light\";\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n}\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n kind: \"smear\",\n background: \"#efe8dc\",\n colors: [\"#f6b48c\", \"#f7d39a\", \"#eab3cc\", \"#cfdccf\"],\n blur: 0.7,\n seed: 6,\n grain: 0.18,\n};\n\nconst THEMES = {\n dark: {\n ink: \"#f2f0fb\",\n accent: \"#3B5BFD\",\n ground: \"velvet-hour\" as GshPresetId | undefined,\n groundParams: undefined as Partial<GradientParams> | undefined,\n groundOffset: 6,\n scrim: \"4,4,14\",\n scrimAlpha: 0.42,\n border: \"rgba(255,255,255,0.14)\",\n highlight: \"inset 0 1px 0 rgba(255,255,255,0.18)\",\n shadow:\n \"0 1px 2px rgba(2,3,12,0.4), 0 12px 28px rgba(2,3,12,0.45), 0 48px 96px rgba(2,3,12,0.55)\",\n base: \"#141833\",\n },\n light: {\n ink: \"#1a1714\",\n accent: \"#f2552c\",\n ground: undefined as GshPresetId | undefined,\n groundParams: LIGHT_GROUND as Partial<GradientParams> | undefined,\n groundOffset: 3,\n scrim: \"244,238,228\",\n scrimAlpha: 0.5,\n border: \"rgba(40,28,16,0.10)\",\n highlight: \"inset 0 1px 0 rgba(255,255,255,0.35)\",\n shadow:\n \"0 1px 2px rgba(80,50,20,0.10), 0 10px 24px rgba(80,50,20,0.14), 0 40px 80px rgba(80,50,20,0.18)\",\n base: \"#e3dacb\",\n },\n};\n\nconst DEFAULT_IMAGES = [\n \"templates/product-showcase/sculpture.jpg\",\n \"templates/product-showcase/gallery.jpg\",\n \"templates/product-showcase/workbench.jpg\",\n \"templates/product-showcase/courtyard.jpg\",\n];\nconst DEFAULT_ASPECTS = [0.8, 1.36, 1.0, 0.86];\nconst DEFAULT_CAPTIONS = [\"Hero\", \"Gallery\", \"Detail\", \"Setting\"];\n\nconst BEAT = {\n wordStep: 3,\n enter: 12,\n open: 24,\n dwell: [36, 30, 24],\n swapLen: 12,\n settleAfter: 18,\n};\n\nconst TRACK = -0.035;\nconst FONT_PX = 200;\nconst ENTER = Easing.bezier(0.22, 1, 0.36, 1);\nconst WIPE = Easing.bezier(0.83, 0, 0.17, 1);\nconst LABEL_IN = Easing.bezier(0.32, 0.72, 0, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ntype Measure = (s: string) => number;\n\nfunction buildMeasure(_version: number): Measure {\n const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n const cache: Record<string, number> = {};\n return (s: string) => {\n if (cache[s] === undefined) {\n if (!ctx) return s.length * 0.55;\n ctx.font = `400 ${FONT_PX}px \"${sans.fontFamily}\"`;\n cache[s] =\n ctx.measureText(s).width / FONT_PX + TRACK * Array.from(s).length;\n }\n return cache[s];\n };\n}\n\nfunction useMeasure() {\n const [version, setVersion] = useState(0);\n const [handle] = useState(() => delayRender(\"word-gap-media: 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 sans.waitUntilDone(),\n document.fonts.load(`400 100px \"${sans.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(() => buildMeasure(version), [version]);\n}\n\nfunction resolveSrc(src: string) {\n return /^(https?:|data:|\\/)/.test(src) ? src : staticFile(src);\n}\n\nfunction Words({\n text,\n startAt,\n t,\n style,\n}: {\n text: string;\n startAt: number;\n t: number;\n style: CSSProperties;\n}) {\n const parts = text.split(\" \").filter(Boolean);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", ...style }}>\n {parts.map((w, i) => {\n const at = startAt + i * BEAT.wordStep - 4;\n const e = interpolate(t, [at, at + BEAT.enter], [0, 1], {\n ...CLAMP,\n easing: ENTER,\n });\n return (\n <span\n key={`${w}${i}`}\n style={{\n display: \"inline-block\",\n clipPath: \"inset(-40% -20% -0.24em -20%)\",\n marginRight: i < parts.length - 1 ? \"0.24em\" : 0,\n }}\n >\n <span\n style={{\n display: \"inline-block\",\n transform: `translateY(${((1 - e) * 0.7).toFixed(4)}em)`,\n opacity: e,\n filter:\n e < 1 ? `blur(${((1 - e) * 6).toFixed(2)}px)` : undefined,\n }}\n >\n {w}\n </span>\n </span>\n );\n })}\n </div>\n );\n}\n\nexport function WordGapMedia({\n before = \"Launch all\",\n after = \"of this\",\n images = DEFAULT_IMAGES,\n aspects = DEFAULT_ASPECTS,\n captions = DEFAULT_CAPTIONS,\n accent,\n ink,\n background,\n theme = \"dark\",\n ground,\n groundParams,\n}: WordGapMediaProps) {\n const frame = useCurrentFrame();\n const { width: W, height: H, fps, durationInFrames } = 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 = background ?? gshParams(preset, gParams).background;\n const m = useMeasure();\n const t = frame;\n const portrait = H > W * 1.1;\n\n const list = (images.length > 0 ? images : DEFAULT_IMAGES).slice(0, 4);\n const n = list.length;\n const aspectOf = (i: number) => aspects[i % Math.max(1, aspects.length)] ?? 1;\n const swapAt: number[] = [BEAT.open];\n for (let i = 1; i < n; i++) {\n swapAt.push(\n swapAt[i - 1] + BEAT.dwell[Math.min(i - 1, BEAT.dwell.length - 1)],\n );\n }\n const settleAt =\n n > 1 ? swapAt[n - 1] + BEAT.settleAfter : BEAT.open + BEAT.settleAfter;\n\n const open = Math.max(\n 0,\n spring({\n frame: t - BEAT.open,\n fps,\n config: { mass: 0.8, damping: 18, stiffness: 160 },\n }),\n );\n const swapP = (i: number, tt: number) =>\n i === 0\n ? 1\n : interpolate(tt, [swapAt[i], swapAt[i] + BEAT.swapLen], [0, 1], {\n ...CLAMP,\n easing: WIPE,\n });\n const morphP = (i: number, tt: number) =>\n i === 0\n ? 1\n : spring({\n frame: tt - swapAt[i],\n fps,\n config: { damping: 200 },\n durationInFrames: 16,\n });\n const aspectAt = (tt: number) => {\n let a = aspectOf(0);\n for (let i = 1; i < n; i++) a += (aspectOf(i) - a) * morphP(i, tt);\n return a;\n };\n const settle = spring({\n frame: t - settleAt,\n fps,\n config: { mass: 0.5, damping: 12, stiffness: 200 },\n });\n const punchScale = t < settleAt ? 1 : 0.965 + 0.035 * settle;\n\n let content: React.ReactNode = <div />;\n if (m) {\n const marginX = W * (portrait ? 0.08 : 0.07);\n const room = W - marginX * 2;\n const maxAspect = Math.max(...list.map((_, i) => aspectOf(i)));\n const minAspect = Math.min(...list.map((_, i) => aspectOf(i)));\n const gapEm = 0.34;\n let F: number;\n let cardBase: number;\n if (portrait) {\n F = Math.min(W * 0.14, room / Math.max(m(before), m(after), 0.1));\n cardBase = Math.min(W * 0.72, H * 0.54 * minAspect);\n } else {\n cardBase = H * 0.5;\n const textW = m(before) + m(after) + gapEm * 2;\n F = Math.min(\n H * 0.13,\n (room - cardBase * maxAspect) / Math.max(0.1, textW),\n );\n }\n\n const a = aspectAt(t);\n const aPrev = aspectAt(t - 1);\n const cardW = portrait ? cardBase : cardBase * a;\n const cardH = portrait ? cardBase / a : cardBase;\n const slotMain = (portrait ? cardH : cardW) * open;\n const slotCross =\n (portrait ? cardW : cardH) * (0.55 + 0.45 * Math.min(1, open));\n const moveSpeed = Math.abs(a - aPrev) * cardBase;\n const wordBlur = Math.min(4, moveSpeed * 0.12);\n const gap = F * Math.max(0.12, gapEm * Math.min(1.1, open));\n\n const tilt = interpolate(t, [BEAT.open, durationInFrames], [-6, 3], CLAMP);\n const tiltX = interpolate(Math.min(1, open), [0, 1], [14, 2]);\n const R = cardBase * 0.055;\n const pad = cardBase * 0.045;\n\n const imgNodes = list.map((src, i) => {\n const r = swapP(i, t);\n const out = i < n - 1 ? swapP(i + 1, t) : 0;\n if (r <= 0 || out >= 1) return null;\n const life = interpolate(t, [swapAt[i], swapAt[i] + 60], [1.12, 1.02], {\n ...CLAMP,\n easing: LABEL_IN,\n });\n const speed = i > 0 ? Math.abs(r - swapP(i, t - 1)) : 0;\n return (\n <div\n key={`img${i}`}\n style={{\n position: \"absolute\",\n inset: 0,\n clipPath:\n i === 0\n ? undefined\n : `inset(0 0 0 ${((1 - r) * 100).toFixed(2)}%)`,\n transform: `translateX(${(-out * 24).toFixed(2)}%)`,\n }}\n >\n <Img\n src={resolveSrc(src)}\n style={{\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n transform: `scale(${(life + (1 - r) * 0.12).toFixed(4)})`,\n filter: `brightness(${(1 - out * 0.45).toFixed(3)})${speed > 0.02 ? ` blur(${Math.min(5, speed * 40).toFixed(2)}px)` : \"\"}`,\n }}\n />\n </div>\n );\n });\n\n const barsIn = interpolate(t, [BEAT.open + 6, BEAT.open + 18], [0, 1], {\n ...CLAMP,\n easing: LABEL_IN,\n });\n const barH = Math.max(3, cardBase * 0.008);\n const bars = (\n <div\n style={{\n position: \"absolute\",\n left: pad,\n right: pad,\n top: pad,\n display: \"flex\",\n gap: barH * 1.6,\n opacity: barsIn,\n transform: `translateY(${((1 - barsIn) * -pad * 0.6).toFixed(2)}px)`,\n }}\n >\n {list.map((_, i) => {\n const from = swapAt[i];\n const to = i < n - 1 ? swapAt[i + 1] : settleAt;\n const fill = interpolate(t, [from, to], [0, 1], CLAMP);\n return (\n <div\n key={`bar${i}`}\n style={{\n flex: 1,\n height: barH,\n borderRadius: barH,\n background: \"rgba(255,255,255,0.32)\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n width: `${(fill * 100).toFixed(2)}%`,\n height: \"100%\",\n background: \"rgba(255,255,255,0.95)\",\n }}\n />\n </div>\n );\n })}\n </div>\n );\n\n const capFont = Math.max(H * 0.026, cardBase * 0.06);\n const capNodes = list.map((_, i) => {\n const label = captions[i % Math.max(1, captions.length)] ?? \"\";\n const inAt = i === 0 ? BEAT.open + 9 : swapAt[i] + 4;\n const e = interpolate(t, [inAt, inAt + 12], [0, 1], {\n ...CLAMP,\n easing: LABEL_IN,\n });\n const x =\n i < n - 1\n ? interpolate(t, [swapAt[i + 1], swapAt[i + 1] + 8], [0, 1], {\n ...CLAMP,\n easing: Easing.bezier(0.55, 0, 1, 0.45),\n })\n : 0;\n if (e <= 0 || x >= 1) return null;\n return (\n <div\n key={`cap${i}`}\n style={{\n position: \"absolute\",\n left: pad * 1.1,\n bottom: pad * 1.15,\n fontFamily: sans.fontFamily,\n fontWeight: 400,\n fontSize: capFont,\n lineHeight: 1,\n letterSpacing: \"-0.01em\",\n color: \"rgba(255,255,255,0.96)\",\n whiteSpace: \"pre\",\n clipPath: \"inset(-20% -10% -20% -10%)\",\n opacity: e * (1 - x),\n transform: `translateY(${((1 - e) * capFont * 0.8 - x * capFont * 0.6).toFixed(2)}px)`,\n }}\n >\n {label}\n </div>\n );\n });\n\n const btnD = Math.max(H * 0.062, cardBase * 0.14);\n const btnIn = spring({\n frame: t - (BEAT.open + 12),\n fps,\n config: { mass: 0.5, damping: 12, stiffness: 200 },\n });\n const armed = interpolate(t - settleAt, [0, 6], [0, 1], {\n ...CLAMP,\n easing: LABEL_IN,\n });\n const btnScale = btnIn * (t < settleAt ? 1 : 0.88 + 0.12 * settle);\n const borderHit = interpolate(t - settleAt, [0, 4, 20], [0, 1, 0.4], CLAMP);\n\n const card = (\n <div\n style={{\n position: \"relative\",\n width: portrait ? slotCross : slotMain,\n height: portrait ? slotMain : slotCross,\n flexShrink: 0,\n margin: portrait ? `${gap}px 0` : `0 ${gap}px`,\n transform: `perspective(${(H * 2).toFixed(0)}px) rotateY(${tilt.toFixed(2)}deg) rotateX(${tiltX.toFixed(2)}deg) scale(${punchScale.toFixed(4)})`,\n opacity: open > 0.001 ? 1 : 0,\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n borderRadius: R,\n overflow: \"hidden\",\n boxShadow: c.shadow,\n background: c.base,\n }}\n >\n {imgNodes}\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background:\n \"linear-gradient(180deg, rgba(0,0,0,0.32) 0%, rgba(0,0,0,0) 22%, rgba(0,0,0,0) 62%, rgba(0,0,0,0.42) 100%)\",\n }}\n />\n {bars}\n {capNodes}\n <div\n style={{\n position: \"absolute\",\n right: pad,\n bottom: pad * 0.8,\n width: btnD,\n height: btnD,\n borderRadius: btnD,\n background: `color-mix(in oklab, ${hi} ${(armed * 100).toFixed(1)}%, rgba(255,255,255,0.2))`,\n backdropFilter: \"blur(14px)\",\n boxShadow: `inset 0 0 0 1px rgba(255,255,255,${(0.38 - 0.2 * armed).toFixed(3)}), 0 ${(btnD * 0.16).toFixed(1)}px ${(btnD * 0.4).toFixed(1)}px rgba(0,0,0,${(0.12 + 0.18 * armed).toFixed(3)})`,\n transform: `scale(${btnScale.toFixed(4)})`,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <svg\n viewBox=\"0 0 24 24\"\n width={btnD * 0.4}\n height={btnD * 0.4}\n aria-hidden\n >\n <path\n d=\"M8.5 6.2v11.6c0 .6.6.9 1.1.6l9-5.8c.5-.3.5-.9 0-1.2l-9-5.8c-.5-.3-1.1 0-1.1.6z\"\n fill=\"#ffffff\"\n />\n </svg>\n </div>\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n borderRadius: R,\n boxShadow: `inset 0 0 0 1px ${borderHit > 0.01 ? `color-mix(in oklab, ${hi} ${(borderHit * 100).toFixed(0)}%, ${c.border})` : c.border}, ${c.highlight}`,\n }}\n />\n </div>\n </div>\n );\n\n const textStyle: CSSProperties = {\n fontFamily: sans.fontFamily,\n fontWeight: 400,\n fontSize: F,\n lineHeight: 1,\n letterSpacing: `${TRACK}em`,\n color: inkC,\n filter: wordBlur > 0.1 ? `blur(${wordBlur.toFixed(2)}px)` : undefined,\n };\n const afterStart = before.split(\" \").filter(Boolean).length * BEAT.wordStep;\n const push = interpolate(frame, [0, durationInFrames], [1, 1.035], CLAMP);\n\n content = (\n <AbsoluteFill\n style={{\n display: \"flex\",\n flexDirection: portrait ? \"column\" : \"row\",\n alignItems: \"center\",\n justifyContent: \"center\",\n transform: `scale(${push.toFixed(5)})`,\n }}\n >\n <Words text={before} startAt={0} t={t} style={textStyle} />\n {card}\n <Words text={after} startAt={afterStart} t={t} style={textStyle} />\n </AbsoluteFill>\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.6}\n />\n <AbsoluteFill\n style={{\n background: `radial-gradient(${portrait ? \"80% 50%\" : \"62% 56%\"} at 50% 50%, rgba(${c.scrim},${c.scrimAlpha}) 0%, rgba(${c.scrim},0) 100%)`,\n }}\n />\n {content}\n </AbsoluteFill>\n );\n}\n\nexport default WordGapMedia;\n",
"type": "registry:component",
"target": "components/remocn/word-gap-media.tsx"
}
],
"type": "registry:component"
}