{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "roll-text",
  "title": "Roll Text",
  "description": "Characters that roll up to a copy of themselves on hover or keyboard focus.",
  "registryDependencies": [
    "@corsair-ui/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/roll-text.tsx",
      "content": "import { Fragment, type ComponentProps, type Ref } from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\n// One splitter for the module: user-perceived characters, so emoji and\n// accents stay whole wherever the runtime can tell them apart.\nconst characterSplitter =\n  typeof Intl === \"object\" && typeof Intl.Segmenter === \"function\"\n    ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n    : null;\n\nfunction graphemes(text: string) {\n  if (!characterSplitter) return [...text];\n  const pieces: string[] = [];\n  for (const { segment } of characterSplitter.segment(text)) pieces.push(segment);\n  return pieces;\n}\n\ntype RollTextTag = \"span\" | \"div\" | \"p\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n\ninterface RollTextProps extends Omit<ComponentProps<\"span\">, \"children\"> {\n  /** Plain text. */\n  children: string;\n  /** The element to render. */\n  as?: RollTextTag;\n  /** Time between one character starting to roll and the next, in ms. */\n  stagger?: number;\n  /** How long each character takes to roll, in ms. */\n  duration?: number;\n}\n\n/**\n * Text whose characters roll up, one after another, to reveal a copy of\n * themselves: a small flourish for links and buttons. It rolls when the\n * text is hovered, or when a parent with Tailwind's `group` class is\n * hovered or has keyboard focus, so it follows the link or button it sits\n * in. It is CSS transitions only and works as a server component. Screen\n * readers get the text once; with `prefers-reduced-motion` it holds still.\n * Characters are clipped to the line box, so keep a line height with room\n * for descenders.\n *\n * @example\n * <a href=\"/about\" className=\"group\">\n *   <RollText>About us</RollText>\n * </a>\n */\nfunction RollText({\n  children,\n  as: Tag = \"span\",\n  stagger = 20,\n  duration = 400,\n  className,\n  ref,\n  ...props\n}: RollTextProps) {\n  // Words and the whitespace between them, whitespace kept as it is.\n  const parts = children.split(/(\\s+)/).filter(Boolean);\n  let next = 0;\n\n  return (\n    <Tag\n      ref={ref as Ref<never>}\n      data-slot=\"roll-text\"\n      className={cn(\"group inline-block whitespace-pre-wrap\", className)}\n      {...props}\n    >\n      <span className=\"sr-only\">{children}</span>\n      <span aria-hidden=\"true\" data-slot=\"roll-text-visual\">\n        {parts.map((part, partIndex) =>\n          /^\\s+$/.test(part) ? (\n            <Fragment key={partIndex}>{part}</Fragment>\n          ) : (\n            // A word never breaks between its characters.\n            <span key={partIndex} className=\"inline-block whitespace-nowrap\">\n              {graphemes(part).map((character) => {\n                const index = next++;\n                return (\n                  <span\n                    key={index}\n                    data-slot=\"roll-text-character\"\n                    className=\"relative inline-block overflow-clip align-top\"\n                  >\n                    <span\n                      className=\"relative inline-block transition-transform ease-[cubic-bezier(0.65,0,0.35,1)] motion-safe:group-hover:-translate-y-full motion-safe:group-focus-visible:-translate-y-full motion-reduce:transition-none\"\n                      style={{\n                        transitionDuration: `${duration}ms`,\n                        transitionDelay: `${index * stagger}ms`,\n                      }}\n                    >\n                      {character}\n                      <span className=\"absolute top-full left-0\">{character}</span>\n                    </span>\n                  </span>\n                );\n              })}\n            </span>\n          )\n        )}\n      </span>\n    </Tag>\n  );\n}\n\nexport { RollText, type RollTextProps };\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}