customizable-toast-notification 3.15.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/README.md +699 -22
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +2 -0
- package/dist/index.css.d.ts +57 -0
- package/dist/index.css.map +7 -0
- package/dist/index.d.ts +751 -12
- package/dist/index.esm.mjs +3 -3
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/package.json +24 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates global toast configuration.
|
|
3
|
+
* @param {Partial<ToastGlobalConfig>} [options]
|
|
4
|
+
* @returns {ToastGlobalConfig}
|
|
5
|
+
*/
|
|
6
|
+
declare function setConfig(options?: Partial<ToastGlobalConfig$1>): ToastGlobalConfig$1;
|
|
7
|
+
/**
|
|
8
|
+
* Resets global toast configuration back to pristine defaults.
|
|
9
|
+
* Cleans up DOM attributes attached to document.documentElement.
|
|
10
|
+
* @returns {ToastGlobalConfig}
|
|
11
|
+
*/
|
|
12
|
+
declare function resetConfig(): ToastGlobalConfig$1;
|
|
13
|
+
/**
|
|
14
|
+
* Returns a snapshot of the current global toast configuration.
|
|
15
|
+
* @returns {ToastGlobalConfig}
|
|
16
|
+
*/
|
|
17
|
+
declare function getConfig(): ToastGlobalConfig$1;
|
|
18
|
+
/**
|
|
19
|
+
* Whether toast animations should be reduced for accessibility.
|
|
20
|
+
* @returns {boolean}
|
|
21
|
+
*/
|
|
22
|
+
declare function shouldReduceMotion(): boolean;
|
|
23
|
+
type ReducedMotionMode$1 = "auto" | "always" | "never";
|
|
24
|
+
type ToastTheme$1 = "light" | "dark" | "high-contrast" | "compact" | "spacious" | "glass";
|
|
25
|
+
type ToastMountTarget$1 = Element | DocumentFragment | ShadowRoot;
|
|
26
|
+
type ToastMetrics$1 = {
|
|
27
|
+
/**
|
|
28
|
+
* - Currently rendered active toasts
|
|
29
|
+
*/
|
|
30
|
+
activeCount: number;
|
|
31
|
+
/**
|
|
32
|
+
* - Number of queued toasts waiting to be displayed
|
|
33
|
+
*/
|
|
34
|
+
queueDepth: number;
|
|
35
|
+
/**
|
|
36
|
+
* - Count of currently visible toasts
|
|
37
|
+
*/
|
|
38
|
+
visibleCount: number;
|
|
39
|
+
/**
|
|
40
|
+
* - Number of toasts dropped due to queue overflow
|
|
41
|
+
*/
|
|
42
|
+
droppedCount: number;
|
|
43
|
+
/**
|
|
44
|
+
* - Epoch timestamp (ms) when metrics were recorded
|
|
45
|
+
*/
|
|
46
|
+
timestamp: number;
|
|
47
|
+
};
|
|
48
|
+
type ToastGlobalConfig$1 = {
|
|
49
|
+
maxVisible: number;
|
|
50
|
+
maxQueueSize: number;
|
|
51
|
+
zIndex: number;
|
|
52
|
+
targetNode: ToastMountTarget$1 | null;
|
|
53
|
+
disableInlineStyles: boolean;
|
|
54
|
+
reducedMotion: ReducedMotionMode$1;
|
|
55
|
+
defaultPosition: string;
|
|
56
|
+
theme: ToastTheme$1;
|
|
57
|
+
stacked: boolean;
|
|
58
|
+
swipeToDismiss: boolean;
|
|
59
|
+
sound: boolean;
|
|
60
|
+
soundPreset?: "modern" | "retro" | "futuristic" | "subtle" | "bell" | string;
|
|
61
|
+
pauseOnHover?: boolean;
|
|
62
|
+
syncTabs: boolean;
|
|
63
|
+
aiPrioritization: boolean;
|
|
64
|
+
debug?: boolean;
|
|
65
|
+
priorityScorer?: ((context: {
|
|
66
|
+
type: string;
|
|
67
|
+
message: string;
|
|
68
|
+
duration?: number;
|
|
69
|
+
options?: Record<string, unknown>;
|
|
70
|
+
}) => number | {
|
|
71
|
+
score: number;
|
|
72
|
+
}) | null;
|
|
73
|
+
onMetrics?: ((metrics: ToastMetrics$1) => void) | null;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns a real-time snapshot of toast manager telemetry metrics.
|
|
78
|
+
* @returns {import('../utils/config.js').ToastMetrics}
|
|
79
|
+
*/
|
|
80
|
+
declare function getToastMetrics(): ToastMetrics$1;
|
|
1
81
|
declare function resetToastManager(): void;
|
|
2
82
|
/**
|
|
3
83
|
* Updates an active, pending, or queued toast in-place with new options.
|
|
@@ -8,15 +88,47 @@ declare function updateToastByKey(key: string, newOptions?: Partial<ToastOptions
|
|
|
8
88
|
|
|
9
89
|
declare function resetContainerRegistry(): void;
|
|
10
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Lazily initialize and return a shared AudioContext.
|
|
93
|
+
* Returns null in non-browser or unsupported environments.
|
|
94
|
+
* @param {boolean} [forceResume=true] - Whether to attempt resuming suspended AudioContext
|
|
95
|
+
* @returns {AudioContext | null}
|
|
96
|
+
*/
|
|
97
|
+
declare function getAudioContext(forceResume?: boolean): AudioContext | null;
|
|
98
|
+
/**
|
|
99
|
+
* Returns a shared AnalyserNode for real-time waveform visualization.
|
|
100
|
+
* @returns {AnalyserNode | null}
|
|
101
|
+
*/
|
|
102
|
+
declare function getAudioAnalyser(): AnalyserNode | null;
|
|
11
103
|
/**
|
|
12
104
|
* Synthesizes a pleasant audio chime or tone using pure Web Audio API oscillators.
|
|
13
105
|
* Zero external audio assets or network requests.
|
|
14
|
-
* @param {'success' | 'error' | 'warning' | 'info' | 'pop' | string} toneType
|
|
106
|
+
* @param {'success' | 'error' | 'warning' | 'info' | 'pop' | string} [toneType="info"]
|
|
107
|
+
* @param {'modern' | 'retro' | 'futuristic' | 'subtle' | 'bell' | string} [preset="modern"]
|
|
108
|
+
* @returns {void}
|
|
109
|
+
*/
|
|
110
|
+
declare function playTone(toneType?: "success" | "error" | "warning" | "info" | "pop" | string, preset?: "modern" | "retro" | "futuristic" | "subtle" | "bell" | string): void;
|
|
111
|
+
/**
|
|
112
|
+
* Registers a custom sound synthesis preset.
|
|
113
|
+
* @param {string} name - Name of the preset (e.g. 'arcade')
|
|
114
|
+
* @param {(ctx: AudioContext, toneType: string, now: number) => void} synthesizerFn
|
|
115
|
+
* @returns {boolean} True if successfully registered
|
|
116
|
+
*/
|
|
117
|
+
declare function registerSoundPreset(name: string, synthesizerFn: (ctx: AudioContext, toneType: string, now: number) => void): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Returns a list of all currently available sound presets (built-in + custom).
|
|
120
|
+
* @returns {string[]}
|
|
121
|
+
*/
|
|
122
|
+
declare function getSoundPresets(): string[];
|
|
123
|
+
/**
|
|
124
|
+
* Clears custom sound presets (primarily for testing and environment resets).
|
|
125
|
+
* @returns {void}
|
|
15
126
|
*/
|
|
16
|
-
declare function
|
|
127
|
+
declare function resetSoundPresets(): void;
|
|
17
128
|
/**
|
|
18
129
|
* Globally enable or disable synthesized notification sounds.
|
|
19
130
|
* @param {boolean} enabled
|
|
131
|
+
* @returns {void}
|
|
20
132
|
*/
|
|
21
133
|
declare function setAudioEnabled(enabled: boolean): void;
|
|
22
134
|
/**
|
|
@@ -24,7 +136,437 @@ declare function setAudioEnabled(enabled: boolean): void;
|
|
|
24
136
|
* @returns {boolean}
|
|
25
137
|
*/
|
|
26
138
|
declare function isAudioEnabled(): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Resets the cached AudioContext instance (useful for test isolation).
|
|
141
|
+
* @returns {void}
|
|
142
|
+
*/
|
|
143
|
+
declare function resetAudioContext(): void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Get or create the global toast pool instance
|
|
147
|
+
* @param {number} [initialSize=5] - Initial pool size
|
|
148
|
+
* @param {number} [maxSize=50] - Maximum pool size
|
|
149
|
+
* @returns {ToastElementPool}
|
|
150
|
+
*/
|
|
151
|
+
declare function getToastPool(initialSize?: number, maxSize?: number): ToastElementPool;
|
|
152
|
+
/**
|
|
153
|
+
* Reset pool instance (for testing)
|
|
154
|
+
*/
|
|
155
|
+
declare function resetToastPool(): void;
|
|
156
|
+
/**
|
|
157
|
+
* @typedef {Object} PooledToastElement
|
|
158
|
+
* @property {HTMLElement} element - The reusable toast element
|
|
159
|
+
* @property {boolean} inUse - Whether element is currently allocated
|
|
160
|
+
* @property {string | null} id - Unique toast ID
|
|
161
|
+
*/
|
|
162
|
+
declare class ToastElementPool {
|
|
163
|
+
constructor(initialSize?: number, maxSize?: number);
|
|
164
|
+
initialSize: number;
|
|
165
|
+
maxSize: number;
|
|
166
|
+
/** @type {Array<{element: HTMLElement, inUse: boolean, id: string | null}>} */
|
|
167
|
+
pool: Array<{
|
|
168
|
+
element: HTMLElement;
|
|
169
|
+
inUse: boolean;
|
|
170
|
+
id: string | null;
|
|
171
|
+
}>;
|
|
172
|
+
inUseCount: number;
|
|
173
|
+
/**
|
|
174
|
+
* Create a new toast element template
|
|
175
|
+
* @private
|
|
176
|
+
* @returns {HTMLElement}
|
|
177
|
+
*/
|
|
178
|
+
private _createToastElement;
|
|
179
|
+
/**
|
|
180
|
+
* Acquire a toast element from pool or create new one
|
|
181
|
+
* @param {string} toastId - Unique identifier for this toast
|
|
182
|
+
* @returns {HTMLElement} - Ready-to-use toast element
|
|
183
|
+
*/
|
|
184
|
+
acquire(toastId: string): HTMLElement;
|
|
185
|
+
/**
|
|
186
|
+
* Release a toast element back to pool
|
|
187
|
+
* @param {HTMLElement} element - The element to release
|
|
188
|
+
* @param {string} toastId - The toast ID being released
|
|
189
|
+
* @returns {void}
|
|
190
|
+
*/
|
|
191
|
+
release(element: HTMLElement, toastId: string): void;
|
|
192
|
+
/**
|
|
193
|
+
* Get pool statistics for monitoring
|
|
194
|
+
* @returns {{total: number, inUse: number, available: number, utilization: number, maxSize: number}} - Pool stats
|
|
195
|
+
*/
|
|
196
|
+
getStats(): {
|
|
197
|
+
total: number;
|
|
198
|
+
inUse: number;
|
|
199
|
+
available: number;
|
|
200
|
+
utilization: number;
|
|
201
|
+
maxSize: number;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Clear all pooled elements (for cleanup/testing)
|
|
205
|
+
* @returns {void}
|
|
206
|
+
*/
|
|
207
|
+
clear(): void;
|
|
208
|
+
/**
|
|
209
|
+
* Compact pool (remove unused elements above initial size)
|
|
210
|
+
* Useful for long-running apps with temporary toast spikes
|
|
211
|
+
* @returns {void}
|
|
212
|
+
*/
|
|
213
|
+
compact(): void;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Get or create the global broadcaster instance
|
|
218
|
+
* @returns {ToastBroadcaster}
|
|
219
|
+
*/
|
|
220
|
+
declare function getToastBroadcaster(): ToastBroadcaster;
|
|
221
|
+
/**
|
|
222
|
+
* Reset broadcaster instance (for testing)
|
|
223
|
+
*/
|
|
224
|
+
declare function resetToastBroadcaster(): void;
|
|
225
|
+
/**
|
|
226
|
+
* @typedef {Object} ToastSyncMessage
|
|
227
|
+
* @property {string} type - Message type: 'create', 'update', 'dismiss', 'sync-request', 'sync-response'
|
|
228
|
+
* @property {string} toastId - Unique toast identifier
|
|
229
|
+
* @property {Record<string, unknown>} payload - Message-specific data
|
|
230
|
+
* @property {number} timestamp - Message timestamp
|
|
231
|
+
* @property {string} tabId - Originating tab ID
|
|
232
|
+
*/
|
|
233
|
+
declare class ToastBroadcaster {
|
|
234
|
+
/** @type {BroadcastChannel | null} */
|
|
235
|
+
channel: BroadcastChannel | null;
|
|
236
|
+
tabId: string;
|
|
237
|
+
isLeadTab: boolean;
|
|
238
|
+
/** @type {ReturnType<typeof setTimeout> | null} */
|
|
239
|
+
leaderTimer: ReturnType<typeof setTimeout> | null;
|
|
240
|
+
/** @type {Map<string, Array<(data: Record<string, unknown>) => void>>} */
|
|
241
|
+
listeners: Map<string, Array<(data: Record<string, unknown>) => void>>;
|
|
242
|
+
supportsBroadcastChannel: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Generate unique tab identifier with high cross-tab entropy.
|
|
245
|
+
* Unlike DOM element IDs (which rely on monotonic counters within a single thread),
|
|
246
|
+
* tab IDs must guarantee uniqueness across independent browser processes/tabs
|
|
247
|
+
* that do not share memory even if opened in the exact same millisecond.
|
|
248
|
+
*
|
|
249
|
+
* @private
|
|
250
|
+
* @returns {string} Unique tab ID matching /^tab-[a-z0-9]+-[a-z0-9]+$/
|
|
251
|
+
*/
|
|
252
|
+
private _generateTabId;
|
|
253
|
+
/**
|
|
254
|
+
* Initialize BroadcastChannel if available
|
|
255
|
+
* @private
|
|
256
|
+
*/
|
|
257
|
+
private _initBroadcastChannel;
|
|
258
|
+
/**
|
|
259
|
+
* Attempt to become the lead tab
|
|
260
|
+
* @private
|
|
261
|
+
*/
|
|
262
|
+
private _becomeLeadIfNeeded;
|
|
263
|
+
/**
|
|
264
|
+
* Broadcast a toast event to other tabs
|
|
265
|
+
* @param {string} type - Event type
|
|
266
|
+
* @param {string} [toastId=''] - Toast ID
|
|
267
|
+
* @param {Record<string, unknown>} [payload={}] - Event payload
|
|
268
|
+
*/
|
|
269
|
+
broadcast(type: string, toastId?: string, payload?: Record<string, unknown>): void;
|
|
270
|
+
/**
|
|
271
|
+
* Handle incoming message from other tab
|
|
272
|
+
* @private
|
|
273
|
+
* @param {ToastSyncMessage} message
|
|
274
|
+
*/
|
|
275
|
+
private _handleMessage;
|
|
276
|
+
/**
|
|
277
|
+
* Register listener for toast events
|
|
278
|
+
* @param {string} type - Event type to listen for
|
|
279
|
+
* @param {Function} callback - Callback function
|
|
280
|
+
* @returns {Function} - Unsubscribe function
|
|
281
|
+
*/
|
|
282
|
+
on(type: string, callback: Function): Function;
|
|
283
|
+
/**
|
|
284
|
+
* Register active toasts getter (set by ToastManager)
|
|
285
|
+
* @param {Function} getter
|
|
286
|
+
*/
|
|
287
|
+
registerActiveToastsGetter(getter: Function): void;
|
|
288
|
+
_getActiveToasts: Function;
|
|
289
|
+
/**
|
|
290
|
+
* Register queued toasts getter (set by ToastManager)
|
|
291
|
+
* @param {Function} getter
|
|
292
|
+
*/
|
|
293
|
+
registerQueuedToastsGetter(getter: Function): void;
|
|
294
|
+
_getQueuedToasts: Function;
|
|
295
|
+
/**
|
|
296
|
+
* Check if cross-tab sync is supported
|
|
297
|
+
* @returns {boolean}
|
|
298
|
+
*/
|
|
299
|
+
isSupported(): boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Get current tab ID
|
|
302
|
+
* @returns {string}
|
|
303
|
+
*/
|
|
304
|
+
getTabId(): string;
|
|
305
|
+
/**
|
|
306
|
+
* Is this the lead tab
|
|
307
|
+
* @returns {boolean}
|
|
308
|
+
*/
|
|
309
|
+
isLeadingTab(): boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Cleanup on unload
|
|
312
|
+
*/
|
|
313
|
+
destroy(): void;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Calculate priority score for toast based on type, message, and context
|
|
318
|
+
* @param {ToastScoringContext} context
|
|
319
|
+
* @returns {ScorerResult}
|
|
320
|
+
*/
|
|
321
|
+
declare function calculateToastPriority(context: ToastScoringContext): ScorerResult;
|
|
322
|
+
/**
|
|
323
|
+
* Extract semantic category from toast message
|
|
324
|
+
* @param {string} message
|
|
325
|
+
* @returns {string[]} - Categories (security, performance, user, system, etc.)
|
|
326
|
+
*/
|
|
327
|
+
declare function categorizeToast(message: string): string[];
|
|
328
|
+
type ToastScoringContext = {
|
|
329
|
+
/**
|
|
330
|
+
* - Toast type (success, error, warning, info)
|
|
331
|
+
*/
|
|
332
|
+
type: string;
|
|
333
|
+
/**
|
|
334
|
+
* - Toast message content
|
|
335
|
+
*/
|
|
336
|
+
message: string;
|
|
337
|
+
/**
|
|
338
|
+
* - Duration in milliseconds
|
|
339
|
+
*/
|
|
340
|
+
duration: number;
|
|
341
|
+
/**
|
|
342
|
+
* - Full toast options
|
|
343
|
+
*/
|
|
344
|
+
options: Record<string, unknown>;
|
|
345
|
+
};
|
|
346
|
+
type ScorerResult = {
|
|
347
|
+
/**
|
|
348
|
+
* - Priority score (0-100)
|
|
349
|
+
*/
|
|
350
|
+
score: number;
|
|
351
|
+
/**
|
|
352
|
+
* - Score breakdown by factor
|
|
353
|
+
*/
|
|
354
|
+
breakdown: Record<string, number>;
|
|
355
|
+
/**
|
|
356
|
+
* - Detected keywords affecting score
|
|
357
|
+
*/
|
|
358
|
+
keywords: string[];
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Calculate velocity of a swipe gesture
|
|
363
|
+
* @param {number} distance - Distance traveled in pixels
|
|
364
|
+
* @param {number} duration - Duration in milliseconds
|
|
365
|
+
* @returns {number} - Velocity in pixels/millisecond
|
|
366
|
+
*/
|
|
367
|
+
declare function calculateVelocity(distance: number, duration: number): number;
|
|
368
|
+
/**
|
|
369
|
+
* Detect if gesture is a flick (fast swipe with high velocity)
|
|
370
|
+
* @param {number} velocity - Gesture velocity (px/ms)
|
|
371
|
+
* @param {number} distance - Distance traveled (px)
|
|
372
|
+
* @param {number} [velocityThreshold=0.5] - Minimum velocity for flick (default 0.5 px/ms)
|
|
373
|
+
* @param {number} [distanceThreshold=50] - Minimum distance for flick (default 50px)
|
|
374
|
+
* @returns {boolean}
|
|
375
|
+
*/
|
|
376
|
+
declare function isFlick(velocity: number, distance: number, velocityThreshold?: number, distanceThreshold?: number): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Detect pinch gesture (two-finger distance change)
|
|
379
|
+
* @param {GestureState} state
|
|
380
|
+
* @param {number} [sensitivityThreshold=20] - Minimum distance change for pinch (default 20px)
|
|
381
|
+
* @returns {PinchResult} - Pinch info { isPinch, scale, direction, distanceChange }
|
|
382
|
+
*/
|
|
383
|
+
declare function detectPinch(state: GestureState, sensitivityThreshold?: number): PinchResult;
|
|
384
|
+
/**
|
|
385
|
+
* Create gesture detector function for element
|
|
386
|
+
* @param {HTMLElement} element
|
|
387
|
+
* @param {GestureDetectorOptions} [options]
|
|
388
|
+
* @returns {GestureDetector} - Detector with attach/detach methods
|
|
389
|
+
*/
|
|
390
|
+
declare function createGestureDetector(element: HTMLElement, options?: GestureDetectorOptions): GestureDetector;
|
|
391
|
+
type TouchPoint = {
|
|
392
|
+
/**
|
|
393
|
+
* - X coordinate
|
|
394
|
+
*/
|
|
395
|
+
x: number;
|
|
396
|
+
/**
|
|
397
|
+
* - Y coordinate
|
|
398
|
+
*/
|
|
399
|
+
y: number;
|
|
400
|
+
/**
|
|
401
|
+
* - Touch identifier
|
|
402
|
+
*/
|
|
403
|
+
id: number;
|
|
404
|
+
/**
|
|
405
|
+
* - Timestamp
|
|
406
|
+
*/
|
|
407
|
+
time: number;
|
|
408
|
+
};
|
|
409
|
+
type GestureState = {
|
|
410
|
+
/**
|
|
411
|
+
* - Current touch points
|
|
412
|
+
*/
|
|
413
|
+
touches: TouchPoint[];
|
|
414
|
+
/**
|
|
415
|
+
* - Initial touch points
|
|
416
|
+
*/
|
|
417
|
+
startTouches: TouchPoint[];
|
|
418
|
+
/**
|
|
419
|
+
* - Gesture start time
|
|
420
|
+
*/
|
|
421
|
+
startTime: number;
|
|
422
|
+
/**
|
|
423
|
+
* - Initial distance between touches (for pinch)
|
|
424
|
+
*/
|
|
425
|
+
startDistance: number;
|
|
426
|
+
/**
|
|
427
|
+
* - Current distance between touches
|
|
428
|
+
*/
|
|
429
|
+
currentDistance: number;
|
|
430
|
+
};
|
|
431
|
+
type PinchResult = {
|
|
432
|
+
isPinch: boolean;
|
|
433
|
+
scale: number;
|
|
434
|
+
direction: "none" | "in" | "out";
|
|
435
|
+
distanceChange?: number;
|
|
436
|
+
};
|
|
437
|
+
type SwipeResult = {
|
|
438
|
+
distance: number;
|
|
439
|
+
velocity: number;
|
|
440
|
+
direction: "none" | "left" | "right";
|
|
441
|
+
duration: number;
|
|
442
|
+
};
|
|
443
|
+
type GestureDetectorOptions = {
|
|
444
|
+
onFlick?: ((swipe: SwipeResult) => void);
|
|
445
|
+
onPinch?: ((pinch: PinchResult) => void);
|
|
446
|
+
onSwipe?: ((swipe: SwipeResult) => void);
|
|
447
|
+
flickVelocityThreshold?: number;
|
|
448
|
+
swipeVelocityThreshold?: number;
|
|
449
|
+
swipeDistanceThreshold?: number;
|
|
450
|
+
pinchSensitivity?: number;
|
|
451
|
+
};
|
|
452
|
+
type GestureDetector = {
|
|
453
|
+
attach: () => void;
|
|
454
|
+
detach: () => void;
|
|
455
|
+
getState: () => GestureState | null;
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Reset the internal monotonic counter (primarily for test isolation)
|
|
460
|
+
* @returns {void}
|
|
461
|
+
*/
|
|
462
|
+
declare function resetToastIdCounter(): void;
|
|
463
|
+
/**
|
|
464
|
+
* Generate unique, CSS-safe ID for DOM elements.
|
|
465
|
+
* Combines sanitized prefix, millisecond timestamp, and monotonic counter with session salt.
|
|
466
|
+
* Guarantees 0% collision rate without HTTP/HTTPS secure context restrictions.
|
|
467
|
+
*
|
|
468
|
+
* @param {string} [prefix="toast"] - Optional prefix for ID
|
|
469
|
+
* @returns {string} Unique ID matching /^toast-[a-z0-9]+-[a-z0-9]+$/
|
|
470
|
+
*/
|
|
471
|
+
declare function generateToastId(prefix?: string): string;
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Register a custom named spring preset.
|
|
475
|
+
* @param {string} name - Unique preset identifier
|
|
476
|
+
* @param {SpringConfig & { bezierFallback?: string }} config - Spring parameters
|
|
477
|
+
*/
|
|
478
|
+
declare function registerSpringPreset(name: string, config: SpringConfig$1 & {
|
|
479
|
+
bezierFallback?: string;
|
|
480
|
+
}): void;
|
|
481
|
+
/**
|
|
482
|
+
* Retrieve list of registered spring preset names.
|
|
483
|
+
* @returns {string[]}
|
|
484
|
+
*/
|
|
485
|
+
declare function getSpringPresets(): string[];
|
|
486
|
+
/**
|
|
487
|
+
* Reset all registered custom spring presets back to defaults.
|
|
488
|
+
*/
|
|
489
|
+
declare function resetSpringPresets(): void;
|
|
490
|
+
/**
|
|
491
|
+
* Resolves a spring input into concrete numerical physics constants.
|
|
492
|
+
* @param {boolean | SpringPreset | SpringConfig} spring - Preset name or custom parameters
|
|
493
|
+
* @returns {{ stiffness: number, damping: number, mass: number, bezierFallback: string } | null}
|
|
494
|
+
*/
|
|
495
|
+
declare function resolveSpringConfig(spring: boolean | SpringPreset$1 | SpringConfig$1): {
|
|
496
|
+
stiffness: number;
|
|
497
|
+
damping: number;
|
|
498
|
+
mass: number;
|
|
499
|
+
bezierFallback: string;
|
|
500
|
+
} | null;
|
|
501
|
+
/**
|
|
502
|
+
* Solves the damped harmonic oscillator step response at time t (in seconds).
|
|
503
|
+
* Returns displacement value y(t) transitioning from 0 to 1.
|
|
504
|
+
*
|
|
505
|
+
* @param {number} t - Time in seconds (t >= 0)
|
|
506
|
+
* @param {{ stiffness: number, damping: number, mass: number }} config
|
|
507
|
+
* @returns {number} Value of step response at time t
|
|
508
|
+
*/
|
|
509
|
+
declare function solveSpring(t: number, config: {
|
|
510
|
+
stiffness: number;
|
|
511
|
+
damping: number;
|
|
512
|
+
mass: number;
|
|
513
|
+
}): number;
|
|
514
|
+
/**
|
|
515
|
+
* Calculates the duration (in milliseconds) required for the spring to settle
|
|
516
|
+
* within an acceptable error threshold (default: 0.005 / 0.5%).
|
|
517
|
+
*
|
|
518
|
+
* @param {{ stiffness: number, damping: number, mass: number }} config
|
|
519
|
+
* @param {number} [threshold=0.005]
|
|
520
|
+
* @returns {number} Settling duration in milliseconds
|
|
521
|
+
*/
|
|
522
|
+
declare function calculateSpringSettlingDuration(config: {
|
|
523
|
+
stiffness: number;
|
|
524
|
+
damping: number;
|
|
525
|
+
mass: number;
|
|
526
|
+
}, threshold?: number): number;
|
|
527
|
+
/**
|
|
528
|
+
* Generates a modern CSS linear(...) timing function representation of the spring motion.
|
|
529
|
+
* @param {{ stiffness: number, damping: number, mass: number }} config
|
|
530
|
+
* @param {number} [points=32]
|
|
531
|
+
* @returns {string} CSS linear(...) curve string
|
|
532
|
+
*/
|
|
533
|
+
declare function generateSpringLinearEasing(config: {
|
|
534
|
+
stiffness: number;
|
|
535
|
+
damping: number;
|
|
536
|
+
mass: number;
|
|
537
|
+
}, points?: number): string;
|
|
538
|
+
/**
|
|
539
|
+
* Returns comprehensive transition timing, easing, and duration parameters for a toast with spring physics.
|
|
540
|
+
* @param {boolean | SpringPreset | SpringConfig} spring
|
|
541
|
+
* @returns {{ config: { stiffness: number, damping: number, mass: number }, duration: number, easing: string, isSpring: boolean } | null}
|
|
542
|
+
*/
|
|
543
|
+
declare function getSpringTransition(spring: boolean | SpringPreset$1 | SpringConfig$1): {
|
|
544
|
+
config: {
|
|
545
|
+
stiffness: number;
|
|
546
|
+
damping: number;
|
|
547
|
+
mass: number;
|
|
548
|
+
};
|
|
549
|
+
duration: number;
|
|
550
|
+
easing: string;
|
|
551
|
+
isSpring: boolean;
|
|
552
|
+
} | null;
|
|
553
|
+
type SpringConfig$1 = {
|
|
554
|
+
/**
|
|
555
|
+
* - Spring tension / stiffness constant (k > 0)
|
|
556
|
+
*/
|
|
557
|
+
stiffness?: number;
|
|
558
|
+
/**
|
|
559
|
+
* - Damping friction coefficient (c > 0)
|
|
560
|
+
*/
|
|
561
|
+
damping?: number;
|
|
562
|
+
/**
|
|
563
|
+
* - Inertial mass (m > 0)
|
|
564
|
+
*/
|
|
565
|
+
mass?: number;
|
|
566
|
+
};
|
|
567
|
+
type SpringPreset$1 = "default" | "gentle" | "wobbly" | "stiff" | "bouncy" | string;
|
|
27
568
|
|
|
569
|
+
type SoundPreset = "modern" | "retro" | "futuristic" | "subtle" | "bell" | string;
|
|
28
570
|
type ToastType = "info" | "success" | "error" | "warning";
|
|
29
571
|
type ToastPosition = "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-center" | "bottom-center" | "left-center" | "right-center" | "top-full-width" | "bottom-full-width" | "center";
|
|
30
572
|
type CTAOptions = {
|
|
@@ -35,8 +577,41 @@ type CTAOptions = {
|
|
|
35
577
|
rel?: string;
|
|
36
578
|
ariaLabel?: string;
|
|
37
579
|
autoClose?: boolean;
|
|
580
|
+
color?: string;
|
|
581
|
+
textColor?: string;
|
|
582
|
+
background?: string;
|
|
583
|
+
backgroundColor?: string;
|
|
38
584
|
onClick?: (e: MouseEvent) => void | Promise<void>;
|
|
39
585
|
};
|
|
586
|
+
type UndoOptions = {
|
|
587
|
+
/**
|
|
588
|
+
* - Button text label (default: 'Undo')
|
|
589
|
+
*/
|
|
590
|
+
label?: string;
|
|
591
|
+
/**
|
|
592
|
+
* - Whether to display decaying seconds counter (default: true)
|
|
593
|
+
*/
|
|
594
|
+
showCountdown?: boolean;
|
|
595
|
+
/**
|
|
596
|
+
* - Callback fired when clicked
|
|
597
|
+
*/
|
|
598
|
+
onUndo?: (e: MouseEvent, toast: HTMLElement) => void | Promise<void>;
|
|
599
|
+
};
|
|
600
|
+
type SpringConfig = {
|
|
601
|
+
/**
|
|
602
|
+
* - Spring stiffness constant (k > 0)
|
|
603
|
+
*/
|
|
604
|
+
stiffness?: number;
|
|
605
|
+
/**
|
|
606
|
+
* - Damping friction coefficient (c > 0)
|
|
607
|
+
*/
|
|
608
|
+
damping?: number;
|
|
609
|
+
/**
|
|
610
|
+
* - Inertial mass (m > 0)
|
|
611
|
+
*/
|
|
612
|
+
mass?: number;
|
|
613
|
+
};
|
|
614
|
+
type SpringPreset = "default" | "gentle" | "wobbly" | "stiff" | "bouncy" | string;
|
|
40
615
|
type ToastLoaderOptions = {
|
|
41
616
|
/**
|
|
42
617
|
* - Spinner size in pixels (default 14)
|
|
@@ -80,27 +655,183 @@ type ToastOptions = {
|
|
|
80
655
|
fontDirection?: "auto" | "ltr" | "rtl";
|
|
81
656
|
fontPadding?: string;
|
|
82
657
|
className?: string;
|
|
83
|
-
cta?: CTAOptions;
|
|
658
|
+
cta?: CTAOptions | CTAOptions[];
|
|
659
|
+
undo?: ((e: MouseEvent, toast: HTMLElement) => void | Promise<void>) | UndoOptions;
|
|
660
|
+
spring?: boolean | SpringPreset | SpringConfig;
|
|
84
661
|
stacked?: boolean;
|
|
85
662
|
sound?: boolean | "success" | "error" | "warning" | "info" | "pop" | string;
|
|
663
|
+
soundPreset?: SoundPreset;
|
|
664
|
+
icon?: boolean | string | HTMLElement | ((options: ToastOptions) => boolean | string | HTMLElement | null | undefined);
|
|
86
665
|
swipeToDismiss?: boolean;
|
|
87
666
|
progress?: number;
|
|
667
|
+
syncTabs?: boolean;
|
|
668
|
+
aiPrioritization?: boolean;
|
|
669
|
+
priority?: number;
|
|
670
|
+
usePool?: boolean;
|
|
671
|
+
};
|
|
672
|
+
type ReducedMotionMode = "auto" | "always" | "never";
|
|
673
|
+
type ToastTheme = "light" | "dark" | "high-contrast" | "compact" | "spacious" | "glass";
|
|
674
|
+
type ToastMountTarget = Element | DocumentFragment | ShadowRoot;
|
|
675
|
+
type ToastMetrics = {
|
|
676
|
+
/**
|
|
677
|
+
* - Currently rendered active toasts
|
|
678
|
+
*/
|
|
679
|
+
activeCount: number;
|
|
680
|
+
/**
|
|
681
|
+
* - Number of queued toasts waiting to be displayed
|
|
682
|
+
*/
|
|
683
|
+
queueDepth: number;
|
|
684
|
+
/**
|
|
685
|
+
* - Count of currently visible toasts
|
|
686
|
+
*/
|
|
687
|
+
visibleCount: number;
|
|
688
|
+
/**
|
|
689
|
+
* - Number of toasts dropped due to queue overflow
|
|
690
|
+
*/
|
|
691
|
+
droppedCount: number;
|
|
692
|
+
/**
|
|
693
|
+
* - Epoch timestamp (ms) when metrics were recorded
|
|
694
|
+
*/
|
|
695
|
+
timestamp: number;
|
|
696
|
+
};
|
|
697
|
+
type ToastGlobalConfig = {
|
|
698
|
+
maxVisible?: number;
|
|
699
|
+
maxQueueSize?: number;
|
|
700
|
+
zIndex?: number;
|
|
701
|
+
targetNode?: ToastMountTarget | null;
|
|
702
|
+
disableInlineStyles?: boolean;
|
|
703
|
+
reducedMotion?: ReducedMotionMode;
|
|
704
|
+
defaultPosition?: ToastPosition | string;
|
|
705
|
+
theme?: ToastTheme;
|
|
706
|
+
stacked?: boolean;
|
|
707
|
+
swipeToDismiss?: boolean;
|
|
708
|
+
sound?: boolean;
|
|
709
|
+
soundPreset?: SoundPreset;
|
|
710
|
+
syncTabs?: boolean;
|
|
711
|
+
aiPrioritization?: boolean;
|
|
712
|
+
debug?: boolean;
|
|
713
|
+
priorityScorer?: ((context: {
|
|
714
|
+
type: string;
|
|
715
|
+
message: string;
|
|
716
|
+
duration?: number;
|
|
717
|
+
options?: Record<string, unknown>;
|
|
718
|
+
}) => number | {
|
|
719
|
+
score: number;
|
|
720
|
+
}) | null;
|
|
721
|
+
onMetrics?: ((metrics: ToastMetrics) => void) | null;
|
|
88
722
|
};
|
|
89
723
|
type ToastHandle = {
|
|
724
|
+
/**
|
|
725
|
+
* - The unique identifier/key of the toast notification.
|
|
726
|
+
*/
|
|
727
|
+
id?: string;
|
|
90
728
|
dismiss: () => Promise<void>;
|
|
91
729
|
update: (newOptions: Partial<ToastOptions>) => Promise<void>;
|
|
92
730
|
};
|
|
93
731
|
type ToastPromiseMessages = {
|
|
94
|
-
loading?: string
|
|
95
|
-
success?: string | ((result: unknown) => string);
|
|
96
|
-
error?: string | ((error: unknown) => string);
|
|
732
|
+
loading?: string | Partial<ToastOptions>;
|
|
733
|
+
success?: string | Partial<ToastOptions> | ((result: unknown) => string | Partial<ToastOptions>);
|
|
734
|
+
error?: string | Partial<ToastOptions> | ((error: unknown) => string | Partial<ToastOptions>);
|
|
97
735
|
};
|
|
98
736
|
/**
|
|
99
737
|
* Creates and displays a toast notification.
|
|
100
|
-
*
|
|
738
|
+
* Supports string shorthand: `createToast("Message")` or full options `createToast({ message: "..." })`.
|
|
739
|
+
* Also provides ergonomic shorthand methods: `createToast.success(...)`, `createToast.error(...)`, etc.
|
|
740
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
741
|
+
* @param {Partial<ToastOptions>} [maybeOptions]
|
|
101
742
|
* @returns {Promise<ToastHandle>}
|
|
102
743
|
*/
|
|
103
|
-
declare function createToastWithPriority(
|
|
744
|
+
declare function createToastWithPriority(messageOrOptions?: string | ToastOptions, maybeOptions?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
745
|
+
declare namespace createToastWithPriority {
|
|
746
|
+
/**
|
|
747
|
+
* Displays a success toast notification.
|
|
748
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
749
|
+
* @param {Partial<ToastOptions>} [options]
|
|
750
|
+
* @returns {Promise<ToastHandle>}
|
|
751
|
+
*/
|
|
752
|
+
export function success(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
753
|
+
/**
|
|
754
|
+
* Displays an error toast notification.
|
|
755
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
756
|
+
* @param {Partial<ToastOptions>} [options]
|
|
757
|
+
* @returns {Promise<ToastHandle>}
|
|
758
|
+
*/
|
|
759
|
+
export function error(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
760
|
+
/**
|
|
761
|
+
* Displays a warning toast notification.
|
|
762
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
763
|
+
* @param {Partial<ToastOptions>} [options]
|
|
764
|
+
* @returns {Promise<ToastHandle>}
|
|
765
|
+
*/
|
|
766
|
+
export function warning(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
767
|
+
/**
|
|
768
|
+
* Displays an informational toast notification.
|
|
769
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
770
|
+
* @param {Partial<ToastOptions>} [options]
|
|
771
|
+
* @returns {Promise<ToastHandle>}
|
|
772
|
+
*/
|
|
773
|
+
export function info(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
774
|
+
/**
|
|
775
|
+
* Displays a persistent loading toast with an animated spinner.
|
|
776
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
777
|
+
* @param {Partial<ToastOptions>} [options]
|
|
778
|
+
* @returns {Promise<ToastHandle>}
|
|
779
|
+
*/
|
|
780
|
+
export function loading(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
781
|
+
/**
|
|
782
|
+
* Displays a custom styled HTML toast notification.
|
|
783
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
784
|
+
* @param {Partial<ToastOptions>} [options]
|
|
785
|
+
* @returns {Promise<ToastHandle>}
|
|
786
|
+
*/
|
|
787
|
+
export function custom(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
788
|
+
export { toastPromise as promise };
|
|
789
|
+
export { dismissToast as dismiss };
|
|
790
|
+
export { noopAll as dismissAll };
|
|
791
|
+
export { noopAll as clear };
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Displays a success toast notification.
|
|
795
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
796
|
+
* @param {Partial<ToastOptions>} [options]
|
|
797
|
+
* @returns {Promise<ToastHandle>}
|
|
798
|
+
*/
|
|
799
|
+
declare function success(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
800
|
+
/**
|
|
801
|
+
* Displays an error toast notification.
|
|
802
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
803
|
+
* @param {Partial<ToastOptions>} [options]
|
|
804
|
+
* @returns {Promise<ToastHandle>}
|
|
805
|
+
*/
|
|
806
|
+
declare function error(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
807
|
+
/**
|
|
808
|
+
* Displays a warning toast notification.
|
|
809
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
810
|
+
* @param {Partial<ToastOptions>} [options]
|
|
811
|
+
* @returns {Promise<ToastHandle>}
|
|
812
|
+
*/
|
|
813
|
+
declare function warning(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
814
|
+
/**
|
|
815
|
+
* Displays an informational toast notification.
|
|
816
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
817
|
+
* @param {Partial<ToastOptions>} [options]
|
|
818
|
+
* @returns {Promise<ToastHandle>}
|
|
819
|
+
*/
|
|
820
|
+
declare function info(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
821
|
+
/**
|
|
822
|
+
* Displays a persistent loading toast with an animated spinner.
|
|
823
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
824
|
+
* @param {Partial<ToastOptions>} [options]
|
|
825
|
+
* @returns {Promise<ToastHandle>}
|
|
826
|
+
*/
|
|
827
|
+
declare function loading(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
828
|
+
/**
|
|
829
|
+
* Displays a custom styled HTML toast notification.
|
|
830
|
+
* @param {string | ToastOptions} [messageOrOptions]
|
|
831
|
+
* @param {Partial<ToastOptions>} [options]
|
|
832
|
+
* @returns {Promise<ToastHandle>}
|
|
833
|
+
*/
|
|
834
|
+
declare function custom(messageOrOptions?: string | ToastOptions, options?: Partial<ToastOptions>): Promise<ToastHandle>;
|
|
104
835
|
/**
|
|
105
836
|
* Sets default background colors for toast types.
|
|
106
837
|
* @param {Partial<Record<ToastType, string>>} colors
|
|
@@ -111,9 +842,17 @@ declare function setDefaultColors(colors: Partial<Record<ToastType, string>>): v
|
|
|
111
842
|
* @param {Partial<Record<ToastType, string>>} messages
|
|
112
843
|
*/
|
|
113
844
|
declare function setDefaultMessages(messages: Partial<Record<ToastType, string>>): void;
|
|
114
|
-
|
|
845
|
+
/**
|
|
846
|
+
* Dismisses a toast by its key/id, handle, element, or dismisses the most recent toast if target is omitted.
|
|
847
|
+
* @param {string | ToastHandle | HTMLElement | Promise<ToastHandle>} [target]
|
|
848
|
+
* @returns {Promise<void>}
|
|
849
|
+
*/
|
|
850
|
+
declare function dismissToast(target?: string | ToastHandle | HTMLElement | Promise<ToastHandle>): Promise<void>;
|
|
115
851
|
declare function noopAll(): Promise<void>;
|
|
116
|
-
declare
|
|
852
|
+
declare function dismissAll(): Promise<void>;
|
|
853
|
+
declare function clear(): Promise<void>;
|
|
854
|
+
/** @type {string} */
|
|
855
|
+
declare const version: string;
|
|
117
856
|
/**
|
|
118
857
|
* Wraps a promise or function with automatic loading, success, and error toasts.
|
|
119
858
|
* @template T
|
|
@@ -124,5 +863,5 @@ declare const version: any;
|
|
|
124
863
|
*/
|
|
125
864
|
declare function toastPromise<T>(promiseOrFn: Promise<T> | (() => Promise<T> | T), messages?: ToastPromiseMessages, options?: ToastOptions): Promise<T>;
|
|
126
865
|
|
|
127
|
-
export { createToastWithPriority as createToast, dismissToast as dismiss, isAudioEnabled, noopAll as noop, playTone, resetContainerRegistry, resetToastManager, setAudioEnabled, setDefaultColors, setDefaultMessages, toastPromise, updateToastByKey, version };
|
|
128
|
-
export type { CTAOptions, ToastHandle, ToastLoaderOptions, ToastOptions, ToastPosition, ToastPromiseMessages, ToastType };
|
|
866
|
+
export { calculateSpringSettlingDuration, calculateToastPriority, calculateVelocity, categorizeToast, clear, createGestureDetector, createToastWithPriority as createToast, custom, createToastWithPriority as default, detectPinch, dismissToast as dismiss, dismissAll, error, generateSpringLinearEasing, generateToastId, getAudioAnalyser, getAudioContext, getConfig, getSoundPresets, getSpringPresets, getSpringTransition, getToastBroadcaster, getToastMetrics, getToastPool, info, isAudioEnabled, isFlick, loading, noopAll as noop, playTone, registerSoundPreset, registerSpringPreset, resetAudioContext, resetConfig, resetContainerRegistry, resetSoundPresets, resetSpringPresets, resetToastBroadcaster, resetToastIdCounter, resetToastManager, resetToastPool, resolveSpringConfig, setAudioEnabled, setConfig, setDefaultColors, setDefaultMessages, shouldReduceMotion, solveSpring, success, toastPromise, updateToastByKey, version, warning };
|
|
867
|
+
export type { CTAOptions, ReducedMotionMode, SoundPreset, SpringConfig, SpringPreset, ToastGlobalConfig, ToastHandle, ToastLoaderOptions, ToastMetrics, ToastMountTarget, ToastOptions, ToastPosition, ToastPromiseMessages, ToastTheme, ToastType, UndoOptions };
|