@t007/toast 0.0.22 → 0.0.24

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.
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  (() => {
3
- // ../../node_modules/sia-reactor/dist/chunk-IBAPWB27.js
3
+ // ../../../sia-reactor/dist/chunk-IBAPWB27.js
4
4
  function clamp(min = 0, val, max = Infinity) {
5
5
  return Math.min(Math.max(val, min), max);
6
6
  }
7
7
 
8
- // ../../node_modules/sia-reactor/dist/chunk-RVYL3OLW.js
8
+ // ../../../sia-reactor/dist/chunk-RVYL3OLW.js
9
9
  function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
10
10
  return assignEl(el, props, dataset, styles), el;
11
11
  }
@@ -22,7 +22,7 @@
22
22
  }
23
23
  }
24
24
 
25
- // ../../node_modules/sia-reactor/dist/chunk-3OT72G7R.js
25
+ // ../../../sia-reactor/dist/chunk-3OT72G7R.js
26
26
  function onAllMethods(owner, callback, skipOwn = true, nested = false) {
27
27
  let proto = owner;
28
28
  while (proto && proto !== Object.prototype) {
@@ -40,7 +40,7 @@
40
40
  });
41
41
  }
42
42
 
43
- // ../../node_modules/sia-reactor/dist/chunk-EZ4VRGYI.js
43
+ // ../../../sia-reactor/dist/chunk-EZ4VRGYI.js
44
44
  var CTX = {
45
45
  /** Flag indicating whether the application is running in development mode. */
46
46
  isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
@@ -56,7 +56,9 @@
56
56
  return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
57
57
  }
58
58
 
59
- // ../utils/dist/index.js
59
+ // ../utils/dist/chunk-XVFFZZJA.js
60
+ var INTERACTIVE_SELECTOR = 'button,[href],input,label,select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]:not([tabindex="-1"])';
61
+ var isInteractive = (target) => target instanceof HTMLElement && target.matches(INTERACTIVE_SELECTOR);
60
62
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
61
63
  function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
62
64
  w.t007 ??= {}, w.t007._resourceCache ??= {};
@@ -85,6 +87,9 @@
85
87
  });
86
88
  return w.t007._resourceCache[src];
87
89
  }
90
+ function isDef(val) {
91
+ return "undefined" !== typeof val;
92
+ }
88
93
  function isSym(val) {
89
94
  return "symbol" === typeof val;
90
95
  }
@@ -110,8 +115,7 @@
110
115
  }
111
116
  }
112
117
  if ("undefined" !== typeof window) {
113
- window.t007 ??= {};
114
- t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
118
+ (window.t007 ??= {}).VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
115
119
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
116
120
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
117
121
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
@@ -120,57 +124,62 @@
120
124
  window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
121
125
  }
122
126
 
