{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glitch-text",
  "title": "Glitch text",
  "description": "Text that decodes itself into place and tears for a moment, with a stable copy for screen readers.",
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json"
  ],
  "files": [
    {
      "path": "registry/cyber/ui/glitch-text.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { burst, scramble } from \"@/registry/cyber/lib/glitch\"\nimport \"@/registry/cyber/ui/cyber/glitch-text.css\"\n\n// Text that decodes itself into place, and tears for a moment when asked.\n//\n// The words a screen reader gets never change: the real text sits in a\n// visually hidden span, and the animated copy beside it is aria-hidden.\n// Below FX \"full\" nothing animates; the text is simply there.\n//\n// - `decode`: \"mount\" decodes once when it appears, \"view\" when it scrolls\n//   into view, \"hover\" each time the pointer arrives. Changing `children`\n//   always decodes to the new text.\n// - `as`: the element to render, \"span\" by default.\nfunction GlitchText({\n  children,\n  as: Tag = \"span\",\n  decode = \"mount\",\n  duration,\n  ...props\n}: Omit<React.ComponentProps<\"span\">, \"children\"> & {\n  children: string\n  as?: \"span\" | \"h1\" | \"h2\" | \"h3\" | \"p\" | \"div\" | \"strong\"\n  decode?: \"mount\" | \"view\" | \"hover\" | \"none\"\n  duration?: number\n}) {\n  const visible = React.useRef<HTMLSpanElement>(null)\n  const stop = React.useRef<() => void>(() => {})\n  const run = React.useCallback(() => {\n    const node = visible.current\n    if (!node) return\n    stop.current()\n    stop.current = scramble(node, children, { duration: duration ?? Math.min(900, 220 + children.length * 22) })\n    burst(node.parentElement!, 300)\n  }, [children, duration])\n\n  React.useEffect(() => {\n    const node = visible.current\n    if (!node) return\n    if (decode === \"none\" || decode === \"hover\") {\n      node.textContent = children\n      return\n    }\n    if (decode === \"mount\") {\n      run()\n      return () => stop.current()\n    }\n    const observer = new IntersectionObserver(\n      (entries) => {\n        if (!entries.some((entry) => entry.isIntersecting)) return\n        observer.disconnect()\n        run()\n      },\n      { threshold: 0.4 },\n    )\n    observer.observe(node)\n    return () => {\n      observer.disconnect()\n      stop.current()\n    }\n  }, [children, decode, run])\n\n  const Root = Tag as \"span\"\n  return (\n    <Root data-kit=\"glitch-text\" onPointerEnter={decode === \"hover\" ? run : undefined} {...props}>\n      <span data-sr-only>{children}</span>\n      <span ref={visible} data-kit=\"glitch-text-visible\" aria-hidden>\n        {children}\n      </span>\n    </Root>\n  )\n}\n\nexport { GlitchText }\n",
      "type": "registry:ui",
      "target": "@ui/glitch-text.tsx"
    },
    {
      "path": "registry/cyber/ui/cyber/glitch-text.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.ui {\n  [data-skin=\"cyber\"] [data-kit=\"glitch-text\"] {\n    position: relative;\n    display: inline-block;\n    /* The decoding copy is the same length as the text, so the line never\n       reflows while it runs. */\n    white-space: pre-wrap;\n\n    & [data-kit=\"glitch-text-visible\"] {\n      display: inline-block;\n    }\n\n    /* The tear: channels slip apart for a moment. */\n    &[data-glitching] [data-kit=\"glitch-text-visible\"] {\n      animation: var(--cy-fx-rgb) 300ms var(--cy-ease-snap);\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/cyber/glitch-text.css"
    }
  ],
  "type": "registry:ui"
}
