{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dither-image",
  "title": "Dither Image",
  "description": "Converts any image to dither or ASCII live, with the real image kept for accessibility.",
  "dependencies": [],
  "registryDependencies": [
    "https://dotgrain.space/r/engine.json"
  ],
  "files": [
    {
      "path": "registry/ui/dither-image.tsx",
      "content": "\"use client\";\n\nimport { useState, type CSSProperties, type Ref } from \"react\";\nimport { Quantize } from \"@/lib/dotgrain/quantize\";\nimport type { DitherTokens } from \"@/lib/dotgrain/types\";\n\nexport type DitherImageProps = Partial<DitherTokens> & {\n  src: string;\n  /** Required: the real image stays in the DOM for screen readers and search engines. */\n  alt: string;\n  /** Intrinsic width; with `height` it reserves the aspect ratio so nothing shifts on load. */\n  width?: number;\n  height?: number;\n  crossOrigin?: \"anonymous\";\n  className?: string;\n  style?: CSSProperties;\n  ref?: Ref<HTMLDivElement>;\n};\n\nconst visuallyHidden: CSSProperties = {\n  position: \"absolute\",\n  width: 1,\n  height: 1,\n  overflow: \"hidden\",\n  clipPath: \"inset(50%)\",\n  whiteSpace: \"nowrap\",\n};\nconst fill: CSSProperties = { position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\", objectFit: \"cover\" };\n\nexport function DitherImage({ src, alt, width, height, crossOrigin, className, style, ref, ...tokens }: DitherImageProps) {\n  // If the pixels can't be read (CORS), show the plain image instead: content never disappears.\n  const [failed, setFailed] = useState(false);\n  return (\n    <div\n      ref={ref}\n      className={className}\n      style={{ position: \"relative\", aspectRatio: width && height ? `${width} / ${height}` : undefined, maxWidth: width, ...style }}\n    >\n      {/* eslint-disable-next-line @next/next/no-img-element -- registry components can't assume next/image */}\n      <img src={src} alt={alt} width={width} height={height} crossOrigin={crossOrigin} style={failed ? fill : visuallyHidden} />\n      {!failed && (\n        <Quantize\n          source={{ kind: \"image\", src, crossOrigin }}\n          onError={() => setFailed(true)}\n          {...tokens}\n          style={{ position: \"absolute\", inset: 0 }}\n        />\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "modes": [
      "dither",
      "ascii"
    ]
  },
  "categories": [
    "media"
  ],
  "type": "registry:ui"
}