Skip to content

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

11.0 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Anamorphic Flare",
    "initialProps": null,
    "slug": "anamorphic-flare",
    "sourceCode": "import React, { forwardRef, useId, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, random, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\ntype AnamorphicFlareProps = {\n  /** Lockup revealed behind the streak. Falls back to a placeholder \"remocn\" lockup. */\n  children?: React.ReactNode;\n  /** Warm tint of the streak glow and ghosts. */\n  tint?: string;\n  /** Color of the hot core line. */\n  coreColor?: string;\n  backgroundColor?: string;\n  /** Number of ghost orbs mirrored across the frame center. */\n  ghosts?: number;\n  /** Vertical position of the streak, 0 to 1. */\n  y?: number;\n  seed?: number;\n  speed?: number;\n};\n\nconst anamorphicFlareDefaults = {\n  tint: \"#E5322D\",\n  coreColor: \"#FFFFFF\",\n  backgroundColor: \"#111111\",\n  ghosts: 4,\n  y: 0.5,\n  seed: 2,\n  speed: 1,\n};\n\nconst IGNITE = 6;\nconst CROSS_START = 4;\nconst CROSS_END = 26;\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 AnamorphicFlareBase(props: AnamorphicFlareProps) {\n  const { children, tint, coreColor, backgroundColor, ghosts, y, seed, speed } =\n    { ...anamorphicFlareDefaults, ...props };\n  const uid = `anamorphic-flare-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  const frame = useCurrentFrame();\n  const { width, height } = useVideoConfig();\n  const t = frame * Math.max(0, speed);\n  const cy = y * height;\n  const cx = width / 2;\n\n  const head = interpolate(t, [CROSS_START, CROSS_END], [0.07, 1.12], {\n    ...clamp,\n    easing: Easing.bezier(0.45, 0, 0.4, 1),\n  });\n  const hx = head * width;\n  const ignite = interpolate(t, [0, IGNITE], [0, 1], {\n    ...clamp,\n    easing: Easing.out(Easing.cubic),\n  });\n  const fade = interpolate(t, [CROSS_END - 6, CROSS_END + 2], [1, 0], clamp);\n  const power = ignite * fade;\n  const streakLen =\n    width *\n    interpolate(t, [0, 12], [0.04, 1.3], {\n      ...clamp,\n      easing: Easing.out(Easing.quad),\n    });\n  const coreH = Math.max(2, height * 0.004);\n  const glowH = height * 0.05;\n  const residual = interpolate(\n    t,\n    [CROSS_END - 2, CROSS_END + 14],\n    [0, 0.14],\n    clamp,\n  );\n  const soft = width * 0.08;\n  const mask = `linear-gradient(90deg, #000 0px, #000 ${hx - soft}px, transparent ${hx}px)`;\n\n  const ghostList = Array.from(\n    { length: Math.max(0, Math.round(ghosts)) },\n    (_, i) => {\n      const k = -1.3 + random(`anamorphic-flare-${seed}-${i}-k`) * 2.2;\n      return {\n        x: cx - (hx - cx) * k,\n        r: height * (0.025 + 0.07 * random(`anamorphic-flare-${seed}-${i}-r`)),\n        o: 0.12 + 0.18 * random(`anamorphic-flare-${seed}-${i}-o`),\n        dy: (random(`anamorphic-flare-${seed}-${i}-y`) - 0.5) * height * 0.05,\n      };\n    },\n  );\n\n  return (\n    <AbsoluteFill style={{ backgroundColor }}>\n      <svg\n        width={width}\n        height={height}\n        viewBox={`0 0 ${width} ${height}`}\n        style={{ position: \"absolute\", inset: 0 }}\n      >\n        <defs>\n          <linearGradient id={`${uid}-trail`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n            <stop offset=\"0\" stopColor={tint} stopOpacity={0} />\n            <stop offset=\"0.5\" stopColor={tint} stopOpacity={1} />\n            <stop offset=\"1\" stopColor={tint} stopOpacity={0} />\n          </linearGradient>\n        </defs>\n        <rect\n          x={0}\n          y={cy - 1}\n          width={width}\n          height={2}\n          fill={`url(#${uid}-trail)`}\n          opacity={residual}\n        />\n      </svg>\n      <AbsoluteFill\n        style={{\n          alignItems: \"center\",\n          justifyContent: \"center\",\n          WebkitMaskImage: mask,\n          maskImage: mask,\n        }}\n      >\n        {children ?? (\n          <PlaceholderLockup\n            mark={tint}\n            dot={backgroundColor}\n            text={coreColor}\n          />\n        )}\n      </AbsoluteFill>\n      <svg\n        width={width}\n        height={height}\n        viewBox={`0 0 ${width} ${height}`}\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          mixBlendMode: \"screen\",\n        }}\n      >\n        <defs>\n          <linearGradient id={`${uid}-core`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\">\n            <stop offset=\"0\" stopColor={coreColor} stopOpacity={0} />\n            <stop offset=\"0.5\" stopColor={coreColor} stopOpacity={1} />\n            <stop offset=\"1\" stopColor={coreColor} stopOpacity={0} />\n          </linearGradient>\n          <radialGradient id={`${uid}-bloom`}>\n            <stop offset=\"0\" stopColor={coreColor} stopOpacity={1} />\n            <stop offset=\"0.25\" stopColor={tint} stopOpacity={0.7} />\n            <stop offset=\"1\" stopColor={tint} stopOpacity={0} />\n          </radialGradient>\n          <radialGradient id={`${uid}-ghost`}>\n            <stop offset=\"0\" stopColor={tint} stopOpacity={0.15} />\n            <stop offset=\"0.8\" stopColor={tint} stopOpacity={0.5} />\n            <stop offset=\"1\" stopColor={tint} stopOpacity={0} />\n          </radialGradient>\n          <filter\n            id={`${uid}-blur`}\n            x={-width}\n            y={-height}\n            width={width * 3}\n            height={height * 3}\n            filterUnits=\"userSpaceOnUse\"\n          >\n            <feGaussianBlur stdDeviation={glowH * 0.35} />\n          </filter>\n        </defs>\n        <g opacity={power}>\n          <rect\n            x={hx - streakLen * 0.45}\n            y={cy - glowH / 2}\n            width={streakLen * 0.9}\n            height={glowH}\n            fill={`url(#${uid}-trail)`}\n            opacity={0.55}\n            filter={`url(#${uid}-blur)`}\n          />\n          <rect\n            x={hx - streakLen / 2}\n            y={cy - coreH / 2}\n            width={streakLen}\n            height={coreH}\n            fill={`url(#${uid}-core)`}\n          />\n          <ellipse\n            cx={hx}\n            cy={cy}\n            rx={height * 0.16}\n            ry={height * 0.1}\n            fill={`url(#${uid}-bloom)`}\n          />\n          {ghostList.map((g, i) => (\n            <circle\n              key={i}\n              cx={g.x}\n              cy={cy + g.dy}\n              r={g.r}\n              fill={`url(#${uid}-ghost)`}\n              opacity={g.o * 2}\n            />\n          ))}\n        </g>\n      </svg>\n    </AbsoluteFill>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  ghosts: {\n    type: \"number\",\n    default: 4,\n    min: 0,\n    max: 8,\n    step: 1,\n    description: \"Ghosts\",\n    hiddenFromList: false,\n  },\n  y: {\n    type: \"number\",\n    default: 0.5,\n    min: 0.1,\n    max: 0.9,\n    step: 0.01,\n    description: \"Streak height\",\n    hiddenFromList: false,\n  },\n  seed: {\n    type: \"number\",\n    default: 2,\n    min: 1,\n    max: 99,\n    step: 1,\n    description: \"Seed\",\n    hiddenFromList: false,\n  },\n  tint: {\n    type: \"color\",\n    default: \"#E5322D\",\n    description: \"Tint\",\n  },\n  coreColor: {\n    type: \"color\",\n    default: \"#FFFFFF\",\n    description: \"Core\",\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([\"ghosts\",\"y\",\"seed\",\"tint\",\"coreColor\",\"backgroundColor\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  ghosts: 4,\n  y: 0.5,\n  seed: 2,\n  tint: \"#E5322D\",\n  coreColor: \"#FFFFFF\",\n  backgroundColor: \"#111111\",\n  speed: 1,\n};\n\ntype AnamorphicFlareElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof AnamorphicFlareBase>;\n\nconst AnamorphicFlareInner = forwardRef<\n  HTMLDivElement,\n  AnamorphicFlareElementProps & { 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 ?? \"<AnamorphicFlare>\"}\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        <AnamorphicFlareBase\n          {...(componentProps as unknown as ComponentProps<typeof AnamorphicFlareBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const AnamorphicFlare = Interactive.withSchema({\n  Component: AnamorphicFlareInner,\n  componentName: \"<AnamorphicFlare>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 40,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 40
}