{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"text-select","type":"registry:component","title":"Text Select","description":"Typewriter with text selection: a line types word by word, then gets highlighted. A line that writes itself a word at a time — each one arriving in the accent and cooling to the foreground a beat later, so exactly one word is ever coloured — then pushes forward to full size on a baseline-pivoted scale and gets selected, the drag sweeping across under a gradient sheen with a hard caret edge.","dependencies":["remotion","@remotion/google-fonts"],"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-select.tsx","type":"registry:component","target":"components/kuchi/text-select.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Inter\";\r\nimport { Fragment, 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  mixOklch,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n  withAlpha,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n// Loaded through @remotion/google-fonts, never a CSS variable — a Remotion\r\n// bundle has none of the app's CSS, so a `var(--font-…)` gets you the right face\r\n// in the Player and a fallback in the mp4 (design-system rule 4).\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"400\", \"500\", \"600\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\n// --- The stage -------------------------------------------------------------\r\n//\r\n// The reference recording is 810×458 — near enough 16:9 — and every number\r\n// below was read off its frames, so there is no second conversion to get wrong.\r\n\r\nconst REF_W = 810;\r\nconst REF_H = 458;\r\n\r\n// --- Measured proportions --------------------------------------------------\r\n\r\n/** The line is set tight: a hair of negative tracking and tighter word gaps. */\r\nconst TRACKING = -0.012;\r\nconst WORD_GAP = -0.07;\r\n/** Selection box: 0.941em tall, sitting 0.120em below the baseline. */\r\nconst SEL_HEIGHT = 0.941;\r\nconst SEL_BELOW = 0.12;\r\n/** …and reaching 0.063em past the type on each side, as a caret's would. */\r\nconst SEL_PAD = 0.063;\r\n\r\n/**\r\n * The sheen, read straight off the reference.\r\n *\r\n * The selection is **not a flat fill**. Sampled column by column with the glyphs\r\n * masked out, its blue deepens to a trough a third of the way across, opens into\r\n * a bright band at 59%, and closes again toward the right edge — a swing of 2.8×\r\n * in strength from the palest point to the deepest. Each pair is `[position,\r\n * multiple of the base alpha]`.\r\n *\r\n * It is anchored to the **box**, not to the page: through the whole drag the\r\n * bright band sits at 0.58 of whatever width the box has reached that frame\r\n * (measured: 0.584, 0.571, 0.580, 0.603, 0.585, 0.576, 0.589 …), which is what a\r\n * CSS gradient on a growing element does for free — and it is why the sheen\r\n * appears to travel while the selection is being pulled across.\r\n */\r\nconst SHEEN: readonly (readonly [number, number])[] = [\r\n  [0, 0.72],\r\n  [0.1, 0.95],\r\n  [0.19, 1.12],\r\n  [0.3, 1.42],\r\n  [0.37, 1.44],\r\n  [0.44, 1.22],\r\n  [0.51, 0.78],\r\n  [0.59, 0.51],\r\n  [0.69, 0.74],\r\n  [0.78, 0.88],\r\n  [0.89, 1.05],\r\n  [1, 1.2],\r\n];\r\n\r\n// --- Measured timeline, in seconds -----------------------------------------\r\n\r\n/** A word lands every 208ms, and each one resolves in 130ms. */\r\nconst WORD_STAGGER = 0.208;\r\nconst WORD_DUR = 0.13;\r\n/** The line arrives from 0.475em to the right on every word, and settles. */\r\nconst SHIFT_X = 0.475;\r\nconst SHIFT_Y = 0.085;\r\n/** Barely a blur — 1px at 20px type. It softens the landing, nothing more. */\r\nconst WORD_BLUR = 1;\r\n/** A word stays accent-coloured for one beat, then cools over another. */\r\nconst COOL_DELAY = 0.208;\r\nconst COOL_DUR = 0.208;\r\n\r\n/** Fitted to the ink: half the distance in the first eighth of the move. */\r\nconst WORD_EASE = Easing.out(Easing.poly(4));\r\n/** The drag. Harder still — it is a hand pulling a selection, not a tween. */\r\nconst SELECT_EASE = Easing.out(Easing.poly(5));\r\n/**\r\n * The push forward.\r\n *\r\n * A *moderate* decelerate on purpose. Quint- and expo-out cover 99% of their\r\n * travel in the first third and then crawl, and on a frame clock that crawl is\r\n * not a settle, it is identical frames — measured elsewhere in this repo, five\r\n * of fourteen frames moved under half a pixel and the type visibly stopped dead\r\n * partway. This curve arrives at a standstill without spending frames on travel\r\n * you cannot see.\r\n */\r\nconst ZOOM_EASE = Easing.bezier(0.2, 0.6, 0.35, 1);\r\n\r\n// --- Pure helpers (unit-tested) --------------------------------------------\r\n\r\nexport interface WordInk {\r\n  /** 0 before its cue, 1 once it has landed. */\r\n  opacity: number;\r\n  /** How far through the accent → foreground cool-down it is. */\r\n  cool: number;\r\n  blur: number;\r\n}\r\n\r\n/**\r\n * One word's arrival and its cool-down.\r\n *\r\n * The entrance is a **fade**, not the scale-and-blur of a title reveal: measure\r\n * the ink and its second moment barely moves (11.87px → 11.79px rms), so there\r\n * is no scale worth the name and about a pixel of blur. What does move is the\r\n * whole line — see `lineShift`.\r\n *\r\n * The colour is the other half. A word arrives in the accent, holds it for one\r\n * beat while it is the newest thing on the line, and cools to the foreground\r\n * over the next — which is what makes the eye follow the line left to right\r\n * instead of reading it all at once.\r\n */\r\nexport function wordInk(\r\n  t: number,\r\n  index: number,\r\n  o: {\r\n    at: number;\r\n    stagger: number;\r\n    dur: number;\r\n    coolDelay: number;\r\n    coolDur: number;\r\n    blur: number;\r\n    /** Set on the last word: it cools on the drag, not on a word that never comes. */\r\n    selectAt?: number;\r\n    selectDur?: number;\r\n  },\r\n): WordInk {\r\n  const cue = o.at + index * o.stagger;\r\n  if (t < cue) return { opacity: 0, cool: 0, blur: o.blur };\r\n  const p = interpolate(t, [cue, cue + o.dur], [0, 1], {\r\n    extrapolateLeft: \"clamp\",\r\n    extrapolateRight: \"clamp\",\r\n    easing: WORD_EASE,\r\n  });\r\n  // Every word cools one beat after it lands — one beat being exactly the\r\n  // stagger, so the accent walks the line. The last word has no next word to\r\n  // hand off to, and on the reference it cools as the selection is dragged\r\n  // across, in half the time the drag takes.\r\n  const usesDrag = o.selectAt !== undefined && o.selectAt > cue;\r\n  const coolFrom = usesDrag ? (o.selectAt as number) : cue + o.coolDelay;\r\n  const coolOver = usesDrag ? (o.selectDur as number) / 2 : o.coolDur;\r\n  const cool = interpolate(t, [coolFrom, coolFrom + coolOver], [0, 1], {\r\n    extrapolateLeft: \"clamp\",\r\n    extrapolateRight: \"clamp\",\r\n  });\r\n  return { opacity: p, cool, blur: o.blur * (1 - p) };\r\n}\r\n\r\n/**\r\n * How far right the whole line still is, in em.\r\n *\r\n * This is the measurement that took the longest to see. When the second word\r\n * lands, the first one moves — but so does the second, by the *same* 10px, and\r\n * a line that grew a word would not do that. It is not the layout re-centring\r\n * and it is not the new word widening into place: the entire line arrives half\r\n * an em to the right on every word and settles back, which reads as the line\r\n * being nudged along rather than stretched.\r\n */\r\nexport function lineShift(\r\n  t: number,\r\n  words: number,\r\n  o: { at: number; stagger: number; dur: number },\r\n): number {\r\n  if (t < o.at) return 1;\r\n  const landed = Math.min(words - 1, Math.floor((t - o.at) / o.stagger));\r\n  const cue = o.at + landed * o.stagger;\r\n  return (\r\n    1 -\r\n    interpolate(t, [cue, cue + o.dur], [0, 1], {\r\n      extrapolateLeft: \"clamp\",\r\n      extrapolateRight: \"clamp\",\r\n      easing: WORD_EASE,\r\n    })\r\n  );\r\n}\r\n\r\n/**\r\n * The push forward, as a scale.\r\n *\r\n * On the reference this is a **cut**: 215px of ink on one frame and 516px on the\r\n * next, with the single dropped frame between them the only place an in-between\r\n * could have hidden. Set `dur` to 0 and you get that exactly.\r\n *\r\n * It defaults to a ramp because a cut is the one thing a 30fps composition\r\n * cannot make read as *coming forward* — at that frame rate a step reads as an\r\n * edit, not a move. The ramp is a moderate decelerate for the reason in\r\n * `ZOOM_EASE`, and it is a **transform**, never an animated `font-size`:\r\n * font-size reflows every frame *and* still hits glyph snapping.\r\n */\r\nexport function zoomScale(\r\n  t: number,\r\n  o: { at: number; dur: number; to: number },\r\n): number {\r\n  if (o.dur <= 0) return t >= o.at ? o.to : 1;\r\n  return interpolate(t, [o.at, o.at + o.dur], [1, o.to], {\r\n    extrapolateLeft: \"clamp\",\r\n    extrapolateRight: \"clamp\",\r\n    easing: ZOOM_EASE,\r\n  });\r\n}\r\n\r\n/**\r\n * The selection, as a fraction of the line it has covered.\r\n *\r\n * A drag, not a wipe: it is 31% across in the first frame and spends the back\r\n * half of its time covering the last 5%. Fitted to the sweep edge on fourteen\r\n * frames, `easeOutQuint` over 220ms is what that is.\r\n */\r\nexport function selectionSweep(\r\n  t: number,\r\n  o: { at: number; dur: number },\r\n): number {\r\n  return interpolate(t, [o.at, o.at + o.dur], [0, 1], {\r\n    extrapolateLeft: \"clamp\",\r\n    extrapolateRight: \"clamp\",\r\n    easing: SELECT_EASE,\r\n  });\r\n}\r\n\r\n/** The sheen as a CSS gradient, in `color` at `alpha` times each stop. */\r\nexport function sheenGradient(\r\n  color: string,\r\n  alpha: number,\r\n  angle: number,\r\n  stops: readonly (readonly [number, number])[] = SHEEN,\r\n): string {\r\n  const list = stops\r\n    .map(\r\n      ([u, k]) =>\r\n        `${withAlpha(color, Math.min(1, alpha * k))} ${(u * 100).toFixed(1)}%`,\r\n    )\r\n    .join(\", \");\r\n  return `linear-gradient(${angle}deg, ${list})`;\r\n}\r\n\r\n/**\r\n * Where the travelling glint sits, as a fraction of the selection box — or\r\n * `null` on the frames between passes.\r\n *\r\n * The sheen above is *anchored* to the box: it stretches as the box grows,\r\n * which is what the reference does, and it is the right description of a\r\n * selection being pulled across. But it stops the instant the drag lands, and a\r\n * highlight that stops moving stops shining. So a second, narrow band is swept\r\n * across the finished box on its own clock.\r\n *\r\n * It travels **linearly**. A specular is a light source passing a surface, not\r\n * something that settles, and a constant velocity is also the only curve that\r\n * cannot spend frames on travel too small to rasterise: at the defaults the\r\n * band covers 58px a frame from the first frame to the last.\r\n *\r\n * The range is `[-width/2, 1 + width/2]` so the band enters from off the left\r\n * edge and leaves off the right, rather than being born and dying inside the\r\n * box.\r\n */\r\nexport function shineSweep(\r\n  t: number,\r\n  o: { at: number; dur: number; every: number; width: number },\r\n): number | null {\r\n  if (o.dur <= 0 || t < o.at) return null;\r\n  const since = t - o.at;\r\n  const u = (o.every > 0 ? since % o.every : since) / o.dur;\r\n  if (u > 1) return null;\r\n  return -o.width / 2 + u * (1 + o.width);\r\n}\r\n\r\n/**\r\n * The glint as a CSS gradient: a soft band centred on `pos`, `width` wide.\r\n *\r\n * It is **not** just a light band. A white band over a light page has almost no\r\n * room to work in — measured on the render, white at 0.34 over a fill sitting at\r\n * R 230 lifts it eight levels, against the static sheen's own ±15. The glint was\r\n * quieter than the gradient it was supposed to be shining on.\r\n *\r\n * So it is shaped like a real specular on a coloured gel: a bright core with\r\n * **deepened shoulders** either side, where the light compresses the film. The\r\n * shoulders are painted in the selection's own colour, and there is plenty of\r\n * room downward — the same measurement gives them −17. A 25-level band, moving.\r\n *\r\n * The ends are at **zero alpha of a real colour**, never the keyword\r\n * `transparent` — `transparent` is `rgba(0,0,0,0)`, so a gradient running to it\r\n * fades through black and leaves a grey bruise on either side of the band.\r\n */\r\nexport function shineGradient(o: {\r\n  /** The light itself, at the centre of the band. */\r\n  core: string;\r\n  /** What the shoulders deepen with — the selection's own colour. */\r\n  shoulder: string;\r\n  /** Strength of the core. */\r\n  alpha: number;\r\n  /** Strength of the shoulders, as a fraction of the core's. */\r\n  depth: number;\r\n  /** Centre of the band, as a fraction of the box. */\r\n  pos: number;\r\n  /** Width of the band, as a fraction of the box. */\r\n  width: number;\r\n  angle: number;\r\n}): string {\r\n  const half = o.width / 2;\r\n  const at = (x: number) => `${(x * 100).toFixed(1)}%`;\r\n  const edge = Math.min(1, o.alpha * o.depth);\r\n  const s0 = withAlpha(o.shoulder, 0);\r\n  const s1 = withAlpha(o.shoulder, edge);\r\n  return (\r\n    `linear-gradient(${o.angle}deg, ${s0} ${at(o.pos - half)}, ` +\r\n    `${s1} ${at(o.pos - half * 0.55)}, ` +\r\n    `${withAlpha(o.core, Math.min(1, o.alpha))} ${at(o.pos)}, ` +\r\n    `${s1} ${at(o.pos + half * 0.55)}, ${s0} ${at(o.pos + half)})`\r\n  );\r\n}\r\n\r\n// --- Props -----------------------------------------------------------------\r\n\r\nexport interface TextSelectProps {\r\n  /** The line that writes itself, one word at a time. */\r\n  headline?: string;\r\n\r\n  // --- Timing, in seconds. ---\r\n  /** When the first word lands, and the gap between words. */\r\n  wordAt?: number;\r\n  wordStagger?: number;\r\n  /** How long a word takes to resolve. */\r\n  wordDuration?: number;\r\n  /** How far right the line arrives on each word, and how far down, in em. */\r\n  shiftX?: number;\r\n  shiftY?: number;\r\n  /** How soft a word arrives, in px at `fontSize`. */\r\n  wordBlur?: number;\r\n  /** How long a word holds the accent, and how long it takes to cool. */\r\n  coolDelay?: number;\r\n  coolDuration?: number;\r\n  /** When the line starts coming forward, how long it takes, and how far. */\r\n  cutAt?: number;\r\n  zoomDuration?: number;\r\n  zoom?: number;\r\n  /** When the selection is dragged across, and how long the drag takes. */\r\n  selectAt?: number;\r\n  selectDuration?: number;\r\n\r\n  // --- Size and paint. ---\r\n  /** Type size before the push, in stage px. */\r\n  fontSize?: number;\r\n  fontWeight?: number;\r\n  /** Where the line's box sits down the frame, as a fraction. */\r\n  centerY?: number;\r\n  /** Tracking and word gap, in em. */\r\n  tracking?: number;\r\n  wordGap?: number;\r\n  /** Base strength of the selection, before the sheen multiplies it. */\r\n  selectionOpacity?: number;\r\n  /** Angle of the sheen. 90 is the reference's — straight across. */\r\n  selectionAngle?: number;\r\n  /** Override the sheen shape entirely: `[position, × base alpha]` pairs. */\r\n  selectionSheen?: readonly (readonly [number, number])[];\r\n  /** How far the selection reaches past the type on each side, in em. */\r\n  selectionPad?: number;\r\n  /** The travelling glint's colour. Light, not accent — a specular adds. */\r\n  shineColor?: string;\r\n  /** How strong the glint's core is. 0 turns the whole thing off. */\r\n  shineOpacity?: number;\r\n  /** How hard the shoulders either side deepen, as a fraction of the core. */\r\n  shineDepth?: number;\r\n  /** How wide the glint is, as a fraction of the selection. */\r\n  shineWidth?: number;\r\n  /** Seconds at which the first pass starts. Defaults to the drag landing. */\r\n  shineAt?: number;\r\n  /** How long one pass takes to cross. */\r\n  shineDuration?: number;\r\n  /** Seconds between passes. 0 shines once and stops. */\r\n  shineEvery?: number;\r\n  /** The soft wash behind the line. */\r\n  glow?: boolean;\r\n  glowColor?: string;\r\n  glowOpacity?: number;\r\n  /** The colour a word arrives in, before it cools. Defaults to `theme.primary`. */\r\n  accentColor?: string;\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  speed?: number;\r\n}\r\n\r\n// --- Main composition ------------------------------------------------------\r\n\r\n/**\r\n * A line that writes itself a word at a time, comes forward, and gets selected —\r\n * the beat before somebody copies it.\r\n *\r\n * ## Four measurements, and they are the component\r\n *\r\n * **The newest word is the accent.** Every word arrives in the accent colour,\r\n * holds it for exactly one beat — 208ms, the same as the stagger — and cools to\r\n * the foreground over the next. So there is always exactly one coloured word,\r\n * and it walks the line ahead of the reader.\r\n *\r\n * **The whole line arrives half an em to the right on every word**, not just the\r\n * new one. Both words move by the same ten pixels when the second lands, which a\r\n * line that had merely grown a word would not do.\r\n *\r\n * **The selection is a drag.** It is 31% across on its first frame and spends the\r\n * back half of its time on the last 5% — `easeOutQuint` over 220ms, fitted to the\r\n * sweep edge across fourteen frames — and it has a hard vertical right edge,\r\n * because that is what a caret dragging through text leaves behind.\r\n *\r\n * **And the selection is not a flat fill.** Sample it column by column with the\r\n * glyphs masked out and the blue deepens to a trough a third of the way across,\r\n * opens into a bright band at 59%, and closes again at the right edge: a 2.8×\r\n * swing. The band is anchored to the *box*, so it sits at 0.58 of whatever width\r\n * the selection has reached on every frame of the drag — which is why it reads as\r\n * a shine travelling ahead of the caret.\r\n *\r\n * ## The one place this departs from the reference\r\n *\r\n * On the recording the size change is a **cut** — 215px of ink on one frame and\r\n * 516px on the next, with a single dropped frame the only place an in-between\r\n * could have hidden. Here it defaults to a 420ms push instead, because at 30fps a\r\n * step reads as an edit rather than as the line coming forward. `zoomDuration={0}`\r\n * gives you the measured cut back.\r\n *\r\n * Because it is a push, it is a **transform pivoted on the baseline**, measured\r\n * off the font's real metrics rather than guessed from a line-height ratio. That\r\n * is not a detail: the rasteriser gives glyph origins no vertical sub-pixel\r\n * precision at all, so a scale that moves the baseline makes the type climb the\r\n * pixel grid in whole-pixel jumps — sit still, jump, sit still. Pivot on the\r\n * baseline and there is nothing to snap. `text-rendering: geometricPrecision`\r\n * turns hinting off for the same reason: hinting re-snaps every stem as the size\r\n * slides, and the letterforms boil.\r\n *\r\n * ## What is not measured\r\n *\r\n * The colours and the wording. The reference is a specific product with a\r\n * specific blue; none of that belongs in a component that ships to strangers\r\n * (design-system rule 5). The paint is the shadcn token set, the accent and the\r\n * selection are `theme.primary` unless you say otherwise, and the line is a prop.\r\n */\r\nexport function TextSelect({\r\n  headline = \"One command into your project.\",\r\n  wordAt = 0.066,\r\n  wordStagger = WORD_STAGGER,\r\n  wordDuration = WORD_DUR,\r\n  shiftX = SHIFT_X,\r\n  shiftY = SHIFT_Y,\r\n  wordBlur = WORD_BLUR,\r\n  coolDelay = COOL_DELAY,\r\n  coolDuration = COOL_DUR,\r\n  cutAt = 1.13,\r\n  zoomDuration = 0.42,\r\n  zoom = 2.39,\r\n  selectAt = 1.4,\r\n  selectDuration = 0.26,\r\n  fontSize = 20,\r\n  fontWeight = 500,\r\n  centerY = 0.5116,\r\n  tracking = TRACKING,\r\n  wordGap = WORD_GAP,\r\n  selectionOpacity = 0.207,\r\n  selectionAngle = 90,\r\n  selectionSheen = SHEEN,\r\n  selectionPad = SEL_PAD,\r\n  shineColor = \"#ffffff\",\r\n  shineOpacity = 0.5,\r\n  shineDepth = 0.55,\r\n  shineWidth = 0.3,\r\n  shineAt,\r\n  shineDuration = 0.62,\r\n  shineEvery = 1.1,\r\n  glow = true,\r\n  glowColor,\r\n  glowOpacity = 0.075,\r\n  accentColor,\r\n  theme,\r\n  mode,\r\n  fontFamily,\r\n  speed = 1,\r\n}: TextSelectProps) {\r\n  const frame = useCurrentFrame();\r\n  const { width, height, fps } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS;\r\n  const accent = accentColor ?? t.primary;\r\n  const wash = glowColor ?? accent;\r\n\r\n  const now = (frame * speed) / fps;\r\n  const stageScale = Math.min(width / REF_W, height / REF_H);\r\n  const words = headline.split(/\\s+/).filter(Boolean);\r\n  const lineHeight = fontSize * 1.2;\r\n\r\n  // --- measure, once, behind delayRender ----------------------------------\r\n  //\r\n  // A hidden probe carries the *whole* line at the base size, so its width is\r\n  // the real rendered width — tracking, word-spacing and kerning included. That\r\n  // is a measurement `measureText` on a canvas cannot give: it knows nothing\r\n  // about CSS letter-spacing or word-spacing, and sizing the selection from it\r\n  // draws the box to a width the line does not have.\r\n  //\r\n  // The zero-sized inline-block inside it sits with its bottom edge on the text\r\n  // baseline, so its `offsetTop` reads the baseline off the font's real metrics.\r\n  const probeRef = useRef<HTMLSpanElement>(null);\r\n  const baselineRef = useRef<HTMLSpanElement>(null);\r\n  const [handle] = useState(() => delayRender(\"text-select: measure line\"));\r\n  const [metrics, setMetrics] = useState<{\r\n    lineWidth: number;\r\n    baseline: number;\r\n  } | null>(null);\r\n\r\n  useEffect(() => {\r\n    const probe = probeRef.current;\r\n    if (!probe) {\r\n      continueRender(handle);\r\n      return;\r\n    }\r\n    setMetrics({\r\n      lineWidth: probe.offsetWidth,\r\n      baseline: baselineRef.current?.offsetTop ?? lineHeight * 0.8,\r\n    });\r\n  }, [handle, lineHeight]);\r\n\r\n  // Release the render only once the measurement has re-rendered, so the very\r\n  // first captured frame already carries the correct geometry.\r\n  useEffect(() => {\r\n    if (metrics) continueRender(handle);\r\n  }, [metrics, handle]);\r\n\r\n  const lineWidth = metrics?.lineWidth ?? headline.length * fontSize * 0.5;\r\n  const baseline = metrics?.baseline ?? lineHeight * 0.8;\r\n  const boxTop = centerY * REF_H - lineHeight / 2;\r\n\r\n  // --- timeline -----------------------------------------------------------\r\n  const shift = lineShift(now, words.length, {\r\n    at: wordAt,\r\n    stagger: wordStagger,\r\n    dur: wordDuration,\r\n  });\r\n  const scale = zoomScale(now, { at: cutAt, dur: zoomDuration, to: zoom });\r\n  const sweep = selectionSweep(now, { at: selectAt, dur: selectDuration });\r\n\r\n  const pad = fontSize * selectionPad;\r\n  const selWidth = (lineWidth + pad * 2) * sweep;\r\n\r\n  // The glint runs on the finished box by default — during the drag the sheen\r\n  // is already travelling, because a gradient painted on a growing element\r\n  // travels for free, and two moving highlights at once is a busy frame.\r\n  const shinePos = shineSweep(now, {\r\n    at: shineAt ?? selectAt + selectDuration,\r\n    dur: shineDuration,\r\n    every: shineEvery,\r\n    width: shineWidth,\r\n  });\r\n\r\n  // `will-change` hands the scale to the compositor, which resamples a bitmap\r\n  // instead of re-rasterising real type. That is the right trade in the Player\r\n  // (one tab, an 8ms budget) and the wrong one in a render (parallel tabs, each\r\n  // inheriting a stale raster). And it is only worth paying *while the push is\r\n  // running* — hold the line at 2.39× under a promoted layer and you are looking\r\n  // at a 20px raster blown up.\r\n  const isRendering = getRemotionEnvironment().isRendering;\r\n  const pushing = now > cutAt && now < cutAt + zoomDuration;\r\n  const willChange =\r\n    !isRendering && pushing ? (\"transform\" as const) : undefined;\r\n\r\n  return (\r\n    <AbsoluteFill style={{ background: t.background }}>\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: \"50%\",\r\n          top: \"50%\",\r\n          width: REF_W,\r\n          height: REF_H,\r\n          transform: `translate(-50%, -50%) scale(${stageScale})`,\r\n          overflow: \"hidden\",\r\n          background: t.background,\r\n        }}\r\n      >\r\n        {/* The wash. Static — it does not move, breathe or answer the push on\r\n            the reference, and a glow that animates under a headline reads as a\r\n            mistake rather than as light. It sits outside the scaled group\r\n            because it belongs to the page, not to the line. */}\r\n        {glow ? (\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              inset: 0,\r\n              background: `radial-gradient(${0.46 * REF_W}px ${0.36 * REF_H}px at 50% ${centerY * 100}%, ${withAlpha(wash, glowOpacity)} 0%, transparent 74%)`,\r\n            }}\r\n          />\r\n        ) : null}\r\n\r\n        {/* The hidden ruler: the full line at the base size, laid out but never\r\n            painted, so the width and the baseline are the real ones. */}\r\n        <span\r\n          ref={probeRef}\r\n          style={{\r\n            position: \"absolute\",\r\n            left: 0,\r\n            top: 0,\r\n            visibility: \"hidden\",\r\n            whiteSpace: \"pre\",\r\n            fontFamily: face,\r\n            fontSize,\r\n            fontWeight,\r\n            lineHeight: `${lineHeight}px`,\r\n            letterSpacing: `${tracking}em`,\r\n            wordSpacing: `${wordGap}em`,\r\n          }}\r\n        >\r\n          {headline}\r\n          <span\r\n            style={{ display: \"inline-block\", width: 0, height: 0 }}\r\n            ref={baselineRef}\r\n          />\r\n        </span>\r\n\r\n        {/* The line and its selection, in one group so the push moves both.\r\n            The scale is pivoted on the **baseline**: the rasteriser gives glyph\r\n            origins no vertical sub-pixel precision, so any pivot that moves the\r\n            baseline makes the type climb the pixel grid in whole-pixel jumps. */}\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: 0,\r\n            right: 0,\r\n            top: boxTop,\r\n            height: lineHeight,\r\n            transform: `translate(${shift * fontSize * shiftX}px, ${shift * fontSize * shiftY}px) scale(${scale})`,\r\n            transformOrigin: `50% ${baseline}px`,\r\n            willChange,\r\n          }}\r\n        >\r\n          {/* The selection, behind the type. A hard right edge and no rounding:\r\n              this is a caret's drag, not a marker pen. The gradient is painted\r\n              on the box itself, so it stretches as the box grows — which is what\r\n              puts the sheen at 0.58 of the current width on every frame. */}\r\n          {sweep > 0 ? (\r\n            <div\r\n              style={{\r\n                position: \"absolute\",\r\n                left: REF_W / 2 - lineWidth / 2 - pad,\r\n                top: baseline + fontSize * SEL_BELOW - fontSize * SEL_HEIGHT,\r\n                width: selWidth,\r\n                height: fontSize * SEL_HEIGHT,\r\n                // Two layers, glint first: CSS paints background layers\r\n                // front to back, so the specular sits over the fill rather\r\n                // than replacing it.\r\n                background: [\r\n                  shinePos === null || shineOpacity <= 0\r\n                    ? null\r\n                    : shineGradient({\r\n                        core: shineColor,\r\n                        shoulder: accent,\r\n                        alpha: shineOpacity,\r\n                        depth: shineDepth,\r\n                        pos: shinePos,\r\n                        width: shineWidth,\r\n                        angle: selectionAngle,\r\n                      }),\r\n                  sheenGradient(\r\n                    accent,\r\n                    selectionOpacity,\r\n                    selectionAngle,\r\n                    selectionSheen,\r\n                  ),\r\n                ]\r\n                  .filter(Boolean)\r\n                  .join(\", \"),\r\n              }}\r\n            />\r\n          ) : null}\r\n\r\n          {/* The line. Only landed words are in the flow, so it grows and\r\n              re-centres exactly as the reference's does. Normal flow, not flex:\r\n              a flex container drops whitespace-only text nodes, so the spaces\r\n              between the words would vanish and the line would render narrower\r\n              than the ruler says it is. */}\r\n          <div\r\n            style={{\r\n              position: \"absolute\",\r\n              inset: 0,\r\n              textAlign: \"center\",\r\n              fontFamily: face,\r\n              fontSize,\r\n              fontWeight,\r\n              lineHeight: `${lineHeight}px`,\r\n              letterSpacing: `${tracking}em`,\r\n              wordSpacing: `${wordGap}em`,\r\n              whiteSpace: \"pre\",\r\n              // Hinting bends each glyph so its stems land on whole pixels, so\r\n              // as the size slides every stem re-snaps and the letterforms boil.\r\n              // This turns it off and draws the outline as it actually is —\r\n              // fifteen times steadier, measured on the shape invariant.\r\n              textRendering: \"geometricPrecision\",\r\n            }}\r\n          >\r\n            {words.map((word, i) => {\r\n              const w = wordInk(now, i, {\r\n                at: wordAt,\r\n                stagger: wordStagger,\r\n                dur: wordDuration,\r\n                coolDelay,\r\n                coolDur: coolDuration,\r\n                blur: wordBlur,\r\n                ...(i === words.length - 1\r\n                  ? { selectAt, selectDur: selectDuration }\r\n                  : {}),\r\n              });\r\n              if (w.opacity <= 0) return null;\r\n              return (\r\n                // biome-ignore lint/suspicious/noArrayIndexKey: words in a headline repeat, so the index is what makes each key unique\r\n                <Fragment key={`${word}-${i}`}>\r\n                  {i > 0 ? \" \" : null}\r\n                  <span\r\n                    style={{\r\n                      display: \"inline-block\",\r\n                      color: mixOklch(accent, t.foreground, w.cool),\r\n                      opacity: w.opacity,\r\n                      filter: w.blur > 0.02 ? `blur(${w.blur}px)` : undefined,\r\n                    }}\r\n                  >\r\n                    {word}\r\n                  </span>\r\n                </Fragment>\r\n              );\r\n            })}\r\n          </div>\r\n        </div>\r\n      </div>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}