{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-shape-mask",
  "title": "Image Shape Mask",
  "description": "Masks an image into a shape (circle, squircle, arch, hexagon, flower, blob or diamond) that grows out from the centre as it scrolls into view and morphs smoothly into another shape on hover while the photo slowly zooms.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/image-shape-mask/image-shape-mask.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, useInView, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type MaskShape = \"circle\" | \"squircle\" | \"arch\" | \"hexagon\" | \"flower\" | \"blob\" | \"diamond\";\n\n// Each shape is an inside-test on a unit box centred at 0 (x, y in -0.5…0.5, y down).\nconst INSIDE: Record<MaskShape, (x: number, y: number) => boolean> = {\n  circle: (x, y) => x * x + y * y <= 0.25,\n  squircle: (x, y) => Math.pow(Math.abs(x) / 0.5, 4) + Math.pow(Math.abs(y) / 0.5, 4) <= 1,\n  arch: (x, y) => Math.abs(x) <= 0.42 && y <= 0.5 && (y >= -0.08 || x * x + (y + 0.08) * (y + 0.08) <= 0.42 * 0.42),\n  hexagon: (x, y) => {\n    const ax = Math.abs(x);\n    const ay = Math.abs(y);\n    return ay <= 0.433 && ax * 0.866 + ay * 0.5 <= 0.433;\n  },\n  flower: (x, y) => {\n    const r = Math.hypot(x, y);\n    const a = Math.atan2(y, x);\n    return r <= 0.38 + 0.12 * Math.cos(6 * a);\n  },\n  blob: (x, y) => {\n    const r = Math.hypot(x, y);\n    const a = Math.atan2(y, x);\n    return r <= 0.42 + 0.05 * Math.sin(3 * a + 1) + 0.035 * Math.cos(5 * a - 0.6);\n  },\n  diamond: (x, y) => Math.abs(x) + Math.abs(y) <= 0.5,\n};\n\nconst POINTS = 72;\n\n// Walk out from the centre along evenly spaced angles and binary-search the edge, so every shape\n// is a polygon with the same number of points and clip-path can morph between any two.\nfunction polygonFor(shape: MaskShape) {\n  const inside = INSIDE[shape];\n  const pts: string[] = [];\n  for (let i = 0; i < POINTS; i++) {\n    const a = (i / POINTS) * Math.PI * 2 - Math.PI / 2;\n    const dx = Math.cos(a);\n    const dy = Math.sin(a);\n    let lo = 0;\n    let hi = 0.75;\n    for (let k = 0; k < 22; k++) {\n      const mid = (lo + hi) / 2;\n      if (inside(dx * mid, dy * mid)) lo = mid;\n      else hi = mid;\n    }\n    pts.push(`${(50 + dx * lo * 100).toFixed(2)}% ${(50 + dy * lo * 100).toFixed(2)}%`);\n  }\n  return `polygon(${pts.join(\", \")})`;\n}\n\nconst CACHE = new Map<MaskShape, string>();\nexport const shapePath = (s: MaskShape) => {\n  if (!CACHE.has(s)) CACHE.set(s, polygonFor(s));\n  return CACHE.get(s)!;\n};\n// A tiny version of a shape, for growing it in from the middle.\nconst collapsed = `polygon(${Array.from({ length: POINTS }, () => \"50% 50%\").join(\", \")})`;\n\nexport interface ImageShapeMaskProps {\n  src?: string;\n  alt?: string;\n  shape?: MaskShape;\n  /** Shape to morph into on hover and focus. */\n  hoverShape?: MaskShape;\n  /** Grow the mask out from the centre the first time it scrolls into view. */\n  animateIn?: boolean;\n  /** Width / height, e.g. \"1 / 1\" or \"4 / 5\". */\n  aspectRatio?: string;\n  /** Slow zoom of the image inside the mask on hover. */\n  zoom?: boolean;\n  className?: string;\n}\n\nexport function ImageShapeMask({ src = \"/demo/21.webp\", alt = \"Portrait\", shape = \"blob\", hoverShape = \"circle\", animateIn = true, aspectRatio = \"1 / 1\", zoom = true, className }: ImageShapeMaskProps) {\n  const reduce = Boolean(useReducedMotion());\n  const ref = React.useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, amount: 0.3 });\n  const [hover, setHover] = React.useState(false);\n  const shown = !animateIn || reduce || inView;\n  const clip = !shown ? collapsed : shapePath(hover && hoverShape ? hoverShape : shape);\n\n  return (\n    <motion.div\n      ref={ref}\n      className={cn(\"relative w-full outline-none\", className)}\n      style={{ aspectRatio }}\n      onHoverStart={() => setHover(true)}\n      onHoverEnd={() => setHover(false)}\n      onFocus={() => setHover(true)}\n      onBlur={() => setHover(false)}\n    >\n      <motion.div\n        className=\"absolute inset-0 overflow-hidden\"\n        initial={false}\n        animate={{ clipPath: clip }}\n        transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 140, damping: 20, mass: 0.9 }}\n        style={{ clipPath: animateIn && !reduce ? collapsed : shapePath(shape) }}\n      >\n        <motion.img src={src} alt={alt} draggable={false} className=\"h-full w-full object-cover\" initial={false} animate={{ scale: zoom && hover && !reduce ? 1.08 : 1 }} transition={{ duration: 0.8, ease: [0.22, 1, 0.36, 1] }} />\n      </motion.div>\n    </motion.div>\n  );\n}\n\nexport default ImageShapeMask;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}