123
- // src/index.js
127
+ // src/js/index.js
124
128
  var T007_Toast = class {
129
+ #constructed = false;
130
+ // to minimize updates
125
131
  #autoCloseInterval;
126
132
  #progressInterval;
127
133
  #timeVisible = 0;
128
134
  #isPaused = false;
129
135
  #shouldUnPause;
130
136
  queue = [];
131
- destroyed = true;
137
+ inactive = true;
132
138
  #visiblityChange = () => this.#shouldUnPause = document.visibilityState === "visible";
133
139
  constructor(options) {
134
140
  bindAllMethods(this);
135
- this.opts = { ...options };
136
- this.id = this.opts.id ??= uid(this.opts.idPrefix ?? "t007_toast_");
137
- t007.toasts.set(this.id, this);
138
- !isNum(this.opts.delay) ? this.init() : this.queue.push(setTimeout(this.init, this.opts.delay));
141
+ this.opts = options;
142
+ t007.toasts.set(this.opts.id ??= uid(this.opts.groupId ??= "t007_toast_"), this);
143
+ !isNum(this.opts.delay) ? this.activate() : this.queue.push(setTimeout(this.activate, this.opts.delay));
139
144
  this.update(this.opts);
140
145
  }
141
- init() {
142
- this.toastElement = createEl("div", { className: "t007-toast", id: this.id, ariaAtomic: "true" }, { idPrefix: this.opts.idPrefix });
146
+ activate() {
147
+ this.toastElement = createEl("div", { className: `t007-toast${this.scoped ? " t007-toast-scoped" : ""}`, id: this.opts.id, ariaAtomic: "true" }, { groupId: this.opts.groupId });
143
148
  requestAnimationFrame(() => this.toastElement.classList.add("t007-toast-show"));
144
- this.destroyed = false;
149
+ this.inactive = false;
145
150
  }
146
- update(options) {
147
- if (!options || !isObj(options)) return this.opts.id;
151
+ update(options, constructed = this.#constructed) {
152
+ if (!options || !isObj(options) || constructed && this.inactive) return this.opts.id;
148
153
  try {
149
154
  this.opts = { ...this.opts, ...options };
150
- const run = () => Object.keys(options).forEach((key) => this[key] = options[key]);
155
+ const run = () => (Object.keys(options).forEach((key) => this[key] = options[key]), this.#constructed = true, !constructed && (this.position = this.opts.position));
151
156
  !isNum(this.opts.delay) ? run() : this.queue.push(setTimeout(run, this.opts.delay));
152
157
  this.opts.delay = null;
153
158
  } catch (err) {
154
- console.error("toast update failed:", err);
159
+ console.error("t007 toast update failed:", err);
155
160
  }
156
161
  return this.opts.id;
157
162
  }
158
163
  play = () => setTimeout(() => this.#isPaused = false);
159
164
  pause = () => this.#isPaused = true;
165
+ get rootElement() {
166
+ return this.opts.rootElement ?? document.body;
167
+ }
160
168
  set rootElement(value) {
161
- const container = value?.querySelector(`.t007-toast-container[data-position="${this.opts.position}"]`);
162
- container?.style.setProperty("--t007-toast-container-position", value === document.body ? "fixed" : "absolute");
163
- container && !value.contains(container) && value.append(container);
169
+ if (this.#constructed) this.position = this.opts.position;
170
+ }
171
+ get scoped() {
172
+ return this.rootElement !== document.body;
164
173
  }
165
174
  set type(value) {
166
175
  this.toastElement.classList.remove("info", "success", "error", "warning");
167
176
  value && this.toastElement.classList.add(value);
168
177
  this.toastElement.role = value === "error" || value === "warning" ? "alert" : "status";
169
178
  this.toastElement.ariaLive = value === "error" || value === "warning" ? "assertive" : "polite";
170
- if (value) this.icon = this.opts.icon;
179
+ if (value && this.#constructed) this.icon = this.opts.icon;
171
180
  }
172
181
  set bodyHTML(value) {
173
- this.toastElement.querySelectorAll(".t007-toast > *:not(.t007-toast-cancel-button)").forEach((el) => el.remove());
182
+ for (const el of this.toastElement.querySelectorAll(":scope > *:not(.t007-toast-cancel-button)")) el.remove();
174
183
  this.toastElement.insertAdjacentHTML("afterbegin", `${value ? isFunc(value) ? value() : value : ""}`);
175
184
  }
176
185
  set render(value) {
@@ -196,12 +205,7 @@
196
205
  const image = () => this.toastElement.querySelector(".t007-toast-image");
197
206
  if (value) {
198
207
  this._setUpBodyHTML();
199
- this.toastElement.querySelector(".t007-toast-image-wrapper").prepend(
200
- image() || createEl("img", {
201
- className: "t007-toast-image",
202
- alt: "toast-image"
203
- })
204
- );
208
+ this.toastElement.querySelector(".t007-toast-image-wrapper").prepend(image() || createEl("img", { className: "t007-toast-image", alt: "toast-image" }));
205
209
  const img = image();
206
210
  img.src = value;
207
211
  img.onload = img.onerror = () => img.dataset.loaded = img.complete && img.naturalWidth > 0;
@@ -215,7 +219,7 @@
215
219
  const icon = () => this.toastElement.querySelector(".t007-toast-icon:not(.t007-toast-loader)");
216
220
  if (value) {
217
221
  this._setUpBodyHTML();
218
- this.toastElement.querySelector(".t007-toast-image-wrapper").appendChild(icon() || createEl("span", { className: "t007-toast-icon" }));
222
+ this.toastElement.querySelector(".t007-toast-image-wrapper").append(icon() || createEl("span", { className: "t007-toast-icon" }));
219
223
  const icn = icon();
220
224
  icn.innerHTML = icn.dataset.icon = this.icon;
221
225
  } else icon()?.remove();
@@ -224,49 +228,25 @@
224
228
  const loader = () => this.toastElement.querySelector(".t007-toast-loader");
225
229
  if (value) {
226
230
  this._setUpBodyHTML();
227
- this.toastElement.querySelectorAll(".t007-toast-icon:not(.t007-toast-loader)").forEach((i) => i.remove());
228
- this.toastElement.querySelector(".t007-toast-image-wrapper").appendChild(
229
- loader() || createEl("span", {
230
- className: "t007-toast-icon t007-toast-loader"
231
- })
232
- );
231
+ for (const i of this.toastElement.querySelectorAll(".t007-toast-icon:not(.t007-toast-loader)")) i.remove();
232
+ this.toastElement.querySelector(".t007-toast-image-wrapper").append(loader() || createEl("span", { className: "t007-toast-icon t007-toast-loader" }));
233
233
  loader().innerHTML = isStr(value) ? value : t007.TOAST_ICONS.loading;
234
234
  } else {
235
235
  loader()?.remove();
236
- this.icon = this.opts.icon;
236
+ if (this.#constructed) this.icon = this.opts.icon;
237
237
  }
238
238
  }
239
239
  set closeButton(value) {
240
240
  const btn = this.toastElement.querySelector(".t007-toast-cancel-button");
241
- if (value)
242
- this.toastElement.appendChild(
243
- btn || createEl("button", {
244
- title: "Close",
245
- ariaLabel: "Close notification",
246
- className: "t007-toast-cancel-button",
247
- innerHTML: "×",
248
- onclick: this._remove
249
- })
250
- );
241
+ if (value) this.toastElement.append(btn || createEl("button", { title: "Close", ariaLabel: "Close notification", className: "t007-toast-cancel-button", innerHTML: "×", onclick: this.remove }));
251
242
  else btn?.remove();
252
243
  }
253
244
  get animation() {
245
+ const p = this.opts.position;
254
246
  if (this.opts.animation === true || this.opts.animation === "slide")
255
- switch (this.opts.position) {
256
- case "top-right":
257
- case "center-right":
258
- case "bottom-right":
259
- return "slide-left";
260
- case "top-center":
261
- case "center-center":
262
- case "bottom-center":
263
- return this.opts.position === "top-center" ? "slide-down" : "slide-up";
264
- case "top-left":
265
- case "center-left":
266
- case "bottom-left":
267
- default:
268
- return "slide-right";
269
- }
247
+ if (p === "top-right" || p === "center-right" || p === "bottom-right") return "slide-left";
248
+ else if (p === "top-center" || p === "center-center" || p === "bottom-center") return p === "top-center" ? "slide-down" : "slide-up";
249
+ else return "slide-right";
270
250
  return this.opts.animation;
271
251
  }
272
252
  set animation(value) {
@@ -278,6 +258,7 @@
278
258
  set autoClose(value) {
279
259
  cancelAnimationFrame(this.#autoCloseInterval);
280
260
  this.#timeVisible = 0;
261
+ this.nprogress = void 0;
281
262
  let lastTime;
282
263
  const loop = (time) => {
283
264
  if (this.#shouldUnPause) {
@@ -291,7 +272,7 @@
291
272
  if (!this.#isPaused) {
292
273
  this.#timeVisible += time - lastTime;
293
274
  this.onTimeUpdate?.(this.#timeVisible);
294
- if (isNum(this.autoClose) && this.#timeVisible >= this.autoClose) return this._remove("smooth", true);
275
+ if (isNum(this.autoClose) && this.#timeVisible >= this.autoClose) return this.remove("smooth", true);
295
276
  }
296
277
  lastTime = time;
297
278
  this.#autoCloseInterval = requestAnimationFrame(loop);
@@ -299,20 +280,21 @@
299
280
  if (value) this.#autoCloseInterval = requestAnimationFrame(loop);
300
281
  }
301
282
  set position(value) {
302
- const currentContainer = this.toastElement.parentElement;
303
- const container = this.opts.rootElement?.querySelector(`.t007-toast-container[data-position="${value}"]`) || this._createContainer(value);
283
+ if (!this.#constructed) return;
284
+ const currContainer = this.toastElement.parentElement, container = this.rootElement.querySelector(`:scope > .t007-toast-container[data-position="${value}"]`) || this._createContainer(value);
304
285
  container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
305
- if (!(currentContainer == null || currentContainer.hasChildNodes())) currentContainer.remove();
286
+ this.toastElement.classList.toggle("t007-toast-scoped", this.scoped);
287
+ if (!(currContainer == null || currContainer.hasChildNodes())) currContainer.remove();
306
288
  }
307
289
  set closeOnClick(value) {
308
- this.toastElement.onclick = value ? () => this._remove() : null;
290
+ this.toastElement.onclick = value ? () => this.remove() : null;
309
291
  }
310
292
  set hideProgressBar(value) {
311
293
  this.toastElement.classList.toggle("progress", !value);
312
- this.nprogress = 0;
294
+ this.nprogress = void 0;
313
295
  cancelAnimationFrame(this.#progressInterval);
314
296
  const loop = () => {
315
- if (isNum(this.autoClose) && !this.#isPaused) this.nprogress = 1 - this.#timeVisible / this.autoClose;
297
+ if (isNum(this.autoClose) && !this.#isPaused) this.nprogress = void 0;
316
298
  this.#progressInterval = requestAnimationFrame(loop);
317
299
  };
318
300
  if (!value) this.#progressInterval = requestAnimationFrame(loop);
@@ -320,7 +302,7 @@
320
302
  get nprogress() {
321
303
  return Number(this.toastElement.style.getProperty("--progress"));
322
304
  }
323
- set nprogress(value) {
305
+ set nprogress(value = 1 - this.#timeVisible / this.autoClose) {
324
306
  this.toastElement.style.setProperty("--progress", value);
325
307
  }
326
308
  set pauseOnHover(value) {
@@ -335,7 +317,9 @@
335
317
  this.toastElement.dataset.tag = value;
336
318
  }
337
319
  set renotify(value) {
338
- value && this.opts.tag && t007.toasts.entries().forEach(([id, toast2]) => id !== this.id && (toast2.opts.tag ?? 1) === (this.opts.tag ?? 0) && toast2._remove("instant"));
320
+ if (value && this.opts.tag) {
321
+ for (const toast2 of t007.toasts.values()) if (toast2.opts.tag === this.opts.tag && toast2.opts.id !== this.opts.id) toast2.remove("instant");
322
+ }
339
323
  }
340
324
  get vibrate() {
341
325
  return this.opts.vibrate === true ? t007.TOAST_VIBRATIONS[this.opts.type] || t007.TOAST_VIBRATIONS.info : this.opts.vibrate;
@@ -343,12 +327,10 @@
343
327
  set vibrate(value) {
344
328
  value && navigator?.vibrate?.(this.vibrate);
345
329
  }
346
- set maxToasts(value) {
330
+ set limit(value) {
347
331
  const toastsInContainer = [...this.toastElement?.parentElement?.children || []];
348
332
  if (!toastsInContainer.length) return;
349
- for (let i = 0; i < toastsInContainer.length - value; i++) {
350
- [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?._remove("instant");
351
- }
333
+ for (let i = 0; i < toastsInContainer.length - value; i++) [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?.remove("instant");
352
334
  }
353
335
  set newestOnTop(value) {
354
336
  this.toastElement?.parentElement?.[value ? "prepend" : "append"](this.toastElement);
@@ -361,7 +343,7 @@
361
343
  _handleToastPointerStart(e) {
362
344
  if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
363
345
  if (e.touches?.length > 1) return;
364
- !e.target?.matches('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') && this.toastElement.setPointerCapture(e.pointerId);
346
+ !isInteractive(e.target) && this.toastElement.setPointerCapture(e.pointerId);
365
347
  this.#isPaused = true;
366
348
  this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
367
349
  this._ptrStartX = e.clientX ?? e.targetTouches[0]?.clientX;
@@ -389,34 +371,28 @@
389
371
  _handleToastPointerUp(e) {
390
372
  if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
391
373
  cancelAnimationFrame(this._ptrRAF);
392
- if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * (this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * (this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent / 100)) return this._remove("instant");
374
+ if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * ((this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent) / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * ((this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent) / 100)) return this.remove("instant");
393
375
  this.#isPaused = this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
394
376
  this.toastElement.removeEventListener("pointermove", this._handleToastPointerMove, { passive: false });
395
- this.toastElement.style.removeProperty("transition");
396
- this.toastElement.style.removeProperty("transform");
397
- this.toastElement.style.removeProperty("opacity");
377
+ for (const prop of ["transition", "transform", "opacity"]) this.toastElement.style.removeProperty(prop);
398
378
  }
399
- _remove(manner = "smooth", timeElapsed = false) {
400
- if (!this.opts.isLoading) t007.toasts.delete(this.id);
401
- this.queue.forEach(clearTimeout);
379
+ remove(manner = "smooth", timeElapsed = false) {
380
+ if (!this.opts.isLoading) t007.toasts.delete(this.opts.id);
381
+ for (const tid of this.queue) clearTimeout(tid);
402
382
  document.removeEventListener("visibilitychange", this.#visiblityChange);
403
- cancelAnimationFrame(this.#autoCloseInterval);
404
- cancelAnimationFrame(this.#progressInterval);
405
- if (this.destroyed || manner === "instant" || !this.animation) this._cleanUpToast();
383
+ cancelAnimationFrame(this.#autoCloseInterval), cancelAnimationFrame(this.#progressInterval);
384
+ if (this.inactive || manner === "instant" || !this.animation) this._cleanUpToast();
406
385
  else this.toastElement.onanimationend = this._cleanUpToast;
407
386
  this.toastElement.classList.remove("t007-toast-show");
408
387
  this.onClose?.(timeElapsed);
409
388
  }
410
389
  _createContainer(position) {
411
- const container = document.createElement("div");
412
- container.classList.add("t007-toast-container");
413
- container.style.setProperty("--t007-toast-container-position", this.opts.rootElement === document.body ? "fixed" : "absolute");
414
- container.dataset.position = position;
415
- this.opts.rootElement?.append(container);
416
- return container;
390
+ const container = createEl("div", { className: "t007-toast-container" }, { position });
391
+ container.style.setProperty("--t007-toast-container-position", !this.scoped ? "fixed" : "absolute");
392
+ return this.rootElement.appendChild(container);
417
393
  }
418
394
  _setUpBodyHTML() {
419
- this.toastElement.querySelectorAll(".t007-toast > *:not(.t007-toast-image-wrapper, .t007-toast-body, .t007-toast-actions-wrapper, .t007-toast-cancel-button)").forEach((el) => el.remove());
395
+ this.#constructed && this.toastElement.querySelectorAll(":scope > *:not(.t007-toast-image-wrapper, .t007-toast-body, .t007-toast-actions-wrapper, .t007-toast-cancel-button)").forEach((el) => el.remove());
420
396
  const imageWrapper = () => this.toastElement.querySelector(".t007-toast-image-wrapper");
421
397
  if (!imageWrapper()) this.toastElement.prepend(createEl("div", { className: "t007-toast-image-wrapper" }));
422
398
  if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
@@ -425,46 +401,42 @@
425
401
  const container = this.toastElement.parentElement;
426
402
  this.toastElement.remove();
427
403
  if (!container?.hasChildNodes()) container?.remove();
428
- this.destroyed = true;
404
+ this.inactive = true;
429
405
  }
430
406
  };
431
407
  var toasting = {
432
- update(base, id, options) {
408
+ isActive(_, id) {
433
409
  const toast2 = t007.toasts.get(id);
434
- toast2?.queue.forEach(clearTimeout);
435
- return !!toast2 && (toast2.destroyed ? base(options.render, { ...toast2.opts, id, ...options }) : toast2.update(options));
410
+ return !!toast2 && !toast2.inactive;
411
+ },
412
+ update(base, id, options, _toast) {
413
+ const toast2 = _toast ?? t007.toasts.get(id);
414
+ if (toast2?.queue) for (const tid of toast2.queue) clearTimeout(tid);
415
+ return toast2 && (toast2.inactive ? base(options.render, { ...toast2.opts, id, ...options }) : toast2.update(options));
436
416
  },
437
- message: (base, defaults, action) => base[action] = (renderOrId, options = {}) => {
417
+ message: (base, getDefaults, action, renderOrId, options = {}) => {
438
418
  options = { ...options, type: action === "warn" ? "warning" : action };
439
- if (!t007.toasts.get(renderOrId)) return base(renderOrId, options);
440
- const { autoClose, closeButton, closeOnClick, dragToClose } = defaults();
441
- return base.update(renderOrId, {
442
- ...t007.toasts.get(renderOrId)?.opts.isLoading ? { autoClose, closeButton, closeOnClick, dragToClose } : {},
443
- ...options,
444
- isLoading: false
445
- });
419
+ const id = options.id ?? renderOrId, toast2 = t007.toasts.get(id);
420
+ if (!toast2) return base(renderOrId, options);
421
+ const { autoClose, closeButton, closeOnClick, dragToClose } = getDefaults();
422
+ return base.update(id, { ...toast2.opts.isLoading ? { closeButton, closeOnClick, dragToClose } : null, ...options.id ? { render: renderOrId } : null, autoClose, ...options, isLoading: false }, toast2);
423
+ },
424
+ loading: (base, renderOrId, options = {}) => {
425
+ const id = options.id ?? renderOrId, toast2 = t007.toasts.get(id);
426
+ return (toast2 ? base.update : base)(id, { closeButton: false, closeOnClick: false, dragToClose: false, ...options.id ? { render: renderOrId } : null, autoClose: false, ...options, isLoading: options.isLoading || true, type: "" }, toast2 || void 0);
446
427
  },
447
- loading: (base, renderOrId, options = {}) => (t007.toasts.get(renderOrId) ? base.update : base)(renderOrId, {
448
- autoClose: false,
449
- closeButton: false,
450
- closeOnClick: false,
451
- dragToClose: false,
452
- ...options,
453
- isLoading: options.isLoading || true,
454
- type: ""
455
- }),
456
428
  promise(base, promise = new Promise((res, rej) => setTimeout(Math.round(Math.random()) ? res : rej, 3e3)), { pending, success, error } = {}) {
457
429
  if (!promise || !isFunc(promise.then)) return console.error("toast.promise() requires a valid promise");
458
430
  const NFC = (input, type) => isStr(input) ? { render: input, type } : isObj(input) ? { ...input, type } : { type };
459
- const pendingConfig = NFC(pending);
460
- const pendingToastId = base.loading(pendingConfig.render || "Promise pending...", { ...pendingConfig });
431
+ const pendingCfg = NFC(pending);
432
+ const pendingId = base.loading(pendingCfg.render || "Promise pending...", { ...pendingCfg });
461
433
  promise.then(
462
434
  (response) => {
463
435
  const successConfig = NFC(success || "Promise resolved", "success");
464
436
  const { render, bodyHTML } = successConfig;
465
437
  if (isFunc(render)) successConfig.render = (response2) => render(response2);
466
438
  if (isFunc(bodyHTML)) successConfig.bodyHTML = (response2) => bodyHTML(response2);
467
- base.success(pendingToastId, successConfig);
439
+ base.success(pendingId, successConfig);
468
440
  return response;
469
441
  },
470
442
  (err) => {
@@ -472,41 +444,36 @@
472
444
  const { render, bodyHTML } = errorConfig;
473
445
  if (isFunc(render)) errorConfig.render = (err2) => render(err2);
474
446
  if (isFunc(bodyHTML)) errorConfig.bodyHTML = (err2) => bodyHTML(err2);
475
- base.error(pendingToastId, errorConfig);
447
+ base.error(pendingId, errorConfig);
476
448
  return Promise.reject(err);
477
449
  }
478
450
  );
479
451
  return promise;
480
452
  },
481
453
  dismiss(base, id, manner, timeElapsed) {
482
- return !arguments.length ? base.dismissAll() : t007.toasts.get(id)?._remove(manner, timeElapsed);
454
+ return !isDef(id) ? base.dismissAll() : t007.toasts.get(id)?.remove(manner, timeElapsed);
483
455
  },
484
- dismissAll(base, idPrefix) {
485
- t007.toasts.values().forEach((toast2) => (!arguments.length ? true : toast2.id.startsWith(idPrefix)) && toast2._remove());
456
+ dismissAll(base, groupId) {
457
+ for (const toast2 of t007.toasts.values()) (!isDef(groupId) ? true : toast2.opts.groupId === groupId) && toast2.remove();
486
458
  },
487
- doForAll(base, action, options, idPrefix) {
488
- t007.toasts.keys().forEach((id) => (!arguments.length ? true : id.startsWith(idPrefix)) && base[action]?.(id, options));
459
+ doForAll(base, action, options, groupId) {
460
+ for (const toast2 of t007.toasts.values()) (!isDef(groupId) ? true : toast2.opts.groupId === groupId) && base[action]?.(toast2.opts.id, options);
489
461
  },
490
- getAll(base, idPrefix) {
491
- return t007.toasts.values().filter((toast2) => !arguments.length ? true : toast2.id.startsWith(idPrefix));
462
+ getAll(base, groupId) {
463
+ return t007.toasts.values().filter((toast2) => !isDef(groupId) ? true : toast2.opts.groupId === groupId);
492
464
  }
493
465
  };
494
- var toaster = (defOptions = {}, idPrefix = "t007_toast_") => {
495
- const defaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (render, options = {}) => new T007_Toast({
496
- ...defaults(),
497
- ...options,
498
- id: render?.startsWith?.(idPrefix) ? render : options.id,
499
- render: render?.startsWith?.(idPrefix) ? options.render : render,
500
- idPrefix
501
- }).id;
502
- base.update = (id, options) => toasting.update(base, id, options);
503
- ["info", "success", "warn", "error"].forEach((action) => toasting.message(base, defaults, action));
504
- base.loading = (render, options) => toasting.loading(base, render, options);
505
- base.promise = (promise, options) => toasting.promise(base, promise, options);
466
+ var toaster = (defOptions = {}, groupId = "t007_toast_") => {
467
+ const getDefaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (render, options = {}, mayBeId = render?.startsWith?.(groupId)) => new T007_Toast({ ...getDefaults(), ...options, id: mayBeId ? render : options.id, render: mayBeId ? options.render : render, groupId }).opts.id;
468
+ base.isActive = (id) => toasting.isActive(base, id);
469
+ base.update = (id, options, _toast) => toasting.update(base, id, options, _toast);
470
+ for (const action of ["info", "success", "warn", "error"]) base[action] = (renderOrId, options) => toasting.message(base, getDefaults, action, renderOrId, options);
471
+ base.loading = (renderOrId, options) => toasting.loading(base, renderOrId, options);
472
+ base.promise = (promise, config) => toasting.promise(base, promise, config);
506
473
  base.dismiss = (id, manner, timeElapsed) => toasting.dismiss(base, id, manner, timeElapsed);
507
- base.dismissAll = (idPrefix2) => toasting.dismissAll(base, idPrefix2);
508
- base.doForAll = (action, options, idPrefix2) => toasting.doForAll(base, action, options, idPrefix2);
509
- base.getAll = (idPrefix2) => toasting.getAll(base, idPrefix2);
474
+ base.dismissAll = (groupId2) => toasting.dismissAll(base, groupId2);
475
+ base.doForAll = (action, options, groupId2) => toasting.doForAll(base, action, options, groupId2);
476
+ base.getAll = (groupId2) => toasting.getAll(base, groupId2);
510
477
  return base;
511
478
  };
512
479
  var toast = toaster();
@@ -516,11 +483,7 @@
516
483
  t007.toasting = toasting;
517
484
  t007.toaster = toaster;
518
485
  t007.toasts = /* @__PURE__ */ new Map();
519
- t007.TOAST_DEFAULT_OPTIONS ??= {};
520
- t007.TOAST_DURATIONS ??= {};
521
- t007.TOAST_VIBRATIONS ??= {};
522
- t007.TOAST_ICONS ??= {};
523
- t007.TOAST_DEFAULT_OPTIONS.rootElement ??= document.body;
486
+ t007.TOAST_DEFAULT_OPTIONS ??= {}, t007.TOAST_DURATIONS ??= {}, t007.TOAST_VIBRATIONS ??= {}, t007.TOAST_ICONS ??= {};
524
487
  t007.TOAST_DEFAULT_OPTIONS.render ??= "";
525
488
  t007.TOAST_DEFAULT_OPTIONS.type ??= "";
526
489
  t007.TOAST_DEFAULT_OPTIONS.icon ??= true;
@@ -540,22 +503,16 @@
540
503
  t007.TOAST_DEFAULT_OPTIONS.vibrate ??= false;
541
504
  t007.TOAST_DEFAULT_OPTIONS.animation ??= true;
542
505
  t007.TOAST_DEFAULT_OPTIONS.newestOnTop ??= false;
543
- t007.TOAST_DEFAULT_OPTIONS.maxToasts ??= 1e3;
544
- t007.TOAST_DURATIONS.success ??= 2500;
545
- t007.TOAST_DURATIONS.error ??= 4500;
546
- t007.TOAST_DURATIONS.warning ??= 3500;
547
- t007.TOAST_DURATIONS.info ??= 4e3;
548
- t007.TOAST_VIBRATIONS.success ??= [100, 50, 100];
549
- t007.TOAST_VIBRATIONS.warning ??= [300, 100, 300];
550
- t007.TOAST_VIBRATIONS.error ??= [500, 200, 500];
551
- t007.TOAST_VIBRATIONS.info ??= [200];
506
+ t007.TOAST_DEFAULT_OPTIONS.limit ??= 100;
507
+ t007.TOAST_DURATIONS.success ??= 2500, t007.TOAST_DURATIONS.error ??= 4500, t007.TOAST_DURATIONS.warning ??= 3500, t007.TOAST_DURATIONS.info ??= 4e3;
508
+ t007.TOAST_VIBRATIONS.success ??= [100, 50, 100], t007.TOAST_VIBRATIONS.warning ??= [300, 100, 300], t007.TOAST_VIBRATIONS.error ??= [500, 200, 500], t007.TOAST_VIBRATIONS.info ??= [200];
552
509
  t007.TOAST_ICONS.success ??= `<svg class="no-css-fill" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#27ae60"/><path fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M7 12l3 3l6-6"/></svg>`;
553
510
  t007.TOAST_ICONS.error ??= `<svg class="no-css-fill" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#e74c3c"/><path fill="#fff" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M8 8l8 8M16 8l-8 8"/></svg>`;
554
511
  t007.TOAST_ICONS.warning ??= `<svg class="no-css-fill" width="24" height="24" viewBox="0 0 24 24"><path fill="#f1c40f" stroke="#f39c12" stroke-width="2" stroke-linejoin="round" d="M12 3L2.5 20.5A2 2 0 0 0 4.5 23h15a2 2 0 0 0 2-2.5L12 3z"/><circle cx="12" cy="17" r="1.5" fill="#fff"/><path fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M12 8v6"/></svg>`;
555
512
  t007.TOAST_ICONS.info ??= `<svg class="no-css-fill" width="24" height="24" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#3498db"/><path fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="M12 10v6"/><circle cx="12" cy="7" r="1.5" fill="#fff"/></svg>`;
556
513
  t007.TOAST_ICONS.loading ??= `<svg class="no-css-fill" width="24" height="24" viewBox="0 0 16 16" fill="none" style="scale:0.75;"><g fill-rule="evenodd" clip-rule="evenodd"><path fill="whitesmoke" d="M8 1.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8"/><path fill="gray" d="M7.25.75A.75.75 0 0 1 8 0a8 8 0 0 1 8 8 .75.75 0 0 1-1.5 0A6.5 6.5 0 0 0 8 1.5a.75.75 0 0 1-.75-.75"/></g><animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0" to="360" dur="600ms" repeatCount="indefinite"/></svg>`;
557
514
  loadResource(T007_TOAST_CSS_SRC);
558
- window.Toast ??= t007.toast;
515
+ window.toast ??= t007.toast;
559
516
  console.log("%cT007 Toasts attached to window!", "color: darkturquoise");
560
517
  }
561
518
  })();