Skip to content

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

17.9 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [
      {
        "name": "@remotion/google-fonts",
        "version": null
      }
    ],
    "dimensions": null,
    "displayName": "Feature Headline",
    "initialProps": null,
    "slug": "feature-headline",
    "sourceCode": "import { loadFont as loadGeist } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport React, { Fragment, forwardRef, useImperativeHandle, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst geist = loadGeist(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\nconst mono = loadGeistMono(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n\n/**\n * Beat sheet (30fps, speed 1). Built to be used five times in one film, so\n * it is fast and gets out of the way:\n * 0–14    the pill opens from its left edge (from the centre when centred).\n * 4–30    headline words rise out of their masks, 2 frames apart; the\n *         highlighted phrase carries a slow gradients.sh \"mesh\" fill.\n * 14–34   subhead rises and sharpens.\n * 34–end  hold. Last 12 frames: words leave upward through the same masks\n *         (`exit`), so the next shot can hard-cut in.\n */\n\ninterface FeatureHeadlineProps {\n  /** Short chip at the start of the pill. Empty string hides it. */\n  tag?: string;\n  /** Feature name in the pill. Empty string hides the pill. */\n  label?: string;\n  /** One or two lines. A \"\\n\" forces a break. */\n  headline?: string;\n  /** Phrase inside `headline` that carries the gradient. */\n  highlight?: string;\n  subhead?: string;\n  align?: \"left\" | \"center\";\n  /** Leave through the masks over the last 12 frames of the composition. */\n  exit?: boolean;\n  accent?: string;\n  /** Stage fill. \"transparent\" drops the stage. */\n  background?: string;\n  /** Playback multiplier. */\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\n/** gradients.sh \"mesh\": bg #0a0d24, [#ecdcf2, #8796ee, #2e45b7, #0e1645]. */\nconst MESH = [\"#ecdcf2\", \"#8796ee\", \"#2e45b7\", \"#0e1645\"] as const;\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F4F3F0\",\n    muted: \"#8E8D94\",\n    pillBg: \"rgba(255,255,255,0.045)\",\n    pillLine: \"rgba(255,255,255,0.12)\",\n    tagFg: \"#FFFFFF\",\n    highlight: (accent: string) =>\n      `linear-gradient(90deg, ${MESH[0]} 0%, #b9b6f2 30%, ${MESH[1]} 58%, color-mix(in oklab, ${accent} 70%, ${MESH[1]}) 82%, ${MESH[0]} 100%)`,\n    ground: [\n      `radial-gradient(95% 120% at 108% 118%, color-mix(in oklab, ${MESH[2]} 30%, transparent) 0%, color-mix(in oklab, ${MESH[3]} 30%, transparent) 45%, transparent 75%)`,\n      `radial-gradient(40% 55% at 96% 104%, color-mix(in oklab, ${MESH[1]} 12%, transparent) 0%, transparent 80%)`,\n    ],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#111113\",\n    muted: \"#6E6C67\",\n    pillBg: \"rgba(255,255,255,0.7)\",\n    pillLine: \"rgba(17,17,19,0.12)\",\n    tagFg: \"#FFFFFF\",\n    highlight: (accent: string) =>\n      `linear-gradient(90deg, ${MESH[2]} 0%, ${accent} 34%, #6d7ff0 62%, #9a86e6 82%, ${MESH[2]} 100%)`,\n    ground: [\n      `radial-gradient(95% 120% at 108% 118%, color-mix(in oklab, ${MESH[1]} 22%, transparent) 0%, color-mix(in oklab, ${MESH[0]} 30%, transparent) 45%, transparent 75%)`,\n      `radial-gradient(40% 55% at 96% 104%, color-mix(in oklab, ${MESH[0]} 40%, transparent) 0%, transparent 80%)`,\n    ],\n  },\n} as const;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN = Easing.bezier(0.6, 0, 0.9, 0.5);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n/** Geist 500 advances (per 1000 em), ASCII 32–126. Used to size, not to place. */\nconst GEIST_500 = [\n  243, 230, 349, 513, 632, 853, 668, 174, 329, 329, 420, 563, 186, 432, 186,\n  457, 677, 374, 614, 600, 629, 629, 610, 507, 629, 613, 227, 227, 547, 544,\n  547, 517, 901, 678, 681, 704, 701, 610, 596, 692, 705, 281, 592, 652, 584,\n  883, 738, 739, 653, 739, 673, 642, 558, 696, 688, 956, 633, 586, 557, 342,\n  439, 342, 438, 532, 257, 556, 591, 549, 591, 566, 413, 591, 581, 256, 274,\n  565, 283, 852, 581, 562, 592, 591, 394, 535, 414, 587, 548, 806, 559, 540,\n  499, 405, 274, 406, 522,\n];\n\nfunction textEm(text: string) {\n  let w = 0;\n  for (const ch of text) {\n    const c = ch.charCodeAt(0);\n    w += c >= 32 && c <= 126 ? GEIST_500[c - 32] : 600;\n  }\n  return w / 1000;\n}\n\ninterface Word {\n  text: string;\n  line: number;\n  index: number;\n  /** Char range inside the highlight, as fractions of the highlight. */\n  hl: [number, number] | null;\n}\n\nfunction splitWords(headline: string, highlight: string | undefined) {\n  const lower = headline.toLowerCase();\n  const hStart = highlight ? lower.indexOf(highlight.toLowerCase()) : -1;\n  const hEnd = hStart >= 0 && highlight ? hStart + highlight.length : -1;\n  const hLen = Math.max(1, hEnd - hStart);\n  const words: Word[] = [];\n  const re = /\\S+|\\n/g;\n  let line = 0;\n  let index = 0;\n  for (let m = re.exec(headline); m; m = re.exec(headline)) {\n    if (m[0] === \"\\n\") {\n      line += 1;\n      continue;\n    }\n    const a = m.index;\n    const b = a + m[0].length;\n    const inside = hStart >= 0 && a < hEnd && b > hStart;\n    words.push({\n      text: m[0],\n      line,\n      index: index++,\n      hl: inside\n        ? [\n            (Math.max(a, hStart) - hStart) / hLen,\n            (Math.min(b, hEnd) - hStart) / hLen,\n          ]\n        : null,\n    });\n  }\n  return { words, lines: line + 1 };\n}\n\n/**\n * One gradient spans the whole highlighted phrase even though each word is\n * its own masked span: every word shows its slice of a gradient sized to the\n * phrase (1.6x wider so it can drift slowly).\n */\nfunction highlightFill(\n  [a, b]: [number, number],\n  drift: number,\n  image: string,\n): React.CSSProperties {\n  const f = Math.max(0.02, b - a);\n  const K = 1.6 / f;\n  const o = drift * 0.35;\n  const P = (a / f + o * K) / (K - 1);\n  return {\n    backgroundImage: image,\n    backgroundSize: `${K * 100}% 100%`,\n    backgroundPosition: `${P * 100}% 0%`,\n    WebkitBackgroundClip: \"text\",\n    backgroundClip: \"text\",\n    color: \"transparent\",\n  };\n}\n\nfunction FeatureHeadlineBase({\n  tag = \"New\",\n  label = \"Captions\",\n  headline = \"Captions that move with every word.\",\n  highlight = \"every word\",\n  subhead = \"31 transcript-driven caption styles, ready to drop into any video.\",\n  align = \"left\",\n  exit = true,\n  accent = \"#3B5BFD\",\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: FeatureHeadlineProps) {\n  const raw = useCurrentFrame();\n  const frame = raw * speed;\n  const { width, height, durationInFrames } = useVideoConfig();\n  const p = PALETTES[theme];\n  const centre = align === \"center\";\n\n  const portrait = height > width * 1.1;\n  const s = portrait\n    ? (width / 1280) * 1.55\n    : Math.min(width / 1280, height / 720);\n  const padX = width * (portrait ? 0.08 : 0.09);\n  const maxW = Math.min(width - padX * 2, (portrait ? 2000 : 1040) * s);\n\n  // headline size: two lines at most at full size, then shrink to a floor\n  const { words, lines: hardLines } = splitWords(headline, highlight);\n  const flat = headline.replace(/\\n/g, \" \");\n  const baseFs = (portrait ? 104 : 94) * s;\n  const est = (textEm(flat) - 0.035 * flat.length) * 1.06;\n  const linesAtBase = Math.max(hardLines, Math.ceil((est * baseFs) / maxW));\n  const fs =\n    linesAtBase <= 2\n      ? baseFs\n      : Math.max(baseFs * 0.72, (maxW * 2) / Math.max(est, 1));\n\n  // ---- timing ----------------------------------------------------------------\n  const pillT = interpolate(frame, [0, 14], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const wordT = (i: number) =>\n    interpolate(frame, [4 + i * 2, 20 + i * 2], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n  const subStart = 12 + Math.min(words.length, 8) * 1.5;\n  const subT = interpolate(frame, [subStart, subStart + 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const EXIT = 12;\n  const exitStart = durationInFrames - EXIT;\n  const exitT = (delay: number) =>\n    exit\n      ? interpolate(raw, [exitStart + delay, exitStart + delay + 9], [0, 1], {\n          ...CLAMP,\n          easing: EASE_IN,\n        })\n      : 0;\n  const drift = interpolate(raw, [0, durationInFrames], [0, 1], CLAMP);\n\n  const transparent = background === \"transparent\";\n  const showPill = label.length > 0;\n  const pillFs = 19 * s;\n  const pillExit = exitT(0);\n  const clip = (1 - pillT) * 100;\n  const pillClip = centre\n    ? `inset(0 ${clip / 2}% 0 ${clip / 2}% round 999px)`\n    : `inset(0 ${clip}% 0 0 round 999px)`;\n  const subExit = exitT(1);\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: transparent ? \"transparent\" : (background ?? p.bg),\n        overflow: \"hidden\",\n      }}\n    >\n      {!transparent && background === undefined ? (\n        <div\n          style={{\n            position: \"absolute\",\n            inset: 0,\n            background: p.ground.join(\", \"),\n            transform: `translate(${(-drift * 2).toFixed(3)}%, ${(drift * 1.5).toFixed(3)}%) scale(1.06)`,\n          }}\n        />\n      ) : null}\n\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          padding: `0 ${padX}px`,\n          display: \"flex\",\n          flexDirection: \"column\",\n          justifyContent: \"center\",\n          alignItems: centre ? \"center\" : \"flex-start\",\n          textAlign: centre ? \"center\" : \"left\",\n        }}\n      >\n        {showPill ? (\n          <div\n            style={{\n              display: \"flex\",\n              alignItems: \"center\",\n              gap: pillFs * 0.6,\n              height: pillFs * 2.15,\n              padding: `0 ${pillFs * 0.95}px 0 ${tag ? pillFs * 0.3 : pillFs * 0.95}px`,\n              borderRadius: 999,\n              background: p.pillBg,\n              boxShadow: `inset 0 0 0 1px ${p.pillLine}`,\n              clipPath: pillClip,\n              opacity: 1 - pillExit,\n              transform: `translateY(${-pillExit * 14 * s}px)`,\n              marginBottom: fs * 0.42,\n            }}\n          >\n            {tag ? (\n              <span\n                style={{\n                  display: \"flex\",\n                  alignItems: \"center\",\n                  height: pillFs * 1.55,\n                  padding: `0 ${pillFs * 0.6}px`,\n                  borderRadius: 999,\n                  background: accent,\n                  color: p.tagFg,\n                  fontFamily: mono.fontFamily,\n                  fontWeight: 500,\n                  fontSize: pillFs * 0.72,\n                  letterSpacing: \"0.08em\",\n                  textTransform: \"uppercase\",\n                  transform: `translateX(${(1 - pillT) * -10 * s}px)`,\n                }}\n              >\n                {tag}\n              </span>\n            ) : null}\n            <span\n              style={{\n                fontFamily: geist.fontFamily,\n                fontWeight: 500,\n                fontSize: pillFs,\n                letterSpacing: \"-0.01em\",\n                color: p.fg,\n                whiteSpace: \"nowrap\",\n                opacity: interpolate(pillT, [0.3, 1], [0, 1], CLAMP),\n                transform: `translateX(${(1 - pillT) * -14 * s}px)`,\n              }}\n            >\n              {label}\n            </span>\n          </div>\n        ) : null}\n\n        <div\n          style={{\n            maxWidth: maxW,\n            fontFamily: geist.fontFamily,\n            fontWeight: 500,\n            fontSize: fs,\n            lineHeight: 1.06,\n            letterSpacing: \"-0.035em\",\n            color: p.fg,\n          }}\n        >\n          {Array.from({ length: hardLines }, (_, line) => (\n            <div key={line} style={{ textWrap: \"balance\" }}>\n              {words\n                .filter((w) => w.line === line)\n                .map((w, k) => {\n                  const t = wordT(w.index);\n                  const out = exitT(w.index * 0.6);\n                  const y = (1 - t) * 108 - out * 108;\n                  const hlStyle: React.CSSProperties = w.hl\n                    ? highlightFill(w.hl, drift, p.highlight(accent))\n                    : {};\n                  return (\n                    <Fragment key={w.index}>\n                      {k > 0 ? \" \" : null}\n                      <span\n                        style={{\n                          display: \"inline-block\",\n                          overflow: \"hidden\",\n                          verticalAlign: \"top\",\n                          paddingBottom: \"0.14em\",\n                          marginBottom: \"-0.14em\",\n                          paddingRight: \"0.04em\",\n                          marginRight: \"-0.04em\",\n                        }}\n                      >\n                        <span\n                          style={{\n                            display: \"inline-block\",\n                            transform: `translateY(${y}%)`,\n                            ...hlStyle,\n                          }}\n                        >\n                          {w.text}\n                        </span>\n                      </span>\n                    </Fragment>\n                  );\n                })}\n            </div>\n          ))}\n        </div>\n\n        {subhead ? (\n          <div\n            style={{\n              marginTop: fs * 0.36,\n              maxWidth: Math.min(maxW * 0.82, 760 * s * (portrait ? 1.3 : 1)),\n              fontFamily: geist.fontFamily,\n              fontWeight: 400,\n              fontSize: (portrait ? 30 : 26) * s,\n              lineHeight: 1.4,\n              letterSpacing: \"-0.008em\",\n              color: p.muted,\n              textWrap: \"balance\",\n              opacity: subT * (1 - subExit),\n              transform: `translateY(${(1 - subT) * 14 * s - subExit * 12 * s}px)`,\n              filter: `blur(${(1 - subT) * 6 * s}px)`,\n            }}\n          >\n            {subhead}\n          </div>\n        ) : null}\n      </div>\n    </AbsoluteFill>\n  );\n}\n\nconst elementSchema = {\n  ...Interactive.baseSchema,\n  theme: {\n    type: \"enum\",\n    default: \"dark\",\n    variants: {\n      dark: {},\n      light: {},\n    },\n    description: \"Theme\",\n  },\n  accent: {\n    type: \"color\",\n    default: \"#3B5BFD\",\n    description: \"Accent\",\n  },\n  tag: {\n    type: \"text-content\",\n    default: \"New\",\n    description: \"Tag\",\n  },\n  label: {\n    type: \"text-content\",\n    default: \"Captions\",\n    description: \"Label\",\n  },\n  headline: {\n    type: \"text-content\",\n    default: \"Captions that move with every word.\",\n    description: \"Headline\",\n  },\n  highlight: {\n    type: \"text-content\",\n    default: \"every word\",\n    description: \"Highlight\",\n  },\n  subhead: {\n    type: \"text-content\",\n    default: \"31 transcript-driven caption styles, ready to drop into any video.\",\n    description: \"Subhead\",\n  },\n  align: {\n    type: \"enum\",\n    default: \"left\",\n    variants: {\n      left: {},\n      center: {},\n    },\n    description: \"Align\",\n  },\n  exit: {\n    type: \"boolean\",\n    default: true,\n    description: \"Exit\",\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([\"theme\",\"accent\",\"tag\",\"label\",\"headline\",\"highlight\",\"subhead\",\"align\",\"exit\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  theme: \"dark\",\n  accent: \"#3B5BFD\",\n  tag: \"New\",\n  label: \"Captions\",\n  headline: \"Captions that move with every word.\",\n  highlight: \"every word\",\n  subhead: \"31 transcript-driven caption styles, ready to drop into any video.\",\n  align: \"left\",\n  exit: true,\n  speed: 1,\n};\n\ntype FeatureHeadlineElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof FeatureHeadlineBase>;\n\nconst FeatureHeadlineInner = forwardRef<\n  HTMLDivElement,\n  FeatureHeadlineElementProps & { 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 ?? \"<FeatureHeadline>\"}\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        <FeatureHeadlineBase\n          {...(componentProps as unknown as ComponentProps<typeof FeatureHeadlineBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const FeatureHeadline = Interactive.withSchema({\n  Component: FeatureHeadlineInner,\n  componentName: \"<FeatureHeadline>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 39,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 39
}