{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic",
  "title": "Magnetic",
  "description": "Wrapper that pulls its content toward the pointer for a magnetic effect.",
  "dependencies": [
    "@vllnt/ui@^0.2.1"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/default/magnetic/magnetic.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@vllnt/ui\";\n\n/** Props for {@link Magnetic}. */\nexport type MagneticProps = React.ComponentPropsWithoutRef<\"div\"> & {\n  /** Fraction of the pointer offset applied as pull. Defaults to `0.4`. */\n  strength?: number;\n};\n\nfunction usePrefersReducedMotion(): boolean {\n  const [reduced, setReduced] = React.useState(false);\n\n  React.useEffect(() => {\n    if (\n      typeof window === \"undefined\" ||\n      typeof window.matchMedia !== \"function\"\n    ) {\n      return;\n    }\n\n    const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    const onChange = (): void => {\n      setReduced(query.matches);\n    };\n\n    onChange();\n    query.addEventListener(\"change\", onChange);\n\n    return () => {\n      query.removeEventListener(\"change\", onChange);\n    };\n  }, []);\n\n  return reduced;\n}\n\n/**\n * Wrapper that drifts its content toward the pointer, then snaps back.\n *\n * Respects `prefers-reduced-motion`: the content stays put.\n *\n * @example\n * ```tsx\n * <Magnetic><img src=\"/logo.svg\" alt=\"logo\" /></Magnetic>\n * ```\n */\nexport const Magnetic = ({\n  children,\n  className,\n  ref,\n  strength = 0.4,\n  style,\n  ...props\n}: MagneticProps & { ref?: React.Ref<HTMLDivElement> }) => {\n  const reduced = usePrefersReducedMotion();\n  const [transform, setTransform] = React.useState<string>();\n\n  const handlePointerMove = (\n    event: React.PointerEvent<HTMLDivElement>,\n  ): void => {\n    if (reduced) {\n      return;\n    }\n\n    const bounds = event.currentTarget.getBoundingClientRect();\n    const offsetX = (event.clientX - bounds.left - bounds.width / 2) * strength;\n    const offsetY = (event.clientY - bounds.top - bounds.height / 2) * strength;\n\n    setTransform(`translate(${offsetX}px, ${offsetY}px)`);\n  };\n\n  return (\n    <div\n      className={cn(\n        \"transition-transform duration-200 ease-out will-change-transform\",\n        className,\n      )}\n      onPointerLeave={() => {\n        setTransform(undefined);\n      }}\n      onPointerMove={handlePointerMove}\n      ref={ref}\n      style={{ transform, ...style }}\n      {...props}\n    >\n      {children}\n    </div>\n  );\n};\nMagnetic.displayName = \"Magnetic\";\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component",
  "version": "0.2.1",
  "stability": "stable"
}
