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