{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"stagger-chars","type":"registry:ui","title":"Stagger Chars","description":"Hover and a wave of bouncing, tilting characters ripples through the text with a flash of accent color.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/stagger-chars.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Fragment, useRef } from \"react\";\n\nconst effects: Record<string, (accent: string) => Keyframe[]> = {\n  wave: (c) => [\n    { transform: \"none\" },\n    { transform: \"translateY(-0.4em) rotate(-12deg)\", color: c, offset: 0.35 },\n    { transform: \"translateY(0.06em) rotate(5deg)\", offset: 0.68 },\n    { transform: \"none\" },\n  ],\n  bounce: (c) => [\n    { transform: \"none\" },\n    { transform: \"translateY(-0.5em) scale(1.08, 0.94)\", color: c, offset: 0.35 },\n    { transform: \"translateY(0.04em) scale(1.1, 0.88)\", offset: 0.62 },\n    { transform: \"translateY(-0.06em) scale(0.97, 1.03)\", offset: 0.8 },\n    { transform: \"none\" },\n  ],\n  spin: (c) => [\n    { transform: \"rotate(0deg)\" },\n    { transform: \"translateY(-0.25em) rotate(180deg) scale(1.1)\", color: c, offset: 0.5 },\n    { transform: \"rotate(360deg)\" },\n  ],\n  flip: (c) => [\n    { transform: \"perspective(400px) rotateX(0deg)\" },\n    { transform: \"perspective(400px) rotateX(180deg)\", color: c, offset: 0.5 },\n    { transform: \"perspective(400px) rotateX(360deg)\" },\n  ],\n};\n\nexport interface StaggerCharsProps {\n  text: string;\n  /** Motion each character performs. */\n  effect?: \"wave\" | \"bounce\" | \"spin\" | \"flip\";\n  /** Where the wave starts. */\n  direction?: \"start\" | \"end\" | \"center\" | \"edges\" | \"random\";\n  /** Delay between characters, in ms. */\n  stagger?: number;\n  /** Duration of each character's motion, in ms. */\n  duration?: number;\n  /** Color flashed at the peak of the motion. */\n  accent?: string;\n  className?: string;\n}\n\nexport function StaggerChars({\n  text,\n  effect = \"wave\",\n  direction = \"start\",\n  stagger = 35,\n  duration = 700,\n  accent = \"#a3e635\",\n  className,\n}: StaggerCharsProps) {\n  const ref = useRef<HTMLSpanElement>(null);\n  const busy = useRef(0);\n\n  const play = () => {\n    const els = ref.current?.querySelectorAll<HTMLElement>(\"[data-sc]\");\n    if (!els?.length || performance.now() < busy.current) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const n = els.length;\n    const mid = (n - 1) / 2;\n    const order = (i: number) =>\n      direction === \"end\"\n        ? n - 1 - i\n        : direction === \"center\"\n          ? Math.abs(i - mid)\n          : direction === \"edges\"\n            ? mid - Math.abs(i - mid)\n            : direction === \"random\"\n              ? (((i + 1) * 7919) % 97) / 97 * (n - 1)\n              : i;\n    const frames = (effects[effect] ?? effects.wave)(accent);\n    let max = 0;\n    els.forEach((el, i) => {\n      const delay = order(i) * stagger;\n      max = Math.max(max, delay);\n      el.animate(frames, { duration, delay, easing: \"cubic-bezier(.3,.7,.3,1)\" });\n    });\n    busy.current = performance.now() + max + duration;\n  };\n\n  const words = text.split(\" \");\n\n  return (\n    <span\n      ref={ref}\n      className={className}\n      style={{ display: \"inline-block\", cursor: \"default\" }}\n      onPointerEnter={play}\n      onClick={play}\n    >\n      <span className=\"sr-only\">{text}</span>\n      {words.map((word, w) => (\n        <Fragment key={w}>\n          <span aria-hidden style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n            {Array.from(word).map((c, k) => (\n              <span key={k} data-sc style={{ display: \"inline-block\", transformOrigin: \"50% 70%\" }}>\n                {c}\n              </span>\n            ))}\n          </span>\n          {w < words.length - 1 && \" \"}\n        </Fragment>\n      ))}\n    </span>\n  );\n}\n"}]}