{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hover-glow",
  "title": "Hover Glow",
  "description": "A pointer glow that follows the cursor over any pattern.",
  "dependencies": [
    "cn"
  ],
  "registryDependencies": [
    "@gnostic/merge-styles"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/patterns/hover-glow/hover-glow.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\nimport type { HoverGlowProps } from \"./types.ts\"\n\nimport { cn } from \"cn\"\nimport { mergeStyles } from \"../../../lib/merge-styles.ts\"\n\n/**\n * Pointer glow over any pattern.\n *\n * The slot holds the pattern and the content. The glow layer paints a\n * radial gradient and follows the pointer. A mask clips that gradient\n * to a pattern shape. With no mask, the glow is a plain spotlight.\n */\ntype Props = HTMLAttributes<\"div\"> & HoverGlowProps\n\nconst {\n  glowSize = 96,\n  maskImage = \"none\",\n  maskSize = \"auto\",\n  maskPosition = \"center\",\n  glowColor = `color-mix(in oklch, var(--primary) ${maskImage === \"none\" ? 42 : 72}%, transparent)`,\n  class: className,\n  style: styleProp,\n  ...props\n} = Astro.props\n\n/** The script moves the glow by updating these variables on the glow layer. */\nconst style = mergeStyles(\n  {\n    \"--glow-color\": glowColor,\n    \"--glow-x\": \"-1000px\",\n    \"--glow-y\": \"-1000px\",\n    \"--glow-opacity\": \"0\",\n  },\n  styleProp,\n)\n\n/** Shared paint. Pattern components supply a mask. The script supplies the position. */\nconst glowStyle = {\n  opacity: \"var(--glow-opacity)\",\n  background: `radial-gradient(circle ${glowSize}px at var(--glow-x) var(--glow-y), var(--glow-color) 0%, var(--glow-color) 25%, transparent 72%)`,\n  \"mask-image\": maskImage,\n  \"mask-size\": maskSize,\n  \"mask-position\": maskPosition,\n  \"-webkit-mask-image\": maskImage,\n  \"-webkit-mask-size\": maskSize,\n  \"-webkit-mask-position\": maskPosition,\n} satisfies astroHTML.JSX.CSSProperties\n---\n\n<div data-slot=\"hover-glow-viewport\" class=\"contents\">\n  <div\n    data-slot=\"hover-glow-container\"\n    class={cn(\"relative\", className)}\n    style={style}\n    {...props}\n  >\n    <slot />\n    <div\n      aria-hidden=\"true\"\n      data-slot=\"hover-glow\"\n      class=\"pointer-events-none absolute inset-0 transition-opacity duration-200\"\n      style={glowStyle}\n    />\n  </div>\n</div>\n\n<script>\n  import { createHoverGlow, type HoverGlowController } from \"./hover-glow.ts\"\n\n  const controllers: HoverGlowController[] = []\n\n  /** Drop listeners before a new page view or a repeat init. */\n  function cleanup() {\n    for (const controller of controllers) controller.destroy()\n    controllers.length = 0\n  }\n\n  /** Bind every glow viewport currently in the document. */\n  function init() {\n    cleanup()\n    document\n      .querySelectorAll<HTMLElement>('[data-slot=\"hover-glow-viewport\"]')\n      .forEach((viewport) => {\n        controllers.push(createHoverGlow(viewport))\n      })\n  }\n\n  init()\n  document.addEventListener(\"astro:page-load\", init)\n  document.addEventListener(\"astro:before-swap\", cleanup)\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/patterns/hover-glow/hover-glow.astro"
    },
    {
      "path": "packages/ui/src/components/patterns/hover-glow/hover-glow.ts",
      "content": "export type GlowPoint = { x: number; y: number }\n\nexport type HoverGlowController = {\n    destroy: () => void\n    readonly isActive: boolean\n}\n\n/** Box whose pointer position drives the glow. */\nconst CONTAINER_SELECTOR = \"[data-slot='hover-glow-container']\"\n\n/** Layer that receives the glow CSS variables. */\nconst GLOW_SELECTOR = \"[data-slot='hover-glow']\"\n\nconst active = new WeakMap<HTMLElement, () => void>()\n\n/**\n * Bind pointer tracking for hover-glow layers inside one viewport.\n *\n * The function writes `--glow-x`, `--glow-y`, and\n * `--glow-opacity`. It does not read the pattern under the glow.\n *\n * Listeners attach to the viewport, not `document`. Call again after\n * `astro:page-load`. Call `destroy` on `astro:before-swap`.\n *\n * @param viewport - Element that contains the hover-glow containers.\n * @returns Teardown for this viewport binding.\n */\nexport function createHoverGlow(viewport: HTMLElement): HoverGlowController {\n    // Replace an earlier binding for this viewport.\n    active.get(viewport)?.()\n\n    // Latest pointer position for each container, in container pixels.\n    const points = new WeakMap<HTMLElement, GlowPoint>()\n    // Pending animation frame id for each container.\n    const frames = new WeakMap<HTMLElement, number>()\n\n    // The event target can be content inside the container.\n    const getContainer = (event: PointerEvent) => {\n        const target = event.target\n        if (!(target instanceof Element)) return null\n        const container = target.closest<HTMLElement>(CONTAINER_SELECTOR)\n        return container && viewport.contains(container) ? container : null\n    }\n\n    const getGlow = (container: HTMLElement) =>\n        container.querySelector<HTMLElement>(GLOW_SELECTOR)\n\n    const paint = (container: HTMLElement) => {\n        frames.delete(container)\n        const point = points.get(container)\n        const glow = getGlow(container)\n        if (!point || !glow) return\n        glow.style.setProperty('--glow-x', `${point.x}px`)\n        glow.style.setProperty('--glow-y', `${point.y}px`)\n    }\n\n    const hide = (container: HTMLElement) => {\n        points.delete(container)\n        const glow = getGlow(container)\n        if (!glow) return\n        glow.style.setProperty('--glow-opacity', '0')\n    }\n\n    const hideAllInViewport = () => {\n        viewport\n            .querySelectorAll<HTMLElement>(CONTAINER_SELECTOR)\n            .forEach((container) => hide(container))\n    }\n\n    const onPointerEnter = (event: PointerEvent) => {\n        const container = getContainer(event)\n        const glow = container && getGlow(container)\n        if (!container || !glow) return\n        glow.style.setProperty('--glow-opacity', '1')\n    }\n\n    const onPointerMove = (event: PointerEvent) => {\n        const container = getContainer(event)\n        if (!container) return\n        const rect = container.getBoundingClientRect()\n        points.set(container, {\n            x: event.clientX - rect.left,\n            y: event.clientY - rect.top,\n        })\n        if (frames.has(container)) return\n        frames.set(\n            container,\n            requestAnimationFrame(() => paint(container)),\n        )\n    }\n\n    const onPointerLeave = (event: PointerEvent) => {\n        const container = getContainer(event)\n        if (!container) return\n        const next = event.relatedTarget\n        // Ignore moves between elements inside the same container.\n        if (next instanceof Node && container.contains(next)) return\n        hide(container)\n    }\n\n    const onWindowBlur = () => {\n        hideAllInViewport()\n    }\n\n    // pointerenter and pointerleave do not bubble, so listen during capture.\n    viewport.addEventListener('pointerenter', onPointerEnter, true)\n    viewport.addEventListener('pointermove', onPointerMove, { passive: true })\n    viewport.addEventListener('pointerleave', onPointerLeave, true)\n    window.addEventListener('blur', onWindowBlur)\n\n    const destroy = () => {\n        viewport.removeEventListener('pointerenter', onPointerEnter, true)\n        viewport.removeEventListener('pointermove', onPointerMove)\n        viewport.removeEventListener('pointerleave', onPointerLeave, true)\n        window.removeEventListener('blur', onWindowBlur)\n        hideAllInViewport()\n        active.delete(viewport)\n    }\n\n    active.set(viewport, destroy)\n    return {\n        destroy,\n        get isActive() {\n            return active.has(viewport)\n        },\n    }\n}\n",
      "type": "registry:file",
      "target": "~/src/components/patterns/hover-glow/hover-glow.ts"
    },
    {
      "path": "packages/ui/src/components/patterns/hover-glow/index.ts",
      "content": "export { default as HoverGlow } from './hover-glow.astro'\nexport type { HoverGlowProps } from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/patterns/hover-glow/index.ts"
    },
    {
      "path": "packages/ui/src/components/patterns/hover-glow/types.ts",
      "content": "/**\n * Pointer glow that sits over any pattern or content.\n *\n * The default slot is the pattern and the content. A color layer fades in\n * under the pointer. `maskImage` clips that layer to a pattern shape.\n * Leave the mask unset for a plain spotlight.\n */\nexport type HoverGlowProps = {\n    /**\n     * CSS color of the glow.\n     * Use the color's alpha value to set the glow opacity.\n     * The default keeps the glow soft.\n     *\n     * @default \"color-mix(in oklch, var(--primary) 72%, transparent)\"\n     */\n    glowColor?: string\n    /**\n     * Radius of the glow, in pixels.\n     *\n     * @default 96\n     */\n    glowSize?: number\n    /**\n     * CSS `mask-image` for the glow layer.\n     * Use a repeating mask so the glow shows only inside a pattern shape.\n     *\n     * @default \"none\"\n     */\n    maskImage?: string\n    /**\n     * CSS `mask-size` for the glow layer.\n     *\n     * @default \"auto\"\n     */\n    maskSize?: string\n    /**\n     * CSS `mask-position` for the glow layer.\n     *\n     * @default \"center\"\n     */\n    maskPosition?: string\n}\n",
      "type": "registry:file",
      "target": "~/src/components/patterns/hover-glow/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "cn": "0.5.2"
    }
  },
  "docs": "https://ui.gnosticai.com/patterns/hover-glow",
  "categories": [
    "patterns"
  ],
  "type": "registry:component"
}
