{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toaster",
  "title": "Toaster",
  "description": "Shows the toasts you send with `toast(\"Saved\")` from `@/lib/ouro/toast`: render it once, at the root of your app, inside `OuroProvider` if you use one, or alone.",
  "dependencies": [
    "@base-ui/react@^1.8.0"
  ],
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-focus-handoff",
    "@ouro/lib-keep-clear",
    "@ouro/lib-keep-focus-clear",
    "@ouro/lib-portal-container",
    "@ouro/lib-refs",
    "@ouro/lib-spring",
    "@ouro/lib-toast",
    "@ouro/lib-touch-target",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-drag",
    "@ouro/lib-use-reduced-motion"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/toast/toaster-styles.ts",
      "content": "export { actionClass, closeClass, contentClass, iconTones, portalClass, rootClass, viewportClass };\n\n// Class strings for Toaster, apart from the component so its file exports only components\n// (React Fast Refresh). Class strings are literal so the app's Tailwind finds them when it\n// compiles.\n\n/**\n * The portal: its own stacking context one level above `--ouro-layer`, so a toast shows\n * over an open Dialog or Sheet.\n *\n * @internal\n */\nconst portalClass = \"relative isolate z-[calc(var(--ouro-layer)+1)]\";\n\n/**\n * The fixed region the toasts stack in: full width at the bottom of a phone, inside the\n * safe area, and spacing-scale 90 at the bottom end from `sm`. Each overridable\n * property has one unprefixed utility, so app layout classes win at every width.\n * Universal and named scales compile independently: an unavailable candidate\n * is omitted, preserving the phone value at sm. Same-element [&] variants\n * retain distinct candidates through cn: two for the universal path, one for\n * the later named path. Both share the same variant group, so sm still wins\n * over phone values. Neither path introduces a global spacing default.\n *\n * @internal\n * @claim \"Each overridable property has one unprefixed\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > lets unprefixed app clearance and width win on the actual viewport at phone and desktop widths)\n * @claim \"The fixed region the toasts stack\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::spans the phone's width at the bottom, inside a 16px margin)\n * @claim \"Same-element [&] variants retain distinct candidates\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > keeps named spacing-scale values on the viewport as well as the universal spacing fallback)\n */\nconst viewportClass =\n  \"group/toaster fixed outline-none [--ouro-toast-dir:-1] data-[edge=top]:[--ouro-toast-dir:1] \" +\n  \"start-(--ouro-toaster-start) end-(--ouro-toaster-end) bottom-(--ouro-toaster-bottom) w-(--ouro-toaster-width) \" +\n  // A move to the top cross-fades: the stack fades out, moves while invisible and fades back in, so it never slides across the screen.\n  \"transition-opacity duration-(--ouro-duration-fast) ease-(--ouro-ease-out) data-[ouro-toaster-fading]:opacity-0 \" +\n  \"data-[ouro-toaster-moved=top]:!top-(--ouro-toaster-moved-top) data-[ouro-toaster-moved=top]:!bottom-auto \" +\n  \"[&]:[&]:[--ouro-toaster-start:var(--spacing-4,--spacing(4))] [&]:[--ouro-toaster-start:--theme(--spacing-4)] \" +\n  \"[&]:[&]:[--ouro-toaster-end:var(--spacing-4,--spacing(4))] [&]:[--ouro-toaster-end:--theme(--spacing-4)] \" +\n  \"[--ouro-toaster-bottom:max(1rem,env(safe-area-inset-bottom))] [--ouro-toaster-width:auto] \" +\n  \"sm:[&]:[--ouro-toaster-start:auto] \" +\n  \"sm:[&]:[&]:[--ouro-toaster-end:var(--spacing-6,--spacing(6))] sm:[&]:[--ouro-toaster-end:--theme(--spacing-6)] \" +\n  \"sm:[&]:[&]:[--ouro-toaster-bottom:var(--spacing-6,--spacing(6))] sm:[&]:[--ouro-toaster-bottom:--theme(--spacing-6)] \" +\n  \"sm:[&]:[&]:[--ouro-toaster-width:var(--spacing-90,--spacing(90))] sm:[&]:[--ouro-toaster-width:--theme(--spacing-90)]\";\n\n/**\n * One toast. Collapsed, the newest is in front and the older ones peek out behind it, smaller,\n * toward the middle of the screen (above it at the bottom edge, below it at the top); hovering or\n * focusing the stack (`data-expanded`) fans them out the same way. Base UI sets\n * `--toast-index`, `--toast-offset-y` and `--toast-height`. The swipe (`useSwipeAway`)\n * moves the toast with `translate`, which adds to this `transform` and is not in the\n * transition, so it follows the finger at once. A swiped toast (`data-ouro-swiped`)\n * fades on the way it was thrown; a toast closed any other way slides back out past its edge. With\n * reduced motion nothing slides or springs: toasts fade in and out where they are.\n * A toast swipes away toward its edge (down at the bottom, up at the top) as well as sideways, so\n * it takes every touch gesture (`touch-none`, not `touch-pan-y`): otherwise a swipe on a\n * scrollable page scrolls the page, and the browser cancels the swipe.\n *\n * @internal\n * @claim \"A toast swipes away toward its edge\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n * @claim \"A toast swipes away toward its edge\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > goes back to rest when the browser cancels the touch, however far out it was)\n * @claim \"A toast swipes away toward its edge\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::pausing > pauses while the pointer is over the toasts, and resumes after)\n * @claim \"Collapsed, the newest is in front\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::pausing > pauses while the pointer is over the toasts, and resumes after)\n * @claim \"Collapsed, the newest is in front\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::waits while a finger is on a toast, and fans the stack out, as a mouse over it does)\n */\nconst rootClass =\n  \"absolute inset-x-0 bottom-0 box-border origin-bottom touch-none \" +\n  // At the top edge (the viewport's `data-edge=\"top\"`) the stack hangs from the top and unfurls downward:\n  // `--ouro-toast-dir` turns every offset below toward the screen's middle.\n  \"group-data-[edge=top]/toaster:top-0 group-data-[edge=top]/toaster:bottom-auto group-data-[edge=top]/toaster:origin-top \" +\n  \"select-none [-webkit-tap-highlight-color:transparent] \" +\n  \"rounded-ouro-lg border border-solid border-border bg-popover text-popover-foreground shadow-(--shadow-lg) \" +\n  \"outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"[--gap:0.75rem] [--peek:0.75rem] [--scale:calc(max(0,1-(var(--toast-index)*0.1)))] [--shrink:calc(1-var(--scale))] \" +\n  \"[--height:var(--toast-frontmost-height,var(--toast-height))] \" +\n  \"[--offset-y:calc(var(--ouro-toast-dir)*(var(--toast-offset-y)+var(--toast-index)*var(--gap)))] \" +\n  \"z-[calc(1000-var(--toast-index))] h-(--height) data-expanded:h-(--toast-height) \" +\n  \"[transform:translateY(calc(var(--ouro-toast-dir)*(var(--toast-index)*var(--peek)+var(--shrink)*var(--height))))_scale(var(--scale))] \" +\n  \"data-expanded:[transform:translateY(var(--offset-y))] \" +\n\n  \"data-starting-style:opacity-0 data-ending-style:opacity-0 data-limited:opacity-0 \" +\n  \"motion-safe:data-starting-style:[transform:translateY(calc(var(--ouro-toast-dir)*-150%))] motion-safe:data-expanded:data-starting-style:[transform:translateY(calc(var(--ouro-toast-dir)*-150%))] \" +\n  \"motion-safe:[&[data-ending-style]:not([data-limited]):not([data-ouro-swiped])]:[transform:translateY(calc(var(--ouro-toast-dir)*-150%))] \" +\n  \"motion-safe:[transition:transform_var(--ouro-duration-slow)_var(--ouro-ease-out),opacity_var(--ouro-duration-base)_var(--ouro-ease-out)] \" +\n  \"motion-reduce:[transition:opacity_var(--ouro-duration-base)_var(--ouro-ease-out)]\";\n\n/**\n * The toast's content. Toasts behind the front one hide theirs until the stack fans out.\n *\n * @internal\n */\nconst contentClass =\n  \"flex h-full items-start gap-3 overflow-hidden p-4 transition-opacity duration-(--ouro-duration-base) ease-(--ouro-ease-out) \" +\n  \"data-behind:opacity-0 data-expanded:opacity-100 \" +\n  // A strip bridges the gap between a fanned-out toast and the one in front of it (below it at the\n  // bottom edge, above it at the top), so moving between them keeps the stack open. The front toast\n  // has none, so no dead strip sits over the page beside the stack. Positioned against the toast.\n  \"data-expanded:data-behind:after:absolute data-expanded:data-behind:after:inset-x-0 data-expanded:data-behind:after:top-full \" +\n  \"data-expanded:data-behind:after:h-[calc(var(--gap)+1px)] data-expanded:data-behind:after:content-[''] \" +\n  \"group-data-[edge=top]/toaster:data-expanded:data-behind:after:top-auto group-data-[edge=top]/toaster:data-expanded:data-behind:after:bottom-full\";\n\n/**\n * The action button: a quiet bordered button, 44px to touch on a coarse pointer.\n *\n * @internal\n * @claim \"The action button: a quiet bordered\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::gives the dismiss and action buttons 44px touch targets)\n */\nconst actionClass =\n  \"press relative m-0 -my-1 box-border inline-flex h-9 shrink-0 items-center justify-center rounded-ouro-md border border-solid border-border \" +\n  \"bg-transparent px-3 text-base font-medium text-foreground pointer-fine:h-8 pointer-fine:text-sm whitespace-nowrap \" +\n  \"cursor-pointer touch-manipulation outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground motion-safe:active:scale-(--ouro-press-scale)\";\n\n/**\n * The dismiss button: a small icon button with a 44px touch target on a coarse pointer.\n *\n * @internal\n * @claim \"The dismiss button: a small icon\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::gives the dismiss and action buttons 44px touch targets)\n * @claim \"The dismiss button: a small icon\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > closes from the dismiss button)\n */\nconst closeClass =\n  \"press relative m-0 -me-1 -mt-1 box-border inline-flex size-7 shrink-0 items-center justify-center rounded-ouro-md border-0 bg-transparent p-0 \" +\n  \"text-muted-foreground cursor-pointer touch-manipulation outline-ring outline-offset-2 focus-visible:outline-2 focus-visible:outline-solid \" +\n  \"pointer-fine:hover:bg-accent pointer-fine:hover:text-accent-foreground motion-safe:active:scale-(--ouro-press-scale)\";\n\n/**\n * The icon color for each tone. `secondary` has no icon.\n *\n * @internal\n * @claim \"The icon color for each tone\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > marks the tone and shows an icon for every tone but secondary)\n * @claim \"`secondary` has no icon\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > marks the tone and shows an icon for every tone but secondary)\n */\nconst iconTones = {\n  primary: \"text-primary\",\n  success: \"text-success\",\n  warning: \"text-warning\",\n  destructive: \"text-destructive\",\n} as const;\n",
      "type": "registry:ui",
      "target": "@components/ouro/toast/toaster-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/toast/toaster.tsx",
      "content": "\"use client\";\n\nimport { Toast } from \"@base-ui/react/toast\";\nimport type { BaseUIEvent } from \"@base-ui/react/types\";\nimport { memo, useCallback, useEffect, useLayoutEffect, useRef, useState, type FocusEvent, type JSX, type MouseEvent as ReactMouseEvent, type PointerEvent as ReactPointerEvent } from \"react\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { devWarn } from \"@/registry/ouro/lib/ouro/dev\";\nimport { useFocusHandoff, type FocusHandoffOptions } from \"@/registry/ouro/lib/ouro/focus-handoff\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { rubberband, spring, type SpringHandle } from \"@/registry/ouro/lib/ouro/spring\";\nimport { connectToaster, type ToastRecord } from \"@/registry/ouro/lib/ouro/toast\";\nimport { keepClear } from \"@/registry/ouro/lib/ouro/keep-clear\";\nimport { keepFocusClear, type FocusClearHandle } from \"@/registry/ouro/lib/ouro/keep-focus-clear\";\nimport { TouchTarget } from \"@/registry/ouro/lib/ouro/touch-target\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useDrag, type DragState } from \"@/registry/ouro/lib/ouro/use-drag\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\nimport { PortalScope } from \"@/registry/ouro/lib/ouro/portal-container\";\nimport {\n  actionClass,\n  closeClass,\n  contentClass,\n  iconTones,\n  portalClass,\n  rootClass,\n  viewportClass,\n} from \"@/registry/ouro/components/ouro/toast/toaster-styles\";\n\n/** Props for {@link Toaster}. */\nexport interface ToasterProps {\n  /**\n   * Layout classes on the actual portaled toast viewport, not on each toast.\n   * For example, `bottom-[calc(5rem+max(1rem,env(safe-area-inset-bottom)))]`\n   * clears persistent bottom controls. A bottom override replaces the default\n   * safe-area expression; include the appropriate inset in your own clearance.\n   * Use statically written classes matching your app's visibility/breakpoints,\n   * which need not match the Toaster's `sm` breakpoint.\n   * @claim \"Layout classes on the actual portaled\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > updates viewport layout without replacing or reannouncing a live toast or resetting its countdown)\n   * @claim \"Layout classes on the actual portaled\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > lets unprefixed app clearance and width win on the actual viewport at phone and desktop widths)\n   */\n  className?: string | undefined;\n  /**\n   * The name screen readers give the region the toasts appear in. Translate it with the\n   * rest of your interface.\n   * @default \"Notifications\"\n   */\n  label?: string | undefined;\n  /**\n   * The accessible name of each toast's dismiss button, which shows an icon only.\n   * @default \"Dismiss\"\n   * @claim \"The accessible name of each toast's\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > translates the region name and the dismiss button with label and closeLabel)\n   */\n  closeLabel?: string | undefined;\n  /**\n   * A CSS selector for controls the toasts must stay clear of, such as a call's Join button in a\n   * corner. While one is on screen in the lower half of the window, under the toasts' column, the\n   * toasts rise to sit 8px above it, and they come back down when it goes. They measure again when\n   * the page changes outside the toasts and when the window resizes. Mark the controls and\n   * pass the selector: `<Toaster avoid=\"[data-keep-clear]\" />`. It clears controls for a toaster at\n   * the bottom only; at the top, the app's own top offset (`className=\"top-18 bottom-auto\"`) keeps\n   * the toasts clear of its header.\n   * @claim \"While one is on screen in\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster avoid > keeps the toasts clear of a control the selector matches under them, and comes back down when it goes)\n   * @claim \"While one is on screen in\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster avoid > stays where it is for a matched control away from its column or in the window's top half)\n   * @claim \"While one is on screen in\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster avoid > measures again when the window resizes: a control beside the column on a wide screen is under it on a phone)\n   * @claim \"They measure again when\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster avoid > measures again when the window resizes: a control beside the column on a wide screen is under it on a phone)\n   */\n  avoid?: string | undefined;\n\n  /** Not a prop. Toasts default to the bottom: full width on phones, at the bottom end from `sm`; className adjusts viewport layout. */\n  position?: { 'Not a prop: toasts show at the bottom. Use <Toaster />': never };\n  /**\n   * Not a prop. Each toast takes its own `tone`: `toast(\"Saved\", { tone: \"success\" })`.\n   *\n   * @claim \"Each toast takes its own `tone`\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > marks the tone and shows an icon for every tone but secondary)\n   */\n  richColors?: { 'Use toast(\"Saved\", { tone: \"success\" })': never };\n  /** Not a prop. Dark mode follows the `.dark` class, as in shadcn. */\n  theme?: { 'Not a prop: dark mode follows the .dark class. Use <Toaster />': never };\n  /**\n   * Not a prop. Each toast takes its own `duration`: `toast(\"Saved\", { duration: 8000 })`.\n   *\n   * @claim \"Each toast takes its own `duration`\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > dismisses itself after duration; 0 and Infinity keep it)\n   */\n  duration?: { 'Use toast(\"Saved\", { duration: 8000 })': never };\n}\n\n/**\n * Shows the toasts you send with `toast(\"Saved\")` from `@/lib/ouro/toast`: render it\n * once, at the root of your app, inside `OuroProvider` if you use one, or alone. Adding\n * Toaster installs `toast` with it. Toasts stack at the\n * bottom of the screen, full width on phones by default; `className` adjusts viewport\n * layout/clearance, not each toast's appearance. Up to three show, and later ones wait their\n * turn, a `destructive` toast ahead of the others. They pause while the pointer is over them or a toast has focus, F6 moves focus to\n * them, newest first, and a swipe down or sideways dismisses one: a toast follows the\n * finger, a quick flick is enough, and one let go short of that springs back. Each toast is read to\n * screen readers once, its message and description: politely, and a `destructive` toast\n * assertively, so it interrupts. Every toast and its buttons stay reachable by screen readers, a\n * touch screen reader too, while the stack is collapsed, and focus in a toast fans the stack out\n * and pauses it, however it got there, even while a pointer passes over and away.\n *\n * Put it at the top with layout classes (`className=\"top-4 bottom-auto\"`) and the stack hangs\n * from the top: the newest toast is at the top, older ones peek out below it, it fans out\n * downward, toasts slide in from above, and a swipe up dismisses one.\n *\n * At the bottom edge, keyboard focus stays clear of the stack. The page scrolls a control into view\n * above it. If focus from the keyboard still lands under the stack, the stack moves to the top edge\n * unless the top edge would cover the control too, and it moves back once focus has left and the\n * stack has rested. A pointer's focus does not move it to the top.\n *\n * Render one Toaster. A second one warns in development and shows nothing until the\n * first unmounts, then takes over.\n *\n * The viewport is portaled to the body. A variable set only on an app-shell wrapper\n * does not reach it: put app clearance variables on a real ancestor of the portal\n * (such as `:root`) or declare them through the viewport's supplied classes.\n * Do not construct arbitrary-value class names from runtime numbers. A width override\n * changes the width, not the anchoring mode or centering. Bottom overrides replace\n * the default phone safe-area expression; the app owns its clearance and safe area.\n * Shared `--popover`, `--popover-foreground` and `--radius` theme tokens style the\n * toast surface and also affect other components; a wrapper cannot style this portal.\n *\n * Use `Alert` instead for a message that stays on the page, and `Dialog` when the user\n * must answer before going on.\n *\n * @claim \"Put it at the top with layout\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::Toaster > hangs from the top and unfurls downward when its layout classes put it at the top)\n * @claim \"At the bottom edge, keyboard focus stays clear\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard focus under the stack > lets the browser scroll a control above a stack in the middle of the page, and leaves the stack at the bottom)\n * @claim \"The page scrolls a control into view\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard focus under the stack > lets the browser scroll a control above a stack in the middle of the page, and leaves the stack at the bottom)\n * @claim \"the stack moves to the top edge\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard focus under the stack > moves the stack to the top when focus lands under it at the page's end, and back once focus has left and it has rested)\n * @claim \"and it moves back once focus has left\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard focus under the stack > moves the stack to the top when focus lands under it at the page's end, and back once focus has left and it has rested)\n * @claim \"A pointer's focus does not move it\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard focus under the stack > does not move the stack for a pointer click on a control it covers)\n * @group Feedback\n * @see https://ui.ouroboros.bot/docs/toaster\n *\n * @example\n * <OuroProvider>\n *   <App />\n *   <Toaster />\n * </OuroProvider>\n * // Anywhere in the app:\n * toast(\"Recipe saved\", { tone: \"success\" });\n * @claim \"Toasts stack at the bottom of\" registry/ouro/components/ouro/toast/toaster.tsx verify:fileLine(registry/ouro/components/ouro/toast/toaster.tsx, /^import\\s\\{\\sconnectToaster,\\stype\\sToastRecord\\s\\}\\sfrom\\s\"@\\/registry\\/ouro\\/lib\\/ouro\\/toast\";/)\n * @claim \"Up to three show, and later\" registry/ouro/components/ouro/toast/toaster.tsx verify:fileLine(registry/ouro/components/ouro/toast/toaster.tsx, /^import\\s\\{\\sconnectToaster,\\stype\\sToastRecord\\s\\}\\sfrom\\s\"@\\/registry\\/ouro\\/lib\\/ouro\\/toast\";/)\n * @claim \"They pause while the pointer is\" registry/ouro/components/ouro/toast/toaster.tsx verify:fileLine(registry/ouro/components/ouro/toast/toaster.tsx, /^import\\s\\{\\sconnectToaster,\\stype\\sToastRecord\\s\\}\\sfrom\\s\"@\\/registry\\/ouro\\/lib\\/ouro\\/toast\";/)\n * @claim \"Each toast is read to screen\" registry/ouro/components/ouro/toast/toaster.tsx verify:fileLine(registry/ouro/components/ouro/toast/toaster.tsx, /^import\\s\\{\\sconnectToaster,\\stype\\sToastRecord\\s\\}\\sfrom\\s\"@\\/registry\\/ouro\\/lib\\/ouro\\/toast\";/)\n * @claim \"Every toast and its buttons stay\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps every toast, its action and its dismiss button reachable by a screen reader while the stack rests collapsed)\n * @claim \"and focus in a toast fans\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > fans the stack out and waits while focus is in a toast though no key moved it there, as a screen reader moves it, and folds it when focus leaves)\n * @claim \"and focus in a toast fans\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps the stack fanned out and waiting while focus is in a toast and a pointer passes over and away)\n * @claim \"Each toast is read to screen\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > is announced once, its message and description only: politely, and a destructive toast assertively (Review Focus 5))\n * @claim \"They pause while the pointer is\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::pausing > pauses while the pointer is over the toasts, and resumes after)\n * @claim \"They pause while the pointer is\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::pausing > pauses while a toast has keyboard focus; F6 moves focus to the toasts)\n * @claim \"Toasts stack at the bottom of\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n * @claim \"Up to three show, and later\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n * @claim \"They pause while the pointer is\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n * @claim \"Each toast is read to screen\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n */\nexport function Toaster(props: ToasterProps): JSX.Element | null {\n  const { className, label = \"Notifications\", closeLabel = \"Dismiss\", avoid, position, richColors, theme, duration } = props;\n  const viewportElement = useRef<HTMLElement | null>(null);\n  const edgeRef = useCallback(\n    (element: HTMLElement | null) => {\n      viewportElement.current = element;\n      return readEdge(element);\n    },\n    // Stryker disable next-line ArrayDeclaration: any list that never changes keeps the same ref, as this one does.\n    [],\n  );\n  // Read the edge again when the layout classes change, as they may move the toasts to the other edge.\n  const classed = useRef(className);\n  useLayoutEffect(() => {\n    // The mount's read comes from the viewport's observer, once the page is laid out, not from the commit.\n    // Stryker disable next-line ConditionalExpression: equivalent; the effect runs only when className changes, and on mount the viewport is not yet mounted, so viewportElement.current is null and nothing is read.\n    if (classed.current === className) return;\n    classed.current = className;\n    /* istanbul ignore else @preserve -- the viewport mounts once Connect reports active, in the first commit's passive effects, before any later className change */\n    if (viewportElement.current) markEdge(viewportElement.current);\n  }, [className]);\n  const [active, setActive] = useState(false);\n  useAppearanceClassNameCheck(\n    \"Toaster\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? \":root { --popover: var(--background); --popover-foreground: var(--foreground); --radius: 0.5rem; } (shared theme tokens affect other components too)\"\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n    process.env.NODE_ENV !== \"production\"\n      ? \"Toaster owns toast-content alignment; use <Toaster /> without the alignment class\"\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Toaster\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          position !== undefined && [\"position is not a prop; toasts show at the bottom, full width on phones\", \"<Toaster />\"],\n          richColors !== undefined && [\"richColors is not a prop\", 'toast(\"Saved\", { tone: \"success\" })'],\n          theme !== undefined && [\"theme is not a prop; dark mode follows the .dark class\", \"<Toaster />\"],\n          duration !== undefined && [\"duration is not a prop\", `toast(\"Saved\", { duration: ${String(duration)} })`],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  // Stryker disable next-line ConditionalExpression: without a selector it would match the tag name \"undefined\", which no page has.\n  const keepingClear = avoid !== undefined && <KeepClear avoid={avoid} />;\n  return (\n    <Toast.Provider limit={VISIBLE}>\n      <Connect onActive={setActive} />\n      {active && (\n        <Toast.Portal className={portalClass}>\n          <PortalScope>\n            <Toast.Viewport\n              aria-label={label}\n              // Not a live region: the announcer inside speaks each toast, so the buttons in the\n              // toasts are never read out as they arrive and need not be hidden to stay quiet.\n              aria-live={undefined}\n              aria-atomic={undefined}\n              aria-relevant={undefined}\n              data-ouro=\"toaster\"\n              ref={edgeRef}\n              className={cn(viewportClass, className)}\n              onFocus={onViewportFocus}\n              onBlur={onViewportBlur}\n              onMouseLeave={onViewportMouseLeave}\n            >\n              <ToastList closeLabel={closeLabel} />\n              <ToastAnnouncer />\n              {keepingClear}\n            </Toast.Viewport>\n          </PortalScope>\n        </Toast.Portal>\n      )}\n    </Toast.Provider>\n  );\n}\n\n/**\n * Keeps the toasts' viewport clear of the elements `avoid` matches (see keepClear). It lives in the\n * viewport, so it runs while there are toasts.\n */\nfunction KeepClear({ avoid }: { avoid: string }): JSX.Element {\n  const mark = useRef<HTMLSpanElement | null>(null);\n  useEffect(() => keepClear(mark.current!.closest<HTMLElement>('[data-ouro=\"toaster\"]')!, avoid), [avoid]);\n  return <span ref={mark} hidden data-ouro-toaster-keep-clear=\"\" />;\n}\n\n/**\n * Keeps keyboard focus clear of the toasts (see keepFocusClear). It lives in the viewport while there\n * are toasts, and measures again whenever they change.\n */\nfunction FocusClear({ toasts }: { toasts: readonly unknown[] }): JSX.Element {\n  const mark = useRef<HTMLSpanElement | null>(null);\n  const keeper = useRef<FocusClearHandle | undefined>(undefined);\n  useLayoutEffect(() => {\n    keeper.current?.refresh();\n  }, [toasts]);\n  useEffect(\n    () => {\n      const handle = keepFocusClear(mark.current!.closest<HTMLElement>('[data-ouro=\"toaster\"]')!);\n      keeper.current = handle;\n      return () => handle.release();\n    },\n    // Stryker disable next-line ArrayDeclaration: any list that never changes runs it once, as this one does.\n    [],\n  );\n  return <span ref={mark} hidden data-ouro-toaster-focus-clear=\"\" />;\n}\n\n/** Whether a toast waits ahead of the others: a destructive one. */\nconst urgent = (record: ToastRecord) => record.tone === \"destructive\";\n\n/** How many toasts show at once; later ones wait in the Toaster's queue. */\nconst VISIBLE = 3;\n/** How many toasts may wait before development warns that the app sends too many; more may still wait. */\nconst MAX_WAITING_HINT = 10;\n\n/**\n * Connects this Toaster to `toast()`. Up to three toasts are in Base UI's manager at a time;\n * later ones wait here, first in first out, and are added, with their countdown, when a\n * slot frees. Another Toaster already connected keeps this one waiting until it unmounts.\n * @claim \"Up to three toasts are in\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > queues: up to three show, and later ones wait, out of the page, until a slot frees)\n * @claim \"Up to three toasts are in\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > starts a waiting toast's countdown only when it shows, so it shows for its full duration and is announced once)\n */\nfunction Connect({ onActive }: { onActive: (active: boolean) => void }): null {\n  // add and close are the store's own methods, stable for the Toaster's life. The queue\n  // lives as long as the Toaster too, across StrictMode's second effect run.\n  const { add, close } = Toast.useToastManager();\n  const state = useRef({ shown: new Set<string>(), queue: [] as ToastRecord[] });\n  const key = useRef({});\n  useEffect(() => {\n    const { shown } = state.current;\n    const next = () => {\n      while (shown.size < VISIBLE && state.current.queue.length > 0) {\n        const [record, ...rest] = state.current.queue;\n        state.current.queue = rest;\n        show(record!);\n      }\n    };\n    const show = (record: ToastRecord) => {\n      shown.add(record.id);\n      add({\n        id: record.id,\n        title: record.message,\n        description: record.description,\n        type: record.tone,\n        timeout: record.timeout,\n        // Never Base UI's \"high\": it hides such a toast, buttons and all, from screen readers until\n        // focused, and speaks it from an alert of its own. ToastAnnouncer speaks a destructive toast\n        // assertively instead, and the toast stays reachable.\n        // Stryker disable next-line StringLiteral: Base UI treats every priority but \"high\" as \"low\".\n        priority: \"low\",\n        onRemove: () => {\n          shown.delete(record.id);\n          // Base UI removes the toast by its index after this call returns, so adding the\n          // next one here would shift the list under it; add it once the removal is done.\n          queueMicrotask(next);\n        },\n        actionProps: record.action\n          ? {\n              children: (\n                <>\n                  <TouchTarget />\n                  {record.action.label}\n                </>\n              ),\n              onClick: () => {\n                record.action!.onClick();\n                close(record.id);\n              },\n            }\n          : undefined,\n      });\n    };\n    const { disconnect, active } = connectToaster({\n      add: (record) => {\n        const { queue } = state.current;\n        const waiting = queue.find((item) => item.id === record.id);\n        if (shown.has(record.id)) show(record);\n        else if (waiting && urgent(waiting) === urgent(record)) state.current.queue = queue.map((item) => (item.id === record.id ? record : item));\n        else {\n          // Destructive toasts wait ahead of the others, first in first out among themselves;\n          // they never push out a toast that is showing. A waiting toast replaced with a tone\n          // that changes its group moves to the end of the destructive ones.\n          const rest = queue.filter((item) => item.id !== record.id);\n          const firstOther = rest.findIndex((item) => !urgent(item));\n          const end = firstOther === -1 ? rest.length : firstOther;\n          const at = urgent(record) || waiting ? end : rest.length;\n          state.current.queue = [...rest.slice(0, at), record, ...rest.slice(at)];\n          next();\n          /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n          if (process.env.NODE_ENV !== \"production\" && state.current.queue.length > MAX_WAITING_HINT) {\n            devWarn(\n              \"Toaster\",\n              `more than ${MAX_WAITING_HINT} toasts are waiting to show`,\n              'send fewer toasts, or update one in place with toast(\"…\", { id })',\n              key.current,\n            );\n          }\n        }\n      },\n      close: (id) => {\n        state.current.queue = id === undefined ? [] : state.current.queue.filter((item) => item.id !== id);\n        if (id === undefined || shown.has(id)) close(id);\n      },\n      activate: () => onActive(true),\n    });\n    /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n    if (!active && process.env.NODE_ENV !== \"production\") {\n      devWarn(\n        \"Toaster\",\n        \"another <Toaster /> is already mounted, so this one shows toasts only after that one unmounts\",\n        \"render <Toaster /> once, at the root of your app\",\n        key.current,\n      );\n    }\n    return () => {\n      disconnect();\n      onActive(false);\n    };\n  }, [add, close, onActive]);\n  return null;\n}\n\n/**\n * The toasts, newest first in the page as Base UI orders them, so F6 then Tab reaches the\n * newest and goes on to each older one. Each is announced as it arrives.\n * @claim \"The toasts, newest first in the\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > puts the newest toast first in the page, where F6 then Tab reaches it, then each older one)\n * @claim \"The toasts, newest first in the\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::keyboard > reaches and runs the oldest toast's action with F6, then Tab)\n * @claim \"Each is announced as it arrives\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > is announced once, its message and description only: politely, and a destructive toast assertively (Review Focus 5))\n * @claim \"Each is announced as it arrives\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > starts a waiting toast's countdown only when it shows, so it shows for its full duration and is announced once)\n */\nfunction ToastList({ closeLabel }: { closeLabel: string }): JSX.Element {\n  const { toasts } = Toast.useToastManager();\n  // Read the edge again as toasts come and go: the app's own CSS may have moved the toaster since.\n  useLayoutEffect(() => {\n    // With no toasts there is nothing to swipe or unfurl, and a read would lay the page out for nothing.\n    if (toasts.length > 0) markEdge(document.querySelector<HTMLElement>('[data-ouro=\"toaster\"]')!);\n  }, [toasts.length]);\n  return (\n    <>\n      {toasts.map((item) => (\n        <ToastItem key={item.id} item={item} closeLabel={closeLabel} />\n      ))}\n      {\n        // Stryker disable next-line ConditionalExpression,EqualityOperator: with no toasts the keeper measures nothing and moves nothing; the check only spares its listeners while none show.\n        toasts.length > 0 && <FocusClear toasts={toasts} />\n      }\n    </>\n  );\n}\n\ntype ToastObject = ReturnType<typeof Toast.useToastManager>[\"toasts\"][number];\n\n/**\n * Where focus was before it entered each toast region, so a toast that leaves with it can send it back there.\n *\n * @claim \"Where focus was before it entered\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > hands focus to %s when its dismiss button closes it from the keyboard)\n */\nconst cameFrom = new WeakMap<Element, HTMLElement>();\n\nfunction rememberEntry(event: FocusEvent<HTMLElement>): void {\n  const from = event.relatedTarget;\n  // Focus that comes from nowhere (a handoff from a toast that left, after focus fell to <body>)\n  // keeps the place it entered from.\n  if (from instanceof HTMLElement && !event.currentTarget.contains(from)) cameFrom.set(event.currentTarget, from);\n}\n\n/**\n * Marks the viewport with the edge it sits at, `data-edge=\"top\"` or `\"bottom\"`, from where its\n * layout classes put it: its top edge above the window's middle, or not (a bottom toaster `avoid` lifted stays at the bottom). The stack unfurls away from that\n * edge, and a toast swipes away toward it. Read again when the window is resized, when Toaster's className changes and as toasts come and go.\n */\nfunction markEdge(viewport: HTMLElement): void {\n  // keepClear (`avoid`) lifts a bottom toaster with an inline `bottom`, which can raise it past the\n  // middle: it is still at the bottom. A stack keepFocusClear moved to the top is at the top, whatever\n  // its position says.\n  let edge = \"top\";\n  if (!viewport.hasAttribute(\"data-ouro-toaster-moved\") && (viewport.style.bottom || viewport.getBoundingClientRect().top >= window.innerHeight / 2)) edge = \"bottom\";\n  if (viewport.getAttribute(\"data-edge\") !== edge) viewport.setAttribute(\"data-edge\", edge);\n}\n\nfunction readEdge(viewport: HTMLElement | null): (() => void) | undefined {\n  /* istanbul ignore if @preserve -- React 19 calls a ref that returns a cleanup only with the element */\n  // Stryker disable next-line ConditionalExpression,BooleanLiteral: React 19 calls a ref that returns a cleanup only with the element.\n  if (!viewport) return undefined;\n  const read = () => markEdge(viewport);\n  // An observer's first callback comes once the page is laid out, where reads are free.\n  const sizes = new ResizeObserver(read);\n  sizes.observe(viewport);\n  window.addEventListener(\"resize\", read);\n  return () => {\n    sizes.disconnect();\n    window.removeEventListener(\"resize\", read);\n  };\n}\n\n/**\n * Focus in the toasts fans the stack out and pauses it, however it came. Base UI does so only for\n * keyboard focus (`:focus-visible`), so a screen reader that moves focus to a toast behind the\n * front one, or a script, would leave it covered and fading out while it is read. A hover says the\n * same to Base UI, so the region gets one, as a finger's press does in `useSwipeAway`.\n *\n * @claim \"Focus in the toasts fans the stack out\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > fans the stack out and waits while focus is in a toast though no key moved it there, as a screen reader moves it, and folds it when focus leaves)\n */\nfunction onViewportFocus(event: FocusEvent<HTMLElement>): void {\n  rememberEntry(event);\n  hover(event.currentTarget, true);\n}\n\n/**\n * Tells Base UI's region that a pointer came in or left (its onMouseEnter and onMouseLeave), and\n * no component around the Toaster. React makes both from `mouseout`: one from the region's\n * parent, Base UI's portal node, to the region enters the region alone, and one back leaves it\n * alone. The page sees only that `mouseout`, between two nodes of the toasts, and no move.\n *\n * @claim \"and no component around the Toaster\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > tells nothing outside the toasts that a pointer came or went when focus fans the stack out and folds it)\n * @claim \"The page sees only that `mouseout`\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > tells nothing outside the toasts that a pointer came or went when focus fans the stack out and folds it)\n */\nfunction hover(region: HTMLElement, entering: boolean): void {\n  // Base UI always renders the region in its portal node.\n  const parent = region.parentElement!;\n  const [from, to] = entering ? [parent, region] : [region, parent];\n  from.dispatchEvent(new MouseEvent(\"mouseout\", { bubbles: true, relatedTarget: to }));\n}\n\n/**\n * A pointer leaving the toasts leaves the stack fanned out while focus is in one, as Base UI\n * does for keyboard focus; focus leaving folds it then.\n *\n * @claim \"A pointer leaving the toasts leaves\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps the stack fanned out and waiting while focus is in a toast and a pointer passes over and away)\n */\nfunction onViewportMouseLeave(event: BaseUIEvent<ReactMouseEvent<HTMLElement>>): void {\n  if (event.currentTarget.contains(document.activeElement)) event.preventBaseUIHandler();\n}\n\n/**\n * Focus that leaves a toast folds the stack, unless the pointer is over it. Focus moving on to\n * another toast fans it out again in the same task, so React renders no fold between.\n *\n * @claim \"Focus that leaves a toast folds the stack\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps the stack fanned out while focus moves from toast to toast, and while the pointer is over it after focus leaves)\n * @claim \"Focus moving on to another toast\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps the stack fanned out while focus moves from toast to toast, and while the pointer is over it after focus leaves)\n */\nfunction onViewportBlur(event: FocusEvent<HTMLElement>): void {\n  const region = event.currentTarget;\n  if (!region.matches(\":hover\")) hover(region, false);\n}\n\n/** How long a live region is on the page before it is given text: Safari drops text added to a newer one (see `announce`). */\nconst LIVE_REGION_SETTLE_MS = 100;\n\n/**\n * How long a toast's words stay in the live regions once said: long enough to be read out, then\n * they leave, so a screen reader moving through the Notifications landmark meets each toast once.\n *\n * @claim \"How long a toast's words stay\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > says a description's words without copying its link, and lets the words go a few seconds after they are said)\n */\nconst SPOKEN_FOR_MS = 7000;\n\n/** Visually hidden, but read. Inline, so it works without the stylesheet. */\nconst visuallyHidden = {\n  position: \"absolute\",\n  width: \"1px\",\n  height: \"1px\",\n  margin: \"-1px\",\n  padding: \"0\",\n  border: \"0\",\n  overflow: \"hidden\",\n  clip: \"rect(0 0 0 0)\",\n  clipPath: \"inset(50%)\",\n  whiteSpace: \"nowrap\",\n} as const;\n\n/** What the live regions say for one toast: its words as shown, and when they were first said. */\ninterface Spoken {\n  id: string;\n  /** Changes when the toast is replaced with new words, so the new ones are an addition. */\n  key: string;\n  destructive: boolean;\n  lines: string[];\n  at: number;\n}\n\n/**\n * What screen readers hear as a toast shows: its message and description, once, from a polite\n * live region, or an assertive one (`role=\"alert\"`) for a destructive toast, so it interrupts. A\n * toast replaced in place is heard again with its new words, and one that leaves says nothing.\n * The regions hold only the words, read from the toast as shown, so a link or button in a\n * description is never there twice, and the words leave after a few seconds. The toasts\n * themselves are not a live region, so their action and dismiss buttons are never read out as\n * they arrive, and nothing in them needs hiding: a touch screen reader reaches every toast and\n * button. The regions sit last in the Notifications landmark, after the toasts they speak for.\n *\n * @claim \"What screen readers hear as a\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > is announced once, its message and description only: politely, and a destructive toast assertively (Review Focus 5))\n * @claim \"A toast replaced in place is\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > announces a toast again when it is replaced with new text, and not when it leaves)\n * @claim \"The regions hold only the words\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > says a description's words without copying its link, and lets the words go a few seconds after they are said)\n * @claim \"a touch screen reader reaches every\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > keeps every toast, its action and its dismiss button reachable by a screen reader while the stack rests collapsed)\n */\nfunction ToastAnnouncer(): JSX.Element {\n  const { toasts } = Toast.useToastManager();\n  const anchor = useRef<HTMLDivElement>(null);\n  const settled = useSettled();\n  // Stryker disable next-line ArrayDeclaration: an entry with no time is never shown, and the first reading of the toasts replaces the list.\n  const [spoken, setSpoken] = useState<Spoken[]>([]);\n  // Read after the toasts are on the page and before it paints, so each toast's words arrive whole.\n  useLayoutEffect(() => {\n    if (!settled) return;\n    const region = anchor.current!.closest('[data-ouro=\"toaster\"]')!;\n    setSpoken((before) => wordsOf(region, toasts, before, Date.now()));\n  }, [settled, toasts]);\n  const current = useUnexpired(spoken);\n  return (\n    <div ref={anchor} data-ouro-toast-announcer=\"\" style={visuallyHidden}>\n      <div aria-live=\"polite\" aria-relevant=\"additions text\">\n        <SpokenWords entries={current.filter((entry) => !entry.destructive)} />\n      </div>\n      <div role=\"alert\" aria-live=\"assertive\" aria-atomic=\"false\" aria-relevant=\"additions text\">\n        <SpokenWords entries={current.filter((entry) => entry.destructive)} />\n      </div>\n    </div>\n  );\n}\n\n/** Whether the live regions have been on the page LIVE_REGION_SETTLE_MS, so text given to them is read. */\nfunction useSettled(): boolean {\n  const [settled, setSettled] = useState(false);\n  useEffect(\n    () => {\n      const timer = setTimeout(() => setSettled(true), LIVE_REGION_SETTLE_MS);\n      // Stryker disable next-line ArrowFunction: React ignores a state set after unmount, so clearing only tidies.\n      return () => clearTimeout(timer);\n    },\n    // Stryker disable next-line ArrayDeclaration: any list that never changes runs it once, as this one does.\n    [],\n  );\n  return settled;\n}\n\n/**\n * The toasts' words as `region` shows them, leaving out a toast with none. A toast whose words are\n * unchanged keeps its entry from `before`, so they are not said again.\n *\n * @claim \"leaving out a toast with none\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > says nothing for a toast with no words, and only the description of one with no message)\n * @claim \"A toast whose words are unchanged\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > says a toast's words once while other toasts come and go)\n */\nfunction wordsOf(region: Element, toasts: ToastObject[], before: Spoken[], at: number): Spoken[] {\n  return toasts\n    .map((item) => ({ item, lines: shownLines(region, item.id) }))\n    .filter(({ lines }) => lines.length > 0)\n    .map(({ item, lines }) => {\n      const was = before.find((entry) => entry.id === item.id);\n      if (was && JSON.stringify(was.lines) === JSON.stringify(lines)) return was;\n      return { id: item.id, key: `${item.id} ${at}`, destructive: item.type === \"destructive\", lines, at };\n    });\n}\n\n/** The message and description the toast with this id shows in `region`, leaving out an empty one. */\nfunction shownLines(region: Element, id: string): string[] {\n  // ToastList renders every toast the manager lists, so each is on the page by now.\n  const shown = [...region.querySelectorAll(\"[data-ouro-toast-id]\")].find((element) => element.getAttribute(\"data-ouro-toast-id\") === id)!;\n  return [shown.querySelector(\"[data-ouro-toast-title]\")?.textContent ?? \"\", shown.querySelector(\"[data-ouro-toast-description]\")?.textContent ?? \"\"].filter(Boolean);\n}\n\n/** The words not yet said for SPOKEN_FOR_MS, rendering again when the oldest of them is due to go. */\nfunction useUnexpired(spoken: Spoken[]): Spoken[] {\n  const [now, setNow] = useState(0);\n  const current = spoken.filter((entry) => now - entry.at < SPOKEN_FOR_MS);\n  const first = Math.min(...current.map((entry) => entry.at));\n  useEffect(() => {\n    if (first === Infinity) return;\n    const timer = setTimeout(() => setNow(first + SPOKEN_FOR_MS), first + SPOKEN_FOR_MS - Date.now());\n    // Stryker disable next-line ArrowFunction: a timer left from an earlier first sets the time it was due, already past, so it hides nothing early.\n    return () => clearTimeout(timer);\n  }, [first]);\n  return current;\n}\n\n/** The toasts' words in one live region, a line to a message or description. */\nfunction SpokenWords({ entries }: { entries: Spoken[] }): JSX.Element[] {\n  return entries.map((entry) => (\n    <div key={entry.key}>\n      {entry.lines.map((line, index) => (\n        <div key={index}>{line}</div>\n      ))}\n    </div>\n  ));\n}\n\n/**\n * A toast hands focus to the next toast, and never past its region to some other control of the\n * page (a footer link): when it was the last, focus goes back where it was before it entered the\n * toasts, or stays on the page when it came from nowhere.\n *\n * @claim \"A toast hands focus to the next toast\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > hands focus to %s when its dismiss button closes it from the keyboard) verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > leaves focus on the page when the last toast goes and focus came from nowhere, rather than moving it to the page's last control)\n */\nfunction toastHandoff(element: HTMLDivElement): FocusHandoffOptions {\n  const region = element.closest('[data-ouro=\"toaster\"]')!;\n  return { within: region, fallback: cameFrom.get(region) ?? null };\n}\n\n/**\n * One toast. The swipe is Ouro's own, so Base UI's is off. Memoised so that a toast whose object\n * Base UI kept skips the render when another toast leaves.\n */\nconst ToastItem = memo(function ToastItem({ item, closeLabel }: { item: ToastObject; closeLabel: string }): JSX.Element {\n  const { close } = Toast.useToastManager();\n  const destructive = item.type === \"destructive\";\n  const swipe = useSwipeAway(() => close(item.id), item.transitionStatus === \"ending\");\n  // A toast its dismiss button or action closes hands focus to the next toast, or back to the page.\n  const ref = useMergedRef(swipe.ref, useFocusHandoff<HTMLDivElement>(toastHandoff));\n  return (\n    <Toast.Root\n      toast={item}\n      swipeDirection={NO_SWIPE}\n      {...swipe}\n      ref={ref}\n      data-ouro=\"toast\"\n      data-ouro-toast-id={item.id}\n      data-tone={item.type}\n      // A destructive toast is an alertdialog, an urgent part of its own.\n      role={destructive ? \"alertdialog\" : \"dialog\"}\n      data-ouro-control=\"toaster\"\n      data-ouro-part={destructive ? \"alert\" : \"toast\"}\n      className={rootClass}\n    >\n      <Toast.Content className={contentClass}>\n        <ToneIcon tone={item.type} />\n        <div className=\"grid min-w-0 flex-1 gap-0.5\">\n          <Toast.Title render={<div />} data-ouro-toast-title=\"\" className=\"m-0 text-sm font-medium text-popover-foreground\" />\n          <Toast.Description render={<div />} data-ouro-toast-description=\"\" className=\"m-0 text-sm text-muted-foreground\" />\n        </div>\n        <Toast.Action data-ouro-control=\"toaster\" data-ouro-part=\"action\" className={actionClass} />\n        {/* Base UI hides this from assistive technology while the stack is collapsed. A touch\n            screen reader could then never reach it, since it cannot focus or hover the stack first. */}\n        <Toast.Close aria-label={closeLabel} aria-hidden={undefined} data-ouro-control=\"toaster\" data-ouro-part=\"close\" className={closeClass}>\n          <TouchTarget />\n          <svg aria-hidden=\"true\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" className=\"size-4\">\n            <path d=\"M4 4l8 8M12 4l-8 8\" />\n          </svg>\n        </Toast.Close>\n      </Toast.Content>\n    </Toast.Root>\n  );\n});\n\nconst NO_SWIPE: [] = [];\n/** How far, in px, a toast let go without a flick must be from rest to leave. */\nconst AWAY = 40;\n/**\n * A press on one of these never starts a swipe: the action, the dismiss button, a link or a control in the message, and anything an app marks `data-swipe-ignore`. The list Base UI's swipe used.\n *\n * @claim \"A press on one of these\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::swiping > takes its press from the first pointer: a second one on a button does not stop the swipe, and one that began on a button starts none)\n * @claim \"A press on one of these\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::swiping > starts no swipe from content marked data-swipe-ignore or data-base-ui-swipe-ignore, as before)\n */\nconst CONTROLS = 'button,a,input,textarea,[role=\"button\"],[data-base-ui-swipe-ignore],[data-swipe-ignore]';\n\ntype Axis = \"x\" | \"y\";\n\n/**\n * The swipe that dismisses a toast: sideways either way, or down, off the edge it came in\n * from. The toast follows the finger from where it is taken, after 10px that choose the\n * axis. Up is the one way it cannot leave, so there it follows less and less. Let go, a\n * flick away from rest dismisses it however short, and so does a release more than 40px\n * from rest that is not on its way back; anything else springs back from where it is,\n * with the speed it was let go at, and can be caught again on the way. A dismissed toast\n * goes on the way it was thrown while it fades. With reduced motion it still follows the\n * finger, then returns or fades with no travel.\n *\n * The offset is the element's `translate`, which adds to the `transform` the stack sets.\n * @claim \"The toast follows the finger from\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > moves 1:1 from where it was taken, either way, once 10px have chosen sideways)\n * @claim \"With reduced motion it still follows\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > moves 1:1 from where it was taken, either way, once 10px have chosen sideways)\n * @claim \"The toast follows the finger from\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > is taken without a jump when caught above rest, where it was held back)\n * @claim \"With reduced motion it still follows\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > is taken without a jump when caught above rest, where it was held back)\n */\nfunction useSwipeAway(dismiss: () => void, ending: boolean) {\n  const reduced = useReducedMotion();\n  const state = useRef<SwipeState>({ element: null, axis: null, offset: 0, grab: 0, pressed: { x: false, y: false }, moved: false, leaving: false, control: false, settle: undefined });\n\n  /**\n   * Whether a y offset points back past rest, the one way a toast cannot leave: up at the bottom\n   * edge, down at the top (the viewport's `data-edge`).\n   */\n  const inward = useCallback(\n    // Stryker disable next-line EqualityOperator: at an offset of 0 the band and its inverse are both 0, so < and <= agree.\n    (offset: number) => (state.current.element!.closest('[data-edge=\"top\"]') !== null ? offset > 0 : offset < 0),\n    // Stryker disable next-line ArrayDeclaration: it reads only the element, so any list that never changes keeps it the same.\n    [],\n  );\n  /** Whether a y offset points the way a toast leaves: down at the bottom edge, up at the top. */\n  const outward = useCallback(\n    // Stryker disable next-line EqualityOperator: an offset of 0 is at rest, where a release settles whichever way it counts.\n    (offset: number) => (state.current.element!.closest('[data-edge=\"top\"]') !== null ? offset < 0 : offset > 0),\n    // Stryker disable next-line ArrayDeclaration: it reads only the element, so any list that never changes keeps it the same.\n    [],\n  );\n  const write = useCallback((offset: number) => {\n    const now = state.current;\n    now.offset = offset;\n    now.element!.style.translate = offset === 0 ? \"\" : now.axis === \"x\" ? `${offset}px 0px` : `0px ${offset}px`;\n  }, []);\n  /** The toast's size along the axis: what a rubber band stretches against, and how far out a dismissed toast is thrown. */\n  const size = useCallback(() => {\n    const { axis, element } = state.current;\n    return axis === \"x\" ? element!.offsetWidth : element!.offsetHeight;\n  }, []);\n  const settle = useCallback(\n    (velocity = 0, flick = false) => {\n      const now = state.current;\n      now.settle = spring({\n        from: now.offset,\n        to: 0,\n        velocity,\n        damping: flick ? 0.8 : 1,\n        element: now.element,\n        reduced,\n        onUpdate: write,\n        onRest: () => {\n          now.axis = null;\n        },\n      });\n    },\n    [write, reduced],\n  );\n\n  // A toast sent again with the id of one that is on its way out comes back on the same\n  // element (Base UI keeps it). It starts over: at rest, not swiped, and the finger's to take.\n  useLayoutEffect(() => {\n    const now = state.current;\n    if (ending || !now.leaving) return;\n    now.settle?.stop();\n    now.leaving = false;\n    now.element!.removeAttribute(\"data-ouro-swiped\");\n    write(0);\n    now.axis = null;\n  }, [ending, write]);\n\n  // Two drags, one per axis, on the one element: the first to move 10px its way has the toast.\n  const press = useCallback((axis: Axis, event: PointerEvent) => {\n    const now = state.current;\n    now.pressed[axis] = true;\n    now.moved = false;\n    // A press on a control holds the toast still, as any press does, so the tap lands; it starts no swipe.\n    now.control = (event.target as Element).closest(CONTROLS) !== null;\n    // Hold still under the finger, where the spring had brought it.\n    now.settle?.stop();\n  }, []);\n  const pressEnd = useCallback(\n    (axis: Axis) => {\n      const now = state.current;\n      now.pressed[axis] = false;\n      // Neither axis took the press: carry on back to rest.\n      if (!now.pressed.x && !now.pressed.y && !now.moved && now.offset !== 0) settle();\n    },\n    [settle],\n  );\n  const start = useCallback(\n    (axis: Axis) => {\n      const now = state.current;\n      // One drag at a time, and a toast caught off rest moves along the axis it is off on.\n      if (now.control || now.moved || (now.offset !== 0 && now.axis !== axis)) return false;\n      now.axis = axis;\n      now.moved = true;\n      now.pressed[axis] = false;\n      // Above rest the toast is held back: start from the finger travel that puts it there.\n      // Stryker disable next-line ConditionalExpression,EqualityOperator,LogicalOperator,StringLiteral: a toast caught mid-band is a finger's move; the touch tests take it above rest without a jump.\n      now.grab = axis === \"y\" && inward(now.offset) ? unband(now.offset, size()) : now.offset;\n      return true;\n    },\n    // Stryker disable next-line ArrayDeclaration: these callbacks never change, so any list keeps this one the same.\n    [size, inward],\n  );\n  const move = useCallback(\n    (axis: Axis, { delta }: DragState) => {\n      const wanted = state.current.grab + delta;\n      // Following a finger is not an animation: the toast does it with reduced motion too.\n      write(axis === \"y\" && inward(wanted) ? rubberband(wanted, size()) : wanted);\n    },\n    // Stryker disable next-line ArrayDeclaration: these callbacks never change, so any list keeps this one the same.\n    [size, write, inward],\n  );\n  const end = (axis: Axis, { velocity, flick, cancelled }: DragState & { cancelled: boolean }) => {\n    const now = state.current;\n    const { offset } = now;\n    // Whether the finger was moving the toast away from rest when it lifted.\n    const toward = velocity * offset;\n    const canLeave = axis === \"x\" || outward(offset);\n    if (cancelled || !canLeave || !(flick ? toward > 0 : Math.abs(offset) > AWAY && toward >= 0)) return settle(cancelled ? 0 : velocity, flick && !cancelled);\n    now.leaving = true;\n    // Before the close: a swiped toast fades on its way, and does not slide down as a closed one does.\n    now.element!.setAttribute(\"data-ouro-swiped\", \"\");\n    // With reduced motion it fades where it is.\n    if (!reduced) {\n      now.settle = spring({ from: offset, to: offset + Math.sign(offset) * size() * 1.5, velocity, onUpdate: write });\n    }\n    dismiss();\n  };\n  const x = useDrag({\n    axis: \"x\",\n    onPress: (event) => press(\"x\", event),\n    onPressEnd: () => pressEnd(\"x\"),\n    onStart: () => start(\"x\"),\n    onMove: (drag) => move(\"x\", drag),\n    onEnd: (drag) => end(\"x\", drag),\n  });\n  const y = useDrag({\n    axis: \"y\",\n    // The toast takes every touch (`touch-none`), so no move is a scroll: sideways travel is the other drag's.\n    crossAxis: \"ignore\",\n    onPress: (event) => press(\"y\", event),\n    onPressEnd: () => pressEnd(\"y\"),\n    onStart: () => start(\"y\"),\n    onMove: (drag) => move(\"y\", drag),\n    onEnd: (drag) => end(\"y\", drag),\n  });\n\n  const ref = useCallback(\n    (element: HTMLDivElement) => {\n      state.current.element = element;\n      const detachX = x.ref(element);\n      const detachY = y.ref(element);\n      return () => {\n        // A toast removed on its way out, or on its way back, stops there.\n        state.current.settle?.stop();\n        detachX!();\n        detachY!();\n      };\n    },\n    [x, y],\n  );\n  const onPointerDown = useCallback(\n    (event: ReactPointerEvent<HTMLElement>) => {\n      // Base UI pauses the toasts and fans them out while a mouse is over them. A finger has no\n      // hover, so its press says the same: the toasts wait while one is held or read.\n      // The event is where the finger is, for an app that follows the mouse.\n      if (event.pointerType !== \"mouse\") {\n        const { clientX, clientY, screenX, screenY } = event;\n        event.currentTarget.dispatchEvent(new MouseEvent(\"mousemove\", { bubbles: true, clientX, clientY, screenX, screenY }));\n      }\n      // A toast on its way out is no longer the finger's.\n      if (state.current.leaving) return;\n      x.onPointerDown(event);\n      y.onPointerDown(event);\n    },\n    [x, y],\n  );\n  // Sideways first, so a move that could start either drag starts that one.\n  const onPointerMove = useCallback(\n    (event: ReactPointerEvent<HTMLElement>) => {\n      x.onPointerMove(event);\n      y.onPointerMove(event);\n    },\n    [x, y],\n  );\n  const onPointerEnd = useCallback(\n    (event: ReactPointerEvent<HTMLElement>) => {\n      x.onPointerUp(event);\n      y.onPointerUp(event);\n    },\n    [x, y],\n  );\n  return { ref, onPointerDown, onPointerMove, onPointerUp: onPointerEnd, onPointerCancel: onPointerEnd };\n}\n\n/** What a toast's swipe keeps between events. */\ninterface SwipeState {\n  element: HTMLElement | null;\n  /** The axis of the drag, or of the offset a settle is bringing back. */\n  axis: Axis | null;\n  /** What is on screen, in px along `axis`. */\n  offset: number;\n  /** The finger travel that put the toast where it was taken. */\n  grab: number;\n  /**\n   * Which of the two drags, one per axis, still follows a press that has not chosen.\n   *\n   * @claim \"Which of the two drags, one\" registry/ouro/components/ouro/toast/toaster.touch.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.touch.test.tsx::the swipe follows the finger (rule 12) > moves 1:1 from where it was taken, either way, once 10px have chosen sideways)\n   */\n  pressed: { x: boolean; y: boolean };\n  /** Whether the press became a drag. */\n  moved: boolean;\n  leaving: boolean;\n  /** Whether the press is on one of the toast's controls. */\n  control: boolean;\n  settle: SpringHandle | undefined;\n}\n\n/** The finger travel past an end that `rubberband` turns into `shown`, for a toast `size` px along the axis. */\nfunction unband(shown: number, size: number, constant = 0.55): number {\n  return (shown * size) / (constant * (size - Math.abs(shown)));\n}\n\n/**\n * The tone's icon, drawn in the tone's color; `secondary` has none.\n *\n * @claim \"The tone's icon, drawn in the\" registry/ouro/components/ouro/toast/toaster.test.tsx verify:testExists(registry/ouro/components/ouro/toast/toaster.test.tsx::toast() > marks the tone and shows an icon for every tone but secondary)\n */\nfunction ToneIcon({ tone }: { tone: string | undefined }): JSX.Element | null {\n  if (tone === undefined || !Object.hasOwn(iconTones, tone)) return null;\n  const color = iconTones[tone as keyof typeof iconTones];\n  return (\n    <svg\n      aria-hidden=\"true\"\n      data-ouro-toast-icon=\"\"\n      viewBox=\"0 0 20 20\"\n      fill=\"none\"\n      stroke=\"currentColor\"\n      strokeWidth=\"1.75\"\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      className={cn(\"mt-px size-5 shrink-0\", color)}\n    >\n      {tone === \"success\" && (\n        <>\n          <circle cx=\"10\" cy=\"10\" r=\"8\" />\n          <path d=\"M6.5 10.25l2.25 2.25 4.75-5\" />\n        </>\n      )}\n      {tone === \"warning\" && (\n        <>\n          <path d=\"M10 2.75 1.75 17.25h16.5Z\" />\n          <path d=\"M10 8v4M10 14.75v.01\" />\n        </>\n      )}\n      {tone === \"destructive\" && (\n        <>\n          <circle cx=\"10\" cy=\"10\" r=\"8\" />\n          <path d=\"M10 6v4.5M10 13.75v.01\" />\n        </>\n      )}\n      {tone === \"primary\" && (\n        <>\n          <circle cx=\"10\" cy=\"10\" r=\"8\" />\n          <path d=\"M10 9v5M10 6.25v.01\" />\n        </>\n      )}\n    </svg>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/toast/toaster.tsx"
    }
  ],
  "docs": "Shows the toasts you send with `toast(\"Saved\")` from `@/lib/ouro/toast`: render it once, at the root of your app, inside `OuroProvider` if you use one, or alone. Import: import { Toaster } from \"@/components/ouro/toast/toaster\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/toaster.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}