{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scramble-text",
  "title": "Scramble Text",
  "description": "Text that scrambles through ASCII glyphs before settling, with the real string in the DOM from the first frame.",
  "dependencies": [],
  "registryDependencies": [
    "https://dotgrain.space/r/engine.json"
  ],
  "files": [
    {
      "path": "registry/ui/scramble-text.tsx",
      "content": "\"use client\";\n\nimport { useImperativeHandle, useState, type CSSProperties, type Ref } from \"react\";\nimport { useDitherTokens, useReducedMotion } from \"@/lib/dotgrain/provider\";\nimport { Quantize } from \"@/lib/dotgrain/quantize\";\nimport { useTrigger, type Trigger } from \"@/lib/dotgrain/trigger\";\nimport type { DitherTokens } from \"@/lib/dotgrain/types\";\n\nexport type ScrambleTextProps = Partial<Omit<DitherTokens, \"mode\">> & {\n  /** The real text: in the DOM, readable and selectable from the first frame. */\n  children: string;\n  as?: \"span\" | \"p\" | \"div\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n  /** When to scramble: on mount, on pointer hover, or the first time it scrolls into view. */\n  trigger?: Trigger;\n  /** Scramble length in milliseconds. */\n  duration?: number;\n  className?: string;\n  style?: CSSProperties;\n  ref?: Ref<HTMLElement>;\n};\n\nexport function ScrambleText({\n  children,\n  as: Tag = \"span\",\n  trigger = \"mount\",\n  duration = 900,\n  className,\n  style,\n  ref,\n  ...tokens\n}: ScrambleTextProps) {\n  const [element, setElement] = useState<HTMLElement | null>(null);\n  const reduced = useReducedMotion();\n  const { speed } = useDitherTokens({ ...tokens, mode: \"ascii\" });\n  // Re-scrambles on mount when the text changes.\n  const { start, onMouseEnter } = useTrigger(element, trigger, duration, !reduced && speed > 0, children);\n  const active = start !== null;\n  useImperativeHandle(ref, () => element!, [element]);\n\n  return (\n    <Tag\n      ref={setElement}\n      className={className}\n      onMouseEnter={onMouseEnter}\n      style={{\n        position: \"relative\",\n        display: Tag === \"span\" ? \"inline-block\" : undefined,\n        transition: \"color 150ms\",\n        ...style,\n        // Hidden only visually while the overlay scrambles; screen readers and selection still get the text.\n        color: active ? \"transparent\" : style?.color,\n      }}\n    >\n      {children}\n      {active && element && (\n        <Quantize\n          source={{ kind: \"text\", element, scramble: 1 }}\n          {...tokens}\n          mode=\"ascii\"\n          style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\" }}\n        />\n      )}\n    </Tag>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "modes": [
      "ascii"
    ]
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}