vue-notifyr 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/LICENCE +21 -0
- package/README.md +226 -0
- package/dist/index.cjs +355 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +281 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +245 -0
- package/package.json +71 -0
- package/src/adapters/inertia/index.ts +2 -0
- package/src/adapters/nuxt/index.ts +24 -0
- package/src/adapters/vue/NotificationContainer.vue +78 -0
- package/src/adapters/vue/index.ts +70 -0
- package/src/composables/useNotification.ts +11 -0
- package/src/core/notification-manager.ts +151 -0
- package/src/env.d.ts +5 -0
- package/src/index.ts +27 -0
- package/src/styles/style.css +245 -0
- package/src/types/index.ts +23 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ComponentOptionsMixin } from 'vue';
|
|
2
|
+
import { ComponentProvideOptions } from 'vue';
|
|
3
|
+
import { DefineComponent } from 'vue';
|
|
4
|
+
import { PublicProps } from 'vue';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create a reactive store for Vue that syncs with the NotificationManager.
|
|
8
|
+
* @param manager - The NotificationManager instance (optional, uses default if not provided)
|
|
9
|
+
* @returns Reactive store
|
|
10
|
+
*/
|
|
11
|
+
export declare function createReactiveNotificationStore(manager?: NotificationManager): ReactiveNotificationStore;
|
|
12
|
+
|
|
13
|
+
export declare function createVueNotificationPlugin(manager?: NotificationManager): {
|
|
14
|
+
install(app: any): void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export declare const NotificationContainer: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
|
|
18
|
+
|
|
19
|
+
export declare interface NotificationItem {
|
|
20
|
+
id: number;
|
|
21
|
+
type: NotificationType;
|
|
22
|
+
title: string;
|
|
23
|
+
options: Required<NotificationOptions_2>;
|
|
24
|
+
createdAt: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare class NotificationManager {
|
|
28
|
+
private notifications;
|
|
29
|
+
private options;
|
|
30
|
+
private listeners;
|
|
31
|
+
private idCounter;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to an event.
|
|
34
|
+
* @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')
|
|
35
|
+
* @param callback - The callback function
|
|
36
|
+
*/
|
|
37
|
+
on(event: string, callback: Function): void;
|
|
38
|
+
/**
|
|
39
|
+
* Unsubscribe from an event.
|
|
40
|
+
* @param event - The event name
|
|
41
|
+
* @param callback - The callback function to remove
|
|
42
|
+
*/
|
|
43
|
+
off(event: string, callback: Function): void;
|
|
44
|
+
private emit;
|
|
45
|
+
/**
|
|
46
|
+
* Set default options for notifications.
|
|
47
|
+
* @param opts - The options to set as defaults
|
|
48
|
+
*/
|
|
49
|
+
setDefaults(opts: NotificationOptions_2): void;
|
|
50
|
+
/**
|
|
51
|
+
* Show a notification.
|
|
52
|
+
* @param type - The type of notification
|
|
53
|
+
* @param title - The title/message of the notification
|
|
54
|
+
* @param opts - Optional override options
|
|
55
|
+
*/
|
|
56
|
+
show(type: NotificationType, title: string, opts?: NotificationOptions_2): void;
|
|
57
|
+
/**
|
|
58
|
+
* Remove a notification by ID.
|
|
59
|
+
* @param id - The ID of the notification to remove
|
|
60
|
+
*/
|
|
61
|
+
remove(id: number): void;
|
|
62
|
+
/**
|
|
63
|
+
* Clear all notifications.
|
|
64
|
+
*/
|
|
65
|
+
clear(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Get a copy of the current notifications.
|
|
68
|
+
* @returns Array of notification items
|
|
69
|
+
*/
|
|
70
|
+
getNotifications(): NotificationItem[];
|
|
71
|
+
/**
|
|
72
|
+
* Get the current default options.
|
|
73
|
+
* @returns The default options
|
|
74
|
+
*/
|
|
75
|
+
getOptions(): Required<NotificationOptions_2>;
|
|
76
|
+
/**
|
|
77
|
+
* Success notification shorthand.
|
|
78
|
+
* @param title - The title/message
|
|
79
|
+
* @param opts - Optional options
|
|
80
|
+
*/
|
|
81
|
+
success(title: string, opts?: NotificationOptions_2): void;
|
|
82
|
+
/**
|
|
83
|
+
* Error notification shorthand.
|
|
84
|
+
* @param title - The title/message
|
|
85
|
+
* @param opts - Optional options
|
|
86
|
+
*/
|
|
87
|
+
error(title: string, opts?: NotificationOptions_2): void;
|
|
88
|
+
/**
|
|
89
|
+
* Warning notification shorthand.
|
|
90
|
+
* @param title - The title/message
|
|
91
|
+
* @param opts - Optional options
|
|
92
|
+
*/
|
|
93
|
+
warning(title: string, opts?: NotificationOptions_2): void;
|
|
94
|
+
/**
|
|
95
|
+
* Info notification shorthand.
|
|
96
|
+
* @param title - The title/message
|
|
97
|
+
* @param opts - Optional options
|
|
98
|
+
*/
|
|
99
|
+
info(title: string, opts?: NotificationOptions_2): void;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export declare const notificationManager: NotificationManager;
|
|
103
|
+
|
|
104
|
+
declare interface NotificationOptions_2 {
|
|
105
|
+
position?: NotificationPosition;
|
|
106
|
+
autoClose?: number | false;
|
|
107
|
+
progress?: boolean;
|
|
108
|
+
}
|
|
109
|
+
export { NotificationOptions_2 as NotificationOptions }
|
|
110
|
+
|
|
111
|
+
export declare type NotificationPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
112
|
+
|
|
113
|
+
export declare const notificationStore: ReactiveNotificationStore;
|
|
114
|
+
|
|
115
|
+
export declare type NotificationType = 'success' | 'error' | 'warning' | 'info';
|
|
116
|
+
|
|
117
|
+
export declare interface ReactiveNotificationStore {
|
|
118
|
+
notifications: NotificationItem[];
|
|
119
|
+
options: NotificationOptions_2;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Vue composable for notification management.
|
|
124
|
+
* Provides a clean API to show notifications in Vue components.
|
|
125
|
+
*
|
|
126
|
+
* @returns Notification manager API
|
|
127
|
+
*/
|
|
128
|
+
export declare function useNotification(): {
|
|
129
|
+
success: (title: string, opts?: NotificationOptions_2) => void;
|
|
130
|
+
error: (title: string, opts?: NotificationOptions_2) => void;
|
|
131
|
+
warning: (title: string, opts?: NotificationOptions_2) => void;
|
|
132
|
+
info: (title: string, opts?: NotificationOptions_2) => void;
|
|
133
|
+
show: (type: string, title: string, opts?: NotificationOptions_2) => void;
|
|
134
|
+
remove: (id: number) => void;
|
|
135
|
+
clear: () => void;
|
|
136
|
+
setDefaults: (opts: NotificationOptions_2) => void;
|
|
137
|
+
getNotifications: () => NotificationItem[];
|
|
138
|
+
getOptions: () => Required<NotificationOptions_2>;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export declare function useNotificationManager(manager?: NotificationManager): {
|
|
142
|
+
success: (title: string, opts?: NotificationOptions_2) => void;
|
|
143
|
+
error: (title: string, opts?: NotificationOptions_2) => void;
|
|
144
|
+
warning: (title: string, opts?: NotificationOptions_2) => void;
|
|
145
|
+
info: (title: string, opts?: NotificationOptions_2) => void;
|
|
146
|
+
show: (type: string, title: string, opts?: NotificationOptions_2) => void;
|
|
147
|
+
remove: (id: number) => void;
|
|
148
|
+
clear: () => void;
|
|
149
|
+
setDefaults: (opts: NotificationOptions_2) => void;
|
|
150
|
+
getNotifications: () => NotificationItem[];
|
|
151
|
+
getOptions: () => Required<NotificationOptions_2>;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { reactive, defineComponent, ref, computed, openBlock, createBlock, Teleport, createElementBlock, Fragment, renderList, TransitionGroup, withCtx, normalizeClass, createElementVNode, toDisplayString, normalizeStyle, createCommentVNode } from "vue";
|
|
2
|
+
const DEFAULT_OPTIONS = {
|
|
3
|
+
position: "top-center",
|
|
4
|
+
autoClose: 3e3,
|
|
5
|
+
progress: true
|
|
6
|
+
};
|
|
7
|
+
class NotificationManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.notifications = [];
|
|
10
|
+
this.options = { ...DEFAULT_OPTIONS };
|
|
11
|
+
this.listeners = {};
|
|
12
|
+
this.idCounter = 1;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Subscribe to an event.
|
|
16
|
+
* @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')
|
|
17
|
+
* @param callback - The callback function
|
|
18
|
+
*/
|
|
19
|
+
on(event, callback) {
|
|
20
|
+
if (!this.listeners[event]) {
|
|
21
|
+
this.listeners[event] = [];
|
|
22
|
+
}
|
|
23
|
+
this.listeners[event].push(callback);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Unsubscribe from an event.
|
|
27
|
+
* @param event - The event name
|
|
28
|
+
* @param callback - The callback function to remove
|
|
29
|
+
*/
|
|
30
|
+
off(event, callback) {
|
|
31
|
+
if (this.listeners[event]) {
|
|
32
|
+
this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
emit(event, data) {
|
|
36
|
+
if (this.listeners[event]) {
|
|
37
|
+
this.listeners[event].forEach((callback) => callback(data));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set default options for notifications.
|
|
42
|
+
* @param opts - The options to set as defaults
|
|
43
|
+
*/
|
|
44
|
+
setDefaults(opts) {
|
|
45
|
+
this.options = { ...this.options, ...opts };
|
|
46
|
+
this.emit("options-changed", this.options);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Show a notification.
|
|
50
|
+
* @param type - The type of notification
|
|
51
|
+
* @param title - The title/message of the notification
|
|
52
|
+
* @param opts - Optional override options
|
|
53
|
+
*/
|
|
54
|
+
show(type, title, opts) {
|
|
55
|
+
const options = { ...this.options, ...opts || {} };
|
|
56
|
+
const item = {
|
|
57
|
+
id: this.idCounter++,
|
|
58
|
+
type,
|
|
59
|
+
title,
|
|
60
|
+
options,
|
|
61
|
+
createdAt: Date.now()
|
|
62
|
+
};
|
|
63
|
+
this.notifications.push(item);
|
|
64
|
+
this.emit("notification-added", item);
|
|
65
|
+
if (options.autoClose !== false && typeof window !== "undefined") {
|
|
66
|
+
setTimeout(() => this.remove(item.id), options.autoClose);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Remove a notification by ID.
|
|
71
|
+
* @param id - The ID of the notification to remove
|
|
72
|
+
*/
|
|
73
|
+
remove(id) {
|
|
74
|
+
const index = this.notifications.findIndex((n) => n.id === id);
|
|
75
|
+
if (index !== -1) {
|
|
76
|
+
const removed = this.notifications.splice(index, 1)[0];
|
|
77
|
+
this.emit("notification-removed", removed);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Clear all notifications.
|
|
82
|
+
*/
|
|
83
|
+
clear() {
|
|
84
|
+
const removed = [...this.notifications];
|
|
85
|
+
this.notifications.splice(0);
|
|
86
|
+
this.emit("notifications-cleared", removed);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get a copy of the current notifications.
|
|
90
|
+
* @returns Array of notification items
|
|
91
|
+
*/
|
|
92
|
+
getNotifications() {
|
|
93
|
+
return [...this.notifications];
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Get the current default options.
|
|
97
|
+
* @returns The default options
|
|
98
|
+
*/
|
|
99
|
+
getOptions() {
|
|
100
|
+
return { ...this.options };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Success notification shorthand.
|
|
104
|
+
* @param title - The title/message
|
|
105
|
+
* @param opts - Optional options
|
|
106
|
+
*/
|
|
107
|
+
success(title, opts) {
|
|
108
|
+
this.show("success", title, opts);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Error notification shorthand.
|
|
112
|
+
* @param title - The title/message
|
|
113
|
+
* @param opts - Optional options
|
|
114
|
+
*/
|
|
115
|
+
error(title, opts) {
|
|
116
|
+
this.show("error", title, opts);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Warning notification shorthand.
|
|
120
|
+
* @param title - The title/message
|
|
121
|
+
* @param opts - Optional options
|
|
122
|
+
*/
|
|
123
|
+
warning(title, opts) {
|
|
124
|
+
this.show("warning", title, opts);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Info notification shorthand.
|
|
128
|
+
* @param title - The title/message
|
|
129
|
+
* @param opts - Optional options
|
|
130
|
+
*/
|
|
131
|
+
info(title, opts) {
|
|
132
|
+
this.show("info", title, opts);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const notificationManager = new NotificationManager();
|
|
136
|
+
function createReactiveNotificationStore(manager = notificationManager) {
|
|
137
|
+
const store = reactive({
|
|
138
|
+
notifications: manager.getNotifications(),
|
|
139
|
+
options: manager.getOptions()
|
|
140
|
+
});
|
|
141
|
+
manager.on("notification-added", () => {
|
|
142
|
+
store.notifications = manager.getNotifications();
|
|
143
|
+
});
|
|
144
|
+
manager.on("notification-removed", () => {
|
|
145
|
+
store.notifications = manager.getNotifications();
|
|
146
|
+
});
|
|
147
|
+
manager.on("notifications-cleared", () => {
|
|
148
|
+
store.notifications = manager.getNotifications();
|
|
149
|
+
});
|
|
150
|
+
manager.on("options-changed", () => {
|
|
151
|
+
store.options = manager.getOptions();
|
|
152
|
+
});
|
|
153
|
+
return store;
|
|
154
|
+
}
|
|
155
|
+
const notificationStore = createReactiveNotificationStore();
|
|
156
|
+
function useNotificationManager(manager = notificationManager) {
|
|
157
|
+
return {
|
|
158
|
+
success: (title, opts) => manager.success(title, opts),
|
|
159
|
+
error: (title, opts) => manager.error(title, opts),
|
|
160
|
+
warning: (title, opts) => manager.warning(title, opts),
|
|
161
|
+
info: (title, opts) => manager.info(title, opts),
|
|
162
|
+
show: (type, title, opts) => manager.show(type, title, opts),
|
|
163
|
+
remove: (id) => manager.remove(id),
|
|
164
|
+
clear: () => manager.clear(),
|
|
165
|
+
setDefaults: (opts) => manager.setDefaults(opts),
|
|
166
|
+
getNotifications: () => manager.getNotifications(),
|
|
167
|
+
getOptions: () => manager.getOptions()
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function createVueNotificationPlugin$1(manager = notificationManager) {
|
|
171
|
+
return {
|
|
172
|
+
install(app) {
|
|
173
|
+
app.config.globalProperties.$notificationManager = manager;
|
|
174
|
+
app.provide("notificationManager", manager);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const _hoisted_1 = ["data-position"];
|
|
179
|
+
const _hoisted_2 = { class: "notification-content" };
|
|
180
|
+
const _hoisted_3 = { class: "notification-title" };
|
|
181
|
+
const _hoisted_4 = { class: "notification-close" };
|
|
182
|
+
const _hoisted_5 = ["onClick"];
|
|
183
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
184
|
+
__name: "NotificationContainer",
|
|
185
|
+
setup(__props) {
|
|
186
|
+
const isClient = ref(false);
|
|
187
|
+
if (typeof window !== "undefined") {
|
|
188
|
+
isClient.value = true;
|
|
189
|
+
}
|
|
190
|
+
const groups = computed(() => {
|
|
191
|
+
const map = {
|
|
192
|
+
"top-left": [],
|
|
193
|
+
"top-center": [],
|
|
194
|
+
"top-right": [],
|
|
195
|
+
"bottom-left": [],
|
|
196
|
+
"bottom-center": [],
|
|
197
|
+
"bottom-right": []
|
|
198
|
+
};
|
|
199
|
+
for (const notification of notificationStore.notifications) {
|
|
200
|
+
map[notification.options.position].push(notification);
|
|
201
|
+
}
|
|
202
|
+
return map;
|
|
203
|
+
});
|
|
204
|
+
function removeNotification(id) {
|
|
205
|
+
notificationManager.remove(id);
|
|
206
|
+
}
|
|
207
|
+
return (_ctx, _cache) => {
|
|
208
|
+
return isClient.value ? (openBlock(), createBlock(Teleport, {
|
|
209
|
+
key: 0,
|
|
210
|
+
to: "body"
|
|
211
|
+
}, [
|
|
212
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(groups.value, (items, pos) => {
|
|
213
|
+
return openBlock(), createBlock(TransitionGroup, {
|
|
214
|
+
key: pos,
|
|
215
|
+
tag: "div",
|
|
216
|
+
name: "notification",
|
|
217
|
+
class: "notification-list",
|
|
218
|
+
"data-position": pos
|
|
219
|
+
}, {
|
|
220
|
+
default: withCtx(() => [
|
|
221
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(items, (notification) => {
|
|
222
|
+
return openBlock(), createElementBlock("article", {
|
|
223
|
+
key: notification.id,
|
|
224
|
+
class: normalizeClass(["notification", [
|
|
225
|
+
`notification-${notification.type}`,
|
|
226
|
+
{
|
|
227
|
+
"notification-auto-close": notification.options.progress && notification.options.autoClose !== false
|
|
228
|
+
}
|
|
229
|
+
]]),
|
|
230
|
+
"data-position": pos
|
|
231
|
+
}, [
|
|
232
|
+
createElementVNode("div", _hoisted_2, [
|
|
233
|
+
createElementVNode("span", _hoisted_3, toDisplayString(notification.title), 1)
|
|
234
|
+
]),
|
|
235
|
+
notification.options.progress && notification.options.autoClose !== false ? (openBlock(), createElementBlock("div", {
|
|
236
|
+
key: 0,
|
|
237
|
+
class: "notification-progress",
|
|
238
|
+
style: normalizeStyle({ animationDuration: (notification.options.autoClose || 0) + "ms" })
|
|
239
|
+
}, null, 4)) : createCommentVNode("", true),
|
|
240
|
+
createElementVNode("div", _hoisted_4, [
|
|
241
|
+
createElementVNode("button", {
|
|
242
|
+
type: "button",
|
|
243
|
+
onClick: ($event) => removeNotification(notification.id),
|
|
244
|
+
"aria-label": "Dismiss notification"
|
|
245
|
+
}, " × ", 8, _hoisted_5)
|
|
246
|
+
])
|
|
247
|
+
], 10, _hoisted_1);
|
|
248
|
+
}), 128))
|
|
249
|
+
]),
|
|
250
|
+
_: 2
|
|
251
|
+
}, 1032, ["data-position"]);
|
|
252
|
+
}), 128))
|
|
253
|
+
])) : createCommentVNode("", true);
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
function useNotification() {
|
|
258
|
+
return useNotificationManager();
|
|
259
|
+
}
|
|
260
|
+
defineNuxtPlugin((nuxtApp) => {
|
|
261
|
+
nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));
|
|
262
|
+
});
|
|
263
|
+
function createVueNotificationPlugin(manager) {
|
|
264
|
+
return {
|
|
265
|
+
install(app) {
|
|
266
|
+
app.config.globalProperties.$notificationManager = manager;
|
|
267
|
+
app.provide("notificationManager", manager);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
export {
|
|
272
|
+
_sfc_main as NotificationContainer,
|
|
273
|
+
NotificationManager,
|
|
274
|
+
createReactiveNotificationStore,
|
|
275
|
+
createVueNotificationPlugin$1 as createVueNotificationPlugin,
|
|
276
|
+
notificationManager,
|
|
277
|
+
notificationStore,
|
|
278
|
+
useNotification,
|
|
279
|
+
useNotificationManager
|
|
280
|
+
};
|
|
281
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/core/notification-manager.ts","../src/adapters/vue/index.ts","../src/adapters/vue/NotificationContainer.vue","../src/composables/useNotification.ts","../src/adapters/nuxt/index.ts"],"sourcesContent":["import type { NotificationType, NotificationOptions, NotificationItem } from '../types';\n\nconst DEFAULT_OPTIONS: Required<NotificationOptions> = {\n position: 'top-center',\n autoClose: 3000,\n progress: true,\n};\n\nexport class NotificationManager {\n private notifications: NotificationItem[] = [];\n private options: Required<NotificationOptions> = { ...DEFAULT_OPTIONS };\n private listeners: { [event: string]: Function[] } = {};\n private idCounter = 1;\n\n /**\n * Subscribe to an event.\n * @param event - The event name ('notification-added', 'notification-removed', 'notifications-cleared', 'options-changed')\n * @param callback - The callback function\n */\n on(event: string, callback: Function): void {\n if (!this.listeners[event]) {\n this.listeners[event] = [];\n }\n this.listeners[event].push(callback);\n }\n\n /**\n * Unsubscribe from an event.\n * @param event - The event name\n * @param callback - The callback function to remove\n */\n off(event: string, callback: Function): void {\n if (this.listeners[event]) {\n this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);\n }\n }\n\n private emit(event: string, data?: any): void {\n if (this.listeners[event]) {\n this.listeners[event].forEach((callback) => callback(data));\n }\n }\n\n /**\n * Set default options for notifications.\n * @param opts - The options to set as defaults\n */\n setDefaults(opts: NotificationOptions): void {\n this.options = { ...this.options, ...opts };\n this.emit('options-changed', this.options);\n }\n\n /**\n * Show a notification.\n * @param type - The type of notification\n * @param title - The title/message of the notification\n * @param opts - Optional override options\n */\n show(type: NotificationType, title: string, opts?: NotificationOptions): void {\n const options = { ...this.options, ...(opts || {}) };\n const item: NotificationItem = {\n id: this.idCounter++,\n type,\n title,\n options,\n createdAt: Date.now(),\n };\n this.notifications.push(item);\n this.emit('notification-added', item);\n\n if (options.autoClose !== false && typeof window !== 'undefined') {\n setTimeout(() => this.remove(item.id), options.autoClose);\n }\n }\n\n /**\n * Remove a notification by ID.\n * @param id - The ID of the notification to remove\n */\n remove(id: number): void {\n const index = this.notifications.findIndex((n) => n.id === id);\n if (index !== -1) {\n const removed = this.notifications.splice(index, 1)[0];\n this.emit('notification-removed', removed);\n }\n }\n\n /**\n * Clear all notifications.\n */\n clear(): void {\n const removed = [...this.notifications];\n this.notifications.splice(0);\n this.emit('notifications-cleared', removed);\n }\n\n /**\n * Get a copy of the current notifications.\n * @returns Array of notification items\n */\n getNotifications(): NotificationItem[] {\n return [...this.notifications];\n }\n\n /**\n * Get the current default options.\n * @returns The default options\n */\n getOptions(): Required<NotificationOptions> {\n return { ...this.options };\n }\n\n /**\n * Success notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n success(title: string, opts?: NotificationOptions): void {\n this.show('success', title, opts);\n }\n\n /**\n * Error notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n error(title: string, opts?: NotificationOptions): void {\n this.show('error', title, opts);\n }\n\n /**\n * Warning notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n warning(title: string, opts?: NotificationOptions): void {\n this.show('warning', title, opts);\n }\n\n /**\n * Info notification shorthand.\n * @param title - The title/message\n * @param opts - Optional options\n */\n info(title: string, opts?: NotificationOptions): void {\n this.show('info', title, opts);\n }\n}\n\n// Default instance for convenience\nexport const notificationManager = new NotificationManager();\n","import { reactive, watchEffect } from 'vue';\nimport { NotificationManager, notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationOptions } from '../../types';\n\nexport interface ReactiveNotificationStore {\n notifications: NotificationItem[];\n options: NotificationOptions;\n}\n\n/**\n * Create a reactive store for Vue that syncs with the NotificationManager.\n * @param manager - The NotificationManager instance (optional, uses default if not provided)\n * @returns Reactive store\n */\nexport function createReactiveNotificationStore(\n manager: NotificationManager = notificationManager\n): ReactiveNotificationStore {\n const store = reactive({\n notifications: manager.getNotifications(),\n options: manager.getOptions(),\n });\n\n // Sync notifications\n manager.on('notification-added', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notification-removed', () => {\n store.notifications = manager.getNotifications();\n });\n manager.on('notifications-cleared', () => {\n store.notifications = manager.getNotifications();\n });\n\n // Sync options\n manager.on('options-changed', () => {\n store.options = manager.getOptions();\n });\n\n return store;\n}\n\n// Default reactive store\nexport const notificationStore = createReactiveNotificationStore();\n\n// Vue composable\nexport function useNotificationManager(manager: NotificationManager = notificationManager) {\n return {\n success: (title: string, opts?: NotificationOptions) => manager.success(title, opts),\n error: (title: string, opts?: NotificationOptions) => manager.error(title, opts),\n warning: (title: string, opts?: NotificationOptions) => manager.warning(title, opts),\n info: (title: string, opts?: NotificationOptions) => manager.info(title, opts),\n show: (type: string, title: string, opts?: NotificationOptions) =>\n manager.show(type as any, title, opts),\n remove: (id: number) => manager.remove(id),\n clear: () => manager.clear(),\n setDefaults: (opts: NotificationOptions) => manager.setDefaults(opts),\n getNotifications: () => manager.getNotifications(),\n getOptions: () => manager.getOptions(),\n };\n}\n\n// Vue plugin\nexport function createVueNotificationPlugin(manager: NotificationManager = notificationManager) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, ref } from 'vue';\nimport { notificationStore } from './index';\nimport { notificationManager } from '../../core/notification-manager';\nimport type { NotificationItem, NotificationPosition } from '../../types';\n\nconst isClient = ref(false);\n\nif (typeof window !== 'undefined') {\n isClient.value = true;\n}\n\nconst groups = computed<Record<NotificationPosition, NotificationItem[]>>(() => {\n const map: Record<NotificationPosition, NotificationItem[]> = {\n 'top-left': [],\n 'top-center': [],\n 'top-right': [],\n 'bottom-left': [],\n 'bottom-center': [],\n 'bottom-right': [],\n };\n for (const notification of notificationStore.notifications) {\n map[notification.options.position].push(notification);\n }\n return map;\n});\n\nfunction removeNotification(id: number) {\n notificationManager.remove(id);\n}\n</script>\n\n<template>\n <Teleport v-if=\"isClient\" to=\"body\">\n <TransitionGroup\n v-for=\"(items, pos) in groups\"\n :key=\"pos\"\n tag=\"div\"\n name=\"notification\"\n class=\"notification-list\"\n :data-position=\"pos\"\n >\n <article\n v-for=\"notification in items\"\n :key=\"notification.id\"\n class=\"notification\"\n :class=\"[\n `notification-${notification.type}`,\n {\n 'notification-auto-close':\n notification.options.progress && notification.options.autoClose !== false,\n },\n ]\"\n :data-position=\"pos\"\n >\n <div class=\"notification-content\">\n <span class=\"notification-title\">{{ notification.title }}</span>\n </div>\n\n <div\n v-if=\"notification.options.progress && notification.options.autoClose !== false\"\n class=\"notification-progress\"\n :style=\"{ animationDuration: (notification.options.autoClose || 0) + 'ms' }\"\n ></div>\n\n <div class=\"notification-close\">\n <button\n type=\"button\"\n @click=\"removeNotification(notification.id)\"\n aria-label=\"Dismiss notification\"\n >\n ×\n </button>\n </div>\n </article>\n </TransitionGroup>\n </Teleport>\n</template>\n","import { useNotificationManager } from '../adapters/vue';\n\n/**\n * Vue composable for notification management.\n * Provides a clean API to show notifications in Vue components.\n *\n * @returns Notification manager API\n */\nexport function useNotification() {\n return useNotificationManager();\n}\n","import { notificationManager } from '../../core/notification-manager';\n\n/**\n * Nuxt plugin for notification management.\n * Integrates the notification manager into Nuxt applications.\n */\nexport default defineNuxtPlugin((nuxtApp) => {\n nuxtApp.vueApp.use(createVueNotificationPlugin(notificationManager));\n});\n\n/**\n * Create Vue plugin for Nuxt (internal use).\n */\nfunction createVueNotificationPlugin(manager: any) {\n return {\n install(app: any) {\n app.config.globalProperties.$notificationManager = manager;\n app.provide('notificationManager', manager);\n },\n };\n}\n\n// Re-export Vue adapter functions for convenience\nexport { useNotificationManager, createReactiveNotificationStore, notificationStore } from '../vue';\n"],"names":["createVueNotificationPlugin","_createBlock","_Teleport","_openBlock","_createElementBlock","_Fragment","_renderList","_TransitionGroup","_createElementVNode","_toDisplayString","_normalizeStyle"],"mappings":";AAEA,MAAM,kBAAiD;AAAA,EACrD,UAAU;AAAA,EACV,WAAW;AAAA,EACX,UAAU;AACZ;AAEO,MAAM,oBAAoB;AAAA,EAA1B,cAAA;AACL,SAAQ,gBAAoC,CAAA;AAC5C,SAAQ,UAAyC,EAAE,GAAG,gBAAA;AACtD,SAAQ,YAA6C,CAAA;AACrD,SAAQ,YAAY;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpB,GAAG,OAAe,UAA0B;AAC1C,QAAI,CAAC,KAAK,UAAU,KAAK,GAAG;AAC1B,WAAK,UAAU,KAAK,IAAI,CAAA;AAAA,IAC1B;AACA,SAAK,UAAU,KAAK,EAAE,KAAK,QAAQ;AAAA,EACrC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAI,OAAe,UAA0B;AAC3C,QAAI,KAAK,UAAU,KAAK,GAAG;AACzB,WAAK,UAAU,KAAK,IAAI,KAAK,UAAU,KAAK,EAAE,OAAO,CAAC,OAAO,OAAO,QAAQ;AAAA,IAC9E;AAAA,EACF;AAAA,EAEQ,K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