{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glow-card",
  "title": "Glow Card",
  "description": "An Astro container that paints a pointer glow on each child.",
  "dependencies": [
    "cn"
  ],
  "registryDependencies": [
    "@gnostic/merge-styles"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/ui/glow-card/glow-card.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\n\nimport { mergeStyles } from \"../../../lib/merge-styles.ts\"\nimport { GLOW_CARD_DEFAULTS, finiteNumber, glowGradient } from \"./glow-card.ts\"\nimport type { GlowCardProps } from \"./types.ts\"\n\n/**\n * Container that paints a pointer glow on each direct child.\n * Layout classes belong here. The script reads each child's box.\n */\ntype Props = HTMLAttributes<\"div\"> & GlowCardProps\n\nconst {\n  colors,\n  proximity = GLOW_CARD_DEFAULTS.proximity,\n  spread = GLOW_CARD_DEFAULTS.spread,\n  blur = GLOW_CARD_DEFAULTS.blur,\n  opacity = GLOW_CARD_DEFAULTS.opacity,\n  class: className,\n  style: styleProp,\n  ...props\n} = Astro.props\n\n/** Props become inherited custom properties. Callers can override them with `style`. */\nconst style = mergeStyles(\n  {\n    \"--glow\": glowGradient(colors),\n    \"--spread\": String(finiteNumber(spread, GLOW_CARD_DEFAULTS.spread)),\n    \"--blur\": String(finiteNumber(blur, GLOW_CARD_DEFAULTS.blur)),\n    \"--glow-proximity\": String(\n      finiteNumber(proximity, GLOW_CARD_DEFAULTS.proximity),\n    ),\n    \"--glow-opacity\": String(finiteNumber(opacity, GLOW_CARD_DEFAULTS.opacity)),\n    \"--glow-border\": \"2px\",\n  },\n  styleProp,\n)\n---\n\n<div\n  data-slot=\"glow-card\"\n  class={cn(\"relative isolate *:data-[slot=card]:overflow-visible\", className)}\n  style={style}\n  {...props}\n>\n  <!--\n    Cloned into each child. The child's own ::before and ::after stay free.\n  -->\n  <template data-slot=\"glow-card-template\">\n    <span\n      aria-hidden=\"true\"\n      data-slot=\"glow-card-glow\"\n      class=\"pointer-events-none absolute inset-0 z-10 rounded-[inherit] before:pointer-events-none before:absolute before:inset-0 before:rounded-[inherit] before:bg-origin-border before:bg-fixed before:p-[calc(var(--glow-border)*2)] before:opacity-(--active) before:transition-opacity before:duration-1000 before:blur-[calc(var(--blur)*1px)] before:content-[''] before:[background-image:var(--glow)] after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:bg-origin-border after:bg-fixed after:p-(--glow-border) after:opacity-(--active) after:brightness-150 after:transition-opacity after:duration-1000 after:content-[''] after:[background-image:var(--glow)] motion-reduce:before:transition-none motion-reduce:after:transition-none\"\n    ></span>\n  </template>\n  <slot />\n</div>\n\n<style is:global>\n  @property --start {\n    syntax: \"<number>\";\n    inherits: true;\n    initial-value: 0;\n  }\n\n  @property --spread {\n    syntax: \"<number>\";\n    inherits: true;\n    initial-value: 60;\n  }\n\n  @property --blur {\n    syntax: \"<number>\";\n    inherits: true;\n    initial-value: 20;\n  }\n\n  /* Zero specificity so a child's position or z-index utility still wins. */\n  :where([data-slot=\"glow-card\"] > :not(template)) {\n    position: relative;\n    --active: var(--glow-opacity, 0);\n    --start: 0;\n  }\n\n  :where([data-slot=\"glow-card\"] > :not(template)):is(:hover, :focus-within) {\n    z-index: 1;\n  }\n\n  /*\n    The conic mask is the arc. Excluding the content box leaves the border.\n    Intersect keeps that arc on the border. The soft arc is wider.\n  */\n  :where([data-slot=\"glow-card-glow\"])::before,\n  :where([data-slot=\"glow-card-glow\"])::after {\n    content: \"\";\n    background-clip: border-box;\n    mask-repeat: no-repeat;\n    -webkit-mask-repeat: no-repeat;\n  }\n\n  :where([data-slot=\"glow-card-glow\"])::before {\n    /* Wide arc. The bright point sits on --start. */\n    --glow-arc: calc(var(--spread) * 1deg);\n    mask-image:\n      conic-gradient(\n        from calc((var(--start) * 1deg) - var(--glow-arc)),\n        transparent 0deg,\n        #fff var(--glow-arc),\n        transparent calc(var(--glow-arc) * 2)\n      ),\n      linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);\n    mask-clip: border-box, content-box, border-box;\n    mask-composite: intersect, exclude;\n    -webkit-mask-image:\n      conic-gradient(\n        from calc((var(--start) * 1deg) - var(--glow-arc)),\n        transparent 0deg,\n        #fff var(--glow-arc),\n        transparent calc(var(--glow-arc) * 2)\n      ),\n      linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);\n    -webkit-mask-clip: border-box, content-box, border-box;\n    -webkit-mask-composite: source-in, xor;\n  }\n\n  :where([data-slot=\"glow-card-glow\"])::after {\n    /* Narrow arc, centered on the same angle. */\n    --glow-arc: calc(var(--spread) * 0.25deg);\n    mask-image:\n      conic-gradient(\n        from calc((var(--start) * 1deg) - var(--glow-arc)),\n        transparent 0deg,\n        #fff var(--glow-arc),\n        transparent calc(var(--glow-arc) * 2)\n      ),\n      linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);\n    mask-clip: border-box, content-box, border-box;\n    mask-composite: intersect, exclude;\n    -webkit-mask-image:\n      conic-gradient(\n        from calc((var(--start) * 1deg) - var(--glow-arc)),\n        transparent 0deg,\n        #fff var(--glow-arc),\n        transparent calc(var(--glow-arc) * 2)\n      ),\n      linear-gradient(#fff 0 0), linear-gradient(#fff 0 0);\n    -webkit-mask-clip: border-box, content-box, border-box;\n    -webkit-mask-composite: source-in, xor;\n  }\n</style>\n\n<script>\n  import { isNear, pointerAngle } from \"./glow-card.ts\"\n\n  /** Containers already bound on this page. A later page load skips them. */\n  const bound = new WeakSet<HTMLElement>()\n  /** Removes listeners before the next page replaces them. */\n  const stops: Array<() => void> = []\n\n  /** Elements that cannot contain the glow layer. */\n  const voidElements = new Set([\n    \"AREA\",\n    \"BASE\",\n    \"BR\",\n    \"COL\",\n    \"EMBED\",\n    \"HR\",\n    \"IMG\",\n    \"INPUT\",\n    \"LINK\",\n    \"META\",\n    \"PARAM\",\n    \"SOURCE\",\n    \"TRACK\",\n    \"WBR\",\n  ])\n\n  /** Read one inline custom property. Blank text keeps the fallback. */\n  function readNumber(element: HTMLElement, name: string, fallback: number) {\n    const value = Number.parseFloat(element.style.getPropertyValue(name))\n    return Number.isFinite(value) ? value : fallback\n  }\n\n  /** Direct children that can show a glow. The template is not one of them. */\n  function glowChildren(container: HTMLElement) {\n    return [...container.children].filter(\n      (node): node is HTMLElement =>\n        node instanceof HTMLElement &&\n        node.tagName !== \"TEMPLATE\" &&\n        !voidElements.has(node.tagName),\n    )\n  }\n\n  /** Copy the glow layer into a child once. */\n  function ensureGlow(container: HTMLElement, child: HTMLElement) {\n    if (child.querySelector(\":scope > [data-slot='glow-card-glow']\")) return\n\n    const template = container.querySelector<HTMLTemplateElement>(\n      \":scope > template[data-slot='glow-card-template']\",\n    )\n    const layer = template?.content.firstElementChild\n    if (!layer) return\n\n    child.append(layer.cloneNode(true))\n  }\n\n  /** Aim every child from the pointer, and fade children outside proximity. */\n  function update(container: HTMLElement, event: PointerEvent) {\n    const proximity = readNumber(container, \"--glow-proximity\", 40)\n    const rest = readNumber(container, \"--glow-opacity\", 0)\n\n    for (const child of glowChildren(container)) {\n      ensureGlow(container, child)\n      const bounds = child.getBoundingClientRect()\n      const near = isNear(event.clientX, event.clientY, bounds, proximity)\n      child.style.setProperty(\"--active\", near ? \"1\" : String(rest))\n      child.style.setProperty(\n        \"--start\",\n        String(pointerAngle(event.clientX, event.clientY, bounds)),\n      )\n    }\n  }\n\n  /** Return every child to the resting opacity. Keep the last angle. */\n  function rest(container: HTMLElement) {\n    const opacity = readNumber(container, \"--glow-opacity\", 0)\n    for (const child of glowChildren(container)) {\n      child.style.setProperty(\"--active\", String(opacity))\n    }\n  }\n\n  /** Insert glow layers and follow the pointer for one container. */\n  function bind(container: HTMLElement) {\n    if (bound.has(container)) return\n    bound.add(container)\n\n    for (const child of glowChildren(container)) ensureGlow(container, child)\n\n    // The glow position follows the pointer. Reduced motion keeps the rest state.\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return\n\n    const onMove = (event: PointerEvent) => update(container, event)\n    const onLeave = () => rest(container)\n    container.addEventListener(\"pointermove\", onMove)\n    container.addEventListener(\"pointerleave\", onLeave)\n    stops.push(() => {\n      container.removeEventListener(\"pointermove\", onMove)\n      container.removeEventListener(\"pointerleave\", onLeave)\n      bound.delete(container)\n    })\n  }\n\n  /** Bind every glow container currently in the document. */\n  const start = () => {\n    document\n      .querySelectorAll<HTMLElement>(\"[data-slot='glow-card']\")\n      .forEach(bind)\n  }\n\n  start()\n  document.addEventListener(\"astro:page-load\", start)\n  document.addEventListener(\"astro:before-swap\", () => {\n    for (const stop of stops) stop()\n    stops.length = 0\n  })\n</script>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-card/glow-card.astro"
    },
    {
      "path": "packages/ui/src/components/ui/glow-card/glow-card.ts",
      "content": "/** Box used to aim the glow. Values match `DOMRect` fields the script reads. */\nexport type GlowRect = {\n    left: number\n    top: number\n    width: number\n    height: number\n}\n\n/** Palette used when a caller does not pass colors. */\nexport const DEFAULT_GLOW_CARD_COLORS: readonly string[] = [\n    'var(--foreground)',\n    'var(--primary)',\n]\n\n/** Numeric defaults. The container writes these onto its style. */\nexport const GLOW_CARD_DEFAULTS = {\n    proximity: 40,\n    spread: 60,\n    blur: 20,\n    opacity: 0,\n} as const\n\n/**\n * Keep a finite number. Any other value uses the fallback.\n */\nexport function finiteNumber(value: number | undefined, fallback: number) {\n    return typeof value === 'number' && Number.isFinite(value)\n        ? value\n        : fallback\n}\n\n/**\n * Build the conic gradient shared by every child.\n * Fixed attachment lets each child show a different slice of this image.\n */\nexport function glowGradient(colors?: readonly string[]) {\n    const given = colors\n        ?.map((color) => color.trim())\n        .filter((color) => color.length > 0)\n    const list = given && given.length > 0 ? given : DEFAULT_GLOW_CARD_COLORS\n    const stops = list.map((color, index) => {\n        const deg = (index / list.length) * 360\n        return `${color} ${deg}deg`\n    })\n    stops.push(`${list[0]} 360deg`)\n    return `conic-gradient(from 180deg at 50% 70%, ${stops.join(', ')})`\n}\n\n/**\n * True when the pointer is inside the child box, plus `proximity` on each edge.\n */\nexport function isNear(\n    x: number,\n    y: number,\n    rect: GlowRect,\n    proximity: number,\n) {\n    return (\n        x > rect.left - proximity &&\n        x < rect.left + rect.width + proximity &&\n        y > rect.top - proximity &&\n        y < rect.top + rect.height + proximity\n    )\n}\n\n/**\n * Degrees for `--start`.\n * The value follows the pointer around the child center.\n */\nexport function pointerAngle(x: number, y: number, rect: GlowRect) {\n    const centerX = rect.left + rect.width * 0.5\n    const centerY = rect.top + rect.height * 0.5\n    let angle = (Math.atan2(y - centerY, x - centerX) * 180) / Math.PI\n    if (angle < 0) angle += 360\n    return angle + 90\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-card/glow-card.ts"
    },
    {
      "path": "packages/ui/src/components/ui/glow-card/index.ts",
      "content": "export { default as GlowCard } from './glow-card.astro'\n\nexport type { GlowCardProps } from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-card/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/glow-card/types.ts",
      "content": "/**\n * Props for a container that paints a pointer glow on its children.\n *\n * Div attributes such as `class` and `style` pass through.\n * Put layout classes on this element. The glow reads each child's box.\n */\nexport interface GlowCardProps {\n    /**\n     * Colors in the shared conic glow.\n     * The first color also closes the loop.\n     * The default uses the theme foreground and primary.\n     *\n     * @default [\"var(--foreground)\", \"var(--primary)\"]\n     */\n    colors?: string[]\n    /**\n     * Distance from a child edge, in pixels, that turns the glow on.\n     *\n     * @default 40\n     */\n    proximity?: number\n    /**\n     * Width of the bright arc, in degrees.\n     *\n     * @default 60\n     */\n    spread?: number\n    /**\n     * Blur of the soft arc, in pixels.\n     *\n     * @default 20\n     */\n    blur?: number\n    /**\n     * Opacity of the glow when the pointer is outside `proximity`.\n     * `0` hides the glow until the pointer is near. `1` keeps it on.\n     *\n     * @default 0\n     */\n    opacity?: number\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-card/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "cn": "0.5.2"
    }
  },
  "docs": "https://ui.gnosticai.com/components/glow-card",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
