{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"velocity-marquee-rail","type":"registry:component","title":"Velocity Marquee Rail","description":"A marquee that accelerates with scroll speed and flips direction when you scroll back.","dependencies":["framer-motion"],"registryDependencies":[],"files":[{"path":"components/viberdy/velocity-marquee-rail.tsx","content":"\"use client\";\n\nimport { useRef } from \"react\";\nimport {\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useScroll,\n  useSpring,\n  useTransform,\n  useVelocity,\n  wrap,\n} from \"framer-motion\";\n\nexport function VelocityMarqueeRail({\n  words,\n  baseSpeed = 2,\n  velocityBoost = 4,\n  reverse = true,\n}: {\n  words: string[];\n  baseSpeed?: number;\n  velocityBoost?: number;\n  /** Flip the rail's travel direction when the page scrolls up. */\n  reverse?: boolean;\n}) {\n  const { scrollY } = useScroll();\n  const scrollVelocity = useVelocity(scrollY);\n\n  // Raw scroll velocity is extremely spiky; the spring is what turns it into\n  // something usable as an animation input.\n  const smoothVelocity = useSpring(scrollVelocity, { damping: 50, stiffness: 400 });\n\n  // Map px/s into a small multiplier, CLAMPED — without the clamp a fast\n  // flick sends the rail off at an unreadable speed.\n  const velocityFactor = useTransform(smoothVelocity, [0, 1000], [0, velocityBoost], {\n    clamp: true,\n  });\n\n  const baseX = useMotionValue(0);\n  const direction = useRef(1);\n\n  useAnimationFrame((_, delta) => {\n    // delta-scaled, so speed is identical on 60Hz and 120Hz displays.\n    let moveBy = direction.current * baseSpeed * (delta / 1000) * 60;\n\n    // Scrolling up flips the rail. Advancing position manually in a frame\n    // callback (rather than running a CSS animation) is the only way to\n    // reverse mid-flight without a visible restart.\n    if (reverse) {\n      const v = velocityFactor.get();\n      if (v < 0) direction.current = -1;\n      else if (v > 0) direction.current = 1;\n    }\n\n    moveBy += direction.current * moveBy * velocityFactor.get();\n    baseX.set(baseX.get() + moveBy);\n  });\n\n  // The track repeats 4x, so one tile is 25%. Wrapping over [-25, 0] loops\n  // seamlessly and keeps the offset bounded instead of growing forever.\n  const x = useTransform(baseX, (v) => wrap(-25, 0, v / 12) + \"%\");\n\n  return (\n    <div className=\"overflow-hidden py-4\">\n      <motion.div style={{ x }} className=\"flex whitespace-nowrap will-change-transform\">\n        {Array.from({ length: 4 }).map((_, tile) => (\n          <span key={tile} className=\"flex shrink-0 items-center\" aria-hidden={tile > 0}>\n            {words.map((w) => (\n              <span key={w} className=\"flex items-center\">\n                <span className=\"px-3 text-3xl font-black tracking-tight\">{w}</span>\n                <span className=\"size-1.5 rounded-full bg-blue-500\" />\n              </span>\n            ))}\n          </span>\n        ))}\n      </motion.div>\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/velocity-marquee-rail.tsx"}],"meta":{"tier":"free","tags":["marquee","scroll","velocity","framer-motion"],"href":"https://viberdy.dev/library/velocity-marquee-rail","aiPrompt":"Create a React + Tailwind + Framer Motion component named VelocityMarqueeRail — a marquee whose speed and direction are driven by scroll.\n\nBehavior:\n- The rail drifts at a slow base speed when the page is still.\n- Scrolling accelerates it; scrolling the other way REVERSES its direction.\n- The loop is seamless.\n\nImplementation requirements (each of these is load-bearing):\n- Get velocity with useVelocity(scrollY) and smooth it with useSpring (damping 50, stiffness 400). Raw scroll velocity is far too spiky to use directly as an animation input.\n- Map velocity to a multiplier with useTransform(..., [0, 1000], [0, boost], { clamp: true }). WITHOUT the clamp, a fast flick sends the rail off at an unreadable speed.\n- Advance the position manually inside useAnimationFrame by mutating a motion value — do NOT use a CSS animation. Manual advancement is the only way to reverse direction mid-flight without a visible restart.\n- Scale movement by (delta / 1000) * 60 so the speed is identical on 60Hz and 120Hz displays.\n- Repeat the content 4 times and wrap the offset with Framer's wrap(-25, 0, v) helper — one tile is 25% of the track, so this loops seamlessly AND keeps the offset bounded instead of growing without limit.\n\nAccessibility:\n- The content is repeated 4x for the loop. Mark every duplicate tile aria-hidden so the text is announced once.\n\nProps: words (string[]), baseSpeed (number), velocityBoost (number).\n\nOutput a single self-contained \"use client\" component.","license":"https://viberdy.dev/license"}}