Production-ready animations, transitions, backgrounds, and scenes for Remotion
TypeScript ai-agentsclaude-codedemo-videomcpmcp-servermodel-context-protocolmotion-designproduct-demoreactremotionshadcnvideo
{
"type": "remotion-element",
"version": 1,
"element": {
"assets": [],
"dependencies": [
{
"name": "@remotion/google-fonts",
"version": null
}
],
"dimensions": null,
"displayName": "Wrapped Squash",
"initialProps": null,
"slug": "wrapped-squash",
"sourceCode": "import { loadFont } from \"@remotion/google-fonts/BricolageGrotesque\";\nimport { forwardRef, useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst { fontFamily: display } = loadFont(\"normal\", {\n weights: [\"500\"],\n subsets: [\"latin\"],\n});\n\ninterface WrappedSquashProps {\n /** Two or three short lines. Set in caps; each line fills its own block. */\n lines?: string[];\n accent?: string;\n /** A bolder two-color pair, e.g. `[\"#FF4632\", \"#FFD2F2\"]`. Replaces the gradient palette. */\n colors?: [string, string];\n theme?: \"dark\" | \"light\";\n speed?: number;\n}\n\n// Bricolage Grotesque 500, per 1000 em, chars 32–126 (harfbuzz).\nconst ADV = [\n 246, 266, 317, 613, 630, 947, 756, 159, 305, 290, 395, 516, 165, 339, 196,\n 354, 656, 320, 583, 595, 595, 600, 646, 494, 646, 641, 207, 188, 516, 516,\n 516, 413, 952, 671, 666, 671, 691, 599, 578, 706, 709, 275, 358, 666, 508,\n 909, 747, 716, 629, 719, 660, 641, 553, 718, 657, 957, 653, 600, 560, 315,\n 342, 300, 547, 578, 283, 567, 618, 555, 617, 570, 380, 589, 608, 260, 266,\n 561, 257, 913, 608, 604, 618, 617, 411, 535, 380, 599, 547, 827, 534, 591,\n 500, 353, 260, 331, 516,\n];\nconst LSB = [\n 0, 59, 28, 23, 50, 30, 32, 28, 63, 8, 12, 60, 3, 33, 24, -1, 59, 33, 47, 30,\n 27, 56, 59, 26, 54, 57, 29, 4, 60, 60, 60, 22, 61, 26, 82, 59, 82, 82, 82, 59,\n 82, 82, 11, 82, 82, 82, 82, 59, 82, 59, 82, 50, 23, 77, 26, 31, 30, 11, 35,\n 82, -13, 13, 17, 0, 20, 46, 75, 47, 48, 47, 27, 32, 75, 58, -28, 75, 75, 75,\n 75, 47, 75, 48, 75, 42, 19, 67, 17, 22, 20, 54, 36, 29, 82, 2, 42,\n];\nconst RSB = [\n 0, 57, 28, 23, 48, 29, 40, 28, 23, 63, 12, 60, 24, 33, 23, -1, 57, 81, 48, 49,\n 29, 55, 55, 26, 55, 58, 28, 25, 60, 60, 60, 24, 61, 25, 54, 38, 58, 39, 27,\n 62, 82, 82, 81, 34, 18, 82, 82, 57, 36, 58, 44, 48, 22, 76, 26, 30, 27, 11,\n 34, 24, -1, 78, 17, 0, 76, 58, 47, 23, 74, 40, 15, 33, 66, 58, 57, 20, 75, 68,\n 66, 46, 48, 74, 18, 40, 33, 74, 17, 22, 19, 73, 35, 22, 83, 27, 43,\n];\nconst KERN = new Map(\n [\n \"AA16 AC-25 AG-24 AJ21 AO-25 AQ-15 AT-67 AU-26 AV-83 AW-53 AY-78 AZ20\",\n \"A0-22 A1-26 A6-22 A7-31 A.28 A,25 A’-59 BV-18 BX-17 BY-20 CS16 CX-17\",\n \"CY-16 C318 C424 DA-27 DJ-17 DT-25 DV-24 DX-40 DY-32 DZ-15 D7-25 D.-18\",\n \"D,-25 EC-15 EG-15 EJ32 EO-15 ET23 EW19 EX19 EY22 EZ27 E317 E728 E.27\",\n \"E,26 FA-46 FJ-41 FT40 FV23 FW29 FY31 FZ18 F735 F.-59 F,-57 F’17 GJ19\",\n \"GV-20 GY-23 G420 G,18 G-20 JA-23 J,-15 KC-24 KG-24 KJ16 KO-24 KT15\",\n \"KX24 KZ29 K0-21 K216 K6-21 K722 K.22 K,18 K--25 LA26 LC-18 LG-17 LJ57\",\n \"LO-18 LT-74 LU-17 LV-74 LW-45 LX16 LY-87 LZ41 L0-16 L1-24 L229 L6-16\",\n \"L7-27 L.42 L,50 L’-83 L--80 OA-25 OT-22 OV-25 OX-38 OY-31 O7-25 O.-15\",\n \"O,-21 PA-43 PJ-48 PX-20 P.-60 P,-66 P’21 QQ18 QT-22 QV-25 QY-31 Q7-25\",\n \"Q,21 RV-15 RY-16 RZ17 R.15 R--19 SV-20 SY-20 S317 S419 TA-67 TC-25\",\n \"TG-23 TJ-47 TO-23 TQ-23 TT44 TV27 TW31 TX16 TY33 TZ21 T0-18 T4-66\",\n \"T6-18 T739 T.-62 T,-60 T’18 T--81 UA-26 U.-15 U,-20 VA-83 VC-26 VG-24\",\n \"VJ-47 VO-25 VQ-25 VT27 VV19 VW31 VY29 V0-22 V4-44 V6-22 V724 V8-16\",\n \"V.-60 V,-57 V’22 V--35 WA-55 WC-15 WJ-40 WT31 WV31 WW30 WY26 WZ16\",\n \"W4-25 W724 W.-39 W,-43 W’22 W--22 XC-38 XG-39 XJ17 XO-39 XX17 XZ21\",\n \"X0-34 X4-19 X6-34 X9-19 X.18 X,15 X--47 YA-78 YC-33 YG-32 YJ-46 YO-32\",\n \"YQ-32 YT33 YV29 YW26 YY38 YZ15 Y0-29 Y4-66 Y6-29 Y733 Y8-16 Y.-75\",\n \"Y,-72 Y’26 Y--57 ZA17 ZC-15 ZG-16 ZJ40 ZO-16 ZT27 ZV19 ZW21 ZX20 ZY20\",\n \"ZZ31 Z224 Z727 Z.30 Z,32 Z’21 Z--49 0A-24 0T-19 0V-22 0X-34 0Y-29\",\n \"07-20 0,-19 2J21 2Z15 2.21 2,17 2--22 3315 3420 4T-18 4V-17 4Y-15\",\n \"41-16 4431 47-16 4’-15 5418 6V-21 6X-21 6Y-22 6415 7A-72 7C-15 7G-15\",\n \"7J-44 7O-15 7Q-15 7T44 7V27 7W30 7X16 7Y34 7Z21 7118 74-60 7740 7.-68\",\n \"7,-65 7’35 7--55 8V-17 8Y-17 9A-24 9T-20 9V-22 9X-34 9Y-29 97-21 9,-17\",\n \".A28 .J45 .T-62 .U-15 .V-60 .W-37 .X16 .Y-76 .Z38 .1-18 .227 .7-22\",\n \"..26 .’-87 .--38 ,0-17 ,1-18 ,232 ,6-15 ,7-21 ,’-82 ,--30 ’A-70 ’C-17\",\n \"’G-17 ’J-49 ’O-15 ’Q-17 ’T34 ’V32 ’W33 ’X23 ’Y41 ’Z15 ’119 ’4-66 ’730\",\n \"’.-87 ’,-82 ’’22 ’--76 -J-30 -T-80 -V-34 -W-21 -X-48 -Y-57 -Z-16 -1-25\",\n \"-2-26 -417 -7-47 -.-38 -,-35 -’-74\",\n ]\n .join(\" \")\n .split(\" \")\n .map((p) => [p.slice(0, 2), Number(p.slice(2)) / 1000] as const),\n);\nconst CAP = 0.66;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_BEAT = Easing.bezier(0.76, 0, 0.18, 1);\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\n// One gradients.sh palette per theme, laid as a single field across the whole\n// frame: odd blocks are windows onto it, even blocks are solid and let the field\n// through their letters. Dark = radial-glow (+ accent), light = ribbon.\nconst THEMES = {\n dark: {\n stage: \"#08080C\",\n field: [\"\", \"#5A46CB\", \"#1D1240\"],\n glow: \"#9DB4FF\",\n glowAlpha: 0.6,\n solid: \"#F3F1FF\",\n onField: \"#F3F1FF\",\n grain: 0.1,\n },\n light: {\n stage: \"#F5F4F0\",\n field: [\"#7A5CFF\", \"#FF3D9A\", \"#FF8A3D\"],\n glow: \"#FFFFFF\",\n glowAlpha: 0.34,\n solid: \"#0A0A0B\",\n onField: \"#FFFFFF\",\n grain: 0.08,\n },\n} as const;\n\nfunction code(ch: string) {\n const c = ch.charCodeAt(0);\n return c >= 32 && c < 127 ? c - 32 : 33;\n}\n\n/** Advance width plus the ink box of a line, in em. */\nfunction measure(text: string) {\n let adv = 0;\n for (let i = 0; i < text.length; i++) {\n adv += ADV[code(text[i])] / 1000;\n if (i > 0) adv += KERN.get(text[i - 1] + text[i]) ?? 0;\n }\n const lsb = LSB[code(text[0] ?? \" \")] / 1000;\n const rsb = RSB[code(text[text.length - 1] ?? \" \")] / 1000;\n return { adv, lsb, ink: Math.max(0.2, adv - lsb - rsb) };\n}\n\n/** Stage n shows lines 0..n; the newest line arrives loud and squeezes the rest. */\nfunction weights(inks: number[], visible: number, final: boolean) {\n return inks.map((ink, i) => {\n if (i >= visible) return 0;\n const balanced = 1 / ink;\n if (final || visible === 1) return balanced;\n return i === visible - 1 ? balanced * 1.75 : balanced * 0.7;\n });\n}\n\nfunction normalize(w: number[]) {\n const sum = w.reduce((a, b) => a + b, 0) || 1;\n return w.map((v) => v / sum);\n}\n\nfunction WrappedSquashBase({\n lines = [\"YOU\", \"SHIPPED\", \"A LOT\"],\n accent = \"#3B5BFD\",\n colors,\n theme = \"dark\",\n speed = 1,\n}: WrappedSquashProps) {\n const frame = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n const t = THEMES[theme];\n\n const rows = lines\n .slice(0, 3)\n .map((l) => l.toUpperCase().replace(/\\s+/g, \" \").trim())\n .filter(Boolean);\n const n = Math.max(1, rows.length);\n const metrics = rows.map(measure);\n const inks = metrics.map((m) => m.ink);\n\n const field = t.field.map((c, i) =>\n theme === \"dark\" && i === 0 ? accent : c,\n );\n // Flat two-color override: blocks alternate the pair, no field.\n const flat = colors\n ? (i: number) =>\n i % 2 === 0\n ? { bg: colors[0], fg: colors[1] }\n : { bg: colors[1], fg: colors[0] }\n : null;\n\n // Beats: line 1 grows in, each next line arrives on a beat, then the lock.\n const BEATS = [26, 52].slice(0, n - 1);\n const LOCK = 26 + 26 * (n - 1);\n const intro = interpolate(frame, [0, 16], [0.46, 1], {\n ...CLAMP,\n easing: EASE_OUT,\n });\n\n const stages = [\n ...Array.from({ length: n }, (_, s) =>\n normalize(weights(inks, s + 1, false)),\n ),\n normalize(weights(inks, n, true)),\n ];\n // How far each line has arrived (0..1), drives its gutter.\n const arrive = rows.map((_, i) =>\n i === 0\n ? 1\n : interpolate(frame, [BEATS[i - 1], BEATS[i - 1] + 14], [0, 1], {\n ...CLAMP,\n easing: EASE_BEAT,\n }),\n );\n let frac = stages[0];\n for (let s = 1; s < n; s++) {\n const p = arrive[s];\n frac = frac.map((v, i) => v + (stages[s][i] - v) * p);\n }\n const lock = spring({\n frame: frame - LOCK,\n fps,\n config: { damping: 16, stiffness: 170, mass: 0.9 },\n });\n frac = frac.map((v, i) => v + (stages[n][i] - v) * lock);\n\n const margin = Math.round(H * 0.03);\n const gutter = Math.round(H * 0.012);\n const gaps = arrive.slice(1).reduce((a, p) => a + p * gutter, 0);\n const full = H - margin * 2 - gaps;\n const usable = full * intro;\n const blockW = W - margin * 2;\n const F = H * 0.4;\n\n let y = margin + (full - usable) / 2;\n const blocks = rows.map((text, i) => {\n if (i > 0) y += arrive[i] * gutter;\n const h = Math.max(0, frac[i] * usable);\n const top = y;\n y += h;\n return { text, i, top, h };\n });\n\n // The field turns a few degrees and its light drifts across the shot.\n const drift = interpolate(frame, [0, 150], [0, 1], CLAMP);\n const ang = ((24 + 8 * drift) * Math.PI) / 180;\n const reach = Math.hypot(W, H) / 2;\n const fx = Math.cos(ang) * reach;\n const fy = Math.sin(ang) * reach;\n const fieldFill = `url(#${uid}-field)`;\n const glowFill = `url(#${uid}-glow)`;\n\n return (\n <AbsoluteFill style={{ background: t.stage }}>\n <svg width={W} height={H} viewBox={`0 0 ${W} ${H}`} aria-hidden>\n <defs>\n <linearGradient\n id={`${uid}-field`}\n gradientUnits=\"userSpaceOnUse\"\n x1={W / 2 - fx}\n y1={H / 2 - fy}\n x2={W / 2 + fx}\n y2={H / 2 + fy}\n >\n {field.map((c, i) => (\n <stop\n key={`${uid}-s${String(i)}`}\n offset={0.12 + (0.8 * i) / (field.length - 1)}\n stopColor={c}\n />\n ))}\n </linearGradient>\n <radialGradient\n id={`${uid}-glow`}\n gradientUnits=\"userSpaceOnUse\"\n cx={W * (0.16 + 0.1 * drift)}\n cy={H * (0.12 + 0.04 * drift)}\n r={W * 0.55}\n >\n <stop offset=\"0\" stopColor={t.glow} stopOpacity={t.glowAlpha} />\n <stop\n offset=\"0.5\"\n stopColor={t.glow}\n stopOpacity={t.glowAlpha * 0.27}\n />\n <stop offset=\"1\" stopColor={t.glow} stopOpacity={0} />\n </radialGradient>\n <filter id={`${uid}-grain`} x=\"0\" y=\"0\" width=\"100%\" height=\"100%\">\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.85\"\n numOctaves={2}\n seed={7}\n stitchTiles=\"stitch\"\n />\n <feColorMatrix values=\"0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.4 -0.2\" />\n </filter>\n </defs>\n {blocks.map(({ text, i, top, h }) => {\n if (h < 0.5) return null;\n const m = metrics[i];\n const pad = Math.min(W * 0.018, h * 0.12);\n const innerW = blockW - pad * 2;\n const innerH = Math.max(0.01, h - pad * 2);\n const sx = innerW / (m.ink * F);\n const sy = innerH / (CAP * F);\n const tx = margin + pad - m.lsb * F * sx;\n const base = top + h - pad;\n const isWindow = i % 2 === 0;\n const flatC = flat ? flat(i) : null;\n const word = (fill: string) => (\n <text\n x={0}\n y={0}\n fill={fill}\n fontFamily={display}\n fontWeight={500}\n fontSize={F}\n textLength={m.adv * F}\n lengthAdjust=\"spacingAndGlyphs\"\n style={{ fontKerning: \"normal\" }}\n transform={`translate(${tx} ${base}) scale(${sx} ${sy})`}\n >\n {text}\n </text>\n );\n const rect = (fill: string, mask?: string) => (\n <rect\n x={margin}\n y={top}\n width={blockW}\n height={h}\n fill={fill}\n mask={mask}\n />\n );\n return (\n <g key={`${uid}-${i}`}>\n {flatC ? (\n rect(flatC.bg)\n ) : isWindow ? (\n <>\n {rect(fieldFill)}\n {rect(glowFill)}\n </>\n ) : (\n rect(t.solid)\n )}\n <svg\n x={margin}\n y={top}\n width={blockW}\n height={h}\n viewBox={`${margin} ${top} ${blockW} ${h}`}\n overflow=\"hidden\"\n >\n {flatC ? (\n word(flatC.fg)\n ) : isWindow ? (\n word(t.onField)\n ) : (\n <>\n <mask\n id={`${uid}-m${i}`}\n maskUnits=\"userSpaceOnUse\"\n x={margin}\n y={top}\n width={blockW}\n height={h}\n >\n {word(\"#FFFFFF\")}\n </mask>\n {rect(fieldFill, `url(#${uid}-m${i})`)}\n {rect(glowFill, `url(#${uid}-m${i})`)}\n </>\n )}\n </svg>\n </g>\n );\n })}\n {flat ? null : (\n <rect\n width={W}\n height={H}\n filter={`url(#${uid}-grain)`}\n opacity={t.grain}\n style={{ mixBlendMode: \"overlay\" }}\n />\n )}\n </svg>\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n theme: {\n type: \"enum\",\n default: \"dark\",\n variants: {\n dark: {},\n light: {},\n },\n description: \"Theme\",\n },\n accent: {\n type: \"color\",\n default: \"#3B5BFD\",\n description: \"Accent\",\n },\n speed: {\n type: \"number\",\n default: 1,\n min: 0.25,\n max: 4,\n step: 0.25,\n description: \"Speed\",\n hiddenFromList: false,\n },\n ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"theme\",\"accent\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n theme: \"dark\",\n accent: \"#3B5BFD\",\n speed: 1,\n};\n\ntype WrappedSquashElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof WrappedSquashBase>;\n\nconst WrappedSquashInner = forwardRef<\n HTMLDivElement,\n WrappedSquashElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, ...rest }, ref) => {\n const outlineRef = useRef<HTMLDivElement>(null);\n useImperativeHandle(ref, () => outlineRef.current as HTMLDivElement, []);\n const componentProps: Record<string, unknown> = { ...ELEMENT_PROP_DEFAULTS };\n const sequenceProps: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(rest)) {\n if (ELEMENT_PROP_KEYS.has(key)) {\n if (value !== undefined) componentProps[key] = value;\n } else {\n sequenceProps[key] = value;\n }\n }\n return (\n <Sequence\n layout=\"none\"\n {...sequenceProps}\n controls={controls}\n name={name ?? \"<WrappedSquash>\"}\n outlineRef={outlineRef}\n >\n <div\n ref={outlineRef}\n style={{\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n ...style,\n }}\n >\n <WrappedSquashBase\n {...(componentProps as unknown as ComponentProps<typeof WrappedSquashBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const WrappedSquash = Interactive.withSchema({\n Component: WrappedSquashInner,\n componentName: \"<WrappedSquash>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 93,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 93
}