Skip to content

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

11.1 KB
Raw Blame
{
  "type": "remotion-element",
  "version": 1,
  "element": {
    "assets": [],
    "dependencies": [
      {
        "name": "@remotion/google-fonts",
        "version": null
      }
    ],
    "dimensions": null,
    "displayName": "Scrub Reveal",
    "initialProps": null,
    "slug": "scrub-reveal",
    "sourceCode": "import { loadFont } from \"@remotion/google-fonts/Geist\";\nimport { loadVariableFont } from \"@remotion/google-fonts/Newsreader\";\nimport { forwardRef, useImperativeHandle, useMemo, useRef, type ComponentProps } from \"react\";\nimport { AbsoluteFill, Easing, Interactive, Sequence, interpolate, interpolateColors, useCurrentFrame, useVideoConfig, type InteractiveBaseProps, type InteractiveTransformProps, type InteractivitySchema, type SequenceControls } from \"remotion\";\n\nconst { fontFamily } = loadFont(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n/** Editorial italic for the highlight; optical size follows the font size. */\nconst serif = loadVariableFont(\"italic\", { subsets: [\"latin\"] });\n\ninterface ScrubRevealProps {\n  /** The statement. Each word brightens as the reveal front passes it. */\n  text?: string;\n  /**\n   * A phrase inside `text` that turns to an italic serif and lights up in a\n   * gradient. Pass \"\" for none.\n   */\n  highlight?: string;\n  accent?: string;\n  /** Playback multiplier. */\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\n// Beat sheet (30fps):\n//  0–6     the dim paragraph is already on screen, low in frame, drifting up\n//  4–122   one \"scroll\": the paragraph climbs while a soft front brightens it\n//          word by word; both ride the same eased progress, like a real scrub\n//  118–142 fully lit; the plain words settle a step back, the accent phrase holds\n//  142–170 poster hold, the drift never quite stops\nconst SCROLL_START = 4;\nconst SCROLL_END = 122;\nconst SETTLE_START = 118;\nconst SETTLE_END = 142;\n\n/** Trackpad scroll: eases in, carries steady velocity, glides to a stop. */\nconst SCROLL = Easing.bezier(0.3, 0.06, 0.22, 1);\nconst SETTLE = Easing.bezier(0.33, 0, 0.2, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n/** Width of the brightening front, in characters. */\nconst SOFT = 11;\n\n/**\n * The highlight is filled with the gradients.sh \"halo\" palette (peach, rose,\n * into the accent blue); the light stage uses its deeper end for contrast.\n */\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F5F5F4\",\n    dim: [42, 42, 45],\n    rest: \"#B9B9BC\",\n    halo: (accent: string) => [\"#FFC394\", \"#F07A86\", \"#C25BC0\", accent],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#111113\",\n    dim: [218, 216, 210],\n    rest: \"#4A4946\",\n    halo: (accent: string) => [\"#E2457A\", \"#B6449F\", \"#7148D8\", accent],\n  },\n} as const;\n\ninterface Word {\n  text: string;\n  start: number;\n  end: number;\n  accent: boolean;\n}\n\nfunction splitWords(text: string, highlight: string): Word[] {\n  const at = highlight ? text.indexOf(highlight) : -1;\n  const hiEnd = at + highlight.length;\n  const words: Word[] = [];\n  for (const m of text.matchAll(/\\S+/g)) {\n    const start = m.index ?? 0;\n    const end = start + m[0].length;\n    words.push({\n      text: m[0],\n      start,\n      end,\n      accent: at >= 0 && start < hiEnd && end > at,\n    });\n  }\n  return words;\n}\n\nfunction smooth(x: number) {\n  const t = Math.min(1, Math.max(0, x));\n  return t * t * (3 - 2 * t);\n}\n\nfunction ScrubRevealBase({\n  text = \"Every frame is code. Every cut is yours. Ship the film your product deserves.\",\n  highlight = \"Every cut is yours.\",\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: ScrubRevealProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n\n  const words = useMemo(() => splitWords(text, highlight), [text, highlight]);\n  const lastStart = words.length ? words[words.length - 1].start : 0;\n\n  const scroll = interpolate(frame, [SCROLL_START, SCROLL_END], [0, 1], {\n    ...CLAMP,\n    easing: SCROLL,\n  });\n  const settle = interpolate(frame, [SETTLE_START, SETTLE_END], [0, 1], {\n    ...CLAMP,\n    easing: SETTLE,\n  });\n\n  // The front starts just before the first word and parks past the last one.\n  const front = interpolate(scroll, [0, 1], [-SOFT * 0.15, lastStart + SOFT]);\n\n  // The page climbs with the same progress, then keeps a hair of drift.\n  const climb = interpolate(scroll, [0, 1], [H * 0.15, 0]);\n  const tail = interpolate(\n    frame,\n    [SCROLL_END, SCROLL_END + 90],\n    [0, -H * 0.012],\n    {\n      ...CLAMP,\n    },\n  );\n\n  const size = Math.round(Math.min(W * 0.064, H * 0.114));\n  const measure = Math.min(W * 0.8, size * 13.2);\n  const restColor = interpolateColors(settle, [0, 1], [c.fg, c.rest]);\n  const [dr, dg, db] = c.dim;\n  const dimColor = `rgb(${dr},${dg},${db})`;\n  const stops = c.halo(accent);\n  // The halo drifts a few degrees across the hold, nothing more.\n  const angle = 96 + Math.sin(frame / 50) * 5;\n  const haloAt = (k: number) =>\n    interpolateColors(\n      Math.min(1, Math.max(0, k)),\n      [0, 0.34, 0.66, 1],\n      [...stops],\n    );\n\n  const accentWords = words.filter((w) => w.accent);\n  const first = accentWords[0];\n  const last = accentWords[accentWords.length - 1];\n\n  const word = (w: Word, i: number) => {\n    const lit = smooth((front - w.start) / SOFT);\n    const gap = i < words.length - 1 ? \" \" : \"\";\n    if (w.accent && first && last) {\n      // Each word carries its own slice of the halo, so the phrase reads as\n      // one continuous gradient. A dim veil on top lifts as the front passes;\n      // both layers clip to the same glyphs, so no colour fringes at the edges.\n      const span = Math.max(1, last.end - first.start);\n      const k0 = (w.start - first.start) / span;\n      const k1 = (w.end - first.start) / span;\n      const veil = `rgba(${dr},${dg},${db},${(1 - lit).toFixed(3)})`;\n      return (\n        <span key={`${w.start}-${w.text}`}>\n          <span\n            style={{\n              backgroundImage: `linear-gradient(${veil}, ${veil}), linear-gradient(${angle.toFixed(2)}deg, ${haloAt(k0)}, ${haloAt(k1)})`,\n              WebkitBackgroundClip: \"text\",\n              backgroundClip: \"text\",\n              color: \"transparent\",\n              // the box must hold the italic overhang and the descenders\n              padding: \"0.1em 0.1em 0.3em 0.06em\",\n              margin: \"0 -0.1em 0 -0.06em\",\n            }}\n          >\n            {w.text}\n          </span>\n          {w === last ? \"\" : gap}\n        </span>\n      );\n    }\n    return (\n      <span\n        key={`${w.start}-${w.text}`}\n        style={{ color: interpolateColors(lit, [0, 1], [dimColor, restColor]) }}\n      >\n        {w.text}\n        {gap}\n      </span>\n    );\n  };\n\n  const before = first ? words.filter((w) => w.end <= first.start) : words;\n  const after = last ? words.filter((w) => w.start >= last.end) : [];\n  const index = (w: Word) => words.indexOf(w);\n\n  return (\n    <AbsoluteFill style={{ backgroundColor: c.bg, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: (W - measure) / 2,\n          top: H / 2,\n          width: measure,\n          transform: `translateY(calc(-50% + ${climb + tail}px))`,\n          fontFamily,\n          fontWeight: 500,\n          fontSize: size,\n          lineHeight: 1.12,\n          letterSpacing: \"-0.03em\",\n          textWrap: \"balance\",\n        }}\n      >\n        {before.map((w) => word(w, index(w)))}\n        {first ? (\n          <span\n            style={{\n              fontFamily: serif.fontFamily,\n              fontStyle: \"italic\",\n              fontWeight: 400,\n              // the serif's x-height is smaller; match it to the grotesk\n              fontSize: \"1.12em\",\n              lineHeight: 0,\n              letterSpacing: \"-0.015em\",\n              paddingRight: \"0.06em\",\n            }}\n          >\n            {accentWords.map((w) => word(w, index(w)))}\n          </span>\n        ) : null}\n        {first && after.length ? \" \" : \"\"}\n        {after.map((w) => word(w, index(w)))}\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  text: {\n    type: \"text-content\",\n    default: \"Every frame is code. Every cut is yours. Ship the film your product deserves.\",\n    description: \"Text\",\n  },\n  highlight: {\n    type: \"text-content\",\n    default: \"Every cut is yours.\",\n    description: \"Highlight\",\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\",\"text\",\"highlight\",\"speed\"]);\n\nconst ELEMENT_PROP_DEFAULTS: Record<string, unknown> = {\n  theme: \"dark\",\n  accent: \"#3B5BFD\",\n  text: \"Every frame is code. Every cut is yours. Ship the film your product deserves.\",\n  highlight: \"Every cut is yours.\",\n  speed: 1,\n};\n\ntype ScrubRevealElementProps = InteractiveBaseProps &\n  InteractiveTransformProps &\n  ComponentProps<typeof ScrubRevealBase>;\n\nconst ScrubRevealInner = forwardRef<\n  HTMLDivElement,\n  ScrubRevealElementProps & { 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 ?? \"<ScrubReveal>\"}\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        <ScrubRevealBase\n          {...(componentProps as unknown as ComponentProps<typeof ScrubRevealBase>)}\n        />\n      </div>\n    </Sequence>\n  );\n});\n\nexport const ScrubReveal = Interactive.withSchema({\n  Component: ScrubRevealInner,\n  componentName: \"<ScrubReveal>\",\n  componentIdentity: null,\n  schema: elementSchema,\n  supportsEffects: false,\n});\n",
    "durationInFrames": 142,
    "installationMode": "component-owned-sequence"
  },
  "durationInFrames": 142
}