import type { AnchoredAlign, AnchoredSide } from '../utils/anchored-position'; export type ToastPriority = 'low' | 'high'; export type ToastTransitionStatus = 'starting' | 'active' | 'ending'; export type ToastSwipeDirection = 'up' | 'down' | 'left' | 'right'; export type ToastCloseReason = 'timeout' | 'close-button' | 'swipe' | 'escape' | 'programmatic'; export interface ToastPositionerOptions { /** Element or document id used to position this toast outside the global stack. */ anchor: HTMLElement | string; side?: AnchoredSide; align?: AnchoredAlign; sideOffset?: number | string; alignOffset?: number | string; } export interface ToastActionContext { id: string; data: Data | undefined; manager: ToastManager; originalEvent: MouseEvent; } export interface ToastAction { label: string; ariaLabel?: string; onAction?: (context: ToastActionContext) => void; } export interface ToastCloseContext { id: string; reason: ToastCloseReason; toast: ToastRecord; } export interface ToastOptions { id?: string; title?: string; description?: string; /** Styling/state hook, including `loading`, `success`, and `error`. */ type?: string; /** Milliseconds, a CSS time/token value, or 0 to keep the toast open. */ timeout?: number | string; priority?: ToastPriority; action?: ToastAction; positioner?: ToastPositionerOptions; data?: Data; onClose?: (context: ToastCloseContext) => void; onRemove?: (context: ToastCloseContext) => void; } export interface ToastRecord extends Omit, 'id' | 'priority'> { id: string; priority: ToastPriority; transitionStatus: ToastTransitionStatus; updateKey: number; /** Internal timer generation; changes only when countdown timing must restart. */ timerKey: number; closeReason?: ToastCloseReason; } export type ToastPromiseValue = string | ToastOptions; export interface ToastPromiseOptions { loading: ToastPromiseValue; success: ToastPromiseValue | ((value: Value) => ToastPromiseValue); error: ToastPromiseValue | ((error: unknown) => ToastPromiseValue); } export type ToastListener = (records: readonly ToastRecord[]) => void; export interface ToastManager { add(options: ToastOptions): string; update(id: string, updates: Partial>): void; close(id: string, reason?: ToastCloseReason): void; closeAll(reason?: ToastCloseReason): void; promise(promiseValue: PromiseLike, options: ToastPromiseOptions): Promise; subscribe(listener: ToastListener): () => void; getSnapshot(): readonly ToastRecord[]; /** Component lifecycle hook; consumers should not need to call this. */ activate(id: string): void; /** Component lifecycle hook; consumers should not need to call this. */ remove(id: string): ToastCloseContext | null; /** Component lifecycle hook; invokes onRemove after rendered DOM removal. */ notifyRemove(context: ToastCloseContext): void; } export interface ToastEventDetail { id: string; toast: ToastRecord; } export interface ToastCloseEventDetail extends ToastEventDetail { reason: ToastCloseReason; } export interface ToastActionEventDetail extends ToastEventDetail { originalEvent: MouseEvent; }