{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "loader-text-scramble",
  "type": "registry:component",
  "title": "Loader Text Scramble",
  "description": "A word scrambles through random glyphs and resolves letter by letter, holds for a moment and starts over. Monospace, with a blinking cursor.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "loaders",
    "loader",
    "text",
    "scramble",
    "terminal",
    "mono",
    "glyphs"
  ],
  "docs": "https://hyperblur.dev/effects/loader-text-scramble",
  "files": [
    {
      "path": "registry/hyperblur/loader-text-scramble.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/loader-text-scramble.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LoaderTextScrambleProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text?: string;\n  glyphs?: string;\n  size?: number;\n  color?: string;\n  accent?: string;\n  interval?: number;\n  label?: string;\n}\n\nconst css = `\n.hb-qcc {\n  position: relative;\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 0.6em;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  vertical-align: middle;\n}\n.hb-qcc *, .hb-qcc *::before, .hb-qcc *::after { box-sizing: border-box; }\n.hb-qcc-t {\n  display: inline-flex;\n  align-items: baseline;\n  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;\n  font-size: var(--hb-qcc-s);\n  font-weight: 500;\n  line-height: 1.2;\n  letter-spacing: 0.02em;\n  white-space: pre;\n}\n.hb-qcc-ch { color: var(--hb-qcc-c); }\n.hb-qcc-ch[data-s=\"1\"] { color: var(--hb-qcc-a); opacity: 0.8; }\n.hb-qcc-cur {\n  display: inline-block;\n  width: 0.55em;\n  height: 0.12em;\n  margin-left: 0.12em;\n  background: var(--hb-qcc-a);\n  animation: hb-qcc-blink 1s steps(1) infinite;\n}\n.hb-qcc-l { font-size: 12px; line-height: 1.3; color: #a1a1a1; white-space: nowrap; }\n.hb-qcc-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-qcc-blink {\n  0%, 100% { opacity: 1; }\n  50% { opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qcc-cur { animation: none; }\n}\n`;\n\nconst SCRAMBLE = 8;\nconst STAGGER = 3;\nconst HOLD = 22;\n\nfunction hash(a: number, b: number) {\n  let h = Math.imul(a + 1, 374761393) ^ Math.imul(b + 7, 668265263);\n  h = Math.imul(h ^ (h >>> 13), 1274126177);\n  return (h ^ (h >>> 16)) >>> 0;\n}\n\nexport function LoaderTextScramble({\n  text = \"Loading\",\n  glyphs = \"!<>-_/[]{}=+*^?#%&\",\n  size = 20,\n  color = \"#ededed\",\n  accent = \"#2f7bff\",\n  interval = 55,\n  label,\n  className = \"\",\n  style,\n  ...rest\n}: LoaderTextScrambleProps) {\n  const chars = React.useMemo(() => Array.from(text), [text]);\n  const pool = React.useMemo(() => Array.from(glyphs || \"#\"), [glyphs]);\n  const [frame, setFrame] = React.useState(-1);\n\n  React.useEffect(() => {\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const cycle = SCRAMBLE + chars.length * STAGGER + STAGGER + HOLD;\n    let f = 0;\n    const id = window.setInterval(() => {\n      f = (f + 1) % cycle;\n      setFrame(f);\n    }, Math.max(16, interval));\n    return () => window.clearInterval(id);\n  }, [chars.length, interval]);\n\n  const shown = chars.map((ch, i) => {\n    if (frame < 0 || ch === \" \") return { ch, s: 0 };\n    const resolveAt = SCRAMBLE + i * STAGGER + STAGGER;\n    if (frame >= resolveAt) return { ch, s: 0 };\n    return { ch: pool[hash(frame, i) % pool.length], s: 1 };\n  });\n\n  const vars = {\n    \"--hb-qcc-s\": `${size}px`,\n    \"--hb-qcc-c\": color,\n    \"--hb-qcc-a\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-loader-text-scramble\" precedence=\"default\">{css}</style>\n      <span role=\"status\" className={`hb-qcc ${className}`} style={vars} {...rest}>\n        <span className=\"hb-qcc-t\" aria-hidden=\"true\">\n          {shown.map((c, i) => (\n            <span key={i} className=\"hb-qcc-ch\" data-s={c.s}>\n              {c.ch}\n            </span>\n          ))}\n          <span className=\"hb-qcc-cur\" />\n        </span>\n        {label ? (\n          <span className=\"hb-qcc-l\" aria-hidden=\"true\">\n            {label}\n          </span>\n        ) : null}\n        <span className=\"hb-qcc-sr\">{label ?? text}</span>\n      </span>\n    </>\n  );\n}\n"
    }
  ]
}