{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-rail",
  "title": "Card Rail",
  "description": "Card carousel animation: cards flicked sideways on a tilted 3D plane. A rail of cards flicked sideways across a tilted plane. The cards do not crawl past on a loop — they are flicked: the rail leaves at speed, decelerates for well over a second and comes to rest about a card further along, the way a carousel behaves under a thumb rather than under a timer. The plane is not flat to the camera either. Measured on a recording's card edges, the horizontal scale grows 0.000825 per pixel of height about the frame's own centre line, so the foot of a card is a fifth wider than its head while horizontals stay horizontal and the type stays upright — which is why a row of plain rectangles reads as a surface receding into the frame rather than as a filmstrip.",
  "dependencies": [
    "remotion",
    "@remotion/google-fonts"
  ],
  "registryDependencies": [
    "https://snapcn.dev/r/snap-cn-ui.json"
  ],
  "files": [
    {
      "path": "registry/snap-cn/card-rail/index.tsx",
      "content": "// Card Rail · snapcn — https://snapcn.dev/docs/scenes/card-rail\n\"use client\";\n\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Figtree\";\nimport type { CSSProperties } from \"react\";\nimport { forwardRef, useCallback, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  getRemotionEnvironment,\n  staticFile,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport {\n  Item,\n  mixOklch,\n  parseColor,\n  resolveFont,\n  type SnapCnTheme,\n  useSnapCnTheme,\n} from \"@/lib/snap-cn-ui\";\n\n/**\n * A rail of cards flicked sideways across a tilted plane.\n *\n * The cards do not crawl past on a loop. They are *flicked* — the rail leaves at\n * speed, decelerates for well over a second, and comes to rest one card further\n * along, the way a carousel behaves under a thumb rather than under a timer. A\n * title holds the top of the frame and does not move with them.\n *\n * ## The plane is tilted, and that is the whole look\n *\n * The rail is not flat to the camera. Measured on the card edges of a recording,\n * the horizontal scale grows **0.000825 per pixel of height** about the frame's\n * own centre line — the bottom of a card is 22% wider than its top — while\n * horizontals stay horizontal and the type stays upright. That is a plane\n * rotated about a horizontal axis under perspective, and it is why a row of\n * plain rectangles reads as a surface receding into the frame.\n *\n * The three numbers that describe it are `DEPTH`, `TILT` and `HORIZON`, and they\n * are deliberately separate from the card metrics: change the card size and the\n * plane does not move.\n *\n * ## The flick is measured, not eased\n *\n * `FLICK` is the curve off the recording — it peaks at 29px a frame three frames\n * in and is still moving at 2px a frame a second later. No standard ease has that\n * tail; a cubic-out arrives four times too early and a spring overshoots\n * something that never overshoots.\n */\n\nconst { fontFamily: SANS } = loadSans(\"normal\", {\n  weights: [\"400\", \"500\", \"600\", \"700\"],\n  subsets: [\"latin\"],\n});\n\n/* ─────────────────────────────────────────────────────────────────────────\n   The stage, in the recording's own 714 × 396 pixels\n   ───────────────────────────────────────────────────────────────────────── */\n\nexport const REF_W = 714;\nexport const REF_H = 396;\n\n/** Title: cap height and baseline, measured on its own ink. */\nexport const HEAD_CAP = 20.81;\nexport const HEAD_BASE = 64.45;\n\n/** The card, in layout pixels — before the plane tilts it. */\nexport const CARD_W = 259.2;\nexport const CARD_TOP = 79.8;\nexport const GAP = 54.2;\nexport const RADIUS = 10;\n/**\n * The card runs to the foot of the frame — the rail is a surface passing\n * through the shot, not a row of objects sitting in it.\n *\n * Its own number rather than `REF_H - CARD_TOP`, because `CARD_TOP` is a\n * *layout* height on a tilted plane and the two are not the same measurement:\n * the plane pushes the card 54px down the frame on its way to the camera.\n */\nexport const CARD_H = 323.3;\n/** The picture's share of the card's width, as an aspect. */\nexport const SHOT_ASPECT = 16 / 9;\n\n/**\n * The plane.\n *\n * `HORIZON` is the height at which the plane is exactly life-size — above it the\n * rail is smaller and further away, below it nearer and larger. It is measured,\n * not chosen: solving the card's width at two heights puts it at 300.6, which is\n * most of the way down the visible card rather than at the frame's middle.\n */\nexport const DEPTH = 740;\nexport const TILT = 30;\nexport const HORIZON = 300;\n\n/**\n * The backdrop's axis, in degrees.\n *\n * Fitted, not guessed: a plane's corners have to satisfy TL + BR = TR + BL for a\n * linear gradient, and the recording's do to within five parts in 235 — so it is\n * linear, and the angle that puts its measured corners on one line is 138°.\n */\nexport const ANGLE = 138;\n\n/**\n * How far the rail travels, and the curve it travels on.\n *\n * One card pitch, so the rail comes to rest showing the next card where the last\n * one stood. The table is seconds → share of that distance, straight off the\n * recording: 29px on frame three, 2px a second later, and no analytic curve in\n * between that fits both ends.\n */\n/**\n * Not `CARD_W + GAP`, and the difference is the point.\n *\n * A rail that advanced by exactly one pitch would be an assumption; measured, the\n * recording's travels 333 where its pitch is 325. A flick is a flick — it ends\n * where the momentum ran out, not on a snap — and eight pixels of overshoot is\n * the whole difference between a carousel and a surface someone pushed.\n */\nexport const TRAVEL = 323;\nexport const FLICK: readonly (readonly [number, number])[] = [\n  [0, 0],\n  [0.0333, 0.009],\n  [0.0667, 0.0338],\n  [0.1, 0.07508],\n  [0.1333, 0.13213],\n  [0.1667, 0.21021],\n  [0.2, 0.2973],\n  [0.225, 0.38138],\n  [0.2583, 0.45345],\n  [0.2917, 0.51351],\n  [0.325, 0.56757],\n  [0.3583, 0.60961],\n  [0.3917, 0.65165],\n  [0.4333, 0.68468],\n  [0.4583, 0.71171],\n  [0.4917, 0.73874],\n  [0.525, 0.76276],\n  [0.5583, 0.78378],\n  [0.5917, 0.8018],\n  [0.625, 0.81982],\n  [0.6583, 0.83483],\n  [0.6917, 0.84985],\n  [0.73, 0.86186],\n  [0.7633, 0.87387],\n  [0.7967, 0.88288],\n  [0.8383, 0.89189],\n  [0.8717, 0.9009],\n  [0.905, 0.90991],\n  [0.9383, 0.91592],\n  [0.9717, 0.92492],\n  [0.9967, 0.93093],\n  [1.03, 0.93694],\n  [2.2, 1],\n];\n\n/** Linear read of a rising table, clamped at both ends. */\nexport function read(\n  table: readonly (readonly [number, number])[],\n  x: number,\n): number {\n  const first = table[0];\n  const last = table[table.length - 1];\n  if (!first || !last) return 0;\n  if (x <= first[0]) return first[1];\n  if (x >= last[0]) return last[1];\n  for (let i = 1; i < table.length; i++) {\n    const hi = table[i];\n    const lo = table[i - 1];\n    if (hi && lo && x <= hi[0]) {\n      return lo[1] + ((hi[1] - lo[1]) * (x - lo[0])) / (hi[0] - lo[0]);\n    }\n  }\n  return last[1];\n}\n\n/** One card. Leave the words out and the picture is the whole card. */\nexport interface RailCard {\n  image?: string;\n  title?: string;\n  /** A line of small print under the title. */\n  note?: string;\n  tag?: string;\n}\n\nconst POSTERS = \"https://media.snapcn.dev/demos/posters/\";\n\nexport const DEFAULT_CARDS: readonly RailCard[] = (\n  [\n    [\"orbit-gallery\", \"Orbit Gallery\", 300],\n    [\"moodboard-reveal\", \"Moodboard Reveal\", 150],\n    [\"hero-launch\", \"Hero Launch\", 170],\n    [\"phone-frame\", \"Phone Frame\", 240],\n    [\"count-grid\", \"Count Grid\", 47],\n    [\"terminal-simulator\", \"Terminal Simulator\", 200],\n    [\"logo-flicker\", \"Logo Flicker\", 100],\n    [\"laptop-frame\", \"Laptop Frame\", 240],\n    [\"announce-title\", \"Announce Title\", 170],\n  ] as const\n).map(([slug, title, frames]) => ({\n  image: `${POSTERS}${slug}.webp`,\n  title,\n  note: `Scene · ${frames} frames`,\n  tag: `@snapcn/${slug}`,\n}));\n\nexport interface CardRailProps {\n  /**\n   * The cards, in order. The rail repeats them if it runs out.\n   *\n   * Also accepts one string, for the customizer and for quick edits: cards\n   * split by `|`, and each card's picture, title, small print and tag split by\n   * `>` — `\"https://… > Inbox > 4 screens > @acme/inbox | https://…\"`. A card\n   * that is only a URL is only a picture. Not commas or `;`: a data: URL has\n   * both.\n   */\n  cards?: readonly RailCard[] | string;\n  /** The line that holds the top of the frame. */\n  heading?: string;\n  /** Frame the first flick starts on. Negative starts the scene already moving. */\n  from?: number;\n  /** How many flicks. Each one carries the rail about another card along. */\n  flicks?: number;\n  /** Frames between one flick leaving and the next. */\n  every?: number;\n  /** Where the rail sits before it moves, in layout pixels. */\n  offset?: number;\n  /**\n   * The backdrop: two colour stops split by `|`, or one picture.\n   *\n   * A picture because a brand backdrop is often not a gradient at all — the\n   * recording this was measured from has corners that satisfy a linear fit and a\n   * middle that is 40 levels darker than one, which is a mesh or a painted plate\n   * and not something two stops can be talked into.\n   */\n  backdrop?: string;\n  theme?: Partial<SnapCnTheme>;\n  mode?: \"light\" | \"dark\";\n  fontFamily?: string;\n}\n\nexport function CardRail({\n  cards = DEFAULT_CARDS,\n  heading = \"Browse scenes\",\n  from = 0,\n  flicks = 3,\n  every = 30,\n  offset = 0,\n  backdrop = \"\",\n  theme,\n  mode = \"light\",\n  fontFamily = \"Default\",\n}: CardRailProps) {\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 u = height / REF_H;\n  const ox = (width - REF_W * u) / 2;\n\n  const deck = toCards(cards);\n  // No cards is a rail of blank ones, not a modulo by zero.\n  const count = Math.max(1, deck.length);\n  const stops = split(backdrop);\n  const only = stops.length === 1 ? (stops[0] ?? \"\") : \"\";\n  const plate = only.startsWith(\"data:\") || only.startsWith(\"/\") ? only : \"\";\n\n  /**\n   * Flicks add up.\n   *\n   * Each one is the same measured curve started `every` frames after the last,\n   * and the rail's position is their sum — so a flick begun while the one before\n   * it is still creeping carries that creep with it, which is what repeated\n   * swipes actually do. `read` clamps at both ends, so a flick that has not\n   * started contributes nothing and one that has finished contributes all of it.\n   */\n  let travelled = 0;\n  for (let k = 0; k < Math.max(1, Math.round(flicks)); k++) {\n    travelled += TRAVEL * read(FLICK, (frame - from - k * every) / fps);\n  }\n  const pitch = CARD_W + GAP;\n\n  // Enough cards to cover the frame at its widest, plus one leaving and one\n  // arriving. The rail repeats the list rather than running out.\n  const span = Math.ceil(REF_W / pitch) + 3;\n  // The rail has a beginning. Cards repeat to the right for as long as the flick\n  // needs them, but nothing is drawn before the first one — a loop that wraps\n  // round puts a card in the empty half of the frame the scene opens on.\n  const first = Math.max(0, Math.floor((travelled - offset) / pitch));\n  // The rail can show one card twice. Studio outlines the copy nearest the\n  // middle of the frame; the other is only a picture of it.\n  const nearest = new Map<number, number>();\n  for (let n = 0; n < span; n++) {\n    const i = first + n;\n    const k = ((i % count) + count) % count;\n    const d = Math.abs(i * pitch - travelled + offset - (REF_W - CARD_W) / 2);\n    const held = nearest.get(k);\n    const dHeld =\n      held === undefined\n        ? Number.POSITIVE_INFINITY\n        : Math.abs(held * pitch - travelled + offset - (REF_W - CARD_W) / 2);\n    if (d < dHeld) nearest.set(k, i);\n  }\n\n  // Both stops are mixed toward *blues*, never toward the page. The page is a\n  // near-neutral, its hue in oklch is undefined, and interpolating the accent\n  // through it comes out somewhere else entirely — measured once already, a blue\n  // accent over a warm off-white mixed to a pale green.\n  const from0 = stops[0] ?? mixOklch(t.primary, \"#0b1f3d\", 0.55);\n  const to0 = stops[1] ?? mixOklch(t.primary, \"#dceaff\", 0.78);\n  // A theme with a transparent page asks for no page: no backdrop, so the rail\n  // sits on whatever is under it, and a heading in ink rather than mixed off it.\n  const bare = parseColor(t.background).alpha === 0;\n\n  return (\n    <AbsoluteFill\n      style={\n        bare\n          ? undefined\n          : plate\n            ? { backgroundColor: t.background }\n            : { background: `linear-gradient(${ANGLE}deg, ${from0}, ${to0})` }\n      }\n    >\n      {plate && !bare && (\n        <Plate\n          src={plate}\n          style={{ position: \"absolute\", inset: 0, objectFit: \"cover\" }}\n        />\n      )}\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          textRendering: \"geometricPrecision\",\n          overflow: \"hidden\",\n        }}\n      >\n        {heading && (\n          <div\n            style={{\n              position: \"absolute\",\n              left: 0,\n              right: 0,\n              top: (HEAD_BASE - HEAD_CAP * 1.32) * u,\n              textAlign: \"center\",\n              fontSize: HEAD_CAP * 1.38 * u,\n              lineHeight: 1,\n              fontWeight: 500,\n              color: bare ? t.foreground : mixOklch(to0, t.background, 0.62),\n            }}\n          >\n            {heading}\n          </div>\n        )}\n        <div\n          style={{\n            position: \"absolute\",\n            inset: 0,\n            // The plane. `HORIZON` is where it is life-size, so the tilt pivots\n            // about a line inside the visible band rather than about the top of\n            // a box nobody can see.\n            perspective: DEPTH * u,\n            perspectiveOrigin: `50% ${HORIZON * u}px`,\n          }}\n        >\n          <div\n            style={{\n              position: \"absolute\",\n              inset: 0,\n              transform: `rotateX(${TILT}deg)`,\n              transformOrigin: `50% ${HORIZON * u}px`,\n              transformStyle: \"preserve-3d\",\n            }}\n          >\n            {Array.from({ length: span }, (_, n) => {\n              const i = first + n;\n              const x = i * pitch - travelled + offset;\n              const k = ((i % count) + count) % count;\n              const card = deck[k] ?? {};\n              return (\n                <Item key={i} index={k} primary={nearest.get(k) === i}>\n                  <Card\n                    x={x * u}\n                    src={card.image ?? \"\"}\n                    title={card.title ?? \"\"}\n                    note={card.note ?? \"\"}\n                    tag={card.tag ?? \"\"}\n                    t={t}\n                    u={u}\n                  />\n                </Item>\n              );\n            })}\n          </div>\n        </div>\n      </div>\n    </AbsoluteFill>\n  );\n}\n\nconst split = (s: string) =>\n  s\n    .split(\"|\")\n    .map((v) => v.trim())\n    .filter(Boolean);\n\n/** The string form of `cards`: see `CardRailProps.cards`. */\nexport function toCards(\n  input: readonly RailCard[] | string,\n): readonly RailCard[] {\n  if (typeof input !== \"string\") return input;\n  return input\n    .split(\"|\")\n    .filter((c) => c.trim())\n    .map((c) => {\n      const [image = \"\", title = \"\", note = \"\", tag = \"\"] = c\n        .split(\">\")\n        .map((v) => v.trim());\n      return { image, title, note, tag };\n    });\n}\n\n/**\n * One card: a picture, and under it a title and a line of small print. Forwards\n * its `ref` and takes a `style` on top of its own so Remotion Studio can\n * outline it and nudge it (see `Item`) — forwardRef, not a `ref` prop, which\n * React 18 would drop.\n */\nconst Card = forwardRef<\n  HTMLDivElement,\n  {\n    x: number;\n    src: string;\n    title: string;\n    note: string;\n    tag: string;\n    t: SnapCnTheme;\n    u: number;\n    style?: CSSProperties;\n  }\n>(function Card({ x, src, title, note, tag, t, u, style }, ref) {\n  const bodied = Boolean(title || note || tag);\n  const shot = CARD_W / SHOT_ASPECT;\n  return (\n    <div\n      ref={ref}\n      style={{\n        ...style,\n        position: \"absolute\",\n        left: x,\n        top: CARD_TOP * u,\n        width: CARD_W * u,\n        height: CARD_H * u,\n        borderRadius: RADIUS * u,\n        overflow: \"hidden\",\n        background: t.card,\n      }}\n    >\n      <Plate\n        src={src}\n        style={{\n          display: \"block\",\n          width: CARD_W * u,\n          // With no body the picture *is* the card. That is not a special case\n          // for its own sake — it is what lets a whole card be handed in as one\n          // image when the layout below is somebody else's.\n          height: (bodied ? shot : CARD_H) * u,\n          objectFit: \"cover\",\n        }}\n      />\n      {bodied && (\n        <div style={{ padding: `${13 * u}px ${15 * u}px` }}>\n          <div\n            style={{\n              fontSize: 15 * u,\n              lineHeight: 1.25,\n              fontWeight: 700,\n              color: t.foreground,\n            }}\n          >\n            {title}\n          </div>\n          <div\n            style={{\n              marginTop: 5 * u,\n              fontSize: 12.5 * u,\n              lineHeight: 1.3,\n              color: t.mutedForeground,\n            }}\n          >\n            {note}\n          </div>\n          {tag && (\n            <div\n              style={{\n                marginTop: 14 * u,\n                display: \"inline-block\",\n                padding: `${5 * u}px ${10 * u}px`,\n                borderRadius: 999,\n                fontSize: 11.5 * u,\n                lineHeight: 1.2,\n                fontWeight: 500,\n                color: t.mutedForeground,\n                border: `1px solid ${t.border}`,\n              }}\n            >\n              {tag}\n            </div>\n          )}\n        </div>\n      )}\n    </div>\n  );\n});\n\n/**\n * A root-relative asset is a `public/` file. Only the site's own Player serves\n * it at that path; Remotion Studio and a render know its URL through\n * `staticFile()` alone — so every environment but the Player rewrites it.\n */\nfunction resolveSrc(src: string): string {\n  const isLocal = src.startsWith(\"/\") && !src.startsWith(\"//\");\n  if (!isLocal || getRemotionEnvironment().isPlayer) return src;\n  // A value that already came out of staticFile() carries the static base\n  // (`/static-<hash>/…`); running it through again would prefix it twice.\n  const base = staticFile(\"_\").slice(0, -2);\n  if (base && src.startsWith(`${base}/`)) return src;\n  try {\n    return staticFile(src.replace(/^\\/+/, \"\"));\n  } catch {\n    return src;\n  }\n}\n\n/**\n * A picture that holds the render until it has actually loaded.\n *\n * Without it a frame can be captured before the image arrives and the card comes\n * out empty — invisible in the Player, where an image simply appears, and silent\n * in an mp4 until somebody watches it. Remotion's own `Img` is avoided for the\n * reason `hero-launch` documents: it awaits `decode()`, which the headless\n * compositor rejects for some progressive JPEGs and hangs the export.\n */\nfunction Plate({ src, style }: { src: string; style: CSSProperties }) {\n  // No picture is an empty surface, not an <img> that never loads and holds\n  // the render open.\n  return src ? <Picture src={src} style={style} /> : <div style={style} />;\n}\n\nfunction Picture({ src, style }: { src: string; style: CSSProperties }) {\n  const [handle] = useState(() => delayRender(`card-rail: ${src}`));\n  const release = useCallback(() => continueRender(handle), [handle]);\n  return (\n    // biome-ignore lint/performance/noImgElement: Remotion frame, not a Next route.\n    <img // eslint-disable-line @remotion/warn-native-media-tag -- onLoad releases the frame; <Img> hangs on some JPEGs\n      src={resolveSrc(src)}\n      alt=\"\"\n      // Tailwind's preflight sets `img { max-width: 100% }`, which collapses an\n      // image inside a shrink-to-fit box to zero pixels wide on the site while\n      // rendering perfectly in an mp4. Size it here and say so.\n      style={{ ...style, maxWidth: \"none\" }}\n      onLoad={release}\n      onError={release}\n    />\n  );\n}\n",
      "type": "registry:component",
      "target": "components/snap-cn/card-rail.tsx"
    }
  ],
  "docs": "Docs and props: https://snapcn.dev/docs/scenes/card-rail?ref=cli — images, titles, notes and tags are parallel lists split by `|` (not by comma: a data: URL has one of its own), one entry per card, and the rail repeats them rather than running out. Leave the text fields blank and the picture becomes the whole card, which is how a card designed elsewhere is handed in as one image. heading holds the top of the frame; from is the frame the flick starts on and may be negative to open mid-flight; offset is where the rail sits before it moves. backdrop takes two colour stops or one picture. 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"
}
