{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glow-button",
  "title": "Glow Button",
  "description": "An Astro button with an animated glow behind the control.",
  "dependencies": [
    "cn",
    "motion"
  ],
  "registryDependencies": [
    "@gnostic/button",
    "@gnostic/merge-styles"
  ],
  "files": [
    {
      "path": "packages/ui/src/components/ui/glow-button/glow-animation.ts",
      "content": "import type { AnimationOptions, DOMKeyframesDefinition } from 'motion'\n\nimport type { GlowMode } from './types.ts'\n\n/** Palette used when a caller does not pass colors. */\nexport const DEFAULT_GLOW_COLORS: string[] = [\n    '#FF5733', // red\n    '#33FF57', // green\n    '#3357FF', // blue\n    '#F1C40F', // yellow\n]\n\n/** Modes the shell accepts from a data attribute. */\nexport const GLOW_MODES = [\n    'rotate',\n    'pulse',\n    'breathe',\n    'colorShift',\n    'flowHorizontal',\n    'static',\n] as const satisfies readonly GlowMode[]\n\n/** Keyframes plus the options for `animate(element, keyframes, options)`. */\nexport type GlowAnimation = {\n    keyframes: DOMKeyframesDefinition\n    options?: AnimationOptions\n}\n\ntype GlowAnimationInput = {\n    colors: string[]\n    mode: GlowMode\n    scale: number\n    duration: number\n}\n\n/**\n * Build the glow keyframes for one mode.\n * The React port kept `transition` on the animate object.\n * The element API takes keyframes and options as separate arguments.\n */\nexport function buildGlowAnimation({\n    colors = DEFAULT_GLOW_COLORS,\n    mode,\n    scale,\n    duration,\n}: GlowAnimationInput): GlowAnimation {\n    const cycle = duration > 0 ? duration : 5\n    const loop: AnimationOptions = {\n        duration: cycle,\n        ease: 'linear',\n        repeat: Infinity,\n    }\n    const mirror: AnimationOptions = {\n        ...loop,\n        repeatType: 'mirror',\n    }\n    const list = colors.join(', ')\n\n    switch (mode) {\n        case 'rotate':\n            return {\n                keyframes: {\n                    background: [\n                        `conic-gradient(from 0deg at 50% 50%, ${list})`,\n                        `conic-gradient(from 360deg at 50% 50%, ${list})`,\n                    ],\n                },\n                options: loop,\n            }\n        case 'pulse':\n            return {\n                keyframes: {\n                    background: colors.map(\n                        (color) =>\n                            `radial-gradient(circle at 50% 50%, ${color} 0%, transparent 100%)`,\n                    ),\n                    opacity: [0.5, 0.8, 0.5],\n                    scale: [scale, scale * 1.1, scale],\n                } as DOMKeyframesDefinition,\n                options: mirror,\n            }\n        case 'breathe':\n            return {\n                keyframes: {\n                    background: colors.map(\n                        (color) =>\n                            `radial-gradient(circle at 50% 50%, ${color} 0%, transparent 100%)`,\n                    ),\n                    scale: [scale, scale * 1.05, scale],\n                } as DOMKeyframesDefinition,\n                options: mirror,\n            }\n        case 'colorShift':\n            return {\n                keyframes: {\n                    background: colors.map((color, index) => {\n                        const next = colors[(index + 1) % colors.length]!\n                        return `conic-gradient(from 0deg at 50% 50%, ${color} 0%, ${next} 50%, ${color} 100%)`\n                    }),\n                },\n                options: mirror,\n            }\n        case 'flowHorizontal':\n            return {\n                keyframes: {\n                    background: colors.map((color, index) => {\n                        const next = colors[(index + 1) % colors.length]!\n                        return `linear-gradient(to right, ${color}, ${next})`\n                    }),\n                },\n                options: mirror,\n            }\n        case 'static':\n            return {\n                keyframes: {\n                    background: `linear-gradient(to right, ${list})`,\n                },\n            }\n    }\n}\n\n/**\n * First painted frame.\n * The effect renders this before the shell script starts.\n */\nexport function initialGlowBackground(\n    mode: GlowMode,\n    colors: string[],\n): string {\n    const background = buildGlowAnimation({\n        colors,\n        duration: 1,\n        mode,\n        scale: 1,\n    }).keyframes.background\n\n    if (Array.isArray(background)) {\n        const first = background[0]\n        return typeof first === 'string' ? first : ''\n    }\n\n    return typeof background === 'string' ? background : ''\n}\n\n/** Read a mode attribute. Unknown text falls back to rotate. */\nexport function parseGlowMode(value: string | null | undefined): GlowMode {\n    if (value && (GLOW_MODES as readonly string[]).includes(value)) {\n        return value as GlowMode\n    }\n\n    return 'rotate'\n}\n\n/** Read a colors attribute. The value is a JSON string array. */\nexport function parseGlowColors(value: string | null | undefined): string[] {\n    if (!value) return [...DEFAULT_GLOW_COLORS]\n\n    try {\n        const parsed: unknown = JSON.parse(value)\n\n        if (\n            Array.isArray(parsed) &&\n            parsed.length > 0 &&\n            parsed.every((color) => typeof color === 'string' && color !== '')\n        ) {\n            return parsed\n        }\n    } catch {\n        // Attribute text that is not JSON keeps the default palette.\n    }\n\n    return [...DEFAULT_GLOW_COLORS]\n}\n\n/** Read a numeric data attribute. Blank or invalid text keeps the fallback. */\nexport function parseGlowNumber(\n    value: string | null | undefined,\n    fallback: number,\n): number {\n    if (value == null || value.trim() === '') return fallback\n\n    const parsed = Number(value)\n\n    return Number.isFinite(parsed) ? parsed : fallback\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-button/glow-animation.ts"
    },
    {
      "path": "packages/ui/src/components/ui/glow-button/glow-button-effect.astro",
      "content": "---\nimport type { HTMLAttributes } from \"astro/types\"\n\nimport { cn } from \"cn\"\n\nimport { mergeStyles } from \"../../../lib/merge-styles.ts\"\nimport { DEFAULT_GLOW_COLORS, initialGlowBackground } from \"./glow-animation.ts\"\nimport type { GlowBlur, GlowButtonEffectProps } from \"./types.ts\"\n\n/** Div attributes pass through. Glow fields come from `GlowButtonEffectProps`. */\ntype Props = HTMLAttributes<\"div\"> & GlowButtonEffectProps\n\n/**\n * Named blur steps. Each value is a full Tailwind class so the build can see it.\n * A number uses an inline filter because a built class name cannot include the pixel value.\n */\nconst BLUR_CLASS = {\n  softest: \"blur-xs\",\n  soft: \"blur-sm\",\n  medium: \"blur-md\",\n  strong: \"blur-lg\",\n  stronger: \"blur-xl\",\n  strongest: \"blur-2xl\",\n  none: \"blur-none\",\n} as const satisfies Record<Exclude<GlowBlur, number>, string>\n\n/** Tailwind blur class for a named step. A pixel blur returns no class. */\nfunction blurClass(blur: GlowBlur) {\n  if (typeof blur === \"number\") return undefined\n  return BLUR_CLASS[blur]\n}\n\nconst {\n  colors = DEFAULT_GLOW_COLORS,\n  mode = \"rotate\",\n  blur = \"strong\",\n  scale = 1,\n  duration = 5,\n  class: className,\n  style: styleProp,\n  ...props\n} = Astro.props\n\nconst style = mergeStyles(\n  {\n    \"--glow-scale\": String(scale),\n    background: initialGlowBackground(mode, colors),\n    ...(typeof blur === \"number\" ? { filter: `blur(${blur}px)` } : {}),\n  },\n  styleProp,\n)\n---\n\n<div\n  data-slot=\"glow-button-effect\"\n  data-mode={mode}\n  data-colors={JSON.stringify(colors)}\n  data-duration={duration}\n  data-scale={scale}\n  class={cn(\n    \"pointer-events-none absolute inset-0 size-full scale-(--glow-scale) transform-gpu rounded-lg will-change-transform\",\n    blurClass(blur),\n    className,\n  )}\n  style={style}\n  {...props}\n/>\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-button/glow-button-effect.astro"
    },
    {
      "path": "packages/ui/src/components/ui/glow-button/glow-button.astro",
      "content": "---\nimport type { HTMLTag, Polymorphic } from \"astro/types\"\n\nimport { cn } from \"cn\"\n\nimport { Button } from \"../button/index.ts\"\nimport { DEFAULT_GLOW_COLORS } from \"./glow-animation.ts\"\nimport GlowButtonEffect from \"./glow-button-effect.astro\"\nimport type { GlowButtonProps } from \"./types.ts\"\n\n/**\n * Button attributes pass through to the inner button.\n * `href` selects an anchor when `as` is omitted.\n */\ntype Props<Tag extends HTMLTag = \"button\"> = Polymorphic<{ as: Tag }> &\n  GlowButtonProps\n\n/**\n * True when the caller disabled the control.\n * An empty string still counts. `false` does not.\n */\nfunction disabledProp(props: object) {\n  if (!(\"disabled\" in props)) return false\n  const value = (props as { disabled?: unknown }).disabled\n  return value !== false && value != null\n}\n\nconst {\n  as: Tag = \"href\" in Astro.props ? \"a\" : \"button\",\n  class: className,\n  variant = \"default\",\n  size = \"default\",\n  withLoader = false,\n  mode = \"rotate\",\n  colors = DEFAULT_GLOW_COLORS,\n  blur = \"strong\",\n  duration = 5,\n  glowScale = 1,\n  ...props\n} = Astro.props\n\nconst isDisabled = disabledProp(Astro.props)\nconst resolvedGlowScale = Number.isFinite(glowScale) ? glowScale : 1\n\nconst elementProps: Record<string, unknown> = {\n  ...(Tag === \"button\" ? { type: \"button\" as const } : {}),\n  ...props,\n  ...(isDisabled && Tag !== \"button\"\n    ? { \"aria-disabled\": \"true\", tabindex: -1 }\n    : {}),\n}\n\n// Anchors have no disabled attribute. The shell blocks the link instead.\nif (Tag !== \"button\") delete elementProps.disabled\n---\n\n<div\n  data-slot=\"glow-button\"\n  data-glow-scale={resolvedGlowScale}\n  data-disabled={isDisabled ? \"true\" : undefined}\n  class={cn(\n    \"relative inline-flex\",\n    isDisabled && \"pointer-events-none opacity-50\",\n  )}\n>\n  <div\n    aria-hidden=\"true\"\n    data-slot=\"glow-button-scale\"\n    class=\"pointer-events-none absolute inset-0\"\n    style={`scale: ${resolvedGlowScale}`}\n  >\n    <GlowButtonEffect\n      colors={colors}\n      mode={mode}\n      blur={blur}\n      duration={duration}\n      scale={1}\n    />\n  </div>\n  <Button\n    as={Tag}\n    variant={variant}\n    size={size}\n    withLoader={withLoader}\n    class={cn(\"relative\", isDisabled && \"disabled:opacity-100\", className)}\n    {...elementProps}\n  >\n    <slot />\n    {Astro.slots.has(\"button-loading-indicator\") && (\n      <slot name=\"button-loading-indicator\" slot=\"button-loading-indicator\" />\n    )}\n  </Button>\n</div>\n\n<script>\n  import { animate, hover } from \"motion\"\n\n  import {\n    buildGlowAnimation,\n    parseGlowColors,\n    parseGlowMode,\n    parseGlowNumber,\n  } from \"./glow-animation.ts\"\n\n  /** Roots already bound on this page. A later page load skips them. */\n  const bound = new WeakSet<HTMLElement>()\n  /** Stops animations and hover listeners before the next page replaces them. */\n  const stops: Array<() => void> = []\n\n  /** Spring used for the hover scale. Matches the original motion transition. */\n  const hoverSpring = { type: \"spring\" as const, stiffness: 300, damping: 20 }\n\n  /**\n   * Start the mode animation and the hover scale for one shell.\n   * The effect element holds the mode, colors, duration, and layer scale.\n   * The shell holds the hover scale.\n   */\n  function bindGlowButton(root: HTMLElement) {\n    if (bound.has(root)) return\n\n    const scaleLayer = root.querySelector<HTMLElement>(\n      \":scope > [data-slot='glow-button-scale']\",\n    )\n    const effect = scaleLayer?.querySelector<HTMLElement>(\n      \":scope > [data-slot='glow-button-effect']\",\n    )\n\n    if (!scaleLayer || !effect) return\n\n    bound.add(root)\n\n    const colors = parseGlowColors(effect.dataset.colors)\n    const mode = parseGlowMode(effect.dataset.mode)\n    const duration = parseGlowNumber(effect.dataset.duration, 5)\n    const scale = parseGlowNumber(effect.dataset.scale, 1)\n    const glowScale = parseGlowNumber(root.dataset.glowScale, 1)\n    const reduced = window.matchMedia(\n      \"(prefers-reduced-motion: reduce)\",\n    ).matches\n\n    // A static frame is already painted. Reduced motion keeps that frame.\n    if (!reduced && mode !== \"static\") {\n      const animation = buildGlowAnimation({ colors, duration, mode, scale })\n      const playback = animate(effect, animation.keyframes, animation.options)\n      stops.push(() => playback.stop())\n    }\n\n    if (reduced || root.dataset.disabled === \"true\") return\n\n    const stopHover = hover(root, () => {\n      animate(scaleLayer, { scale: glowScale * 1.05 }, hoverSpring)\n      return () => {\n        animate(scaleLayer, { scale: glowScale }, hoverSpring)\n      }\n    })\n    stops.push(stopHover)\n  }\n\n  /** Bind every shell currently in the document. */\n  const start = () => {\n    document\n      .querySelectorAll<HTMLElement>(\"[data-slot='glow-button']\")\n      .forEach(bindGlowButton)\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-button/glow-button.astro"
    },
    {
      "path": "packages/ui/src/components/ui/glow-button/index.ts",
      "content": "export { default as GlowButton } from './glow-button.astro'\nexport { default as GlowButtonEffect } from './glow-button-effect.astro'\n\nexport type {\n    GlowBlur,\n    GlowButtonEffectProps,\n    GlowButtonProps,\n    GlowMode,\n} from './types.ts'\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-button/index.ts"
    },
    {
      "path": "packages/ui/src/components/ui/glow-button/types.ts",
      "content": "import type { ButtonProps } from '../button/types.ts'\n\n/**\n * How the glow layer moves.\n * `static` paints one gradient and does not loop.\n */\nexport type GlowMode =\n    | 'rotate'\n    | 'pulse'\n    | 'breathe'\n    | 'colorShift'\n    | 'flowHorizontal'\n    | 'static'\n\n/**\n * Blur of the glow layer.\n * A number is a pixel radius. A name selects a Tailwind blur step.\n */\nexport type GlowBlur =\n    | number\n    | 'softest'\n    | 'soft'\n    | 'medium'\n    | 'strong'\n    | 'stronger'\n    | 'strongest'\n    | 'none'\n\n/**\n * Props for the painted glow layer.\n * The shell reads these values and runs the animation.\n * Div attributes such as `class` and `style` pass through.\n */\nexport interface GlowButtonEffectProps {\n    /**\n     * Glow colors. Use at least two colors for a visible shift.\n     * @default [\"#FF5733\", \"#33FF57\", \"#3357FF\", \"#F1C40F\"]\n     */\n    colors?: string[]\n    /**\n     * Glow animation mode.\n     * @default \"rotate\"\n     */\n    mode?: GlowMode\n    /**\n     * Blur strength of the glow layer.\n     * @default \"strong\"\n     */\n    blur?: GlowBlur\n    /**\n     * Scale of this layer before the shell hover scale.\n     * Pulse and breathe animate around this value.\n     * @default 1\n     */\n    scale?: number\n    /**\n     * Duration of one animation cycle, in seconds.\n     * @default 5\n     */\n    duration?: number\n}\n\n/**\n * Props for a button with an animated glow behind it.\n * Button attributes such as `class`, `disabled`, `type`, and `href` pass through.\n */\nexport interface GlowButtonProps extends ButtonProps {\n    /**\n     * Glow animation mode.\n     * @default \"rotate\"\n     */\n    mode?: GlowMode\n    /**\n     * Glow colors. Use at least two colors for a visible shift.\n     * A theme token such as `var(--primary)` follows the active preset.\n     * @default [\"#FF5733\", \"#33FF57\", \"#3357FF\", \"#F1C40F\"]\n     */\n    colors?: string[]\n    /**\n     * Blur strength of the glow layer.\n     * @default \"strong\"\n     */\n    blur?: GlowBlur\n    /**\n     * Duration of one animation cycle, in seconds.\n     * @default 5\n     */\n    duration?: number\n    /**\n     * Scale of the glow layer relative to the button.\n     * Values above 1 spread the glow past the button edges.\n     * @default 1\n     */\n    glowScale?: number\n}\n",
      "type": "registry:file",
      "target": "~/src/components/ui/glow-button/types.ts"
    }
  ],
  "meta": {
    "framework": "astro",
    "source": "@gnostic/ui",
    "testedDependencies": {
      "cn": "0.5.2",
      "motion": "^14.6.0"
    }
  },
  "docs": "https://ui.gnosticai.com/components/glow-button",
  "categories": [
    "ui"
  ],
  "type": "registry:ui"
}
