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": [],
"dimensions": null,
"displayName": "Accordion Unfold",
"initialProps": null,
"slug": "accordion-unfold",
"sourceCode": "import { AbsoluteFill, Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport React, { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ntype AccordionUnfoldProps = {\n /** Lockup printed across the card. Use a color that reads on `color`. Falls back to a placeholder \"remocn\" lockup. */\n children?: React.ReactNode;\n /** Number of vertical pleats. */\n panels?: number;\n /** Paper color of the card. */\n color?: string;\n /** Darkness of the panels facing away from the light, 0 to 1. */\n shade?: number;\n backgroundColor?: string;\n /** Fold angle of each pleat at the start, in degrees. */\n foldAngle?: number;\n speed?: number;\n};\n\nconst accordionUnfoldDefaults = {\n panels: 6,\n color: \"#FFFFFF\",\n shade: 0.55,\n backgroundColor: \"#111111\",\n foldAngle: 82,\n speed: 1,\n};\n\nconst START = 4;\nconst clamp = {\n extrapolateLeft: \"clamp\" as const,\n extrapolateRight: \"clamp\" as const,\n};\n\nconst PLACEHOLDER_FONT =\n \"-apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Helvetica, Arial, sans-serif\";\n\n// Neutral lockup shown when no children are passed.\nfunction PlaceholderLockup({\n mark,\n dot,\n text,\n scale = 1,\n}: {\n mark: string;\n dot: string;\n text: string;\n scale?: number;\n}) {\n return (\n <div style={{ display: \"flex\", alignItems: \"center\", gap: 28 * scale }}>\n <div\n style={{\n width: 120 * scale,\n height: 120 * scale,\n borderRadius: 32 * scale,\n backgroundColor: mark,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n <div\n style={{\n width: 36 * scale,\n height: 36 * scale,\n borderRadius: \"50%\",\n backgroundColor: dot,\n }}\n />\n </div>\n <span\n style={{\n fontFamily: PLACEHOLDER_FONT,\n fontSize: 104 * scale,\n fontWeight: 800,\n letterSpacing: \"-0.04em\",\n color: text,\n }}\n >\n remocn\n </span>\n </div>\n );\n}\n\nfunction AccordionUnfoldBase(props: AccordionUnfoldProps) {\n const { children, panels, color, shade, backgroundColor, foldAngle, speed } =\n { ...accordionUnfoldDefaults, ...props };\n const frame = useCurrentFrame();\n const { width, height, fps } = useVideoConfig();\n const t = frame * Math.max(0, speed);\n const n = Math.max(2, Math.round(panels));\n const cardW = Math.round(Math.min(width * 0.66, height * 1.3));\n const cardH = Math.round(Math.min(height * 0.4, cardW * 0.4));\n const pw = cardW / n;\n\n const open = spring({\n frame: t - START,\n fps,\n config: { damping: 15, stiffness: 70, mass: 0.9 },\n });\n const theta = foldAngle * (1 - open);\n const rad = (theta * Math.PI) / 180;\n // Keep the pleated stack centered while its projected width grows.\n const shift = (cardW - cardW * Math.cos(rad)) / 2;\n const lift = interpolate(t, [0, START + 2], [0.92, 1], clamp);\n const appear = interpolate(t, [0, 3], [0, 1], clamp);\n const flat = Math.abs(theta) < 0.3;\n\n const print = (offset: number) => (\n <div\n style={{\n position: \"absolute\",\n top: 0,\n left: -offset,\n width: cardW,\n height: cardH,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n }}\n >\n {children ?? (\n <PlaceholderLockup\n mark={backgroundColor}\n dot={color}\n text={backgroundColor}\n scale={0.8}\n />\n )}\n </div>\n );\n\n const panel = (i: number): React.ReactNode => {\n if (i >= n) return null;\n const angle = i === 0 ? theta : (i % 2 === 1 ? -2 : 2) * theta;\n const facing = i % 2 === 0 ? 1 : -1;\n const tilt = Math.abs(Math.sin(rad));\n const darkness = facing > 0 ? shade * tilt : shade * 0.25 * tilt;\n return (\n <div\n style={{\n position: \"absolute\",\n top: 0,\n left: i === 0 ? 0 : pw,\n width: pw,\n height: cardH,\n transformOrigin: \"0% 50%\",\n transform: `rotateY(${angle}deg)`,\n transformStyle: \"preserve-3d\",\n }}\n >\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n // A hair of bleed hides antialiased seams between pleats.\n width: pw + 1,\n overflow: \"hidden\",\n backgroundColor: color,\n backfaceVisibility: \"hidden\",\n }}\n >\n {print(i * pw)}\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n background:\n facing > 0\n ? `linear-gradient(90deg, rgba(0,0,0,${darkness * 0.6}), rgba(0,0,0,${darkness}))`\n : `linear-gradient(90deg, rgba(255,255,255,${0.12 * tilt}), rgba(0,0,0,${darkness}))`,\n }}\n />\n </div>\n {panel(i + 1)}\n </div>\n );\n };\n\n return (\n <AbsoluteFill\n style={{\n backgroundColor,\n alignItems: \"center\",\n justifyContent: \"center\",\n perspective: cardW * 1.8,\n }}\n >\n <div\n style={{\n position: \"relative\",\n width: cardW,\n height: cardH,\n opacity: appear,\n transform: `translateX(${shift}px) scale(${lift})`,\n transformStyle: \"preserve-3d\",\n }}\n >\n {flat ? (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n backgroundColor: color,\n overflow: \"hidden\",\n }}\n >\n {print(0)}\n </div>\n ) : (\n panel(0)\n )}\n </div>\n </AbsoluteFill>\n );\n}\n\nconst elementSchema = {\n ...Interactive.baseSchema,\n panels: {\n type: \"number\",\n default: 6,\n min: 2,\n max: 12,\n step: 1,\n description: \"Panels\",\n hiddenFromList: false,\n },\n foldAngle: {\n type: \"number\",\n default: 82,\n min: 10,\n max: 89,\n step: 1,\n description: \"Fold angle\",\n hiddenFromList: false,\n },\n shade: {\n type: \"number\",\n default: 0.55,\n min: 0,\n max: 1,\n step: 0.05,\n description: \"Shade\",\n hiddenFromList: false,\n },\n color: {\n type: \"color\",\n default: \"#FFFFFF\",\n description: \"Paper\",\n },\n backgroundColor: {\n type: \"color\",\n default: \"#111111\",\n description: \"Background\",\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([\"panels\",\"foldAngle\",\"shade\",\"color\",\"backgroundColor\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n panels: 6,\n foldAngle: 82,\n shade: 0.55,\n color: \"#FFFFFF\",\n backgroundColor: \"#111111\",\n speed: 1,\n};\n\ntype AccordionUnfoldElementProps = InteractiveBaseProps &\n InteractiveTransformProps &\n ComponentProps<typeof AccordionUnfoldBase>;\n\nconst AccordionUnfoldInner = forwardRef<\n HTMLDivElement,\n AccordionUnfoldElementProps & { 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 ?? \"<AccordionUnfold>\"}\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 <AccordionUnfoldBase\n {...(componentProps as unknown as ComponentProps<typeof AccordionUnfoldBase>)}\n />\n </div>\n </Sequence>\n );\n});\n\nexport const AccordionUnfold = Interactive.withSchema({\n Component: AccordionUnfoldInner,\n componentName: \"<AccordionUnfold>\",\n componentIdentity: null,\n schema: elementSchema,\n supportsEffects: false,\n});\n",
"durationInFrames": 26,
"installationMode": "component-owned-sequence"
},
"durationInFrames": 26
}