{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"text-reveal","type":"registry:component","title":"Text Reveal","description":"Text reveal animation: word-by-word and letter-by-letter kinetic typography with blur-in, fade, slide, scale and tracking-in presets. One staggered enter/exit text animator: fade, slide, blur, scale, mask and tracking effects over character, word, line or block units, with 14 classic looks as presets.","dependencies":["remotion"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>. Pass mode=\"dark\" for dark frames.","registryDependencies":["https://kuchi.kalarislabs.com/r/kuchi-ui.json"],"files":[{"path":"components/kuchi/text-reveal.tsx","type":"registry:component","target":"components/kuchi/text-reveal.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { useEffect, useRef, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  interpolate,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  defaultLightTheme,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * Pure animation math for TextReveal. Everything in this file is\r\n * frame-deterministic and side-effect free so it can be unit tested.\r\n */\r\n\r\nexport type TextRevealUnit = \"character\" | \"word\" | \"line\" | \"block\";\r\n\r\nexport type TextRevealEffect =\r\n  | \"fade\"\r\n  | \"slide\"\r\n  | \"blur\"\r\n  | \"scale\"\r\n  | \"mask\"\r\n  | \"tracking\";\r\n\r\nexport type TextRevealDirection = \"up\" | \"down\" | \"left\" | \"right\";\r\n\r\nexport type TextRevealEasing =\r\n  | \"smooth\"\r\n  | \"snappy\"\r\n  | \"overshoot\"\r\n  | \"linear\"\r\n  | \"spring\"\r\n  | [number, number, number, number];\r\n\r\nexport type TextRevealExit = \"none\" | \"mirror\";\r\n\r\nexport type TextRevealPreset =\r\n  | \"soft-blur-in\"\r\n  | \"per-character-rise\"\r\n  | \"bottom-up-letters\"\r\n  | \"top-down-letters\"\r\n  | \"spring-scale-in\"\r\n  | \"micro-scale-fade\"\r\n  | \"scale-down-fade\"\r\n  | \"blur-out-up\"\r\n  | \"focus-blur-resolve\"\r\n  | \"line-by-line-slide\"\r\n  | \"mask-reveal-up\"\r\n  | \"tracking-in\"\r\n  | \"short-slide-right\"\r\n  | \"staggered-fade-up\";\r\n\r\nexport interface TextRevealSettings {\r\n  unit: TextRevealUnit;\r\n  effects: TextRevealEffect[];\r\n  direction: TextRevealDirection;\r\n  distance: number;\r\n  blurAmount: number;\r\n  scaleFrom: number;\r\n  /** Starting letter-spacing for the `tracking` effect, in em. */\r\n  trackingFrom: number;\r\n  stagger: number;\r\n  enterDuration: number;\r\n  easing: TextRevealEasing;\r\n  exit: TextRevealExit;\r\n  exitDirection: TextRevealDirection;\r\n  exitDistance: number;\r\n  exitBlur: number;\r\n  exitDuration: number;\r\n  exitStagger: number;\r\n  align: \"left\" | \"center\" | \"right\";\r\n  fontSize: number;\r\n  color: string;\r\n  fontWeight: number | string;\r\n  letterSpacing: string;\r\n  speed: number;\r\n}\r\n\r\nexport const TEXT_REVEAL_DEFAULTS: TextRevealSettings = {\r\n  unit: \"word\",\r\n  effects: [\"fade\", \"slide\"],\r\n  direction: \"up\",\r\n  distance: 24,\r\n  blurAmount: 8,\r\n  scaleFrom: 0.9,\r\n  trackingFrom: 0.5,\r\n  stagger: 2,\r\n  enterDuration: 18,\r\n  easing: \"smooth\",\r\n  exit: \"none\",\r\n  exitDirection: \"up\",\r\n  exitDistance: 14,\r\n  exitBlur: 8,\r\n  exitDuration: 14,\r\n  exitStagger: 1,\r\n  align: \"center\",\r\n  fontSize: 72,\r\n  // A settings preset has no hook to resolve against, so it takes the token's\r\n  // value directly rather than a hex — the component itself still prefers the\r\n  // live theme, and this keeps the customizer's default in step with it.\r\n  color: defaultLightTheme.foreground,\r\n  fontWeight: 600,\r\n  letterSpacing: \"-0.03em\",\r\n  speed: 1,\r\n};\r\n\r\n/**\r\n * The 14 legacy one-off looks, expressed as motion-prop bundles.\r\n * A preset overrides the motion props it defines; typography props\r\n * (text, fontSize, color, fontWeight, align) stay caller-controlled\r\n * unless the bundle lists them.\r\n */\r\nexport const TEXT_REVEAL_PRESETS: Record<\r\n  TextRevealPreset,\r\n  Partial<TextRevealSettings>\r\n> = {\r\n  \"soft-blur-in\": {\r\n    unit: \"character\",\r\n    effects: [\"fade\", \"slide\", \"blur\"],\r\n    direction: \"up\",\r\n    distance: 16,\r\n    blurAmount: 12,\r\n    stagger: 1,\r\n    enterDuration: 27,\r\n    easing: \"smooth\",\r\n    exit: \"none\",\r\n    letterSpacing: \"-0.05em\",\r\n  },\r\n  \"per-character-rise\": {\r\n    unit: \"character\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"up\",\r\n    distance: 32,\r\n    stagger: 1,\r\n    enterDuration: 21,\r\n    easing: \"snappy\",\r\n    exit: \"none\",\r\n    letterSpacing: \"-0.05em\",\r\n  },\r\n  \"bottom-up-letters\": {\r\n    unit: \"character\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"up\",\r\n    distance: 46,\r\n    stagger: 3,\r\n    enterDuration: 12,\r\n    easing: [0.18, 1, 0.32, 1],\r\n    exit: \"none\",\r\n    letterSpacing: \"-0.05em\",\r\n  },\r\n  \"top-down-letters\": {\r\n    unit: \"character\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"down\",\r\n    distance: 46,\r\n    stagger: 3,\r\n    enterDuration: 12,\r\n    easing: [0.18, 1, 0.32, 1],\r\n    exit: \"none\",\r\n    letterSpacing: \"-0.05em\",\r\n  },\r\n  \"spring-scale-in\": {\r\n    unit: \"word\",\r\n    effects: [\"fade\", \"scale\"],\r\n    scaleFrom: 0.7,\r\n    stagger: 3,\r\n    enterDuration: 11,\r\n    easing: \"overshoot\",\r\n    exit: \"none\",\r\n  },\r\n  \"micro-scale-fade\": {\r\n    unit: \"block\",\r\n    effects: [\"fade\", \"scale\"],\r\n    scaleFrom: 0.96,\r\n    enterDuration: 18,\r\n    easing: [0.32, 0.72, 0, 1],\r\n    exit: \"none\",\r\n  },\r\n  \"scale-down-fade\": {\r\n    unit: \"block\",\r\n    effects: [\"fade\", \"slide\", \"scale\"],\r\n    direction: \"up\",\r\n    distance: 8,\r\n    scaleFrom: 1.04,\r\n    enterDuration: 16,\r\n    easing: \"smooth\",\r\n    exit: \"mirror\",\r\n    exitDirection: \"up\",\r\n    exitDistance: 8,\r\n    exitDuration: 11,\r\n  },\r\n  \"blur-out-up\": {\r\n    unit: \"word\",\r\n    effects: [\"fade\", \"slide\", \"blur\"],\r\n    direction: \"up\",\r\n    distance: 10,\r\n    blurAmount: 6,\r\n    stagger: 1,\r\n    enterDuration: 17,\r\n    easing: \"smooth\",\r\n    exit: \"mirror\",\r\n    exitDirection: \"up\",\r\n    exitDistance: 14,\r\n    exitBlur: 8,\r\n    exitDuration: 14,\r\n    exitStagger: 1,\r\n  },\r\n  \"focus-blur-resolve\": {\r\n    unit: \"block\",\r\n    effects: [\"fade\", \"slide\", \"blur\", \"scale\"],\r\n    direction: \"up\",\r\n    distance: 14,\r\n    blurAmount: 14,\r\n    scaleFrom: 1.01,\r\n    enterDuration: 23,\r\n    easing: \"smooth\",\r\n    exit: \"mirror\",\r\n    exitDirection: \"up\",\r\n    exitDistance: 10,\r\n    exitBlur: 10,\r\n    exitDuration: 16,\r\n  },\r\n  \"line-by-line-slide\": {\r\n    unit: \"line\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"right\",\r\n    distance: 48,\r\n    stagger: 4,\r\n    enterDuration: 27,\r\n    easing: \"smooth\",\r\n    exit: \"mirror\",\r\n    exitDirection: \"right\",\r\n    exitDistance: 48,\r\n    exitDuration: 18,\r\n    exitStagger: 2,\r\n    align: \"left\",\r\n  },\r\n  \"mask-reveal-up\": {\r\n    unit: \"line\",\r\n    effects: [\"slide\", \"mask\"],\r\n    direction: \"up\",\r\n    distance: 30,\r\n    stagger: 3,\r\n    enterDuration: 23,\r\n    easing: \"smooth\",\r\n    exit: \"mirror\",\r\n    exitDirection: \"up\",\r\n    exitDistance: 22,\r\n    exitDuration: 16,\r\n    exitStagger: 2,\r\n  },\r\n  \"tracking-in\": {\r\n    unit: \"block\",\r\n    effects: [\"fade\", \"blur\", \"tracking\"],\r\n    blurAmount: 12,\r\n    trackingFrom: 0.5,\r\n    enterDuration: 30,\r\n    easing: \"spring\",\r\n    exit: \"none\",\r\n  },\r\n  \"short-slide-right\": {\r\n    unit: \"word\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"right\",\r\n    distance: 24,\r\n    stagger: 3,\r\n    enterDuration: 16,\r\n    easing: \"snappy\",\r\n    exit: \"none\",\r\n  },\r\n  \"staggered-fade-up\": {\r\n    unit: \"word\",\r\n    effects: [\"fade\", \"slide\"],\r\n    direction: \"up\",\r\n    distance: 20,\r\n    stagger: 4,\r\n    enterDuration: 12,\r\n    easing: \"linear\",\r\n    exit: \"none\",\r\n  },\r\n};\r\n\r\nconst VALID_EFFECTS: TextRevealEffect[] = [\r\n  \"fade\",\r\n  \"slide\",\r\n  \"blur\",\r\n  \"scale\",\r\n  \"mask\",\r\n  \"tracking\",\r\n];\r\n\r\n/** Accepts an array or a comma-separated string (\"fade,slide\"). */\r\nexport function normalizeEffects(\r\n  effects: TextRevealEffect[] | string | undefined,\r\n): TextRevealEffect[] {\r\n  if (effects === undefined) return [...TEXT_REVEAL_DEFAULTS.effects];\r\n  const list = Array.isArray(effects)\r\n    ? effects\r\n    : (effects.split(\",\").map((e) => e.trim()) as TextRevealEffect[]);\r\n  const out = list.filter(\r\n    (e): e is TextRevealEffect => VALID_EFFECTS.indexOf(e) !== -1,\r\n  );\r\n  return out.length > 0 ? out : [...TEXT_REVEAL_DEFAULTS.effects];\r\n}\r\n\r\n/** Splits text into animation units. `block` keeps the whole string as one unit. */\r\nexport function splitText(text: string, unit: TextRevealUnit): string[] {\r\n  switch (unit) {\r\n    case \"character\":\r\n      return Array.from(text);\r\n    case \"word\":\r\n      return text.split(\" \").filter((w) => w.length > 0);\r\n    case \"line\":\r\n      return text.split(\"\\n\");\r\n    case \"block\":\r\n      return [text];\r\n  }\r\n}\r\n\r\n/**\r\n * Analytic damped-spring progress curve (deterministic, no simulation).\r\n * Starts at 0, settles at 1 with a small (~1%) high-damping overshoot.\r\n */\r\nexport function springEase(t: number): number {\r\n  return 1 - Math.exp(-7 * t) * Math.cos(4.5 * t);\r\n}\r\n\r\nexport function resolveEasing(easing: TextRevealEasing): (t: number) => number {\r\n  if (Array.isArray(easing)) {\r\n    return Easing.bezier(easing[0], easing[1], easing[2], easing[3]);\r\n  }\r\n  switch (easing) {\r\n    case \"smooth\":\r\n      return Easing.bezier(0.22, 1, 0.36, 1);\r\n    case \"snappy\":\r\n      return Easing.bezier(0.2, 0.8, 0.2, 1);\r\n    case \"overshoot\":\r\n      return Easing.bezier(0.34, 1.56, 0.64, 1);\r\n    case \"spring\":\r\n      return springEase;\r\n    case \"linear\":\r\n      return (t: number) => t;\r\n  }\r\n}\r\n\r\n/** Accelerating ease used for all mirror exits (matches the legacy exits). */\r\nexport const EXIT_EASING = Easing.bezier(0.64, 0, 0.78, 0);\r\n\r\n/**\r\n * Offset a unit starts from so it travels in `direction` during enter.\r\n * \"up\" rises from below, \"right\" arrives from the left, etc.\r\n */\r\nexport function enterOffset(\r\n  direction: TextRevealDirection,\r\n  distance: number,\r\n): { x: number; y: number } {\r\n  switch (direction) {\r\n    case \"up\":\r\n      return { x: 0, y: distance };\r\n    case \"down\":\r\n      return { x: 0, y: -distance };\r\n    case \"left\":\r\n      return { x: distance, y: 0 };\r\n    case \"right\":\r\n      return { x: -distance, y: 0 };\r\n  }\r\n}\r\n\r\n/** Offset a unit travels to during a mirror exit (keeps moving in `direction`). */\r\nexport function exitOffset(\r\n  direction: TextRevealDirection,\r\n  distance: number,\r\n): { x: number; y: number } {\r\n  const from = enterOffset(direction, distance);\r\n  // `+ 0` normalizes -0 to 0 for clean equality and CSS output.\r\n  return { x: -from.x + 0, y: -from.y + 0 };\r\n}\r\n\r\nexport interface ExitScheduleInput {\r\n  unitCount: number;\r\n  enterDuration: number;\r\n  stagger: number;\r\n  exitDuration: number;\r\n  exitStagger: number;\r\n  /** Total frames available (durationInFrames * speed). */\r\n  totalFrames: number;\r\n}\r\n\r\n/**\r\n * Auto-schedules the mirror exit: it starts as late as possible so the last\r\n * unit finishes exactly at the end of the composition, but never before the\r\n * enter animation (including its stagger tail) has completed.\r\n */\r\nexport function scheduleExit(input: ExitScheduleInput): {\r\n  enterEnd: number;\r\n  exitStart: number;\r\n} {\r\n  const tail = Math.max(0, input.unitCount - 1);\r\n  const enterEnd = input.enterDuration + tail * input.stagger;\r\n  const exitStart = Math.max(\r\n    enterEnd,\r\n    input.totalFrames - input.exitDuration - tail * input.exitStagger,\r\n  );\r\n  return { enterEnd, exitStart };\r\n}\r\n\r\nexport interface TextRevealPropsInput\r\n  extends Partial<Omit<TextRevealSettings, \"effects\" | \"exitDirection\">> {\r\n  text?: string;\r\n  effects?: TextRevealEffect[] | string;\r\n  exitDirection?: TextRevealDirection;\r\n  preset?: TextRevealPreset | \"none\";\r\n  className?: string;\r\n}\r\n\r\n/**\r\n * Merges defaults, caller props and the preset bundle into concrete settings.\r\n * Precedence: defaults < props < preset — a preset is a locked, documented\r\n * look; set `preset` to \"none\" (or omit it) to drive the motion props\r\n * yourself. `exitDirection` inherits `direction` when unset.\r\n */\r\nexport function resolveTextRevealSettings(\r\n  props: TextRevealPropsInput,\r\n): TextRevealSettings {\r\n  const explicit: Record<string, unknown> = {};\r\n  // `keys`, not `Object.entries` (ES2017): stock Remotion types ES2015.\r\n  for (const key of Object.keys(props)) {\r\n    const value = (props as Record<string, unknown>)[key];\r\n    if (value !== undefined && key !== \"preset\") explicit[key] = value;\r\n  }\r\n  const preset =\r\n    props.preset && props.preset !== \"none\"\r\n      ? TEXT_REVEAL_PRESETS[props.preset]\r\n      : undefined;\r\n  const merged = {\r\n    ...TEXT_REVEAL_DEFAULTS,\r\n    ...explicit,\r\n    ...preset,\r\n  } as TextRevealSettings & { effects: TextRevealEffect[] | string };\r\n  const exitDirection = (preset?.exitDirection ??\r\n    props.exitDirection ??\r\n    preset?.direction ??\r\n    props.direction ??\r\n    TEXT_REVEAL_DEFAULTS.direction) as TextRevealDirection;\r\n  return {\r\n    ...merged,\r\n    effects: normalizeEffects(merged.effects),\r\n    exitDirection,\r\n  };\r\n}\r\n\r\nexport interface TextRevealProps {\r\n  /** The sentence to assemble. Its first word leads the reveal. */\r\n  text?: string;\r\n  /** Final font size in px (the size the line settles at). */\r\n  fontSize?: number;\r\n  /** Overrides the design system's `foreground`. */\r\n  color?: string;\r\n  fontWeight?: number | string;\r\n  /** Design-system token overrides. */\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  /**\r\n   * The face this scene paints its words in — a label from `fonts.ts`\r\n   * (\"Inter\", \"Space Grotesk\", \"Instrument Serif\") or a CSS family you have\r\n   * loaded yourself. Unset, the scene keeps the face it was designed around.\r\n   *\r\n   * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole\r\n   * timeline from one value.\r\n   */\r\n  fontFamily?: string;\r\n  /** How much larger the lead word starts (2 = twice the final size). */\r\n  initialScale?: number;\r\n  /** Frames the lead word fades in over at the very start. */\r\n  introDuration?: number;\r\n  /**\r\n   * Frames the lead word spends big and centred, drifting toward the viewer,\r\n   * before it falls back.\r\n   */\r\n  holdDuration?: number;\r\n  /** How far toward the viewer the lead word drifts during the hold (1.06 = 6% larger). */\r\n  pushScale?: number;\r\n  /** Frames the lead word takes to fall back from its peak to its final size. */\r\n  recedeDuration?: number;\r\n  /**\r\n   * Frames the line takes to slide left into its resting place. Starts with the\r\n   * recede but runs well past it, so the line barely moves while the lead word\r\n   * is still falling back and only travels once it has landed.\r\n   */\r\n  assembleDuration?: number;\r\n  /** Frames after the recede begins before the second word pushes in. */\r\n  wordDelay?: number;\r\n  /** Frames between each trailing word pushing in. */\r\n  wordStagger?: number;\r\n  /** Frames a trailing word takes to push into its slot. */\r\n  wordDuration?: number;\r\n  /** How far right of its slot a trailing word starts, in em. */\r\n  wordPush?: number;\r\n  /**\r\n   * Frames a trailing word fades in over. Deliberately tiny — the word should\r\n   * read as _pushed_ into place, not faded in. Raise it for a softer arrival.\r\n   */\r\n  wordFade?: number;\r\n  /** Resting letter-spacing (CSS value, em recommended). */\r\n  letterSpacing?: string;\r\n  speed?: number;\r\n  className?: string;\r\n}\r\n\r\n/**\r\n * The lead word's drift toward the viewer: decelerating, so it hangs at the\r\n * peak for a beat before it falls back.\r\n */\r\nconst PUSH_EASE = Easing.bezier(0.25, 1, 0.5, 1);\r\n\r\n/**\r\n * Shared curve for the recede and the slide-left. Heavily eased in — barely 10%\r\n * travelled at a third of the way through — so a long `assembleDuration` keeps\r\n * the line practically still while the lead word falls back, then carries it\r\n * left and decelerates to a dead stop. No bounce.\r\n */\r\nconst ZOOM_EASE = Easing.bezier(0.5, 0, 0.05, 1);\r\n\r\n/** A trailing word's push into its slot: quick off the mark, long soft landing. */\r\nconst WORD_EASE = Easing.bezier(0.22, 0.8, 0.36, 1);\r\n\r\n/**\r\n * Cinematic \"zoom-out from the lead word\" reveal, in four beats:\r\n *\r\n * 1. The lead word fades in large and centred — close to the viewer.\r\n * 2. It drifts a little _closer_ still, hanging at the peak.\r\n * 3. It falls back to its final size, roughly in place.\r\n * 4. Only once it has landed does the line travel left, while the trailing words\r\n *    push in one by one from the right and settle.\r\n *\r\n * Beats 3 and 4 start on the same frame but run on very different clocks: the\r\n * recede is short, the slide is long and heavily eased in, which is what makes\r\n * the word read as going _back_ first and moving left second rather than doing\r\n * both at once. The trailing words stay invisible until `wordDelay` frames into\r\n * the recede — so none of them show up mid-flight while the lead word is still\r\n * travelling — then cut in a push-distance right of their slot and slide home.\r\n *\r\n * Only `scale`, `translate` and `opacity` animate — nothing reflows — so it\r\n * stays GPU-cheap with a constant baseline and no layout shift.\r\n */\r\nexport function TextReveal({\r\n  text = \"Meet Acme Billing\",\r\n  fontSize = 72,\r\n  color,\r\n  fontWeight = 600,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  initialScale = 2.3,\r\n  introDuration = 6,\r\n  holdDuration = 12,\r\n  pushScale = 1.06,\r\n  recedeDuration = 14,\r\n  assembleDuration = 30,\r\n  wordDelay = 7,\r\n  wordStagger = 4,\r\n  wordDuration = 14,\r\n  wordPush = 0.5,\r\n  wordFade = 2,\r\n  letterSpacing = \"-0.03em\",\r\n  speed = 1,\r\n  className,\r\n}: TextRevealProps) {\r\n  const frame = useCurrentFrame() * speed;\r\n  const { width } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face =\r\n    resolveFont(fontFamily ?? t.fontFamily) ??\r\n    \"-apple-system, BlinkMacSystemFont, sans-serif\";\r\n  const fill = color ?? t.foreground;\r\n\r\n  // The lead word is centred in the frame while big, then lands at its natural\r\n  // spot in the line. That needs the line's rendered width and where the lead\r\n  // word's centre sits inside it — both constant across frames, so measure once\r\n  // and hold the render until they're known.\r\n  const lineRef = useRef<HTMLSpanElement>(null);\r\n  const leadRef = useRef<HTMLSpanElement>(null);\r\n  const [handle] = useState(() => delayRender(\"text-reveal: measure line\"));\r\n  const baselineRef = useRef<HTMLSpanElement>(null);\r\n  const [metrics, setMetrics] = useState<{\r\n    lineWidth: number;\r\n    leadRatio: number;\r\n    /** Distance from the top of the line box down to the text baseline. */\r\n    baseline: number;\r\n  } | null>(null);\r\n\r\n  // Measure the natural line geometry. offsetWidth / offsetLeft are layout px,\r\n  // unaffected by the animated transform or the Player's display scaling, so they\r\n  // give the unscaled line width and the lead word's centre directly.\r\n  useEffect(() => {\r\n    const line = lineRef.current;\r\n    const lead = leadRef.current;\r\n    if (!line || !lead) {\r\n      continueRender(handle);\r\n      return;\r\n    }\r\n    const lineWidth = line.offsetWidth;\r\n    const leadCenter = lead.offsetLeft + lead.offsetWidth / 2;\r\n    // An empty, zero-sized inline-block sits with its bottom edge on the text\r\n    // baseline, so its offsetTop *is* the baseline — read from the font's real\r\n    // metrics rather than guessed from a line-height ratio.\r\n    const baseline = baselineRef.current?.offsetTop ?? line.offsetHeight * 0.8;\r\n    setMetrics({ lineWidth, leadRatio: leadCenter / lineWidth, baseline });\r\n  }, [handle]);\r\n\r\n  // Release the render only after the measurement has re-rendered, so the very\r\n  // first captured frame already carries the correct geometry (no blank frame).\r\n  useEffect(() => {\r\n    if (metrics) continueRender(handle);\r\n  }, [metrics, handle]);\r\n\r\n  const words = text.split(\" \").filter(Boolean);\r\n\r\n  /**\r\n   * Two things make a browser's scaled text look stuck and shaky, and both are\r\n   * the type being quantised rather than the animation being wrong.\r\n   *\r\n   * **The stick.** The glyph rasteriser snaps each glyph's origin to the pixel\r\n   * grid — quarter-pixel precision horizontally, and none at all vertically. So a\r\n   * scale that moves the baseline makes the type climb the grid in whole-pixel\r\n   * steps: during the slow ends of an eased curve the baseline drifts a fraction\r\n   * of a pixel per frame, which rounds to nothing for several frames and then to a\r\n   * whole pixel at once. Pivoting the scale *on the baseline* means the baseline's\r\n   * device Y never changes, so there is nothing to snap.\r\n   *\r\n   * **The shake.** Hinting distorts each glyph's outline so its stems land on\r\n   * whole pixels. As the size slides, every stem re-snaps to a different grid and\r\n   * the letterforms visibly change shape frame to frame — they boil.\r\n   * `text-rendering: geometricPrecision` turns hinting off and renders the outline\r\n   * as it actually is.\r\n   *\r\n   * Measured on the sibling component: vertical judder 0.296px → 0.005px, and the\r\n   * shape invariant steadied from 3.41% drift to 0.22%.\r\n   */\r\n\r\n  const ready = metrics !== null;\r\n  const leadRatio = metrics?.leadRatio ?? 0.14;\r\n  const lineWidth = metrics?.lineWidth ?? width * 0.5;\r\n  // Distance from the top of the line box down to the text baseline — the one\r\n  // point the scale must not move.\r\n  const baseline = metrics?.baseline ?? fontSize * 0.88;\r\n\r\n  // The lead word falls back and the line starts sliding on the same frame.\r\n  const zoomStart = holdDuration;\r\n  // How far the line has to travel to carry the lead word's centre from the\r\n  // frame centre to its natural spot in the sentence.\r\n  const slideDistance = lineWidth * (0.5 - leadRatio);\r\n\r\n  return (\r\n    <AbsoluteFill\r\n      style={{\r\n        alignItems: \"center\",\r\n        justifyContent: \"center\",\r\n        background: \"transparent\",\r\n      }}\r\n    >\r\n      <span\r\n        ref={lineRef}\r\n        className={className}\r\n        style={{\r\n          position: \"relative\",\r\n          display: \"inline-block\",\r\n          fontSize,\r\n          fontWeight,\r\n          color: fill,\r\n          letterSpacing,\r\n          lineHeight: 1.1,\r\n          whiteSpace: \"nowrap\",\r\n          fontFamily: face,\r\n          // Pivot on the lead word's centre horizontally — so the line scales out\r\n          // from that word and it stays planted — and on the baseline vertically,\r\n          // which is the point that must not move. See above.\r\n          transformOrigin: `${leadRatio * 100}% ${baseline}px`,\r\n          // Drift toward the viewer, then the fall back. The two curves never\r\n          // overlap — the first clamps at the peak once the recede starts, the\r\n          // second is 0 until then — so they sum into one continuous scale\r\n          // running initialScale → peak → 1.\r\n          scale:\r\n            interpolate(\r\n              frame,\r\n              [0, holdDuration],\r\n              [initialScale, initialScale * pushScale],\r\n              {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n                easing: PUSH_EASE,\r\n              },\r\n            ) +\r\n            interpolate(\r\n              frame,\r\n              [zoomStart, zoomStart + recedeDuration],\r\n              [0, 1 - initialScale * pushScale],\r\n              {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n                easing: ZOOM_EASE,\r\n              },\r\n            ),\r\n          // The slide left: same start frame as the recede, but it runs about\r\n          // twice as long on a heavily eased-in curve, so the line holds its\r\n          // ground while the lead word falls back and only travels once it has\r\n          // landed.\r\n          translate: `${interpolate(\r\n            frame,\r\n            [zoomStart, zoomStart + assembleDuration],\r\n            [slideDistance, 0],\r\n            {\r\n              extrapolateLeft: \"clamp\",\r\n              extrapolateRight: \"clamp\",\r\n              easing: ZOOM_EASE,\r\n            },\r\n          )}px`,\r\n          opacity: ready ? 1 : 0,\r\n          // Hinting off: renders each outline as it actually is, so the\r\n          // letterforms stop re-snapping to the pixel grid as the size slides.\r\n          // Also forces sub-pixel glyph positioning, which Blink otherwise only\r\n          // enables above a device scale factor of 1 — and a render is exactly 1.\r\n          textRendering: \"geometricPrecision\",\r\n          // Rendering and live playback want opposite things here, so give each\r\n          // what it needs.\r\n          //\r\n          // A render has no time budget: the browser re-shapes and re-rasterises\r\n          // every glyph at every new size, which is why the type stays genuinely\r\n          // crisp, and the two fixes above are what make that smooth. Compositing\r\n          // it would only replace real type with a rescaled texture — and worse,\r\n          // a render is spread across parallel browser tabs, each of which\r\n          // inherits a stale raster from whatever scale it drew last, so the same\r\n          // frame comes out differently depending on which tab drew it.\r\n          //\r\n          // The Player is the opposite: one continuous tab, and roughly eight\r\n          // milliseconds a frame on a 120Hz screen. Re-shaping a line of type at\r\n          // a brand-new size every frame is the most expensive way to draw text,\r\n          // and a frame that misses the budget is simply shown for the wrong\r\n          // length of time — stutter that no amount of CSS can fix. So for live\r\n          // playback, hand the scale to the compositor: measured on a single\r\n          // continuous tab it is smooth (0.016px of judder) with no loss of\r\n          // sharpness at all.\r\n          ...(getRemotionEnvironment().isRendering\r\n            ? null\r\n            : { willChange: \"transform\" as const }),\r\n        }}\r\n      >\r\n        {words.map((word, i) => {\r\n          const isLead = i === 0;\r\n          // Each trailing word sits out most of the recede, then pushes in from\r\n          // the right into its slot. The lead word is the anchor: it never\r\n          // pushes, and it is the only word visible until `wordDelay`.\r\n          const pushStart = zoomStart + wordDelay + (i - 1) * wordStagger;\r\n          const opacity = isLead\r\n            ? interpolate(frame, [0, introDuration], [0, 1], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              })\r\n            : interpolate(frame, [pushStart, pushStart + wordFade], [0, 1], {\r\n                extrapolateLeft: \"clamp\",\r\n                extrapolateRight: \"clamp\",\r\n              });\r\n          return (\r\n            <span\r\n              // biome-ignore lint/suspicious/noArrayIndexKey: words are positional and never reorder\r\n              key={i}\r\n              ref={isLead ? leadRef : undefined}\r\n              style={{\r\n                display: \"inline-block\",\r\n                opacity,\r\n                translate: isLead\r\n                  ? undefined\r\n                  : `${interpolate(\r\n                      frame,\r\n                      [pushStart, pushStart + wordDuration],\r\n                      [wordPush * fontSize, 0],\r\n                      {\r\n                        extrapolateLeft: \"clamp\",\r\n                        extrapolateRight: \"clamp\",\r\n                        easing: WORD_EASE,\r\n                      },\r\n                    )}px`,\r\n              }}\r\n            >\r\n              {word}\r\n              {i < words.length - 1 ? \" \" : \"\"}\r\n            </span>\r\n          );\r\n        })}\r\n        {/* Baseline ruler. An empty, zero-sized inline-block aligns its bottom\r\n            edge to the text baseline, so `offsetTop` reads the baseline straight\r\n            off the font's real metrics. Zero-sized, so it changes no layout. */}\r\n        <span\r\n          ref={baselineRef}\r\n          style={{ display: \"inline-block\", width: 0, height: 0 }}\r\n        />\r\n      </span>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}