Skip to content

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

6.3 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 230,
      "height": 100
    },
    "displayName": "Top-Down Letters",
    "initialProps": null,
    "slug": "top-down-letters",
    "sourceCode": "import { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface TopDownLettersProps {\n  text: string;\n  staggerDelay?: number;\n  distance?: number;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  speed?: number;\n  className?: string;\n}\n\nfunction TopDownLettersBase({\n  text,\n  staggerDelay = 3,\n  distance = 46,\n  fontSize = 72,\n  color = \"#171717\",\n  fontWeight = 600,\n  speed = 1,\n  className,\n}: TopDownLettersProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const chars = Array.from(text);\n  const charDurationFrames = 12;\n  const charTravelFrames = 7;\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        background: \"transparent\",\n      }}\n    >\n      <span\n        className={className}\n        style={{\n          fontSize,\n          fontWeight,\n          color,\n          letterSpacing: \"-0.05em\",\n          fontFamily:\n            \"var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif\",\n        }}\n      >\n        {chars.map((char, i) => {\n          const local = frame - i * staggerDelay;\n          const easing = Easing.bezier(0.18, 1, 0.32, 1);\n          const opacity = interpolate(local, [0, charDurationFrames], [0, 1], {\n            extrapolateLeft: \"clamp\",\n            extrapolateRight: \"clamp\",\n            easing,\n          });\n          const y = interpolate(local, [0, charTravelFrames], [-distance, 0], {\n            extrapolateLeft: \"clamp\",\n            extrapolateRight: \"clamp\",\n            easing,\n          });\n          return (\n            <span\n              key={i}\n              style={{\n                display: \"inline-block\",\n                whiteSpace: \"pre\",\n                backfaceVisibility: \"hidden\",\n                transformOrigin: \"50% 55%\",\n                opacity,\n                translate: `0 ${y}px`,\n              }}\n            >\n              {char}\n            </span>\n          );\n        })}\n      </span>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"Signal\",\n    description: \"Text\",\n  },\n  staggerDelay: {\n    type: \"number\",\n    min: 1,\n    max: 12,\n    step: 1,\n    default: 3,\n    description: \"Stagger\",\n    hiddenFromList: false,\n  },\n  distance: {\n    type: \"number\",\n    min: 0,\n    max: 120,\n    step: 1,\n    default: 46,\n    description: \"Distance\",\n    hiddenFromList: false,\n  },\n  fontSize: {\n    type: \"number\",\n    min: 12,\n    max: 160,\n    step: 1,\n    default: 72,\n    description: \"Font size\",\n    hiddenFromList: false,\n  },\n  color: {\n    type: \"color\",\n    default: \"#171717\",\n    description: \"Color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"600\",\n    variants: {\n      \"400\": {},\n      \"500\": {},\n      \"600\": {},\n      \"700\": {},\n    },\n    description: \"Font weight\",\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  width: {\n    type: \"number\",\n    default: 230,\n    min: 10,\n    step: 10,\n    description: \"Width\",\n  },\n  height: {\n    type: \"number\",\n    default: 100,\n    min: 10,\n    step: 10,\n    description: \"Height\",\n  },\n  ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"text\",\"staggerDelay\",\"distance\",\"fontSize\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Signal\",\n  staggerDelay: 3,\n  distance: 46,\n  fontSize: 72,\n  color: \"#171717\",\n  fontWeight: \"600\",\n  speed: 1,\n};\n\ntype TopDownLettersElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof TopDownLettersBase>;\n\nconst TopDownLettersInner = forwardRef<\n  HTMLDivElement,\n  TopDownLettersElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 230, height = 100, ...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 ?? \"<TopDownLetters>\"}\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,\n            height,\n            ...style,\n          }}\n        >\n          <TopDownLettersBase\n            {...(componentProps as unknown as ComponentProps<typeof TopDownLettersBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const TopDownLetters = Interactive.withSchema({\n  Component: TopDownLettersInner,\n  componentName: \"<TopDownLetters>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 60,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 60
}