{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "word-ladder",
  "title": "Word Ladder",
  "description": "A word changes a letter or two per rung, climbing a ladder to the last word.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/word-ladder/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/SpaceGrotesk\";\nimport { type ReactNode, useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface WordLadderProps {\n  /** Rungs of the ladder, first to last. Neighbours should differ by a letter or two. */\n  words?: string[];\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Space Grotesk 500 advance widths (1/1000 em) for ASCII 32–126, plus its kern pairs.\nconst GROTESK_500 = [\n  255, 276, 470, 632, 609, 765, 598, 273, 389, 383, 530, 620, 273, 443, 276,\n  379, 645, 435, 598, 606, 630, 599, 615, 559, 611, 615, 276, 276, 620, 620,\n  620, 579, 1020, 632, 663, 643, 665, 559, 537, 661, 656, 254, 602, 618, 544,\n  874, 667, 673, 603, 673, 632, 609, 588, 669, 619, 887, 641, 617, 577, 347,\n  379, 347, 620, 620, 288, 577, 641, 592, 641, 584, 439, 640, 615, 256, 258,\n  551, 256, 857, 615, 615, 641, 641, 387, 525, 458, 614, 544, 792, 593, 614,\n  519, 449, 249, 449, 620,\n];\nconst KERN_PAIRS = [\n  \"AT70 AU12 AV49 AW22 AY74 Af23 At23 Av14 BT13 BV12 BX14 BY15 CT15\",\n  \"CY17 DB23 DD23 DT29 DV15 DX24 DY28 DZ14 FA44 GT29 GV18 GY33 JA35\",\n  \"JC16 JG16 JJ31 JO16 JQ16 Ja30 Jc32 Jd32 Je32 Jg32 Jm30 Jn30 Jo32\",\n  \"Jp30 Jq32 Jr30 Ju30 Jy30 KC30 KG30 KO30 KQ30 Kc17 Kd17 Ke17 Kf27\",\n  \"Kg17 Ko17 Kq17 Ks10 Kt27 Ku11 Kv28 Kw16 Ky11 LC22 LG22 LO22 LQ22\",\n  \"LT93 LU18 LV74 LW25 Lf46 Lt46 Lv33 Lw11 OB23 OD23 OT29 OV15 OX24\",\n  \"OY28 OZ14 PA55 PJ48 PX21 PZ19 Pa11 Pc14 Pd14 Pe14 Pg14 Po14 Pq14\",\n  \"Ps12 QB23 QD23 QT29 QV15 QX24 QY28 QZ14 RT11 RV12 RY16 ST26 SV11\",\n  \"SX10 SY21 TA70 TC29 TG29 TJ87 TO29 TQ29 TS15 Ta87 Tc97 Td97 Te97\",\n  \"Tf52 Tg97 Ti11 Tj11 Tm72 Tn72 To97 Tp72 Tq97 Tr72 Ts82 Tt52 Tu74\",\n  \"Tv69 Tw72 Tx80 Ty74 Tz76 UA12 VA49 VC15 VG15 VO15 VQ15 Va33 Vc33\",\n  \"Vd33 Ve33 Vg33 Vo33 Vq33 Vs30 Vu11 Vv15 Vw13 Vx26 Vy11 WA22 Wc10\",\n  \"Wd10 We10 Wg10 Wo10 Wq10 XC24 XG24 XO24 XQ24 Xc17 Xd17 Xe17 Xf20\",\n  \"Xg17 Xo17 Xq17 Xt20 Xu10 Xv20 Xw11 Xy10 YA74 YC28 YG28 YJ95 YO28\",\n  \"YQ28 YS19 Ya83 Yc87 Yd87 Ye87 Yf46 Yg87 Ym73 Yn73 Yo87 Yp73 Yq87\",\n  \"Yr73 Ys80 Yt46 Yu75 Yv63 Yw65 Yx71 Yy75 Yz72 ZC14 ZG14 ZO14 ZQ14\",\n  \"Zc11 Zd11 Ze11 Zf16 Zg11 Zo11 Zq11 Zt16 Zv11 ac12 ad12 ae12 af34\",\n  \"ag12 ao12 aq12 at34 au13 av27 ay13 bf18 bt18 bv17 bx32 bz13 cf18\",\n  \"ct18 cv17 cx32 cz13 ef18 et18 ev17 ex32 ez13 fc20 fd20 fe20 fg20\",\n  \"fi26 fj26 fl26 fo20 fq20 ft13 hf14 ht14 hv15 ka11 kc28 kd28 ke28\",\n  \"kg28 ko28 kq28 ks13 mf14 mt14 mv15 nf14 nt14 nv15 of18 ot18 ov17\",\n  \"ox32 oz13 pf18 pt18 pv17 px32 pz13 ra14 rc18 rd18 re18 rg18 ro18\",\n  \"rq18 rs11 sf11 st11 sv19 tc18 td18 te18 tf27 tg18 to18 tq18 va14\",\n  \"vc17 vd17 ve17 vg17 vo17 vq17 vs13 xa10 xc32 xd32 xe32 xg32 xo32\",\n  \"xq32 xs11 zc14 zd14 ze14 zg14 zo14 zq14\",\n].join(\" \");\nconst KERN = new Map(\n  KERN_PAIRS.split(\" \").map((p) => [p.slice(0, 2), -Number(p.slice(2)) / 1000]),\n);\nconst TRACK = -0.03;\nconst ASC = 0.984;\nconst LINE = 1.276;\nconst ASCENDER = 0.7;\n\n// Timing, in frames at speed 1.\nconst ENTER_STAGGER = 2;\nconst ENTER = 18;\nconst FIRST = 32;\nconst RUNG = 24;\nconst SUB = 3;\nconst DROP = 8;\nconst RISE_DELAY = 7;\nconst RISE = 16;\nconst GLIDE_DELAY = 3;\nconst GLIDE = 16;\nconst BAR_LEAD = 9;\nconst BAR_IN = 10;\nconst BAR_OUT = 7;\nconst SETTLE = 12;\nconst POSTER_GAP = 6;\nconst POSTER = 18;\n\nconst stepAt = (k: number) => FIRST + k * RUNG;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN = Easing.bezier(0.55, 0, 1, 0.45);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n// The ground under the floor line: light spilling down from the slot line the\n// outgoing letters sink through. gradients.sh \"beam\" (dark), \"pixel-glass\" (light).\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F3F2EF\",\n    dim: \"#5E5D5B\",\n    grain: 0.07,\n    beam: [\n      \"rgba(143, 180, 255, 0.46)\",\n      \"rgba(61, 91, 255, 0.46)\",\n      \"rgba(26, 22, 96, 0.5)\",\n    ],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    dim: \"#A9A8A4\",\n    grain: 0.045,\n    beam: [\n      \"rgba(61, 107, 255, 0.34)\",\n      \"rgba(122, 60, 255, 0.2)\",\n      \"rgba(255, 79, 184, 0.07)\",\n    ],\n  },\n} as const;\n\nfunction advance(ch: string) {\n  if (!ch) return 0;\n  const code = ch.charCodeAt(0);\n  return (code >= 32 && code < 127 ? GROTESK_500[code - 32] : 620) / 1000;\n}\n\n/** Glyph centres (em, relative to the word's centre) for every slot. */\nfunction layoutWord(chars: string[], slots: number) {\n  const left: number[] = [];\n  let x = 0;\n  chars.forEach((ch, i) => {\n    if (i > 0) x += KERN.get(chars[i - 1] + ch) ?? 0;\n    left.push(x);\n    x += advance(ch) + TRACK;\n  });\n  const total = Math.max(0, x - TRACK);\n  const cx: number[] = [];\n  for (let i = 0; i < slots; i++) {\n    cx.push(\n      i < chars.length\n        ? left[i] + advance(chars[i]) / 2 - total / 2\n        : total / 2,\n    );\n  }\n  return { cx, total };\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={31}\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 Swap {\n  step: number;\n  at: number;\n  from: string;\n  to: string;\n}\n\ninterface Mark {\n  in: number;\n  out: number;\n}\n\nexport function WordLadder({\n  words = [\"idea\", \"item\", \"stem\", \"step\", \"ship\"],\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: WordLadderProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n\n  const rungs = useMemo(\n    () => (words.length > 0 ? words : [\"\"]).map((w) => Array.from(w)),\n    [words],\n  );\n  const slots = Math.max(1, ...rungs.map((r) => r.length));\n  const layouts = useMemo(\n    () => rungs.map((r) => layoutWord(r, slots)),\n    [rungs, slots],\n  );\n  const steps = rungs.length - 1;\n\n  const plan = useMemo(() => {\n    const swaps: Swap[][] = Array.from({ length: slots }, () => []);\n    const changed: boolean[][] = [];\n    for (let k = 0; k < steps; k++) {\n      const a = rungs[k];\n      const b = rungs[k + 1];\n      const row: boolean[] = [];\n      let order = 0;\n      for (let i = 0; i < slots; i++) {\n        const from = a[i] ?? \"\";\n        const to = b[i] ?? \"\";\n        row.push(from !== to);\n        if (from === to) continue;\n        swaps[i].push({ step: k, at: stepAt(k) + order * SUB, from, to });\n        order++;\n      }\n      changed.push(row);\n    }\n    const lastSwap = Math.max(\n      stepAt(0),\n      ...swaps.flat().map((s) => s.at + RISE_DELAY + RISE),\n    );\n    const posterAt = steps > 0 ? lastSwap + POSTER_GAP : stepAt(0);\n    // Accent marks: one per slot and run of consecutive steps that change it.\n    const marks: Mark[][] = Array.from({ length: slots }, () => []);\n    for (let i = 0; i < slots; i++) {\n      for (let k = 0; k < steps; k++) {\n        if (!changed[k][i]) continue;\n        const prev = marks[i][marks[i].length - 1];\n        const end = k + 1 < steps ? stepAt(k + 1) - BAR_LEAD : posterAt;\n        if (prev && k > 0 && changed[k - 1][i]) prev.out = end;\n        else marks[i].push({ in: stepAt(k) - BAR_LEAD, out: end });\n      }\n    }\n    return { swaps, changed, posterAt, marks };\n  }, [rungs, slots, steps]);\n\n  const F = Math.min(\n    H * 0.42,\n    (W * 0.62) / Math.max(0.1, ...layouts.map((l) => l.total)),\n  );\n  const floorGap = 0.27 * F;\n  const barH = Math.max(3, F * 0.042);\n  const baseline = H / 2 + (ASCENDER * F - floorGap - barH) / 2;\n  const floorY = baseline + floorGap;\n  const dropD = floorGap + ASCENDER * F + F * 0.04;\n\n  const glide = (k: number) =>\n    interpolate(\n      t,\n      [stepAt(k) + GLIDE_DELAY, stepAt(k) + GLIDE_DELAY + GLIDE],\n      [0, 1],\n      { ...CLAMP, easing: EASE_IO },\n    );\n  const glides = Array.from({ length: steps }, (_, k) => glide(k));\n  const slotX = (i: number) => {\n    let x = layouts[0].cx[i];\n    glides.forEach((g, k) => {\n      x += (layouts[k + 1].cx[i] - layouts[k].cx[i]) * g;\n    });\n    return W / 2 + x * F;\n  };\n\n  const poster = interpolate(\n    t,\n    [plan.posterAt, plan.posterAt + POSTER],\n    [0, 1],\n    { ...CLAMP, easing: EASE_IO },\n  );\n  const isFinal = steps > 0;\n\n  const glyphs: ReactNode[] = [];\n  const bars: ReactNode[] = [];\n  const barSpan = (i: number, ch: string) => {\n    const half = Math.max(advance(ch) * 0.4, 0.11) * F;\n    const x = slotX(i);\n    return [x - half, x + half] as const;\n  };\n\n  for (let i = 0; i < slots; i++) {\n    const x = slotX(i);\n    const list = plan.swaps[i];\n    let current: Swap | undefined;\n    for (const s of list) if (s.at <= t) current = s;\n\n    const draw = (\n      key: string,\n      ch: string,\n      y: number,\n      color: string,\n      opacity = 1,\n    ) => {\n      if (!ch || opacity <= 0) return;\n      glyphs.push(\n        <span\n          key={key}\n          style={{\n            position: \"absolute\",\n            left: x - (advance(ch) * F) / 2,\n            top: baseline - ASC * F,\n            color,\n            opacity,\n            transform: `translateY(${y}px)`,\n          }}\n        >\n          {ch}\n        </span>,\n      );\n    };\n\n    if (!current) {\n      const enter = interpolate(\n        t,\n        [i * ENTER_STAGGER, i * ENTER_STAGGER + ENTER],\n        [0, 1],\n        { ...CLAMP, easing: EASE_OUT },\n      );\n      draw(`s${i}`, rungs[0][i] ?? \"\", (1 - enter) * dropD, c.fg);\n    } else {\n      const drop = interpolate(t, [current.at, current.at + DROP], [0, 1], {\n        ...CLAMP,\n        easing: EASE_IN,\n      });\n      if (drop < 1)\n        draw(\n          `o${i}-${current.step}`,\n          current.from,\n          drop * dropD,\n          interpolateColors(drop, [0, 1], [c.fg, c.dim]),\n        );\n      const rise = interpolate(\n        t,\n        [current.at + RISE_DELAY, current.at + RISE_DELAY + RISE],\n        [0, 1],\n        { ...CLAMP, easing: EASE_OUT },\n      );\n      const settleAt =\n        current.step + 1 < steps\n          ? stepAt(current.step + 1) - BAR_LEAD\n          : plan.posterAt;\n      const settle = interpolate(t, [settleAt, settleAt + SETTLE], [0, 1], {\n        ...CLAMP,\n        easing: EASE_IO,\n      });\n      draw(\n        `i${i}-${current.step}`,\n        current.to,\n        (1 - rise) * dropD,\n        interpolateColors(settle, [0, 1], [accent, c.fg]),\n      );\n    }\n\n    // Accent mark under the slot that is about to change.\n    const glyphNow = current\n      ? t < current.at + RISE_DELAY\n        ? current.from\n        : current.to\n      : (rungs[0][i] ?? \"\");\n    for (const m of plan.marks[i]) {\n      const grow = interpolate(t, [m.in, m.in + BAR_IN], [0, 1], {\n        ...CLAMP,\n        easing: EASE_OUT,\n      });\n      const isLast = isFinal && m.out === plan.posterAt;\n      const shrink = isLast\n        ? interpolate(t, [m.out + POSTER, m.out + POSTER + 1], [0, 1], CLAMP)\n        : interpolate(t, [m.out, m.out + BAR_OUT], [0, 1], {\n            ...CLAMP,\n            easing: EASE_IN,\n          });\n      const v = grow * (1 - shrink);\n      if (v <= 0) continue;\n      const [l, r] = barSpan(i, glyphNow);\n      bars.push(\n        <div\n          key={`b${i}-${m.in}`}\n          style={{\n            position: \"absolute\",\n            left: l,\n            top: floorY,\n            width: r - l,\n            height: barH,\n            background: accent,\n            opacity: isLast ? 1 : Math.min(1, v * 1.4),\n            transform: `scaleX(${isLast ? 0.35 + 0.65 * grow : 0.35 + 0.65 * v})`,\n          }}\n        />,\n      );\n    }\n  }\n\n  // Poster: the last marks run out into one rule under the final word.\n  if (isFinal && t >= plan.posterAt) {\n    const last = rungs[steps];\n    const lastChanged = plan.changed[steps - 1]\n      .map((on, i) => (on && last[i] ? i : -1))\n      .filter((i) => i >= 0);\n    if (last.length > 0 && lastChanged.length > 0) {\n      // Grow out of the first mark; the others are covered as it passes.\n      const from = barSpan(lastChanged[0], last[lastChanged[0]]);\n      const to = [\n        barSpan(0, last[0])[0],\n        barSpan(last.length - 1, last[last.length - 1])[1],\n      ];\n      const l = from[0] + (to[0] - from[0]) * poster;\n      const r = from[1] + (to[1] - from[1]) * poster;\n      bars.push(\n        <div\n          key=\"rule\"\n          style={{\n            position: \"absolute\",\n            left: l,\n            top: floorY,\n            width: r - l,\n            height: barH,\n            background: accent,\n          }}\n        />,\n      );\n    }\n  }\n\n  // Ground: light spilling down from the slot line, drifting a touch wider.\n  const drift = interpolate(t, [0, plan.posterAt + POSTER], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const groundTop = floorY + barH;\n  const spread = 58 + 8 * drift;\n  const ground = `radial-gradient(${spread.toFixed(2)}% 100% at 50% 0%, ${c.beam[0]} 0%, ${c.beam[1]} 30%, ${c.beam[2]} 62%, transparent 100%)`;\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          top: groundTop,\n          width: W,\n          height: H - groundTop,\n          background: ground,\n        }}\n      />\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          top: 0,\n          width: W,\n          height: floorY,\n          overflow: \"hidden\",\n          fontFamily: sans,\n          fontWeight: 500,\n          fontSize: F,\n          lineHeight: LINE,\n          fontKerning: \"none\",\n          whiteSpace: \"pre\",\n        }}\n      >\n        {glyphs}\n      </div>\n      {bars}\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/word-ladder.tsx"
    }
  ],
  "type": "registry:component"
}
