{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "glass-toaster",
  "title": "Glass Toaster",
  "description": "Frosted toasts that stack, fan out, swipe away, and burn down like an ember.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "@animate-ui/icons-x"
  ],
  "files": [
    {
      "path": "components/ui/glass-toaster.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimateIcon } from \"@/components/animate-ui/icons/icon\"\nimport { X } from \"@/components/animate-ui/icons/x\"\nimport {\n  AnimatePresence,\n  animate,\n  motion,\n  useMotionValue,\n  useReducedMotion,\n  useTransform,\n  type AnimationPlaybackControls,\n} from \"motion/react\"\n\nimport { spring } from \"@/lib/afterglow\"\nimport { cn } from \"@/lib/utils\"\n\ntype ToastOptions = {\n  id?: string\n  description?: React.ReactNode\n  icon?: React.ReactNode\n  /** milliseconds, Infinity keeps the toast until dismissed */\n  duration?: number\n  action?: { label: string; onClick: () => void }\n}\n\ntype ToastItem = Omit<ToastOptions, \"id\"> & {\n  id: string\n  title: React.ReactNode\n}\n\n// a tiny store, so toast() can be called from anywhere\nlet toasts: ToastItem[] = []\nlet count = 0\nconst listeners = new Set<() => void>()\nconst emit = () => listeners.forEach((listener) => listener())\nconst subscribe = (listener: () => void) => {\n  listeners.add(listener)\n  return () => {\n    listeners.delete(listener)\n  }\n}\nconst getSnapshot = () => toasts\nconst empty: ToastItem[] = []\n\nfunction toast(title: React.ReactNode, { id, ...options }: ToastOptions = {}) {\n  const key = id ?? `toast-${++count}`\n  toasts = [\n    { id: key, title, ...options },\n    ...toasts.filter((item) => item.id !== key),\n  ].slice(0, 20)\n  emit()\n  return key\n}\n\ntoast.dismiss = (id?: string) => {\n  toasts = id ? toasts.filter((item) => item.id !== id) : []\n  emit()\n}\n\nconst positions = {\n  \"top-left\": \"top-6 left-6\",\n  \"top-center\": \"top-6 left-1/2 -translate-x-1/2\",\n  \"top-right\": \"top-6 right-6\",\n  \"bottom-left\": \"bottom-6 left-6\",\n  \"bottom-center\": \"bottom-6 left-1/2 -translate-x-1/2\",\n  \"bottom-right\": \"bottom-6 right-6\",\n}\n\ntype GlassToasterProps = Omit<React.ComponentProps<\"section\">, \"children\"> & {\n  position?: keyof typeof positions\n  /** how many toasts show in the collapsed stack */\n  visible?: number\n  gap?: number\n}\n\nconst PEEK = 14\n\nfunction GlassToaster({\n  position = \"bottom-right\",\n  visible = 3,\n  gap = 10,\n  className,\n  ...props\n}: GlassToasterProps) {\n  const items = React.useSyncExternalStore(subscribe, getSnapshot, () => empty)\n  const [hovered, setHovered] = React.useState(false)\n  const [hidden, setHidden] = React.useState(false)\n  const [heights, setHeights] = React.useState<Record<string, number>>({})\n  const expanded = hovered && items.length > 0\n  const top = position.startsWith(\"top\")\n  const direction = top ? 1 : -1\n\n  React.useEffect(() => {\n    const update = () => setHidden(document.visibilityState === \"hidden\")\n    document.addEventListener(\"visibilitychange\", update)\n    return () => document.removeEventListener(\"visibilitychange\", update)\n  }, [])\n\n  const report = React.useCallback((id: string, height: number) => {\n    setHeights((prev) => (prev[id] === height ? prev : { ...prev, [id]: height }))\n  }, [])\n\n  const front = heights[items[0]?.id] ?? 0\n  const shown = items.slice(0, visible)\n  const stackHeight = expanded\n    ? shown.reduce((sum, item) => sum + (heights[item.id] ?? 0), 0) +\n      gap * Math.max(shown.length - 1, 0)\n    : front + PEEK * Math.max(shown.length - 1, 0)\n\n  // expanded, each toast sits above the ones that arrived after it\n  const offsets: number[] = []\n  items.forEach((item, index) => {\n    offsets.push(\n      index === 0 ? 0 : offsets[index - 1] + (heights[items[index - 1].id] ?? 0) + gap\n    )\n  })\n\n  return (\n    <section\n      data-slot=\"glass-toaster\"\n      aria-label=\"Notifications\"\n      className={cn(\n        \"fixed z-50 w-[min(356px,calc(100vw-3rem))]\",\n        positions[position],\n        className\n      )}\n      onPointerEnter={() => setHovered(true)}\n      onPointerLeave={() => setHovered(false)}\n      onFocus={() => setHovered(true)}\n      onBlur={(event) => {\n        if (!event.currentTarget.contains(event.relatedTarget)) setHovered(false)\n      }}\n      {...props}\n    >\n      <ol\n        aria-live=\"polite\"\n        aria-relevant=\"additions text\"\n        className=\"relative\"\n        style={{ height: stackHeight }}\n      >\n        <AnimatePresence initial={false}>\n          {items.map((item, index) => {\n            const height = heights[item.id]\n            const y = expanded ? offsets[index] : index * PEEK\n            return (\n              <ToastCard\n                key={item.id}\n                item={item}\n                index={index}\n                y={direction * y}\n                direction={direction}\n                anchor={top ? \"top\" : \"bottom\"}\n                expanded={expanded}\n                hiddenInStack={index >= visible}\n                height={!expanded && index > 0 ? front : height}\n                paused={expanded || hidden || index >= visible}\n                onHeight={report}\n              />\n            )\n          })}\n        </AnimatePresence>\n      </ol>\n    </section>\n  )\n}\n\ntype ToastCardProps = {\n  item: ToastItem\n  index: number\n  y: number\n  direction: number\n  anchor: \"top\" | \"bottom\"\n  expanded: boolean\n  hiddenInStack: boolean\n  height: number | undefined\n  paused: boolean\n  onHeight: (id: string, height: number) => void\n}\n\nfunction ToastCard({\n  item,\n  index,\n  y,\n  direction,\n  anchor,\n  expanded,\n  hiddenInStack,\n  height,\n  paused,\n  onHeight,\n}: ToastCardProps) {\n  const reduceMotion = useReducedMotion()\n  const contentRef = React.useRef<HTMLDivElement>(null)\n  const life = useMotionValue(1)\n  const timer = React.useRef<AnimationPlaybackControls>(null)\n  const x = useMotionValue(0)\n  const swipeFade = useTransform(x, [-240, 0, 240], [0, 1, 0])\n  const duration = item.duration ?? 4000\n  const collapsedBehind = !expanded && index > 0\n\n  React.useLayoutEffect(() => {\n    const node = contentRef.current\n    if (!node) return\n    onHeight(item.id, node.offsetHeight)\n    const observer = new ResizeObserver(() => onHeight(item.id, node.offsetHeight))\n    observer.observe(node)\n    return () => observer.disconnect()\n  }, [item.id, onHeight])\n\n  // the progress line burns down like an ember, and the toast leaves when it's out\n  React.useEffect(() => {\n    if (!Number.isFinite(duration)) return\n    timer.current = animate(life, 0, {\n      duration: duration / 1000,\n      ease: \"linear\",\n      onComplete: () => toast.dismiss(item.id),\n    })\n    timer.current.pause()\n    return () => timer.current?.stop()\n  }, [duration, item.id, life])\n\n  React.useEffect(() => {\n    if (paused) timer.current?.pause()\n    else timer.current?.play()\n  }, [paused])\n\n  const scale = expanded ? 1 : 1 - Math.min(index, 3) * 0.05\n\n  return (\n    <motion.li\n      className={cn(\n        \"absolute inset-x-0\",\n        anchor === \"top\" ? \"top-0\" : \"bottom-0\",\n        hiddenInStack && \"pointer-events-none\"\n      )}\n      style={{ zIndex: 100 - index }}\n      initial={{ opacity: 0, y: -direction * 24, scale: 0.95 }}\n      animate={{\n        opacity: hiddenInStack ? 0 : 1,\n        y,\n        scale,\n        height: height ?? \"auto\",\n      }}\n      exit={{\n        opacity: 0,\n        scale: 0.95,\n        transition: { duration: 0.15, ease: \"easeIn\" },\n      }}\n      transition={reduceMotion ? { duration: 0 } : spring(\"soft\")}\n    >\n      <motion.div\n        className=\"relative h-full overflow-hidden rounded-2xl bg-card/80 shadow-glass backdrop-blur-xl backdrop-saturate-150\"\n        style={{ x, opacity: swipeFade }}\n        drag={reduceMotion ? false : \"x\"}\n        dragMomentum={false}\n        onDragEnd={(_, info) => {\n          const out = Math.abs(info.offset.x) > 90 || Math.abs(info.velocity.x) > 600\n          if (out) {\n            const side = Math.sign(info.offset.x || info.velocity.x)\n            animate(x, side * 400, { duration: 0.2, ease: \"easeOut\" }).then(() =>\n              toast.dismiss(item.id)\n            )\n          } else {\n            animate(x, 0, spring(\"snappy\"))\n          }\n        }}\n      >\n        <span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-x-0 top-0 h-8 bg-linear-to-b from-gloss-highlight/40 to-transparent\"\n        />\n        <motion.div\n          ref={contentRef}\n          className=\"relative flex gap-3 p-4 pr-10\"\n          animate={{ opacity: collapsedBehind ? 0 : 1 }}\n          transition={{ duration: 0.15 }}\n        >\n          {item.icon && (\n            <span className=\"relative mt-0.5 grid size-5 shrink-0 place-items-center text-glow [&>svg]:size-4\">\n              <span className=\"absolute inset-0 rounded-full bg-glow/30 blur-sm\" />\n              <span className=\"relative\">{item.icon}</span>\n            </span>\n          )}\n          <div className=\"min-w-0 flex-1\">\n            <p className=\"text-sm font-medium text-foreground\">{item.title}</p>\n            {item.description && (\n              <p className=\"mt-0.5 text-[13px] text-muted-foreground\">\n                {item.description}\n              </p>\n            )}\n            {item.action && (\n              <button\n                type=\"button\"\n                className=\"mt-3 h-7 rounded-full bg-glow px-3 text-xs font-medium text-glow-foreground shadow-gloss outline-none transition-transform duration-150 ease-out motion-reduce:transition-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring motion-safe:active:scale-96\"\n                onClick={() => {\n                  item.action?.onClick()\n                  toast.dismiss(item.id)\n                }}\n              >\n                {item.action.label}\n              </button>\n            )}\n          </div>\n          <AnimateIcon animateOnHover asChild>\n          <button\n            type=\"button\"\n            aria-label=\"Dismiss notification\"\n            className=\"absolute top-3 right-3 grid size-6 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring\"\n            onClick={() => toast.dismiss(item.id)}\n          >\n            <X aria-hidden className=\"size-3.5\" />\n          </button>\n          </AnimateIcon>\n        </motion.div>\n        {Number.isFinite(duration) && (\n          <motion.span\n            aria-hidden\n            className=\"absolute inset-x-4 bottom-0 h-px origin-left bg-linear-to-r from-glow-3/0 via-glow-2 to-glow shadow-[0_0_8px_var(--glow)]\"\n            style={{ scaleX: life }}\n          />\n        )}\n      </motion.div>\n    </motion.li>\n  )\n}\n\nexport { GlassToaster, toast, type GlassToasterProps, type ToastOptions }\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/afterglow.ts",
      "content": "import type { CSSProperties } from \"react\"\nimport type { TargetAndTransition, Transition } from \"motion/react\"\n\n// shared spring presets, every component picks from these\nexport const springs = {\n  snappy: { stiffness: 520, damping: 34, mass: 0.6 },\n  soft: { stiffness: 260, damping: 26, mass: 0.8 },\n  glide: { stiffness: 120, damping: 20, mass: 1 },\n} as const\n\nexport type SpringName = keyof typeof springs\n\nexport function spring(name: SpringName): Transition {\n  return { type: \"spring\", ...springs[name] }\n}\n\n// how a glow fades once its source moves away: slow, with a long tail\nexport const afterglow = {\n  linger: 0.9,\n  ease: [0.22, 1, 0.36, 1],\n} as const satisfies { linger: number; ease: Transition[\"ease\"] }\n\n// paints only the padding ring of an element, used for glowing borders\nexport const ringMask: CSSProperties = {\n  WebkitMask:\n    \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n}\n\n// small icon gestures, played when a control is pressed or selected\nexport const iconGestures = {\n  pop: { scale: [1, 1.2, 1] },\n  ring: { rotate: [0, -18, 14, -9, 4, 0], scale: [1, 1.12, 1] },\n  // a gear looks the same after half a turn, so it can rest there and snap back unseen\n  turn: { rotate: [0, 180], scale: [1, 1.12, 1] },\n  hop: { y: [0, -3, 0], scale: [1, 1.1, 1] },\n  nudge: { x: [0, 2.5, 0], scale: [1, 1.1, 1] },\n} satisfies Record<string, TargetAndTransition>\n\nexport type IconGesture = keyof typeof iconGestures\n\n// leaving a gesture is instant: every gesture already ends at, or looks like, its resting pose\nexport const iconRest: TargetAndTransition = { scale: 1, rotate: 0, x: 0, y: 0, transition: { duration: 0 } }\n",
      "type": "registry:lib"
    }
  ],
  "cssVars": {
    "theme": {
      "color-glow": "var(--glow)",
      "color-glow-foreground": "var(--glow-foreground)",
      "color-glow-2": "var(--glow-2)",
      "color-glow-3": "var(--glow-3)",
      "color-glass": "var(--glass)",
      "color-gloss-highlight": "var(--gloss-highlight)",
      "shadow-gloss": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -1px 0 0 var(--gloss-shade), 0 0 0 1px var(--gloss-edge), 0 1px 2px 0 var(--gloss-depth), 0 4px 12px -4px var(--gloss-depth)",
      "shadow-glass": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -10px 24px -18px var(--gloss-shade), inset 0 0 0 1px var(--gloss-edge), 0 2px 6px -1px var(--gloss-depth), 0 18px 40px -12px var(--gloss-depth)",
      "shadow-well": "inset 0 1px 3px 0 var(--gloss-depth), inset 0 0 0 1px var(--gloss-edge), 0 1px 0 0 var(--gloss-highlight)"
    },
    "light": {
      "glow": "oklch(0.7 0.19 45)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.64 0.22 12)",
      "glow-3": "oklch(0.56 0.21 300)",
      "glass": "oklch(1 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 95%)",
      "gloss-shade": "oklch(0.3 0.03 285 / 10%)",
      "gloss-depth": "oklch(0.32 0.03 285 / 20%)",
      "gloss-edge": "oklch(0.22 0.02 285 / 10%)",
      "liquid-tint": "oklch(1 0 0 / 18%)",
      "liquid-fallback": "oklch(1 0 0 / 55%)",
      "liquid-rim": "oklch(1 0 0 / 95%)",
      "liquid-edge": "oklch(0.2 0.02 285 / 10%)",
      "liquid-shadow": "oklch(0.22 0.02 285 / 26%)",
      "liquid-glow": "oklch(1 0 0 / 55%)",
      "liquid-shade": "oklch(0.25 0.03 285 / 14%)"
    },
    "dark": {
      "glow": "oklch(0.8 0.16 55)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.7 0.2 15)",
      "glow-3": "oklch(0.65 0.2 300)",
      "glass": "oklch(0.19 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 16%)",
      "gloss-shade": "oklch(0 0 0 / 30%)",
      "gloss-depth": "oklch(0.04 0 0 / 60%)",
      "gloss-edge": "oklch(1 0 0 / 9%)",
      "liquid-tint": "oklch(0.2 0 0 / 22%)",
      "liquid-fallback": "oklch(0.2 0 0 / 45%)",
      "liquid-rim": "oklch(1 0 0 / 60%)",
      "liquid-edge": "oklch(1 0 0 / 10%)",
      "liquid-shadow": "oklch(0 0 0 / 50%)",
      "liquid-glow": "oklch(1 0 0 / 24%)",
      "liquid-shade": "oklch(0 0 0 / 28%)"
    }
  },
  "type": "registry:ui"
}