Skip to content

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

11.2 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [],
    "dimensions": null,
    "displayName": "Gradient Scale Cut Text",
    "initialProps": null,
    "slug": "gradient-scale-cut-text",
    "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 GradientScaleCutTextProps {\n  text?: string;\n  giantFontSize?: number;\n  compactFontSize?: number;\n  fontWeight?: number;\n  gradientStart?: string;\n  gradientEnd?: string;\n  ghostColor?: string;\n  backgroundColor?: string;\n  anchorOffsetX?: number;\n  giantTravel?: number;\n  settleTravel?: number;\n  cutFrame?: number;\n  revealSoftness?: number;\n  compactBlur?: number;\n  speed?: number;\n  className?: string;\n}\n\nconst gradientScaleCutTextLength = 36;\n\nconst REVEAL_END = 33;\nconst SETTLE_FRAMES = 8;\nconst GIANT_Y = -28;\nconst GIANT_X_CORRECTION = -48;\nconst COMPACT_Y = 5;\nconst COMPACT_X_SCALE = 0.87;\nconst COMPACT_START_X_CORRECTION = 28;\nconst FONT_FAMILY = \"Arial, Helvetica, sans-serif\";\nconst clamp = {\n  extrapolateLeft: \"clamp\" as const,\n  extrapolateRight: \"clamp\" as const,\n};\n\ninterface TextLayerProps {\n  text: string;\n  fontSize: number;\n  fontWeight: number;\n  gradientStart: string;\n  gradientEnd: string;\n  ghostColor: string;\n  maskImage: string;\n}\n\nfunction TextLayer({\n  text,\n  fontSize,\n  fontWeight,\n  gradientStart,\n  gradientEnd,\n  ghostColor,\n  maskImage,\n}: TextLayerProps) {\n  const textStyle = {\n    display: \"block\",\n    fontFamily: FONT_FAMILY,\n    fontSize,\n    fontWeight,\n    letterSpacing: 0,\n    lineHeight: 1.12,\n    whiteSpace: \"nowrap\" as const,\n  };\n\n  return (\n    <div style={{ position: \"relative\" }}>\n      <span style={{ ...textStyle, color: ghostColor }}>{text}</span>\n      <span\n        style={{\n          ...textStyle,\n          position: \"absolute\",\n          inset: 0,\n          color: \"transparent\",\n          backgroundImage: `linear-gradient(90deg, ${gradientStart} 0%, ${gradientStart} 4%, ${gradientEnd} 26%, ${gradientEnd} 100%)`,\n          backgroundClip: \"text\",\n          maskImage,\n          maskRepeat: \"no-repeat\",\n          opacity: 1,\n          WebkitBackgroundClip: \"text\",\n          WebkitMaskImage: maskImage,\n          WebkitMaskRepeat: \"no-repeat\",\n        }}\n      >\n        {text}\n      </span>\n    </div>\n  );\n}\n\nfunction GradientScaleCutTextBase({\n  text = \"Introducing\",\n  giantFontSize = 520,\n  compactFontSize = 132,\n  fontWeight = 700,\n  gradientStart = \"#f04a14\",\n  gradientEnd = \"#f3f1f1\",\n  ghostColor = \"#170b0a\",\n  backgroundColor = \"#000000\",\n  anchorOffsetX = -16,\n  giantTravel = 400,\n  settleTravel = 160,\n  cutFrame = 13,\n  revealSoftness = 14,\n  compactBlur = 12,\n  speed = 1,\n  className,\n}: GradientScaleCutTextProps) {\n  const frame = useCurrentFrame() * Math.max(speed, 0);\n  const safeCutFrame = Math.max(cutFrame, 1);\n  const safeGiantFontSize = Math.max(giantFontSize, 1);\n  const safeCompactFontSize = Math.max(compactFontSize, 1);\n  const safeSoftness = Math.max(revealSoftness, 0);\n  const safeBlur = Math.max(compactBlur, 0);\n  const revealProgress = interpolate(frame, [0, REVEAL_END], [0.02, 1], {\n    ...clamp,\n    easing: Easing.bezier(0.22, 0.74, 0.24, 1),\n  });\n  const revealEdge = revealProgress * (100 + safeSoftness / 2);\n  const revealSolid = Math.max(0, revealEdge - safeSoftness / 2);\n  const revealFade = revealEdge + safeSoftness / 2;\n  const maskImage = `linear-gradient(90deg, #000 0%, #000 ${revealSolid}%, transparent ${revealFade}%, transparent ${revealFade}%)`;\n  const giantProgress = interpolate(\n    frame,\n    [0, Math.max(safeCutFrame - 1, 1)],\n    [0, 1],\n    {\n      ...clamp,\n      easing: Easing.out(Easing.cubic),\n    },\n  );\n  const settleProgress = interpolate(\n    frame,\n    [safeCutFrame, safeCutFrame + SETTLE_FRAMES],\n    [0, 1],\n    {\n      ...clamp,\n      easing: Easing.out(Easing.cubic),\n    },\n  );\n  const moveProgress = interpolate(\n    frame,\n    [\n      safeCutFrame + 1,\n      safeCutFrame + 2,\n      safeCutFrame + 4,\n      safeCutFrame + SETTLE_FRAMES,\n    ],\n    [0, 0.58, 0.875, 1],\n    clamp,\n  );\n  const showGiant = frame < safeCutFrame;\n  const compactX =\n    interpolate(moveProgress, [0, 1], [settleTravel, 0], clamp) +\n    COMPACT_START_X_CORRECTION * (1 - moveProgress);\n  const compactBlurValue = safeBlur * (1 - settleProgress);\n\n  return (\n    <div\n      className={className}\n      style={{\n        position: \"absolute\",\n        inset: 0,\n        overflow: \"hidden\",\n        backgroundColor,\n      }}\n    >\n      {showGiant ? (\n        <div\n          style={{\n            position: \"absolute\",\n            top: `calc(50% + ${GIANT_Y}px)`,\n            left: `calc(50% + ${anchorOffsetX + GIANT_X_CORRECTION - giantTravel * giantProgress}px)`,\n            opacity: 1,\n            transform: \"translate3d(0, -50%, 0)\",\n          }}\n        >\n          <TextLayer\n            text={text}\n            fontSize={safeGiantFontSize}\n            fontWeight={fontWeight}\n            gradientStart={gradientStart}\n            gradientEnd={gradientEnd}\n            ghostColor={ghostColor}\n            maskImage={maskImage}\n          />\n        </div>\n      ) : (\n        <div\n          style={{\n            position: \"absolute\",\n            top: `calc(50% + ${COMPACT_Y}px)`,\n            left: `calc(50% + ${anchorOffsetX + compactX}px)`,\n            filter: `blur(${compactBlurValue}px)`,\n            opacity: 1,\n            transform: `translate3d(-50%, -50%, 0) scaleX(${COMPACT_X_SCALE})`,\n            transformOrigin: \"center\",\n          }}\n        >\n          <TextLayer\n            text={text}\n            fontSize={safeCompactFontSize}\n            fontWeight={fontWeight}\n            gradientStart={gradientStart}\n            gradientEnd={gradientEnd}\n            ghostColor={ghostColor}\n            maskImage={maskImage}\n          />\n        </div>\n      )}\n    </div>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  text: {\n    type: \"text-content\",\n    default: \"Introducing\",\n    description: \"Text\",\n  },\n  giantFontSize: {\n    type: \"number\",\n    min: 160,\n    max: 720,\n    step: 4,\n    default: 520,\n    description: \"Giant font size\",\n    hiddenFromList: false,\n  },\n  compactFontSize: {\n    type: \"number\",\n    min: 40,\n    max: 240,\n    step: 2,\n    default: 132,\n    description: \"Compact font size\",\n    hiddenFromList: false,\n  },\n  anchorOffsetX: {\n    type: \"number\",\n    min: -400,\n    max: 400,\n    step: 4,\n    default: -16,\n    description: \"Final horizontal anchor offset\",\n    hiddenFromList: false,\n  },\n  giantTravel: {\n    type: \"number\",\n    min: 0,\n    max: 800,\n    step: 4,\n    default: 400,\n    description: \"Giant phase left travel\",\n    hiddenFromList: false,\n  },\n  settleTravel: {\n    type: \"number\",\n    min: 0,\n    max: 400,\n    step: 4,\n    default: 160,\n    description: \"Compact entrance travel\",\n    hiddenFromList: false,\n  },\n  cutFrame: {\n    type: \"number\",\n    min: 4,\n    max: 24,\n    step: 1,\n    default: 13,\n    description: \"Hard cut frame\",\n    hiddenFromList: false,\n  },\n  revealSoftness: {\n    type: \"number\",\n    min: 0,\n    max: 40,\n    step: 1,\n    default: 14,\n    description: \"Reveal edge softness\",\n    hiddenFromList: false,\n  },\n  compactBlur: {\n    type: \"number\",\n    min: 0,\n    max: 40,\n    step: 1,\n    default: 12,\n    description: \"Blur after the cut\",\n    hiddenFromList: false,\n  },\n  gradientStart: {\n    type: \"color\",\n    default: \"#f04a14\",\n    description: \"Gradient start\",\n  },\n  gradientEnd: {\n    type: \"color\",\n    default: \"#f3f1f1\",\n    description: \"Gradient end\",\n  },\n  ghostColor: {\n    type: \"color\",\n    default: \"#170b0a\",\n    description: \"Unrevealed text color\",\n  },\n  backgroundColor: {\n    type: \"color\",\n    default: \"#000000\",\n    description: \"Background color\",\n  },\n  fontWeight: {\n    type: \"enum\",\n    default: \"700\",\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\",\"giantFontSize\",\"compactFontSize\",\"anchorOffsetX\",\"giantTravel\",\"settleTravel\",\"cutFrame\",\"revealSoftness\",\"compactBlur\",\"gradientStart\",\"gradientEnd\",\"ghostColor\",\"backgroundColor\",\"fontWeight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  text: \"Introducing\",\n  giantFontSize: 520,\n  compactFontSize: 132,\n  anchorOffsetX: -16,\n  giantTravel: 400,\n  settleTravel: 160,\n  cutFrame: 13,\n  revealSoftness: 14,\n  compactBlur: 12,\n  gradientStart: \"#f04a14\",\n  gradientEnd: \"#f3f1f1\",\n  ghostColor: \"#170b0a\",\n  backgroundColor: \"#000000\",\n  fontWeight: \"700\",\n  speed: 1,\n};\n\ntype GradientScaleCutTextElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof GradientScaleCutTextBase>;\n\nconst GradientScaleCutTextInner = forwardRef<\n  HTMLDivElement,\n  GradientScaleCutTextElementProps & { 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 ?? \"<GradientScaleCutText>\"}\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        <GradientScaleCutTextBase\n          {...(componentProps as unknown as ComponentProps<typeof GradientScaleCutTextBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const GradientScaleCutText = Interactive.withSchema({\n  Component: GradientScaleCutTextInner,\n  componentName: \"<GradientScaleCutText>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 36,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 36
}