Skip to content

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

7.3 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 640,
      "height": 100
    },
    "displayName": "Fade Through",
    "initialProps": null,
    "slug": "fade-through",
    "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 FadeThroughProps {\n  fromText: string;\n  toText: string;\n  fontSize?: number;\n  color?: string;\n  fontWeight?: number;\n  speed?: number;\n  className?: string;\n}\n\nfunction FadeThroughBase({\n  fromText,\n  toText,\n  fontSize = 72,\n  color = \"#171717\",\n  fontWeight = 600,\n  speed = 1,\n  className,\n}: FadeThroughProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const exitDur = 8;\n  const enterDur = 13;\n  const overlapF = 1;\n  const microDelayF = 2;\n\n  const exitTotal = exitDur;\n  const newStart = Math.max(0, exitTotal - overlapF + microDelayF);\n\n  const exitEasing = Easing.bezier(0.4, 0, 1, 1);\n  const enterEasing = Easing.bezier(0.2, 0, 0, 1);\n\n  const fromOpacity = interpolate(frame, [0, exitDur], [1, 0], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: exitEasing,\n  });\n  const fromY = interpolate(frame, [0, exitDur], [0, -4], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: exitEasing,\n  });\n\n  const local = frame - newStart;\n  const toOpacity = interpolate(local, [0, enterDur], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: enterEasing,\n  });\n  const toY = interpolate(local, [0, enterDur], [6, 0], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: enterEasing,\n  });\n  const toScale = interpolate(local, [0, enterDur], [0.99, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: enterEasing,\n  });\n  const blurVal = interpolate(local, [0, enterDur], [2, 0], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: enterEasing,\n  });\n\n  const fontStack =\n    \"var(--font-geist-sans), -apple-system, BlinkMacSystemFont, sans-serif\";\n\n  return (\n    <div\n      className={className}\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        background: \"transparent\",\n      }}\n    >\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n        }}\n      >\n        <span\n          style={{\n            fontSize,\n            fontWeight,\n            color,\n            letterSpacing: \"-0.03em\",\n            fontFamily: fontStack,\n            display: \"inline-block\",\n            transformOrigin: \"50% 50%\",\n            opacity: fromOpacity,\n            translate: `0 ${fromY}px`,\n          }}\n        >\n          {fromText}\n        </span>\n      </div>\n\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          display: \"flex\",\n          alignItems: \"center\",\n          justifyContent: \"center\",\n        }}\n      >\n        <span\n          style={{\n            fontSize,\n            fontWeight,\n            color,\n            letterSpacing: \"-0.03em\",\n            fontFamily: fontStack,\n            display: \"inline-block\",\n            transformOrigin: \"50% 50%\",\n            opacity: toOpacity,\n            translate: `0 ${toY}px`,\n            scale: `${toScale}`,\n            filter: `blur(${blurVal}px)`,\n          }}\n        >\n          {toText}\n        </span>\n      </div>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  fromText: {\n    type: \"text-content\",\n    default: \"Calm transitions.\",\n    description: \"From text\",\n  },\n  toText: {\n    type: \"text-content\",\n    default: \"Fade through content.\",\n    description: \"To text\",\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([\"fromText\",\"toText\",\"fontSize\",\"color\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  fromText: \"Calm transitions.\",\n  toText: \"Fade through content.\",\n  fontSize: 72,\n  color: \"#171717\",\n  fontWeight: \"600\",\n  speed: 1,\n};\n\ntype FadeThroughElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof FadeThroughBase>;\n\nconst FadeThroughInner = forwardRef<\n  HTMLDivElement,\n  FadeThroughElementProps & { 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 ?? \"<FadeThrough>\"}\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          <FadeThroughBase\n            {...(componentProps as unknown as ComponentProps<typeof FadeThroughBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const FadeThrough = Interactive.withSchema({\n  Component: FadeThroughInner,\n  componentName: \"<FadeThrough>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 90,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 90
}