Skip to content

Production-ready animations, transitions, backgrounds, and scenes for Remotion

5.9 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 1180,
      "height": 676
    },
    "displayName": "Reel",
    "initialProps": null,
    "slug": "reel",
    "sourceCode": "import { AbsoluteFill, Easing, Img, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\nconst clamp = {\n  extrapolateLeft: \"clamp\" as const,\n  extrapolateRight: \"clamp\" as const,\n};\nconst EASE_OUT = Easing.out(Easing.cubic);\n\ntype ReelProps = {\n  images: string[];\n  width?: number;\n  height?: number;\n  radius?: number;\n  step?: number;\n  reveal?: number;\n  objectPosition?: string;\n  background?: string;\n};\n\nfunction ReelBase({\n  images,\n  width = 1180,\n  height = 676,\n  radius = 16,\n  step = 20,\n  reveal = 13,\n  objectPosition = \"top\",\n  background = \"#050506\",\n}: ReelProps) {\n  const frame = useCurrentFrame();\n  const { width: compWidth, height: compHeight } = useVideoConfig();\n  const left = (compWidth - width) / 2;\n  const top = (compHeight - height) / 2;\n\n  return (\n    <AbsoluteFill>\n      {images.map((src, i) => {\n        const p = interpolate(frame, [i * step, i * step + reveal], [0, 1], {\n          ...clamp,\n          easing: EASE_OUT,\n        });\n        if (p <= 0) return null;\n        const inset = (1 - p) * 50;\n        const imgScale = interpolate(p, [0, 1], [1.08, 1], clamp);\n        return (\n          <div\n            key={i}\n            style={{\n              position: \"absolute\",\n              left,\n              top,\n              width,\n              height,\n              zIndex: i,\n              clipPath: `inset(${inset}% ${inset}% round ${radius}px)`,\n              WebkitClipPath: `inset(${inset}% ${inset}% round ${radius}px)`,\n              background,\n              boxShadow: \"0 30px 80px rgba(0,0,0,0.6)\",\n              willChange: \"clip-path\",\n            }}\n          >\n            <Img\n              src={src}\n              style={{\n                width: \"100%\",\n                height: \"100%\",\n                objectFit: \"cover\",\n                objectPosition,\n                scale: `${imgScale}`,\n                willChange: \"transform\",\n              }}\n            />\n            <div\n              style={{\n                position: \"absolute\",\n                inset: 0,\n                borderRadius: radius,\n                border: \"1px solid rgba(255,255,255,0.08)\",\n              }}\n            />\n          </div>\n        );\n      })}\n    </AbsoluteFill>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  width: {\n    type: \"number\",\n    min: 600,\n    max: 1280,\n    step: 20,\n    default: 1180,\n    description: \"Card width\",\n    hiddenFromList: false,\n  },\n  height: {\n    type: \"number\",\n    min: 360,\n    max: 720,\n    step: 4,\n    default: 676,\n    description: \"Card height\",\n    hiddenFromList: false,\n  },\n  radius: {\n    type: \"number\",\n    min: 0,\n    max: 40,\n    step: 1,\n    default: 16,\n    description: \"Corner radius\",\n    hiddenFromList: false,\n  },\n  step: {\n    type: \"number\",\n    min: 6,\n    max: 40,\n    step: 1,\n    default: 20,\n    description: \"Frames / image\",\n    hiddenFromList: false,\n  },\n  reveal: {\n    type: \"number\",\n    min: 4,\n    max: 30,\n    step: 1,\n    default: 13,\n    description: \"Reveal frames\",\n    hiddenFromList: false,\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([\"width\",\"height\",\"radius\",\"step\",\"reveal\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  width: 1180,\n  height: 676,\n  radius: 16,\n  step: 20,\n  reveal: 13,\n  speed: 1,\n};\n\ntype ReelElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof ReelBase>;\n\nconst ReelInner = forwardRef<\n  HTMLDivElement,\n  ReelElementProps & { 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 ?? \"<Reel>\"}\n      outlineRef={outlineRef}\n    >\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n        }}\n      >\n        <div\n          ref={outlineRef}\n          style={{\n            position: \"relative\",\n            width: 1180,\n            height: 676,\n            ...style,\n          }}\n        >\n          <ReelBase\n            {...(componentProps as unknown as ComponentProps<typeof ReelBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const Reel = Interactive.withSchema({\n  Component: ReelInner,\n  componentName: \"<Reel>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 160,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 160
}