{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ripple",
  "description": "ripple (lib)",
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/default/lib/ripple.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\ntype PressOptions = Required<\n  Pick<RippleProps, \"color\" | \"duration\" | \"opacity\" | \"minimumPressDuration\">\n>;\n\ninterface Press {\n  release: () => void;\n  cancel: () => void;\n}\n\nconst EASE = \"cubic-bezier(0.2, 0, 0, 1)\";\n\nfunction startPress(\n  container: HTMLElement,\n  x: number | undefined,\n  y: number | undefined,\n  { color, duration, opacity, minimumPressDuration }: PressOptions,\n  onDone: () => void,\n): Press | null {\n  const rect = container.getBoundingClientRect();\n  if (!rect.width || !rect.height) return null;\n\n  const maxDim = Math.max(rect.width, rect.height);\n  const size = Math.max(Math.floor(maxDim * 0.2), 1);\n  const scale = (Math.hypot(rect.width, rect.height) * 1.35 + 24) / size;\n\n  const end = { x: (rect.width - size) / 2, y: (rect.height - size) / 2 };\n  const start =\n    x != null && y != null\n      ? { x: x - rect.left - size / 2, y: y - rect.top - size / 2 }\n      : end;\n\n  const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n  const el = document.createElement(\"span\");\n  Object.assign(el.style, {\n    background: `radial-gradient(closest-side, ${color} 80%, transparent 100%)`,\n    borderRadius: \"50%\",\n    height: `${size}px`,\n    left: \"0\",\n    opacity: \"0\",\n    pointerEvents: \"none\",\n    position: \"absolute\",\n    top: \"0\",\n    width: `${size}px`,\n    willChange: \"transform, opacity\",\n  });\n  container.appendChild(el);\n\n  const grow = el.animate(\n    [\n      { transform: `translate(${start.x}px, ${start.y}px) scale(1)` },\n      { transform: `translate(${end.x}px, ${end.y}px) scale(${scale})` },\n    ],\n    { duration: reduced ? 0 : duration, easing: EASE, fill: \"forwards\" },\n  );\n  el.animate([{ opacity: 0 }, { opacity }], { duration: 75, fill: \"forwards\" });\n\n  const startedAt = performance.now();\n  let released = false;\n  let timer: number | undefined;\n\n  const cleanup = (): void => {\n    window.clearTimeout(timer);\n    grow.cancel();\n    el.remove();\n    onDone();\n  };\n\n  return {\n    cancel: cleanup,\n    release: (): void => {\n      if (released) return;\n      released = true;\n      const wait = Math.max(\n        0,\n        minimumPressDuration - (performance.now() - startedAt),\n      );\n      timer = window.setTimeout((): void => {\n        const fade = el.animate([{ opacity }, { opacity: 0 }], {\n          duration: 375,\n          fill: \"forwards\",\n        });\n        fade.onfinish = cleanup;\n      }, wait);\n    },\n  };\n}\n\nfunction Ripple({\n  color = \"currentColor\",\n  duration = 450,\n  opacity = 0.1,\n  hoverOpacity = 0.08,\n  hoverDuration = 150,\n  minimumPressDuration = 225,\n  disabled = false,\n  className,\n  style,\n  ...props\n}: RippleProps): React.JSX.Element {\n  const containerRef = React.useRef<HTMLSpanElement>(null);\n  const hoverRef = React.useRef<HTMLSpanElement>(null);\n\n  const optionsRef = React.useRef({\n    color,\n    duration,\n    hoverOpacity,\n    minimumPressDuration,\n    opacity,\n  });\n  optionsRef.current = {\n    color,\n    duration,\n    hoverOpacity,\n    minimumPressDuration,\n    opacity,\n  };\n\n  React.useEffect((): (() => void) | undefined => {\n    const container = containerRef.current;\n    const parent = container?.parentElement;\n    if (!container || !parent || disabled) return;\n    if (typeof container.animate !== \"function\") return;\n\n    if (getComputedStyle(parent).position === \"static\") {\n      parent.style.position = \"relative\";\n    }\n\n    const presses = new Set<Press>();\n    let current: Press | null = null;\n\n    const isDisabled = (): boolean =>\n      (parent as HTMLButtonElement).disabled === true ||\n      parent.getAttribute(\"aria-disabled\") === \"true\" ||\n      parent.hasAttribute(\"data-disabled\");\n\n    const setHover = (on: boolean): void => {\n      if (hoverRef.current) {\n        hoverRef.current.style.opacity = on\n          ? `${optionsRef.current.hoverOpacity}`\n          : \"0\";\n      }\n    };\n\n    const endPress = (): void => {\n      current?.release();\n      current = null;\n    };\n\n    const begin = (x?: number, y?: number): void => {\n      endPress();\n      const press = startPress(container, x, y, optionsRef.current, () =>\n        presses.delete(press as Press),\n      );\n      if (press) {\n        presses.add(press);\n        current = press;\n      }\n    };\n\n    const onEnter = (e: PointerEvent): void => {\n      if (e.pointerType !== \"touch\" && !isDisabled()) setHover(true);\n    };\n    const onLeave = (): void => {\n      setHover(false);\n      endPress();\n    };\n    const onDown = (e: PointerEvent): void => {\n      if (!e.isPrimary || e.button !== 0 || isDisabled()) return;\n      begin(e.clientX, e.clientY);\n    };\n    const onKeyDown = (e: KeyboardEvent): void => {\n      if (e.repeat || isDisabled() || (e.key !== \"Enter\" && e.key !== \" \"))\n        return;\n      begin();\n    };\n    const onKeyUp = (e: KeyboardEvent): void => {\n      if (e.key === \"Enter\" || e.key === \" \") endPress();\n    };\n\n    const listeners: [string, EventListener][] = [\n      [\"pointerenter\", onEnter as EventListener],\n      [\"pointerleave\", onLeave],\n      [\"pointerdown\", onDown as EventListener],\n      [\"pointerup\", endPress],\n      [\"pointercancel\", endPress],\n      [\"keydown\", onKeyDown as EventListener],\n      [\"keyup\", onKeyUp as EventListener],\n      [\"blur\", endPress],\n    ];\n    for (const [name, fn] of listeners) parent.addEventListener(name, fn);\n\n    return () => {\n      for (const [name, fn] of listeners) parent.removeEventListener(name, fn);\n      for (const press of [...presses]) press.cancel();\n      setHover(false);\n    };\n  }, [disabled]);\n\n  return (\n    <span\n      aria-hidden=\"true\"\n      className={className}\n      data-slot=\"ripple\"\n      ref={containerRef}\n      style={{\n        borderRadius: \"inherit\",\n        inset: 0,\n        overflow: \"hidden\",\n        pointerEvents: \"none\",\n        position: \"absolute\",\n        ...style,\n      }}\n      {...props}\n    >\n      <span\n        data-slot=\"ripple-hover\"\n        ref={hoverRef}\n        style={{\n          backgroundColor: color,\n          inset: 0,\n          opacity: 0,\n          position: \"absolute\",\n          transition: hoverDuration > 0 ? `opacity ${hoverDuration}ms` : \"none\",\n        }}\n      />\n    </span>\n  );\n}\n\nexport interface RippleProps extends React.HTMLAttributes<HTMLSpanElement> {\n  color?: string;\n  duration?: number;\n  opacity?: number;\n  hoverOpacity?: number;\n  hoverDuration?: number;\n  minimumPressDuration?: number;\n  disabled?: boolean;\n}\n\nexport { Ripple };\nexport default Ripple;\n",
      "type": "registry:lib"
    }
  ],
  "categories": [
    "lib"
  ],
  "type": "registry:lib"
}