{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "typo-fix",
  "title": "Typo Fix",
  "description": "A misspelled word is caught and corrected in place inside a short line.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/typo-fix/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Onest\";\nimport { useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface TypoFixProps {\n  wrong?: string;\n  correct?: string;\n  before?: string;\n  after?: string;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Onest 500 advance widths (1/1000 em) for ASCII 32–126, plus its kern pairs.\nconst ONEST_500 = [\n  274, 283, 377, 662, 658, 831, 690, 230, 323, 323, 430, 564, 274, 460, 263,\n  489, 663, 372, 564, 604, 634, 616, 623, 507, 623, 620, 263, 274, 564, 564,\n  564, 519, 987, 684, 662, 707, 723, 614, 601, 724, 732, 272, 567, 641, 581,\n  870, 749, 765, 638, 765, 668, 655, 578, 730, 694, 990, 618, 637, 604, 332,\n  489, 332, 564, 457, 576, 559, 611, 556, 611, 574, 372, 611, 596, 230, 259,\n  533, 230, 830, 596, 596, 611, 611, 380, 510, 369, 579, 543, 851, 530, 603,\n  515, 394, 268, 394, 564,\n];\nconst KERN_PAIRS = [\n  \"AA-15 AC18 AG18 AJ-20 AO18 AQ18 AS18 AT50 AU10 AV50 AW30 AY60 Av30\",\n  \"Aw20 BV10 BW10 BX10 BY10 CA19 CJ-10 CV25 CX24 CY20 DA19 DC-15 DG-15\",\n  \"DJ-10 DO-15 DQ-15 DS-15 DT10 DV25 DX30 DY20 Dd-10 FA50 FJ30 FT-20\",\n  \"Fa30 Fc25 Fd25 Fe25 Fg25 Fo25 Fq25 Fs25 GA19 GJ-10 GT10 GV25 GX24\",\n  \"GY20 JA10 KT-10 Ka10 Kv30 LA-20 LJ-30 LT40 LV50 LW40 LX-10 LY80 La-10\",\n  \"Lc-10 Ld-10 Le-10 Lg-10 Lj-20 Lo-10 Lq-10 Ls-10 Lz-20 OA19 OJ-10 OV26\",\n  \"OX24 OY26 PA52 PC-10 PG-10 PJ50 PQ-10 PS-10 PX25 PY15 Pa20 Pc10 Pd10\",\n  \"Pe10 Pg10 Pj10 Po10 Pq10 Ps10 QA19 QJ-10 QT10 QV25 QX24 QY20 RY20\",\n  \"Ra10 Rc10 Rd10 Re10 Rg10 Ro10 Rq10 Rs10 SA19 SJ-10 ST10 SV25 SX30\",\n  \"SY20 TA54 TG10 TJ80 TQ10 TS10 TT-40 Ta60 Tc50 Td50 Te50 Tg50 Tm20\",\n  \"Tn20 To50 Tp20 Tq50 Tr20 Ts50 Tu20 UA10 Ua20 Uc10 Ud10 Ue10 Ug10 Uo10\",\n  \"Uq10 Us10 VA50 VC25 VG25 VJ80 VO26 VQ25 VS25 Va50 Vc50 Vd50 Ve50 Vg50\",\n  \"Vm20 Vn20 Vo50 Vp20 Vq50 Vr20 Vs50 Vu20 Vz20 WA30 WJ30 Wa35 Wd25 XC24\",\n  \"XG24 XO24 XQ24 XS30 YA60 YC20 YG20 YJ90 YO26 YQ20 YS20 Ya70 Yc70 Yd70\",\n  \"Ye70 Yf20 Yg70 Ym30 Yn30 Yo70 Yp30 Yq70 Yr30 Ys70 Yu30 Yv30 Yw20 Yx20\",\n  \"Yz30 bT50 bV50 bY70 bc-10 bd-10 bf10 bx10 cT50 cV50 cY70 cc-10 cf10\",\n  \"cx10 eT50 eV50 eY70 ec-10 ef10 ex10 fc10 fd10 fe10 fg10 fo10 fq10\",\n  \"fs10 jj-20 oT50 oV50 oY70 of10 ox10 pT50 pV50 pY70 pc-10 pf20 pt20\",\n  \"px10 qj-20 rc10 rd10 re10 rg10 ro10 rq10 rs10 rt-30 sT50 sV50 sY70\",\n  \"sc-10 sf10 st10 sx15 vA30 xc10 xd10 xe10 xg10 xo10 xq10 xs10\",\n].join(\" \");\nconst KERN = new Map(\n  KERN_PAIRS.split(\" \").map((p) => [p.slice(0, 2), -Number(p.slice(2)) / 1000]),\n);\n\nconst TRACK = -0.03;\nconst ASC = 0.97;\nconst LINE = 1.275;\nconst CAP = 0.708;\nconst SPACE = 0.274 + TRACK;\n\nconst ENTER_STAGGER = 3;\nconst ENTER_LEN = 18;\nconst SQUIGGLE_AT = 20;\nconst SQUIGGLE_LEN = 14;\nconst SWAP_AT = 44;\nconst SWAP_STAGGER = 1;\nconst TRAVEL = 20;\nconst RETRACT_LEN = 10;\nconst RULE_DELAY = 1;\nconst RULE_LEN = 10;\nconst HOLD = 36;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n// Ground: gradients.sh \"grain\" (dark) and \"smear\" (light), a warm light\n// from the top left, kept low so the type and the red squiggle stay crisp.\nconst THEMES = {\n  dark: {\n    bg: \"#070505\",\n    fg: \"#F5F1EC\",\n    dim: \"#6A605B\",\n    error: \"#FF5A4F\",\n    grain: 0.08,\n    glow: \"rgba(255, 216, 180, 0.36)\",\n    wash: [\n      \"rgba(224, 112, 59, 0.85)\",\n      \"rgba(138, 44, 29, 0.62)\",\n      \"rgba(43, 16, 21, 0.55)\",\n    ],\n  },\n  light: {\n    bg: \"#F5F2EC\",\n    fg: \"#141212\",\n    dim: \"#ABA39C\",\n    error: \"#D9302C\",\n    grain: 0.05,\n    glow: \"rgba(255, 236, 200, 0.6)\",\n    wash: [\n      \"rgba(247, 178, 59, 0.62)\",\n      \"rgba(242, 85, 44, 0.36)\",\n      \"rgba(232, 137, 181, 0.2)\",\n    ],\n  },\n} as const;\n\nfunction advance(ch: string) {\n  const code = ch.charCodeAt(0);\n  return (code >= 32 && code < 127 ? ONEST_500[code - 32] : 620) / 1000;\n}\n\nfunction textEm(s: string) {\n  let w = 0;\n  for (let i = 0; i < s.length; i++) {\n    if (i > 0) w += KERN.get(s[i - 1] + s[i]) ?? 0;\n    w += advance(s[i]) + TRACK;\n  }\n  return w;\n}\n\nfunction layoutWord(chars: string[]) {\n  const xs: number[] = [];\n  let x = 0;\n  chars.forEach((ch, i) => {\n    if (i > 0) x += KERN.get(chars[i - 1] + ch) ?? 0;\n    xs.push(x);\n    x += advance(ch) + TRACK;\n  });\n  return { xs, total: x };\n}\n\nfunction mapLetters(a: string[], b: string[]) {\n  const used = new Array<boolean>(a.length).fill(false);\n  const src = new Array<number>(b.length).fill(-1);\n  b.forEach((ch, j) => {\n    if (a[j] === ch) {\n      src[j] = j;\n      used[j] = true;\n    }\n  });\n  const pick = (j: number, same: (x: string, y: string) => boolean) => {\n    let best = -1;\n    let bestD = Number.POSITIVE_INFINITY;\n    a.forEach((ch, i) => {\n      if (used[i] || !same(ch, b[j])) return;\n      const d = Math.abs(i - j);\n      if (d < bestD) {\n        bestD = d;\n        best = i;\n      }\n    });\n    if (best >= 0) used[best] = true;\n    return best;\n  };\n  b.forEach((_, j) => {\n    if (src[j] < 0) src[j] = pick(j, (x, y) => x === y);\n  });\n  b.forEach((_, j) => {\n    if (src[j] < 0)\n      src[j] = pick(j, (x, y) => x.toLowerCase() === y.toLowerCase());\n  });\n  const orphans = a.map((_, i) => i).filter((i) => !used[i]);\n  return { src, orphans };\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={23}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\ninterface Glyph {\n  key: string;\n  ch: string;\n  x0: number;\n  x1: number;\n  start: number;\n  lift: number;\n  over: boolean;\n  fadeIn: boolean;\n  fadeOut: boolean;\n}\n\nexport function typoFixDuration(wrong = \"Lanuch\") {\n  return (\n    SWAP_AT +\n    Math.max(0, wrong.length - 1) * SWAP_STAGGER +\n    TRAVEL +\n    RULE_DELAY +\n    RULE_LEN +\n    HOLD\n  );\n}\n\nexport function TypoFix({\n  wrong = \"Lanuch\",\n  correct = \"Launch\",\n  before = \"\",\n  after = \"day\",\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: TypoFixProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const c = THEMES[theme];\n  const clipId = `tf${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n\n  const a = useMemo(() => Array.from(wrong), [wrong]);\n  const b = useMemo(() => Array.from(correct), [correct]);\n  const la = useMemo(() => layoutWord(a), [a]);\n  const lb = useMemo(() => layoutWord(b), [b]);\n  const beforeW = before ? textEm(before) + SPACE : 0;\n  const afterW = after ? SPACE + textEm(after) : 0;\n\n  const glyphs = useMemo<Glyph[]>(() => {\n    const { src, orphans } = mapLetters(a, b);\n    let order = 0;\n    const list: Glyph[] = b.map((ch, j) => {\n      const i = src[j];\n      const x1 = lb.xs[j];\n      if (i < 0)\n        return {\n          key: `in-${j}`,\n          ch,\n          x0: x1,\n          x1,\n          start: SWAP_AT,\n          lift: 0,\n          over: true,\n          fadeIn: true,\n          fadeOut: false,\n        };\n      const x0 = la.xs[i];\n      const dx = x1 - x0;\n      const moving = Math.abs(dx) > 0.02;\n      return {\n        key: `m-${i}`,\n        ch,\n        x0,\n        x1,\n        start: SWAP_AT + (moving ? order++ * SWAP_STAGGER : 0),\n        lift: moving ? Math.min(0.62, Math.max(0.44, Math.abs(dx) * 0.85)) : 0,\n        over: dx > 0,\n        fadeIn: false,\n        fadeOut: false,\n      };\n    });\n    for (const i of orphans)\n      list.push({\n        key: `o-${i}`,\n        ch: a[i],\n        x0: la.xs[i],\n        x1: la.xs[i],\n        start: SWAP_AT,\n        lift: 0,\n        over: false,\n        fadeIn: false,\n        fadeOut: true,\n      });\n    return list.sort((m, n) => Number(m.over) - Number(n.over));\n  }, [a, b, la, lb]);\n\n  const swapEnd = Math.max(...glyphs.map((g) => g.start)) + TRAVEL;\n  const fix = EASE_IO(interpolate(t, [SWAP_AT, swapEnd], [0, 1], CLAMP));\n  const wordW = la.total + (lb.total - la.total) * fix;\n  const maxTotal = beforeW + Math.max(la.total, lb.total) - TRACK + afterW;\n  const F = Math.min(H * 0.27, (W * 0.8) / Math.max(maxTotal, 0.1));\n  const total = beforeW + wordW - TRACK + afterW;\n  const left = -total / 2;\n  const wordLeft = left + beforeW;\n  const baseline = H / 2 + (CAP * F) / 2;\n\n  const enter = (k: number) =>\n    EASE_OUT(\n      interpolate(\n        t,\n        [k * ENTER_STAGGER, k * ENTER_STAGGER + ENTER_LEN],\n        [0, 1],\n        CLAMP,\n      ),\n    );\n  const wordEnter = enter(before ? 1 : 0);\n\n  const ulY = baseline + 0.19 * F;\n  const ulX0 = W / 2 + wordLeft * F;\n  const ulX1 = W / 2 + (wordLeft + la.total - TRACK) * F;\n  const amp = 0.036 * F;\n  const wave = 0.13 * F;\n  const pts: string[] = [];\n  for (let x = ulX0; x <= ulX1 + 0.5; x += 2) {\n    const y = ulY + amp * Math.sin(((x - ulX0) / wave) * Math.PI * 2);\n    pts.push(`${x.toFixed(1)},${y.toFixed(1)}`);\n  }\n  const draw = EASE_OUT(\n    interpolate(t, [SQUIGGLE_AT, SQUIGGLE_AT + SQUIGGLE_LEN], [0, 1], CLAMP),\n  );\n  const retractAt = swapEnd - RETRACT_LEN + 2;\n  const retract = EASE_IO(\n    interpolate(t, [retractAt, retractAt + RETRACT_LEN], [0, 1], CLAMP),\n  );\n  const clipL = ulX0 - amp + (ulX1 - ulX0 + 2 * amp) * retract;\n  const clipR = ulX0 - amp + (ulX1 - ulX0 + 2 * amp) * draw;\n\n  const ruleAt = swapEnd + RULE_DELAY;\n  const rule = EASE_OUT(\n    interpolate(t, [ruleAt, ruleAt + RULE_LEN], [0, 1], CLAMP),\n  );\n  const ruleT = Math.max(3, 0.045 * F);\n  const ruleX0 = W / 2 + wordLeft * F;\n  const ruleW = (lb.total - TRACK) * F;\n  const settle = spring({\n    frame: t - swapEnd,\n    fps,\n    config: { damping: 14, stiffness: 220, mass: 0.6 },\n  });\n  const tick = t >= swapEnd ? Math.sin(Math.PI * Math.min(1, settle)) : 0;\n\n  const textStyle = {\n    position: \"absolute\" as const,\n    top: `${-ASC}em`,\n    letterSpacing: `${TRACK}em`,\n    whiteSpace: \"pre\" as const,\n    color: c.fg,\n  };\n\n  // The light drifts a few percent across the shot.\n  const drift = interpolate(t, [0, swapEnd + RULE_LEN + HOLD], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const gx = 10 + 5 * drift;\n  const gy = 8 + 3 * drift;\n  const ground = [\n    `radial-gradient(48% 42% at ${gx.toFixed(2)}% ${gy.toFixed(2)}%, ${c.glow} 0%, transparent 60%)`,\n    `linear-gradient(${(150 - 4 * drift).toFixed(2)}deg, ${c.wash[0]} 0%, ${c.wash[1]} 20%, ${c.wash[2]} 40%, transparent 62%)`,\n  ].join(\", \");\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <div style={{ position: \"absolute\", inset: 0, background: ground }} />\n      <svg\n        width={W}\n        height={H}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <clipPath id={clipId}>\n            <rect\n              x={clipL}\n              y={ulY - amp * 3}\n              width={Math.max(0, clipR - clipL)}\n              height={amp * 6}\n            />\n          </clipPath>\n        </defs>\n        {draw > 0 && retract < 1 ? (\n          <polyline\n            points={pts.join(\" \")}\n            fill=\"none\"\n            stroke={c.error}\n            strokeWidth={Math.max(2, 0.03 * F)}\n            strokeLinecap=\"round\"\n            strokeLinejoin=\"round\"\n            clipPath={`url(#${clipId})`}\n          />\n        ) : null}\n      </svg>\n      {rule > 0 ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: ruleX0,\n            top: ulY - ruleT / 2,\n            width: ruleW * rule,\n            height: ruleT,\n            borderRadius: ruleT / 2,\n            background: accent,\n          }}\n        />\n      ) : null}\n      <div\n        style={{\n          position: \"absolute\",\n          left: W / 2,\n          top: baseline,\n          fontFamily: sans,\n          fontWeight: 500,\n          fontSize: F,\n          lineHeight: LINE,\n          fontKerning: \"none\",\n        }}\n      >\n        {before ? (\n          <div\n            style={{\n              ...textStyle,\n              left: `${left}em`,\n              fontKerning: \"normal\",\n              opacity: enter(0),\n              transform: `translateY(${(1 - enter(0)) * 0.2}em)`,\n            }}\n          >\n            {before}\n          </div>\n        ) : null}\n        <div\n          style={{\n            position: \"absolute\",\n            left: `${wordLeft}em`,\n            top: 0,\n            opacity: wordEnter,\n            transform: `translateY(${(1 - wordEnter) * 0.2 - tick * 0.035}em)`,\n          }}\n        >\n          {glyphs.map((g) => {\n            const p = EASE_IO(\n              interpolate(t, [g.start, g.start + TRAVEL], [0, 1], CLAMP),\n            );\n            const arc = Math.sin(Math.PI * p);\n            const x = g.x0 + (g.x1 - g.x0) * p;\n            const y = g.over ? -g.lift * arc : g.lift * 0.85 * arc;\n            const scale = g.lift\n              ? g.over\n                ? 1 + 0.08 * arc\n                : 1 - 0.08 * arc\n              : 1;\n            let opacity = 1;\n            if (g.fadeIn) opacity = interpolate(p, [0.4, 1], [0, 1], CLAMP);\n            if (g.fadeOut) opacity = interpolate(p, [0, 0.6], [1, 0], CLAMP);\n            const color =\n              g.lift && !g.over\n                ? interpolateColors(arc, [0, 1], [c.fg, c.dim])\n                : c.fg;\n            return (\n              <div\n                key={g.key}\n                style={{\n                  ...textStyle,\n                  left: 0,\n                  color,\n                  opacity,\n                  transform: `translate(${x}em, ${y}em) scale(${scale})`,\n                  transformOrigin: `${advance(g.ch) / 2}em ${ASC}em`,\n                }}\n              >\n                {g.ch}\n              </div>\n            );\n          })}\n        </div>\n        {after ? (\n          <div\n            style={{\n              ...textStyle,\n              left: `${wordLeft + wordW + SPACE}em`,\n              fontKerning: \"normal\",\n              opacity: enter(before ? 2 : 1),\n              transform: `translateY(${(1 - enter(before ? 2 : 1)) * 0.2}em)`,\n            }}\n          >\n            {after}\n          </div>\n        ) : null}\n      </div>\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/typo-fix.tsx"
    }
  ],
  "type": "registry:component"
}
