@samline/notify 1.0.2 → 2.0.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.
Files changed (85) hide show
  1. package/{LICENSE → LICENSE.md} +2 -2
  2. package/README.md +27 -163
  3. package/dist/_runtime.d.mts +87 -0
  4. package/dist/_runtime.d.ts +87 -0
  5. package/dist/_runtime.js +97 -0
  6. package/dist/_runtime.mjs +83 -0
  7. package/dist/browser/assets-client-B-VVPPYQ.js +114 -0
  8. package/dist/browser/assets-client-CUzxHubR.mjs +108 -0
  9. package/dist/browser/index-client-BBOQyMFk.mjs +173 -0
  10. package/dist/browser/index-client-Czb7hTpD.js +181 -0
  11. package/dist/browser/index.cjs +24716 -0
  12. package/dist/browser/index.d.mts +134 -0
  13. package/dist/browser/index.d.ts +134 -0
  14. package/dist/browser/index.js +24718 -0
  15. package/dist/browser/index.mjs +24707 -0
  16. package/dist/browser/render-client-CjcQoukB.js +981 -0
  17. package/dist/browser/render-client-bGRSTd-L.mjs +974 -0
  18. package/dist/core/index.d.mts +68 -0
  19. package/dist/core/index.d.ts +68 -0
  20. package/dist/core/index.js +1 -0
  21. package/dist/core/index.mjs +1 -0
  22. package/dist/index.d.mts +131 -0
  23. package/dist/index.d.ts +131 -0
  24. package/dist/index.js +24700 -0
  25. package/dist/index.mjs +24693 -0
  26. package/dist/react/index.d.mts +158 -0
  27. package/dist/react/index.d.ts +158 -0
  28. package/dist/react/index.js +1116 -0
  29. package/dist/react/index.mjs +1107 -0
  30. package/dist/styles.css +589 -422
  31. package/dist/svelte/assets-client-B-VVPPYQ.js +114 -0
  32. package/dist/svelte/assets-client-CUzxHubR.mjs +108 -0
  33. package/dist/svelte/index-client-DbXbWMIe.js +177 -0
  34. package/dist/svelte/index-client-Dj_WfPK9.mjs +170 -0
  35. package/dist/svelte/index.d.mts +14 -0
  36. package/dist/svelte/index.d.ts +14 -0
  37. package/dist/svelte/index.js +24722 -0
  38. package/dist/svelte/index.mjs +24713 -0
  39. package/dist/svelte/render-client-CjcQoukB.js +981 -0
  40. package/dist/svelte/render-client-bGRSTd-L.mjs +974 -0
  41. package/dist/vue/assets-client-B-VVPPYQ.js +114 -0
  42. package/dist/vue/assets-client-CUzxHubR.mjs +108 -0
  43. package/dist/vue/index-client-DbXbWMIe.js +177 -0
  44. package/dist/vue/index-client-Dj_WfPK9.mjs +170 -0
  45. package/dist/vue/index.d.mts +50 -0
  46. package/dist/vue/index.d.ts +50 -0
  47. package/dist/vue/index.js +24777 -0
  48. package/dist/vue/index.mjs +24770 -0
  49. package/dist/vue/render-client-CjcQoukB.js +981 -0
  50. package/dist/vue/render-client-bGRSTd-L.mjs +974 -0
  51. package/package.json +141 -95
  52. package/dist/browser-notify.js +0 -68
  53. package/dist/cc-2Yt7NqMX.mjs +0 -21
  54. package/dist/cc-B6peeNak.mjs +0 -33
  55. package/dist/cc-BWuAzFJ6.js +0 -12
  56. package/dist/cc-CaBHsjUt.js +0 -34
  57. package/dist/cc-DGff5sSY.js +0 -21
  58. package/dist/cc-he3fHS3P.mjs +0 -12
  59. package/dist/notify.d.mts +0 -48
  60. package/dist/notify.d.mts.map +0 -1
  61. package/dist/notify.d.ts +0 -48
  62. package/dist/notify.d.ts.map +0 -1
  63. package/dist/notify.js +0 -206
  64. package/dist/notify.mjs +0 -202
  65. package/dist/react-notify-12s--2JK5UjB.mjs +0 -1244
  66. package/dist/react-notify-12s-Kv2M6zlv.js +0 -1247
  67. package/dist/react.d.mts +0 -70
  68. package/dist/react.d.mts.map +0 -1
  69. package/dist/react.d.ts +0 -70
  70. package/dist/react.d.ts.map +0 -1
  71. package/dist/react.js +0 -19
  72. package/dist/react.mjs +0 -10
  73. package/dist/render-notify-toasts.js +0 -213
  74. package/dist/svelte.d.mts +0 -49
  75. package/dist/svelte.d.mts.map +0 -1
  76. package/dist/svelte.d.ts +0 -49
  77. package/dist/svelte.d.ts.map +0 -1
  78. package/dist/svelte.js +0 -284
  79. package/dist/svelte.mjs +0 -280
  80. package/dist/vue.d.mts +0 -107
  81. package/dist/vue.d.mts.map +0 -1
  82. package/dist/vue.d.ts +0 -107
  83. package/dist/vue.d.ts.map +0 -1
  84. package/dist/vue.js +0 -2215
  85. package/dist/vue.mjs +0 -2211
