@samline/notify 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,213 @@
1
+ (() => {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+
40
+ // src/render-notify-toasts.ts
41
+ var exports_render_notify_toasts = {};
42
+ __export(exports_render_notify_toasts, {
43
+ renderNotifyToasts: () => renderNotifyToasts
44
+ });
45
+
46
+ // src/core/notify-core.ts
47
+ class NotifyCore {
48
+ toasts = [];
49
+ listeners = new Set;
50
+ position = "top-right";
51
+ options = undefined;
52
+ idCounter = 0;
53
+ generateId() {
54
+ return `${++this.idCounter}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
55
+ }
56
+ subscribe(fn) {
57
+ this.listeners.add(fn);
58
+ fn(this.toasts);
59
+ return () => this.listeners.delete(fn);
60
+ }
61
+ emit() {
62
+ for (const fn of this.listeners)
63
+ fn(this.toasts);
64
+ }
65
+ update(fn) {
66
+ this.toasts = fn(this.toasts);
67
+ this.emit();
68
+ }
69
+ dismiss(id) {
70
+ const item = this.toasts.find((t) => t.id === id);
71
+ if (!item || item.exiting)
72
+ return;
73
+ this.update((prev) => prev.map((t) => t.id === id ? { ...t, exiting: true } : t));
74
+ setTimeout(() => this.update((prev) => prev.filter((t) => t.id !== id)), 600);
75
+ }
76
+ show(opts) {
77
+ const id = opts.title ? `notify-${opts.title}` : "notify-default";
78
+ const prevItem = this.toasts.find((t) => t.id === id);
79
+ const instanceId = prevItem?.instanceId ?? this.generateId();
80
+ const state = opts.type ?? prevItem?.type ?? "success";
81
+ const item = {
82
+ ...prevItem,
83
+ ...opts,
84
+ id,
85
+ instanceId,
86
+ type: state
87
+ };
88
+ this.update((prev) => {
89
+ const filtered = prev.filter((t) => t.id !== id);
90
+ return [...filtered, item];
91
+ });
92
+ return id;
93
+ }
94
+ getToasts() {
95
+ return this.toasts;
96
+ }
97
+ }
98
+ var notifyCore = new NotifyCore;
99
+
100
+ // src/render-notify-toasts.ts
101
+ var ICONS = {
102
+ 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>',
103
+ 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>',
104
+ 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>',
105
+ 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>',
106
+ 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>',
107
+ 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>'
108
+ };
109
+ var EXIT_MS = 600;
110
+ function capitalize(s) {
111
+ return s ? s.charAt(0).toUpperCase() + s.slice(1) : "";
112
+ }
113
+ var viewport = null;
114
+ var toastEls = new Map;
115
+ function getOrCreateViewport(position) {
116
+ if (!viewport) {
117
+ viewport = document.createElement("div");
118
+ viewport.setAttribute("data-notify-viewport", "");
119
+ viewport.setAttribute("data-position", position);
120
+ viewport.setAttribute("data-theme", "light");
121
+ document.body.appendChild(viewport);
122
+ }
123
+ return viewport;
124
+ }
125
+ function buildToastEl(toast) {
126
+ const state = toast.type || "success";
127
+ const btn = document.createElement("button");
128
+ btn.type = "button";
129
+ btn.setAttribute("data-notify-toast", "");
130
+ btn.setAttribute("data-state", state);
131
+ btn.setAttribute("data-ready", "false");
132
+ btn.setAttribute("data-exiting", "false");
133
+ const card = document.createElement("div");
134
+ card.setAttribute("data-notify-card", "");
135
+ const header = document.createElement("div");
136
+ header.setAttribute("data-notify-header", "");
137
+ const badge = document.createElement("div");
138
+ badge.setAttribute("data-notify-badge", "");
139
+ badge.setAttribute("data-state", state);
140
+ badge.innerHTML = ICONS[state] || ICONS.success;
141
+ const titleEl = document.createElement("span");
142
+ titleEl.setAttribute("data-notify-title", "");
143
+ titleEl.setAttribute("data-state", state);
144
+ titleEl.textContent = toast.title || capitalize(state);
145
+ header.appendChild(badge);
146
+ header.appendChild(titleEl);
147
+ card.appendChild(header);
148
+ if (toast.description || toast.button) {
149
+ const content = document.createElement("div");
150
+ content.setAttribute("data-notify-content", "");
151
+ content.setAttribute("data-visible", "true");
152
+ if (toast.description) {
153
+ const desc = document.createElement("div");
154
+ desc.setAttribute("data-notify-description", "");
155
+ desc.textContent = toast.description;
156
+ content.appendChild(desc);
157
+ }
158
+ if (toast.button) {
159
+ const actionBtn = document.createElement("button");
160
+ actionBtn.setAttribute("data-notify-button", "");
161
+ actionBtn.setAttribute("data-state", state);
162
+ actionBtn.textContent = toast.button.title;
163
+ actionBtn.addEventListener("click", (e) => {
164
+ e.stopPropagation();
165
+ toast.button?.onClick();
166
+ notifyCore.dismiss(toast.id);
167
+ });
168
+ content.appendChild(actionBtn);
169
+ }
170
+ card.appendChild(content);
171
+ }
172
+ btn.appendChild(card);
173
+ btn.addEventListener("click", () => notifyCore.dismiss(toast.id));
174
+ requestAnimationFrame(() => {
175
+ requestAnimationFrame(() => {
176
+ btn.setAttribute("data-ready", "true");
177
+ });
178
+ });
179
+ return btn;
180
+ }
181
+ function updateToastEl(el, toast) {
182
+ const state = toast.type || "success";
183
+ el.setAttribute("data-state", state);
184
+ if (toast.exiting) {
185
+ el.setAttribute("data-exiting", "true");
186
+ }
187
+ }
188
+ function renderNotifyToasts(options = {}) {
189
+ const position = options.position ?? "top-right";
190
+ const vp = getOrCreateViewport(position);
191
+ return notifyCore.subscribe((toasts) => {
192
+ const liveIds = new Set(toasts.map((t) => t.id));
193
+ for (const [id, el] of toastEls) {
194
+ if (!liveIds.has(id)) {
195
+ el.setAttribute("data-exiting", "true");
196
+ setTimeout(() => {
197
+ el.remove();
198
+ toastEls.delete(id);
199
+ }, EXIT_MS);
200
+ }
201
+ }
202
+ for (const toast of toasts) {
203
+ if (toastEls.has(toast.id)) {
204
+ updateToastEl(toastEls.get(toast.id), toast);
205
+ } else {
206
+ const el = buildToastEl(toast);
207
+ toastEls.set(toast.id, el);
208
+ vp.appendChild(el);
209
+ }
210
+ }
211
+ });
212
+ }
213
+ })();
package/dist/styles.css CHANGED
@@ -475,3 +475,84 @@
475
475
  [data-notify-viewport][data-theme="light"] [data-notify-description] {
476
476
  color: rgba(255, 255, 255, 0.5);
477
477
  }
478
+
479
+ /* -------- Browser / CDN card renderer (render-notify-toasts.js) ---------- */
480
+ /*
481
+ * When a [data-notify-card] is present (VanillaJS renderer), we override the
482
+ * SVG-based layout from the React component and use a plain HTML card instead.
483
+ */
484
+
485
+ [data-notify-toast]:has([data-notify-card]) {
486
+ width: auto;
487
+ height: auto;
488
+ background: transparent;
489
+ }
490
+
491
+ [data-notify-card] {
492
+ background: #ffffff;
493
+ border-radius: 20px;
494
+ box-shadow:
495
+ 0 4px 24px rgba(0, 0, 0, 0.1),
496
+ 0 1px 4px rgba(0, 0, 0, 0.06);
497
+ width: var(--notify-width);
498
+ overflow: hidden;
499
+ }
500
+
501
+ /* Header row: icon badge + title */
502
+ [data-notify-card] [data-notify-header] {
503
+ position: relative;
504
+ display: flex;
505
+ align-items: center;
506
+ gap: 0.5rem;
507
+ padding: 0.5rem 0.75rem;
508
+ height: auto;
509
+ left: auto;
510
+ max-width: none;
511
+ transform: none;
512
+ overflow: visible;
513
+ }
514
+
515
+ /* Content area: description + optional button */
516
+ [data-notify-card] [data-notify-content] {
517
+ position: relative;
518
+ opacity: 1;
519
+ pointer-events: auto;
520
+ content-visibility: visible;
521
+ border-top: 1px solid rgba(0, 0, 0, 0.06);
522
+ }
523
+
524
+ /* State colors for the badge icon and title inside the card */
525
+ [data-notify-card]
526
+ :is([data-notify-badge], [data-notify-title])[data-state] {
527
+ color: var(--notify-state-success);
528
+ }
529
+
530
+ [data-notify-card]
531
+ :is([data-notify-badge], [data-notify-title])[data-state="error"] {
532
+ color: var(--notify-state-error);
533
+ }
534
+
535
+ [data-notify-card]
536
+ :is([data-notify-badge], [data-notify-title])[data-state="warning"] {
537
+ color: var(--notify-state-warning);
538
+ }
539
+
540
+ [data-notify-card]
541
+ :is([data-notify-badge], [data-notify-title])[data-state="info"] {
542
+ color: var(--notify-state-info);
543
+ }
544
+
545
+ [data-notify-card]
546
+ :is([data-notify-badge], [data-notify-title])[data-state="loading"] {
547
+ color: var(--notify-state-loading);
548
+ }
549
+
550
+ [data-notify-card]
551
+ :is([data-notify-badge], [data-notify-title])[data-state="action"] {
552
+ color: var(--notify-state-action);
553
+ }
554
+
555
+ /* Description text */
556
+ [data-notify-card] [data-notify-description] {
557
+ color: rgba(0, 0, 0, 0.6);
558
+ }
package/dist/svelte.d.mts CHANGED
@@ -41,5 +41,9 @@ interface NotifyItem extends NotifyOptions {
41
41
  declare const notifyToasts: svelte_store.Writable<NotifyItem[]>;
42
42
  declare function showNotifyToast(options: NotifyOptions): string;
43
43
 
44
- export { notifyToasts, showNotifyToast };
44
+ declare function renderNotifyToasts(options?: {
45
+ position?: NotifyPosition;
46
+ }): () => boolean;
47
+
48
+ export { notifyToasts, renderNotifyToasts, showNotifyToast };
45
49
  //# sourceMappingURL=svelte.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.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;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;;;","names":["__core_notify_core.NotifyItem"]}
1
+ {"version":3,"file":"svelte.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-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;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;ACHvD,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":["__core_notify_core.NotifyItem"]}
package/dist/svelte.d.ts CHANGED
@@ -41,5 +41,9 @@ interface NotifyItem extends NotifyOptions {
41
41
  declare const notifyToasts: svelte_store.Writable<NotifyItem[]>;
42
42
  declare function showNotifyToast(options: NotifyOptions): string;
43
43
 
44
- export { notifyToasts, showNotifyToast };
44
+ declare function renderNotifyToasts(options?: {
45
+ position?: NotifyPosition;
46
+ }): () => boolean;
47
+
48
+ export { notifyToasts, renderNotifyToasts, showNotifyToast };
45
49
  //# sourceMappingURL=svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"svelte.d.ts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-notify.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;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;;;","names":["__core_notify_core.NotifyItem"]}
1
+ {"version":3,"file":"svelte.d.ts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/svelte-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;;ACLA,cAAc,YAAY,EAAE,YAAY,CAAC,QAAQ,CAACA,UAA6B;AAC/E,iBAAiB,eAAe,UAAU,aAAa;;ACHvD,iBAAiB,kBAAkB;AACnC,eAAe,cAAc;AAC7B;;;;","names":["__core_notify_core.NotifyItem"]}
package/dist/svelte.js CHANGED
@@ -164,5 +164,121 @@ function showNotifyToast(options) {
164
164
  return notifyCore.show(options);
165
165
  }
166
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
+
167
282
  exports.notifyToasts = notifyToasts;
283
+ exports.renderNotifyToasts = renderNotifyToasts;
168
284
  exports.showNotifyToast = showNotifyToast;
package/dist/svelte.mjs CHANGED
@@ -162,4 +162,119 @@ function showNotifyToast(options) {
162
162
  return notifyCore.show(options);
163
163
  }
164
164
 
165
- export { notifyToasts, showNotifyToast };
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 CHANGED
@@ -99,5 +99,9 @@ declare function useNotifyToasts(): {
99
99
  };
100
100
  declare function showNotifyToast(options: NotifyOptions): string;
101
101
 
102
- export { showNotifyToast, useNotifyToasts };
102
+ declare function renderNotifyToasts(options?: {
103
+ position?: NotifyPosition;
104
+ }): () => boolean;
105
+
106
+ export { renderNotifyToasts, showNotifyToast, useNotifyToasts };
103
107
  //# sourceMappingURL=vue.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.mts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/vue-notify.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;;;;","names":["__types.NotifyState","__types.NotifyPosition","__core_notify_core.NotifyItem"]}
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"]}
package/dist/vue.d.ts CHANGED
@@ -99,5 +99,9 @@ declare function useNotifyToasts(): {
99
99
  };
100
100
  declare function showNotifyToast(options: NotifyOptions): string;
101
101
 
102
- export { showNotifyToast, useNotifyToasts };
102
+ declare function renderNotifyToasts(options?: {
103
+ position?: NotifyPosition;
104
+ }): () => boolean;
105
+
106
+ export { renderNotifyToasts, showNotifyToast, useNotifyToasts };
103
107
  //# sourceMappingURL=vue.d.ts.map
package/dist/vue.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vue.d.ts","sources":["../src/types.ts","../src/core/notify-core.ts","../src/vue-notify.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;;;;","names":["__types.NotifyState","__types.NotifyPosition","__core_notify_core.NotifyItem"]}
1
+ {"version":3,"file":"vue.d.ts","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"]}