{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "speed-ramp-word",
  "title": "Speed Ramp Word",
  "description": "Time slows on the key word as it warms to a gradient, with a timecode HUD.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/speed-ramp-word/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/JetBrainsMono\";\nimport { loadFont as loadDisplay } from \"@remotion/google-fonts/SchibstedGrotesk\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: display } = loadDisplay(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: serif } = loadSerif(\"italic\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: mono } = loadMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\n/**\n * gradients.sh \"swirl\": cream, orange, rose, deep violet. The key word warms\n * into it as time slows; dark stage takes the light end, light stage the deep.\n */\nconst SWIRL = [\"#ffe2c4\", \"#ff9a4d\", \"#d2456b\", \"#3a1f6b\"] as const;\nconst swirlInk = (theme: \"dark\" | \"light\", t: number) => {\n  const stops =\n    theme === \"dark\"\n      ? [SWIRL[0], SWIRL[1], SWIRL[2]]\n      : [SWIRL[1], SWIRL[2], SWIRL[3]];\n  return `linear-gradient(${96 + t * 10}deg, ${stops[0]} 4%, ${stops[1]} 48%, ${stops[2]} 96%)`;\n};\n/** Key word set in the serif italic is optically scaled to the grotesk. */\nconst KEY_SCALE = 1.1;\n\nexport interface SpeedRampWordProps {\n  /** The phrase that rushes across. */\n  text?: string;\n  /** The word inside `text` that drops into slow motion. Defaults to the last word. */\n  keyWord?: string;\n  /** Show the small timecode and speed readout that slow down with the shot. */\n  hud?: boolean;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Beat sheet (30fps):\n//  0–20    the phrase rushes in from the right at full speed, streaked\n//  20–48   speed ramp: a smooth velocity curve down to ~0.5% speed; the key\n//          word warms to the accent, trailing ghosts start to gather\n//  48–100  the key word hangs, drifting a few pixels; ghosts collapse into it\n//  100–110 time snaps back (accelerating curve)\n//  110–end the phrase exits left at full speed\nconst RUSH_END = 20;\nconst RAMP_LEN = 28;\nconst HANG_LEN = 52;\nconst SNAP_LEN = 10;\nconst T_RAMP_END = RUSH_END + RAMP_LEN;\nconst T_HANG_END = T_RAMP_END + HANG_LEN;\nconst T_SNAP_END = T_HANG_END + SNAP_LEN;\nconst T_MID = (T_RAMP_END + T_HANG_END) / 2;\nconst R_MIN = 0.005;\nconst STEP = 0.25;\n\n/** Frames the demo needs: motion through the exit plus a couple of frames. */\nexport const SPEED_RAMP_WORD_DURATION = 121;\n\nconst RAMP_DOWN = Easing.bezier(0.45, 0, 0.25, 1);\nconst SNAP_UP = Easing.bezier(0.55, 0, 0.85, 0.35);\nconst CAMERA = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F2F1EE\",\n    hud: \"rgba(242,241,238,0.42)\",\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#111113\",\n    hud: \"rgba(17,17,19,0.45)\",\n    grain: 0.04,\n  },\n} as const;\n\n/** Playback rate of the shot at real frame t: 1 = full speed. */\nfunction rate(t: number) {\n  if (t <= RUSH_END) return 1;\n  if (t <= T_RAMP_END) {\n    const p = RAMP_DOWN((t - RUSH_END) / RAMP_LEN);\n    return 1 + (R_MIN - 1) * p;\n  }\n  if (t <= T_HANG_END) return R_MIN;\n  if (t <= T_SNAP_END) {\n    const p = SNAP_UP((t - T_HANG_END) / SNAP_LEN);\n    return R_MIN + (1 - R_MIN) * p;\n  }\n  return 1;\n}\n\n/** Scene time elapsed by real frame t (integral of the rate). */\nfunction sceneTime(t: number) {\n  let acc = 0;\n  for (let s = 0; s < t; s += STEP) {\n    const h = Math.min(STEP, t - s);\n    acc += rate(s + h / 2) * h;\n  }\n  return acc;\n}\n\nfunction splitPhrase(text: string, keyWord?: string) {\n  let key = keyWord ?? \"\";\n  let idx = key ? text.indexOf(key) : -1;\n  if (idx < 0) {\n    const words = text.trim().split(/\\s+/);\n    key = (words[words.length - 1] ?? \"\").replace(/[.,!?…]+$/, \"\");\n    idx = text.lastIndexOf(key);\n  }\n  return {\n    before: text.slice(0, idx),\n    key,\n    after: text.slice(idx + key.length),\n  };\n}\n\nfunction timecode(sceneFrames: number) {\n  const f = Math.floor(sceneFrames);\n  const ff = f % 30;\n  const ss = Math.floor(f / 30) % 60;\n  const mm = Math.floor(f / 1800);\n  const p = (n: number) => String(n).padStart(2, \"0\");\n  return `00:${p(mm)}:${p(ss)}:${p(ff)}`;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `srw-grain-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.85\"\n          numOctaves={2}\n          seed={11}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix type=\"saturate\" values=\"0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\nexport function SpeedRampWord({\n  text = \"Everything changes in an instant.\",\n  keyWord = \"instant\",\n  hud = true,\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: SpeedRampWordProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const u = H / 720;\n  const c = THEMES[theme];\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const blurId = `srw-blur-${uid}`;\n  const ghostBlurId = `srw-ghost-${uid}`;\n\n  const { before, key, after } = splitPhrase(text, keyWord);\n  const fs = Math.min(176 * u, W * 0.137);\n  // Rough advances (Schibsted Grotesk 500 at -0.03em, Instrument Serif\n  // italic); only used to plan the travel, the layout itself is real text.\n  const beforeW = before.length * 0.45 * fs;\n  const keyW = key.length * 0.38 * fs * KEY_SCALE;\n\n  // The phrase starts already in frame (no empty first frame) and the key\n  // word's center lands on the frame center at the middle of the hang.\n  const rest = W * 0.56;\n  const startAnchor = W * 0.4 + beforeW + keyW / 2;\n  const v0 = (startAnchor - rest) / sceneTime(T_MID);\n  const anchorAt = (t: number) => startAnchor - v0 * sceneTime(t);\n\n  const tau = sceneTime(frame);\n  const anchor = startAnchor - v0 * tau;\n  const velocity = v0 * rate(frame);\n\n  // Ghosts are lagging followers of the key word: far behind while it slows,\n  // folding into it once it hangs.\n  const alphas = [0.1, 0.066, 0.045];\n  const ghosts = alphas.map(() => anchorAt(0));\n  const stop = Math.floor(frame);\n  for (let t = 1; t <= stop; t++) {\n    const a = anchorAt(t);\n    for (let k = 0; k < alphas.length; k++) {\n      ghosts[k] += (a - ghosts[k]) * alphas[k];\n    }\n  }\n  const frac = frame - stop;\n  const ghostX = ghosts.map((g, k) => {\n    const next = g + (anchorAt(stop + 1) - g) * alphas[k];\n    return g + (next - g) * frac;\n  });\n  const ghostEnv = interpolate(\n    frame,\n    [RUSH_END + 8, T_RAMP_END - 4, T_HANG_END - 6, T_HANG_END + 2],\n    [0, 1, 1, 0],\n    CLAMP,\n  );\n\n  // Look of the slow-motion moment.\n  const slow = interpolate(\n    frame,\n    [RUSH_END + 6, T_RAMP_END, T_HANG_END, T_HANG_END + 6],\n    [0, 1, 1, 0],\n    { ...CLAMP, easing: CAMERA },\n  );\n  const accentMix = interpolate(\n    frame,\n    [RUSH_END + 10, T_RAMP_END + 2],\n    [0, 1],\n    { ...CLAMP, easing: Easing.bezier(0.22, 1, 0.36, 1) },\n  );\n  const push = interpolate(frame, [RUSH_END, T_HANG_END], [1, 1.045], {\n    ...CLAMP,\n    easing: CAMERA,\n  });\n  const drift = interpolate(frame, [T_RAMP_END - 6, T_HANG_END], [0, -5 * u], {\n    ...CLAMP,\n    easing: CAMERA,\n  });\n  const blur = Math.min(velocity * 0.3, 30 * u);\n  const restDim = 1 - 0.62 * slow;\n  const restDefocus = 1.6 * u * slow;\n\n  const textStyle = {\n    fontFamily: display,\n    fontWeight: 500,\n    fontSize: fs,\n    letterSpacing: \"-0.035em\",\n    lineHeight: 1,\n    whiteSpace: \"pre\",\n  } as const;\n  const keyStyle = {\n    fontFamily: serif,\n    fontStyle: \"italic\",\n    fontWeight: 400,\n    fontSize: fs * KEY_SCALE,\n    letterSpacing: \"-0.01em\",\n    lineHeight: 1,\n    whiteSpace: \"pre\",\n  } as const;\n  const ink = swirlInk(theme, slow);\n  const ghostColor = theme === \"dark\" ? SWIRL[1] : SWIRL[2];\n\n  const sharp = blur < 0.3;\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <svg width={0} height={0} style={{ position: \"absolute\" }} aria-hidden>\n        <filter\n          id={blurId}\n          x=\"-30%\"\n          y=\"-10%\"\n          width=\"160%\"\n          height=\"120%\"\n          colorInterpolationFilters=\"sRGB\"\n        >\n          <feGaussianBlur stdDeviation={`${blur} 0`} />\n        </filter>\n        <filter\n          id={ghostBlurId}\n          x=\"-30%\"\n          y=\"-10%\"\n          width=\"160%\"\n          height=\"120%\"\n          colorInterpolationFilters=\"sRGB\"\n        >\n          <feGaussianBlur stdDeviation={`${4 * u} 0`} />\n        </filter>\n      </svg>\n\n      <AbsoluteFill\n        style={{ transform: `scale(${push})`, transformOrigin: \"50% 50%\" }}\n      >\n        {/* ghosts sit under the phrase */}\n        {ghostX.map((gx, k) => {\n          const gap = Math.abs(gx - anchor);\n          const merge = interpolate(gap, [2 * u, 26 * u], [0, 1], CLAMP);\n          const o = [0.3, 0.2, 0.12][k] * ghostEnv * merge;\n          if (o < 0.004) return null;\n          return (\n            <div\n              key={k}\n              style={{\n                position: \"absolute\",\n                left: gx,\n                top: H / 2 + drift,\n                transform: \"translate(-50%, -52%)\",\n                opacity: o,\n                color: ghostColor,\n                filter: `url(#${ghostBlurId})`,\n                ...keyStyle,\n              }}\n            >\n              {key}\n            </div>\n          );\n        })}\n\n        <AbsoluteFill style={{ filter: sharp ? undefined : `url(#${blurId})` }}>\n          <div style={{ position: \"absolute\", left: anchor, top: H / 2 }}>\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                top: 0,\n                transform: `translate(-50%, -52%) translateY(${drift}px)`,\n                ...textStyle,\n              }}\n            >\n              <span style={{ position: \"relative\", display: \"inline-block\" }}>\n                <span\n                  style={{\n                    position: \"absolute\",\n                    right: \"100%\",\n                    top: 0,\n                    color: c.fg,\n                    opacity: restDim,\n                    filter:\n                      restDefocus > 0.05 ? `blur(${restDefocus}px)` : undefined,\n                  }}\n                >\n                  {before}\n                </span>\n                <span\n                  style={{\n                    position: \"relative\",\n                    display: \"inline-block\",\n                    padding: `0 ${0.06 * fs}px`,\n                    ...keyStyle,\n                  }}\n                >\n                  <span style={{ color: c.fg, opacity: 1 - accentMix }}>\n                    {key}\n                  </span>\n                  <span\n                    style={{\n                      position: \"absolute\",\n                      inset: 0,\n                      padding: `0 ${0.06 * fs}px`,\n                      backgroundImage: ink,\n                      WebkitBackgroundClip: \"text\",\n                      backgroundClip: \"text\",\n                      color: \"transparent\",\n                      opacity: accentMix,\n                    }}\n                  >\n                    {key}\n                  </span>\n                </span>\n                <span\n                  style={{\n                    position: \"absolute\",\n                    left: \"100%\",\n                    top: 0,\n                    color: c.fg,\n                    opacity: restDim,\n                    filter:\n                      restDefocus > 0.05 ? `blur(${restDefocus}px)` : undefined,\n                  }}\n                >\n                  {after}\n                </span>\n              </span>\n            </div>\n          </div>\n        </AbsoluteFill>\n      </AbsoluteFill>\n\n      {hud && (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 48 * u,\n            right: 48 * u,\n            bottom: 40 * u,\n            display: \"flex\",\n            justifyContent: \"space-between\",\n            fontFamily: mono,\n            fontWeight: 400,\n            fontSize: 14 * u,\n            letterSpacing: \"0.02em\",\n            fontVariantNumeric: \"tabular-nums\",\n            color: c.hud,\n          }}\n        >\n          <span>{timecode(tau)}</span>\n          <span\n            style={{ color: interpolateColors(slow, [0, 1], [c.hud, accent]) }}\n          >\n            {`${(rate(frame) * 100).toFixed(rate(frame) < 0.1 ? 1 : 0)}%`}\n          </span>\n        </div>\n      )}\n\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/speed-ramp-word.tsx"
    }
  ],
  "type": "registry:component"
}
