{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "rolling-text",
  "title": "Rolling Text",
  "description": "Per-character slot-machine reveal that rolls each letter into place once it scrolls into view, powered by Motion.",
  "dependencies": ["motion"],
  "registryDependencies": ["utils"],
  "files": [
    {
      "path": "registry/primitives/texts/rolling-text/index.tsx",
      "content": "\"use client\";\n\nimport { motion, useInView, useReducedMotion } from \"motion/react\";\nimport type { MotionProps } from \"motion/react\";\nimport { useMemo, useRef } from \"react\";\nimport type { ComponentType, ElementType, ReactNode, Ref } from \"react\";\n\nconst NBSP = \" \";\n\ntype MarginValue = `${number}${\"px\" | \"%\"}`;\ntype InViewMargin =\n  | MarginValue\n  | `${MarginValue} ${MarginValue}`\n  | `${MarginValue} ${MarginValue} ${MarginValue}`\n  | `${MarginValue} ${MarginValue} ${MarginValue} ${MarginValue}`;\n\nexport interface RollingTextProps {\n  /** Render as a different element/component instead of `span`. @default \"span\" */\n  as?: ElementType;\n  className?: string;\n  /** Direction letters roll in when they enter the viewport. @default \"up\" */\n  direction?: \"down\" | \"up\";\n  /** Total settle duration per letter, in seconds. @default 4 */\n  duration?: number;\n  /** Margin passed to the in-view observer (same format as CSS `margin`). @default \"-10%\" */\n  inViewMargin?: InViewMargin;\n  /** Only trigger the roll once, the first time it scrolls into view. @default true */\n  once?: boolean;\n  ref?: Ref<HTMLElement>;\n  /**\n   * Extra per-letter delay added per character of distance from the center,\n   * in seconds.\n   * @default 0.05\n   */\n  speed?: number;\n  /** Text to reveal. */\n  text: string;\n}\n\nexport function RollingText({\n  text,\n  speed = 0.05,\n  duration = 4,\n  direction = \"up\",\n  once = true,\n  inViewMargin = \"-10%\",\n  as: Component = \"span\",\n  className,\n  ref: forwardedRef,\n}: RollingTextProps) {\n  const containerRef = useRef<HTMLElement>(null);\n  const isInView = useInView(containerRef, { once, margin: inViewMargin });\n  const prefersReducedMotion = useReducedMotion();\n  const centerIndex = Math.floor(text.length / 2);\n\n  const MotionComponent = useMemo(\n    () =>\n      motion.create(Component as never) as ComponentType<\n        MotionProps & {\n          children?: ReactNode;\n          className?: string;\n          ref?: Ref<HTMLElement>;\n        }\n      >,\n    [Component]\n  );\n\n  const mergedRef = (node: HTMLElement | null) => {\n    containerRef.current = node;\n    if (typeof forwardedRef === \"function\") {\n      forwardedRef(node);\n    } else if (forwardedRef) {\n      forwardedRef.current = node;\n    }\n  };\n\n  if (prefersReducedMotion) {\n    return (\n      <Component className={className} ref={forwardedRef}>\n        {text}\n      </Component>\n    );\n  }\n\n  return (\n    <MotionComponent aria-label={text} className={className} ref={mergedRef}>\n      {text.split(\"\").map((letter, index) => {\n        const glyph = letter === \" \" ? NBSP : letter;\n        const distanceFromCenter = Math.abs(index - centerIndex);\n        const delay = distanceFromCenter * speed;\n        const rollDuration = 0.2 + distanceFromCenter * 0.15;\n        const numberOfRolls = Math.floor(duration / rollDuration);\n        const totalMovement = numberOfRolls * 1.2;\n        const restY = direction === \"down\" ? `-${totalMovement}em` : \"0em\";\n        const settledY = direction === \"down\" ? \"0em\" : `-${totalMovement}em`;\n\n        return (\n          <span\n            aria-hidden=\"true\"\n            className=\"relative inline-block overflow-hidden\"\n            // oxlint-disable-next-line react/no-array-index-key, react-doctor/no-array-index-as-key -- static per-render character list, order never changes\n            key={`${letter}-${index}`}\n            style={{ height: \"1em\" }}\n          >\n            <motion.span\n              animate={isInView ? { y: settledY } : undefined}\n              className=\"flex flex-col\"\n              initial={{ y: restY }}\n              transition={{\n                duration,\n                ease: [0.15, 1, 0.1, 1],\n                delay,\n              }}\n            >\n              {Array.from({ length: numberOfRolls + 2 }).map((_, copyIndex) => (\n                <span\n                  className=\"flex shrink-0 items-center justify-center\"\n                  // oxlint-disable-next-line react/no-array-index-key, react-doctor/no-array-index-as-key -- static per-render roll-copy list, order never changes\n                  key={copyIndex}\n                  style={{ height: \"1.2em\" }}\n                >\n                  {glyph}\n                </span>\n              ))}\n            </motion.span>\n          </span>\n        );\n      })}\n    </MotionComponent>\n  );\n}\n\nexport default RollingText;\n",
      "type": "registry:ui",
      "target": "components/sora-ui/texts/rolling-text.tsx"
    }
  ],
  "meta": {
    "demoProps": {
      "RollingText": {
        "text": {
          "value": "MOTION FIRST"
        },
        "direction": {
          "value": "up",
          "options": {
            "up": "up",
            "down": "down"
          }
        },
        "speed": {
          "value": 0.05,
          "min": 0,
          "max": 0.2,
          "step": 0.01
        },
        "duration": {
          "value": 4,
          "min": 1,
          "max": 8,
          "step": 0.5
        }
      }
    },
    "inspiration": {
      "type": "adapted",
      "label": "Skiper UI",
      "url": "https://skiper-ui.com/v1/skiper27"
    }
  },
  "type": "registry:ui"
}
