{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"word-wheel","type":"registry:component","title":"Word Wheel","description":"Rotating words text: a slot machine word wheel that spins and stops on one word. A column of words that spins like a reel and stops on one of them.","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/word-wheel.tsx","type":"registry:component","target":"components/kuchi/word-wheel.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/Jost\";\r\nimport { AbsoluteFill, useCurrentFrame, useVideoConfig } from \"remotion\";\r\nimport {\r\n  mixOklch,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * A column of words that spins like a reel and stops on one of them.\r\n *\r\n * A fixed lead-in — \"kuchi for\" — holds the left of the line, and the word\r\n * that finishes the sentence lives in a slot to its right. The slot is one row\r\n * of a taller column: the words above and below it are visible, smaller and\r\n * grey, fading out toward the top and bottom of the frame. The column rolls,\r\n * decelerates over about a second and three quarters, and comes to rest with\r\n * one word at full size and in ink.\r\n *\r\n * ## Everything here was measured off a recording, frame by frame\r\n *\r\n * The numbers below are not taste. They were recovered from a 2.1 second,\r\n * 638 × 354 screen capture by thresholding the ink in each of its 80 frames:\r\n *\r\n *   - the row pitch is exactly **34px**, and every row's baseline — including\r\n *     the oversized selected one — sits on that grid to the pixel. That is the\r\n *     tell that the scale pivots on the baseline, which is also the only pivot\r\n *     that does not make scaled type climb the pixel grid (see below).\r\n *   - the selected word is **1.665×** the others. Measured on the same word in\r\n *     both states, twice: \"Growth\" 97.15/58.28 = 1.6671, \"Educators\"\r\n *     128.55/77.35 = 1.6618.\r\n *   - the reel travels **9 rows**, and the whole curve is in `ROLL` — it is not\r\n *     a bezier and not a spring. The best cubic-bezier fit is 1.8px RMS and\r\n *     5.5px off at worst, the best spring 4.3px RMS. A fifth of a row is a\r\n *     visibly different frame, so the measurement ships instead of a curve.\r\n *\r\n * ## The selection lags the slot, and that is the whole feel of it\r\n *\r\n * A row becomes the selected one when it is nearest the slot — when its\r\n * baseline is within half a pitch. But it does not *arrive* at full size the\r\n * instant it crosses: the reference shows the same row at |d| = 17px reading\r\n * 0.30 on the way in and 0.685 on the way out. That hysteresis is a transition\r\n * lagging a class change, and it is why the fast part of the roll never looks\r\n * like a row of identical pops — each word is still growing when the next one\r\n * takes over. `SWAP` is that lag.\r\n *\r\n * ## The face is Jost, and that was measured too\r\n *\r\n * The reference is set in a licensed brand face, so the question was which\r\n * available one has its *proportions*. Fingerprinted on two space-free words at\r\n * matched cap height — \"Framer\" and \"Growth\", in cap units — the reference reads\r\n * 4.025 and 4.353. Jost reads 4.153 and 4.265; Outfit 4.491 and 4.529; Poppins\r\n * 5.201 and 5.180. Jost is within 3%, everything else is 10% or worse, and a\r\n * word 10% wide is a word that no longer ends where the sentence needs it to.\r\n *\r\n * ## Two fixed left edges\r\n *\r\n * The selected word's ink starts 30.5px left of everyone else's, so it butts up\r\n * against the lead-in and completes the sentence while the column itself stays\r\n * indented and out of the way. Both edges are constant across every word and\r\n * every frame — the reel is left-aligned twice over, not centred once.\r\n */\r\n\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"400\", \"500\", \"600\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The scene, in the reference's own 638 × 354 pixels\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport const REF_W = 638;\r\nexport const REF_H = 354;\r\n\r\n/** Row-to-row distance. Measured on eight consecutive baselines: 34.0 each. */\r\nexport const PITCH = 34;\r\n/** The slot's baseline — where the sentence sits. */\r\nexport const BASE_Y = 183.8;\r\n/** Left of the line's box. The reference's lead-in ink starts at 203.55. */\r\nexport const LINE_X = 201.98;\r\n/**\r\n * The space between the end of the lead-in and the selected word.\r\n *\r\n * Measured as a gap rather than as the word's x, and that distinction is the\r\n * whole reason this scene survives having its copy changed: the reference's word\r\n * sits at 345.29 only because \"Framer for\" happens to end at 336.56. Pin the\r\n * word to 345 and a shorter lead-in leaves a hole, a longer one runs the two\r\n * together — which is exactly what \"kuchi forLaunches\" did before this was a\r\n * gap.\r\n */\r\nexport const GAP = 8.01;\r\n/**\r\n * How far right the column sits from the word that completes the sentence.\r\n *\r\n * The reel is indented and the selected word is not: it steps left out of the\r\n * column to finish the line, and steps back when it loses the slot. Both edges\r\n * are constant across every word and every frame of the reference — the reel is\r\n * left-aligned twice over, not centred once.\r\n */\r\nexport const INDENT = 30.87;\r\n\r\n/** Type size of the selected word. Cap height measured at 22.32px. */\r\nexport const SIZE = 30.63;\r\n/** Box top → baseline, at `lineHeight: 1`. A face metric, measured, not guessed. */\r\nexport const ASC = 25.43;\r\n/** Unselected scale. The reciprocal of the measured 1.665. */\r\nexport const SMALL = 1 / 1.665;\r\n\r\n/** Rows travelled. The reel comes back round to the word it started on. */\r\nexport const SPIN = 9;\r\n\r\n/**\r\n * How long a row takes to grow into the slot, in seconds, and its curve.\r\n *\r\n * Measured from the frame a row crosses half a pitch: 0.90 at 38ms, and inside\r\n * the noise floor of a width measurement thereafter. A settle worth one frame\r\n * is a settle; this one is worth two.\r\n */\r\nexport const SWAP = 0.07;\r\n\r\n/**\r\n * The reel's own deceleration, as (seconds, share of the travel).\r\n *\r\n * Recovered from the recording by taking the phase of the 34px row grid in each\r\n * frame's vertical ink profile — which reads the offset to a hundredth of a\r\n * pixel off all eleven visible rows at once, rather than tracking one word and\r\n * inheriting its glyphs. Frames the capture sampled twice are dropped: they are\r\n * the recorder's duplicates, not the page's, and keeping them would freeze the\r\n * render for a frame in exactly the places the reference is moving fastest.\r\n */\r\nexport const ROLL: readonly (readonly [number, number])[] = [\r\n  [0.1583, 0.00033],\r\n  [0.175, 0.02175],\r\n  [0.2083, 0.05298],\r\n  [0.2417, 0.08995],\r\n  [0.275, 0.13203],\r\n  [0.3083, 0.18194],\r\n  [0.3417, 0.23034],\r\n  [0.3833, 0.28119],\r\n  [0.4167, 0.32889],\r\n  [0.45, 0.37627],\r\n  [0.4833, 0.42203],\r\n  [0.5167, 0.46322],\r\n  [0.5583, 0.50415],\r\n  [0.575, 0.54044],\r\n  [0.6083, 0.57445],\r\n  [0.6417, 0.6073],\r\n  [0.675, 0.63751],\r\n  [0.7083, 0.66516],\r\n  [0.7417, 0.69074],\r\n  [0.775, 0.71485],\r\n  [0.8083, 0.73897],\r\n  [0.8417, 0.75963],\r\n  [0.875, 0.77896],\r\n  [0.9083, 0.79751],\r\n  [0.9417, 0.81422],\r\n  [0.975, 0.83177],\r\n  [1.0167, 0.84767],\r\n  [1.05, 0.86162],\r\n  [1.0833, 0.87394],\r\n  [1.1167, 0.88608],\r\n  [1.1417, 0.89735],\r\n  [1.175, 0.9077],\r\n  [1.2083, 0.91734],\r\n  [1.2417, 0.92633],\r\n  [1.275, 0.93528],\r\n  [1.3083, 0.94438],\r\n  [1.35, 0.95087],\r\n  [1.3833, 0.95819],\r\n  [1.4417, 0.96961],\r\n  [1.475, 0.97442],\r\n  [1.5083, 0.97863],\r\n  [1.5417, 0.98239],\r\n  [1.575, 0.98571],\r\n  [1.6083, 0.98903],\r\n  [1.6417, 0.99161],\r\n  [1.6833, 0.99381],\r\n  [1.7167, 0.99569],\r\n  [1.75, 0.99732],\r\n  [1.7833, 0.99858],\r\n  [1.8083, 0.99926],\r\n  [1.8417, 1],\r\n];\r\n\r\n/**\r\n * How far a row is faded, by its distance from the slot as a share of the frame.\r\n *\r\n * Read as an envelope: the brightest any pixel of an unselected row ever got at\r\n * each height, across all 80 frames. Taking the maximum over the whole reel is\r\n * what makes it a property of the *position* rather than of whichever word\r\n * happened to be sitting there — a word with no ascenders is dimmer at the same\r\n * height, and one sample would have read that as a dip in the fade.\r\n *\r\n * It does not reach zero: the column is cut off by the frame, not by the fade.\r\n */\r\nexport const FADE: readonly (readonly [number, number])[] = [\r\n  [0, 1],\r\n  [0.085, 0.97],\r\n  [0.155, 0.89],\r\n  [0.22, 0.744],\r\n  [0.288, 0.518],\r\n  [0.356, 0.357],\r\n  [0.424, 0.25],\r\n  [0.492, 0.185],\r\n];\r\n\r\ntype Table = readonly (readonly [number, number])[];\r\n\r\n/**\r\n * Linear read of a rising table, in either direction.\r\n *\r\n * `at = 0` reads y from x — the reel's travel at a second. `at = 1` reads x from\r\n * y — the second the reel reaches a share of its travel, which is what tells a\r\n * row when it takes the slot. Both tables here are sorted and monotone in both\r\n * columns, so one walk serves both and there is no second function to keep in\r\n * step with the first.\r\n */\r\nexport function read(table: Table, v: number, at: 0 | 1 = 0): number {\r\n  const to = at === 0 ? 1 : 0;\r\n  const first = table[0];\r\n  const last = table[table.length - 1];\r\n  if (!first || !last) return 0;\r\n  if (v <= first[at]) return first[to];\r\n  if (v >= last[at]) return last[to];\r\n  for (let i = 1; i < table.length; i++) {\r\n    const hi = table[i];\r\n    const lo = table[i - 1];\r\n    if (hi && lo && v <= hi[at]) {\r\n      return lo[to] + ((hi[to] - lo[to]) * (v - lo[at])) / (hi[at] - lo[at]);\r\n    }\r\n  }\r\n  return last[to];\r\n}\r\n\r\n/**\r\n * The second the reel has travelled `p` of its distance.\r\n *\r\n * Outside the roll it answers with an infinity rather than an endpoint: a row\r\n * the reel never reaches must never take the slot, and a row it started past\r\n * must have held it from the first frame. Clamping instead would hand both of\r\n * those a real time and make the scene swap words it never touches.\r\n */\r\nfunction rollReaches(p: number): number {\r\n  const first = ROLL[0];\r\n  const last = ROLL[ROLL.length - 1];\r\n  if (!first || !last) return Number.POSITIVE_INFINITY;\r\n  if (p <= first[1]) return Number.NEGATIVE_INFINITY;\r\n  if (p > last[1]) return Number.POSITIVE_INFINITY;\r\n  return read(ROLL, p, 1);\r\n}\r\n\r\n/** The swap's curve: a moderate decelerate, clamped. */\r\nfunction swell(t: number): number {\r\n  if (t <= 0) return 0;\r\n  if (t >= SWAP) return 1;\r\n  const u = t / SWAP;\r\n  return 1 - (1 - u) ** 3;\r\n}\r\n\r\nexport interface WordWheelProps {\r\n  /** The part of the line that never changes. */\r\n  headline?: string;\r\n  /** The reel, in order. It cycles, so the column is never empty. */\r\n  words?: string;\r\n  /** Rows travelled. Left at the list's length the reel comes full circle. */\r\n  spin?: number;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  fontFamily?: string;\r\n}\r\n\r\nexport function WordWheel({\r\n  headline = \"kuchi for\",\r\n  words = \"Launches, Founders, Indie hackers, Agencies, Designers, Startups, Dev tools, Solo builders, Changelogs\",\r\n  spin,\r\n  theme,\r\n  mode = \"light\",\r\n  fontFamily = \"Default\",\r\n}: WordWheelProps) {\r\n  const frame = useCurrentFrame();\r\n  const { fps, width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily) ?? SANS;\r\n\r\n  const reel = words\r\n    .split(\",\")\r\n    .map((w) => w.trim())\r\n    .filter(Boolean);\r\n  const rows = reel.length || 1;\r\n  const travel = (spin ?? rows) * PITCH;\r\n\r\n  /**\r\n   * One unit of reference pixel, and the offset that centres the layout.\r\n   *\r\n   * The scene is laid out in the recording's own pixels and scaled by height, so\r\n   * a render at the reference's dimensions is the reference's dimensions and\r\n   * nothing is resampled in the middle of a comparison.\r\n   */\r\n  const u = height / REF_H;\r\n  const ox = (width - REF_W * u) / 2;\r\n\r\n  const now = frame / fps;\r\n  const s = read(ROLL, now) * travel;\r\n\r\n  const first = Math.ceil((s - BASE_Y - PITCH) / PITCH);\r\n  const last = Math.floor((s - BASE_Y + REF_H + PITCH) / PITCH);\r\n\r\n  const ink = t.foreground;\r\n  const dim = t.mutedForeground;\r\n\r\n  return (\r\n    <AbsoluteFill style={{ backgroundColor: t.background }}>\r\n      <div\r\n        style={{\r\n          position: \"absolute\",\r\n          left: ox,\r\n          top: 0,\r\n          width: REF_W * u,\r\n          height: REF_H * u,\r\n          fontFamily: face,\r\n          fontWeight: 500,\r\n          // Hinting re-snaps every stem as the scale slides, and the letterforms\r\n          // boil. This turns it off — the type reads a shade softer, which is the\r\n          // outline as it actually is.\r\n          textRendering: \"geometricPrecision\",\r\n          whiteSpace: \"nowrap\",\r\n        }}\r\n      >\r\n        <div\r\n          style={{\r\n            position: \"absolute\",\r\n            left: LINE_X * u,\r\n            top: (BASE_Y - ASC) * u,\r\n            fontSize: SIZE * u,\r\n            lineHeight: 1,\r\n            color: ink,\r\n          }}\r\n        >\r\n          {headline}\r\n          {/*\r\n            A zero-sized inline-block sits on the baseline at the end of the\r\n            lead-in's own advance, whatever that lead-in says. The reel hangs off\r\n            it, so the sentence stays a sentence when the copy changes — and the\r\n            anchor never needs measuring, because the browser has already done\r\n            the layout by the time it paints.\r\n          */}\r\n          <span\r\n            style={{ position: \"relative\", display: \"inline-block\", width: 0 }}\r\n          >\r\n            {Array.from({ length: last - first + 1 }, (_, n) => {\r\n              const i = first + n;\r\n              const y = BASE_Y + PITCH * i - s;\r\n              const d = y - BASE_Y;\r\n\r\n              // A row owns the slot while it is nearest to it, and grows into it\r\n              // over SWAP rather than on the frame it crosses.\r\n              const p =\r\n                swell(now - rollReaches((PITCH * (i - 0.5)) / travel)) -\r\n                swell(now - rollReaches((PITCH * (i + 0.5)) / travel));\r\n\r\n              const scale = SMALL + (1 - SMALL) * p;\r\n              return (\r\n                <div\r\n                  key={i}\r\n                  style={{\r\n                    position: \"absolute\",\r\n                    left: (GAP + INDENT) * u,\r\n                    top: (y - ASC - BASE_Y) * u,\r\n                    color: p > 0 ? mixOklch(dim, ink, p) : dim,\r\n                    opacity: read(FADE, Math.abs(d) / REF_H),\r\n                    // The baseline is the only pivot a browser will not round:\r\n                    // it quantises a glyph's origin to a whole device pixel\r\n                    // vertically, so a scale that moves the baseline makes the\r\n                    // word climb the grid in jumps. Pivot on it and there is\r\n                    // nothing to snap.\r\n                    transform: `translateX(${-INDENT * p * u}px) scale(${scale})`,\r\n                    transformOrigin: `0px ${ASC * u}px`,\r\n                  }}\r\n                >\r\n                  {reel[((i % rows) + rows) % rows]}\r\n                </div>\r\n              );\r\n            })}\r\n          </span>\r\n        </div>\r\n      </div>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}