Skip to content

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

8.8 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 640,
      "height": 100
    },
    "displayName": "Short Slide Down",
    "initialProps": null,
    "slug": "short-slide-down",
    "sourceCode": "import { forwardRef, useImperativeHandle, useMemo, useRef, type ComponentProps } from \"react\";\nimport { Easing, Interactive, Sequence, interpolate, useCurrentFrame, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ninterface ShortSlideDownProps {\n  text: string;\n  entryOffset?: number;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  speed?: number;\n  className?: string;\n}\n\nconst FONT_FAMILY =\n  \"var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif\";\n\nfunction ShortSlideDownBase({\n  text,\n  entryOffset = 28,\n  fontSize = 72,\n  color = \"#171717\",\n  fontWeight = 600,\n  speed = 1,\n  className,\n}: ShortSlideDownProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const words = useMemo(() => text.split(\" \"), [text]);\n  const n = words.length;\n\n  const lineGap = 12;\n  const rowHeight = fontSize;\n  const firstDur = 11;\n  const pushDur = 15;\n  const travelDur = 8;\n  const entryScale = 0.992;\n  const entryBlur = 2.4;\n  const reflowBlur = 0.7;\n  const firstWordY = -14;\n  const easing = Easing.bezier(0.2, 0.8, 0.2, 1);\n\n  const positionsAt = useMemo(() => {\n    const out: number[][] = [];\n    for (let k = 1; k <= n; k++) {\n      const total = rowHeight * k + lineGap * (k - 1);\n      const start = -total / 2 + rowHeight / 2;\n      const ys: number[] = [];\n      for (let j = 0; j < k; j++) ys.push(start + j * (rowHeight + lineGap));\n      out.push(ys);\n    }\n    return out;\n  }, [n, rowHeight]);\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      <div\n        className={className}\n        style={{\n          position: \"relative\",\n          fontSize,\n          fontWeight,\n          color,\n          letterSpacing: \"-0.03em\",\n          fontFamily: FONT_FAMILY,\n          whiteSpace: \"nowrap\",\n        }}\n      >\n        {words.map((word, j) => {\n          const entryStart = j === 0 ? 0 : firstDur + (j - 1) * pushDur;\n          const entryEnd = entryStart + (j === 0 ? firstDur : pushDur);\n          const targetY = positionsAt[j][j];\n          const yFrom = j === 0 ? firstWordY : targetY - entryOffset;\n\n          let y = targetY;\n          let opacity = 1;\n          let scale = 1;\n          let blur = 0;\n\n          if (frame < entryStart) {\n            opacity = 0;\n            y = yFrom;\n            scale = entryScale;\n            blur = entryBlur;\n          } else if (frame <= entryEnd) {\n            const range: [number, number] = [entryStart, entryEnd];\n            const travelRange: [number, number] = [\n              entryStart,\n              Math.min(entryStart + travelDur, entryEnd),\n            ];\n            const opts = {\n              extrapolateLeft: \"clamp\" as const,\n              extrapolateRight: \"clamp\" as const,\n              easing,\n            };\n            y = interpolate(frame, travelRange, [yFrom, targetY], opts);\n            opacity = interpolate(frame, range, [0, 1], opts);\n            scale = interpolate(frame, range, [entryScale, 1], opts);\n            blur = interpolate(frame, range, [entryBlur, 0], opts);\n          } else {\n            for (let w = j + 1; w < n; w++) {\n              const pushStart = firstDur + (w - 1) * pushDur;\n              const pushEnd = pushStart + pushDur;\n              const fromY = positionsAt[w - 1][j];\n              const toY = positionsAt[w][j];\n              if (frame >= pushEnd) {\n                y = toY;\n              } else if (frame >= pushStart) {\n                y = interpolate(\n                  frame,\n                  [pushStart, Math.min(pushStart + travelDur, pushEnd)],\n                  [fromY, toY],\n                  {\n                    extrapolateLeft: \"clamp\",\n                    extrapolateRight: \"clamp\",\n                    easing,\n                  },\n                );\n                blur = interpolate(\n                  frame,\n                  [pushStart, (pushStart + pushEnd) / 2, pushEnd],\n                  [0, reflowBlur, 0],\n                  { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" },\n                );\n                break;\n              } else {\n                y = fromY;\n                break;\n              }\n            }\n          }\n\n          return (\n            <span\n              key={j}\n              style={{\n                position: \"absolute\",\n                left: \"50%\",\n                top: \"50%\",\n                whiteSpace: \"nowrap\",\n                backfaceVisibility: \"hidden\",\n                transform: `translate(-50%, -50%) translate3d(0px, ${y}px, 0) scale(${scale})`,\n                filter: `blur(${blur}px)`,\n                opacity,\n              }}\n            >\n              {word}\n            </span>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"Build from above.\",\n    description: \"Text\",\n  },\n  entryOffset: {\n    type: \"number\",\n    min: 8,\n    max: 80,\n    step: 1,\n    default: 28,\n    description: \"Entry offset\",\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: 640,\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\",\"entryOffset\",\"fontSize\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Build from above.\",\n  entryOffset: 28,\n  fontSize: 72,\n  color: \"#171717\",\n  fontWeight: \"600\",\n  speed: 1,\n};\n\ntype ShortSlideDownElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof ShortSlideDownBase>;\n\nconst ShortSlideDownInner = forwardRef<\n  HTMLDivElement,\n  ShortSlideDownElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 640, 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 ?? \"<ShortSlideDown>\"}\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          <ShortSlideDownBase\n            {...(componentProps as unknown as ComponentProps<typeof ShortSlideDownBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const ShortSlideDown = Interactive.withSchema({\n  Component: ShortSlideDownInner,\n  componentName: \"<ShortSlideDown>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 60,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 60
}