@yusufceng1z/ding 0.0.0-stage → 0.0.2

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.
@@ -0,0 +1,164 @@
1
+ type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading';
2
+ /** enter: shape only · open: pill expanded · closing: text erased, pill shrinking · exit: shape leaves */
3
+ type Phase = 'enter' | 'open' | 'closing' | 'exit';
4
+ type Position = 'top-center' | 'top-left' | 'top-right' | 'bottom-center' | 'bottom-left' | 'bottom-right';
5
+ type Theme = 'system' | 'light' | 'dark';
6
+ interface ToastAction {
7
+ label: string;
8
+ /** Return a patch to morph this toast in place (e.g. Undo → "Restored"). Return nothing to dismiss it. */
9
+ onClick: () => void | ToastPatch;
10
+ }
11
+ interface ToastOptions {
12
+ id?: string;
13
+ description?: string;
14
+ action?: ToastAction;
15
+ /** Second button beside the action (e.g. Reply + Snooze). */
16
+ secondary?: ToastAction;
17
+ /** Small trailing text beside the title, e.g. a timestamp ("now", "2m"). */
18
+ meta?: string;
19
+ /** Avatar or thumbnail URL. Replaces the status icon with a round image. */
20
+ image?: string;
21
+ /** ms before auto-close. 0 = until dismissed. Default 5000; errors, actions and loading stay until dismissed. */
22
+ duration?: number;
23
+ /** 0–1. Draws a thin bar inside the pill. */
24
+ progress?: number;
25
+ }
26
+ interface ToastPatch {
27
+ title?: string;
28
+ description?: string;
29
+ type?: ToastType;
30
+ duration?: number;
31
+ /** 0–1, or null to remove the bar */
32
+ progress?: number | null;
33
+ /** null removes the action button */
34
+ action?: ToastAction | null;
35
+ secondary?: ToastAction | null;
36
+ /** null removes it */
37
+ meta?: string | null;
38
+ /** null returns to the status icon */
39
+ image?: string | null;
40
+ }
41
+ interface ToastItem {
42
+ id: string;
43
+ type: ToastType;
44
+ title: string;
45
+ description?: string;
46
+ phase: Phase;
47
+ /** ms until auto-close; 0 = stays until dismissed */
48
+ duration: number;
49
+ action?: ToastAction;
50
+ secondary?: ToastAction;
51
+ meta?: string;
52
+ image?: string;
53
+ progress?: number;
54
+ /** identical toasts fired again collapse into one with a counter */
55
+ count: number;
56
+ }
57
+ interface ToasterState {
58
+ toasts: ToastItem[];
59
+ position: Position;
60
+ theme: Theme;
61
+ /** text for the persistent polite live region (role=status) */
62
+ status: string;
63
+ /** text for the persistent assertive live region (role=alert) */
64
+ alert: string;
65
+ }
66
+ interface PromiseMessages<T> {
67
+ loading: string;
68
+ success: string | ((value: T) => string);
69
+ error: string | ((error: unknown) => string);
70
+ }
71
+
72
+ declare const TIMING: {
73
+ /** shape arrives, then the pill opens */
74
+ openDelay: number;
75
+ /** text erase + shrink back to shape */
76
+ closing: number;
77
+ /** shape leaves the screen */
78
+ exit: number;
79
+ duration: number;
80
+ };
81
+ declare function createToaster(): {
82
+ show: (type: ToastType, title: string, opts?: ToastOptions) => string;
83
+ success: (title: string, o?: ToastOptions) => string;
84
+ error: (title: string, o?: ToastOptions) => string;
85
+ warning: (title: string, o?: ToastOptions) => string;
86
+ info: (title: string, o?: ToastOptions) => string;
87
+ loading: (title: string, o?: ToastOptions) => string;
88
+ promise: <T>(p: Promise<T> | (() => Promise<T>), m: PromiseMessages<T>) => Promise<T>;
89
+ update: (callerId: string, p: ToastPatch) => void;
90
+ act: (id: string, which?: "action" | "secondary") => void;
91
+ dismiss: (id?: string, opts?: {
92
+ immediate?: boolean;
93
+ }) => void;
94
+ pause: (id?: string) => void;
95
+ resume: (id?: string) => void;
96
+ configure(c: {
97
+ position?: Position;
98
+ theme?: Theme;
99
+ sound?: boolean | ((type: ToastType) => void);
100
+ volume?: number;
101
+ }): void;
102
+ subscribe(fn: () => void): () => undefined;
103
+ getState: () => ToasterState;
104
+ };
105
+ type Toaster = ReturnType<typeof createToaster>;
106
+ declare const toast: Toaster;
107
+
108
+ interface SpringConfig {
109
+ stiffness?: number;
110
+ damping?: number;
111
+ mass?: number;
112
+ }
113
+ /**
114
+ * Bake a spring into a CSS `linear()` easing so the browser animates it
115
+ * (transitions/keyframes) with no per-frame JS.
116
+ */
117
+ declare function springEasing(config?: SpringConfig): {
118
+ easing: string;
119
+ duration: number;
120
+ };
121
+
122
+ type Springs = {
123
+ enter: SpringConfig;
124
+ morph: SpringConfig;
125
+ stack: SpringConfig;
126
+ };
127
+ declare function getSprings(): {
128
+ enter: {
129
+ easing: string;
130
+ duration: number;
131
+ };
132
+ morph: {
133
+ easing: string;
134
+ duration: number;
135
+ };
136
+ stack: {
137
+ easing: string;
138
+ duration: number;
139
+ };
140
+ };
141
+ /** Retune springs live; affects toasts shown afterwards. */
142
+ declare function setSprings(p: Partial<Springs>): void;
143
+ declare function buildCss(): string;
144
+ /** Idempotent; call from the adapter on the client. */
145
+ declare function injectStyles(doc?: Document): void;
146
+
147
+ /** Adapter hook-up: call with the `.tst-slot` element (its first child is the pill). Returns cleanup. */
148
+ declare function bindToast(slot: HTMLElement, id: string, t?: Toaster): () => void;
149
+
150
+ /** Shared keyboard handling for every adapter: Escape dismisses, Alt+T moves focus into the toast. */
151
+ declare function onToastKey(e: KeyboardEvent): void;
152
+ /** Framework-free renderer. Returns an unmount function. */
153
+ declare function mountToaster(opts?: {
154
+ position?: Position;
155
+ theme?: Theme;
156
+ }): () => void;
157
+
158
+ /** Play the cue for a toast type. Silent for types without one, and wherever Web Audio is missing or still locked. */
159
+ declare function chime(type: ToastType, volume?: number): void;
160
+
161
+ declare const ICONS: Record<ToastType, string[]>;
162
+
163
+ export { ICONS, TIMING, bindToast, buildCss, chime, createToaster, getSprings, injectStyles, mountToaster, onToastKey, setSprings, springEasing, toast };
164
+ export type { Phase, Position, PromiseMessages, SpringConfig, Theme, ToastAction, ToastItem, ToastOptions, ToastPatch, ToastType, Toaster, ToasterState };
@@ -0,0 +1,164 @@
1
+ type ToastType = 'success' | 'error' | 'warning' | 'info' | 'loading';
2
+ /** enter: shape only · open: pill expanded · closing: text erased, pill shrinking · exit: shape leaves */
3
+ type Phase = 'enter' | 'open' | 'closing' | 'exit';
4
+ type Position = 'top-center' | 'top-left' | 'top-right' | 'bottom-center' | 'bottom-left' | 'bottom-right';
5
+ type Theme = 'system' | 'light' | 'dark';
6
+ interface ToastAction {
7
+ label: string;
8
+ /** Return a patch to morph this toast in place (e.g. Undo → "Restored"). Return nothing to dismiss it. */
9
+ onClick: () => void | ToastPatch;
10
+ }
11
+ interface ToastOptions {
12
+ id?: string;
13
+ description?: string;
14
+ action?: ToastAction;
15
+ /** Second button beside the action (e.g. Reply + Snooze). */
16
+ secondary?: ToastAction;
17
+ /** Small trailing text beside the title, e.g. a timestamp ("now", "2m"). */
18
+ meta?: string;
19
+ /** Avatar or thumbnail URL. Replaces the status icon with a round image. */
20
+ image?: string;
21
+ /** ms before auto-close. 0 = until dismissed. Default 5000; errors, actions and loading stay until dismissed. */
22
+ duration?: number;
23
+ /** 0–1. Draws a thin bar inside the pill. */
24
+ progress?: number;
25
+ }
26
+ interface ToastPatch {
27
+ title?: string;
28
+ description?: string;
29
+ type?: ToastType;
30
+ duration?: number;
31
+ /** 0–1, or null to remove the bar */
32
+ progress?: number | null;
33
+ /** null removes the action button */
34
+ action?: ToastAction | null;
35
+ secondary?: ToastAction | null;
36
+ /** null removes it */
37
+ meta?: string | null;
38
+ /** null returns to the status icon */
39
+ image?: string | null;
40
+ }
41
+ interface ToastItem {
42
+ id: string;
43
+ type: ToastType;
44
+ title: string;
45
+ description?: string;
46
+ phase: Phase;
47
+ /** ms until auto-close; 0 = stays until dismissed */
48
+ duration: number;
49
+ action?: ToastAction;
50
+ secondary?: ToastAction;
51
+ meta?: string;
52
+ image?: string;
53
+ progress?: number;
54
+ /** identical toasts fired again collapse into one with a counter */
55
+ count: number;
56
+ }
57
+ interface ToasterState {
58
+ toasts: ToastItem[];
59
+ position: Position;
60
+ theme: Theme;
61
+ /** text for the persistent polite live region (role=status) */
62
+ status: string;
63
+ /** text for the persistent assertive live region (role=alert) */
64
+ alert: string;
65
+ }
66
+ interface PromiseMessages<T> {
67
+ loading: string;
68
+ success: string | ((value: T) => string);
69
+ error: string | ((error: unknown) => string);
70
+ }
71
+
72
+ declare const TIMING: {
73
+ /** shape arrives, then the pill opens */
74
+ openDelay: number;
75
+ /** text erase + shrink back to shape */
76
+ closing: number;
77
+ /** shape leaves the screen */
78
+ exit: number;
79
+ duration: number;
80
+ };
81
+ declare function createToaster(): {
82
+ show: (type: ToastType, title: string, opts?: ToastOptions) => string;
83
+ success: (title: string, o?: ToastOptions) => string;
84
+ error: (title: string, o?: ToastOptions) => string;
85
+ warning: (title: string, o?: ToastOptions) => string;
86
+ info: (title: string, o?: ToastOptions) => string;
87
+ loading: (title: string, o?: ToastOptions) => string;
88
+ promise: <T>(p: Promise<T> | (() => Promise<T>), m: PromiseMessages<T>) => Promise<T>;
89
+ update: (callerId: string, p: ToastPatch) => void;
90
+ act: (id: string, which?: "action" | "secondary") => void;
91
+ dismiss: (id?: string, opts?: {
92
+ immediate?: boolean;
93
+ }) => void;
94
+ pause: (id?: string) => void;
95
+ resume: (id?: string) => void;
96
+ configure(c: {
97
+ position?: Position;
98
+ theme?: Theme;
99
+ sound?: boolean | ((type: ToastType) => void);
100
+ volume?: number;
101
+ }): void;
102
+ subscribe(fn: () => void): () => undefined;
103
+ getState: () => ToasterState;
104
+ };
105
+ type Toaster = ReturnType<typeof createToaster>;
106
+ declare const toast: Toaster;
107
+
108
+ interface SpringConfig {
109
+ stiffness?: number;
110
+ damping?: number;
111
+ mass?: number;
112
+ }
113
+ /**
114
+ * Bake a spring into a CSS `linear()` easing so the browser animates it
115
+ * (transitions/keyframes) with no per-frame JS.
116
+ */
117
+ declare function springEasing(config?: SpringConfig): {
118
+ easing: string;
119
+ duration: number;
120
+ };
121
+
122
+ type Springs = {
123
+ enter: SpringConfig;
124
+ morph: SpringConfig;
125
+ stack: SpringConfig;
126
+ };
127
+ declare function getSprings(): {
128
+ enter: {
129
+ easing: string;
130
+ duration: number;
131
+ };
132
+ morph: {
133
+ easing: string;
134
+ duration: number;
135
+ };
136
+ stack: {
137
+ easing: string;
138
+ duration: number;
139
+ };
140
+ };
141
+ /** Retune springs live; affects toasts shown afterwards. */
142
+ declare function setSprings(p: Partial<Springs>): void;
143
+ declare function buildCss(): string;
144
+ /** Idempotent; call from the adapter on the client. */
145
+ declare function injectStyles(doc?: Document): void;
146
+
147
+ /** Adapter hook-up: call with the `.tst-slot` element (its first child is the pill). Returns cleanup. */
148
+ declare function bindToast(slot: HTMLElement, id: string, t?: Toaster): () => void;
149
+
150
+ /** Shared keyboard handling for every adapter: Escape dismisses, Alt+T moves focus into the toast. */
151
+ declare function onToastKey(e: KeyboardEvent): void;
152
+ /** Framework-free renderer. Returns an unmount function. */
153
+ declare function mountToaster(opts?: {
154
+ position?: Position;
155
+ theme?: Theme;
156
+ }): () => void;
157
+
158
+ /** Play the cue for a toast type. Silent for types without one, and wherever Web Audio is missing or still locked. */
159
+ declare function chime(type: ToastType, volume?: number): void;
160
+
161
+ declare const ICONS: Record<ToastType, string[]>;
162
+
163
+ export { ICONS, TIMING, bindToast, buildCss, chime, createToaster, getSprings, injectStyles, mountToaster, onToastKey, setSprings, springEasing, toast };
164
+ export type { Phase, Position, PromiseMessages, SpringConfig, Theme, ToastAction, ToastItem, ToastOptions, ToastPatch, ToastType, Toaster, ToasterState };