lumatoast 0.1.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/LICENSE +0 -0
- package/README.md +522 -0
- package/dist/index.cjs +1011 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +366 -0
- package/dist/index.d.ts +366 -0
- package/dist/index.js +972 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +819 -0
- package/dist/styles.css.map +1 -0
- package/package.json +74 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
type ToastType = "success" | "error" | "warning" | "info" | "loading" | "custom";
|
|
2
|
+
type ToastTheme = "linear" | "aurora" | "vision" | "minimal" | "cupertino" | "material" | "terminal" | "github" | "cyberpunk";
|
|
3
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
4
|
+
/** Where the progress bar is rendered inside the card. */
|
|
5
|
+
type ToastProgressPosition = "top" | "bottom";
|
|
6
|
+
/** Enter animation style. */
|
|
7
|
+
type ToastAnimationEnter = "slide" | "fade" | "scale" | "bounce" | "none";
|
|
8
|
+
/** Exit animation style. */
|
|
9
|
+
type ToastAnimationExit = "slide" | "fade" | "none";
|
|
10
|
+
/** Global animation speed preset. */
|
|
11
|
+
type ToastAnimationSpeed = "slow" | "normal" | "fast";
|
|
12
|
+
/** Action button visual variant. */
|
|
13
|
+
type ToastActionVariant = "solid" | "outline" | "ghost";
|
|
14
|
+
interface ToastAction {
|
|
15
|
+
label: string;
|
|
16
|
+
onClick: () => void;
|
|
17
|
+
/** Visual style of the action button. Default: "solid" */
|
|
18
|
+
variant?: ToastActionVariant;
|
|
19
|
+
}
|
|
20
|
+
interface ToastOptions {
|
|
21
|
+
/** Stable id — useful for `toast.update()`. Auto-generated if omitted. */
|
|
22
|
+
id?: string;
|
|
23
|
+
/** Bold title text rendered above the description. */
|
|
24
|
+
title?: string;
|
|
25
|
+
/** Body text of the toast. */
|
|
26
|
+
description?: string;
|
|
27
|
+
/** Auto-dismiss delay in ms. Use `Infinity` to never auto-dismiss. Default: 4000 */
|
|
28
|
+
duration?: number;
|
|
29
|
+
/** Show the × close button. Default: true */
|
|
30
|
+
dismissible?: boolean;
|
|
31
|
+
/** Screen position of the toast. Default: "top-right" */
|
|
32
|
+
position?: ToastPosition;
|
|
33
|
+
/** Visual theme preset. Default: "linear" */
|
|
34
|
+
theme?: ToastTheme;
|
|
35
|
+
/** Action button shown inside the toast. */
|
|
36
|
+
action?: ToastAction;
|
|
37
|
+
/** Extra CSS class(es) added to the toast wrapper element. */
|
|
38
|
+
className?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Inline styles applied to the toast card.
|
|
41
|
+
* Supports both regular CSS properties and CSS custom properties.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* style: { "--luma-bg": "#1a1a2e", borderRadius: "24px" }
|
|
45
|
+
*/
|
|
46
|
+
style?: Record<string, string>;
|
|
47
|
+
/** Show the type icon. Default: true */
|
|
48
|
+
showIcon?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Dismiss the toast when the user clicks anywhere on the card body.
|
|
51
|
+
* Default: false
|
|
52
|
+
*/
|
|
53
|
+
closeOnClick?: boolean;
|
|
54
|
+
/** Where the progress bar is placed inside the card. Default: "bottom" */
|
|
55
|
+
progressPosition?: ToastProgressPosition;
|
|
56
|
+
/** Enter animation style. Default: "slide" */
|
|
57
|
+
animationEnter?: ToastAnimationEnter;
|
|
58
|
+
/** Exit animation style. Default: "slide" */
|
|
59
|
+
animationExit?: ToastAnimationExit;
|
|
60
|
+
}
|
|
61
|
+
interface ToastItem extends ToastOptions {
|
|
62
|
+
id: string;
|
|
63
|
+
type: ToastType;
|
|
64
|
+
title?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
action?: ToastAction;
|
|
67
|
+
duration: number;
|
|
68
|
+
dismissible: boolean;
|
|
69
|
+
position: ToastPosition;
|
|
70
|
+
theme: ToastTheme;
|
|
71
|
+
showIcon: boolean;
|
|
72
|
+
closeOnClick: boolean;
|
|
73
|
+
progressPosition: ToastProgressPosition;
|
|
74
|
+
animationEnter: ToastAnimationEnter;
|
|
75
|
+
animationExit: ToastAnimationExit;
|
|
76
|
+
createdAt: number;
|
|
77
|
+
visible: boolean;
|
|
78
|
+
}
|
|
79
|
+
interface ToastUpdateOptions {
|
|
80
|
+
type?: ToastType;
|
|
81
|
+
title?: string;
|
|
82
|
+
description?: string;
|
|
83
|
+
duration?: number;
|
|
84
|
+
dismissible?: boolean;
|
|
85
|
+
action?: ToastAction;
|
|
86
|
+
theme?: ToastTheme;
|
|
87
|
+
className?: string;
|
|
88
|
+
style?: Record<string, string>;
|
|
89
|
+
showIcon?: boolean;
|
|
90
|
+
progressPosition?: ToastProgressPosition;
|
|
91
|
+
}
|
|
92
|
+
interface PromiseToastOptions {
|
|
93
|
+
loading: ToastOptions;
|
|
94
|
+
success: ToastOptions;
|
|
95
|
+
error: ToastOptions;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type Listener<T> = (payload: T) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Tiny event emitter used internally by LumaToast.
|
|
101
|
+
*/
|
|
102
|
+
declare class EventEmitter<T> {
|
|
103
|
+
private listeners;
|
|
104
|
+
subscribe(listener: Listener<T>): () => void;
|
|
105
|
+
emit(payload: T): void;
|
|
106
|
+
clear(): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface ToastConfig {
|
|
110
|
+
/** Default auto-dismiss duration in ms. Default: 4000 */
|
|
111
|
+
duration?: number;
|
|
112
|
+
/** Default screen position. Default: "top-right" */
|
|
113
|
+
position?: ToastPosition;
|
|
114
|
+
/** Default visual theme. Default: "linear" */
|
|
115
|
+
theme?: ToastTheme;
|
|
116
|
+
/** Default dismissible flag. Default: true */
|
|
117
|
+
dismissible?: boolean;
|
|
118
|
+
/** Maximum number of toasts visible at once. Default: 5 */
|
|
119
|
+
maxVisible?: number;
|
|
120
|
+
/** Show the type icon by default. Default: true */
|
|
121
|
+
showIcon?: boolean;
|
|
122
|
+
/** Dismiss on card body click by default. Default: false */
|
|
123
|
+
closeOnClick?: boolean;
|
|
124
|
+
/** Default progress bar placement. Default: "bottom" */
|
|
125
|
+
progressPosition?: ToastProgressPosition;
|
|
126
|
+
/** Default enter animation. Default: "slide" */
|
|
127
|
+
animationEnter?: ToastAnimationEnter;
|
|
128
|
+
/** Default exit animation. Default: "slide" */
|
|
129
|
+
animationExit?: ToastAnimationExit;
|
|
130
|
+
/**
|
|
131
|
+
* Global animation speed preset.
|
|
132
|
+
* Applies `--luma-duration-enter/exit/stack` CSS variables on <html>.
|
|
133
|
+
* Default: "normal"
|
|
134
|
+
*/
|
|
135
|
+
animationSpeed?: ToastAnimationSpeed;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Set global defaults for all toasts.
|
|
139
|
+
* Per-toast options always override these.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* configure({
|
|
143
|
+
* position: "bottom-right",
|
|
144
|
+
* theme: "minimal",
|
|
145
|
+
* duration: 3000,
|
|
146
|
+
* progressPosition: "top",
|
|
147
|
+
* animationEnter: "scale",
|
|
148
|
+
* animationSpeed: "fast",
|
|
149
|
+
* });
|
|
150
|
+
*/
|
|
151
|
+
declare function configure(config: ToastConfig): void;
|
|
152
|
+
declare class ToastManager {
|
|
153
|
+
private visible;
|
|
154
|
+
private queue;
|
|
155
|
+
readonly changes: EventEmitter<ToastItem[]>;
|
|
156
|
+
/**
|
|
157
|
+
* Returns all visible toasts.
|
|
158
|
+
*/
|
|
159
|
+
getToasts(): ToastItem[];
|
|
160
|
+
/**
|
|
161
|
+
* Create a new toast.
|
|
162
|
+
*/
|
|
163
|
+
create(type: ToastType, options?: ToastOptions): ToastItem;
|
|
164
|
+
/**
|
|
165
|
+
* Remove a toast by id.
|
|
166
|
+
*/
|
|
167
|
+
dismiss(id: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Remove all visible and queued toasts.
|
|
170
|
+
*/
|
|
171
|
+
dismissAll(): void;
|
|
172
|
+
/**
|
|
173
|
+
* Remove the most recently added visible toast.
|
|
174
|
+
*/
|
|
175
|
+
dismissLatest(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Update an existing toast by id.
|
|
178
|
+
* Works on both visible and queued toasts.
|
|
179
|
+
*/
|
|
180
|
+
update(id: string, updates: ToastUpdateOptions): ToastItem | null;
|
|
181
|
+
}
|
|
182
|
+
declare const toastManager: ToastManager;
|
|
183
|
+
|
|
184
|
+
declare const toast: {
|
|
185
|
+
/**
|
|
186
|
+
* Show a success toast.
|
|
187
|
+
*/
|
|
188
|
+
success(message: string, options?: ToastOptions): ToastItem;
|
|
189
|
+
/**
|
|
190
|
+
* Show an error toast.
|
|
191
|
+
*/
|
|
192
|
+
error(message: string, options?: ToastOptions): ToastItem;
|
|
193
|
+
/**
|
|
194
|
+
* Show a warning toast.
|
|
195
|
+
*/
|
|
196
|
+
warning(message: string, options?: ToastOptions): ToastItem;
|
|
197
|
+
/**
|
|
198
|
+
* Show an info toast.
|
|
199
|
+
*/
|
|
200
|
+
info(message: string, options?: ToastOptions): ToastItem;
|
|
201
|
+
/**
|
|
202
|
+
* Show a persistent loading toast that must be dismissed manually
|
|
203
|
+
* or converted via `toast.update()` / `toast.promise()`.
|
|
204
|
+
*/
|
|
205
|
+
loading(message: string, options?: ToastOptions): ToastItem;
|
|
206
|
+
/**
|
|
207
|
+
* Show a fully custom toast.
|
|
208
|
+
* You control the title, description, action, theme, and position.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* toast.custom("Custom notification", { title: "Hey!", theme: "cyberpunk" });
|
|
212
|
+
*/
|
|
213
|
+
custom(message: string, options?: ToastOptions): ToastItem;
|
|
214
|
+
/**
|
|
215
|
+
* Dismiss a toast by id.
|
|
216
|
+
*/
|
|
217
|
+
dismiss(id: string): void;
|
|
218
|
+
/**
|
|
219
|
+
* Dismiss all visible and queued toasts.
|
|
220
|
+
*/
|
|
221
|
+
dismissAll(): void;
|
|
222
|
+
/**
|
|
223
|
+
* Dismiss the most recently added visible toast.
|
|
224
|
+
*/
|
|
225
|
+
dismissLatest(): void;
|
|
226
|
+
/**
|
|
227
|
+
* Update an existing toast's properties.
|
|
228
|
+
* Useful for transitioning a loading toast to success or error.
|
|
229
|
+
*/
|
|
230
|
+
update(id: string, updates: ToastUpdateOptions): ToastItem | null;
|
|
231
|
+
/**
|
|
232
|
+
* Track a promise: show a loading toast, then auto-transition to
|
|
233
|
+
* success or error based on the promise outcome.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* toast.promise(fetch("/api/save"), {
|
|
237
|
+
* loading: { description: "Saving..." },
|
|
238
|
+
* success: { description: "Saved!" },
|
|
239
|
+
* error: { description: "Failed to save." }
|
|
240
|
+
* });
|
|
241
|
+
*/
|
|
242
|
+
promise<T>(promise: Promise<T>, options: PromiseToastOptions): Promise<T>;
|
|
243
|
+
/**
|
|
244
|
+
* Subscribe to toast state changes.
|
|
245
|
+
* Returns an unsubscribe function.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* const unsub = toast.subscribe((toasts) => console.log(toasts));
|
|
249
|
+
* // later:
|
|
250
|
+
* unsub();
|
|
251
|
+
*/
|
|
252
|
+
subscribe(listener: (toasts: ReturnType<typeof toastManager.getToasts>) => void): () => void;
|
|
253
|
+
/**
|
|
254
|
+
* Set global defaults for all toasts.
|
|
255
|
+
* Per-toast options always override these.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* toast.configure({ position: "bottom-right", theme: "minimal", duration: 3000 });
|
|
259
|
+
*/
|
|
260
|
+
configure: typeof configure;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* LumaToast design tokens.
|
|
265
|
+
*
|
|
266
|
+
* These constants map to CSS custom properties used by the themes.
|
|
267
|
+
* Override any of these in your CSS to customise LumaToast globally
|
|
268
|
+
* or per-theme without writing extra class selectors.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```css
|
|
272
|
+
* :root {
|
|
273
|
+
* --luma-bg: #1a1a2e;
|
|
274
|
+
* --luma-radius: 24px;
|
|
275
|
+
* --luma-font: "Inter", sans-serif;
|
|
276
|
+
* }
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
declare const DURATION_SHORT = 2000;
|
|
280
|
+
declare const DURATION_DEFAULT = 4000;
|
|
281
|
+
declare const DURATION_LONG = 6000;
|
|
282
|
+
declare const DURATION_INFINITE: number;
|
|
283
|
+
declare const ANIMATION_ENTER_MS = 320;
|
|
284
|
+
declare const ANIMATION_EXIT_MS = 300;
|
|
285
|
+
declare const ANIMATION_STACK_MS = 280;
|
|
286
|
+
declare const TOAST_WIDTH_PX = 340;
|
|
287
|
+
declare const TOAST_GAP_PX = 12;
|
|
288
|
+
declare const Z_INDEX_BASE = 1000;
|
|
289
|
+
declare const CSS_VARS: {
|
|
290
|
+
readonly WIDTH: "--luma-width";
|
|
291
|
+
readonly RADIUS: "--luma-radius";
|
|
292
|
+
readonly PADDING: "--luma-padding";
|
|
293
|
+
readonly GAP: "--luma-gap";
|
|
294
|
+
readonly BG: "--luma-bg";
|
|
295
|
+
readonly BORDER_COLOR: "--luma-border-color";
|
|
296
|
+
readonly BORDER_WIDTH: "--luma-border-width";
|
|
297
|
+
readonly SHADOW: "--luma-shadow";
|
|
298
|
+
readonly BACKDROP: "--luma-backdrop";
|
|
299
|
+
readonly FONT: "--luma-font";
|
|
300
|
+
readonly TITLE_SIZE: "--luma-title-size";
|
|
301
|
+
readonly TITLE_WEIGHT: "--luma-title-weight";
|
|
302
|
+
readonly TITLE_COLOR: "--luma-title-color";
|
|
303
|
+
readonly DESC_SIZE: "--luma-desc-size";
|
|
304
|
+
readonly DESC_COLOR: "--luma-desc-color";
|
|
305
|
+
readonly LINE_HEIGHT: "--luma-line-height";
|
|
306
|
+
readonly LETTER_SPACING: "--luma-letter-spacing";
|
|
307
|
+
readonly ICON_SIZE: "--luma-icon-size";
|
|
308
|
+
readonly CLOSE_COLOR: "--luma-close-color";
|
|
309
|
+
readonly CLOSE_SIZE: "--luma-close-size";
|
|
310
|
+
readonly ACTION_BG: "--luma-action-bg";
|
|
311
|
+
readonly ACTION_COLOR: "--luma-action-color";
|
|
312
|
+
readonly ACTION_HOVER_BG: "--luma-action-hover-bg";
|
|
313
|
+
readonly ACTION_RADIUS: "--luma-action-radius";
|
|
314
|
+
readonly ACTION_PADDING: "--luma-action-padding";
|
|
315
|
+
readonly ACTION_SIZE: "--luma-action-size";
|
|
316
|
+
readonly ACTION_WEIGHT: "--luma-action-weight";
|
|
317
|
+
readonly ACTION_BORDER: "--luma-action-border";
|
|
318
|
+
readonly ACTION_HOVER_BORDER: "--luma-action-hover-border";
|
|
319
|
+
readonly PROGRESS_HEIGHT: "--luma-progress-height";
|
|
320
|
+
readonly PROGRESS_RADIUS: "--luma-progress-radius";
|
|
321
|
+
readonly PROGRESS_SUCCESS: "--luma-progress-success";
|
|
322
|
+
readonly PROGRESS_ERROR: "--luma-progress-error";
|
|
323
|
+
readonly PROGRESS_WARNING: "--luma-progress-warning";
|
|
324
|
+
readonly PROGRESS_INFO: "--luma-progress-info";
|
|
325
|
+
readonly PROGRESS_LOADING: "--luma-progress-loading";
|
|
326
|
+
readonly PROGRESS_CUSTOM: "--luma-progress-custom";
|
|
327
|
+
readonly ACCENT_SUCCESS: "--luma-accent-success";
|
|
328
|
+
readonly ACCENT_ERROR: "--luma-accent-error";
|
|
329
|
+
readonly ACCENT_WARNING: "--luma-accent-warning";
|
|
330
|
+
readonly ACCENT_INFO: "--luma-accent-info";
|
|
331
|
+
readonly DURATION_ENTER: "--luma-duration-enter";
|
|
332
|
+
readonly DURATION_EXIT: "--luma-duration-exit";
|
|
333
|
+
readonly DURATION_STACK: "--luma-duration-stack";
|
|
334
|
+
};
|
|
335
|
+
declare const CLASS_CONTAINER = "luma-toast-container";
|
|
336
|
+
declare const CLASS_TOAST = "luma-toast";
|
|
337
|
+
declare const CLASS_CARD = "luma-toast-card";
|
|
338
|
+
declare const CLASS_ICON = "luma-toast-icon";
|
|
339
|
+
declare const CLASS_CONTENT = "luma-toast-content";
|
|
340
|
+
declare const CLASS_TITLE = "luma-toast-title";
|
|
341
|
+
declare const CLASS_DESCRIPTION = "luma-toast-description";
|
|
342
|
+
declare const CLASS_ACTION = "luma-toast-action";
|
|
343
|
+
declare const CLASS_CLOSE = "luma-toast-close";
|
|
344
|
+
declare const CLASS_PROGRESS = "luma-progress";
|
|
345
|
+
declare const CLASS_EXIT = "luma-toast-exit";
|
|
346
|
+
|
|
347
|
+
declare const DEFAULT_DURATION = 4000;
|
|
348
|
+
declare const DEFAULT_POSITION: "top-right";
|
|
349
|
+
declare const DEFAULT_THEME: "linear";
|
|
350
|
+
declare const DEFAULT_DISMISSIBLE = true;
|
|
351
|
+
declare const DEFAULT_SHOW_ICON = true;
|
|
352
|
+
declare const DEFAULT_CLOSE_ON_CLICK = false;
|
|
353
|
+
declare const DEFAULT_PROGRESS_POS: "bottom";
|
|
354
|
+
declare const DEFAULT_ANIMATION_ENTER: "slide";
|
|
355
|
+
declare const DEFAULT_ANIMATION_EXIT: "slide";
|
|
356
|
+
declare const DEFAULT_ANIMATION_SPEED: "normal";
|
|
357
|
+
declare const MAX_VISIBLE_TOASTS = 5;
|
|
358
|
+
declare const STACK_GAP = 12;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Initialize the DOM renderer. Must be called once before showing toasts.
|
|
362
|
+
* Safe to call multiple times — subsequent calls are no-ops.
|
|
363
|
+
*/
|
|
364
|
+
declare function initializeRenderer(): void;
|
|
365
|
+
|
|
366
|
+
export { ANIMATION_ENTER_MS, ANIMATION_EXIT_MS, ANIMATION_STACK_MS, CLASS_ACTION, CLASS_CARD, CLASS_CLOSE, CLASS_CONTAINER, CLASS_CONTENT, CLASS_DESCRIPTION, CLASS_EXIT, CLASS_ICON, CLASS_PROGRESS, CLASS_TITLE, CLASS_TOAST, CSS_VARS, DEFAULT_ANIMATION_ENTER, DEFAULT_ANIMATION_EXIT, DEFAULT_ANIMATION_SPEED, DEFAULT_CLOSE_ON_CLICK, DEFAULT_DISMISSIBLE, DEFAULT_DURATION, DEFAULT_POSITION, DEFAULT_PROGRESS_POS, DEFAULT_SHOW_ICON, DEFAULT_THEME, DURATION_DEFAULT, DURATION_INFINITE, DURATION_LONG, DURATION_SHORT, MAX_VISIBLE_TOASTS, type PromiseToastOptions, STACK_GAP, TOAST_GAP_PX, TOAST_WIDTH_PX, type ToastAction, type ToastActionVariant, type ToastAnimationEnter, type ToastAnimationExit, type ToastAnimationSpeed, type ToastItem, type ToastOptions, type ToastPosition, type ToastProgressPosition, type ToastTheme, type ToastType, type ToastUpdateOptions, Z_INDEX_BASE, configure, initializeRenderer, toast, toastManager };
|