{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast",
  "title": "Toast",
  "description": "Transient notification queue with bounded visible stack, queued count indicator, hover/focus timer pause, Escape dismissal, and stepped 12fps entrance.",
  "registryDependencies": [
    "https://frame12.dev/r/frame12-styles.json",
    "https://frame12.dev/r/tag.json"
  ],
  "files": [
    {
      "path": "ui/toast.tsx",
      "content": "'use client';\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport {\n  type SemanticStatus,\n  STATUS_GLYPHS,\n  STATUS_SR_LABELS,\n  extractTextContent,\n  startsWithStatusLabel,\n} from './tag';\n\nexport type ToastStatus = SemanticStatus;\nexport type ToastDensity = 'comfortable' | 'compact';\n\nexport interface ToastActionDescriptor {\n  label: React.ReactNode;\n  onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;\n  altText?: string;\n}\n\nexport interface ToastItem {\n  id: string;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  status?: ToastStatus;\n  glyph?: string | false;\n  srLabel?: string | false;\n  duration?: number;\n  action?: ToastActionDescriptor | React.ReactNode;\n  dismissible?: boolean;\n  dismissLabel?: string;\n  onDismiss?: (id: string) => void;\n  updateCount?: number;\n}\n\nexport type ToastOptions = Omit<ToastItem, 'id'> & { id?: string };\n\nexport interface ToastContextValue {\n  toasts: ToastItem[];\n  visibleToasts: ToastItem[];\n  queuedCount: number;\n  maxVisible: number;\n  defaultDuration: number;\n  density: ToastDensity;\n  viewportPaused: boolean;\n  documentHidden: boolean;\n  politeAnnouncement?: string;\n  assertiveAnnouncement?: string;\n  setViewportPaused: (paused: boolean) => void;\n  registerCustomViewport?: () => () => void;\n  getRemainingDuration?: (id: string, fallback: number) => number;\n  setRemainingDuration?: (id: string, remaining: number) => void;\n  toast: (options: ToastOptions) => string;\n  dismiss: (id?: string) => void;\n  dismissAll: () => void;\n}\n\nconst ToastContext = React.createContext<ToastContextValue | null>(null);\n\nconst useIsomorphicLayoutEffect =\n  typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;\n\nexport function useToast(): ToastContextValue {\n  const ctx = React.useContext(ToastContext);\n  if (!ctx) {\n    throw new Error('[FRAME/12 useToast] must be used within <ToastProvider>.');\n  }\n  return ctx;\n}\n\nexport function useOptionalToast(): ToastContextValue | null {\n  return React.useContext(ToastContext);\n}\n\nconst ToastItemContext = React.createContext<{\n  id?: string;\n  onDismiss?: () => void;\n} | null>(null);\n\nconst DefaultViewportContext = React.createContext<boolean>(false);\nconst ToastInViewportContext = React.createContext<boolean>(false);\n\nfunction hasExplicitToastViewport(node: React.ReactNode): boolean {\n  let found = false;\n  const walk = (n: React.ReactNode) => {\n    React.Children.forEach(n, (child) => {\n      if (found || !React.isValidElement<Record<string, unknown>>(child)) return;\n      const fnType = child.type as {\n        f12IsToastViewport?: boolean;\n        f12IsToastProvider?: boolean;\n      };\n      if (fnType?.f12IsToastProvider) {\n        return;\n      }\n      if (fnType?.f12IsToastViewport) {\n        found = true;\n        return;\n      }\n      if (child.props?.children) {\n        walk(child.props.children as React.ReactNode);\n      }\n    });\n  };\n  walk(node);\n  return found;\n}\n\nfunction findTopmostModalDialog(): HTMLDialogElement | null {\n  if (typeof document === 'undefined') return null;\n  const openDialogs = document.querySelectorAll<HTMLDialogElement>('dialog[open]');\n  for (let i = openDialogs.length - 1; i >= 0; i--) {\n    const d = openDialogs[i];\n    if (!d.isConnected || !d.open) continue;\n    try {\n      if (d.matches(':modal')) return d;\n      if (typeof d.showModal === 'function' && document.querySelector('dialog:modal')) {\n        continue;\n      }\n    } catch {\n      // Fallback if :modal selector is unsupported\n    }\n    return d;\n  }\n  return null;\n}\n\nfunction extractActionAltText(action: ToastItem['action']): string | undefined {\n  if (!action || typeof action !== 'object') return undefined;\n  if (React.isValidElement<{ altText?: string }>(action)) {\n    return typeof action.props?.altText === 'string' ? action.props.altText : undefined;\n  }\n  if ('altText' in action && typeof (action as ToastActionDescriptor).altText === 'string') {\n    return (action as ToastActionDescriptor).altText;\n  }\n  return undefined;\n}\n\nfunction formatToastAnnouncement(item: ToastItem | undefined): string {\n  if (!item) return '';\n  const status = item.status ?? 'neutral';\n  const resolvedSrLabel =\n    item.srLabel === false\n      ? undefined\n      : item.srLabel !== undefined\n        ? item.srLabel\n        : STATUS_SR_LABELS[status];\n  const combined = `${extractTextContent(item.title)} ${extractTextContent(item.description)}`.trim();\n  const altText = extractActionAltText(item.action);\n  const withAlt = altText ? `${combined}${combined ? ' ' : ''}(${altText})` : combined;\n  if (!withAlt) return resolvedSrLabel ? `${resolvedSrLabel}` : '';\n  const needsPrefix =\n    Boolean(resolvedSrLabel) &&\n    !(resolvedSrLabel && startsWithStatusLabel(withAlt, resolvedSrLabel, status));\n  return needsPrefix ? `${resolvedSrLabel}: ${withAlt}` : withAlt;\n}\n\nexport interface ToastProviderProps {\n  maxVisible?: number;\n  defaultDuration?: number;\n  density?: ToastDensity;\n  label?: string;\n  renderViewport?: boolean;\n  children?: React.ReactNode;\n}\n\nexport function ToastProvider({\n  maxVisible = 3,\n  defaultDuration = 5000,\n  density = 'comfortable',\n  label = 'Notifications',\n  renderViewport = true,\n  children,\n}: ToastProviderProps) {\n  const [toasts, setToasts] = React.useState<ToastItem[]>([]);\n  const toastsRef = React.useRef<ToastItem[]>([]);\n  const remainingByIdRef = React.useRef<Map<string, number>>(new Map());\n  const announcedKeysRef = React.useRef<Set<string>>(new Set());\n  const activePoliteRef = React.useRef<{ id: string; key: string; text: string } | null>(null);\n  const activeAssertiveRef = React.useRef<{ id: string; key: string; text: string } | null>(null);\n  const politePulseTimerRef = React.useRef<number | null>(null);\n  const assertivePulseTimerRef = React.useRef<number | null>(null);\n  const [politeAnnouncement, setPoliteAnnouncement] = React.useState('');\n  const [assertiveAnnouncement, setAssertiveAnnouncement] = React.useState('');\n  const [viewportPaused, setViewportPaused] = React.useState(false);\n  const [documentHidden, setDocumentHidden] = React.useState(false);\n  const [customViewportCount, setCustomViewportCount] = React.useState(0);\n  const seqRef = React.useRef(0);\n  const safeMaxVisible = Math.max(1, maxVisible);\n\n  React.useEffect(() => {\n    return () => {\n      if (politePulseTimerRef.current !== null) {\n        window.clearTimeout(politePulseTimerRef.current);\n      }\n      if (assertivePulseTimerRef.current !== null) {\n        window.clearTimeout(assertivePulseTimerRef.current);\n      }\n    };\n  }, []);\n\n  React.useEffect(() => {\n    if (typeof document === 'undefined') return;\n    const syncVisibility = () => {\n      setDocumentHidden(document.hidden === true);\n    };\n    syncVisibility();\n    document.addEventListener('visibilitychange', syncVisibility);\n    return () => {\n      document.removeEventListener('visibilitychange', syncVisibility);\n    };\n  }, []);\n\n  const registerCustomViewport = React.useCallback(() => {\n    setCustomViewportCount((c) => c + 1);\n    return () => {\n      setCustomViewportCount((c) => Math.max(0, c - 1));\n    };\n  }, []);\n\n  const getRemainingDuration = React.useCallback((id: string, fallback: number) => {\n    const saved = remainingByIdRef.current.get(id);\n    return saved !== undefined ? saved : fallback;\n  }, []);\n\n  const setRemainingDuration = React.useCallback((id: string, remaining: number) => {\n    if (toastsRef.current.some((t) => t.id === id)) {\n      remainingByIdRef.current.set(id, remaining);\n    }\n  }, []);\n\n  const dismiss = React.useCallback(\n    (id?: string) => {\n      const current = toastsRef.current;\n      const visible = current.slice(0, safeMaxVisible);\n      const target = !id\n        ? (visible[visible.length - 1] ?? current[current.length - 1])\n        : current.find((t) => t.id === id);\n      if (!target) return;\n      const targetId = target.id;\n      const next = current.filter((t) => t.id !== targetId);\n      toastsRef.current = next;\n      remainingByIdRef.current.delete(targetId);\n      for (const key of announcedKeysRef.current) {\n        if (key.startsWith(`${targetId}:`)) {\n          announcedKeysRef.current.delete(key);\n        }\n      }\n      setToasts(() => [...toastsRef.current]);\n      target.onDismiss?.(targetId);\n    },\n    [safeMaxVisible],\n  );\n\n  const dismissAll = React.useCallback(() => {\n    const current = toastsRef.current;\n    if (current.length === 0) return;\n    toastsRef.current = [];\n    remainingByIdRef.current.clear();\n    announcedKeysRef.current.clear();\n    activePoliteRef.current = null;\n    activeAssertiveRef.current = null;\n    if (politePulseTimerRef.current !== null) {\n      window.clearTimeout(politePulseTimerRef.current);\n      politePulseTimerRef.current = null;\n    }\n    if (assertivePulseTimerRef.current !== null) {\n      window.clearTimeout(assertivePulseTimerRef.current);\n      assertivePulseTimerRef.current = null;\n    }\n    setPoliteAnnouncement('');\n    setAssertiveAnnouncement('');\n    setToasts(() => [...toastsRef.current]);\n    for (const item of current) {\n      item.onDismiss?.(item.id);\n    }\n  }, []);\n\n  const toast = React.useCallback(\n    (options: ToastOptions): string => {\n      seqRef.current += 1;\n      const id = options.id ?? `f12-toast-${seqRef.current}`;\n      const prev = toastsRef.current;\n      const existingIdx = prev.findIndex((t) => t.id === id);\n      const resolvedDuration =\n        options.duration !== undefined\n          ? options.duration\n          : options.action !== undefined && defaultDuration > 0\n            ? Math.max(defaultDuration, 10000)\n            : defaultDuration;\n      const nextItem: ToastItem = {\n        status: 'neutral',\n        dismissible: true,\n        ...options,\n        duration: resolvedDuration,\n        id,\n        updateCount: existingIdx !== -1 ? (prev[existingIdx].updateCount ?? 0) + 1 : 0,\n      };\n      let next: ToastItem[];\n      if (existingIdx !== -1) {\n        next = [...prev];\n        next[existingIdx] = nextItem;\n      } else {\n        next = [...prev, nextItem];\n      }\n      remainingByIdRef.current.set(id, resolvedDuration);\n      toastsRef.current = next;\n      setToasts(() => [...toastsRef.current]);\n      return id;\n    },\n    [defaultDuration],\n  );\n\n  const visibleToasts = React.useMemo(\n    () => toasts.slice(0, safeMaxVisible),\n    [toasts, safeMaxVisible],\n  );\n  const queuedCount = Math.max(0, toasts.length - safeMaxVisible);\n\n  useIsomorphicLayoutEffect(() => {\n    const politeCandidates = visibleToasts.filter((t) => (t.status ?? 'neutral') !== 'danger');\n    const assertiveCandidates = visibleToasts.filter((t) => t.status === 'danger');\n\n    const unannouncedPolite = politeCandidates.filter(\n      (t) => !announcedKeysRef.current.has(`${t.id}:${t.updateCount ?? 0}`),\n    );\n    if (unannouncedPolite.length > 0) {\n      for (const item of unannouncedPolite) {\n        announcedKeysRef.current.add(`${item.id}:${item.updateCount ?? 0}`);\n      }\n      const newest = unannouncedPolite[unannouncedPolite.length - 1];\n      const nextText = formatToastAnnouncement(newest);\n      const prevText = activePoliteRef.current?.text ?? '';\n      activePoliteRef.current = {\n        id: newest.id,\n        key: `${newest.id}:${newest.updateCount ?? 0}`,\n        text: nextText,\n      };\n      if (politePulseTimerRef.current !== null) {\n        window.clearTimeout(politePulseTimerRef.current);\n        politePulseTimerRef.current = null;\n      }\n      if (prevText && prevText === nextText && typeof window !== 'undefined') {\n        setPoliteAnnouncement('');\n        politePulseTimerRef.current = window.setTimeout(() => {\n          politePulseTimerRef.current = null;\n          setPoliteAnnouncement(nextText);\n        }, 40);\n      } else {\n        setPoliteAnnouncement(nextText);\n      }\n    } else if (\n      activePoliteRef.current &&\n      !politeCandidates.some(\n        (t) => `${t.id}:${t.updateCount ?? 0}` === activePoliteRef.current?.key,\n      )\n    ) {\n      if (politePulseTimerRef.current !== null) {\n        window.clearTimeout(politePulseTimerRef.current);\n        politePulseTimerRef.current = null;\n      }\n      activePoliteRef.current = null;\n      setPoliteAnnouncement('');\n    }\n\n    const unannouncedAssertive = assertiveCandidates.filter(\n      (t) => !announcedKeysRef.current.has(`${t.id}:${t.updateCount ?? 0}`),\n    );\n    if (unannouncedAssertive.length > 0) {\n      for (const item of unannouncedAssertive) {\n        announcedKeysRef.current.add(`${item.id}:${item.updateCount ?? 0}`);\n      }\n      const newest = unannouncedAssertive[unannouncedAssertive.length - 1];\n      const nextText = formatToastAnnouncement(newest);\n      const prevText = activeAssertiveRef.current?.text ?? '';\n      activeAssertiveRef.current = {\n        id: newest.id,\n        key: `${newest.id}:${newest.updateCount ?? 0}`,\n        text: nextText,\n      };\n      if (assertivePulseTimerRef.current !== null) {\n        window.clearTimeout(assertivePulseTimerRef.current);\n        assertivePulseTimerRef.current = null;\n      }\n      if (prevText && prevText === nextText && typeof window !== 'undefined') {\n        setAssertiveAnnouncement('');\n        assertivePulseTimerRef.current = window.setTimeout(() => {\n          assertivePulseTimerRef.current = null;\n          setAssertiveAnnouncement(nextText);\n        }, 40);\n      } else {\n        setAssertiveAnnouncement(nextText);\n      }\n    } else if (\n      activeAssertiveRef.current &&\n      !assertiveCandidates.some(\n        (t) => `${t.id}:${t.updateCount ?? 0}` === activeAssertiveRef.current?.key,\n      )\n    ) {\n      if (assertivePulseTimerRef.current !== null) {\n        window.clearTimeout(assertivePulseTimerRef.current);\n        assertivePulseTimerRef.current = null;\n      }\n      activeAssertiveRef.current = null;\n      setAssertiveAnnouncement('');\n    }\n  }, [visibleToasts]);\n\n  const ctxValue = React.useMemo<ToastContextValue>(\n    () => ({\n      toasts,\n      visibleToasts,\n      queuedCount,\n      maxVisible: safeMaxVisible,\n      defaultDuration,\n      density,\n      viewportPaused,\n      documentHidden,\n      politeAnnouncement,\n      assertiveAnnouncement,\n      setViewportPaused,\n      registerCustomViewport,\n      getRemainingDuration,\n      setRemainingDuration,\n      toast,\n      dismiss,\n      dismissAll,\n    }),\n    [\n      toasts,\n      visibleToasts,\n      queuedCount,\n      safeMaxVisible,\n      defaultDuration,\n      density,\n      viewportPaused,\n      documentHidden,\n      politeAnnouncement,\n      assertiveAnnouncement,\n      registerCustomViewport,\n      getRemainingDuration,\n      setRemainingDuration,\n      toast,\n      dismiss,\n      dismissAll,\n    ],\n  );\n\n  const hasChildViewport = hasExplicitToastViewport(children) || customViewportCount > 0;\n\n  return (\n    <ToastContext.Provider value={ctxValue}>\n      {children}\n      {!renderViewport && !hasChildViewport && (\n        <>\n          <div className=\"f12-sr-only\" aria-live=\"polite\" aria-atomic=\"true\">\n            {politeAnnouncement}\n          </div>\n          <div className=\"f12-sr-only\" aria-live=\"assertive\" aria-atomic=\"true\">\n            {assertiveAnnouncement}\n          </div>\n        </>\n      )}\n      {renderViewport && !hasChildViewport && (\n        <DefaultViewportContext.Provider value={true}>\n          <ToastViewport aria-label={label} />\n        </DefaultViewportContext.Provider>\n      )}\n    </ToastContext.Provider>\n  );\n}\n\n(ToastProvider as unknown as { f12IsToastProvider?: boolean }).f12IsToastProvider = true;\n\nexport interface ToastViewportProps extends React.HTMLAttributes<HTMLDivElement> {\n  density?: ToastDensity;\n  label?: string;\n  hotkey?: string;\n}\n\nexport const ToastViewport = React.forwardRef<HTMLDivElement, ToastViewportProps>(\n  function ToastViewport(\n    {\n      density: propDensity,\n      label = 'Notifications',\n      hotkey = 'F8',\n      'aria-label': userAriaLabel,\n      className = '',\n      onMouseEnter,\n      onMouseLeave,\n      onFocusCapture,\n      onBlurCapture,\n      onKeyDown,\n      children,\n      ...rest\n    },\n    forwardedRef,\n  ) {\n    const ctx = React.useContext(ToastContext);\n    const isDefaultViewport = React.useContext(DefaultViewportContext);\n    const vpRef = React.useRef<HTMLDivElement | null>(null);\n    const anchorRef = React.useRef<HTMLSpanElement | null>(null);\n    const preFocusElementRef = React.useRef<HTMLElement | null>(null);\n    const hadFocusInsideRef = React.useRef<boolean>(false);\n    const prevIdsRef = React.useRef<string[]>([]);\n    const lastPointerPosRef = React.useRef<{ x: number; y: number } | null>(null);\n    const ignoreStationaryEnterRef = React.useRef<boolean>(false);\n    const [hovered, setHovered] = React.useState(false);\n    const [focused, setFocused] = React.useState(false);\n    const [modalDialogHost, setModalDialogHost] = React.useState<HTMLDialogElement | null>(null);\n\n    const registerCustomViewport = ctx?.registerCustomViewport;\n    useIsomorphicLayoutEffect(() => {\n      if (isDefaultViewport || !registerCustomViewport) return;\n      return registerCustomViewport();\n    }, [isDefaultViewport, registerCustomViewport]);\n\n    const setRefs = React.useCallback(\n      (node: HTMLDivElement | null) => {\n        vpRef.current = node;\n        if (typeof forwardedRef === 'function') {\n          forwardedRef(node);\n        } else if (forwardedRef) {\n          (forwardedRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n        }\n      },\n      [forwardedRef],\n    );\n\n    const effectiveDensity = propDensity ?? ctx?.density ?? 'comfortable';\n    const isCompact = effectiveDensity === 'compact';\n    const visibleToasts = ctx?.visibleToasts ?? [];\n    const visibleIdsKey = visibleToasts.map((t) => t.id).join('\\0');\n    const queuedCount = ctx?.queuedCount ?? 0;\n    const setViewportPaused = ctx?.setViewportPaused;\n\n    const hasVisibleToasts = visibleToasts.length > 0;\n\n    useIsomorphicLayoutEffect(() => {\n      if (typeof document === 'undefined') return;\n      const syncDialogHost = () => {\n        const topmost = findTopmostModalDialog();\n        const anchorDialog = anchorRef.current?.closest('dialog[open]') as HTMLDialogElement | null;\n        if (topmost && topmost !== anchorDialog) {\n          setModalDialogHost((prev) => (prev === topmost ? prev : topmost));\n        } else {\n          setModalDialogHost((prev) => (prev === null ? prev : null));\n        }\n      };\n      syncDialogHost();\n      const observer =\n        typeof MutationObserver !== 'undefined'\n          ? new MutationObserver(() => syncDialogHost())\n          : null;\n      if (observer && document.documentElement) {\n        observer.observe(document.documentElement, {\n          subtree: true,\n          childList: hasVisibleToasts,\n          attributes: true,\n          attributeFilter: ['open'],\n        });\n      }\n      document.addEventListener('close', syncDialogHost, true);\n      return () => {\n        observer?.disconnect();\n        document.removeEventListener('close', syncDialogHost, true);\n      };\n    }, [hasVisibleToasts, visibleIdsKey]);\n\n    const needsViewportTabStop =\n      visibleToasts.length > 0 &&\n      visibleToasts.every((t) => t.dismissible === false && !t.action);\n\n    // Reconcile focus and hover whenever visibleToasts changes so unmounting a toast\n    // by click or keyboard never leaves the viewport stuck in a paused state.\n    useIsomorphicLayoutEffect(() => {\n      const currentIds = visibleIdsKey ? visibleIdsKey.split('\\0') : [];\n      const prevIds = prevIdsRef.current;\n      const removedAny = prevIds.some((id) => !currentIds.includes(id));\n      prevIdsRef.current = currentIds;\n\n      const vp = vpRef.current;\n      const vpIsTabStop =\n        needsViewportTabStop || vp?.getAttribute('tabindex') === '0';\n      const isControlInside = (el: Element | null) =>\n        Boolean(\n          vp &&\n            el &&\n            el !== document.body &&\n            (vpIsTabStop ? vp.contains(el) : el !== vp && vp.contains(el)),\n        );\n      const active = typeof document !== 'undefined' ? document.activeElement : null;\n      let activeInside = isControlInside(active);\n\n      if (hadFocusInsideRef.current && !activeInside) {\n        hadFocusInsideRef.current = false;\n        const restoreEl = preFocusElementRef.current;\n        preFocusElementRef.current = null;\n        if (\n          restoreEl &&\n          restoreEl.isConnected &&\n          typeof restoreEl.focus === 'function' &&\n          !restoreEl.closest('[inert], dialog:not([open])')\n        ) {\n          try {\n            restoreEl.focus({ preventScroll: true });\n          } catch {\n            // Ignore focus restoration errors\n          }\n        } else if (vp && active === vp && !vpIsTabStop) {\n          vp.blur();\n        }\n        const nextActive = typeof document !== 'undefined' ? document.activeElement : null;\n        activeInside = isControlInside(nextActive);\n      }\n\n      if (currentIds.length === 0) {\n        ignoreStationaryEnterRef.current = false;\n        hadFocusInsideRef.current = false;\n        setFocused(false);\n        setHovered(false);\n        setViewportPaused?.(false);\n        return;\n      }\n\n      if (removedAny) {\n        ignoreStationaryEnterRef.current = true;\n        setFocused(activeInside);\n        setHovered(false);\n        setViewportPaused?.(activeInside);\n      } else if (!activeInside && focused) {\n        setFocused(false);\n        setViewportPaused?.(hovered);\n      }\n    }, [visibleIdsKey, focused, hovered, needsViewportTabStop, setViewportPaused]);\n\n    React.useEffect(() => {\n      if (!focused || typeof document === 'undefined') return;\n      const handleFocusIn = (e: FocusEvent) => {\n        const vp = vpRef.current;\n        if (vp && e.target instanceof Node && !vp.contains(e.target)) {\n          hadFocusInsideRef.current = false;\n          setFocused(false);\n        }\n      };\n      document.addEventListener('focusin', handleFocusIn, true);\n      return () => {\n        document.removeEventListener('focusin', handleFocusIn, true);\n      };\n    }, [focused]);\n\n    React.useEffect(() => {\n      setViewportPaused?.(hovered || focused);\n    }, [hovered, focused, setViewportPaused]);\n\n    React.useEffect(() => {\n      if (!hotkey || visibleToasts.length === 0 || typeof document === 'undefined') return;\n      const handleHotkey = (e: KeyboardEvent) => {\n        if (e.key !== hotkey || e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return;\n        const vp = vpRef.current;\n        if (!vp) return;\n        const controls = vp.querySelectorAll<HTMLElement>(\n          '.f12-toast-action:not([disabled]), .f12-toast-close:not([disabled]), .f12-toast button:not([disabled]), .f12-toast a[href], .f12-toast input:not([disabled]), .f12-toast select:not([disabled]), .f12-toast textarea:not([disabled]), .f12-toast [tabindex]:not([tabindex=\"-1\"]):not([disabled])',\n        );\n        const target = controls.length > 0 ? controls[controls.length - 1] : vp;\n        if (target) {\n          e.preventDefault();\n          if (target === vp && !vp.hasAttribute('tabindex')) {\n            vp.setAttribute('tabindex', '0');\n          }\n          if (\n            document.activeElement instanceof HTMLElement &&\n            !vp.contains(document.activeElement)\n          ) {\n            preFocusElementRef.current = document.activeElement;\n          }\n          target.focus();\n        }\n      };\n      document.addEventListener('keydown', handleHotkey);\n      return () => {\n        document.removeEventListener('keydown', handleHotkey);\n      };\n    }, [hotkey, visibleToasts.length]);\n\n    const viewportNode = (\n      <ToastInViewportContext.Provider value={true}>\n        <div\n          ref={setRefs}\n          role=\"region\"\n          aria-label={userAriaLabel ?? label}\n          tabIndex={needsViewportTabStop ? 0 : undefined}\n          data-density={isCompact ? 'compact' : undefined}\n          data-paused={hovered || focused ? 'true' : 'false'}\n          data-queued-count={queuedCount}\n          className={`f12-toast-viewport${isCompact ? ' f12-toast-viewport-compact' : ''}${className ? ` ${className}` : ''}`}\n          onPointerDownCapture={(e) => {\n            lastPointerPosRef.current = { x: e.clientX, y: e.clientY };\n          }}\n          onMouseDownCapture={(e) => {\n            lastPointerPosRef.current = { x: e.clientX, y: e.clientY };\n          }}\n          onMouseEnter={(e) => {\n            onMouseEnter?.(e);\n            if (e.relatedTarget instanceof Node && !e.relatedTarget.isConnected) {\n              return;\n            }\n            if (ignoreStationaryEnterRef.current) {\n              const last = lastPointerPosRef.current;\n              if (last && Math.abs(e.clientX - last.x) <= 2 && Math.abs(e.clientY - last.y) <= 2) {\n                return;\n              }\n              ignoreStationaryEnterRef.current = false;\n            }\n            lastPointerPosRef.current = { x: e.clientX, y: e.clientY };\n            if (visibleToasts.length > 0) {\n              setHovered(true);\n            }\n          }}\n          onMouseMove={(e) => {\n            if (ignoreStationaryEnterRef.current) {\n              const last = lastPointerPosRef.current;\n              if (last && Math.abs(e.clientX - last.x) <= 2 && Math.abs(e.clientY - last.y) <= 2) {\n                return;\n              }\n              ignoreStationaryEnterRef.current = false;\n            }\n            lastPointerPosRef.current = { x: e.clientX, y: e.clientY };\n            if (!hovered && visibleToasts.length > 0) {\n              setHovered(true);\n            }\n          }}\n          onMouseLeave={(e) => {\n            onMouseLeave?.(e);\n            if (e.relatedTarget instanceof Node && !e.relatedTarget.isConnected) {\n              return;\n            }\n            ignoreStationaryEnterRef.current = false;\n            setHovered(false);\n          }}\n          onFocusCapture={(e) => {\n            onFocusCapture?.(e);\n            const vpIsTabStop =\n              needsViewportTabStop || vpRef.current?.getAttribute('tabindex') === '0';\n            if (!vpIsTabStop && e.target === vpRef.current) {\n              return;\n            }\n            if (\n              e.relatedTarget instanceof HTMLElement &&\n              !vpRef.current?.contains(e.relatedTarget)\n            ) {\n              preFocusElementRef.current = e.relatedTarget;\n            }\n            hadFocusInsideRef.current = true;\n            setFocused(true);\n          }}\n          onBlurCapture={(e) => {\n            onBlurCapture?.(e);\n            const nextTarget = e.relatedTarget as Node | null;\n            const vpIsTabStop =\n              needsViewportTabStop || vpRef.current?.getAttribute('tabindex') === '0';\n            const nextInside = Boolean(\n              vpRef.current &&\n                nextTarget &&\n                (vpIsTabStop\n                  ? vpRef.current.contains(nextTarget)\n                  : nextTarget !== vpRef.current && vpRef.current.contains(nextTarget)),\n            );\n            if (!nextInside) {\n              if (!needsViewportTabStop && vpRef.current?.hasAttribute('tabindex')) {\n                vpRef.current.removeAttribute('tabindex');\n              }\n              hadFocusInsideRef.current = false;\n              setFocused(false);\n            }\n          }}\n          onKeyDown={(e) => {\n            onKeyDown?.(e);\n            if (e.key === 'Escape' && !e.defaultPrevented) {\n              const dismissibleVisible = [...visibleToasts]\n                .reverse()\n                .find((t) => t.dismissible !== false);\n              if (dismissibleVisible) {\n                e.preventDefault();\n                e.stopPropagation();\n                ctx?.dismiss(dismissibleVisible.id);\n              }\n            }\n          }}\n          {...rest}\n        >\n          {visibleToasts.map((item) => {\n            const isDescriptor =\n              Boolean(item.action) &&\n              typeof item.action === 'object' &&\n              !React.isValidElement(item.action) &&\n              'label' in (item.action as ToastActionDescriptor) &&\n              'onClick' in (item.action as ToastActionDescriptor);\n            const actionNode = isDescriptor ? (\n              <ToastAction\n                altText={(item.action as ToastActionDescriptor).altText}\n                onClick={(item.action as ToastActionDescriptor).onClick}\n              >\n                {(item.action as ToastActionDescriptor).label}\n              </ToastAction>\n            ) : (\n              (item.action as React.ReactNode)\n            );\n\n            return (\n              <Toast\n                key={item.id}\n                id={item.id}\n                status={item.status}\n                glyph={item.glyph}\n                srLabel={item.srLabel}\n                title={item.title}\n                description={item.description}\n                action={actionNode}\n                duration={item.duration}\n                resetKey={item.updateCount}\n                dismissible={item.dismissible}\n                dismissLabel={item.dismissLabel}\n                density={effectiveDensity}\n                onDismiss={() => ctx?.dismiss(item.id)}\n              />\n            );\n          })}\n          {queuedCount > 0 && (\n            <div className=\"f12-toast-queue-badge\" aria-live=\"off\">\n              {`+${queuedCount} QUEUED`}\n            </div>\n          )}\n          {children}\n        </div>\n      </ToastInViewportContext.Provider>\n    );\n\n    const portaledContent = (\n      <>\n        {ctx && (\n          <>\n            <div className=\"f12-sr-only\" aria-live=\"polite\" aria-atomic=\"true\">\n              {ctx.politeAnnouncement ?? ''}\n            </div>\n            <div className=\"f12-sr-only\" aria-live=\"assertive\" aria-atomic=\"true\">\n              {ctx.assertiveAnnouncement ?? ''}\n            </div>\n          </>\n        )}\n        {viewportNode}\n      </>\n    );\n\n    return (\n      <>\n        <span ref={anchorRef} style={{ display: 'none' }} aria-hidden=\"true\" />\n        {modalDialogHost ? createPortal(portaledContent, modalDialogHost) : portaledContent}\n      </>\n    );\n  },\n);\n\n(ToastViewport as unknown as { f12IsToastViewport?: boolean }).f12IsToastViewport = true;\n\nexport interface ToastProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {\n  status?: ToastStatus;\n  title?: React.ReactNode;\n  description?: React.ReactNode;\n  glyph?: string | false;\n  srLabel?: string | false;\n  action?: React.ReactNode;\n  duration?: number;\n  resetKey?: number;\n  paused?: boolean;\n  dismissible?: boolean;\n  dismissLabel?: string;\n  density?: ToastDensity;\n  onDismiss?: () => void;\n}\n\nexport const Toast = React.forwardRef<HTMLDivElement, ToastProps>(function Toast(\n  {\n    id,\n    status = 'neutral',\n    title,\n    description,\n    glyph,\n    srLabel,\n    action,\n    duration,\n    resetKey = 0,\n    paused: controlledPaused,\n    dismissible = true,\n    dismissLabel = 'Dismiss notification',\n    density,\n    onDismiss,\n    role: userRole,\n    'aria-live': userAriaLive,\n    className = '',\n    onMouseEnter,\n    onMouseLeave,\n    onFocusCapture,\n    onBlurCapture,\n    onKeyDown,\n    children,\n    ...rest\n  },\n  forwardedRef,\n) {\n  const ctx = React.useContext(ToastContext);\n  const inViewport = React.useContext(ToastInViewportContext);\n  const toastRef = React.useRef<HTMLDivElement | null>(null);\n  const [hovered, setHovered] = React.useState(false);\n  const [focused, setFocused] = React.useState(false);\n\n  const effectiveDensity = density ?? ctx?.density ?? 'comfortable';\n  const isCompact = effectiveDensity === 'compact';\n  const fallbackDefault = ctx?.defaultDuration ?? 5000;\n  const effectiveDuration =\n    duration ??\n    (onDismiss\n      ? action && fallbackDefault > 0\n        ? Math.max(fallbackDefault, 10000)\n        : fallbackDefault\n      : 0);\n  const isPaused = Boolean(\n    controlledPaused ??\n      (inViewport && ctx\n        ? ctx.viewportPaused || ctx.documentHidden\n        : (ctx?.documentHidden ?? false) || hovered || focused),\n  );\n\n  const initialRemaining =\n    id && ctx?.getRemainingDuration\n      ? ctx.getRemainingDuration(id, effectiveDuration)\n      : effectiveDuration;\n  const remainingRef = React.useRef<number>(initialRemaining);\n  const prevResetKeyRef = React.useRef<number>(resetKey);\n  const prevDurationRef = React.useRef<number>(effectiveDuration);\n  const startedAtRef = React.useRef<number>(Date.now());\n  const onDismissRef = React.useRef(onDismiss);\n  onDismissRef.current = onDismiss;\n\n  const setRemainingDuration = ctx?.setRemainingDuration;\n\n  React.useEffect(() => {\n    if (prevResetKeyRef.current !== resetKey || prevDurationRef.current !== effectiveDuration) {\n      prevResetKeyRef.current = resetKey;\n      prevDurationRef.current = effectiveDuration;\n      remainingRef.current = effectiveDuration;\n      if (id && setRemainingDuration) {\n        setRemainingDuration(id, effectiveDuration);\n      }\n    }\n    if (\n      !onDismissRef.current ||\n      !effectiveDuration ||\n      effectiveDuration <= 0 ||\n      !Number.isFinite(effectiveDuration)\n    ) {\n      return;\n    }\n    if (isPaused) {\n      return;\n    }\n    startedAtRef.current = Date.now();\n    const waitMs = Math.max(0, remainingRef.current);\n    const timer = window.setTimeout(() => {\n      remainingRef.current = 0;\n      if (id && setRemainingDuration) {\n        setRemainingDuration(id, 0);\n      }\n      onDismissRef.current?.();\n    }, waitMs);\n\n    return () => {\n      window.clearTimeout(timer);\n      const elapsed = Date.now() - startedAtRef.current;\n      const nextRemaining = Math.max(0, remainingRef.current - elapsed);\n      remainingRef.current = nextRemaining;\n      if (id && setRemainingDuration) {\n        setRemainingDuration(id, nextRemaining);\n      }\n    };\n  }, [isPaused, effectiveDuration, resetKey, id, setRemainingDuration]);\n\n  const setRefs = React.useCallback(\n    (node: HTMLDivElement | null) => {\n      toastRef.current = node;\n      if (typeof forwardedRef === 'function') {\n        forwardedRef(node);\n      } else if (forwardedRef) {\n        (forwardedRef as React.MutableRefObject<HTMLDivElement | null>).current = node;\n      }\n    },\n    [forwardedRef],\n  );\n\n  const resolvedGlyph =\n    glyph === false\n      ? undefined\n      : glyph !== undefined\n        ? glyph\n        : STATUS_GLYPHS[status];\n\n  const resolvedSrLabel =\n    srLabel === false\n      ? undefined\n      : srLabel !== undefined\n        ? srLabel\n        : STATUS_SR_LABELS[status];\n\n  const combinedText = `${extractTextContent(title)} ${extractTextContent(description)} ${extractTextContent(children)}`.trim();\n  const showSrLabel =\n    Boolean(resolvedSrLabel) &&\n    !(\n      combinedText &&\n      resolvedSrLabel &&\n      startsWithStatusLabel(combinedText, resolvedSrLabel, status)\n    );\n\n  const itemCtx = React.useMemo(\n    () => ({ id, onDismiss }),\n    [id, onDismiss],\n  );\n\n  return (\n    <ToastItemContext.Provider value={itemCtx}>\n      <div\n        ref={setRefs}\n        id={id}\n        role={userRole}\n        aria-live={userAriaLive}\n        aria-atomic={userRole || userAriaLive ? 'true' : undefined}\n        data-status={status}\n        data-paused={isPaused ? 'true' : 'false'}\n        data-density={isCompact ? 'compact' : undefined}\n        className={`f12-toast f12-toast-${status} f12-enter${isCompact ? ' f12-toast-compact' : ''}${className ? ` ${className}` : ''}`}\n        onMouseEnter={(e) => {\n          onMouseEnter?.(e);\n          setHovered(true);\n        }}\n        onMouseLeave={(e) => {\n          onMouseLeave?.(e);\n          setHovered(false);\n        }}\n        onFocusCapture={(e) => {\n          onFocusCapture?.(e);\n          setFocused(true);\n        }}\n        onBlurCapture={(e) => {\n          onBlurCapture?.(e);\n          if (!toastRef.current?.contains(e.relatedTarget as Node | null)) {\n            setFocused(false);\n          }\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e);\n          if (e.key === 'Escape' && !e.defaultPrevented && dismissible && onDismiss) {\n            e.preventDefault();\n            e.stopPropagation();\n            onDismiss();\n          }\n        }}\n        {...rest}\n      >\n        {resolvedGlyph && (\n          <span className=\"f12-toast-glyph f12-status-glyph\" aria-hidden=\"true\">\n            {resolvedGlyph}\n          </span>\n        )}\n        <div className=\"f12-toast-body\">\n          {showSrLabel && <span className=\"f12-sr-only\">{`${resolvedSrLabel}: `}</span>}\n          {title && <div className=\"f12-toast-title\">{title}</div>}\n          {description && <div className=\"f12-toast-description\">{description}</div>}\n          {children}\n        </div>\n        {(action || (dismissible && onDismiss)) && (\n          <div className=\"f12-toast-controls\">\n            {action}\n            {dismissible && onDismiss && (\n              <ToastClose aria-label={dismissLabel} />\n            )}\n          </div>\n        )}\n      </div>\n    </ToastItemContext.Provider>\n  );\n});\n\nexport type ToastTitleProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport const ToastTitle = React.forwardRef<HTMLDivElement, ToastTitleProps>(function ToastTitle(\n  { className = '', children, ...rest },\n  ref,\n) {\n  return (\n    <div ref={ref} className={`f12-toast-title${className ? ` ${className}` : ''}`} {...rest}>\n      {children}\n    </div>\n  );\n});\n\nexport type ToastDescriptionProps = React.HTMLAttributes<HTMLDivElement>;\n\nexport const ToastDescription = React.forwardRef<HTMLDivElement, ToastDescriptionProps>(\n  function ToastDescription({ className = '', children, ...rest }, ref) {\n    return (\n      <div\n        ref={ref}\n        className={`f12-toast-description${className ? ` ${className}` : ''}`}\n        {...rest}\n      >\n        {children}\n      </div>\n    );\n  },\n);\n\nexport interface ToastActionProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {\n  altText?: string;\n}\n\nexport const ToastAction = React.forwardRef<HTMLButtonElement, ToastActionProps>(\n  function ToastAction({ altText, 'aria-label': userAriaLabel, className = '', children, ...rest }, ref) {\n    return (\n      <button\n        ref={ref}\n        type=\"button\"\n        aria-label={userAriaLabel}\n        data-alt-text={altText}\n        className={`f12-toast-action${className ? ` ${className}` : ''}`}\n        {...rest}\n      >\n        {children}\n      </button>\n    );\n  },\n);\n\nexport type ToastCloseProps = React.ButtonHTMLAttributes<HTMLButtonElement>;\n\nexport const ToastClose = React.forwardRef<HTMLButtonElement, ToastCloseProps>(function ToastClose(\n  { 'aria-label': ariaLabel = 'Dismiss notification', className = '', onClick, children, ...rest },\n  ref,\n) {\n  const itemCtx = React.useContext(ToastItemContext);\n  return (\n    <button\n      ref={ref}\n      type=\"button\"\n      aria-label={ariaLabel}\n      className={`f12-toast-close${className ? ` ${className}` : ''}`}\n      onClick={(e) => {\n        onClick?.(e);\n        if (!e.defaultPrevented) {\n          itemCtx?.onDismiss?.();\n        }\n      }}\n      {...rest}\n    >\n      {children ?? <span aria-hidden=\"true\">×</span>}\n    </button>\n  );\n});\n",
      "type": "registry:ui",
      "target": "components/frame12/toast.tsx"
    }
  ],
  "type": "registry:ui"
}