{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dither-reveal",
  "title": "Dither Reveal",
  "description": "Text that dithers in or out when it scrolls into view, mounts or is hovered, with the real text always in the DOM.",
  "dependencies": [],
  "registryDependencies": [
    "https://dotgrain.space/r/engine.json"
  ],
  "files": [
    {
      "path": "registry/ui/dither-reveal.tsx",
      "content": "\"use client\";\n\nimport { useImperativeHandle, useState, useSyncExternalStore, type CSSProperties, type ReactNode, 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 DitherRevealProps = Partial<Omit<DitherTokens, \"mode\" | \"glyphs\">> & {\n  /** The real text: always in the DOM and selectable. */\n  children: ReactNode;\n  as?: \"span\" | \"p\" | \"div\" | \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n  /** When to run: the first time it scrolls into view, on mount, or on pointer hover. */\n  trigger?: Trigger;\n  /** Dither the text in (appear) or out (disappear). */\n  direction?: \"in\" | \"out\";\n  /** Run length in milliseconds. */\n  duration?: number;\n  className?: string;\n  style?: CSSProperties;\n  ref?: Ref<HTMLElement>;\n};\n\nconst subscribe = () => () => {};\n\nexport function DitherReveal({\n  children,\n  as: Tag = \"span\",\n  trigger = \"inView\",\n  direction = \"in\",\n  duration = 1200,\n  className,\n  style,\n  ref,\n  ...tokens\n}: DitherRevealProps) {\n  const [element, setElement] = useState<HTMLElement | null>(null);\n  // False on the server and during hydration: the text is never hidden before JavaScript can reveal it.\n  const hydrated = useSyncExternalStore(subscribe, () => true, () => false);\n  const reduced = useReducedMotion();\n  const { speed } = useDitherTokens({ ...tokens, mode: \"dither\" });\n  const enabled = !reduced && speed > 0;\n  const { start, fired, onMouseEnter } = useTrigger(element, trigger, duration, enabled);\n  useImperativeHandle(ref, () => element!, [element]);\n\n  // \"in\" hides the text while running, and before its first run unless it waits for a hover;\n  // \"out\" hides it once its run starts. Reduced motion keeps it as is.\n  const hidden = enabled && hydrated && (direction === \"in\" ? start !== null || (!fired && trigger !== \"hover\") : fired);\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        ...style,\n        // Hidden only visually; screen readers and selection still get the text.\n        color: hidden ? \"transparent\" : style?.color,\n      }}\n    >\n      {children}\n      {start !== null && element && (\n        <Quantize\n          source={{ kind: \"text\", element, reveal: { start, duration, out: direction === \"out\" } }}\n          {...tokens}\n          mode=\"dither\"\n          style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\" }}\n        />\n      )}\n    </Tag>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "modes": [
      "dither"
    ]
  },
  "categories": [
    "text"
  ],
  "type": "registry:ui"
}