{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cipher-scramble-text",
  "type": "registry:ui",
  "title": "Cipher Scramble Text",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Cryptographic matrix text decoder that permutes characters through a high-frequency glyph wave on pointer hover, focus, or click.",
  "dependencies": [
    "framer-motion",
    "lucide-react",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/cipher-scramble-text.tsx",
      "content": "\"use client\";\n\nimport React, { useCallback, useEffect, useRef, useState } from \"react\";\nimport { motion, useReducedMotion } from \"framer-motion\";\nimport { Terminal, RefreshCw } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface CipherScrambleTextProps {\n  /** Target decoded text string. Default: \"ZERO-DEPENDENCY KINETIC PRIMITIVES\" */\n  text?: string;\n  /** Pool of cipher characters used during scramble permutation. */\n  charset?: string;\n  /** Duration of each scramble frame tick in milliseconds. Default: 28 */\n  frameInterval?: number;\n  /** Number of scramble cycles per character before locking in. Default: 2 */\n  cyclesPerChar?: number;\n  className?: string;\n}\n\nconst DEFAULT_CHARSET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#$%&*+<>?\";\n\nexport function CipherScrambleText({\n  text = \"ZERO-DEPENDENCY KINETIC PRIMITIVES\",\n  charset = DEFAULT_CHARSET,\n  frameInterval = 28,\n  cyclesPerChar = 2,\n  className,\n}: CipherScrambleTextProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const [displayed, setDisplayed] = useState<string>(text);\n  const [isScrambling, setIsScrambling] = useState(false);\n  const timerRef = useRef<ReturnType<typeof setInterval> | null>(null);\n\n  const stopScramble = useCallback(() => {\n    if (timerRef.current) {\n      clearInterval(timerRef.current);\n      timerRef.current = null;\n    }\n    setIsScrambling(false);\n  }, []);\n\n  const triggerScramble = useCallback(() => {\n    if (shouldReduceMotion) {\n      setDisplayed(text);\n      return;\n    }\n\n    stopScramble();\n    setIsScrambling(true);\n\n    let step = 0;\n    const totalSteps = text.length * cyclesPerChar;\n\n    timerRef.current = setInterval(() => {\n      step += 1;\n      const lockedCount = Math.floor(step / cyclesPerChar);\n\n      const nextStr = text\n        .split(\"\")\n        .map((char, idx) => {\n          if (char === \" \") return \" \";\n          if (idx < lockedCount) return char;\n          const randomIndex = Math.floor(Math.random() * charset.length);\n          return charset[randomIndex] || char;\n        })\n        .join(\"\");\n\n      setDisplayed(nextStr);\n\n      if (step >= totalSteps) {\n        setDisplayed(text);\n        stopScramble();\n      }\n    }, frameInterval);\n  }, [text, charset, frameInterval, cyclesPerChar, shouldReduceMotion, stopScramble]);\n\n  useEffect(() => {\n    setDisplayed(text);\n    return () => stopScramble();\n  }, [text, stopScramble]);\n\n  return (\n    <motion.button\n      type=\"button\"\n      onClick={triggerScramble}\n      onMouseEnter={triggerScramble}\n      onFocus={triggerScramble}\n      whileTap={shouldReduceMotion ? undefined : { scale: 0.985 }}\n      transition={{ type: \"spring\", stiffness: 360, damping: 24 }}\n      className={cn(\n        \"group relative inline-flex w-full max-w-lg flex-col items-start justify-between gap-3 rounded-2xl border border-neutral-200 bg-white p-6 text-left transition-colors hover:border-black focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:border-[#222222] dark:bg-[#0A0A0A] dark:hover:border-white dark:focus-visible:ring-white\",\n        className\n      )}\n    >\n      {/* Screen-reader stable text */}\n      <span className=\"sr-only\">{text}</span>\n\n      <div className=\"flex w-full items-center justify-between text-[11px] font-medium uppercase tracking-widest text-neutral-400\">\n        <span className=\"inline-flex items-center gap-1.5 font-mono\">\n          <Terminal className=\"h-3.5 w-3.5 text-black dark:text-white\" />\n          {isScrambling ? \"DECODING_STREAM...\" : \"CIPHER_LOCKED\"}\n        </span>\n        <RefreshCw\n          aria-hidden=\"true\"\n          className={cn(\n            \"h-3.5 w-3.5 transition-transform duration-300\",\n            isScrambling && \"rotate-180 text-black dark:text-white\"\n          )}\n        />\n      </div>\n\n      <div\n        aria-hidden=\"true\"\n        className=\"font-mono text-base font-bold tracking-tight text-black sm:text-lg dark:text-white\"\n      >\n        {displayed}\n      </div>\n\n      <div className=\"text-[11px] text-neutral-500 dark:text-neutral-400\">\n        Hover, focus, or click to trigger cryptographic glyph wave\n      </div>\n    </motion.button>\n  );\n}\n\nexport default CipherScrambleText;\n",
      "type": "registry:ui",
      "target": "components/ui/cipher-scramble-text.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
