Skip to content

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

7.7 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": {
      "width": 620,
      "height": 120
    },
    "displayName": "Sheen Slide In",
    "initialProps": null,
    "slug": "sheen-slide-in",
    "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 SheenSlideInProps {\n  text: string;\n  exitAt?: number;\n  fontSize?: number;\n  baseColor?: string;\n  sheenColor?: string;\n  fontWeight?: number;\n  speed?: number;\n  className?: string;\n}\n\nconst SETTLE_AMP_EM = 1.8;\nconst SETTLE_TAU = 2.5;\nconst CREEP_AMP_EM = 0.28;\nconst CREEP_TAU = 12;\nconst FADE_FRAMES = 4;\nconst SHEEN_IN_START = 0;\nconst SHEEN_IN_END = 4;\nconst SHEEN_SWEEP_END = 48;\nconst SHEEN_OUT_START = 48;\nconst SHEEN_OUT_END = 58;\nconst EXIT_FRAMES = 4;\nconst EXIT_SCALE = 0.9;\n\nfunction sheenSlideInLength(exitAt = 60): number {\n  return exitAt + EXIT_FRAMES;\n}\n\nfunction travelEm(frame: number): number {\n  return (\n    SETTLE_AMP_EM * Math.exp(-frame / SETTLE_TAU) +\n    CREEP_AMP_EM * Math.exp(-frame / CREEP_TAU)\n  );\n}\n\nconst exitEasing = Easing.out(Easing.quad);\n\nfunction SheenSlideInBase({\n  text,\n  exitAt = 60,\n  fontSize = 72,\n  baseColor = \"#18181b\",\n  sheenColor = \"#4f8ef7\",\n  fontWeight = 400,\n  speed = 1,\n  className,\n}: SheenSlideInProps) {\n  const frame = useCurrentFrame() * speed;\n\n  const x = fontSize * travelEm(frame);\n\n  const exit = interpolate(frame, [exitAt, exitAt + EXIT_FRAMES], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: exitEasing,\n  });\n\n  const opacity = interpolate(frame, [0, FADE_FRAMES], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n\n  const sheenOpacity =\n    interpolate(frame, [SHEEN_IN_START, SHEEN_IN_END], [0, 1], {\n      extrapolateLeft: \"clamp\",\n      extrapolateRight: \"clamp\",\n    }) *\n    interpolate(frame, [SHEEN_OUT_START, SHEEN_OUT_END], [1, 0], {\n      extrapolateLeft: \"clamp\",\n      extrapolateRight: \"clamp\",\n    });\n\n  const sheenPosition = interpolate(frame, [0, SHEEN_SWEEP_END], [160, -60], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: Easing.bezier(0.42, 0, 0.58, 1),\n  });\n\n  const textStyle: React.CSSProperties = {\n    fontSize,\n    fontWeight,\n    letterSpacing: \"-0.02em\",\n    lineHeight: 1.1,\n    margin: 0,\n    fontFamily:\n      \"var(--font-geist-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif)\",\n  };\n\n  if (exit >= 1) {\n    return (\n      <div\n        style={{ position: \"absolute\", inset: 0, background: \"transparent\" }}\n      />\n    );\n  }\n\n  return (\n    <div\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        display: \"flex\",\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        whiteSpace: \"nowrap\",\n        background: \"transparent\",\n      }}\n    >\n      <div\n        style={{\n          position: \"relative\",\n          display: \"inline-block\",\n          opacity,\n          translate: `${x}px 0`,\n          scale: `${1 - (1 - EXIT_SCALE) * exit}`,\n        }}\n      >\n        <span className={className} style={{ ...textStyle, color: baseColor }}>\n          {text}\n        </span>\n        <span\n          aria-hidden\n          style={{\n            ...textStyle,\n            position: \"absolute\",\n            inset: 0,\n            color: \"transparent\",\n            backgroundClip: \"text\",\n            WebkitBackgroundClip: \"text\",\n            backgroundImage: `linear-gradient(100deg, transparent 25%, ${sheenColor} 50%, transparent 75%)`,\n            backgroundSize: \"250% 100%\",\n            backgroundPosition: `${sheenPosition}% 50%`,\n            opacity: sheenOpacity,\n          }}\n        >\n          {text}\n        </span>\n      </div>\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"Introducing\",\n    description: \"Text\",\n  },\n  exitAt: {\n    type: \"number\",\n    min: 30,\n    max: 150,\n    step: 5,\n    default: 60,\n    description: \"Exit frame\",\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  baseColor: {\n    type: \"color\",\n    default: \"#18181b\",\n    description: \"Base color\",\n  },\n  sheenColor: {\n    type: \"color\",\n    default: \"#4f8ef7\",\n    description: \"Sheen 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  width: {\n    type: \"number\",\n    default: 620,\n    min: 10,\n    step: 10,\n    description: \"Width\",\n  },\n  height: {\n    type: \"number\",\n    default: 120,\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\",\"exitAt\",\"fontSize\",\"baseColor\",\"sheenColor\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Introducing\",\n  exitAt: 60,\n  fontSize: 72,\n  baseColor: \"#18181b\",\n  sheenColor: \"#4f8ef7\",\n  fontWeight: \"400\",\n  speed: 1,\n};\n\ntype SheenSlideInElementProps = InteractiveBaseProps &\n  InteractiveTransformProps & { readonly width?: number; readonly height?: number } &\n  ComponentProps<typeof SheenSlideInBase>;\n\nconst SheenSlideInInner = forwardRef<\n  HTMLDivElement,\n  SheenSlideInElementProps & { readonly controls: SequenceControls | undefined }\n>(({ controls, name, style, width = 620, height = 120, ...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 ?? \"<SheenSlideIn>\"}\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          <SheenSlideInBase\n            {...(componentProps as unknown as ComponentProps<typeof SheenSlideInBase>)}\n          />\n        </div>\n      </div>\n    </Sequence>\n  );\n});\n\nexport const SheenSlideIn = Interactive.withSchema({\n  Component: SheenSlideInInner,\n  componentName: \"<SheenSlideIn>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 64,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 64
}