varsel 0.5.0 → 0.5.1
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/package.json +1 -1
- package/dist/VarselItem.svelte +0 -900
- package/dist/VarselItem.svelte.d.ts +0 -23
- package/dist/VarselItem.svelte.d.ts.map +0 -1
- package/dist/VarselManager.svelte +0 -431
- package/dist/VarselManager.svelte.d.ts +0 -18
- package/dist/VarselManager.svelte.d.ts.map +0 -1
- package/dist/VarselToaster.svelte +0 -98
- package/dist/VarselToaster.svelte.d.ts +0 -32
- package/dist/VarselToaster.svelte.d.ts.map +0 -1
- package/dist/core/accessibility.d.ts +0 -6
- package/dist/core/accessibility.d.ts.map +0 -1
- package/dist/core/accessibility.js +0 -12
- package/dist/core/animations.d.ts +0 -29
- package/dist/core/animations.d.ts.map +0 -1
- package/dist/core/animations.js +0 -28
- package/dist/core/positions.d.ts +0 -71
- package/dist/core/positions.d.ts.map +0 -1
- package/dist/core/positions.js +0 -30
- package/dist/core/swipe.d.ts +0 -20
- package/dist/core/swipe.d.ts.map +0 -1
- package/dist/core/swipe.js +0 -30
- package/dist/core/toast-factory.d.ts +0 -3
- package/dist/core/toast-factory.d.ts.map +0 -1
- package/dist/core/toast-factory.js +0 -123
- package/dist/core/toast-state.d.ts +0 -49
- package/dist/core/toast-state.d.ts.map +0 -1
- package/dist/core/toast-state.js +0 -80
- package/dist/core/toaster-instances.d.ts +0 -27
- package/dist/core/toaster-instances.d.ts.map +0 -1
- package/dist/core/toaster-instances.js +0 -38
- package/dist/core/types.d.ts +0 -144
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -1
- package/dist/core/utils.d.ts +0 -10
- package/dist/core/utils.d.ts.map +0 -1
- package/dist/core/utils.js +0 -9
- package/dist/core/variants.d.ts +0 -18
- package/dist/core/variants.d.ts.map +0 -1
- package/dist/core/variants.js +0 -56
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/internals.d.ts +0 -16
- package/dist/internals.d.ts.map +0 -1
- package/dist/internals.js +0 -14
- package/dist/styles.css +0 -195
- package/dist/variant-icons.d.ts +0 -108
- package/dist/variant-icons.d.ts.map +0 -1
- package/dist/variant-icons.js +0 -45
package/dist/core/animations.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global configuration constants for toast animations and stacking behavior.
|
|
3
|
-
* These values control timing, spacing, scaling, and easing of toast transitions.
|
|
4
|
-
*/
|
|
5
|
-
export const ANIMATION_CONFIG = {
|
|
6
|
-
/** Duration of the entry animation in seconds. */
|
|
7
|
-
ENTER_DURATION: 0.75,
|
|
8
|
-
/** Duration of the exit animation in seconds. */
|
|
9
|
-
EXIT_DURATION: 0.75,
|
|
10
|
-
/** Duration of the stack reorganization animation in seconds. */
|
|
11
|
-
STACK_DURATION: 0.75,
|
|
12
|
-
/** Vertical offset (in pixels) between stacked toasts in collapsed state. */
|
|
13
|
-
STACK_OFFSET: 16,
|
|
14
|
-
/** Vertical gap (in pixels) between toasts in expanded (hover) state. */
|
|
15
|
-
EXPANDED_GAP: 12,
|
|
16
|
-
/** Scale reduction factor for each subsequent toast in the stack. */
|
|
17
|
-
SCALE_FACTOR: 0.04,
|
|
18
|
-
/** Minimum scale value for the furthest toast in the stack. */
|
|
19
|
-
MIN_SCALE: 0.92,
|
|
20
|
-
/** Maximum number of toasts visible in the stack at once. */
|
|
21
|
-
MAX_VISIBLE_TOASTS: 3,
|
|
22
|
-
/** Base z-index for the toast layer. */
|
|
23
|
-
Z_INDEX_BASE: 50,
|
|
24
|
-
/** Default cubic-bezier easing function for animations. */
|
|
25
|
-
EASING_DEFAULT: "var(--ease-vs-toast)",
|
|
26
|
-
/** Easing function for exit animations. */
|
|
27
|
-
EASING_EXIT: "var(--ease-vs-toast)",
|
|
28
|
-
};
|
package/dist/core/positions.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for initial animation states based on toast position.
|
|
3
|
-
* Defines the starting transform values (x, y) for entering and exiting toasts.
|
|
4
|
-
*/
|
|
5
|
-
export declare const POSITION_CONFIGS: {
|
|
6
|
-
readonly "top-left": {
|
|
7
|
-
readonly animateIn: {
|
|
8
|
-
readonly x: -100;
|
|
9
|
-
readonly y: -20;
|
|
10
|
-
};
|
|
11
|
-
readonly animateOut: {
|
|
12
|
-
readonly x: -100;
|
|
13
|
-
readonly y: -100;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
readonly "top-center": {
|
|
17
|
-
readonly animateIn: {
|
|
18
|
-
readonly x: 0;
|
|
19
|
-
readonly y: -100;
|
|
20
|
-
};
|
|
21
|
-
readonly animateOut: {
|
|
22
|
-
readonly x: 0;
|
|
23
|
-
readonly y: -100;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
readonly "top-right": {
|
|
27
|
-
readonly animateIn: {
|
|
28
|
-
readonly x: 100;
|
|
29
|
-
readonly y: -20;
|
|
30
|
-
};
|
|
31
|
-
readonly animateOut: {
|
|
32
|
-
readonly x: 100;
|
|
33
|
-
readonly y: -100;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
readonly "bottom-left": {
|
|
37
|
-
readonly animateIn: {
|
|
38
|
-
readonly x: -100;
|
|
39
|
-
readonly y: 20;
|
|
40
|
-
};
|
|
41
|
-
readonly animateOut: {
|
|
42
|
-
readonly x: -100;
|
|
43
|
-
readonly y: 100;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
readonly "bottom-center": {
|
|
47
|
-
readonly animateIn: {
|
|
48
|
-
readonly x: 0;
|
|
49
|
-
readonly y: 100;
|
|
50
|
-
};
|
|
51
|
-
readonly animateOut: {
|
|
52
|
-
readonly x: 0;
|
|
53
|
-
readonly y: 100;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
readonly "bottom-right": {
|
|
57
|
-
readonly animateIn: {
|
|
58
|
-
readonly x: 100;
|
|
59
|
-
readonly y: 20;
|
|
60
|
-
};
|
|
61
|
-
readonly animateOut: {
|
|
62
|
-
readonly x: 100;
|
|
63
|
-
readonly y: 100;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Available positions for the toaster on the screen.
|
|
69
|
-
*/
|
|
70
|
-
export type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
71
|
-
//# sourceMappingURL=positions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/lib/core/positions.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBnB,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,aAAa,GACtB,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC"}
|
package/dist/core/positions.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for initial animation states based on toast position.
|
|
3
|
-
* Defines the starting transform values (x, y) for entering and exiting toasts.
|
|
4
|
-
*/
|
|
5
|
-
export const POSITION_CONFIGS = {
|
|
6
|
-
"top-left": {
|
|
7
|
-
animateIn: { x: -100, y: -20 },
|
|
8
|
-
animateOut: { x: -100, y: -100 },
|
|
9
|
-
},
|
|
10
|
-
"top-center": {
|
|
11
|
-
animateIn: { x: 0, y: -100 },
|
|
12
|
-
animateOut: { x: 0, y: -100 },
|
|
13
|
-
},
|
|
14
|
-
"top-right": {
|
|
15
|
-
animateIn: { x: 100, y: -20 },
|
|
16
|
-
animateOut: { x: 100, y: -100 },
|
|
17
|
-
},
|
|
18
|
-
"bottom-left": {
|
|
19
|
-
animateIn: { x: -100, y: 20 },
|
|
20
|
-
animateOut: { x: -100, y: 100 },
|
|
21
|
-
},
|
|
22
|
-
"bottom-center": {
|
|
23
|
-
animateIn: { x: 0, y: 100 },
|
|
24
|
-
animateOut: { x: 0, y: 100 },
|
|
25
|
-
},
|
|
26
|
-
"bottom-right": {
|
|
27
|
-
animateIn: { x: 100, y: 20 },
|
|
28
|
-
animateOut: { x: 100, y: 100 },
|
|
29
|
-
},
|
|
30
|
-
};
|
package/dist/core/swipe.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ToastPosition } from "./positions";
|
|
2
|
-
/** Directions in which a toast can be swiped to dismiss. */
|
|
3
|
-
export type SwipeDirection = "top" | "bottom" | "left" | "right";
|
|
4
|
-
/** Axes along which swipe gestures are tracked. */
|
|
5
|
-
export type SwipeAxis = "x" | "y";
|
|
6
|
-
/** Minimum pixel distance required to trigger a swipe dismissal. */
|
|
7
|
-
export declare const SWIPE_DISMISS_THRESHOLD = 45;
|
|
8
|
-
/** Minimum velocity (pixels/ms) required to trigger a swipe dismissal. */
|
|
9
|
-
export declare const SWIPE_DISMISS_VELOCITY = 0.11;
|
|
10
|
-
/** Distance in pixels to move the toast during the exit animation after a swipe. */
|
|
11
|
-
export declare const SWIPE_EXIT_DISTANCE = 600;
|
|
12
|
-
/**
|
|
13
|
-
* Determines the allowed swipe directions based on the toast's position.
|
|
14
|
-
* For example, a "top-right" toast can be swiped "top" or "right".
|
|
15
|
-
*
|
|
16
|
-
* @param position - The toast's position on screen.
|
|
17
|
-
* @returns An array of allowed swipe directions.
|
|
18
|
-
*/
|
|
19
|
-
export declare const getDefaultSwipeDirections: (position?: ToastPosition | null) => SwipeDirection[];
|
|
20
|
-
//# sourceMappingURL=swipe.d.ts.map
|
package/dist/core/swipe.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"swipe.d.ts","sourceRoot":"","sources":["../../src/lib/core/swipe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AACjE,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG,GAAG,GAAG,GAAG,CAAC;AAElC,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,0EAA0E;AAC1E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACrC,WAAW,aAAa,GAAG,IAAI,KAC7B,cAAc,EAwBhB,CAAC"}
|
package/dist/core/swipe.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/** Minimum pixel distance required to trigger a swipe dismissal. */
|
|
2
|
-
export const SWIPE_DISMISS_THRESHOLD = 45;
|
|
3
|
-
/** Minimum velocity (pixels/ms) required to trigger a swipe dismissal. */
|
|
4
|
-
export const SWIPE_DISMISS_VELOCITY = 0.11;
|
|
5
|
-
/** Distance in pixels to move the toast during the exit animation after a swipe. */
|
|
6
|
-
export const SWIPE_EXIT_DISTANCE = 600;
|
|
7
|
-
/**
|
|
8
|
-
* Determines the allowed swipe directions based on the toast's position.
|
|
9
|
-
* For example, a "top-right" toast can be swiped "top" or "right".
|
|
10
|
-
*
|
|
11
|
-
* @param position - The toast's position on screen.
|
|
12
|
-
* @returns An array of allowed swipe directions.
|
|
13
|
-
*/
|
|
14
|
-
export const getDefaultSwipeDirections = (position) => {
|
|
15
|
-
if (!position) {
|
|
16
|
-
return ["top", "bottom", "left", "right"];
|
|
17
|
-
}
|
|
18
|
-
const [vertical, horizontal] = position.split("-");
|
|
19
|
-
const directions = [];
|
|
20
|
-
if (vertical === "top" || vertical === "bottom") {
|
|
21
|
-
directions.push(vertical);
|
|
22
|
-
}
|
|
23
|
-
if (horizontal === "left" || horizontal === "right") {
|
|
24
|
-
directions.push(horizontal);
|
|
25
|
-
}
|
|
26
|
-
if (directions.length === 0) {
|
|
27
|
-
directions.push("top", "bottom");
|
|
28
|
-
}
|
|
29
|
-
return directions;
|
|
30
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toast-factory.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-factory.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGX,YAAY,EAEZ,MAAM,SAAS,CAAC;AAgKjB,eAAO,MAAM,KAAK,cAAc,CAAC"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { toastState } from "./toast-state";
|
|
2
|
-
/**
|
|
3
|
-
* Helper to normalize string input into a ToastData object.
|
|
4
|
-
*/
|
|
5
|
-
const normalizeToastData = (data) => {
|
|
6
|
-
if (typeof data === "string") {
|
|
7
|
-
return { description: data };
|
|
8
|
-
}
|
|
9
|
-
return data;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Resolves the state of a promise-based toast (success or error) into actual toast data.
|
|
13
|
-
*/
|
|
14
|
-
const resolvePromiseState = async (value, state) => {
|
|
15
|
-
const resolvedValue = typeof state === "function" ? await state(value) : await state;
|
|
16
|
-
return normalizeToastData(resolvedValue);
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* The main entry point for creating toasts.
|
|
20
|
-
* @param data - Toast configuration object or description string.
|
|
21
|
-
* @returns The ID of the created toast.
|
|
22
|
-
*/
|
|
23
|
-
const createToast = ((data) => {
|
|
24
|
-
return toastState.add(normalizeToastData(data));
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
* Creates a success variant toast.
|
|
28
|
-
*/
|
|
29
|
-
createToast.success = (data) => {
|
|
30
|
-
if (typeof data === "string") {
|
|
31
|
-
return toastState.add({ description: data, variant: "success" });
|
|
32
|
-
}
|
|
33
|
-
return toastState.add({ ...data, variant: "success" });
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Creates a warning variant toast.
|
|
37
|
-
*/
|
|
38
|
-
createToast.warning = (data) => {
|
|
39
|
-
if (typeof data === "string") {
|
|
40
|
-
return toastState.add({ description: data, variant: "warning" });
|
|
41
|
-
}
|
|
42
|
-
return toastState.add({ ...data, variant: "warning" });
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Creates an info variant toast.
|
|
46
|
-
*/
|
|
47
|
-
createToast.info = (data) => {
|
|
48
|
-
if (typeof data === "string") {
|
|
49
|
-
return toastState.add({ description: data, variant: "info" });
|
|
50
|
-
}
|
|
51
|
-
return toastState.add({ ...data, variant: "info" });
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Creates an error (destructive) variant toast.
|
|
55
|
-
*/
|
|
56
|
-
createToast.error = (data) => {
|
|
57
|
-
if (typeof data === "string") {
|
|
58
|
-
return toastState.add({ description: data, variant: "destructive" });
|
|
59
|
-
}
|
|
60
|
-
return toastState.add({ ...data, variant: "destructive" });
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Creates a custom component toast.
|
|
64
|
-
* @param component - The Svelte component to render.
|
|
65
|
-
* @param options - Additional options and props for the component.
|
|
66
|
-
*/
|
|
67
|
-
createToast.custom = (component, // Type inferred from ToastInvoker
|
|
68
|
-
options) => {
|
|
69
|
-
return toastState.add({
|
|
70
|
-
...(options ?? {}),
|
|
71
|
-
component: component,
|
|
72
|
-
variant: "custom",
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Creates a toast that tracks a promise's lifecycle.
|
|
77
|
-
* Updates automatically from loading -> success/error.
|
|
78
|
-
*
|
|
79
|
-
* @param promise - The promise to observe.
|
|
80
|
-
* @param options - Configuration for loading, success, and error states.
|
|
81
|
-
* @returns The ID of the toast.
|
|
82
|
-
*/
|
|
83
|
-
createToast.promise = (promise, options) => {
|
|
84
|
-
const loadingData = normalizeToastData(options.loading);
|
|
85
|
-
const toastId = toastState.add({
|
|
86
|
-
...loadingData,
|
|
87
|
-
duration: loadingData.duration ?? 0,
|
|
88
|
-
isLoading: true,
|
|
89
|
-
showClose: loadingData.showClose ?? false,
|
|
90
|
-
});
|
|
91
|
-
const handleResult = async (state, value, defaultVariant) => {
|
|
92
|
-
const payload = await resolvePromiseState(value, state);
|
|
93
|
-
toastState.update(toastId, {
|
|
94
|
-
...payload,
|
|
95
|
-
isLoading: false,
|
|
96
|
-
duration: payload.duration,
|
|
97
|
-
variant: payload.variant ?? defaultVariant,
|
|
98
|
-
showClose: payload.showClose ?? false,
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
Promise.resolve(promise)
|
|
102
|
-
.then(async (value) => {
|
|
103
|
-
await handleResult(options.success, value, "success");
|
|
104
|
-
return value;
|
|
105
|
-
})
|
|
106
|
-
.catch(async (error) => {
|
|
107
|
-
await handleResult(options.error, error, "destructive");
|
|
108
|
-
});
|
|
109
|
-
return toastId;
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Dismisses a toast by ID.
|
|
113
|
-
*/
|
|
114
|
-
createToast.dismiss = (id) => {
|
|
115
|
-
toastState.update(id, { shouldClose: true });
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Dismisses all active toasts.
|
|
119
|
-
*/
|
|
120
|
-
createToast.dismissAll = () => {
|
|
121
|
-
toastState.dismissAll();
|
|
122
|
-
};
|
|
123
|
-
export const toast = createToast;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ToastData, ToastSubscriber } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* Manages the global state of toast notifications.
|
|
4
|
-
* Implements a singleton pattern with a subscription mechanism.
|
|
5
|
-
*/
|
|
6
|
-
declare class ToastState {
|
|
7
|
-
private toasts;
|
|
8
|
-
private subscribers;
|
|
9
|
-
private idCounter;
|
|
10
|
-
/**
|
|
11
|
-
* Subscribes to changes in the toast list.
|
|
12
|
-
* @param callback - Function to be called when the toast list updates.
|
|
13
|
-
* @returns A cleanup function to unsubscribe.
|
|
14
|
-
*/
|
|
15
|
-
subscribe(callback: ToastSubscriber): () => void;
|
|
16
|
-
private notify;
|
|
17
|
-
private generateId;
|
|
18
|
-
/**
|
|
19
|
-
* Adds a new toast to the state.
|
|
20
|
-
* @param data - The toast configuration (without ID).
|
|
21
|
-
* @returns The generated ID of the new toast.
|
|
22
|
-
*/
|
|
23
|
-
add(data: Omit<ToastData, "id">): string;
|
|
24
|
-
/**
|
|
25
|
-
* Removes a toast from the state by its ID.
|
|
26
|
-
* @param id - The ID of the toast to remove.
|
|
27
|
-
*/
|
|
28
|
-
remove(id: string): void;
|
|
29
|
-
/**
|
|
30
|
-
* Updates an existing toast's data.
|
|
31
|
-
* @param id - The ID of the toast to update.
|
|
32
|
-
* @param data - Partial data to merge into the existing toast.
|
|
33
|
-
*/
|
|
34
|
-
update(id: string, data: Partial<ToastData>): void;
|
|
35
|
-
/**
|
|
36
|
-
* Marks all active toasts for dismissal.
|
|
37
|
-
* Triggers the closing animation by setting `shouldClose` to true.
|
|
38
|
-
*/
|
|
39
|
-
dismissAll(): void;
|
|
40
|
-
/**
|
|
41
|
-
* Returns the current list of active toasts.
|
|
42
|
-
* @returns A copy of the toast array.
|
|
43
|
-
*/
|
|
44
|
-
getToasts(): ToastData[];
|
|
45
|
-
}
|
|
46
|
-
/** Global singleton instance of the toast state. */
|
|
47
|
-
export declare const toastState: ToastState;
|
|
48
|
-
export { ToastState };
|
|
49
|
-
//# sourceMappingURL=toast-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toast-state.d.ts","sourceRoot":"","sources":["../../src/lib/core/toast-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1D;;;GAGG;AACH,cAAM,UAAU;IACf,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,SAAS,CAAK;IAEtB;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAOhD,OAAO,CAAC,MAAM;IAMd,OAAO,CAAC,UAAU;IAIlB;;;;OAIG;IACH,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,MAAM;IASxC;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,IAAI;IAOlD;;;OAGG;IACH,UAAU,IAAI,IAAI;IASlB;;;OAGG;IACH,SAAS,IAAI,SAAS,EAAE;CAGxB;AAED,oDAAoD;AACpD,eAAO,MAAM,UAAU,YAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/core/toast-state.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages the global state of toast notifications.
|
|
3
|
-
* Implements a singleton pattern with a subscription mechanism.
|
|
4
|
-
*/
|
|
5
|
-
class ToastState {
|
|
6
|
-
toasts = [];
|
|
7
|
-
subscribers = new Set();
|
|
8
|
-
idCounter = 0;
|
|
9
|
-
/**
|
|
10
|
-
* Subscribes to changes in the toast list.
|
|
11
|
-
* @param callback - Function to be called when the toast list updates.
|
|
12
|
-
* @returns A cleanup function to unsubscribe.
|
|
13
|
-
*/
|
|
14
|
-
subscribe(callback) {
|
|
15
|
-
this.subscribers.add(callback);
|
|
16
|
-
return () => {
|
|
17
|
-
this.subscribers.delete(callback);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
notify() {
|
|
21
|
-
this.subscribers.forEach((callback) => {
|
|
22
|
-
callback([...this.toasts]);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
generateId() {
|
|
26
|
-
return `toast-${Date.now()}-${++this.idCounter}`;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Adds a new toast to the state.
|
|
30
|
-
* @param data - The toast configuration (without ID).
|
|
31
|
-
* @returns The generated ID of the new toast.
|
|
32
|
-
*/
|
|
33
|
-
add(data) {
|
|
34
|
-
const id = this.generateId();
|
|
35
|
-
const newToast = { ...data, id };
|
|
36
|
-
// Add new toasts to the beginning of the array (stack LIFO visually for some positions, logic handled in manager)
|
|
37
|
-
this.toasts = [newToast, ...this.toasts];
|
|
38
|
-
this.notify();
|
|
39
|
-
return id;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Removes a toast from the state by its ID.
|
|
43
|
-
* @param id - The ID of the toast to remove.
|
|
44
|
-
*/
|
|
45
|
-
remove(id) {
|
|
46
|
-
this.toasts = this.toasts.filter((toast) => toast.id !== id);
|
|
47
|
-
this.notify();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Updates an existing toast's data.
|
|
51
|
-
* @param id - The ID of the toast to update.
|
|
52
|
-
* @param data - Partial data to merge into the existing toast.
|
|
53
|
-
*/
|
|
54
|
-
update(id, data) {
|
|
55
|
-
this.toasts = this.toasts.map((toast) => toast.id === id ? { ...toast, ...data } : toast);
|
|
56
|
-
this.notify();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Marks all active toasts for dismissal.
|
|
60
|
-
* Triggers the closing animation by setting `shouldClose` to true.
|
|
61
|
-
*/
|
|
62
|
-
dismissAll() {
|
|
63
|
-
this.toasts = this.toasts.map((toast) => ({
|
|
64
|
-
...toast,
|
|
65
|
-
shouldClose: true,
|
|
66
|
-
duration: 0,
|
|
67
|
-
}));
|
|
68
|
-
this.notify();
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Returns the current list of active toasts.
|
|
72
|
-
* @returns A copy of the toast array.
|
|
73
|
-
*/
|
|
74
|
-
getToasts() {
|
|
75
|
-
return [...this.toasts];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/** Global singleton instance of the toast state. */
|
|
79
|
-
export const toastState = new ToastState();
|
|
80
|
-
export { ToastState };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages unique instances of the Toaster component to prevent conflicts.
|
|
3
|
-
* Ensures that if multiple Toasters are rendered, only one (the first or primary) is active.
|
|
4
|
-
*/
|
|
5
|
-
declare class ToasterInstanceManager {
|
|
6
|
-
private activeInstanceId;
|
|
7
|
-
private instanceCounter;
|
|
8
|
-
/**
|
|
9
|
-
* Registers a new toaster instance.
|
|
10
|
-
* @returns A unique instance ID.
|
|
11
|
-
*/
|
|
12
|
-
registerInstance(): string;
|
|
13
|
-
/**
|
|
14
|
-
* Unregisters an instance, potentially freeing up the active slot.
|
|
15
|
-
* @param instanceId - The ID of the instance to unregister.
|
|
16
|
-
*/
|
|
17
|
-
unregisterInstance(instanceId: string): void;
|
|
18
|
-
/**
|
|
19
|
-
* Checks if the given instance is the currently active one.
|
|
20
|
-
* @param instanceId - The ID to check.
|
|
21
|
-
* @returns True if active, false otherwise.
|
|
22
|
-
*/
|
|
23
|
-
isActiveInstance(instanceId: string): boolean;
|
|
24
|
-
}
|
|
25
|
-
export declare const toasterInstanceManager: ToasterInstanceManager;
|
|
26
|
-
export { ToasterInstanceManager };
|
|
27
|
-
//# sourceMappingURL=toaster-instances.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toaster-instances.d.ts","sourceRoot":"","sources":["../../src/lib/core/toaster-instances.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAM,sBAAsB;IAC3B,OAAO,CAAC,gBAAgB,CAAuB;IAC/C,OAAO,CAAC,eAAe,CAAK;IAE5B;;;OAGG;IACH,gBAAgB,IAAI,MAAM;IAQ1B;;;OAGG;IACH,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAM5C;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;CAG7C;AAED,eAAO,MAAM,sBAAsB,wBAA+B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages unique instances of the Toaster component to prevent conflicts.
|
|
3
|
-
* Ensures that if multiple Toasters are rendered, only one (the first or primary) is active.
|
|
4
|
-
*/
|
|
5
|
-
class ToasterInstanceManager {
|
|
6
|
-
activeInstanceId = null;
|
|
7
|
-
instanceCounter = 0;
|
|
8
|
-
/**
|
|
9
|
-
* Registers a new toaster instance.
|
|
10
|
-
* @returns A unique instance ID.
|
|
11
|
-
*/
|
|
12
|
-
registerInstance() {
|
|
13
|
-
const instanceId = `toaster-${++this.instanceCounter}`;
|
|
14
|
-
if (!this.activeInstanceId) {
|
|
15
|
-
this.activeInstanceId = instanceId;
|
|
16
|
-
}
|
|
17
|
-
return instanceId;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Unregisters an instance, potentially freeing up the active slot.
|
|
21
|
-
* @param instanceId - The ID of the instance to unregister.
|
|
22
|
-
*/
|
|
23
|
-
unregisterInstance(instanceId) {
|
|
24
|
-
if (this.activeInstanceId === instanceId) {
|
|
25
|
-
this.activeInstanceId = null;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Checks if the given instance is the currently active one.
|
|
30
|
-
* @param instanceId - The ID to check.
|
|
31
|
-
* @returns True if active, false otherwise.
|
|
32
|
-
*/
|
|
33
|
-
isActiveInstance(instanceId) {
|
|
34
|
-
return this.activeInstanceId === instanceId;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export const toasterInstanceManager = new ToasterInstanceManager();
|
|
38
|
-
export { ToasterInstanceManager };
|
package/dist/core/types.d.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import type { VariantProps } from "class-variance-authority";
|
|
2
|
-
import type { Component } from "svelte";
|
|
3
|
-
import type { toastContainerVariants } from "./variants";
|
|
4
|
-
import type { ToastPosition } from "./positions";
|
|
5
|
-
import type { SwipeAxis, SwipeDirection } from "./swipe";
|
|
6
|
-
/**
|
|
7
|
-
* Represents the data structure for a single toast notification.
|
|
8
|
-
*/
|
|
9
|
-
export interface ToastData extends VariantProps<typeof toastContainerVariants> {
|
|
10
|
-
/** Unique identifier for the toast. */
|
|
11
|
-
id: string;
|
|
12
|
-
/** The main title of the toast notification. */
|
|
13
|
-
title?: string;
|
|
14
|
-
/** Additional details or description displayed below the title. */
|
|
15
|
-
description?: string;
|
|
16
|
-
/** Optional CSS class to apply to the toast container. */
|
|
17
|
-
className?: string;
|
|
18
|
-
/**
|
|
19
|
-
* Duration in milliseconds before the toast automatically closes.
|
|
20
|
-
* Defaults to 5000ms. Set to `Infinity` to keep open indefinitely.
|
|
21
|
-
*/
|
|
22
|
-
duration?: number;
|
|
23
|
-
/** Whether the toast is in a loading state. */
|
|
24
|
-
isLoading?: boolean;
|
|
25
|
-
/** Whether to show the close button. Defaults to `true`. */
|
|
26
|
-
showClose?: boolean;
|
|
27
|
-
/** Optional action button to display within the toast. */
|
|
28
|
-
action?: {
|
|
29
|
-
/** Label for the action button. */
|
|
30
|
-
label: string;
|
|
31
|
-
/** Callback function executed when the action button is clicked. */
|
|
32
|
-
onClick: () => void;
|
|
33
|
-
};
|
|
34
|
-
/** Callback fired when the toast finishes its auto-close timer. */
|
|
35
|
-
onAutoClose?: () => void;
|
|
36
|
-
/** Callback fired when the toast is dismissed manually (button, swipe, `toast.dismiss`, etc.). */
|
|
37
|
-
onDismiss?: () => void;
|
|
38
|
-
/** Internal flag: signals that the toast should begin its closing animation. */
|
|
39
|
-
shouldClose?: boolean;
|
|
40
|
-
/** Internal flag: signals that the toast is currently leaving the DOM. */
|
|
41
|
-
isLeaving?: boolean;
|
|
42
|
-
/** The position on the screen where this toast should appear. */
|
|
43
|
-
position?: ToastPosition;
|
|
44
|
-
/** Custom Svelte component to render instead of the default toast layout. */
|
|
45
|
-
component?: Component<any>;
|
|
46
|
-
/** Props to pass to the custom component. */
|
|
47
|
-
componentProps?: Record<string, any>;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Represents the possible states for a promise-based toast.
|
|
51
|
-
* Can be a static message string, a ToastData object (minus ID), or a function returning one of those.
|
|
52
|
-
*/
|
|
53
|
-
export type PromiseToastState<Value> = string | Omit<ToastData, "id"> | ((value: Value) => string | Omit<ToastData, "id"> | PromiseLike<string | Omit<ToastData, "id">>);
|
|
54
|
-
/**
|
|
55
|
-
* Options for the `toast.promise` function.
|
|
56
|
-
*/
|
|
57
|
-
export type ToastPromiseOptions<SuccessValue = unknown, ErrorValue = unknown> = {
|
|
58
|
-
/** The message or data to show while the promise is pending. */
|
|
59
|
-
loading: Omit<ToastData, "id"> | string;
|
|
60
|
-
/** The message or data to show when the promise resolves successfully. */
|
|
61
|
-
success: PromiseToastState<SuccessValue>;
|
|
62
|
-
/** The message or data to show when the promise rejects. */
|
|
63
|
-
error: PromiseToastState<ErrorValue>;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* The interface for the main `toast` function and its utility methods.
|
|
67
|
-
*/
|
|
68
|
-
export type ToastInvoker = {
|
|
69
|
-
/**
|
|
70
|
-
* Creates a default toast notification.
|
|
71
|
-
* @param data - The toast options or description string.
|
|
72
|
-
* @returns The ID of the created toast.
|
|
73
|
-
*/
|
|
74
|
-
(data: Omit<ToastData, "id"> | string): string;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a success toast notification.
|
|
77
|
-
*/
|
|
78
|
-
success: (data: Omit<ToastData, "id" | "variant"> | string) => string;
|
|
79
|
-
/**
|
|
80
|
-
* Creates a warning toast notification.
|
|
81
|
-
*/
|
|
82
|
-
warning: (data: Omit<ToastData, "id" | "variant"> | string) => string;
|
|
83
|
-
/**
|
|
84
|
-
* Creates an info toast notification.
|
|
85
|
-
*/
|
|
86
|
-
info: (data: Omit<ToastData, "id" | "variant"> | string) => string;
|
|
87
|
-
/**
|
|
88
|
-
* Creates an error toast notification.
|
|
89
|
-
*/
|
|
90
|
-
error: (data: Omit<ToastData, "id" | "variant"> | string) => string;
|
|
91
|
-
/**
|
|
92
|
-
* Creates a custom component toast.
|
|
93
|
-
* @param component - The Svelte component to render.
|
|
94
|
-
* @param options - Additional options and props for the component.
|
|
95
|
-
*/
|
|
96
|
-
custom: <Props extends Record<string, any> = Record<string, any>>(component: Component<Props>, options?: Omit<ToastData, "id" | "component" | "variant" | "componentProps"> & {
|
|
97
|
-
componentProps?: Omit<Props, "id" | "toast">;
|
|
98
|
-
}) => string;
|
|
99
|
-
/**
|
|
100
|
-
* Creates a toast that updates based on the state of a Promise.
|
|
101
|
-
* @param promise - The promise to track.
|
|
102
|
-
* @param options - Configuration for loading, success, and error states.
|
|
103
|
-
* @returns The ID of the toast.
|
|
104
|
-
*/
|
|
105
|
-
promise: <T, E = unknown>(promise: PromiseLike<T>, options: ToastPromiseOptions<T, E>) => string;
|
|
106
|
-
/**
|
|
107
|
-
* Dismisses a specific toast by its ID.
|
|
108
|
-
* @param id - The ID of the toast to dismiss.
|
|
109
|
-
*/
|
|
110
|
-
dismiss: (id: string) => void;
|
|
111
|
-
/**
|
|
112
|
-
* Dismisses all currently active toasts.
|
|
113
|
-
*/
|
|
114
|
-
dismissAll: () => void;
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Extends `ToastData` with positioning information for rendering.
|
|
118
|
-
*/
|
|
119
|
-
export type PositionedToast = ToastData & {
|
|
120
|
-
/** The visual index of the toast in the stack. */
|
|
121
|
-
index: number;
|
|
122
|
-
/** The render order index (z-index calculation base). */
|
|
123
|
-
renderIndex: number;
|
|
124
|
-
/** Total number of toasts in the current group. */
|
|
125
|
-
total: number;
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Context provided to toast items (mostly for internal use).
|
|
129
|
-
*/
|
|
130
|
-
export interface VarselItemContext {
|
|
131
|
-
toast: PositionedToast;
|
|
132
|
-
onRemove: (id: string) => void;
|
|
133
|
-
isGroupHovered?: boolean;
|
|
134
|
-
expandedOffset?: number;
|
|
135
|
-
expandedGap?: number;
|
|
136
|
-
collapsedOffset?: number;
|
|
137
|
-
hiddenCollapsedOffset?: number;
|
|
138
|
-
onHeightChange?: (id: string, height: number) => void;
|
|
139
|
-
onGroupHoverEnter?: () => void;
|
|
140
|
-
}
|
|
141
|
-
/** Function signature for toast state subscribers. */
|
|
142
|
-
export type ToastSubscriber = (toasts: ToastData[]) => void;
|
|
143
|
-
export type { ToastPosition, SwipeAxis, SwipeDirection };
|
|
144
|
-
//# sourceMappingURL=types.d.ts.map
|