package/dist/svelte.js DELETED
@@ -1,284 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- var cc = require('./cc-BWuAzFJ6.js');
4
-
5
- // Store the references to globals in case someone tries to monkey patch these, causing the below
6
- // to de-opt (this occurs often when using popular extensions).
7
- const noop = ()=>{};
8
-
9
- /**
10
- * @param {unknown} a
11
- * @param {unknown} b
12
- * @returns {boolean}
13
- */ function safe_not_equal(a, b) {
14
- return a != a ? b == b : a !== b || a !== null && typeof a === 'object' || typeof a === 'function';
15
- }
16
-
17
- var _globalThis_document;
18
- /** allow users to ignore aborted signal errors if `reason.name === 'StaleReactionError` */ new class StaleReactionError extends Error {
19
- constructor(...args){
20
- super(...args), this.name = 'StaleReactionError', this.message = 'The reaction that called `getAbortSignal()` was re-run or destroyed';
21
- }
22
- }();
23
- // We gotta write it like this because after downleveling the pure comment may end up in the wrong location
24
- !!((_globalThis_document = globalThis.document) == null ? void 0 : _globalThis_document.contentType) && /* @__PURE__ */ globalThis.document.contentType.includes('xml');
25
-
26
- /**
27
- * @type {Array<SubscribeInvalidateTuple<any> | any>}
28
- */ const subscriber_queue = [];
29
- /**
30
- * Create a `Writable` store that allows both updating and reading by subscription.
31
- *
32
- * @template T
33
- * @param {T} [value] initial value
34
- * @param {StartStopNotifier<T>} [start]
35
- * @returns {Writable<T>}
36
- */ function writable(value, start = noop) {
37
- /** @type {Unsubscriber | null} */ let stop = null;
38
- /** @type {Set<SubscribeInvalidateTuple<T>>} */ const subscribers = new Set();
39
- /**
40
- * @param {T} new_value
41
- * @returns {void}
42
- */ function set(new_value) {
43
- if (safe_not_equal(value, new_value)) {
44
- value = new_value;
45
- if (stop) {
46
- // store is ready
47
- const run_queue = !subscriber_queue.length;
48
- for (const subscriber of subscribers){
49
- subscriber[1]();
50
- subscriber_queue.push(subscriber, value);
51
- }
52
- if (run_queue) {
53
- for(let i = 0; i < subscriber_queue.length; i += 2){
54
- subscriber_queue[i][0](subscriber_queue[i + 1]);
55
- }
56
- subscriber_queue.length = 0;
57
- }
58
- }
59
- }
60
- }
61
- /**
62
- * @param {Updater<T>} fn
63
- * @returns {void}
64
- */ function update(fn) {
65
- set(fn(/** @type {T} */ value));
66
- }
67
- /**
68
- * @param {Subscriber<T>} run
69
- * @param {() => void} [invalidate]
70
- * @returns {Unsubscriber}
71
- */ function subscribe(run, invalidate = noop) {
72
- /** @type {SubscribeInvalidateTuple<T>} */ const subscriber = [
73
- run,
74
- invalidate
75
- ];
76
- subscribers.add(subscriber);
77
- if (subscribers.size === 1) {
78
- stop = start(set, update) || noop;
79
- }
80
- run(/** @type {T} */ value);
81
- return ()=>{
82
- subscribers.delete(subscriber);
83
- if (subscribers.size === 0 && stop) {
84
- stop();
85
- stop = null;
86
- }
87
- };
88
- }
89
- return {
90
- set,
91
- update,
92
- subscribe
93
- };
94
- }
95
-
96
- // Notify logic (no React dependencies)
97
- // Provides toast management and utilities for VanillaJS, Vue, Svelte, etc.
98
- class NotifyCore {
99
- generateId() {
100
- return `${++this.idCounter}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
101
- }
102
- subscribe(fn) {
103
- this.listeners.add(fn);
104
- fn(this.toasts);
105
- return ()=>this.listeners.delete(fn);
106
- }
107
- emit() {
108
- for (const fn of this.listeners)fn(this.toasts);
109
- }
110
- update(fn) {
111
- this.toasts = fn(this.toasts);
112
- this.emit();
113
- }
114
- dismiss(id) {
115
- const item = this.toasts.find((t)=>t.id === id);
116
- if (!item || item.exiting) return;
117
- this.update((prev)=>prev.map((t)=>t.id === id ? cc._extends({}, t, {
118
- exiting: true
119
- }) : t));
120
- setTimeout(()=>this.update((prev)=>prev.filter((t)=>t.id !== id)), 600);
121
- }
122
- show(opts) {
123
- var _ref, _ref1, _opts_type;
124
- // Use a unique identifier based on options (e.g., the title or a generated key)
125
- // If not provided, use a default one
126
- const id = opts.title ? `notify-${opts.title}` : "notify-default";
127
- const prevItem = this.toasts.find((t)=>t.id === id);
128
- const instanceId = (_ref = prevItem == null ? void 0 : prevItem.instanceId) != null ? _ref : this.generateId();
129
- // Set the state correctly
130
- const state = (_ref1 = (_opts_type = opts.type) != null ? _opts_type : prevItem == null ? void 0 : prevItem.type) != null ? _ref1 : "success";
131
- const item = cc._extends({}, prevItem, opts, {
132
- id,
133
- instanceId,
134
- type: state
135
- });
136
- this.update((prev)=>{
137
- const filtered = prev.filter((t)=>t.id !== id);
138
- return [
139
- ...filtered,
140
- item
141
- ];
142
- });
143
- return id;
144
- }
145
- getToasts() {
146
- return this.toasts;
147
- }
148
- constructor(){
149
- this.toasts = [];
150
- this.listeners = new Set();
151
- this.position = "top-right";
152
- this.options = undefined;
153
- this.idCounter = 0;
154
- }
155
- }
156
- // Global instance for multiplatform usage
157
- const notifyCore = new NotifyCore();
158
-
159
- // Svelte wrapper for Notify
160
- // Provides a store and function to show toasts in Svelte
161
- const notifyToasts = writable(notifyCore.getToasts());
162
- notifyCore.subscribe((t)=>notifyToasts.set(t));
163
- function showNotifyToast(options) {
164
- return notifyCore.show(options);
165
- }
166
-
167
- const ICONS = {
168
- success: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>',
169
- error: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',
170
- warning: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
171
- info: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m4.93 4.93 4.24 4.24"/><path d="m14.83 9.17 4.24-4.24"/><path d="m14.83 14.83 4.24 4.24"/><path d="m9.17 14.83-4.24 4.24"/><circle cx="12" cy="12" r="4"/></svg>',
172
- loading: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" data-notify-icon="spin" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
173
- action: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>'
174
- };
175
- const EXIT_MS = 600;
176
- function capitalize(s) {
177
- return s ? s.charAt(0).toUpperCase() + s.slice(1) : "";
178
- }
179
- let viewport = null;
180
- const toastEls = new Map();
181
- function getOrCreateViewport(position) {
182
- if (!viewport) {
183
- viewport = document.createElement("div");
184
- viewport.setAttribute("data-notify-viewport", "");
185
- viewport.setAttribute("data-position", position);
186
- viewport.setAttribute("data-theme", "light");
187
- document.body.appendChild(viewport);
188
- }
189
- return viewport;
190
- }
191
- function buildToastEl(toast) {
192
- const state = toast.type || "success";
193
- const btn = document.createElement("button");
194
- btn.type = "button";
195
- btn.setAttribute("data-notify-toast", "");
196
- btn.setAttribute("data-state", state);
197
- btn.setAttribute("data-ready", "false");
198
- btn.setAttribute("data-exiting", "false");
199
- const card = document.createElement("div");
200
- card.setAttribute("data-notify-card", "");
201
- const header = document.createElement("div");
202
- header.setAttribute("data-notify-header", "");
203
- const badge = document.createElement("div");
204
- badge.setAttribute("data-notify-badge", "");
205
- badge.setAttribute("data-state", state);
206
- badge.innerHTML = ICONS[state] || ICONS.success;
207
- const titleEl = document.createElement("span");
208
- titleEl.setAttribute("data-notify-title", "");
209
- titleEl.setAttribute("data-state", state);
210
- titleEl.textContent = toast.title || capitalize(state);
211
- header.appendChild(badge);
212
- header.appendChild(titleEl);
213
- card.appendChild(header);
214
- if (toast.description || toast.button) {
215
- const content = document.createElement("div");
216
- content.setAttribute("data-notify-content", "");
217
- content.setAttribute("data-visible", "true");
218
- if (toast.description) {
219
- const desc = document.createElement("div");
220
- desc.setAttribute("data-notify-description", "");
221
- desc.textContent = toast.description;
222
- content.appendChild(desc);
223
- }
224
- if (toast.button) {
225
- const actionBtn = document.createElement("button");
226
- actionBtn.setAttribute("data-notify-button", "");
227
- actionBtn.setAttribute("data-state", state);
228
- actionBtn.textContent = toast.button.title;
229
- actionBtn.addEventListener("click", (e)=>{
230
- var _toast_button;
231
- e.stopPropagation();
232
- (_toast_button = toast.button) == null ? void 0 : _toast_button.onClick();
233
- notifyCore.dismiss(toast.id);
234
- });
235
- content.appendChild(actionBtn);
236
- }
237
- card.appendChild(content);
238
- }
239
- btn.appendChild(card);
240
- btn.addEventListener("click", ()=>notifyCore.dismiss(toast.id));
241
- requestAnimationFrame(()=>{
242
- requestAnimationFrame(()=>{
243
- btn.setAttribute("data-ready", "true");
244
- });
245
- });
246
- return btn;
247
- }
248
- function updateToastEl(el, toast) {
249
- const state = toast.type || "success";
250
- el.setAttribute("data-state", state);
251
- if (toast.exiting) {
252
- el.setAttribute("data-exiting", "true");
253
- }
254
- }
255
- function renderNotifyToasts(options = {}) {
256
- var _options_position;
257
- const position = (_options_position = options.position) != null ? _options_position : "top-right";
258
- const vp = getOrCreateViewport(position);
259
- return notifyCore.subscribe((toasts)=>{
260
- const liveIds = new Set(toasts.map((t)=>t.id));
261
- for (const [id, el] of toastEls){
262
- if (!liveIds.has(id)) {
263
- el.setAttribute("data-exiting", "true");
264
- setTimeout(()=>{
265
- el.remove();
266
- toastEls.delete(id);
267
- }, EXIT_MS);
268
- }
269
- }
270
- for (const toast of toasts){
271
- if (toastEls.has(toast.id)) {
272
- updateToastEl(toastEls.get(toast.id), toast);
273
- } else {
274
- const el = buildToastEl(toast);
275
- toastEls.set(toast.id, el);
276
- vp.appendChild(el);
277
- }
278
- }
279
- });
280
- }
281
-
282
- exports.notifyToasts = notifyToasts;
283
- exports.renderNotifyToasts = renderNotifyToasts;
284
- exports.showNotifyToast = showNotifyToast;
package/dist/svelte.mjs DELETED
@@ -1,280 +0,0 @@
1
- import { _ as _extends } from './cc-he3fHS3P.mjs';
2
-
3
- // Store the references to globals in case someone tries to monkey patch these, causing the below
4
- // to de-opt (this occurs often when using popular extensions).
5
- const noop = ()=>{};
6
-
7
- /**
8
- * @param {unknown} a
9
- * @param {unknown} b
10
- * @returns {boolean}
11
- */ function safe_not_equal(a, b) {
12
- return a != a ? b == b : a !== b || a !== null && typeof a === 'object' || typeof a === 'function';
13
- }
14
-
15
- var _globalThis_document;
16
- /** allow users to ignore aborted signal errors if `reason.name === 'StaleReactionError` */ new class StaleReactionError extends Error {
17
- constructor(...args){
18
- super(...args), this.name = 'StaleReactionError', this.message = 'The reaction that called `getAbortSignal()` was re-run or destroyed';
19
- }
20
- }();
21
- // We gotta write it like this because after downleveling the pure comment may end up in the wrong location
22
- !!((_globalThis_document = globalThis.document) == null ? void 0 : _globalThis_document.contentType) && /* @__PURE__ */ globalThis.document.contentType.includes('xml');
23
-
24
- /**
25
- * @type {Array<SubscribeInvalidateTuple<any> | any>}
26
- */ const subscriber_queue = [];
27
- /**
28
- * Create a `Writable` store that allows both updating and reading by subscription.
29
- *
30
- * @template T
31
- * @param {T} [value] initial value
32
- * @param {StartStopNotifier<T>} [start]
33
- * @returns {Writable<T>}
34
- */ function writable(value, start = noop) {
35
- /** @type {Unsubscriber | null} */ let stop = null;
36
- /** @type {Set<SubscribeInvalidateTuple<T>>} */ const subscribers = new Set();
37
- /**
38
- * @param {T} new_value
39
- * @returns {void}
40
- */ function set(new_value) {
41
- if (safe_not_equal(value, new_value)) {
42
- value = new_value;
43
- if (stop) {
44
- // store is ready
45
- const run_queue = !subscriber_queue.length;
46
- for (const subscriber of subscribers){
47
- subscriber[1]();
48
- subscriber_queue.push(subscriber, value);
49
- }
50
- if (run_queue) {
51
- for(let i = 0; i < subscriber_queue.length; i += 2){
52
- subscriber_queue[i][0](subscriber_queue[i + 1]);
53
- }
54
- subscriber_queue.length = 0;
55
- }
56
- }
57
- }
58
- }
59
- /**
60
- * @param {Updater<T>} fn
61
- * @returns {void}
62
- */ function update(fn) {
63
- set(fn(/** @type {T} */ value));
64
- }
65
- /**
66
- * @param {Subscriber<T>} run
67
- * @param {() => void} [invalidate]
68
- * @returns {Unsubscriber}
69
- */ function subscribe(run, invalidate = noop) {
70
- /** @type {SubscribeInvalidateTuple<T>} */ const subscriber = [
71
- run,
72
- invalidate
73
- ];
74
- subscribers.add(subscriber);
75
- if (subscribers.size === 1) {
76
- stop = start(set, update) || noop;
77
- }
78
- run(/** @type {T} */ value);
79
- return ()=>{
80
- subscribers.delete(subscriber);
81
- if (subscribers.size === 0 && stop) {
82
- stop();
83
- stop = null;
84
- }
85
- };
86
- }
87
- return {
88
- set,
89
- update,
90
- subscribe
91
- };
92
- }
93
-
94
- // Notify logic (no React dependencies)
95
- // Provides toast management and utilities for VanillaJS, Vue, Svelte, etc.
96
- class NotifyCore {
97
- generateId() {
98
- return `${++this.idCounter}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
99
- }
100
- subscribe(fn) {
101
- this.listeners.add(fn);
102
- fn(this.toasts);
103
- return ()=>this.listeners.delete(fn);
104
- }
105
- emit() {
106
- for (const fn of this.listeners)fn(this.toasts);
107
- }
108
- update(fn) {
109
- this.toasts = fn(this.toasts);
110
- this.emit();
111
- }
112
- dismiss(id) {
113
- const item = this.toasts.find((t)=>t.id === id);
114
- if (!item || item.exiting) return;
115
- this.update((prev)=>prev.map((t)=>t.id === id ? _extends({}, t, {
116
- exiting: true
117
- }) : t));
118
- setTimeout(()=>this.update((prev)=>prev.filter((t)=>t.id !== id)), 600);
119
- }
120
- show(opts) {
121
- var _ref, _ref1, _opts_type;
122
- // Use a unique identifier based on options (e.g., the title or a generated key)
123
- // If not provided, use a default one
124
- const id = opts.title ? `notify-${opts.title}` : "notify-default";
125
- const prevItem = this.toasts.find((t)=>t.id === id);
126
- const instanceId = (_ref = prevItem == null ? void 0 : prevItem.instanceId) != null ? _ref : this.generateId();
127
- // Set the state correctly
128
- const state = (_ref1 = (_opts_type = opts.type) != null ? _opts_type : prevItem == null ? void 0 : prevItem.type) != null ? _ref1 : "success";
129
- const item = _extends({}, prevItem, opts, {
130
- id,
131
- instanceId,
132
- type: state
133
- });
134
- this.update((prev)=>{
135
- const filtered = prev.filter((t)=>t.id !== id);
136
- return [
137
- ...filtered,
138
- item
139
- ];
140
- });
141
- return id;
142
- }
143
- getToasts() {
144
- return this.toasts;
145
- }
146
- constructor(){
147
- this.toasts = [];
148
- this.listeners = new Set();
149
- this.position = "top-right";
150
- this.options = undefined;
151
- this.idCounter = 0;
152
- }
153
- }
154
- // Global instance for multiplatform usage
155
- const notifyCore = new NotifyCore();
156
-
157
- // Svelte wrapper for Notify
158
- // Provides a store and function to show toasts in Svelte
159
- const notifyToasts = writable(notifyCore.getToasts());
160
- notifyCore.subscribe((t)=>notifyToasts.set(t));
161
- function showNotifyToast(options) {
162
- return notifyCore.show(options);
163
- }
164
-
165
- const ICONS = {
166
- success: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="20 6 9 17 4 12"/></svg>',
167
- error: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>',
168
- warning: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
169
- info: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10"/><path d="m4.93 4.93 4.24 4.24"/><path d="m14.83 9.17 4.24-4.24"/><path d="m14.83 14.83 4.24 4.24"/><path d="m9.17 14.83-4.24 4.24"/><circle cx="12" cy="12" r="4"/></svg>',
170
- loading: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" data-notify-icon="spin" aria-hidden="true"><path d="M21 12a9 9 0 1 1-6.219-8.56"/></svg>',
171
- action: '<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12h14"/><path d="m12 5 7 7-7 7"/></svg>'
172
- };
173
- const EXIT_MS = 600;
174
- function capitalize(s) {
175
- return s ? s.charAt(0).toUpperCase() + s.slice(1) : "";
176
- }
177
- let viewport = null;
178
- const toastEls = new Map();
179
- function getOrCreateViewport(position) {
180
- if (!viewport) {
181
- viewport = document.createElement("div");
182
- viewport.setAttribute("data-notify-viewport", "");
183
- viewport.setAttribute("data-position", position);
184
- viewport.setAttribute("data-theme", "light");
185
- document.body.appendChild(viewport);
186
- }
187
- return viewport;
188
- }
189
- function buildToastEl(toast) {
190
- const state = toast.type || "success";
191
- const btn = document.createElement("button");
192
- btn.type = "button";
193
- btn.setAttribute("data-notify-toast", "");
194
- btn.setAttribute("data-state", state);
195
- btn.setAttribute("data-ready", "false");
196
- btn.setAttribute("data-exiting", "false");
197
- const card = document.createElement("div");
198
- card.setAttribute("data-notify-card", "");
199
- const header = document.createElement("div");
200
- header.setAttribute("data-notify-header", "");
201
- const badge = document.createElement("div");
202
- badge.setAttribute("data-notify-badge", "");
203
- badge.setAttribute("data-state", state);
204
- badge.innerHTML = ICONS[state] || ICONS.success;
205
- const titleEl = document.createElement("span");
206
- titleEl.setAttribute("data-notify-title", "");
207
- titleEl.setAttribute("data-state", state);
208
- titleEl.textContent = toast.title || capitalize(state);
209
- header.appendChild(badge);
210
- header.appendChild(titleEl);
211
- card.appendChild(header);
212
- if (toast.description || toast.button) {
213
- const content = document.createElement("div");
214
- content.setAttribute("data-notify-content", "");
215
- content.setAttribute("data-visible", "true");
216
- if (toast.description) {
217
- const desc = document.createElement("div");
218
- desc.setAttribute("data-notify-description", "");
219
- desc.textContent = toast.description;
220
- content.appendChild(desc);
221
- }
222
- if (toast.button) {
223
- const actionBtn = document.createElement("button");
224
- actionBtn.setAttribute("data-notify-button", "");
225
- actionBtn.setAttribute("data-state", state);
226
- actionBtn.textContent = toast.button.title;
227
- actionBtn.addEventListener("click", (e)=>{
228
- var _toast_button;
229
- e.stopPropagation();
230
- (_toast_button = toast.button) == null ? void 0 : _toast_button.onClick();
231
- notifyCore.dismiss(toast.id);
232
- });
233
- content.appendChild(actionBtn);
234
- }
235
- card.appendChild(content);
236
- }
237
- btn.appendChild(card);
238
- btn.addEventListener("click", ()=>notifyCore.dismiss(toast.id));
239
- requestAnimationFrame(()=>{
240
- requestAnimationFrame(()=>{
241
- btn.setAttribute("data-ready", "true");
242
- });
243
- });
244
- return btn;
245
- }
246
- function updateToastEl(el, toast) {
247
- const state = toast.type || "success";
248
- el.setAttribute("data-state", state);
249
- if (toast.exiting) {
250
- el.setAttribute("data-exiting", "true");
251
- }
252
- }
253
- function renderNotifyToasts(options = {}) {
254
- var _options_position;
255
- const position = (_options_position = options.position) != null ? _options_position : "top-right";
256
- const vp = getOrCreateViewport(position);
257
- return notifyCore.subscribe((toasts)=>{
258
- const liveIds = new Set(toasts.map((t)=>t.id));
259
- for (const [id, el] of toastEls){
260
- if (!liveIds.has(id)) {
261
- el.setAttribute("data-exiting", "true");
262
- setTimeout(()=>{
263
- el.remove();
264
- toastEls.delete(id);
265
- }, EXIT_MS);
266
- }
267
- }
268
- for (const toast of toasts){
269
- if (toastEls.has(toast.id)) {
270
- updateToastEl(toastEls.get(toast.id), toast);
271
- } else {
272
- const el = buildToastEl(toast);
273
- toastEls.set(toast.id, el);
274
- vp.appendChild(el);
275
- }
276
- }
277
- });
278
- }
279
-
280
- export { notifyToasts, renderNotifyToasts, showNotifyToast };
package/dist/vue.d.mts DELETED
@@ -1,107 +0,0 @@
1
- import * as vue from 'vue';
2
-
3
- type NotifyState = "success" | "loading" | "error" | "warning" | "info" | "action";
4
- interface NotifyStyles {
5
- title?: string;
6
- description?: string;
7
- badge?: string;
8
- button?: string;
9
- }
10
- interface NotifyButton {
11
- title: string;
12
- onClick: () => void;
13
- }
14
- declare const NOTIFY_POSITIONS: readonly ["top-left", "top-center", "top-right", "bottom-left", "bottom-center", "bottom-right"];
15
- type NotifyPosition = (typeof NOTIFY_POSITIONS)[number];
16
- interface NotifyOptions {
17
- title?: string;
18
- description?: string;
19
- type?: NotifyState;
20
- position?: NotifyPosition;
21
- duration?: number | null;
22
- icon?: any;
23
- styles?: NotifyStyles;
24
- fill?: string;
25
- roundness?: number;
26
- autopilot?: boolean | {
27
- expand?: number;
28
- collapse?: number;
29
- };
30
- button?: NotifyButton;
31
- }
32
-
33
- interface NotifyItem extends NotifyOptions {
34
- id: string;
35
- instanceId: string;
36
- exiting?: boolean;
37
- autoExpandDelayMs?: number;
38
- autoCollapseDelayMs?: number;
39
- }
40
-
41
- declare function useNotifyToasts(): {
42
- toasts: vue.Ref<{
43
- id: string;
44
- instanceId: string;
45
- exiting?: boolean | undefined;
46
- autoExpandDelayMs?: number | undefined;
47
- autoCollapseDelayMs?: number | undefined;
48
- title?: string | undefined;
49
- description?: string | undefined;
50
- type?: NotifyState | undefined;
51
- position?: NotifyPosition | undefined;
52
- duration?: number | null | undefined;
53
- icon?: any;
54
- styles?: {
55
- title?: string | undefined;
56
- description?: string | undefined;
57
- badge?: string | undefined;
58
- button?: string | undefined;
59
- } | undefined;
60
- fill?: string | undefined;
61
- roundness?: number | undefined;
62
- autopilot?: boolean | {
63
- expand?: number | undefined;
64
- collapse?: number | undefined;
65
- } | undefined;
66
- button?: {
67
- title: string;
68
- onClick: () => void;
69
- } | undefined;
70
- }[], NotifyItem[] | {
71
- id: string;
72
- instanceId: string;
73
- exiting?: boolean | undefined;
74
- autoExpandDelayMs?: number | undefined;
75
- autoCollapseDelayMs?: number | undefined;
76
- title?: string | undefined;
77
- description?: string | undefined;
78
- type?: NotifyState | undefined;
79
- position?: NotifyPosition | undefined;
80
- duration?: number | null | undefined;
81
- icon?: any;
82
- styles?: {
83
- title?: string | undefined;
84
- description?: string | undefined;
85
- badge?: string | undefined;
86
- button?: string | undefined;
87
- } | undefined;
88
- fill?: string | undefined;
89
- roundness?: number | undefined;
90
- autopilot?: boolean | {
91
- expand?: number | undefined;
92
- collapse?: number | undefined;
93
- } | undefined;
94
- button?: {
95
- title: string;
96
- onClick: () => void;
97
- } | undefined;
98
- }[]>;
99
- };
100
- declare function showNotifyToast(options: NotifyOptions): string;
101
-
102
- declare function renderNotifyToasts(options?: {
103
- position?: NotifyPosition;
104
- }): () => boolean;
105
-
106
- export { renderNotifyToasts, showNotifyToast, useNotifyToasts };
107
- //# sourceMappingURL=vue.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vue.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/vue-notify.ts","../src/render-notify-toasts.ts"],"mappings":";;AAAA,KAAK,WAAW;AAChB,UAAU,YAAY;AACtB;AACA;AACA;AACA;AACA;AACA,UAAU,YAAY;AACtB;AACA;AACA;AACA,cAAc,gBAAgB;AAC9B,KAAK,cAAc,WAAW,gBAAgB;AAC9C,UAAU,aAAa;AACvB;AACA;AACA,WAAW,WAAW;AACtB,eAAe,cAAc;AAC7B;AACA;AACA,aAAa,YAAY;AACzB;AACA;AACA;AACA;AACA;AACA;AACA,aAAa,YAAY;AACzB;;AC1BA,UAAU,UAAU,SAAS,aAAa;AAC1C;AACA;AACA;AACA;AACA;AACA;;ACJA,iBAAiB,eAAe;AAChC,YAAY,GAAG,CAAC,GAAG;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeA,WAAmB;AAClC,mBAAmBC,cAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAA6B;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeF,WAAmB;AAClC,mBAAmBC,cAAsB;AACzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB,eAAe,UAAU,aAAa;;AC9DvD,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":["__types.NotifyState","__types.NotifyPosition","__core_notify_core.NotifyItem"]}