{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-shuffle-in",
  "type": "registry:component",
  "title": "Text Shuffle In",
  "description": "Every letter slides through a few other letters before it lands on its own. Plays when the text enters the viewport and again on hover or focus.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "shuffle",
    "text",
    "letters",
    "reveal",
    "hover",
    "stagger"
  ],
  "docs": "https://hyperblur.dev/effects/text-shuffle-in",
  "files": [
    {
      "path": "registry/hyperblur/text-shuffle-in.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-shuffle-in.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextShuffleInProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  shuffles?: number;\n  duration?: number;\n  stagger?: number;\n  trigger?: \"view\" | \"mount\";\n  hover?: boolean;\n  replayEvery?: number;\n  charset?: string;\n  accent?: string;\n}\n\nconst css = `\n.hb-qt1 {\n  --hb-qt1-h: 1.2em;\n  position: relative;\n  display: inline-block;\n  box-sizing: border-box;\n  font-family: inherit;\n  white-space: pre-wrap;\n  border-radius: 0.15em;\n}\n.hb-qt1:focus-visible { outline: 2px solid var(--hb-qt1-ac); outline-offset: 4px; }\n.hb-qt1-w { display: inline-block; white-space: nowrap; }\n.hb-qt1-c {\n  position: relative;\n  display: inline-block;\n  height: var(--hb-qt1-h);\n  line-height: var(--hb-qt1-h);\n  vertical-align: top;\n  clip-path: inset(0 -0.6em);\n}\n.hb-qt1-g { visibility: hidden; }\n.hb-qt1-s {\n  position: absolute;\n  top: 0;\n  left: 0;\n  width: 100%;\n  display: block;\n  opacity: 0;\n  will-change: transform;\n}\n.hb-qt1-x {\n  display: block;\n  height: var(--hb-qt1-h);\n  line-height: var(--hb-qt1-h);\n  text-align: center;\n  color: var(--hb-qt1-ac);\n}\n.hb-qt1-x:last-child { color: inherit; }\n.hb-qt1[data-on=\"true\"] .hb-qt1-s {\n  opacity: 1;\n  animation: hb-qt1-a var(--hb-qt1-d) cubic-bezier(0.2, 0.8, 0.2, 1) both;\n  animation-delay: calc(var(--hb-qt1-i) * var(--hb-qt1-st));\n}\n.hb-qt1[data-on=\"true\"][data-run=\"1\"] .hb-qt1-s { animation-name: hb-qt1-b; }\n.hb-qt1[data-on=\"true\"][data-run=\"2\"] .hb-qt1-s { animation-name: hb-qt1-c; }\n.hb-qt1-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n@keyframes hb-qt1-a {\n  0% { opacity: 0; transform: translate3d(0, 0, 0); }\n  14% { opacity: 1; }\n  100% { opacity: 1; transform: translate3d(0, var(--hb-qt1-f), 0); }\n}\n@keyframes hb-qt1-b {\n  0% { transform: translate3d(0, 0, 0); }\n  100% { transform: translate3d(0, var(--hb-qt1-f), 0); }\n}\n@keyframes hb-qt1-c {\n  0% { transform: translate3d(0, 0, 0); }\n  100% { transform: translate3d(0, var(--hb-qt1-f), 0); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qt1 .hb-qt1-s {\n    opacity: 1;\n    animation: none !important;\n    will-change: auto;\n    transform: translate3d(0, var(--hb-qt1-f), 0);\n  }\n}\n`;\n\nconst FALLBACK_POOL = \"abcdefghijklmnopqrstuvwxyz\";\n\nfunction mix(i: number, k: number) {\n  let h = Math.imul(i + 1, 2654435761) ^ Math.imul(k + 7, 40503);\n  h ^= h >>> 13;\n  h = Math.imul(h, 1274126177);\n  h ^= h >>> 16;\n  return h >>> 0;\n}\n\nfunction build(text: string, count: number, charset?: string) {\n  const own = Array.from(new Set(Array.from(charset ?? text).filter((c) => !/\\s/.test(c))));\n  const pool = own.length > 1 ? own : Array.from(FALLBACK_POOL);\n  let n = 0;\n  const words = text.split(/(\\s+)/).filter((t) => t !== \"\").map((value) => {\n    if (/^\\s+$/.test(value)) return { space: true, value, letters: [] as { ch: string; i: number; seq: string[] }[] };\n    const letters = Array.from(value).map((ch) => {\n      const i = n++;\n      const seq: string[] = [];\n      for (let k = 0; k < count; k++) {\n        let idx = mix(i, k) % pool.length;\n        if (pool[idx] === ch) idx = (idx + 1) % pool.length;\n        seq.push(pool[idx]);\n      }\n      seq.push(ch);\n      return { ch, i, seq };\n    });\n    return { space: false, value, letters };\n  });\n  return words;\n}\n\nexport function TextShuffleIn({\n  text,\n  shuffles = 4,\n  duration = 0.9,\n  stagger = 0.045,\n  trigger = \"view\",\n  hover = true,\n  replayEvery = 0,\n  charset,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onPointerEnter,\n  onFocus,\n  ...rest\n}: TextShuffleInProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const visible = React.useRef(true);\n  const [on, setOn] = React.useState(false);\n  const [run, setRun] = React.useState(0);\n\n  const count = Math.max(1, Math.round(shuffles));\n\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    if (trigger === \"mount\" || typeof IntersectionObserver === \"undefined\") {\n      const id = requestAnimationFrame(() => setOn(true));\n      return () => cancelAnimationFrame(id);\n    }\n    const io = new IntersectionObserver(\n      (entries) => {\n        for (const entry of entries) {\n          visible.current = entry.isIntersecting;\n          if (entry.isIntersecting) setOn(true);\n        }\n      },\n      { threshold: 0.2 }\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, [trigger]);\n\n  const replay = React.useCallback(() => {\n    setOn(true);\n    setRun((r) => (r === 1 ? 2 : 1));\n  }, []);\n\n  React.useEffect(() => {\n    if (!(replayEvery > 0)) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const id = window.setInterval(() => {\n      if (visible.current) replay();\n    }, replayEvery * 1000);\n    return () => window.clearInterval(id);\n  }, [replayEvery, replay]);\n\n  const words = build(text, count, charset);\n\n  const vars = {\n    \"--hb-qt1-d\": `${Math.max(0.05, duration).toFixed(3)}s`,\n    \"--hb-qt1-st\": `${Math.max(0, stagger).toFixed(3)}s`,\n    \"--hb-qt1-f\": `${((-count / (count + 1)) * 100).toFixed(3)}%`,\n    \"--hb-qt1-ac\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <span\n      ref={ref}\n      className={`hb-qt1 ${className}`}\n      style={vars}\n      data-on={on}\n      data-run={run}\n      tabIndex={hover ? 0 : undefined}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        if (hover) replay();\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        if (hover) replay();\n      }}\n      {...rest}\n    >\n      <style href=\"hb-text-shuffle-in\" precedence=\"default\">{css}</style>\n      <span className=\"hb-qt1-sr\">{text}</span>\n      <span aria-hidden=\"true\">\n        {words.map((w, wi) =>\n          w.space ? (\n            w.value\n          ) : (\n            <span key={wi} className=\"hb-qt1-w\">\n              {w.letters.map((l) => (\n                <span key={l.i} className=\"hb-qt1-c\" style={{ \"--hb-qt1-i\": l.i } as React.CSSProperties}>\n                  <span className=\"hb-qt1-g\">{l.ch}</span>\n                  <span className=\"hb-qt1-s\">\n                    {l.seq.map((c, k) => (\n                      <span key={k} className=\"hb-qt1-x\">\n                        {c}\n                      </span>\n                    ))}\n                  </span>\n                </span>\n              ))}\n            </span>\n          )\n        )}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}