{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-rewrite",
  "title": "Text Rewrite",
  "description": "Text rewrite animation, a typewriter line that deletes and retypes its ending. A line that writes itself a word at a time, comes forward and gets selected — then its opening is swept away by a clip that cuts letters in half as it passes, and a new ending is written on while the line slides to its new centre. The mark rides the sweeping edge throughout.",
  "dependencies": [
    "remotion",
    "@remotion/google-fonts"
  ],
  "registryDependencies": [
    "https://snapcn.dev/r/snap-cn-ui.json"
  ],
  "files": [
    {
      "path": "registry/snap-cn/text-rewrite/index.tsx",
      "content": "// Text Rewrite · snapcn — https://snapcn.dev/docs/text/text-rewrite\n\"use client\";\n\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Inter\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  getRemotionEnvironment,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport {\n  mixOklch,\n  resolveFont,\n  type SnapCnTheme,\n  useSnapCnTheme,\n  withAlpha,\n} from \"@/lib/snap-cn-ui\";\n\n// Loaded through @remotion/google-fonts, never a CSS variable — a Remotion\n// bundle has none of the app's CSS, so a `var(--font-…)` gets you the right face\n// in the Player and a fallback in the mp4 (design-system rule 4).\nconst { fontFamily: SANS } = loadSans(\"normal\", {\n  weights: [\"400\", \"500\", \"600\"],\n  subsets: [\"latin\"],\n});\n\n// --- The stage -------------------------------------------------------------\n//\n// The reference recording is 810×458 and every number below was read off its\n// frames, so there is no second conversion to get wrong.\n\nconst REF_W = 810;\nconst REF_H = 458;\n\n// --- Measured proportions --------------------------------------------------\n\n/** The line is set tight — a hair of negative tracking, tighter word gaps. */\nconst TRACKING = -0.012;\nconst WORD_GAP = -0.05;\n\n/**\n * The selection box, in em of the type it sits behind: `0.954` tall, bottom\n * `0.083` below the baseline, reaching `0.11` past the type on an unclipped end.\n *\n * Measured at full size: the box is y 200…245 against a baseline at 241, and\n * runs x 174…577 against ink at 180…572.\n */\nconst SEL_HEIGHT = 0.954;\nconst SEL_BELOW = 0.083;\nconst SEL_PAD = 0.11;\n\n/**\n * The mark: `0.4em` clear of the last visible letter, its centre sitting `0.4em`\n * above the baseline — measured, 19.5px above a baseline at 241, at a type size\n * of 48.\n *\n * `markSize` is the *box*, not the ink. The reference's mark inks 36×40px of a\n * 0.83em square; ours fills about 70% of its own box, so 1.15em of box puts the\n * same amount of ink on the line.\n */\nconst MARK_GAP = 0.4;\nconst MARK_SIZE = 1.15;\nconst MARK_RISE = 0.4;\n\n/**\n * The sheen, as `[position, × the base alpha]`.\n *\n * Measured on eight frames spanning three different box widths and two phases —\n * 402px selected, 272px after the rewrite, 193px mid-erase. It lands in the same\n * place every time: **deepest at 0.36, palest at 0.575, a 3.2× swing**. That is\n * a gradient painted on the box, not on the page, which is why it appears to\n * travel as the box is dragged and then eaten.\n */\nconst SHEEN: readonly (readonly [number, number])[] = [\n  [0, 0.93],\n  [0.1, 1.19],\n  [0.19, 1.24],\n  [0.3, 1.49],\n  [0.37, 1.56],\n  [0.44, 1.03],\n  [0.51, 0.57],\n  [0.59, 0.49],\n  [0.69, 0.59],\n  [0.78, 0.75],\n  [0.89, 1.03],\n  [1, 1.16],\n];\n\n/**\n * The curve the erase and the rewrite both run on.\n *\n * Fitted on the recording's own timestamps — it is a 60fps capture with eight\n * dropped frames, so a frame index is not a clock. The erase's clip edge over\n * 29 frames gives **cubic-bezier(0.419, −0.050, 0.184, 1.044)** at rms 0.0086 of\n * the travel; the rewrite, fitted independently on the line's *centre* rather\n * than on any edge, gives **cubic-bezier(0.427, 0.021, 0.193, 0.999)** at rms\n * 0.0059. Two different signals, two different halves of the gesture, the same\n * curve — so it is one ease, and this is it.\n *\n * It is an ease-in-out, and that is the whole character of the move: the edge\n * creeps for four frames, crosses the sentence in twelve, and settles for\n * twelve more. An ease-out would have made it look like a deletion. This looks\n * like something being read and then taken away.\n */\nconst SWEEP_EASE = Easing.bezier(0.42, 0, 0.19, 1);\n\n/**\n * The selection drag.\n *\n * Measured without touching the gradient at all: take nineteen fixed columns\n * across the line and find the frame the warmth arrives in each. The edge is\n * 28% across by 17ms, 54% by 33ms, 71% by 50ms, 91% by 100ms and 97% by 150ms.\n * That is an `easeOut` of degree **3.5 over 200ms** — a `quint` is far too fast\n * off the mark and misses the first two points by twenty points of travel.\n */\nconst DRAG_EASE = Easing.out(Easing.poly(3.5));\n\n/** A word's fade, and the settle of the line's width around it. */\nconst WORD_EASE = Easing.out(Easing.cubic);\n\n/**\n * The snapcn mark, the same outline `public/logo.svg` draws, in a `0 0 100 100`\n * box. `markPath` replaces it with any path drawn in the same box; an empty\n * string leaves the line bare.\n */\nexport const MARK_PATH =\n  \"M15.757 15.459c-3.324 0.816 -6.07 2.966 -7.563 5.911 -1.194 2.388 -1.174 1.672 -1.174 24.66 0 19.982 0.02 21.077 0.378 22.132 0.955 2.926 2.946 4.498 6.588 5.215 1.99 0.398 2.528 0.657 3.702 1.732 1.055 0.975 1.473 2.169 1.473 4.219 0.02 2.408 0.836 3.901 2.647 4.856l1.035 0.537 19.505 0.06c17.574 0.06 19.624 0.02 20.739 -0.259 1.493 -0.418 2.647 -1.333 3.403 -2.766l0.537 -1.015 0.06 -6.269c0.04 -3.443 0.04 -6.807 0 -7.444l-0.06 -1.194 -0.617 0.995c-0.717 1.174 -2.01 2.289 -3.383 2.906l-0.975 0.458 -16.121 0.06c-11.763 0.04 -16.42 -0 -17.216 -0.159 -2.548 -0.557 -5.135 -2.408 -6.468 -4.657 -1.294 -2.189 -1.314 -2.548 -1.254 -16.44l0.06 -12.439 0.478 -1.154c0.876 -2.209 2.926 -4.18 5.374 -5.155l1.115 -0.458 16.519 -0.06c16.101 -0.04 16.539 -0.04 17.813 0.358 1.592 0.498 2.966 1.473 3.941 2.826l0.736 1.035 0.06 -6.648c0.06 -7.304 -0.06 -8.319 -1.115 -9.832 -0.597 -0.876 -1.95 -1.811 -3.025 -2.11 -0.438 -0.119 -9.096 -0.199 -23.386 -0.179 -18.37 0.02 -22.908 0.06 -23.804 0.279zM79.665 31.819c-6.508 3.901 -11.902 7.185 -11.981 7.304 -0.08 0.119 -0.139 5.055 -0.1 10.947l0.04 10.748 2.886 1.811c1.592 0.995 4.14 2.587 5.672 3.523 1.533 0.935 5.632 3.463 9.096 5.613 3.463 2.15 6.488 3.901 6.707 3.901 0.219 -0 0.537 -0.139 0.697 -0.318 0.279 -0.279 0.318 -2.806 0.318 -24.958 0 -15.544 -0.08 -24.839 -0.199 -25.157 -0.139 -0.398 -0.318 -0.517 -0.736 -0.517 -0.358 0.02 -4.617 2.448 -12.399 7.105z\";\n\n// --- The timeline, as pure functions ---------------------------------------\n\n/**\n * How many words have landed, and how far the newest one has opened the line.\n *\n * The reference does **not** reflow when a word lands. Measured across all four\n * arrivals, both ends of the line move outward by the same amount over the same\n * five frames — +18, +8, +4, +2, +1 on the right and the mirror of that on the\n * left — while the centre never leaves 404 of 810. So the line's *width* is\n * tweened around a fixed centre and the new word is revealed by it, rather than\n * being dropped into a flow that jumps.\n */\nexport function landed(\n  t: number,\n  n: number,\n  o: { at: number; stagger: number; dur: number },\n): { count: number; grow: number } {\n  if (t < o.at) return { count: 0, grow: 0 };\n  // +1e-6: a cue lands on an exact multiple of the stagger, and in doubles\n  // 0.217 + 3 × 0.189 divides back to 2.9999999, which drops a word.\n  const raw = Math.floor((t - o.at) / o.stagger + 1e-6) + 1;\n  const count = Math.min(n, raw);\n  const cue = o.at + (count - 1) * o.stagger;\n  const grow =\n    o.dur <= 0\n      ? 1\n      : interpolate(t, [cue, cue + o.dur], [0, 1], {\n          extrapolateLeft: \"clamp\",\n          extrapolateRight: \"clamp\",\n          easing: WORD_EASE,\n        });\n  return { count, grow };\n}\n\n/**\n * A word's ink: its opacity, and how far it has cooled out of the accent.\n *\n * Every word arrives in the accent, holds it for one beat — the same 189ms as\n * the stagger — and cools over the next, so exactly one word is ever coloured\n * and it walks the line ahead of the reader. The last word has no next word to\n * hand off to: on the reference it cools *while the selection is dragged over\n * it*, in half the time the drag takes, and is dark by the time the line is\n * selected.\n */\nexport function wordInk(\n  t: number,\n  i: number,\n  o: {\n    at: number;\n    stagger: number;\n    dur: number;\n    coolDelay: number;\n    coolDur: number;\n    dragAt?: number;\n    dragDur?: number;\n    last?: boolean;\n  },\n): { opacity: number; cool: number } {\n  const cue = o.at + i * o.stagger;\n  if (t < cue) return { opacity: 0, cool: 0 };\n  const opacity = interpolate(t, [cue, cue + o.dur], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: WORD_EASE,\n  });\n  const useDrag = o.last === true && o.dragAt !== undefined;\n  const from = useDrag ? (o.dragAt as number) : cue + o.coolDelay;\n  const span = useDrag ? (o.dragDur ?? o.coolDur) / 2 : o.coolDur;\n  const cool = interpolate(t, [from, from + Math.max(1e-4, span)], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n  return { opacity, cool };\n}\n\n/**\n * The selection being dragged across, as a fraction of the line.\n *\n * 28% across at 17ms, 54% at 33ms, 71% at 50ms — see `DRAG_EASE` for how that\n * was measured without the gradient getting in the way. It starts on the same\n * frame the line comes forward.\n */\nexport function dragIn(t: number, o: { at: number; dur: number }): number {\n  if (o.dur <= 0) return t >= o.at ? 1 : 0;\n  return interpolate(t, [o.at, o.at + o.dur], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: DRAG_EASE,\n  });\n}\n\n/** A sweep on the measured ease-in-out. Both halves of the rewrite use it. */\nexport function sweep(t: number, o: { at: number; dur: number }): number {\n  if (o.dur <= 0) return t >= o.at ? 1 : 0;\n  return interpolate(t, [o.at, o.at + o.dur], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: SWEEP_EASE,\n  });\n}\n\n/**\n * The deselect: the highlight's left edge running out to meet its right one.\n *\n * Nine frames, and **linear to within 6% of the travel** — 0.109, 0.233, 0.400,\n * 0.567, 0.691, 0.778, 0.851 against a straight line's 0.22, 0.33, 0.44, 0.55,\n * 0.67, 0.78, 0.89. No named curve does meaningfully better over nine frames,\n * and nothing about it reads as an ease. The selection is simply dropped.\n */\nexport function deselect(t: number, o: { at: number; dur: number }): number {\n  if (o.dur <= 0) return t >= o.at ? 1 : 0;\n  return interpolate(t, [o.at, o.at + o.dur], [0, 1], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n}\n\n/**\n * The forward move, as a scale.\n *\n * On the reference this is a **cut**: 188px of ink on one frame and 453px on the\n * next, with nothing in between anywhere in the recording. `zoomDuration={0}`\n * is that exactly.\n *\n * It is not the default. At 30fps a step in scale does not read as *coming\n * forward*, it reads as an edit — so the default is a short ramp on a moderate\n * decelerate, pivoted on the measured baseline because the rasteriser gives\n * glyph origins no vertical sub-pixel precision and any pivot that moves the\n * baseline makes the type climb the grid in whole-pixel jumps.\n */\nexport function zoomScale(\n  t: number,\n  o: { at: number; dur: number; to: number },\n): number {\n  if (o.dur <= 0) return t >= o.at ? o.to : 1;\n  return interpolate(t, [o.at, o.at + o.dur], [1, o.to], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n    easing: Easing.bezier(0.2, 0.6, 0.35, 1),\n  });\n}\n\n/** The sheen as a CSS gradient, in `color` at `alpha` times each stop. */\nexport function sheenGradient(\n  color: string,\n  alpha: number,\n  angle: number,\n  stops: readonly (readonly [number, number])[] = SHEEN,\n): string {\n  const list = stops\n    .map(\n      ([u, k]) =>\n        `${withAlpha(color, Math.min(1, alpha * k))} ${(u * 100).toFixed(1)}%`,\n    )\n    .join(\", \");\n  return `linear-gradient(${angle}deg, ${list})`;\n}\n\n// --- Props -----------------------------------------------------------------\n\nexport interface TextRewriteProps {\n  /** The line that writes itself, one word at a time. */\n  headline?: string;\n  /**\n   * How many words off the end of `headline` survive the erase. The rest are\n   * swept away from the left, and `append` is typed onto what is left.\n   */\n  keep?: number;\n  /** What gets written onto the surviving words. Empty leaves them alone. */\n  append?: string;\n\n  /** Seconds at which the mark appears, ahead of the first word. */\n  markAt?: number;\n  /** Seconds at which the first word lands. */\n  wordAt?: number;\n  /** Seconds between words — also how long a word holds the accent. */\n  wordStagger?: number;\n  /** How long a word takes to fade up and open the line. */\n  wordDuration?: number;\n  /** How long a word holds the accent before it starts cooling. */\n  coolDelay?: number;\n  /** How long the accent takes to become the foreground. */\n  coolDuration?: number;\n\n  /** Seconds at which the line comes forward. */\n  cutAt?: number;\n  /** How long the forward move takes. 0 is the reference's single-frame cut. */\n  zoomDuration?: number;\n  /** How far forward it goes. */\n  zoom?: number;\n\n  /** Seconds at which the selection starts being dragged across. */\n  dragAt?: number;\n  /** How long the drag takes. */\n  dragDuration?: number;\n  /** Seconds at which the erase starts eating the line from the left. */\n  eraseAt?: number;\n  /** How long the erase takes. */\n  eraseDuration?: number;\n  /** Seconds at which `append` starts being written on. */\n  rewriteAt?: number;\n  /** How long the rewrite takes. */\n  rewriteDuration?: number;\n  /** Seconds at which the selection is dropped. */\n  deselectAt?: number;\n  /** How long the deselect takes. */\n  deselectDuration?: number;\n\n  /** Type size before the forward move, in stage px. */\n  fontSize?: number;\n  /** Weight of the line. Inter ships 400/500/600 here. */\n  fontWeight?: number;\n  /** Where the line sits down the frame, as a fraction. */\n  centerY?: number;\n  /** Letter-spacing, in em. */\n  tracking?: number;\n  /** Word-spacing, in em. */\n  wordGap?: number;\n\n  /** Base strength of the selection, before the sheen multiplies it. */\n  selectionOpacity?: number;\n  /** Angle of the sheen. 90 is the reference's — straight across. */\n  selectionAngle?: number;\n  /** Override the sheen shape: `[position, × base alpha]` pairs. */\n  selectionSheen?: readonly (readonly [number, number])[];\n  /** How far the selection reaches past the type on an unclipped end, in em. */\n  selectionPad?: number;\n\n  /** The mark that trails the line, as a path in a `0 0 100 100` box. */\n  markPath?: string;\n  /** Its colour, if it should differ from the accent. */\n  markColor?: string;\n  /** Its height, in em. 0 leaves the line bare. */\n  markSize?: number;\n\n  /** The soft wash behind the line. */\n  glow?: boolean;\n  /** Colour of the wash, if it should differ from the accent. */\n  glowColor?: string;\n  /** Strength of the wash. */\n  glowOpacity?: number;\n\n  /** The colour a word arrives in, and the colour the sheen is painted from. */\n  accentColor?: string;\n  /** Token overrides. */\n  theme?: Partial<SnapCnTheme>;\n  /** Which token set to resolve against. */\n  mode?: \"light\" | \"dark\";\n  /**\n   * The face this scene paints its words in — a label from `fonts.ts`\n   * (\"Inter\", \"Space Grotesk\", \"Instrument Serif\") or a CSS family you have\n   * loaded yourself. Unset, the scene keeps the face it was designed around.\n   *\n   * Overrides `theme.fontFamily`, which is how a brand kit re-skins a whole\n   * timeline from one value.\n   */\n  fontFamily?: string;\n  /** Multiplies the frame clock. */\n  speed?: number;\n}\n\n/**\n * A line that writes itself, is selected, has its opening swept away and a new\n * ending written on — the gesture of a claim being corrected in front of you.\n *\n * Everything here came off the recording frame by frame. The three things worth\n * knowing before you change anything:\n *\n * 1. **The erase is a clip, not a deletion.** Letters are cut in half by a\n *    vertical edge as it passes — \"Or\" becomes \")r\" becomes \"r\" — and the words\n *    that survive never move. A word-by-word delete would have re-laid the line\n *    out on every step, and the recording plainly does not.\n * 2. **The rewrite is the same edge run the other way**, over a line that is\n *    sliding to its new centre at the same time. Fitted separately, the slide\n *    and the reveal land on one shared progress to within 0.001.\n * 3. **The mark rides the edge**, not the end of the line — it sits `0.4em`\n *    clear of the last *visible* letter through all of it, which is what keeps\n *    the gesture reading as one object rather than a line and a decoration.\n */\nexport function TextRewrite({\n  headline = \"Or just add snapcn\",\n  keep = 1,\n  append = \"registry\",\n\n  markAt = 0.117,\n  wordAt = 0.217,\n  wordStagger = 0.189,\n  wordDuration = 0.085,\n  coolDelay = 0.189,\n  coolDuration = 0.189,\n\n  cutAt = 1.033,\n  zoomDuration = 0,\n  zoom = 2.41,\n\n  dragAt = 1.033,\n  dragDuration = 0.2,\n  eraseAt = 1.45,\n  eraseDuration = 0.517,\n  rewriteAt = 2.0,\n  rewriteDuration = 0.533,\n  deselectAt = 2.85,\n  deselectDuration = 0.15,\n\n  fontSize = 20,\n  fontWeight = 500,\n  centerY = 0.4902,\n  tracking = TRACKING,\n  wordGap = WORD_GAP,\n\n  selectionOpacity = 0.21,\n  selectionAngle = 90,\n  selectionSheen = SHEEN,\n  selectionPad = SEL_PAD,\n\n  markPath = MARK_PATH,\n  markColor,\n  markSize = MARK_SIZE,\n\n  glow = true,\n  glowColor,\n  glowOpacity = 0.075,\n\n  accentColor,\n  theme,\n  mode,\n  fontFamily,\n  speed = 1,\n}: TextRewriteProps) {\n  const frame = useCurrentFrame();\n  const { width, height, fps } = useVideoConfig();\n  const t = useSnapCnTheme(theme, mode);\n  const face = resolveFont(fontFamily ?? t.fontFamily) ?? SANS;\n  const accent = accentColor ?? t.primary;\n  const wash = glowColor ?? accent;\n  const mark = markColor ?? accent;\n\n  const now = (frame * speed) / fps;\n  const stageScale = Math.min(width / REF_W, height / REF_H);\n  const words = headline.split(/\\s+/).filter(Boolean);\n  const kept = Math.max(0, Math.min(words.length, Math.round(keep)));\n  const cut = words.length - kept;\n  const lineHeight = Math.round(fontSize * 1.35);\n\n  // --- measurement -------------------------------------------------------\n  //\n  // Every position below is arithmetic on real widths, because the gesture\n  // needs geometry the flow cannot give it: where the surviving words sat in\n  // the *old* layout, how far a clip has to travel to reach them, and where the\n  // mark goes when the last visible letter is halfway through being eaten. A\n  // canvas ruler is no use — it knows nothing about CSS tracking or\n  // word-spacing — so the widths come from a hidden copy of the real line.\n  const probeRef = useRef<HTMLSpanElement>(null);\n  const baselineRef = useRef<HTMLSpanElement>(null);\n  const [handle] = useState(() => delayRender(\"text-rewrite: measure line\"));\n  const [m, setM] = useState<{\n    word: number[];\n    space: number;\n    append: number;\n    baseline: number;\n  } | null>(null);\n\n  useEffect(() => {\n    const probe = probeRef.current;\n    if (!probe) {\n      continueRender(handle);\n      return;\n    }\n    const parts = Array.from(probe.querySelectorAll<HTMLElement>(\"[data-w]\"));\n    const word = parts\n      .filter((p) => p.dataset.w === \"word\")\n      .map((p) => p.offsetWidth);\n    const space =\n      parts.find((p) => p.dataset.w === \"space\")?.offsetWidth ??\n      fontSize * 0.28;\n    const app = parts.find((p) => p.dataset.w === \"append\")?.offsetWidth ?? 0;\n    setM({\n      word,\n      space,\n      append: app,\n      baseline: baselineRef.current?.offsetTop ?? lineHeight * 0.8,\n    });\n  }, [handle, fontSize, lineHeight]);\n\n  useEffect(() => {\n    if (m) continueRender(handle);\n  }, [m, handle]);\n\n  const W = m?.word ?? words.map((w) => w.length * fontSize * 0.5);\n  const SP = m?.space ?? fontSize * 0.28;\n  const APP = m?.append ?? append.length * fontSize * 0.5;\n  const baseline = m?.baseline ?? lineHeight * 0.8;\n\n  /** Left edge of word `i` inside the line, and the line's width at `n` words. */\n  const offset = (i: number) => W.slice(0, i).reduce((a, b) => a + b + SP, 0);\n  const runWidth = (n: number) => (n <= 0 ? 0 : offset(n) - SP);\n\n  // --- timeline ----------------------------------------------------------\n  const pad = fontSize * selectionPad;\n  const gap = fontSize * MARK_GAP;\n  const markW = fontSize * markSize;\n  const tail = markPath ? gap + markW : 0;\n\n  const { count, grow } = landed(now, words.length, {\n    at: wordAt,\n    stagger: wordStagger,\n    dur: wordDuration,\n  });\n  const drag = dragIn(now, { at: dragAt, dur: dragDuration });\n  const erase = sweep(now, { at: eraseAt, dur: eraseDuration });\n  const write = sweep(now, { at: rewriteAt, dur: rewriteDuration });\n  const drop = deselect(now, { at: deselectAt, dur: deselectDuration });\n  const scale = zoomScale(now, { at: cutAt, dur: zoomDuration, to: zoom });\n\n  // Phase 1–2 layout. The line's *centring* width tweens around a fixed centre\n  // as each word opens it — measured, the ink's centre never leaves 404 of 810\n  // while its ends move ±34 over five frames. The word itself is drawn at full\n  // width from its first frame and fades: on the reference it lands whole and\n  // pale, overlapping the mark, and the mark slides clear over the next four\n  // frames. Nothing is ever clipped while the line is being written.\n  const opening = count > 0 ? (count > 1 ? SP : 0) + (W[count - 1] ?? 0) : 0;\n  const grown = runWidth(Math.max(0, count - 1)) + opening * grow;\n  const drawn = runWidth(count);\n  const full = runWidth(words.length);\n\n  // Layout A: the opening line, centred. Layout B: what it is rewritten into.\n  const aLeft = REF_W / 2 - (full + tail) / 2;\n  const keptLeft = aLeft + offset(cut);\n  const keptWidth = full - offset(cut);\n  const newWidth = keptWidth + (append ? SP + APP : 0);\n  const bLeft = REF_W / 2 - (newWidth + tail) / 2;\n\n  // Before the rewrite the line sits where it was written; after it, where its\n  // new content belongs. Fitted separately, the slide and the reveal land on\n  // one shared progress to within 0.001 of the travel.\n  const rewriting = write > 0;\n  const left = rewriting\n    ? keptLeft + (bLeft - keptLeft) * write\n    : REF_W / 2 - (grown + tail) / 2;\n\n  // The clip window. Its left edge is the erase, its right edge the rewrite —\n  // and nothing else touches it, which is why a letter gets cut in half by the\n  // edge instead of being deleted and re-laid-out.\n  const k0 = rewriting ? left : left + offset(cut) * erase;\n  const k1 = rewriting\n    ? left + keptWidth + (append ? SP + APP : 0) * write\n    : left + drawn;\n\n  // The selection is its own rectangle, not a lining inside the window: the\n  // drag sweeps it across a line that is entirely visible the whole time, and\n  // the deselect runs its left edge out to meet its right one over a line the\n  // clip has finished with.\n  const selFrom = erase > 0 || rewriting ? k0 : left - pad;\n  const selTo = rewriting ? k1 : left + drawn + pad;\n  const s1 = selFrom + (selTo - selFrom) * drag;\n  const s0 = selFrom + (s1 - selFrom) * drop;\n  const selShown = drag > 0 && drop < 1;\n\n  // The mark rides the end of what is *visible*, not the end of the line.\n  const markX = rewriting ? k1 : left + grown;\n\n  // A cut has no in-between frame to judder on, so it pivots on the line's\n  // optical centre — which is what the reference does: its small line and its\n  // full-size line share a centre at y 224 of 458, not a baseline. A *ramp*\n  // does have in-between frames, and there the pivot has to be the measured\n  // baseline: the rasteriser gives glyph origins no vertical sub-pixel\n  // precision, so any pivot that moves the baseline makes the type climb the\n  // pixel grid in whole-pixel jumps.\n  const pivot = zoomDuration > 0 ? `${baseline}px` : \"50%\";\n\n  const isRendering = getRemotionEnvironment().isRendering;\n  const moving = now > cutAt && now < cutAt + zoomDuration;\n  const willChange =\n    !isRendering && moving ? (\"transform\" as const) : undefined;\n\n  const boxTop = centerY * REF_H - lineHeight / 2;\n  const textStyle = {\n    fontFamily: face,\n    fontSize,\n    fontWeight,\n    lineHeight: `${lineHeight}px`,\n    letterSpacing: `${tracking}em`,\n    wordSpacing: `${wordGap}em`,\n    whiteSpace: \"pre\" as const,\n    // Hinting bends each glyph so its stems land on whole pixels, so as the size\n    // slides every stem re-snaps and the letterforms boil. This draws the\n    // outline as it actually is.\n    textRendering: \"geometricPrecision\" as const,\n  };\n\n  return (\n    <AbsoluteFill style={{ background: t.background }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: \"50%\",\n          top: \"50%\",\n          width: REF_W,\n          height: REF_H,\n          transform: `translate(-50%, -50%) scale(${stageScale})`,\n          overflow: \"hidden\",\n        }}\n      >\n        {glow ? (\n          <div\n            style={{\n              position: \"absolute\",\n              inset: 0,\n              background: `radial-gradient(46% 34% at 50% ${centerY * 100}%, ${withAlpha(wash, glowOpacity)} 0%, ${withAlpha(wash, 0)} 100%)`,\n            }}\n          />\n        ) : null}\n\n        {/* The ruler. Hidden, laid out once, read for the widths the geometry\n            above is built from — and for the baseline, which is never guessed\n            from a line-height ratio. */}\n        <span\n          ref={probeRef}\n          aria-hidden\n          style={{\n            ...textStyle,\n            position: \"absolute\",\n            left: 0,\n            top: 0,\n            visibility: \"hidden\",\n            pointerEvents: \"none\",\n          }}\n        >\n          {words.map((word, i) => (\n            <span data-w=\"word\" key={`${word}-${i}`}>\n              {word}\n            </span>\n          ))}\n          <span data-w=\"space\"> </span>\n          <span data-w=\"append\">{append}</span>\n          <span\n            ref={baselineRef}\n            style={{ display: \"inline-block\", width: 0, height: 0 }}\n          />\n        </span>\n\n        {/* The line, its selection and its mark in one group, so the forward\n            move carries all three. The scale is pivoted on the measured\n            baseline: the rasteriser gives glyph origins no vertical sub-pixel\n            precision, so any pivot that moves the baseline makes the type climb\n            the pixel grid in whole-pixel jumps. */}\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            right: 0,\n            top: boxTop,\n            height: lineHeight,\n            transform: `scale(${scale})`,\n            transformOrigin: `50% ${pivot}`,\n            willChange,\n          }}\n        >\n          {/* The selection. Its own rectangle, outside the window, because it\n              is painted over a line the window is not yet touching. */}\n          {selShown ? (\n            <div\n              style={{\n                position: \"absolute\",\n                left: s0,\n                top: baseline + fontSize * SEL_BELOW - fontSize * SEL_HEIGHT,\n                width: Math.max(0, s1 - s0),\n                height: fontSize * SEL_HEIGHT,\n                background: sheenGradient(\n                  accent,\n                  selectionOpacity,\n                  selectionAngle,\n                  selectionSheen,\n                ),\n              }}\n            />\n          ) : null}\n\n          {/* The window. `overflow: hidden` is the erase and the rewrite both —\n              the text inside never moves relative to the line, so a letter is\n              cut in half by the edge rather than removed. */}\n          <div\n            style={{\n              position: \"absolute\",\n              left: k0,\n              top: 0,\n              width: Math.max(0, k1 - k0),\n              height: lineHeight,\n              overflow: \"hidden\",\n            }}\n          >\n            <div\n              style={{\n                ...textStyle,\n                position: \"absolute\",\n                left: left - k0,\n                top: 0,\n                width: \"max-content\",\n              }}\n            >\n              {(rewriting\n                ? [...words.slice(cut), ...(append ? [append] : [])]\n                : words.slice(0, count)\n              ).map((word, i) => {\n                const idx = rewriting ? cut + i : i;\n                const ink = wordInk(now, idx, {\n                  at: wordAt,\n                  stagger: wordStagger,\n                  dur: wordDuration,\n                  coolDelay,\n                  coolDur: coolDuration,\n                  dragAt,\n                  dragDur: dragDuration,\n                  last: idx === words.length - 1,\n                });\n                return (\n                  <span\n                    // biome-ignore lint/suspicious/noArrayIndexKey: words repeat, so the index is what makes each key unique\n                    key={`${word}-${i}`}\n                    style={{\n                      color: rewriting\n                        ? t.foreground\n                        : mixOklch(accent, t.foreground, ink.cool),\n                      opacity: rewriting ? 1 : ink.opacity,\n                    }}\n                  >\n                    {i > 0 ? \" \" : null}\n                    {word}\n                  </span>\n                );\n              })}\n            </div>\n          </div>\n\n          {/* The mark rides the window's right edge, not the end of the line. */}\n          {markPath && now >= markAt ? (\n            <svg\n              viewBox=\"0 0 100 100\"\n              width={markW}\n              height={markW}\n              aria-hidden\n              style={{\n                position: \"absolute\",\n                left: markX + gap,\n                top: baseline - fontSize * MARK_RISE - markW / 2,\n                overflow: \"visible\",\n              }}\n            >\n              <path d={markPath} fill={mark} />\n            </svg>\n          ) : null}\n        </div>\n      </div>\n    </AbsoluteFill>\n  );\n}\n\nexport default TextRewrite;\n",
      "type": "registry:component",
      "target": "components/snap-cn/text-rewrite.tsx"
    }
  ],
  "docs": "Docs and props: https://snapcn.dev/docs/text/text-rewrite?ref=cli — pass mode=\"dark\" if you are rendering onto a dark frame — these default to shadcn's light palette and a bare Remotion render is black. — 82 Pro components too — charts, launch scenes, device shots: https://snapcn.dev/docs/pricing?ref=cli-docs",
  "type": "registry:component"
}
