{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "components-toast",
  "type": "registry:component",
  "title": "Toast",
  "description": "A stacked, auto-dismissing notification queue",
  "author": "sudo-kw <https://github.com/sudo-kw>",
  "dependencies": [
    "@gpuix/native@0.11.0",
    "@gpuix/react@0.11.0",
    "effect@4.1.2",
    "react@^19.2.4"
  ],
  "registryDependencies": [
    "https://gpuixui.sudokw.com/gpuix-icons.json",
    "https://gpuixui.sudokw.com/gpuix-motion.json",
    "https://gpuixui.sudokw.com/gpuix-primitives.json",
    "https://gpuixui.sudokw.com/gpuix-tokens.json",
    "https://gpuixui.sudokw.com/gpuix-tw.json"
  ],
  "files": [
    {
      "path": "packages/components/src/internal/button.tsx",
      "target": "@ui/gpuixui/components/internal/button.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { Props } from \"@gpuix/react\";\nimport type { ReactNode } from \"react\";\nimport {\n  Button as PrimitiveButton,\n  IconButton as PrimitiveIconButton,\n  actionOnColor as primitiveActionOnColor,\n  type ButtonVariant as PrimitiveVariant,\n} from \"../../primitives/button.js\";\nimport { cn } from \"../../tw/index.js\";\nimport * as Schema from \"effect/Schema\";\nimport type { Theme } from \"./theme.js\";\n\nconst ButtonVariants = Schema.Literals([\n  \"primary\",\n  \"secondary\",\n  \"ghost\",\n  \"danger\",\n  \"link\",\n]);\n\nexport type ButtonVariant = typeof ButtonVariants.Type;\n\nexport type ButtonSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface ButtonProps extends Props {\n  readonly variant?: ButtonVariant;\n\n  readonly size?: ButtonSize;\n\n  readonly disabled?: boolean;\n\n  readonly loading?: boolean;\n\n  readonly loadingLabel?: string;\n\n  readonly reducedMotion?: boolean;\n\n  readonly leading?: ReactNode;\n\n  readonly trailing?: ReactNode;\n}\n\nexport interface IconButtonProps extends Props {\n  readonly label: string;\n\n  readonly size?: ButtonSize;\n  readonly disabled?: boolean;\n}\n\ninterface Look {\n  readonly variant: PrimitiveVariant;\n  readonly className: string;\n}\n\nconst LOOKS: Readonly<Record<ButtonVariant, Look>> = {\n  primary: { variant: \"primary\", className: \"\" },\n  secondary: { variant: \"secondary\", className: \"border border-strong\" },\n  ghost: { variant: \"ghost\", className: \"\" },\n  danger: { variant: \"destructive\", className: \"\" },\n\n  link: { variant: \"link\", className: \"underline underline-offset-4\" },\n};\n\nconst lookOf = (variant: unknown): Look =>\n  LOOKS[Schema.is(ButtonVariants)(variant) ? variant : \"secondary\"];\n\nexport const actionOnColor = (theme: Theme, variant: ButtonVariant): string =>\n  primitiveActionOnColor(theme, lookOf(variant).variant);\n\nexport const Button = ({\n  variant = \"secondary\",\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  \"aria-label\": ariaLabel,\n  ...rest\n}: ButtonProps) => {\n  const look = lookOf(variant);\n  return (\n    <PrimitiveButton\n      {...rest}\n      variant={look.variant}\n      size={size}\n      disabled={disabled}\n      label={ariaLabel}\n      className={cn(look.className)}\n      onActivate={onClick}\n      style={style}\n    />\n  );\n};\n\nexport const IconButton = ({\n  label,\n  size = \"md\",\n  disabled = false,\n  onClick,\n  style,\n  children,\n  ...rest\n}: IconButtonProps) => (\n  <PrimitiveIconButton\n    {...rest}\n    icon={children}\n    variant=\"ghost\"\n    size={size}\n    disabled={disabled}\n    label={label}\n    className=\"text-muted-foreground hover:text-foreground\"\n    onActivate={onClick}\n    style={style}\n  />\n);\n"
    },
    {
      "path": "packages/components/src/internal/clock.ts",
      "target": "@ui/gpuixui/components/internal/clock.ts",
      "type": "registry:lib",
      "content": "import { Effect } from \"effect\";\nimport * as Clock from \"effect/Clock\";\n\nexport const monotonicNanos = (): bigint =>\n  Effect.runSync(Clock.monotonicTimeNanos);\n\nexport const hoverDelay = (value: number, fallback: number): number =>\n  Number.isFinite(value) ? Math.max(0, value) : fallback;\n"
    },
    {
      "path": "packages/components/src/internal/measure.ts",
      "target": "@ui/gpuixui/components/internal/measure.ts",
      "type": "registry:lib",
      "content": "import type { EventPayload } from \"@gpuix/react\";\nimport * as Option from \"effect/Option\";\n\nexport interface MeasuredBox {\n  readonly x: number;\n  readonly y: number;\n  readonly width: number;\n  readonly height: number;\n}\n\nconst measurable = (value: number | undefined): Option.Option<number> =>\n  Option.filter(Option.fromNullishOr(value), Number.isFinite);\n\nexport const measuredBox = (event: EventPayload): Option.Option<MeasuredBox> =>\n  Option.all({\n    x: measurable(event.x),\n    y: measurable(event.y),\n    width: measurable(event.width),\n    height: measurable(event.height),\n  });\n\nexport const measuredHeight = (event: EventPayload): Option.Option<number> =>\n  measurable(event.height);\n\nexport interface MeasuredPoint {\n  readonly x: number;\n  readonly y: number;\n}\n\nexport const measuredPoint = (\n  event: EventPayload,\n): Option.Option<MeasuredPoint> =>\n  Option.all({\n    x: measurable(event.x),\n    y: measurable(event.y),\n  });\n"
    },
    {
      "path": "packages/components/src/internal/overlay.ts",
      "target": "@ui/gpuixui/components/internal/overlay.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { cn } from \"../../tw/index.js\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport { recipeStyle } from \"./recipe.js\";\nimport {\n  alpha,\n  elevationShadow,\n  type BoxShadow,\n  type ElevationLevel,\n  type Theme,\n} from \"./theme.js\";\n\nexport const OVERLAY_WASH = 0.55;\n\nexport const overlayVeilColor = (theme: Theme): string =>\n  alpha(theme.colors.background, OVERLAY_WASH);\n\nconst isEdge = (shadow: BoxShadow): boolean =>\n  shadow.blurRadius === 0 && shadow.spreadRadius > 0;\n\nconst shadows = (painted: StyleDesc[\"boxShadow\"]): ReadonlyArray<BoxShadow> =>\n  Option.match(Option.fromNullishOr(painted), {\n    onNone: () => [],\n    onSome: (value) => Arr.ensure(value),\n  });\n\nexport const overlaySurfaceStyle = (\n  recipe: string,\n  className: string | undefined,\n  theme: Theme,\n  elevation?: ElevationLevel,\n): StyleDesc => {\n  const style = recipeStyle(cn(recipe, className), theme);\n  const lift = Option.fromNullishOr(elevation).pipe(\n    Option.flatMap((level) =>\n      Option.fromNullishOr(elevationShadow(theme, level)),\n    ),\n  );\n\n  return Option.match(lift, {\n    onNone: () => style,\n    onSome: (shadow) => {\n      const painted = shadows(style.boxShadow);\n      const lost = Arr.every(painted, isEdge) && painted.length > 0;\n      return lost ? { ...style, boxShadow: [shadow, ...painted] } : style;\n    },\n  });\n};\n"
    },
    {
      "path": "packages/components/src/internal/presence.tsx",
      "target": "@ui/gpuixui/components/internal/presence.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { MotionProps } from \"@gpuix/react\";\nimport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceMotion as motionOfPresence,\n  presenceStyle,\n  transitionWindowMs,\n  type PresenceFrames,\n  type PresenceHitRule,\n  type PresenceSide,\n  type PresenceTiming,\n  type PresenceTransition,\n} from \"../../motion/presence.js\";\nimport {\n  MotionProvider,\n  useMotionPreference,\n  useSurfacePresence,\n  useSurfaceTiming,\n  type MotionProviderProps,\n  type SurfacePresence,\n} from \"../../motion/react/presence.js\";\nimport {\n  motionTiming,\n  type MotionLevel,\n  type MotionPreference,\n} from \"../../motion/timing.js\";\n\nexport { MotionProvider, useMotionPreference, type MotionProviderProps };\n\nexport type SurfaceFrames = PresenceFrames;\n\nexport type SurfaceTiming = PresenceTiming;\n\nexport type PanelSide = PresenceSide;\n\nexport {\n  delayedTiming,\n  exitWindowMs,\n  fadeFrom,\n  fadeFromAnchor,\n  fadeFromSide,\n  fadeOnly,\n  presenceStyle,\n  transitionWindowMs,\n};\nexport type { PresenceHitRule };\n\nexport { useSurfacePresence, useSurfaceTiming, type SurfacePresence };\n\nexport const moveTiming = (\n  level: MotionLevel,\n  preference: MotionPreference,\n): PresenceTransition => motionTiming(level, { phase: \"standard\", preference });\n\nexport const useMoveTiming = (level: MotionLevel): PresenceTransition =>\n  moveTiming(level, useMotionPreference());\n\nexport const presenceMotion = (\n  frames: SurfaceFrames,\n  presence: SurfacePresence,\n  timing: SurfaceTiming = presence.timing,\n): MotionProps => motionOfPresence(frames, presence.present, timing);\n\nexport const PresenceShield = ({ present }: { readonly present: boolean }) =>\n  present ? null : (\n    <div\n      testId=\"presence-shield\"\n      style={{ position: \"absolute\", top: 0, right: 0, bottom: 0, left: 0 }}\n    />\n  );\n\nexport const presenceTabStop = (\n  present: boolean,\n): { readonly tabIndex?: number } => (present ? {} : { tabIndex: -1 });\n"
    },
    {
      "path": "packages/components/src/internal/recipe.ts",
      "target": "@ui/gpuixui/components/internal/recipe.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport { createRecipeCache } from \"../../tw/index.js\";\nimport type { Theme } from \"./theme.js\";\n\nexport const recipeStyle: (recipe: string, theme: Theme) => StyleDesc =\n  createRecipeCache(512);\n"
    },
    {
      "path": "packages/components/src/internal/theme.ts",
      "target": "@ui/gpuixui/components/internal/theme.ts",
      "type": "registry:lib",
      "content": "import type { StyleDesc } from \"@gpuix/react\";\nimport * as Schema from \"effect/Schema\";\nimport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  brandTextOn,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  pointerWash,\n  selectionOn,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n  type BoxShadow,\n  type ElevationLevel,\n  type FindHighlightSource,\n  type NativeTextFill,\n  type PlatformName,\n  type PointerWashSurface,\n  type StatusTone,\n  type SyntaxColors,\n  type SyntaxRole,\n  type TextRole,\n  type Theme,\n  type ThemeColors,\n} from \"../../tokens/index.js\";\n\nexport {\n  alpha,\n  avatarPixels,\n  avatarSize,\n  controlFocusRing,\n  controlHeight,\n  controlPaddingX,\n  currentPlatform,\n  darkTheme,\n  disabledAction,\n  disabledOpacity,\n  elevationShadow,\n  filledHover,\n  filledPressed,\n  findHighlight,\n  focusRing,\n  keyboardFocusRing,\n  lightTheme,\n  nativeTextTheme,\n  statusTone,\n  syntaxColors,\n  targetSize,\n  textStyle,\n};\nexport type {\n  BoxShadow,\n  ElevationLevel,\n  FindHighlightSource,\n  NativeTextFill,\n  PlatformName,\n  StatusTone,\n  SyntaxColors,\n  SyntaxRole,\n  TextRole,\n  Theme,\n};\nexport { ThemeProvider, useTheme } from \"../../tokens/react.js\";\n\nexport const keyboardRing = (theme: Theme, invalid = false): StyleDesc =>\n  controlFocusRing(theme, { invalid }) ?? {};\n\nexport interface ControlRingState {\n  readonly disabled?: boolean;\n\n  readonly invalid?: boolean;\n}\n\nexport const controlRing = (\n  theme: Theme,\n  state: ControlRingState = {},\n): StyleDesc => controlFocusRing(theme, state) ?? {};\n\nexport const pressWash = (theme: Theme, replaced: PointerWashSurface): string =>\n  pointerWash(theme, \"active\", replaced) ?? theme.colors.active;\n\nexport const selectionWash = (theme: Theme): StyleDesc => ({\n  selectionColor: theme.colors.selection,\n});\n\nexport const keepContent: StyleDesc = { keyboardFocusDim: false };\n\nexport const disabledFade = (\n  disabled: boolean,\n): { readonly opacity: number } | undefined =>\n  disabled ? { opacity: disabledOpacity } : undefined;\n\nconst Tones = Schema.Literals([\"info\", \"success\", \"warning\", \"danger\"]);\n\nexport type Tone = typeof Tones.Type;\n\nexport const toneOf = (value: unknown): Tone =>\n  Schema.is(Tones)(value) ? value : \"info\";\n\nexport interface ToneStyle {\n  readonly fg: string;\n  readonly bg: string;\n  readonly border: string;\n}\n\nconst TOKEN_TONE: Readonly<Record<Tone, StatusTone>> = {\n  info: \"info\",\n  success: \"success\",\n  warning: \"warning\",\n  danger: \"destructive\",\n};\n\nexport const tone = (theme: Theme, value: Tone): ToneStyle => {\n  const { background, border, foreground } = statusTone(\n    theme,\n    TOKEN_TONE[value],\n  );\n  return { bg: background, border, fg: foreground };\n};\n\nconst softRoles: Readonly<Record<Tone, keyof ThemeColors>> = {\n  info: \"infoSoft\",\n  success: \"successSoft\",\n  warning: \"warningSoft\",\n  danger: \"destructiveSoft\",\n};\n\nexport const messageLink = (theme: Theme, value: Tone): string =>\n  brandTextOn(theme, softRoles[value]);\n\nexport const messageSelection = (theme: Theme, value: Tone): string =>\n  selectionOn(theme, softRoles[value]);\n\nexport const toneSurface = (theme: Theme, value: Tone): StyleDesc => {\n  const { bg, border, fg } = tone(theme, value);\n  return {\n    backgroundColor: bg,\n    color: fg,\n    borderWidth: theme.borderWidth.thin,\n    borderColor: border,\n  };\n};\n"
    },
    {
      "path": "packages/components/src/toast.tsx",
      "target": "@ui/gpuixui/components/toast.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nexport { ToastProvider, useToast } from \"./toast/provider.js\";\nexport type {\n  ToastApi,\n  ToastPromiseOptions,\n  ToastProviderProps,\n  ToastPushOptions,\n} from \"./toast/provider.js\";\nexport { ToastViewport, toastMeta } from \"./toast/viewport.js\";\nexport type { ToastViewportProps } from \"./toast/viewport.js\";\nexport type { ToastStoreOptions } from \"./toast/store.js\";\nexport {\n  Toast,\n  ToastInput,\n  ToastPhase,\n  ToastTone,\n  type ToastDraft,\n  type ToastPromiseStep,\n} from \"./toast/model.js\";\n"
    },
    {
      "path": "packages/components/src/toast/lifecycle.ts",
      "target": "@ui/gpuixui/components/toast/lifecycle.ts",
      "type": "registry:lib",
      "content": "export interface RuntimeLifecycle {\n  readonly mount: () => void;\n\n  readonly unmount: () => void;\n}\n\nexport const createRuntimeLifecycle = (\n  dispose: () => void,\n): RuntimeLifecycle => {\n  let active = false;\n  return {\n    mount: () => {\n      active = true;\n    },\n    unmount: () => {\n      active = false;\n      queueMicrotask(() => {\n        if (!active) dispose();\n      });\n    },\n  };\n};\n"
    },
    {
      "path": "packages/components/src/toast/model.ts",
      "target": "@ui/gpuixui/components/toast/model.ts",
      "type": "registry:lib",
      "content": "import { Effect } from \"effect\";\nimport * as Schema from \"effect/Schema\";\n\nexport const ToastTone = Schema.Literals([\n  \"info\",\n  \"success\",\n  \"warning\",\n  \"danger\",\n]);\n\nexport type ToastTone = typeof ToastTone.Type;\n\nexport const ToastPhase = Schema.Literals([\"loading\", \"settled\"]);\n\nexport type ToastPhase = typeof ToastPhase.Type;\n\nconst defaultTone: ToastTone = \"info\";\n\nconst defaultPhase: ToastPhase = \"settled\";\n\nconst DurationInput = Schema.Union([\n  Schema.Duration,\n  Schema.DurationFromMillis,\n]);\n\nexport class ToastAction extends Schema.Class<ToastAction>(\"ToastAction\")({\n  label: Schema.NonEmptyString,\n}) {}\n\nexport class ToastInput extends Schema.Class<ToastInput>(\"ToastInput\")({\n  title: Schema.NonEmptyString,\n  description: Schema.OptionFromOptionalKey(Schema.String),\n  action: Schema.OptionFromOptionalKey(ToastAction),\n  tone: ToastTone.pipe(Schema.withDecodingDefault(Effect.succeed(defaultTone))),\n  phase: ToastPhase.pipe(\n    Schema.withDecodingDefault(Effect.succeed(defaultPhase)),\n  ),\n  duration: Schema.OptionFromOptionalKey(DurationInput),\n}) {}\n\nexport type ToastDraft = typeof ToastInput.Encoded;\n\nexport type ToastPromiseStep<Value> =\n  | ToastDraft\n  | ((value: Value) => ToastDraft);\n\nexport const toastStep = <Value>(\n  step: ToastPromiseStep<Value>,\n  value: Value,\n): ToastDraft => (typeof step === \"function\" ? step(value) : step);\n\nexport class Toast extends Schema.Class<Toast>(\"Toast\")({\n  id: Schema.NonEmptyString,\n  title: Schema.NonEmptyString,\n  description: Schema.OptionFromOptionalKey(Schema.String),\n  action: Schema.OptionFromOptionalKey(ToastAction),\n  tone: ToastTone,\n  phase: ToastPhase,\n}) {}\n"
    },
    {
      "path": "packages/components/src/toast/provider.tsx",
      "target": "@ui/gpuixui/components/toast/provider.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport { Effect, Exit } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Cause from \"effect/Cause\";\nimport * as Fiber from \"effect/Fiber\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as ManagedRuntime from \"effect/ManagedRuntime\";\nimport * as Option from \"effect/Option\";\nimport * as Stream from \"effect/Stream\";\nimport {\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useMemo,\n  useState,\n  type ReactNode,\n} from \"react\";\nimport {\n  toastStep,\n  type Toast,\n  type ToastDraft,\n  type ToastPromiseStep,\n} from \"./model.js\";\nimport {\n  ToastStore,\n  layer as storeLayer,\n  type ToastStoreOptions,\n} from \"./store.js\";\nimport { createRuntimeLifecycle } from \"./lifecycle.js\";\n\nexport interface ToastPushOptions {\n  readonly onAction?: () => void;\n}\n\nexport interface ToastPromiseOptions<Value> {\n  readonly loading: ToastDraft;\n\n  readonly success: ToastPromiseStep<Value>;\n\n  readonly error: ToastPromiseStep<unknown>;\n}\n\nexport interface ToastApi {\n  readonly toasts: ReadonlyArray<Toast>;\n\n  readonly push: (draft: ToastDraft, options?: ToastPushOptions) => void;\n\n  readonly promise: <Value>(\n    source: Promise<Value>,\n    options: ToastPromiseOptions<Value>,\n  ) => Promise<Value>;\n  readonly dismiss: (id: string) => void;\n  readonly dismissAll: () => void;\n\n  readonly pause: (id: string) => void;\n\n  readonly resume: (id: string) => void;\n\n  readonly hold: (held: boolean) => void;\n\n  readonly actionFor: (id: string) => Option.Option<() => void>;\n}\n\nconst ToastContext = createContext<ToastApi | undefined>(undefined);\n\nexport const useToast = (): ToastApi => {\n  const value = useContext(ToastContext);\n  if (value === undefined) {\n    throw new Error(\"useToast must be used inside ToastProvider\");\n  }\n  return value;\n};\n\nexport interface ToastProviderProps extends ToastStoreOptions {\n  readonly children?: ReactNode;\n}\n\nexport const ToastProvider = ({\n  children,\n  max,\n  defaultDuration,\n}: ToastProviderProps) => {\n  const [runtime] = useState(() =>\n    ManagedRuntime.make(storeLayer({ max, defaultDuration })),\n  );\n  const [toasts, setToasts] = useState<ReadonlyArray<Toast>>([]);\n  const [actions, setActions] = useState<HashMap.HashMap<string, () => void>>(\n    HashMap.empty,\n  );\n  const [lifecycle] = useState(() =>\n    createRuntimeLifecycle(() => {\n      void runtime.dispose();\n    }),\n  );\n\n  useEffect(() => {\n    lifecycle.mount();\n    return () => lifecycle.unmount();\n  }, [lifecycle]);\n\n  useEffect(() => {\n    const fiber = runtime.runFork(\n      Effect.flatMap(ToastStore, (store) =>\n        Stream.runForEach(store.changes, (next) =>\n          Effect.sync(() => setToasts(next)),\n        ),\n      ),\n    );\n    return () => {\n      runtime.runFork(Fiber.interrupt(fiber));\n    };\n  }, [runtime]);\n\n  useEffect(() => {\n    const live = HashSet.fromIterable(Arr.map(toasts, (toast) => toast.id));\n    setActions((current) => {\n      const next = HashMap.filter(current, (_, id) => HashSet.has(live, id));\n      return HashMap.size(next) === HashMap.size(current) ? current : next;\n    });\n  }, [toasts]);\n\n  const push = useCallback(\n    (draft: ToastDraft, options?: ToastPushOptions) => {\n      const onAction = options?.onAction;\n      runtime.runFork(\n        Effect.flatMap(ToastStore, (store) => store.push(draft)).pipe(\n          Effect.tap((toast) =>\n            Effect.sync(() => {\n              if (onAction === undefined) return;\n              setActions((current) => HashMap.set(current, toast.id, onAction));\n            }),\n          ),\n          Effect.tapError((error) =>\n            Effect.logWarning(\"toast rejected\", error),\n          ),\n          Effect.ignore,\n        ),\n      );\n    },\n    [runtime],\n  );\n\n  const promise = useCallback(\n    <Value,>(\n      source: Promise<Value>,\n      options: ToastPromiseOptions<Value>,\n    ): Promise<Value> => {\n      runtime.runFork(\n        Effect.gen(function* () {\n          const store = yield* ToastStore;\n          const toast = yield* store.push({\n            ...options.loading,\n            phase: \"loading\",\n          });\n          const result = yield* Effect.exit(\n            Effect.tryPromise({\n              try: () => source,\n              catch: (cause) => cause,\n            }),\n          );\n          const draft = Exit.isSuccess(result)\n            ? toastStep(options.success, result.value)\n            : toastStep(options.error, Cause.squash(result.cause));\n\n          const settled = yield* Effect.exit(store.update(toast.id, draft));\n          if (Exit.isFailure(settled)) {\n            yield* Effect.logWarning(\n              \"toast promise answer rejected\",\n              Cause.squash(settled.cause),\n            );\n            yield* store.dismiss(toast.id);\n          }\n        }).pipe(\n          Effect.tapError((error) =>\n            Effect.logWarning(\"toast promise rejected\", error),\n          ),\n          Effect.ignore,\n        ),\n      );\n      return source;\n    },\n    [runtime],\n  );\n\n  const dismiss = useCallback(\n    (id: string) => {\n      runtime.runFork(Effect.flatMap(ToastStore, (store) => store.dismiss(id)));\n    },\n    [runtime],\n  );\n\n  const dismissAll = useCallback(() => {\n    runtime.runFork(Effect.flatMap(ToastStore, (store) => store.dismissAll));\n  }, [runtime]);\n\n  const pause = useCallback(\n    (id: string) => {\n      runtime.runFork(Effect.flatMap(ToastStore, (store) => store.pause(id)));\n    },\n    [runtime],\n  );\n\n  const resume = useCallback(\n    (id: string) => {\n      runtime.runFork(Effect.flatMap(ToastStore, (store) => store.resume(id)));\n    },\n    [runtime],\n  );\n\n  const hold = useCallback(\n    (held: boolean) => {\n      runtime.runFork(Effect.flatMap(ToastStore, (store) => store.hold(held)));\n    },\n    [runtime],\n  );\n\n  const actionFor = useCallback(\n    (id: string): Option.Option<() => void> => HashMap.get(actions, id),\n    [actions],\n  );\n\n  const api = useMemo<ToastApi>(\n    () => ({\n      toasts,\n      push,\n      promise,\n      dismiss,\n      dismissAll,\n      pause,\n      resume,\n      hold,\n      actionFor,\n    }),\n    [\n      actionFor,\n      dismiss,\n      dismissAll,\n      hold,\n      pause,\n      promise,\n      push,\n      resume,\n      toasts,\n    ],\n  );\n\n  return <ToastContext.Provider value={api}>{children}</ToastContext.Provider>;\n};\n"
    },
    {
      "path": "packages/components/src/toast/stack.ts",
      "target": "@ui/gpuixui/components/toast/stack.ts",
      "type": "registry:lib",
      "content": "export const STACK_VISIBLE = 3;\n\nexport const STACK_PEEK = 12;\n\nexport const STACK_INSET = 8;\n\nexport const STACK_GAP = 12;\n\nexport interface ToastSlot {\n  readonly rank: number;\n\n  readonly height: number;\n\n  readonly inset: number;\n\n  readonly interactive: boolean;\n}\n\nconst readHeight = (height: number): number =>\n  Number.isFinite(height) && height > 0 ? height : 0;\n\nexport const toastSlotOf = (\n  rank: number,\n  height: number,\n  expanded: boolean,\n): ToastSlot => {\n  if (expanded) {\n    return { rank, height, inset: 0, interactive: true };\n  }\n  if (rank === 0) {\n    return { rank, height, inset: 0, interactive: true };\n  }\n  if (rank >= STACK_VISIBLE) {\n    return { rank, height: 0, inset: 0, interactive: false };\n  }\n  return {\n    rank,\n    height: STACK_PEEK,\n    inset: STACK_INSET * rank,\n    interactive: false,\n  };\n};\n\nexport const toastSlots = (\n  heights: ReadonlyArray<number>,\n  expanded: boolean,\n): ReadonlyArray<ToastSlot> =>\n  heights.map((value, index) =>\n    toastSlotOf(heights.length - 1 - index, readHeight(value), expanded),\n  );\n\nexport const stackGap = (expanded: boolean): number =>\n  expanded ? STACK_GAP : 0;\n"
    },
    {
      "path": "packages/components/src/toast/store.ts",
      "target": "@ui/gpuixui/components/toast/store.ts",
      "type": "registry:lib",
      "content": "import { Effect, pipe } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Clock from \"effect/Clock\";\nimport * as Context from \"effect/Context\";\nimport * as Duration from \"effect/Duration\";\nimport * as FiberMap from \"effect/FiberMap\";\nimport * as HashMap from \"effect/HashMap\";\nimport * as Layer from \"effect/Layer\";\nimport * as Option from \"effect/Option\";\nimport * as Ref from \"effect/Ref\";\nimport type * as Scope from \"effect/Scope\";\nimport * as Schema from \"effect/Schema\";\nimport * as Stream from \"effect/Stream\";\nimport * as SubscriptionRef from \"effect/SubscriptionRef\";\nimport { Toast, ToastInput, type ToastDraft } from \"./model.js\";\n\ninterface State {\n  readonly seq: number;\n  readonly toasts: ReadonlyArray<Toast>;\n}\n\nexport interface ToastStoreService {\n  readonly toasts: Effect.Effect<ReadonlyArray<Toast>>;\n\n  readonly changes: Stream.Stream<ReadonlyArray<Toast>>;\n\n  readonly push: (\n    draft: ToastDraft,\n  ) => Effect.Effect<Toast, Schema.SchemaError>;\n\n  readonly update: (\n    id: string,\n    draft: ToastDraft,\n  ) => Effect.Effect<Option.Option<Toast>, Schema.SchemaError>;\n\n  readonly dismiss: (id: string) => Effect.Effect<void>;\n\n  readonly dismissAll: Effect.Effect<void>;\n\n  readonly pause: (id: string) => Effect.Effect<void>;\n\n  readonly resume: (id: string) => Effect.Effect<void>;\n\n  readonly hold: (held: boolean) => Effect.Effect<void>;\n}\n\nexport class ToastStore extends Context.Service<\n  ToastStore,\n  ToastStoreService\n>()(\"gpuixui/components/ToastStore\") {}\n\nexport interface ToastStoreOptions {\n  readonly max?: number;\n\n  readonly defaultDuration?: Duration.Input;\n}\n\nconst DEFAULT_MAX = 3;\nconst DEFAULT_DURATION = Duration.seconds(5);\n\nconst keepCount = (requested: number | undefined): number => {\n  const value = requested ?? DEFAULT_MAX;\n  return Number.isFinite(value) ? Math.max(1, Math.trunc(value)) : DEFAULT_MAX;\n};\n\nconst decodeDraft = Schema.decodeUnknownEffect(ToastInput);\n\nconst dismisses = (duration: Duration.Duration): boolean =>\n  Duration.isFinite(duration) && Duration.toMillis(duration) > 0;\n\nexport const makeToastStore = Effect.fn(\"ToastStore.make\")(function* (\n  options?: ToastStoreOptions,\n): Effect.fn.Return<ToastStoreService, never, Scope.Scope> {\n  const max = keepCount(options?.max);\n  const fallback = pipe(\n    Duration.fromInput(options?.defaultDuration ?? DEFAULT_DURATION),\n    Option.getOrElse(() => DEFAULT_DURATION),\n  );\n\n  const state = yield* SubscriptionRef.make<State>({ seq: 0, toasts: [] });\n  const timers = yield* FiberMap.make<string>();\n\n  const deadlines = yield* Ref.make(HashMap.empty<string, number>());\n\n  const paused = yield* Ref.make(HashMap.empty<string, number>());\n\n  const held = yield* Ref.make(false);\n\n  const drop = Effect.fnUntraced(function* (id: string) {\n    yield* SubscriptionRef.update(state, (current) => ({\n      ...current,\n      toasts: Arr.filter(current.toasts, (toast) => toast.id !== id),\n    }));\n  });\n\n  const forget = Effect.fnUntraced(function* (id: string) {\n    yield* FiberMap.remove(timers, id);\n    yield* Ref.update(deadlines, HashMap.remove(id));\n    yield* Ref.update(paused, HashMap.remove(id));\n  });\n\n  const schedule = Effect.fnUntraced(function* (id: string, millis: number) {\n    if (yield* Ref.get(held)) {\n      yield* Ref.update(paused, HashMap.set(id, millis));\n      return;\n    }\n    const now = yield* Clock.currentTimeMillis;\n    yield* Ref.update(deadlines, HashMap.set(id, now + millis));\n    yield* FiberMap.run(\n      timers,\n      id,\n      Effect.sleep(Duration.millis(millis)).pipe(\n        Effect.andThen(drop(id)),\n        Effect.ensuring(Ref.update(deadlines, HashMap.remove(id))),\n      ),\n    );\n  });\n\n  const dismiss = Effect.fn(\"ToastStore.dismiss\")(function* (id: string) {\n    yield* drop(id);\n    yield* forget(id);\n  });\n\n  const dismissAll = Effect.fn(\"ToastStore.dismissAll\")(function* () {\n    yield* SubscriptionRef.update(state, (current) => ({\n      ...current,\n      toasts: [],\n    }));\n    yield* FiberMap.clear(timers);\n    yield* Ref.set(deadlines, HashMap.empty());\n    yield* Ref.set(paused, HashMap.empty());\n  })();\n\n  const pause = Effect.fn(\"ToastStore.pause\")(function* (id: string) {\n    const now = yield* Clock.currentTimeMillis;\n    const remaining = yield* Ref.modify(deadlines, (current) =>\n      pipe(\n        HashMap.get(current, id),\n        Option.match({\n          onNone: () => [Option.none<number>(), current] as const,\n          onSome: (deadline) =>\n            [\n              Option.some(Math.max(0, deadline - now)),\n              HashMap.remove(current, id),\n            ] as const,\n        }),\n      ),\n    );\n\n    yield* Option.match(remaining, {\n      onNone: () => Effect.void,\n      onSome: (millis) =>\n        Effect.gen(function* () {\n          yield* FiberMap.remove(timers, id);\n          yield* Ref.update(paused, HashMap.set(id, millis));\n        }),\n    });\n  });\n\n  const resume = Effect.fn(\"ToastStore.resume\")(function* (id: string) {\n    const remaining = yield* Ref.modify(paused, (current) =>\n      pipe(\n        HashMap.get(current, id),\n        Option.match({\n          onNone: () => [Option.none<number>(), current] as const,\n          onSome: (millis) =>\n            [Option.some(millis), HashMap.remove(current, id)] as const,\n        }),\n      ),\n    );\n\n    yield* Option.match(remaining, {\n      onNone: () => Effect.void,\n      onSome: (millis) => (millis <= 0 ? drop(id) : schedule(id, millis)),\n    });\n  });\n\n  const hold = Effect.fn(\"ToastStore.hold\")(function* (value: boolean) {\n    yield* Ref.set(held, value);\n    const current = yield* SubscriptionRef.get(state);\n\n    yield* Effect.forEach(\n      current.toasts,\n      (toast) => (value ? pause(toast.id) : resume(toast.id)),\n      { concurrency: 1, discard: true },\n    );\n  });\n\n  const replace = Effect.fnUntraced(function* (\n    id: string,\n    build: (current: Toast) => Toast,\n  ) {\n    const existing = Arr.findFirst(\n      (yield* SubscriptionRef.get(state)).toasts,\n      (toast) => toast.id === id,\n    );\n    if (Option.isNone(existing)) return Option.none<Toast>();\n    const next = build(existing.value);\n    yield* SubscriptionRef.update(state, (current) => ({\n      ...current,\n      toasts: Arr.map(current.toasts, (toast) =>\n        toast.id === id ? next : toast,\n      ),\n    }));\n    return Option.some(next);\n  });\n\n  const update = Effect.fn(\"ToastStore.update\")(function* (\n    id: string,\n    draft: ToastDraft,\n  ) {\n    const input = yield* decodeDraft(draft);\n\n    yield* forget(id);\n    const replaced = yield* replace(\n      id,\n      (current) =>\n        new Toast({\n          id: current.id,\n          title: input.title,\n          description: input.description,\n          action: input.action,\n          tone: input.tone,\n          phase: input.phase,\n        }),\n    );\n\n    if (Option.isNone(replaced)) return replaced;\n\n    const duration = Option.getOrElse(input.duration, () => fallback);\n    if (replaced.value.phase === \"settled\" && dismisses(duration)) {\n      yield* schedule(id, Duration.toMillis(duration));\n    }\n    return replaced;\n  });\n\n  const push = Effect.fn(\"ToastStore.push\")(function* (draft: ToastDraft) {\n    const input = yield* decodeDraft(draft);\n    const { toast, expired } = yield* SubscriptionRef.modify(\n      state,\n      (current) => {\n        const toast = new Toast({\n          id: String(current.seq + 1),\n          title: input.title,\n          description: input.description,\n          action: input.action,\n          tone: input.tone,\n          phase: input.phase,\n        });\n        const appended = Arr.append(current.toasts, toast);\n        const overflow = Math.max(0, Arr.length(appended) - max);\n        return [\n          {\n            toast,\n            expired: Arr.map(Arr.take(appended, overflow), (t) => t.id),\n          },\n          { seq: current.seq + 1, toasts: Arr.drop(appended, overflow) },\n        ] as const;\n      },\n    );\n\n    yield* Effect.forEach(expired, forget, { concurrency: 1, discard: true });\n\n    const duration = Option.getOrElse(input.duration, () => fallback);\n    if (toast.phase === \"settled\" && dismisses(duration)) {\n      yield* schedule(toast.id, Duration.toMillis(duration));\n    }\n\n    return toast;\n  });\n\n  return {\n    toasts: pipe(\n      SubscriptionRef.get(state),\n      Effect.map((current) => current.toasts),\n    ),\n    changes: pipe(\n      SubscriptionRef.changes(state),\n      Stream.map((current) => current.toasts),\n    ),\n    push,\n    update,\n    dismiss,\n    dismissAll,\n    pause,\n    resume,\n    hold,\n  };\n});\n\nexport const layer = (options?: ToastStoreOptions): Layer.Layer<ToastStore> =>\n  Layer.effect(ToastStore, makeToastStore(options));\n"
    },
    {
      "path": "packages/components/src/toast/swipe.ts",
      "target": "@ui/gpuixui/components/toast/swipe.ts",
      "type": "registry:lib",
      "content": "export const SWIPE_THRESHOLD = 40;\n\nexport const SWIPE_MIN_TRAVEL = 12;\n\nexport const SWIPE_VELOCITY = 0.5;\n\nexport type SwipeEdge = \"left\" | \"right\";\n\nexport const swipeEdge = (\n  dx: number,\n  elapsedMs: number,\n): SwipeEdge | undefined => {\n  if (!Number.isFinite(dx) || !Number.isFinite(elapsedMs)) return undefined;\n  const travel = Math.abs(dx);\n  if (travel === 0) return undefined;\n  const speed = travel / Math.max(1, elapsedMs);\n  const flicked = travel >= SWIPE_MIN_TRAVEL && speed >= SWIPE_VELOCITY;\n  if (travel < SWIPE_THRESHOLD && !flicked) return undefined;\n  return dx < 0 ? \"left\" : \"right\";\n};\n"
    },
    {
      "path": "packages/components/src/toast/viewport.tsx",
      "target": "@ui/gpuixui/components/toast/viewport.tsx",
      "type": "registry:component",
      "content": "/** @jsxImportSource @gpuix/react */\nimport type { EventPayload, Props } from \"@gpuix/react\";\nimport { mergeStyles } from \"@gpuix/react/floating\";\nimport { Icon } from \"../../icons/index.js\";\nimport {\n  motionTimingOf,\n  type MotionCurve,\n  type MotionTiming,\n} from \"../../motion/timing.js\";\nimport {\n  cn,\n  TOAST_BODY,\n  TOAST_CARD,\n  TOAST_COPY,\n  TOAST_DESCRIPTION,\n  TOAST_DRAG,\n  TOAST_GLYPH,\n  TOAST_STACK,\n  TOAST_TITLE,\n  TOAST_VIEWPORT,\n} from \"../../tw/index.js\";\nimport { HashMap, HashSet, Match } from \"effect\";\nimport * as Arr from \"effect/Array\";\nimport * as Option from \"effect/Option\";\nimport {\n  Fragment,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n  type ReactNode,\n} from \"react\";\nimport { monotonicNanos } from \"../internal/clock.js\";\nimport { Button, IconButton } from \"../internal/button.js\";\nimport {\n  measuredBox,\n  measuredHeight,\n  measuredPoint,\n} from \"../internal/measure.js\";\nimport { overlaySurfaceStyle } from \"../internal/overlay.js\";\nimport {\n  exitWindowMs,\n  PresenceShield,\n  presenceStyle,\n  presenceTabStop,\n  useMotionPreference,\n  type SurfaceTiming,\n} from \"../internal/presence.js\";\nimport { recipeStyle } from \"../internal/recipe.js\";\nimport { tone, useTheme, type Tone } from \"../internal/theme.js\";\nimport type { Toast, ToastTone } from \"./model.js\";\nimport { useToast } from \"./provider.js\";\nimport { stackGap, toastSlotOf, type ToastSlot } from \"./stack.js\";\nimport { swipeEdge } from \"./swipe.js\";\n\nconst asTone = (value: ToastTone): Tone =>\n  Match.value(value).pipe(\n    Match.when(\"info\", () => \"info\" as const),\n    Match.when(\"success\", () => \"success\" as const),\n    Match.when(\"warning\", () => \"warning\" as const),\n    Match.when(\"danger\", () => \"danger\" as const),\n    Match.exhaustive,\n  );\n\nconst glyph = (\n  value: ToastTone,\n): \"info\" | \"success\" | \"warning\" | \"error\" | \"loader\" =>\n  Match.value(value).pipe(\n    Match.when(\"info\", () => \"info\" as const),\n    Match.when(\"success\", () => \"success\" as const),\n    Match.when(\"warning\", () => \"warning\" as const),\n    Match.when(\"danger\", () => \"error\" as const),\n    Match.exhaustive,\n  );\n\ninterface ToastTiming {\n  readonly enter: MotionTiming;\n  readonly exit: MotionTiming;\n  readonly move: MotionTiming;\n}\n\nconst STACK_CURVE: MotionCurve = [0.22, 1, 0.36, 1];\n\nconst useToastTiming = (): ToastTiming => {\n  const preference = useMotionPreference();\n  return {\n    enter: motionTimingOf(240, { phase: \"enter\", preference }),\n    exit: motionTimingOf(180, { phase: \"exit\", preference }),\n    move: motionTimingOf(260, {\n      phase: \"standard\",\n      preference,\n      ease: STACK_CURVE,\n    }),\n  };\n};\n\nconst EDGE_TRAVEL = 16;\n\nconst HOLD_GRACE_MS = 120;\n\nconst EMPTY_SLOT: ToastSlot = {\n  rank: 0,\n  height: 0,\n  inset: 0,\n  interactive: false,\n};\n\ninterface StackEntry {\n  readonly toast: Toast;\n  readonly present: boolean;\n}\n\ninterface ExitTimer {\n  readonly handle: ReturnType<typeof setTimeout>;\n  readonly ms: number;\n}\n\nconst useToastStack = (\n  toasts: ReadonlyArray<Toast>,\n  timing: SurfaceTiming,\n): ReadonlyArray<StackEntry> => {\n  const [entries, setEntries] = useState<ReadonlyArray<StackEntry>>(() =>\n    Arr.map(toasts, (toast) => ({ toast, present: true })),\n  );\n  const painted = useRef(entries);\n  const timers = useRef(new Map<string, ExitTimer>());\n\n  const windowMs = exitWindowMs(timing);\n\n  useLayoutEffect(() => {\n    painted.current = entries;\n  }, [entries]);\n\n  useLayoutEffect(() => {\n    const live = HashMap.fromIterable(\n      Arr.map(toasts, (toast) => [toast.id, toast] as const),\n    );\n    const current = painted.current;\n    const kept = Arr.map(current, (entry): StackEntry => {\n      const next = HashMap.get(live, entry.toast.id);\n      return Option.isSome(next)\n        ? { toast: next.value, present: true }\n        : { toast: entry.toast, present: false };\n    });\n    const appended = Arr.map(\n      Arr.filter(\n        toasts,\n        (toast) => !Arr.some(current, (entry) => entry.toast.id === toast.id),\n      ),\n      (toast): StackEntry => ({ toast, present: true }),\n    );\n    const merged = [...kept, ...appended];\n\n    setEntries((list) =>\n      list.length === merged.length &&\n      list.every(\n        (entry, index) =>\n          entry.toast === merged[index]?.toast &&\n          entry.present === merged[index]?.present,\n      )\n        ? list\n        : merged,\n    );\n    Arr.forEach(merged, (entry) => {\n      if (entry.present) return;\n      const id = entry.toast.id;\n      const running = timers.current.get(id);\n\n      if (running !== undefined && running.ms === windowMs) return;\n      if (running !== undefined) clearTimeout(running.handle);\n      timers.current.set(id, {\n        ms: windowMs,\n        handle: setTimeout(() => {\n          timers.current.delete(id);\n          setEntries((list) =>\n            Arr.filter(list, (item) => item.toast.id !== id),\n          );\n        }, windowMs),\n      });\n    });\n  }, [windowMs, toasts]);\n\n  useLayoutEffect(\n    () => () => {\n      timers.current.forEach((timer) => clearTimeout(timer.handle));\n      timers.current.clear();\n    },\n    [],\n  );\n\n  return entries;\n};\n\nconst ToastCard = ({\n  toast,\n  present,\n  slot,\n  naturalHeight,\n  stackWidth,\n  timing,\n  swipe,\n  onMeasure,\n  onHover,\n  onFocusChange,\n  onDrag,\n}: {\n  readonly toast: Toast;\n  readonly present: boolean;\n  readonly slot: ToastSlot;\n\n  readonly naturalHeight: number;\n\n  readonly stackWidth: number;\n  readonly timing: ToastTiming;\n  readonly swipe: boolean;\n  readonly onMeasure: (id: string, height: number) => void;\n  readonly onHover: (entered: boolean) => void;\n  readonly onFocusChange: (id: string, focused: boolean) => void;\n  readonly onDrag: (active: boolean) => void;\n}) => {\n  const theme = useTheme();\n  const { dismiss, actionFor } = useToast();\n  const palette = tone(theme, asTone(toast.tone));\n  const [drag, setDrag] = useState(0);\n  const dragX = useRef(0);\n  const press = useRef<\n    Option.Option<{ readonly x: number; readonly at: bigint }>\n  >(Option.none());\n  const exitLeft = useRef(EDGE_TRAVEL);\n  const fired = useRef(false);\n\n  const placed = useRef(false);\n\n  useEffect(() => {\n    if (slot.height > 0) placed.current = true;\n  }, [slot.height]);\n\n  const action = Option.flatMap(toast.action, (candidate) =>\n    Option.map(actionFor(toast.id), (onSelect) => ({ candidate, onSelect })),\n  );\n\n  const lastAction = useRef(action);\n  if (Option.isSome(action)) lastAction.current = action;\n\n  const measure = (event: EventPayload): void => {\n    Option.match(measuredHeight(event), {\n      onNone: () => undefined,\n      onSome: (value) => onMeasure(toast.id, value),\n    });\n  };\n\n  const startDrag = (event: EventPayload): void => {\n    if (!present || !slot.interactive) return;\n    Option.match(measuredPoint(event), {\n      onNone: () => undefined,\n      onSome: (point) => {\n        press.current = Option.some({ x: point.x, at: monotonicNanos() });\n        dragX.current = 0;\n        onDrag(true);\n      },\n    });\n  };\n\n  const moveDrag = (event: EventPayload): void => {\n    Option.match(press.current, {\n      onNone: () => undefined,\n      onSome: (begin) =>\n        Option.match(measuredPoint(event), {\n          onNone: () => undefined,\n          onSome: (point) => {\n            dragX.current = point.x - begin.x;\n            setDrag(dragX.current);\n          },\n        }),\n    });\n  };\n\n  const endDrag = (event: EventPayload): void => {\n    Option.match(press.current, {\n      onNone: () => undefined,\n      onSome: (begin) => {\n        press.current = Option.none();\n        onDrag(false);\n        const dx = Option.match(measuredPoint(event), {\n          onNone: () => dragX.current,\n          onSome: (point) => point.x - begin.x,\n        });\n        const elapsed = Number(monotonicNanos() - begin.at) / 1_000_000;\n        Option.match(Option.fromNullishOr(swipeEdge(dx, elapsed)), {\n          onNone: () => setDrag(0),\n          onSome: (edge) => {\n            exitLeft.current =\n              dx + (edge === \"left\" ? -EDGE_TRAVEL : EDGE_TRAVEL);\n            dismiss(toast.id);\n          },\n        });\n      },\n    });\n  };\n\n  const dragTransition: MotionTiming = { duration: 0 };\n\n  const width = stackWidth > 0 ? stackWidth - slot.inset * 2 : undefined;\n  const frame = width === undefined ? {} : { width };\n\n  const live = present && slot.height > 0;\n\n  const motion = present\n    ? {\n        initial: { opacity: 0, left: EDGE_TRAVEL, height: 0, ...frame },\n        animate: {\n          opacity: live ? 1 : 0,\n          left: live ? drag : EDGE_TRAVEL,\n          height: live ? slot.height : 0,\n          ...frame,\n        },\n        transition:\n          drag !== 0\n            ? dragTransition\n            : placed.current\n              ? timing.move\n              : timing.enter,\n      }\n    : {\n        initial: false as const,\n        animate: { opacity: 0, left: exitLeft.current, height: 0, ...frame },\n        transition: timing.exit,\n      };\n\n  const surface = overlaySurfaceStyle(TOAST_CARD, undefined, theme);\n\n  const whole = naturalHeight > 0 && slot.height >= naturalHeight;\n  const edge = whole\n    ? { borderRadius: surface.borderRadius, boxShadow: surface.boxShadow }\n    : {};\n\n  return (\n    <div\n      testId={`toast-${toast.id}`}\n      role={toast.tone === \"danger\" ? \"alert\" : \"status\"}\n      aria-label={toast.title}\n      motion={motion}\n      style={mergeStyles(edge, {\n        position: \"relative\",\n        overflow: \"hidden\",\n        width: width === undefined ? \"100%\" : undefined,\n\n        ...presenceStyle(present, \"target\"),\n      })}\n    >\n      <div\n        style={surface}\n        testId={`toast-surface-${toast.id}`}\n        onMouseEnter={() => onHover(true)}\n        onMouseLeave={() => onHover(false)}\n        onFocus={() => onFocusChange(toast.id, true)}\n        onBlur={() => onFocusChange(toast.id, false)}\n      >\n        <div\n          onLayout={measure}\n          style={mergeStyles(recipeStyle(TOAST_BODY, theme), {\n            width: stackWidth > 0 ? stackWidth : \"100%\",\n          })}\n        >\n          <div\n            onMouseDown={swipe ? startDrag : undefined}\n            onMouseMove={swipe ? moveDrag : undefined}\n            onMouseUp={swipe ? endDrag : undefined}\n            style={recipeStyle(TOAST_DRAG, theme)}\n          >\n            <div\n              style={mergeStyles(recipeStyle(TOAST_GLYPH, theme), {\n                color: palette.fg,\n                width: theme.iconSize.md,\n              })}\n            >\n              <Icon\n                name={toast.phase === \"loading\" ? \"loader\" : glyph(toast.tone)}\n                size=\"sm\"\n                color={palette.fg}\n                label={toast.phase === \"loading\" ? \"loading\" : toast.tone}\n              />\n            </div>\n            <div style={recipeStyle(TOAST_COPY, theme)}>\n              <text style={recipeStyle(TOAST_TITLE, theme)}>{toast.title}</text>\n              {Option.match(toast.description, {\n                onNone: () => null,\n                onSome: (description) => (\n                  <text style={recipeStyle(TOAST_DESCRIPTION, theme)}>\n                    {description}\n                  </text>\n                ),\n              })}\n            </div>\n          </div>\n          {Option.match(lastAction.current, {\n            onNone: () => null,\n            onSome: ({ candidate, onSelect }) => (\n              <Button\n                size=\"sm\"\n                variant=\"secondary\"\n                testId={`toast-action-${toast.id}`}\n                disabled={!present || !slot.interactive}\n                {...presenceTabStop(present && slot.interactive)}\n                onClick={() => {\n                  if (fired.current) return;\n                  fired.current = true;\n                  onSelect();\n                  dismiss(toast.id);\n                }}\n              >\n                {candidate.label}\n              </Button>\n            ),\n          })}\n          <IconButton\n            label=\"Dismiss\"\n            size=\"sm\"\n            testId={`toast-dismiss-${toast.id}`}\n            disabled={!present || !slot.interactive}\n            {...presenceTabStop(present && slot.interactive)}\n            onClick={() => {\n              exitLeft.current = EDGE_TRAVEL;\n              dismiss(toast.id);\n            }}\n          >\n            <Icon name=\"x\" size=\"sm\" color={theme.colors.foreground} />\n          </IconButton>\n        </div>\n      </div>\n      <PresenceShield present={present} />\n    </div>\n  );\n};\n\nconst ToastGap = ({\n  open,\n  timing,\n}: {\n  readonly open: boolean;\n  readonly timing: ToastTiming;\n}) => (\n  <div\n    style={{ width: \"100%\", pointerEvents: \"none\" }}\n    motion={{\n      initial: false,\n      animate: { height: stackGap(open) },\n      transition: timing.move,\n    }}\n  />\n);\n\nexport interface ToastViewportProps extends Props {\n  readonly className?: string;\n\n  readonly children?: ReactNode;\n\n  readonly swipe?: boolean;\n}\n\nexport const ToastViewport = ({\n  children,\n  className,\n  style,\n  swipe = true,\n  ...rest\n}: ToastViewportProps) => {\n  const theme = useTheme();\n  const { toasts, hold } = useToast();\n  const timing = useToastTiming();\n  const stack = useToastStack(toasts, timing);\n  const [held, setHeld] = useState(false);\n  const [stackWidth, setStackWidth] = useState(0);\n  const [heights, setHeights] = useState<HashMap.HashMap<string, number>>(\n    HashMap.empty,\n  );\n\n  const hovered = useRef(HashSet.empty<string>());\n  const focused = useRef(HashSet.empty<string>());\n  const dragging = useRef(false);\n  const heldNow = useRef(false);\n  const grace = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  const clearGrace = (): void => {\n    if (grace.current === null) return;\n    clearTimeout(grace.current);\n    grace.current = null;\n  };\n\n  const applyHold = (next: boolean): void => {\n    if (next) {\n      clearGrace();\n      if (!heldNow.current) {\n        heldNow.current = true;\n        setHeld(true);\n      }\n      return;\n    }\n    if (!heldNow.current || grace.current !== null) return;\n    grace.current = setTimeout(() => {\n      grace.current = null;\n      heldNow.current = false;\n      setHeld(false);\n    }, HOLD_GRACE_MS);\n  };\n\n  const syncHold = (): void => {\n    applyHold(\n      HashSet.size(hovered.current) > 0 ||\n        HashSet.size(focused.current) > 0 ||\n        dragging.current,\n    );\n  };\n\n  useEffect(\n    () => () => {\n      clearGrace();\n    },\n    [],\n  );\n\n  useEffect(() => {\n    hold(held);\n  }, [held, hold]);\n\n  useEffect(\n    () => () => {\n      hold(false);\n    },\n    [hold],\n  );\n\n  useEffect(() => {\n    if (!Arr.some(stack, (entry) => entry.present)) {\n      hovered.current = HashSet.empty();\n    }\n    const live = HashSet.fromIterable(\n      Arr.map(\n        Arr.filter(stack, (entry) => entry.present),\n        (entry) => entry.toast.id,\n      ),\n    );\n    hovered.current = HashSet.filter(hovered.current, (id) =>\n      HashSet.has(live, id),\n    );\n    focused.current = HashSet.filter(focused.current, (id) =>\n      HashSet.has(live, id),\n    );\n    syncHold();\n  }, [stack]);\n\n  useEffect(() => {\n    const live = HashSet.fromIterable(\n      Arr.map(stack, (entry) => entry.toast.id),\n    );\n    setHeights((current) => {\n      const next = HashMap.filter(current, (_, id) => HashSet.has(live, id));\n      return HashMap.size(next) === HashMap.size(current) ? current : next;\n    });\n  }, [stack]);\n\n  const onMeasure = (id: string, height: number): void => {\n    setHeights((current) =>\n      Option.match(HashMap.get(current, id), {\n        onNone: () => HashMap.set(current, id, height),\n        onSome: (known) =>\n          known === height ? current : HashMap.set(current, id, height),\n      }),\n    );\n  };\n\n  const onHover = (id: string, entered: boolean): void => {\n    hovered.current = entered\n      ? HashSet.add(hovered.current, id)\n      : HashSet.remove(hovered.current, id);\n    syncHold();\n  };\n\n  const onFocusChange = (id: string, focusedNow: boolean): void => {\n    focused.current = focusedNow\n      ? HashSet.add(focused.current, id)\n      : HashSet.remove(focused.current, id);\n    syncHold();\n  };\n\n  const onDrag = (active: boolean): void => {\n    dragging.current = active;\n    syncHold();\n  };\n\n  const present = Arr.filter(stack, (entry) => entry.present);\n  const presentCount = Arr.length(present);\n  const liveSlots = HashMap.fromIterable(\n    Arr.map(\n      present,\n      (entry, index) =>\n        [\n          entry.toast.id,\n          toastSlotOf(\n            presentCount - 1 - index,\n            Option.getOrElse(HashMap.get(heights, entry.toast.id), () => 0),\n            held,\n          ),\n        ] as const,\n    ),\n  );\n\n  const lastSlots = useRef(HashMap.empty<string, ToastSlot>());\n\n  const slotFor = (entry: StackEntry): ToastSlot =>\n    Option.getOrElse(\n      HashMap.get(\n        entry.present ? liveSlots : lastSlots.current,\n        entry.toast.id,\n      ),\n      () => EMPTY_SLOT,\n    );\n  const slots = Arr.map(stack, slotFor);\n\n  useLayoutEffect(() => {\n    const live = HashSet.fromIterable(\n      Arr.map(stack, (entry) => entry.toast.id),\n    );\n    lastSlots.current = Arr.reduce(\n      present,\n      HashMap.filter(lastSlots.current, (_, id) => HashSet.has(live, id)),\n      (map, entry) => HashMap.set(map, entry.toast.id, slotFor(entry)),\n    );\n  }, [present, stack, liveSlots, held, heights]);\n\n  return (\n    <div\n      role=\"group\"\n      aria-label=\"Notifications\"\n      testId=\"toast-viewport\"\n      {...rest}\n      style={mergeStyles(\n        mergeStyles(recipeStyle(cn(TOAST_VIEWPORT, className), theme), {\n          position: \"absolute\",\n          right: theme.spacing.xl,\n          bottom: theme.spacing.xl,\n        }),\n        style,\n      )}\n    >\n      {children}\n      <div\n        testId=\"toast-stack\"\n        onLayout={(event) => {\n          Option.match(measuredBox(event), {\n            onNone: () => undefined,\n            onSome: (box) => setStackWidth(box.width),\n          });\n        }}\n        style={recipeStyle(TOAST_STACK, theme)}\n      >\n        {Arr.map(stack, (entry, index) => {\n          const slot = slots[index] ?? EMPTY_SLOT;\n          const above = stack[index - 1];\n          return (\n            <Fragment key={entry.toast.id}>\n              {index === 0 ? null : (\n                <ToastGap\n                  open={held && entry.present && above?.present === true}\n                  timing={timing}\n                />\n              )}\n              <ToastCard\n                toast={entry.toast}\n                present={entry.present}\n                slot={slot}\n                naturalHeight={Option.getOrElse(\n                  HashMap.get(heights, entry.toast.id),\n                  () => 0,\n                )}\n                stackWidth={stackWidth}\n                timing={timing}\n                swipe={swipe}\n                onMeasure={onMeasure}\n                onHover={(entered) => onHover(entry.toast.id, entered)}\n                onFocusChange={onFocusChange}\n                onDrag={onDrag}\n              />\n            </Fragment>\n          );\n        })}\n      </div>\n    </div>\n  );\n};\n\nexport const toastMeta = {\n  name: \"Toasts / notifications\",\n  tier: 2,\n  status: \"done\",\n  gpuixSupport: \"yes\",\n  limitations: [\n    \"no zIndex: the viewport stacks by paint order, so render it last in the app root\",\n    \"no aria-live or aria-atomic: a card paints role=status (alert for danger) and does not claim an announcement\",\n    \"the stack shows three cards while collapsed; more stay queued and unfold only when the stack is expanded\",\n    \"no progress indicator for the remaining auto-dismiss time\",\n    \"swipe travels one axis (horizontal), because the runtime has no transform and an arbitrary-angle card would cover the page\",\n  ],\n  docs: \"docs/toast.mdx\",\n  example: \"examples/toast.example.tsx\",\n  testFile: \"src/behaviour/toast.test.tsx\",\n} as const;\n"
    }
  ],
  "docs": "[Toast](https://gpuixui.sudokw.com/components/toast) — These are GPUix native components: the files render through GPUix's reconciler against `@gpuix/react`, not the DOM, and need the per-platform `@gpuix/native` binding. The CLI installs the `@gpuixui/*` runtime the components import as registry items, so the copied tree resolves on its own; wrap it in `ThemeProvider` before it renders.",
  "meta": {
    "url": "/components/toast",
    "kind": "component",
    "runtime": "gpuix",
    "registry": "gpuixui"
  }
}