{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reveal-image",
  "title": "Reveal Image",
  "description": "An image that arrives as it is generated: blur to sharp, coarse mosaic to fine, or a left-to-right wipe, driven by a progress value.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/motion.json"
  ],
  "files": [
    {
      "path": "registry/miseui/ui/reveal-image.tsx",
      "content": "import type * as React from \"react\"\nimport { useEffect, useRef } from \"react\"\nimport { animate, motion, useMotionValue, useMotionValueEvent, useReducedMotion, useTransform } from \"motion/react\"\nimport { SPRING_DEFAULT, clampUnit } from \"@/registry/miseui/lib/motion\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\n\ntype RevealMode = \"blur\" | \"pixelate\" | \"wipe\"\n\nconst DEFAULT_MODE: RevealMode = \"blur\"\nconst COMPLETE = 1\nconst PERCENT = 100\n/** 24 px of blur hides detail but keeps the composition readable, which is the point. */\nconst MAX_BLUR_PX = 24\n/** A 4 % zoom that settles to 1 reads as the image arriving, not merely sharpening. */\nconst BLUR_SCALE_RANGE = 0.04\n/** The mosaic runs from 6 to 96 cells across. Quadratic growth keeps detail for the end, like a progressive decode. */\nconst MIN_CELLS = 6\nconst MAX_CELLS = 96\n/** The mosaic dissolves over the final share of progress so the last step is a fade, not a snap. */\nconst MOSAIC_FADE_SHARE = 0.15\nconst NO_EFFECT = \"none\"\n\n/** motion.img owns these; the same names on a plain img would not type-check against it. */\ntype ImgProps = Omit<\n  React.ComponentProps<\"img\">,\n  \"src\" | \"alt\" | \"style\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\"\n>\n\ninterface RevealImageProps extends ImgProps {\n  src: string\n  alt: string\n  /** 0..1, how much of the image has arrived. Values outside the range are clamped. 1 shows it plain. */\n  progress?: number\n  /** blur: soft to sharp. pixelate: coarse mosaic to fine. wipe: left to right. */\n  mode?: RevealMode\n  /** Applied to the wrapper, together with className. */\n  style?: React.CSSProperties\n}\n\nfunction blurFor(progress: number) {\n  if (progress >= COMPLETE) return NO_EFFECT\n  return `blur(${((1 - progress) * MAX_BLUR_PX).toFixed(2)}px)`\n}\n\nfunction clipFor(progress: number) {\n  if (progress >= COMPLETE) return NO_EFFECT\n  return `inset(0 ${((1 - progress) * PERCENT).toFixed(2)}% 0 0)`\n}\n\n/** Paints the image at mosaic resolution; CSS upscales it with image-rendering: pixelated. */\nfunction drawMosaic(canvas: HTMLCanvasElement | null, image: HTMLImageElement | null, progress: number) {\n  if (!canvas || !image || image.naturalWidth === 0) return\n  const ctx = canvas.getContext(\"2d\")\n  if (!ctx) return\n  const cells = Math.round(MIN_CELLS + (MAX_CELLS - MIN_CELLS) * progress * progress)\n  const rows = Math.max(1, Math.round((cells * image.naturalHeight) / image.naturalWidth))\n  if (canvas.width !== cells || canvas.height !== rows) {\n    canvas.width = cells\n    canvas.height = rows\n  }\n  ctx.imageSmoothingEnabled = true\n  ctx.drawImage(image, 0, 0, cells, rows)\n}\n\nfunction RevealImage({\n  src,\n  alt,\n  progress = COMPLETE,\n  mode = DEFAULT_MODE,\n  className,\n  style,\n  onLoad,\n  ...props\n}: RevealImageProps) {\n  const reduceMotion = useReducedMotion() ?? false\n  const target = clampUnit(progress)\n  const value = useMotionValue(target)\n  const imageRef = useRef<HTMLImageElement>(null)\n  const canvasRef = useRef<HTMLCanvasElement>(null)\n  const softens = mode === \"blur\" || mode === \"pixelate\"\n\n  useEffect(() => {\n    const controls = animate(value, target, reduceMotion ? { duration: 0 } : SPRING_DEFAULT)\n    return () => controls.stop()\n  }, [value, target, reduceMotion])\n\n  // Every mode writes all three styles so switching modes leaves no stale effect behind.\n  const filter = useTransform(value, (p) => (softens ? blurFor(p) : NO_EFFECT))\n  const scale = useTransform(value, (p) => (mode === \"blur\" ? 1 + (1 - p) * BLUR_SCALE_RANGE : 1))\n  const clipPath = useTransform(value, (p) => (mode === \"wipe\" ? clipFor(p) : NO_EFFECT))\n  const mosaicOpacity = useTransform(value, (p) => clampUnit((1 - p) / MOSAIC_FADE_SHARE))\n\n  useMotionValueEvent(value, \"change\", (p) => {\n    if (mode === \"pixelate\") drawMosaic(canvasRef.current, imageRef.current, p)\n  })\n\n  useEffect(() => {\n    if (mode === \"pixelate\") drawMosaic(canvasRef.current, imageRef.current, value.get())\n  }, [mode, src, value])\n\n  return (\n    <span\n      data-slot=\"reveal-image\"\n      data-mode={mode}\n      data-progress={target}\n      data-reduced={reduceMotion ? \"true\" : \"false\"}\n      className={cn(\"relative inline-block overflow-hidden align-middle\", className)}\n      style={style}\n    >\n      <motion.img\n        ref={imageRef}\n        src={src}\n        alt={alt}\n        className=\"block max-w-full\"\n        style={{ filter, scale, clipPath }}\n        onLoad={(event) => {\n          drawMosaic(canvasRef.current, event.currentTarget, value.get())\n          onLoad?.(event)\n        }}\n        {...props}\n      />\n      {mode === \"pixelate\" ? (\n        <motion.canvas\n          ref={canvasRef}\n          aria-hidden=\"true\"\n          data-testid=\"reveal-mosaic\"\n          className=\"pointer-events-none absolute inset-0 size-full [image-rendering:pixelated]\"\n          style={{ opacity: mosaicOpacity }}\n        />\n      ) : null}\n    </span>\n  )\n}\n\nexport { RevealImage, type RevealImageProps, type RevealMode }\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "effects"
  ],
  "type": "registry:ui"
}