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": "grid-montage",
"title": "Grid Montage",
"description": "One shot splits into a 2x2 then a 3x3 montage, cutting on the beat.",
"dependencies": ["remotion", "@remotion/google-fonts"],
"registryDependencies": ["@remocn/gsh"],
"files": [
{
"path": "registry/remocn/grid-montage/index.tsx",
"content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/InstrumentSans\";\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport type React from \"react\";\nimport { useId } from \"react\";\nimport {\n AbsoluteFill,\n Easing,\n Img,\n interpolate,\n spring,\n useCurrentFrame,\n useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\nconst display = sans;\nconst { fontFamily: serif } = loadSerif(\"italic\", {\n weights: [\"400\"],\n subsets: [\"latin\"],\n});\nconst manrope = loadManrope(\"normal\", {\n weights: [\"500\", \"600\"],\n subsets: [\"latin\"],\n});\n\nconst CLAMP = {\n extrapolateLeft: \"clamp\",\n extrapolateRight: \"clamp\",\n} as const;\n\ntype Tone = \"dark\" | \"graphite\" | \"light\" | \"accent\";\ntype Kind =\n | \"title\"\n | \"pane\"\n | \"number\"\n | \"statement\"\n | \"mark\"\n | \"clock\"\n | \"chart\"\n | \"word\";\ninterface SceneSpec {\n kind: Kind;\n tone: Tone;\n}\ninterface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\nfunction toRgb(color: string): [number, number, number] {\n if (color.startsWith(\"rgb\")) {\n const [r, g, b] = color.match(/[\\d.]+/g)?.map(Number) ?? [0, 0, 0];\n return [r, g, b];\n }\n const h = color.replace(\"#\", \"\");\n const v =\n h.length === 3\n ? h\n .split(\"\")\n .map((ch) => ch + ch)\n .join(\"\")\n : h.slice(0, 6);\n const n = Number.parseInt(v, 16);\n return [(n >> 16) & 255, (n >> 8) & 255, n & 255];\n}\n\nfunction mix(a: string, b: string, t: number) {\n const x = toRgb(a);\n const y = toRgb(b);\n const c = x.map((v, i) => Math.round(v + (y[i] - v) * t));\n return `rgb(${c[0]},${c[1]},${c[2]})`;\n}\n\nfunction palette(tone: Tone, accent: string, lightStage: boolean) {\n if (tone === \"light\") {\n return {\n bg: \"#F5F4F0\",\n fg: \"#121214\",\n muted: \"#6E6C67\",\n hair: \"rgba(18,18,20,0.10)\",\n surface: \"#FFFFFF\",\n block: \"#E6E3DC\",\n light: \"rgba(255,255,255,0.95)\",\n shadow: \"rgba(40,36,30,0.16)\",\n dot: accent,\n };\n }\n if (tone === \"accent\") {\n return lightStage\n ? {\n bg: \"transparent\",\n fg: \"#121214\",\n muted: \"rgba(18,18,20,0.6)\",\n hair: \"rgba(18,18,20,0.12)\",\n surface: \"rgba(255,255,255,0.6)\",\n block: \"rgba(18,18,20,0.08)\",\n light: \"rgba(255,255,255,0)\",\n shadow: \"rgba(26,42,158,0.2)\",\n dot: accent,\n }\n : {\n bg: \"transparent\",\n fg: \"#F7F7F5\",\n muted: \"rgba(247,247,245,0.7)\",\n hair: \"rgba(255,255,255,0.22)\",\n surface: \"rgba(10,10,11,0.4)\",\n block: \"rgba(255,255,255,0.16)\",\n light: \"rgba(255,255,255,0)\",\n shadow: \"rgba(0,0,0,0.35)\",\n dot: accent,\n };\n }\n const graphite = tone === \"graphite\";\n return {\n bg: graphite ? \"#17171A\" : \"#0A0A0B\",\n fg: \"#F3F2EF\",\n muted: graphite ? \"#97969C\" : \"#8B8A90\",\n hair: \"rgba(255,255,255,0.10)\",\n surface: graphite ? \"#1F1F23\" : \"#151517\",\n block: graphite ? \"#2B2B30\" : \"#232326\",\n light: graphite ? \"rgba(255,255,255,0.07)\" : \"rgba(255,255,255,0.06)\",\n shadow: \"rgba(0,0,0,0.6)\",\n dot: accent,\n };\n}\n\ntype Colors = ReturnType<typeof palette>;\ninterface Ctx {\n W: number;\n H: number;\n u: number;\n c: Colors;\n accent: string;\n slot?: Rect;\n}\n\nconst LIGHT_AT: Record<Kind, string> = {\n title: \"18% 8%\",\n pane: \"50% -10%\",\n number: \"88% 12%\",\n statement: \"82% 100%\",\n mark: \"30% 15%\",\n clock: \"64% 50%\",\n chart: \"8% 0%\",\n word: \"22% 0%\",\n};\n\nconst REMOCN_R_PATH =\n \"M 0.01 0.81 C 0.01 1.73, 0.36 2.79, 1.09 4.13 C 4.91 11.04, 13.45 17.16, 21.7 18.9 C 22.94 19.16, 23.18 19.16, 51.39 19.27 C 76.07 19.36, 80.02 19.4, 81.32 19.57 C 89.89 20.69, 96.2 24.68, 99.38 31.01 C 103.19 38.56, 102.53 50.1, 97.91 57.07 C 94.66 61.96, 89.68 64.99, 83.26 66 C 82.81 66.07, 70.18 66.83, 55.2 67.69 C 24.82 69.43, 27.03 69.23, 24.18 70.4 C 19.9 72.15, 14.84 75.7, 10.65 79.89 C 4.86 85.68, 1.3 91.91, 0.25 98.13 C 0.12 98.85, 0.08 103.13, 0.04 116.66 L 0 134.26 9.5 134.26 L 19 134.26 19.05 119.41 C 19.1 103.27, 19.08 103.82, 19.82 101.04 C 21.79 93.65, 27.86 88.75, 36.45 87.63 C 37.23 87.53, 39.41 87.5, 43.57 87.53 C 50.12 87.59, 50.75 87.65, 53.22 88.45 C 56.61 89.56, 59.67 91.86, 62.02 95.07 C 62.52 95.76, 69.35 103.85, 77.2 113.07 C 85.04 122.28, 91.63 130.04, 91.85 130.32 C 92.07 130.59, 92.5 131.34, 92.82 131.97 C 93.52 133.35, 94.11 133.93, 95.06 134.13 C 95.5 134.23, 98.97 134.26, 106.36 134.23 L 117.01 134.19 100.82 113.07 C 91.91 101.45, 84.52 91.78, 84.39 91.57 C 83.36 89.89, 83.66 87.53, 85.09 86 C 85.79 85.25, 86.36 84.94, 88.07 84.38 C 96.18 81.72, 104.15 76.62, 109.97 70.36 C 120.59 58.93, 124.06 44.32, 119.44 30.43 C 114.59 15.81, 101.93 4.02, 87.64 0.83 C 83.93 0.01, 88.09 0.08, 41.85 0.04 L 0.01 0 0.01 0.81 Z\";\n\nfunction RemocnR({ height, color }: { height: number; color: string }) {\n return (\n <svg\n viewBox=\"0 0 124.06 134.26\"\n height={height}\n width={(height * 124.06) / 134.26}\n style={{ display: \"block\", flexShrink: 0 }}\n aria-hidden\n >\n <path fill={color} d={REMOCN_R_PATH} />\n </svg>\n );\n}\n\nfunction RemocnLogo({ fontSize, color }: { fontSize: number; color: string }) {\n return (\n <div\n style={{\n display: \"flex\",\n alignItems: \"baseline\",\n color,\n fontFamily: manrope.fontFamily,\n fontWeight: 600,\n fontSize,\n letterSpacing: \"-0.025em\",\n lineHeight: 1,\n flexShrink: 0,\n }}\n >\n <svg\n viewBox=\"0 0 124.06 134.26\"\n style={{ height: \"0.76em\", width: \"auto\" }}\n aria-hidden\n >\n <path fill=\"currentColor\" d={REMOCN_R_PATH} />\n </svg>\n <span style={{ marginLeft: \"0.04em\" }}>emocn</span>\n </div>\n );\n}\n\nconst abs = (r: Rect): React.CSSProperties => ({\n position: \"absolute\",\n left: r.x,\n top: r.y,\n width: r.w,\n height: r.h,\n});\n\nconst displayType = (size: number): React.CSSProperties => ({\n fontFamily: display,\n fontWeight: 400,\n fontSize: size,\n letterSpacing: \"-0.035em\",\n lineHeight: 1,\n fontVariantNumeric: \"tabular-nums\",\n});\n\nfunction TitleBody({ x }: { x: Ctx }) {\n const { W, H, u, c, slot } = x;\n const left = slot ? 0.08 * W : 0;\n return (\n <div\n style={{\n position: \"absolute\",\n left,\n top: 0,\n height: H,\n width: slot ? slot.x - left - 0.03 * W : W,\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n alignItems: slot ? \"flex-start\" : \"center\",\n gap: 18 * u,\n }}\n >\n <div style={{ fontSize: 22 * u, fontWeight: 400, color: c.muted }}>\n Introducing\n </div>\n <RemocnLogo fontSize={132 * u} color={c.fg} />\n <div\n style={{\n fontSize: 24 * u,\n color: c.muted,\n letterSpacing: \"-0.01em\",\n textAlign: slot ? \"left\" : \"center\",\n }}\n >\n Motion for the films you launch with.\n </div>\n </div>\n );\n}\n\nfunction PaneBody({ x }: { x: Ctx }) {\n const { W, H, u, c, accent, slot } = x;\n const pane = { x: 0.08 * W, y: 0.1 * H, w: 0.84 * W, h: 0.8 * H };\n const canvas = slot ?? { x: 0.335 * W, y: 0.2 * H, w: 0.36 * W, h: 0.36 * H };\n const side = 0.27 * W;\n const insp = 0.765 * W;\n const bar = 0.075 * H;\n const lightPane = c.surface === \"#FFFFFF\";\n const tint = mix(accent, c.surface, lightPane ? 0.9 : 0.82);\n const rows = [\n \"Hook\",\n \"Title card\",\n \"Feature tour\",\n \"Pricing\",\n \"Quote\",\n \"Logo\",\n ];\n const fields = [\n [\"Duration\", \"4.0s\"],\n [\"Easing\", \"Spring\"],\n [\"Scale\", \"1.04\"],\n [\"Opacity\", \"100%\"],\n [\"Blur\", \"0px\"],\n ];\n const clipNames = [\"Title\", \"Shot 02\", \"Logo\"];\n const tracks = [\n [\n [0.3, 0.42],\n [0.43, 0.62],\n ],\n [[0.34, 0.56]],\n [\n [0.29, 0.38],\n [0.39, 0.52],\n [0.53, 0.74],\n ],\n ];\n return (\n <>\n <div\n style={{\n ...abs(pane),\n background: c.surface,\n borderRadius: 16 * u,\n boxShadow: `0 0 0 1px ${c.hair}, 0 ${30 * u}px ${70 * u}px ${c.shadow}`,\n overflow: \"hidden\",\n }}\n />\n <div\n style={{\n ...abs({ x: pane.x, y: pane.y + bar, w: pane.w, h: 1 }),\n background: c.hair,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n left: pane.x + 22 * u,\n top: pane.y,\n height: bar,\n display: \"flex\",\n alignItems: \"center\",\n gap: 9 * u,\n }}\n >\n <RemocnLogo fontSize={18 * u} color={c.fg} />\n <div style={{ fontSize: 15 * u, color: c.muted, marginLeft: 6 * u }}>\n / Launch film\n </div>\n </div>\n <div\n style={{\n position: \"absolute\",\n right: W - pane.x - pane.w + 18 * u,\n top: pane.y + bar / 2 - 15 * u,\n height: 30 * u,\n padding: `0 ${14 * u}px`,\n borderRadius: 8 * u,\n background: accent,\n color: \"#FFFFFF\",\n fontSize: 14 * u,\n fontWeight: 400,\n display: \"flex\",\n alignItems: \"center\",\n }}\n >\n Render\n </div>\n <div\n style={{\n ...abs({ x: side, y: pane.y + bar, w: 1, h: pane.h - bar }),\n background: c.hair,\n }}\n />\n <div\n style={{\n ...abs({ x: insp, y: pane.y + bar, w: 1, h: pane.h - bar }),\n background: c.hair,\n }}\n />\n {rows.map((label, i) => {\n const y = pane.y + bar + 26 * u + i * 0.062 * H;\n const on = i === 1;\n return (\n <div key={label}>\n {on ? (\n <div\n style={{\n ...abs({\n x: pane.x + 12 * u,\n y: y - 9 * u,\n w: side - pane.x - 24 * u,\n h: 34 * u,\n }),\n background: tint,\n borderRadius: 8 * u,\n }}\n />\n ) : null}\n <div\n style={{\n ...abs({ x: pane.x + 24 * u, y, w: 14 * u, h: 14 * u }),\n borderRadius: 4 * u,\n boxShadow: `inset 0 0 0 ${1.5 * u}px ${on ? accent : c.muted}`,\n opacity: on ? 1 : 0.6,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n left: pane.x + 48 * u,\n top: y - 3 * u,\n fontSize: 17 * u,\n lineHeight: 1.2,\n color: on ? c.fg : c.muted,\n whiteSpace: \"nowrap\",\n }}\n >\n {label}\n </div>\n </div>\n );\n })}\n {fields.map(([k, v], i) => {\n const y = pane.y + bar + 24 * u + i * 0.075 * H;\n return (\n <div key={k}>\n <div\n style={{\n position: \"absolute\",\n left: insp + 20 * u,\n top: y - 4 * u,\n fontSize: 14 * u,\n color: c.muted,\n }}\n >\n {k}\n </div>\n <div\n style={{\n ...abs({\n x: insp + 20 * u,\n y: y + 16 * u,\n w: 0.155 * W - 40 * u,\n h: 26 * u,\n }),\n borderRadius: 6 * u,\n boxShadow: `inset 0 0 0 1px ${c.hair}`,\n display: \"flex\",\n alignItems: \"center\",\n paddingLeft: 9 * u,\n fontSize: 15 * u,\n color: c.fg,\n fontVariantNumeric: \"tabular-nums\",\n }}\n >\n {v}\n </div>\n </div>\n );\n })}\n <div\n style={{\n ...abs({\n x: side,\n y: canvas.y + canvas.h + 0.07 * H,\n w: insp - side,\n h: 1,\n }),\n background: c.hair,\n }}\n />\n {tracks.map((clips, ti) =>\n clips.map(([a, b], ci) => (\n <div\n key={`${ti}-${a}`}\n style={{\n ...abs({\n x: a * W,\n y: canvas.y + canvas.h + 0.1 * H + ti * 0.058 * H,\n w: (b - a) * W - 4 * u,\n h: 0.042 * H,\n }),\n borderRadius: 6 * u,\n background: ti === 1 ? accent : c.block,\n display: \"flex\",\n alignItems: \"center\",\n paddingLeft: 8 * u,\n fontSize: 13 * u,\n color: ti === 1 ? \"#FFFFFF\" : c.muted,\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n }}\n >\n {clipNames[(ti + ci) % clipNames.length]}\n </div>\n )),\n )}\n <div\n style={{\n ...abs({\n x: 0.47 * W,\n y: canvas.y + canvas.h + 0.085 * H,\n w: 2 * u,\n h: 0.2 * H,\n }),\n background: c.fg,\n borderRadius: u,\n }}\n />\n {slot ? null : (\n <div\n style={{\n ...abs(canvas),\n borderRadius: 10 * u,\n background: lightPane ? \"#0A0A0B\" : \"#F5F4F0\",\n boxShadow: `inset 0 0 0 1px ${c.hair}`,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n overflow: \"hidden\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background: `radial-gradient(ellipse 80% 90% at 30% 0%, ${lightPane ? \"rgba(255,255,255,0.09)\" : \"rgba(255,255,255,0.9)\"}, transparent 70%)`,\n }}\n />\n <RemocnR height={58 * u} color={lightPane ? \"#F3F2EF\" : \"#121214\"} />\n </div>\n )}\n </>\n );\n}\n\nfunction NumberBody({ x }: { x: Ctx }) {\n const { W, H, u, c, accent, slot } = x;\n const left = 0.08 * W;\n return (\n <>\n <div\n style={{\n position: \"absolute\",\n left,\n top: 0.16 * H,\n display: \"flex\",\n alignItems: \"center\",\n gap: 10 * u,\n fontSize: 19 * u,\n fontWeight: 400,\n color: c.muted,\n }}\n >\n <div\n style={{\n width: 9 * u,\n height: 9 * u,\n borderRadius: 9 * u,\n background: c.dot,\n }}\n />\n Median render time\n </div>\n <div\n style={{\n position: \"absolute\",\n left: left - 10 * u,\n top: 0.27 * H,\n ...displayType(250 * u),\n letterSpacing: \"-0.05em\",\n }}\n >\n 4.8×\n </div>\n <div\n style={{\n position: \"absolute\",\n left,\n top: 0.27 * H + 268 * u,\n width: slot ? slot.x - left - 0.04 * W : 0.4 * W,\n fontSize: 28 * u,\n lineHeight: 1.25,\n color: c.muted,\n letterSpacing: \"-0.015em\",\n textWrap: \"balance\",\n }}\n >\n faster from script to final cut\n </div>\n {slot\n ? null\n : [\n { label: \"Before\", w: 1, color: c.block },\n { label: \"With remocn\", w: 1 / 4.8, color: accent },\n ].map((row, i) => (\n <div\n key={row.label}\n style={{\n position: \"absolute\",\n left: 0.58 * W,\n top: 0.4 * H + i * 0.13 * H,\n }}\n >\n <div\n style={{\n fontSize: 18 * u,\n color: c.muted,\n marginBottom: 12 * u,\n }}\n >\n {row.label}\n </div>\n <div\n style={{\n width: 0.32 * W * row.w,\n height: 20 * u,\n borderRadius: 10 * u,\n background: row.color,\n boxShadow:\n row.color === accent\n ? undefined\n : `inset 0 0 0 1px ${c.hair}`,\n }}\n />\n </div>\n ))}\n </>\n );\n}\n\nfunction StatementBody({ x }: { x: Ctx }) {\n const { W, H, u, c } = x;\n return (\n <>\n <div\n style={{\n position: \"absolute\",\n left: 0.08 * W,\n top: 0.1 * H,\n display: \"flex\",\n alignItems: \"center\",\n gap: 10 * u,\n }}\n >\n <RemocnLogo fontSize={30 * u} color={c.fg} />\n </div>\n <div\n style={{\n position: \"absolute\",\n left: 0.08 * W - 6 * u,\n bottom: 0.13 * H,\n ...displayType(140 * u),\n lineHeight: 0.94,\n }}\n >\n <div>Own every</div>\n <div>\n <span\n style={{\n fontFamily: serif,\n fontStyle: \"italic\",\n fontWeight: 400,\n letterSpacing: \"-0.02em\",\n }}\n >\n frame\n </span>\n <span style={{ color: c.dot }}>.</span>\n </div>\n </div>\n <div\n style={{\n position: \"absolute\",\n right: 0.08 * W,\n bottom: 0.14 * H,\n fontSize: 20 * u,\n color: c.muted,\n }}\n >\n remocn.dev\n </div>\n </>\n );\n}\n\nfunction MarkBody({ x }: { x: Ctx }) {\n const { u, c } = x;\n return (\n <AbsoluteFill\n style={{\n alignItems: \"center\",\n justifyContent: \"center\",\n flexDirection: \"column\",\n gap: 26 * u,\n }}\n >\n <RemocnLogo fontSize={170 * u} color={c.fg} />\n </AbsoluteFill>\n );\n}\n\nfunction ClockBody({ x }: { x: Ctx }) {\n const { W, H, u, c, accent } = x;\n const left = 0.08 * W;\n const right = 0.92 * W;\n const base = 0.74 * H;\n const head = 12.07 / 30;\n const marks = [0, 5, 10, 15, 20, 25, 30];\n const clips = [\n { a: 0, b: 4.2, label: \"Hook\" },\n { a: 4.4, b: 13.6, label: \"Feature tour\" },\n { a: 13.8, b: 22.4, label: \"Pricing\" },\n { a: 22.6, b: 30, label: \"Logo\" },\n ];\n const span = right - left;\n return (\n <>\n <div style={{ position: \"absolute\", left, top: 0.16 * H }}>\n <div style={{ fontSize: 22 * u, color: c.muted }}>Playhead</div>\n <div style={{ ...displayType(150 * u), marginTop: 14 * u }}>\n 00:12:04\n </div>\n <div\n style={{\n fontSize: 22 * u,\n color: c.muted,\n marginTop: 14 * u,\n fontVariantNumeric: \"tabular-nums\",\n }}\n >\n Frame 362 of 900\n </div>\n </div>\n {marks.map((m) => (\n <div\n key={m}\n style={{\n position: \"absolute\",\n left: left + (m / 30) * span,\n top: base - 34 * u,\n fontSize: 17 * u,\n color: c.muted,\n fontVariantNumeric: \"tabular-nums\",\n transform: m === 0 ? undefined : \"translateX(-50%)\",\n }}\n >\n {m}s\n </div>\n ))}\n <div\n style={{\n ...abs({ x: left, y: base - 8 * u, w: span, h: 1 }),\n background: c.hair,\n }}\n />\n {clips.map((cl, i) => (\n <div\n key={cl.label}\n style={{\n ...abs({\n x: left + (cl.a / 30) * span,\n y: base + 6 * u,\n w: ((cl.b - cl.a) / 30) * span,\n h: 52 * u,\n }),\n borderRadius: 8 * u,\n background: i === 1 ? mix(accent, c.bg, 0.25) : c.block,\n boxShadow: `inset 0 0 0 1px ${c.hair}`,\n display: \"flex\",\n alignItems: \"center\",\n paddingLeft: 14 * u,\n fontSize: 18 * u,\n color: i === 1 ? \"#FFFFFF\" : c.fg,\n whiteSpace: \"nowrap\",\n overflow: \"hidden\",\n }}\n >\n {cl.label}\n </div>\n ))}\n <div\n style={{\n ...abs({\n x: left + head * span - 1 * u,\n y: base - 14 * u,\n w: 2 * u,\n h: 82 * u,\n }),\n background: c.fg,\n borderRadius: u,\n }}\n />\n </>\n );\n}\n\nfunction ChartBody({ x }: { x: Ctx }) {\n const { W, H, u, c, accent } = x;\n const heights = [0.14, 0.19, 0.17, 0.26, 0.31, 0.38, 0.52];\n const base = 0.84 * H;\n const bw = 0.046 * W;\n const gap = 0.018 * W;\n const x0 = 0.92 * W - heights.length * (bw + gap) + gap;\n return (\n <>\n <div style={{ position: \"absolute\", left: 0.08 * W, top: 0.14 * H }}>\n <div style={{ fontSize: 20 * u, color: c.muted, fontWeight: 400 }}>\n Videos shipped per week\n </div>\n <div style={{ ...displayType(110 * u), marginTop: 22 * u }}>+212%</div>\n </div>\n <div\n style={{\n ...abs({ x: 0.08 * W, y: base, w: 0.84 * W, h: 1 }),\n background: c.hair,\n }}\n />\n {heights.map((h, i) => (\n <div\n key={h}\n style={{\n ...abs({\n x: x0 + i * (bw + gap),\n y: base - h * H,\n w: bw,\n h: h * H,\n }),\n borderRadius: `${8 * u}px ${8 * u}px ${2 * u}px ${2 * u}px`,\n background: i === heights.length - 1 ? accent : c.block,\n }}\n />\n ))}\n </>\n );\n}\n\nfunction WordBody({ x }: { x: Ctx }) {\n const { W, H, u, c } = x;\n return (\n <>\n <div\n style={{\n ...abs({ x: 0.08 * W, y: 0.2 * H, w: 0.84 * W, h: 1 }),\n background: c.hair,\n }}\n />\n <div\n style={{\n position: \"absolute\",\n left: 0.08 * W,\n right: 0.08 * W,\n top: 0.2 * H - 40 * u,\n display: \"flex\",\n justifyContent: \"space-between\",\n fontSize: 19 * u,\n color: c.muted,\n fontVariantNumeric: \"tabular-nums\",\n }}\n >\n <span>02</span>\n <span>Chapter</span>\n </div>\n <div\n style={{\n position: \"absolute\",\n left: 0.08 * W - 12 * u,\n bottom: 0.1 * H,\n ...displayType(250 * u),\n letterSpacing: \"-0.055em\",\n }}\n >\n Render<span style={{ color: c.dot }}>.</span>\n </div>\n </>\n );\n}\n\nconst BODIES: Record<Kind, (p: { x: Ctx }) => React.ReactElement> = {\n title: TitleBody,\n pane: PaneBody,\n number: NumberBody,\n statement: StatementBody,\n mark: MarkBody,\n clock: ClockBody,\n chart: ChartBody,\n word: WordBody,\n};\n\nfunction PlaceholderScene({\n kind,\n tone,\n accent,\n slot,\n lightStage,\n}: SceneSpec & { accent: string; slot?: Rect; lightStage: boolean }) {\n const { width: W, height: H } = useVideoConfig();\n const u = Math.min(H / 720, W / 1280);\n const c = palette(tone, accent, lightStage);\n const Body = BODIES[kind];\n const open = tone === \"accent\";\n return (\n <AbsoluteFill\n style={{\n background: c.bg,\n color: c.fg,\n fontFamily: sans,\n overflow: \"hidden\",\n }}\n >\n {open ? null : (\n <AbsoluteFill\n style={{\n background: `radial-gradient(ellipse 75% 85% at ${LIGHT_AT[kind]}, ${c.light}, transparent 72%)`,\n }}\n />\n )}\n <Body x={{ W, H, u, c, accent, slot }} />\n </AbsoluteFill>\n );\n}\n\nfunction ImageScene({ src }: { src: string }) {\n return (\n <AbsoluteFill style={{ background: \"#0A0A0B\" }}>\n <Img\n src={src}\n style={{ width: \"100%\", height: \"100%\", objectFit: \"cover\" }}\n />\n </AbsoluteFill>\n );\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n return (\n <svg\n width=\"100%\"\n height=\"100%\"\n style={{\n position: \"absolute\",\n inset: 0,\n opacity,\n pointerEvents: \"none\",\n }}\n aria-hidden\n >\n <filter id={id}>\n <feTurbulence\n type=\"fractalNoise\"\n baseFrequency=\"0.9\"\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 0.9 0\" />\n </filter>\n <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n </svg>\n );\n}\n\nexport interface GridMontageProps {\n scenes?: React.ReactNode[];\n images?: string[];\n beat?: number;\n accent?: string;\n ground?: GshPresetId;\n groundParams?: Partial<GradientParams>;\n speed?: number;\n theme?: \"dark\" | \"light\";\n}\n\nconst DARK_LIST: SceneSpec[] = [\n { kind: \"mark\", tone: \"accent\" },\n { kind: \"pane\", tone: \"light\" },\n { kind: \"number\", tone: \"graphite\" },\n { kind: \"clock\", tone: \"graphite\" },\n { kind: \"chart\", tone: \"light\" },\n { kind: \"mark\", tone: \"accent\" },\n { kind: \"word\", tone: \"light\" },\n { kind: \"title\", tone: \"graphite\" },\n { kind: \"pane\", tone: \"graphite\" },\n { kind: \"number\", tone: \"light\" },\n { kind: \"statement\", tone: \"light\" },\n];\nconst flipTone = (t: Tone): Tone =>\n t === \"light\" ? \"graphite\" : t === \"graphite\" ? \"light\" : t;\nconst LIGHT_LIST: SceneSpec[] = DARK_LIST.map((s) => ({\n ...s,\n tone: flipTone(s.tone),\n}));\n\nconst EASE_SNAP = Easing.bezier(0.22, 1, 0.36, 1);\nconst CARD = { mass: 0.8, damping: 18, stiffness: 160 };\nconst MORPH_SPRING = { damping: 200 };\nconst EASE_SWAP = Easing.bezier(0.83, 0, 0.17, 1);\nconst SWAP = 8;\nconst MERGE = 12;\n\nconst CORNERS = [\n [0, 0],\n [0, 2],\n [2, 0],\n [2, 2],\n];\nconst FOCI = [\n [-10, -6],\n [8, -10],\n [-6, 8],\n [10, 6],\n [0, -12],\n [-12, 0],\n [0, 0],\n [12, 0],\n [0, 12],\n];\n\nfunction grid(\n cols: number,\n rows: number,\n W: number,\n H: number,\n m: number,\n g: number,\n) {\n const cw = (W - 2 * m - (cols - 1) * g) / cols;\n const ch = (H - 2 * m - (rows - 1) * g) / rows;\n const out: Rect[] = [];\n for (let r = 0; r < rows; r++) {\n for (let c = 0; c < cols; c++) {\n out.push({ x: m + c * (cw + g), y: m + r * (ch + g), w: cw, h: ch });\n }\n }\n return out;\n}\n\nconst lerpRect = (a: Rect, b: Rect, t: number): Rect => ({\n x: a.x + (b.x - a.x) * t,\n y: a.y + (b.y - a.y) * t,\n w: a.w + (b.w - a.w) * t,\n h: a.h + (b.h - a.h) * t,\n});\n\ntype Fill =\n | { type: \"own\"; shot: number; push: number; focus: number[]; nominal: Rect }\n | { type: \"piece\"; shot: number; push: number; source: Rect };\n\nexport function GridMontage({\n scenes,\n images,\n beat = 14,\n accent = \"#3B5BFD\",\n ground,\n groundParams,\n speed = 1,\n theme = \"dark\",\n}: GridMontageProps) {\n const frame = useCurrentFrame() * speed;\n const { width: W, height: H, fps } = useVideoConfig();\n const u = H / 720;\n const b = Math.max(8, beat);\n const lightStage = theme === \"light\";\n const specs = theme === \"light\" ? LIGHT_LIST : DARK_LIST;\n const stage = theme === \"light\" ? \"#F5F4F0\" : \"#0A0A0B\";\n const hairline =\n theme === \"light\" ? \"rgba(18,18,20,0.10)\" : \"rgba(255,255,255,0.10)\";\n const panelShadow = (e: number) =>\n lightStage\n ? `0 ${2 * u}px ${4 * u}px rgba(26,42,158,${0.06 * e}), 0 ${18 * u}px ${40 * u}px -${14 * u}px rgba(26,42,158,${0.22 * e})`\n : `0 ${2 * u}px ${6 * u}px rgba(0,0,0,${0.3 * e}), 0 ${20 * u}px ${44 * u}px -${14 * u}px rgba(0,0,0,${0.6 * e})`;\n\n const M = 0.042 * H;\n const G = 0.022 * H;\n const R = 14 * u;\n\n const tOpen = 2 * b;\n const tSwap1 = 3 * b;\n const tGrow = 5 * b;\n const tSwap2 = 7 * b;\n const tMerge = 9 * b;\n const p = (start: number, dur: number) =>\n interpolate(frame, [start, start + dur], [0, 1], CLAMP);\n\n const beats = (since: number) => {\n let s = 0;\n for (let k = 0; k < 12; k++) {\n s += EASE_SNAP(interpolate(since - k * b, [0, 7], [0, 1], CLAMP));\n }\n return s;\n };\n const ownPush = (start: number) => 1.02 + 0.012 * beats(frame - start);\n const openerPush = 1 + 0.03 * (frame / Math.max(1, tGrow));\n const closerPush =\n 1 +\n 0.035 *\n Easing.bezier(0.22, 1, 0.36, 1)(p(tSwap2, tMerge + MERGE + 40 - tSwap2));\n\n const list = scenes ?? images;\n const pickShot = (slot: number) => {\n if (!list?.length) return slot;\n const len = list.length;\n if (slot === 0) return 0;\n if (slot === 10) return len - 1;\n if (len <= 2) return slot % len;\n return 1 + ((slot - 1) % (len - 2));\n };\n const shot = (slot: number) => {\n const i = pickShot(slot);\n if (scenes) return <AbsoluteFill>{scenes[i]}</AbsoluteFill>;\n if (images) return <ImageScene src={images[i]} />;\n return (\n <PlaceholderScene {...specs[i]} accent={accent} lightStage={lightStage} />\n );\n };\n\n const content = (fill: Fill, tile: Rect) => {\n if (fill.type === \"piece\") {\n const q = fill.source;\n const sc = Math.max(tile.w / q.w, tile.h / q.h);\n return (\n <div\n style={{\n position: \"absolute\",\n width: W,\n height: H,\n transformOrigin: \"0 0\",\n transform: `translate(${tile.w / 2}px, ${tile.h / 2}px) scale(${sc}) translate(${-(q.x + q.w / 2)}px, ${-(q.y + q.h / 2)}px)`,\n }}\n >\n <AbsoluteFill style={{ transform: `scale(${fill.push})` }}>\n {shot(fill.shot)}\n </AbsoluteFill>\n </div>\n );\n }\n const sc = Math.max(fill.nominal.w / W, fill.nominal.h / H);\n return (\n <div\n style={{\n position: \"absolute\",\n width: W,\n height: H,\n transformOrigin: \"0 0\",\n transform: `translate(${tile.w / 2}px, ${tile.h / 2}px) scale(${sc}) translate(${-W / 2}px, ${-H / 2}px)`,\n }}\n >\n <AbsoluteFill\n style={{\n transform: `scale(${fill.push})`,\n transformOrigin: `${50 + fill.focus[0]}% ${50 + fill.focus[1]}%`,\n }}\n >\n {shot(fill.shot)}\n </AbsoluteFill>\n </div>\n );\n };\n\n const panel = (\n key: string,\n rect: Rect,\n radius: number,\n edge: number,\n from: Fill,\n to: Fill,\n swap: number,\n ) => (\n <div\n key={key}\n style={{\n position: \"absolute\",\n left: rect.x,\n top: rect.y,\n width: rect.w,\n height: rect.h,\n borderRadius: Math.min(radius, rect.w / 2, rect.h / 2),\n overflow: \"hidden\",\n boxShadow: edge > 0.01 ? panelShadow(edge) : undefined,\n }}\n >\n {swap < 1 ? (\n <AbsoluteFill\n style={{ transform: `translateY(${-0.4 * rect.h * swap}px)` }}\n >\n {content(from, rect)}\n <AbsoluteFill\n style={{ background: \"#0A0A0B\", opacity: 0.22 * swap }}\n />\n </AbsoluteFill>\n ) : null}\n {swap > 0 ? (\n <AbsoluteFill\n style={{\n transform: `translateY(${rect.h * (1 - swap)}px)`,\n boxShadow:\n swap < 1\n ? `0 ${-10 * u}px ${30 * u}px rgba(0,0,0,${0.3 * (1 - swap)})`\n : undefined,\n }}\n >\n {content(to, rect)}\n </AbsoluteFill>\n ) : null}\n <AbsoluteFill\n style={{\n borderRadius: Math.min(radius, rect.w / 2, rect.h / 2),\n boxShadow: `inset 0 0 0 1px ${hairline}`,\n opacity: edge,\n }}\n />\n </div>\n );\n\n let body: React.ReactNode;\n if (frame < tOpen) {\n body = (\n <AbsoluteFill style={{ transform: `scale(${openerPush})` }}>\n {shot(0)}\n </AbsoluteFill>\n );\n } else if (frame < tGrow) {\n const q = spring({ frame: frame - tOpen, fps, config: CARD });\n const rects = grid(2, 2, W, H, M * q, G * q);\n const quads = grid(2, 2, W, H, 0, 0);\n body = rects.map((rect, i) =>\n panel(\n `a${i}`,\n rect,\n R * q,\n q,\n { type: \"piece\", shot: 0, push: openerPush, source: quads[i] },\n {\n type: \"own\",\n shot: 1 + i,\n push: ownPush(tSwap1),\n focus: FOCI[i],\n nominal: rect,\n },\n EASE_SWAP(p(tSwap1 + i * 2, SWAP)),\n ),\n );\n } else {\n const qg = spring({ frame: frame - tGrow, fps, config: CARD });\n const qm =\n frame >= tMerge + MERGE\n ? 1\n : Math.min(\n 1,\n spring({\n frame: frame - tMerge,\n fps,\n config: MORPH_SPRING,\n durationInFrames: MERGE,\n }),\n );\n const m = M * (1 - qm);\n const g = G * (1 - qm);\n const cells = grid(3, 3, W, H, m, g);\n const full3 = grid(3, 3, W, H, M, G);\n const thirds = grid(3, 3, W, H, 0, 0);\n const two = grid(2, 2, W, H, M, G);\n const span = (k: number, axis: \"x\" | \"y\") => {\n const a = axis === \"x\" ? two[k] : two[k * 2];\n return axis === \"x\" ? [a.x, a.x + a.w] : [a.y, a.y + a.h];\n };\n const seed = (r: number, c: number): Rect => {\n const xs = c === 1 ? [W / 2, W / 2] : span(c === 0 ? 0 : 1, \"x\");\n const ys = r === 1 ? [H / 2, H / 2] : span(r === 0 ? 0 : 1, \"y\");\n return { x: xs[0], y: ys[0], w: xs[1] - xs[0], h: ys[1] - ys[0] };\n };\n let fresh = 0;\n const panels: React.ReactNode[] = [];\n for (let r = 0; r < 3; r++) {\n for (let c = 0; c < 3; c++) {\n const idx = r * 3 + c;\n const corner = CORNERS.findIndex(([cr, cc]) => cr === r && cc === c);\n const isCorner = corner >= 0;\n const rect = isCorner\n ? lerpRect(two[corner], cells[idx], qg)\n : lerpRect(seed(r, c), cells[idx], qg);\n const ownShot = isCorner ? 1 + corner : 5 + fresh++;\n const own: Fill = {\n type: \"own\",\n shot: ownShot,\n push: ownPush(isCorner ? tSwap1 : tGrow),\n focus: FOCI[isCorner ? corner : 4 + fresh - 1],\n nominal: isCorner ? rect : full3[idx],\n };\n if (rect.w < 0.5 || rect.h < 0.5) continue;\n panels.push(\n panel(\n `b${idx}`,\n rect,\n R * (1 - qm),\n 1 - qm,\n own,\n {\n type: \"piece\",\n shot: 10,\n push: closerPush,\n source: thirds[idx],\n },\n EASE_SWAP(p(tSwap2 + (r + c) * 2, SWAP)),\n ),\n );\n }\n }\n body =\n qm >= 1 ? (\n <AbsoluteFill style={{ transform: `scale(${closerPush})` }}>\n {shot(10)}\n </AbsoluteFill>\n ) : (\n <>\n {qm > 0.9 ? (\n <AbsoluteFill style={{ transform: `scale(${closerPush})` }}>\n {shot(10)}\n </AbsoluteFill>\n ) : null}\n {panels}\n </>\n );\n }\n\n return (\n <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n <GshGround\n preset={ground ?? (lightStage ? \"glasswork\" : \"velvet-hour\")}\n params={groundParams}\n timeOffset={4}\n timeScale={0.5}\n />\n {body}\n <Grain opacity={theme === \"light\" ? 0.04 : 0.055} />\n </AbsoluteFill>\n );\n}\n",
"type": "registry:component",
"target": "components/remocn/grid-montage.tsx"
}
],
"type": "registry:component"
}