{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast-stack",
  "type": "registry:component",
  "title": "Toast Stack",
  "description": "Stacked notifications that slide in, pause on hover and dismiss by button, swipe or timeout.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "toast",
    "notification",
    "swipe",
    "feedback"
  ],
  "docs": "https://hyperblur.dev/effects/toast-stack",
  "files": [
    {
      "path": "registry/hyperblur/toast-stack.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/toast-stack.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ToastVariant = \"default\" | \"success\" | \"error\";\nexport type ToastPosition = \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\";\n\nexport interface ToastOptions {\n  title: string;\n  description?: string;\n  variant?: ToastVariant;\n  duration?: number;\n}\n\nexport interface ToastApi {\n  toast: (options: ToastOptions) => number;\n  dismiss: (id: number) => void;\n}\n\nexport interface ToastProviderProps {\n  children?: React.ReactNode;\n  position?: ToastPosition;\n  max?: number;\n  duration?: number;\n  color?: string;\n  inline?: boolean;\n  className?: string;\n}\n\ninterface ToastEntry {\n  id: number;\n  title: string;\n  description?: string;\n  variant: ToastVariant;\n  duration: number;\n  leaving: boolean;\n}\n\nconst css = `\n.hb-tos-v {\n  position: fixed;\n  z-index: 2147483000;\n  display: flex;\n  flex-direction: column;\n  gap: 8px;\n  box-sizing: border-box;\n  width: 344px;\n  max-width: 100vw;\n  padding: 16px;\n  pointer-events: none;\n}\n.hb-tos-bottom-right { bottom: 0; right: 0; --hb-tos-x: 32px; }\n.hb-tos-bottom-left { bottom: 0; left: 0; --hb-tos-x: -32px; }\n.hb-tos-top-right { top: 0; right: 0; --hb-tos-x: 32px; }\n.hb-tos-top-left { top: 0; left: 0; --hb-tos-x: -32px; }\n.hb-tos-v.hb-tos-inline {\n  position: absolute;\n  z-index: 10;\n  width: min(344px, 100%);\n  max-width: 100%;\n  padding: 12px;\n}\n.hb-tos-t {\n  --hb-tos-a: var(--hb-c);\n  position: relative;\n  display: flex;\n  align-items: flex-start;\n  gap: 10px;\n  overflow: hidden;\n  box-sizing: border-box;\n  padding: 12px 10px 12px 14px;\n  border: 1px solid rgba(255, 255, 255, 0.12);\n  border-radius: 10px;\n  background: #141414;\n  color: #f2f2f2;\n  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);\n  font: 14px/1.4 system-ui, -apple-system, \"Segoe UI\", sans-serif;\n  pointer-events: auto;\n  touch-action: pan-y;\n  user-select: none;\n  transition: transform 0.2s ease, opacity 0.2s ease;\n  animation: hb-tos-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);\n}\n.hb-tos-t[data-variant=\"success\"] { --hb-tos-a: #2fd17a; }\n.hb-tos-t[data-variant=\"error\"] { --hb-tos-a: #ff4d5e; }\n.hb-tos-t[data-drag] { transition: none; }\n.hb-tos-t[data-leaving] {\n  pointer-events: none;\n  animation: hb-tos-out 0.22s ease-in forwards;\n}\n.hb-tos-i {\n  flex: none;\n  width: 8px;\n  height: 8px;\n  margin-top: 6px;\n  border-radius: 50%;\n  background: var(--hb-tos-a);\n  box-shadow: 0 0 10px var(--hb-tos-a);\n}\n.hb-tos-m { flex: 1; min-width: 0; }\n.hb-tos-title { font-weight: 600; }\n.hb-tos-desc { margin-top: 2px; color: rgba(255, 255, 255, 0.62); font-size: 13px; }\n.hb-tos-x {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  padding: 0;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: rgba(255, 255, 255, 0.55);\n  cursor: pointer;\n}\n.hb-tos-x:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }\n.hb-tos-x:focus-visible { outline: 2px solid var(--hb-tos-a); outline-offset: 1px; }\n.hb-tos-b {\n  position: absolute;\n  left: 0;\n  bottom: 0;\n  width: 100%;\n  height: 2px;\n  background: var(--hb-tos-a);\n  opacity: 0.7;\n  transform-origin: left;\n  animation: hb-tos-bar var(--hb-tos-d) linear forwards;\n}\n.hb-tos-t[data-paused] .hb-tos-b { animation-play-state: paused; }\n@keyframes hb-tos-in { from { opacity: 0; transform: translateX(var(--hb-tos-x)); } }\n@keyframes hb-tos-out { to { opacity: 0; transform: translateX(var(--hb-tos-o, var(--hb-tos-x))); } }\n@keyframes hb-tos-bar { to { transform: scaleX(0); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-tos-t { animation: none; transition: none; }\n  .hb-tos-t[data-leaving] { animation: none; opacity: 0; }\n  .hb-tos-b { display: none; }\n}\n`;\n\nconst ToastContext = React.createContext<ToastApi | null>(null);\n\nexport function useToast(): ToastApi {\n  const api = React.useContext(ToastContext);\n  if (!api) throw new Error(\"useToast must be used inside <ToastProvider>\");\n  return api;\n}\n\ninterface ToastItemProps {\n  item: ToastEntry;\n  onDismiss: (id: number) => void;\n  onRemove: (id: number) => void;\n}\n\nfunction ToastItem({ item, onDismiss, onRemove }: ToastItemProps) {\n  const ref = React.useRef<HTMLDivElement>(null);\n  const drag = React.useRef<{ x: number; dx: number } | null>(null);\n  const timer = React.useRef<number | undefined>(undefined);\n  const left = React.useRef(item.duration);\n  const started = React.useRef(0);\n  const [hover, setHover] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n  const paused = hover || focused;\n\n  React.useEffect(() => {\n    if (item.leaving || paused || item.duration <= 0) return;\n    started.current = performance.now();\n    timer.current = window.setTimeout(() => onDismiss(item.id), Math.max(0, left.current));\n    return () => {\n      window.clearTimeout(timer.current);\n      left.current -= performance.now() - started.current;\n    };\n  }, [paused, item.leaving, item.id, item.duration, onDismiss]);\n\n  React.useEffect(() => {\n    if (!item.leaving) return;\n    const t = window.setTimeout(() => onRemove(item.id), 260);\n    return () => window.clearTimeout(t);\n  }, [item.leaving, item.id, onRemove]);\n\n  function down(e: React.PointerEvent<HTMLDivElement>) {\n    if (e.button !== 0 || item.leaving) return;\n    if ((e.target as HTMLElement).closest(\"button\")) return;\n    drag.current = { x: e.clientX, dx: 0 };\n    setHover(true);\n    e.currentTarget.setPointerCapture(e.pointerId);\n    e.currentTarget.setAttribute(\"data-drag\", \"\");\n  }\n\n  function move(e: React.PointerEvent<HTMLDivElement>) {\n    const d = drag.current;\n    if (!d) return;\n    d.dx = e.clientX - d.x;\n    const el = e.currentTarget;\n    el.style.transform = `translateX(${d.dx}px)`;\n    el.style.opacity = String(Math.max(0.2, 1 - Math.abs(d.dx) / 240));\n  }\n\n  function up(e: React.PointerEvent<HTMLDivElement>) {\n    const d = drag.current;\n    if (!d) return;\n    drag.current = null;\n    const el = e.currentTarget;\n    el.removeAttribute(\"data-drag\");\n    if (Math.abs(d.dx) > 80) {\n      el.style.setProperty(\"--hb-tos-o\", `${Math.sign(d.dx) * 320}px`);\n      onDismiss(item.id);\n    } else {\n      el.style.transform = \"\";\n      el.style.opacity = \"\";\n    }\n  }\n\n  function blur(e: React.FocusEvent<HTMLDivElement>) {\n    if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n  }\n\n  function key(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"Escape\") onDismiss(item.id);\n  }\n\n  return (\n    <div\n      ref={ref}\n      className=\"hb-tos-t\"\n      data-variant={item.variant}\n      data-paused={paused ? \"\" : undefined}\n      data-leaving={item.leaving ? \"\" : undefined}\n      style={{ \"--hb-tos-d\": `${item.duration}ms` } as React.CSSProperties}\n      onPointerEnter={() => setHover(true)}\n      onPointerLeave={() => setHover(false)}\n      onFocus={() => setFocused(true)}\n      onBlur={blur}\n      onKeyDown={key}\n      onPointerDown={down}\n      onPointerMove={move}\n      onPointerUp={up}\n      onPointerCancel={up}\n    >\n      <span className=\"hb-tos-i\" aria-hidden=\"true\" />\n      <div className=\"hb-tos-m\">\n        <div className=\"hb-tos-title\">{item.title}</div>\n        {item.description ? <div className=\"hb-tos-desc\">{item.description}</div> : null}\n      </div>\n      <button\n        type=\"button\"\n        className=\"hb-tos-x\"\n        aria-label=\"Dismiss notification\"\n        onClick={() => onDismiss(item.id)}\n      >\n        <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" aria-hidden=\"true\">\n          <path d=\"M3 3l8 8M11 3l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n        </svg>\n      </button>\n      {item.duration > 0 ? <span className=\"hb-tos-b\" aria-hidden=\"true\" /> : null}\n    </div>\n  );\n}\n\nexport function ToastProvider({\n  children,\n  position = \"bottom-right\",\n  max = 3,\n  duration = 4000,\n  color = \"#2f7bff\",\n  inline = false,\n  className = \"\",\n}: ToastProviderProps) {\n  const counter = React.useRef(0);\n  const [items, setItems] = React.useState<ToastEntry[]>([]);\n\n  const dismiss = React.useCallback((id: number) => {\n    setItems((list) => list.map((t) => (t.id === id && !t.leaving ? { ...t, leaving: true } : t)));\n  }, []);\n\n  const remove = React.useCallback((id: number) => {\n    setItems((list) => list.filter((t) => t.id !== id));\n  }, []);\n\n  const toast = React.useCallback(\n    (options: ToastOptions) => {\n      const id = counter.current++;\n      const entry: ToastEntry = {\n        id,\n        title: options.title,\n        description: options.description,\n        variant: options.variant ?? \"default\",\n        duration: options.duration ?? duration,\n        leaving: false,\n      };\n      setItems((list) => {\n        const next = [...list, entry];\n        let active = next.filter((t) => !t.leaving).length;\n        return next.map((t) => {\n          if (active > max && !t.leaving && t.id !== id) {\n            active -= 1;\n            return { ...t, leaving: true };\n          }\n          return t;\n        });\n      });\n      return id;\n    },\n    [max, duration],\n  );\n\n  const api = React.useMemo<ToastApi>(() => ({ toast, dismiss }), [toast, dismiss]);\n\n  return (\n    <ToastContext.Provider value={api}>\n      <style href=\"hb-toast-stack\" precedence=\"default\">{css}</style>\n      {children}\n      <div\n        className={`hb-tos-v hb-tos-${position}${inline ? \" hb-tos-inline\" : \"\"} ${className}`}\n        style={{ \"--hb-c\": color } as React.CSSProperties}\n        role=\"status\"\n        aria-live=\"polite\"\n        aria-relevant=\"additions text\"\n      >\n        {[...items].reverse().map((item) => (\n          <ToastItem key={item.id} item={item} onDismiss={dismiss} onRemove={remove} />\n        ))}\n      </div>\n    </ToastContext.Provider>\n  );\n}\n"
    }
  ]
}