Skip to content

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

9.9 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Fog Rise",
    "initialProps": null,
    "slug": "fog-rise",
    "sourceCode": "import { Interactive, Sequence, interpolate, spring, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\nimport { forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\n\ninterface FogRiseProps {\n  text: string;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  stagger?: number;\n  blur?: number;\n  tilt?: number;\n  depth?: number;\n  lift?: number;\n  drift?: number;\n  exitAt?: number;\n  exitAccel?: number;\n  mass?: number;\n  stiffness?: number;\n  damping?: number;\n  spreadGap?: number;\n  tracking?: number;\n  resolveFrames?: number;\n  fadeFrames?: number;\n  speed?: number;\n  className?: string;\n}\n\nfunction fogRiseLength(\n  text: string,\n  stagger = 5,\n  resolveFrames = 22,\n): number {\n  const chars = Array.from(text);\n  if (chars.length === 0) return 0;\n  const center = (chars.length - 1) / 2;\n  const maxRing = Math.floor(center);\n  return maxRing * stagger + resolveFrames;\n}\n\nfunction FogRiseBase({\n  text,\n  fontSize = 304,\n  color = \"#004CFF\",\n  fontWeight = 400,\n  stagger = 5,\n  blur = 0.17,\n  tilt = 55,\n  depth = 5,\n  lift = 0.85,\n  drift = 0.005,\n  exitAt = 60,\n  exitAccel = 0.04,\n  mass = 1.3,\n  stiffness = 60,\n  damping = 13,\n  spreadGap = 0.07,\n  tracking = -0.07,\n  resolveFrames = 22,\n  fadeFrames = 18,\n  speed = 1,\n  className,\n}: FogRiseProps) {\n  const frame = useCurrentFrame() * speed;\n  const { fps } = useVideoConfig();\n\n  const chars = Array.from(text);\n  const center = (chars.length - 1) / 2;\n  const minRing = chars.length % 2 === 0 ? 0.5 : 0;\n  const maxRing = Math.floor(center);\n\n  const converge = spring({\n    frame,\n    fps,\n    config: { mass, stiffness, damping },\n  });\n  const angle = tilt * (1 - converge);\n  const liftY = lift * fontSize * (1 - converge);\n  const driftY = drift * fontSize * frame;\n  const exitT = exitAt > 0 ? Math.max(frame - exitAt, 0) : 0;\n  const exitY = 0.5 * exitAccel * exitT * exitT * fontSize;\n  const gap = spreadGap * fontSize * (1 - converge);\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"flex-end\",\n        justifyContent: \"center\",\n        paddingBottom: \"6%\",\n        whiteSpace: \"nowrap\",\n        perspective: `${depth * fontSize}px`,\n        background: \"transparent\",\n      }}\n    >\n      <span\n        className={className}\n        style={{\n          transform: `translateY(${liftY - driftY - exitY}px) rotateX(${-angle}deg)`,\n          transformOrigin: \"50% 100%\",\n          fontSize,\n          fontWeight,\n          color,\n          letterSpacing: `${tracking}em`,\n          lineHeight: 1.15,\n          fontFamily:\n            \"var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)\",\n        }}\n      >\n        {chars.map((char, j) => {\n          const ring = Math.abs(j - center) - minRing;\n          const startAt = ring * stagger;\n\n          const opacity = interpolate(\n            frame,\n            [startAt, startAt + fadeFrames],\n            [0, 1],\n            { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" },\n          );\n\n          const charBlur =\n            blur *\n            fontSize *\n            interpolate(frame, [0, maxRing * stagger + resolveFrames], [1, 0], {\n              extrapolateLeft: \"clamp\",\n              extrapolateRight: \"clamp\",\n            });\n\n          return (\n            <span\n              key={j}\n              style={{\n                display: \"inline-block\",\n                whiteSpace: \"pre\",\n                marginRight: j < chars.length - 1 ? gap : undefined,\n                opacity,\n                filter: charBlur > 0.05 ? `blur(${charBlur}px)` : undefined,\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: \"Remocn\",\n    description: \"Text\",\n  },\n  fontSize: {\n    type: \"number\",\n    min: 40,\n    max: 560,\n    step: 4,\n    default: 304,\n    description: \"Font size\",\n    hiddenFromList: false,\n  },\n  stagger: {\n    type: \"number\",\n    min: 0,\n    max: 15,\n    step: 1,\n    default: 5,\n    description: \"Frames / ring\",\n    hiddenFromList: false,\n  },\n  blur: {\n    type: \"number\",\n    min: 0,\n    max: 0.5,\n    step: 0.01,\n    default: 0.17,\n    description: \"Blur (em)\",\n    hiddenFromList: false,\n  },\n  tilt: {\n    type: \"number\",\n    min: 0,\n    max: 90,\n    step: 5,\n    default: 55,\n    description: \"Start tilt (deg)\",\n    hiddenFromList: false,\n  },\n  depth: {\n    type: \"number\",\n    min: 1,\n    max: 8,\n    step: 0.5,\n    default: 5,\n    description: \"Perspective depth\",\n    hiddenFromList: false,\n  },\n  lift: {\n    type: \"number\",\n    min: 0,\n    max: 1,\n    step: 0.05,\n    default: 0.85,\n    description: \"Lift (em)\",\n    hiddenFromList: false,\n  },\n  drift: {\n    type: \"number\",\n    min: 0,\n    max: 0.012,\n    step: 0.001,\n    default: 0.005,\n    description: \"Drift (em / frame)\",\n    hiddenFromList: false,\n  },\n  exitAt: {\n    type: \"number\",\n    min: 0,\n    max: 200,\n    step: 5,\n    default: 60,\n    description: \"Exit frame\",\n    hiddenFromList: false,\n  },\n  exitAccel: {\n    type: \"number\",\n    min: 0.002,\n    max: 0.05,\n    step: 0.002,\n    default: 0.04,\n    description: \"Exit accel\",\n    hiddenFromList: false,\n  },\n  mass: {\n    type: \"number\",\n    min: 0.3,\n    max: 3,\n    step: 0.1,\n    default: 1.3,\n    description: \"Mass\",\n    hiddenFromList: false,\n  },\n  stiffness: {\n    type: \"number\",\n    min: 30,\n    max: 250,\n    step: 10,\n    default: 60,\n    description: \"Stiffness\",\n    hiddenFromList: false,\n  },\n  damping: {\n    type: \"number\",\n    min: 5,\n    max: 30,\n    step: 1,\n    default: 13,\n    description: \"Damping\",\n    hiddenFromList: false,\n  },\n  spreadGap: {\n    type: \"number\",\n    min: 0,\n    max: 0.3,\n    step: 0.01,\n    default: 0.07,\n    description: \"Spread gap (em)\",\n    hiddenFromList: false,\n  },\n  tracking: {\n    type: \"number\",\n    min: -0.12,\n    max: 0,\n    step: 0.005,\n    default: -0.07,\n    description: \"Tracking (em)\",\n    hiddenFromList: false,\n  },\n  resolveFrames: {\n    type: \"number\",\n    min: 8,\n    max: 50,\n    step: 1,\n    default: 22,\n    description: \"Converge frames\",\n    hiddenFromList: false,\n  },\n  fadeFrames: {\n    type: \"number\",\n    min: 2,\n    max: 25,\n    step: 1,\n    default: 18,\n    description: \"Fade frames\",\n    hiddenFromList: false,\n  },\n  color: {\n    type: \"color\",\n    default: \"#004CFF\",\n    description: \"Color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"400\",\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  ...Interactive.transformSchema,\n} as const satisfies InteractivitySchema;\n\nconst ELEMENT_PROP_KEYS = new Set([\"text\",\"fontSize\",\"stagger\",\"blur\",\"tilt\",\"depth\",\"lift\",\"drift\",\"exitAt\",\"exitAccel\",\"mass\",\"stiffness\",\"damping\",\"spreadGap\",\"tracking\",\"resolveFrames\",\"fadeFrames\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Remocn\",\n  fontSize: 304,\n  stagger: 5,\n  blur: 0.17,\n  tilt: 55,\n  depth: 5,\n  lift: 0.85,\n  drift: 0.005,\n  exitAt: 60,\n  exitAccel: 0.04,\n  mass: 1.3,\n  stiffness: 60,\n  damping: 13,\n  spreadGap: 0.07,\n  tracking: -0.07,\n  resolveFrames: 22,\n  fadeFrames: 18,\n  color: \"#004CFF\",\n  fontWeight: \"400\",\n  speed: 1,\n};\n\ntype FogRiseElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof FogRiseBase>;\n\nconst FogRiseInner = forwardRef<\n  HTMLDivElement,\n  FogRiseElementProps & { 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 ?? \"<FogRise>\"}\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        <FogRiseBase\n          {...(componentProps as unknown as ComponentProps<typeof FogRiseBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const FogRise = Interactive.withSchema({\n  Component: FogRiseInner,\n  componentName: \"<FogRise>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 27,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 27
}