{
  "name": "toast",
  "type": "ui:component",
  "title": "Toast & Toaster",
  "description": "signal()-driven crisp notification stack with mobile safe-area layout, auto-dismiss, and try/finally timer teardown.",
  "dependencies": [
    "@lucide/icons"
  ],
  "registryDependencies": [
    "theme",
    "icon"
  ],
  "files": [
    {
      "path": "src/ui/toast.tsx",
      "target": "src/ui/toast.tsx",
      "sha256": "f18408333920c91a6fdb5648aca0c8152b8c8389b0e1e363f2f62e906a512445",
      "content": "import './theme.css';\nimport { X } from '@lucide/icons';\nimport { signal, scope } from '@fierst/aster';\nimport { Icon } from './icon';\n\nexport type ToastTone = 'neutral' | 'success' | 'warning' | 'danger';\n\nexport interface ToastItem {\n  id: string;\n  title: string;\n  description?: string;\n  tone: ToastTone;\n}\n\nconst toasts = signal<ToastItem[]>([]);\nconst timers = new Map<string, ReturnType<typeof setTimeout>>();\n\nexport function dismissToast(id: string): void {\n  const t = timers.get(id);\n  if (t) {\n    clearTimeout(t);\n    timers.delete(id);\n  }\n  toasts.update((list) => list.filter((item) => item.id !== id));\n}\n\nexport function showToast(\n  title: string,\n  opts: { description?: string; tone?: ToastTone; duration?: number } = {},\n): string {\n  const id = `aster-t-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;\n  const item: ToastItem = {\n    id,\n    title,\n    description: opts.description,\n    tone: opts.tone ?? 'neutral',\n  };\n  toasts.update((list) => [item, ...list].slice(0, 5));\n  const dur = opts.duration ?? 3500;\n  if (dur > 0) {\n    timers.set(\n      id,\n      setTimeout(() => dismissToast(id), dur),\n    );\n  }\n  return id;\n}\n\nexport const toast = {\n  show: (title: string, description?: string) => showToast(title, { description, tone: 'neutral' }),\n  success: (title: string, description?: string) =>\n    showToast(title, { description, tone: 'success' }),\n  warning: (title: string, description?: string) =>\n    showToast(title, { description, tone: 'warning' }),\n  error: (title: string, description?: string) => showToast(title, { description, tone: 'danger' }),\n  dismiss: dismissToast,\n};\n\nconst toasterScope = scope`\n  :scope {\n    position: fixed;\n    left: calc(0.75rem + var(--aster-safe-left));\n    right: calc(0.75rem + var(--aster-safe-right));\n    bottom: calc(0.75rem + var(--aster-safe-bottom));\n    z-index: 60;\n    display: grid;\n    gap: 0.6rem;\n    pointer-events: none;\n  }\n  @media (min-width: 640px) {\n    :scope {\n      left: auto;\n      right: 1.25rem;\n      bottom: 1.25rem;\n      width: 360px;\n    }\n  }\n  .toast-item {\n    pointer-events: auto;\n    display: flex;\n    align-items: flex-start;\n    justify-content: space-between;\n    gap: 0.75rem;\n    padding: 0.85rem 1rem;\n    border-radius: var(--aster-radius-md);\n    color: var(--aster-on-surface);\n  }\n  .dot {\n    width: 8px;\n    height: 8px;\n    border-radius: 50%;\n    margin-top: 0.42rem;\n    flex-shrink: 0;\n    background: var(--aster-primary);\n  }\n  .tone-success .dot { background: var(--aster-success); }\n  .tone-warning .dot { background: var(--aster-warning); }\n  .tone-danger .dot { background: var(--aster-danger); }\n  .body { flex: 1; display: grid; gap: 0.15rem; }\n  .title { font-size: 0.88rem; font-weight: 600; }\n  .desc { font-size: 0.8rem; color: var(--aster-on-surface-variant); }\n  .close {\n    border: none;\n    background: transparent;\n    color: var(--aster-on-surface-variant);\n    cursor: pointer;\n    padding: 0.25rem;\n    display: inline-grid;\n    place-items: center;\n    border-radius: var(--aster-radius-xs);\n  }\n  .close:hover { background: var(--aster-surface-low); color: var(--aster-on-surface); }\n`;\n\nexport function* Toaster() {\n  try {\n    for (;;) {\n      const list = toasts();\n      yield (\n        <div class={toasterScope} role=\"region\" aria-label=\"Notifications\" aria-live=\"polite\">\n          {list.map((t) => (\n            <div key={t.id} class={`aster-surface-popover toast-item tone-${t.tone}`} role=\"status\">\n              <span class=\"dot\" aria-hidden=\"true\" />\n              <div class=\"body\">\n                <span class=\"title\">{t.title}</span>\n                {t.description ? <span class=\"desc\">{t.description}</span> : null}\n              </div>\n              <button\n                type=\"button\"\n                class=\"close\"\n                aria-label=\"Dismiss\"\n                onClick={() => dismissToast(t.id)}\n              >\n                <Icon icon={X} size={15} />\n              </button>\n            </div>\n          ))}\n        </div>\n      );\n    }\n  } finally {\n    for (const timer of timers.values()) clearTimeout(timer);\n    timers.clear();\n  }\n}\n"
    }
  ]
}
