@t007/toast 0.0.12 → 0.0.14

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,24 +1,36 @@
1
1
  "use strict";
2
2
  (() => {
3
- // ../utils/dist/index.js
4
- function isDef(val) {
5
- return "undefined" !== typeof val;
6
- }
7
- function isSym(val) {
8
- return "symbol" === typeof val;
3
+ // ../sia-reactor/dist/chunk-UQIMMJTY.js
4
+ function onAllMethods(owner, callback, skipOwn = true, nested = false) {
5
+ let proto = owner;
6
+ while (proto && proto !== Object.prototype) {
7
+ for (const method of Object.getOwnPropertyNames(proto)) {
8
+ if (method === "constructor") continue;
9
+ if (nested && skipOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
10
+ if ("function" === typeof Object.getOwnPropertyDescriptor(proto, method)?.value) callback(method, owner);
11
+ }
12
+ proto = Object.getPrototypeOf(proto), nested = true;
13
+ }
9
14
  }
10
- function isNum(val) {
11
- return "number" === typeof val;
15
+ function bindAllMethods(owner) {
16
+ onAllMethods(owner, (method, owner2) => {
17
+ owner2[method] = owner2[method].bind(owner2);
18
+ });
12
19
  }
13
- function isStr(val) {
14
- return "string" === typeof val;
20
+ function clamp(min = 0, val, max = Infinity) {
21
+ return Math.min(Math.max(val, min), max);
15
22
  }
23
+
24
+ // ../sia-reactor/dist/chunk-4MJUBEI7.js
25
+ var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
26
+ var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
27
+ var EVT_WARN = console.warn.bind(console, "[S.I.A Event]");
28
+ var NIL = Object.freeze({});
16
29
  function isObj(obj, arraycheck = true) {
17
30
  return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
18
31
  }
19
- function isFunc(val) {
20
- return "function" === typeof val;
21
- }
32
+
33
+ // ../utils/dist/index.js
22
34
  function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
23
35
  return assignEl(el, props, dataset, styles), el;
24
36
  }
@@ -62,8 +74,17 @@
62
74
  });
63
75
  return w.t007._resourceCache[src];
64
76
  }
65
- function clamp(min = 0, val, max = Infinity) {
66
- return Math.min(Math.max(val, min), max);
77
+ function isSym(val) {
78
+ return "symbol" === typeof val;
79
+ }
80
+ function isNum(val) {
81
+ return "number" === typeof val;
82
+ }
83
+ function isStr(val) {
84
+ return "string" === typeof val;
85
+ }
86
+ function isFunc(val) {
87
+ return "function" === typeof val;
67
88
  }
68
89
  function uid(prefix = "") {
69
90
  return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
@@ -77,23 +98,7 @@
77
98
  return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
78
99
  }
79
100
  }
80
- function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
81
- let proto = owner;
82
- while (proto && proto !== Object.prototype) {
83
- for (const method of Object.getOwnPropertyNames(proto)) {
84
- if (method === "constructor") continue;
85
- if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
86
- if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
87
- }
88
- proto = Object.getPrototypeOf(proto), nested = true;
89
- }
90
- }
91
- function bindAllMethods(owner) {
92
- onAllMethods(owner, (method, owner2) => {
93
- owner2[method] = owner2[method].bind(owner2);
94
- });
95
- }
96
- if (isDef(window)) {
101
+ if ("undefined" !== typeof window) {
97
102
  window.t007 ??= {};
98
103
  t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
99
104
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
@@ -495,7 +500,7 @@
495
500
  };
496
501
  var toast = toaster();
497
502
  var index_default = toast;
498
- if (isDef(window)) {
503
+ if ("undefined" !== typeof window) {
499
504
  t007.toast = toast;
500
505
  t007.toasting = toasting;
501
506
  t007.toaster = toaster;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/index.js
2
- import { isDef, isStr, isNum, isObj, isFunc, clamp, uid, bindAllMethods, createEl, loadResource } from "@t007/utils";
2
+ import { isStr, isNum, isObj, isFunc, clamp, uid, bindAllMethods, createEl, loadResource } from "@t007/utils";
3
3
  var T007_Toast = class {
4
4
  #autoCloseInterval;
5
5
  #progressInterval;
@@ -390,7 +390,7 @@ var toaster = (defOptions = {}, idPrefix = "t007_toast_") => {
390
390
  };
391
391
  var toast = toaster();
392
392
  var index_default = toast;
393
- if (isDef(window)) {
393
+ if ("undefined" !== typeof window) {
394
394
  t007.toast = toast;
395
395
  t007.toasting = toasting;
396
396
  t007.toaster = toaster;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/toast",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "A lightweight, pure JS toast system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -29,8 +29,6 @@
29
29
  "import": "./dist/index.js",
30
30
  "default": "./dist/index.js"
31
31
  },
32
- "./standalone": "./dist/standalone.js",
33
- "./global": "./dist/index.global.js",
34
32
  "./style.css": "./dist/index.css"
35
33
  },
36
34
  "publishConfig": {
@@ -55,6 +53,6 @@
55
53
  "promise"
56
54
  ],
57
55
  "dependencies": {
58
- "@t007/utils": "^0.0.15"
56
+ "@t007/utils": "^0.0.16"
59
57
  }
60
58
  }
@@ -1,547 +0,0 @@
1
- // ../utils/dist/index.js
2
- function isDef(val) {
3
- return "undefined" !== typeof val;
4
- }
5
- function isSym(val) {
6
- return "symbol" === typeof val;
7
- }
8
- function isNum(val) {
9
- return "number" === typeof val;
10
- }
11
- function isStr(val) {
12
- return "string" === typeof val;
13
- }
14
- function isObj(obj, arraycheck = true) {
15
- return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
16
- }
17
- function isFunc(val) {
18
- return "function" === typeof val;
19
- }
20
- function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
21
- return assignEl(el, props, dataset, styles), el;
22
- }
23
- function assignEl(el, props, dataset, styles) {
24
- if (!el) return;
25
- if (props) {
26
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
27
- }
28
- if (dataset) {
29
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
30
- }
31
- if (styles) {
32
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
33
- }
34
- }
35
- var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
36
- function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
37
- w.t007 ??= {}, w.t007._resourceCache ??= {};
38
- if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
39
- const src = req;
40
- if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
41
- const existing = type === "script" ? Array.prototype.find.call(w.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(w.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
42
- if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
43
- w.t007._resourceCache[src] = new Promise((resolve, reject) => {
44
- (function tryLoad(remaining, el) {
45
- const onerror = () => {
46
- el?.remove?.();
47
- if (remaining > 1) {
48
- setTimeout(tryLoad, 1e3, remaining - 1);
49
- console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
50
- } else {
51
- delete w.t007._resourceCache[src];
52
- reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
53
- }
54
- };
55
- const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
56
- if (type === "script") w.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
57
- else if (type === "style") w.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
58
- else reject(new Error(`Unsupported resource type: ${type}`));
59
- })(attempts);
60
- });
61
- return w.t007._resourceCache[src];
62
- }
63
- function clamp(min = 0, val, max = Infinity) {
64
- return Math.min(Math.max(val, min), max);
65
- }
66
- function uid(prefix = "") {
67
- return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
68
- }
69
- function isSameURL(src1, src2) {
70
- if (!isStr(src1) || !isStr(src2) || !src1 || !src2) return false;
71
- try {
72
- const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
73
- return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
74
- } catch {
75
- return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
76
- }
77
- }
78
- function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
79
- let proto = owner;
80
- while (proto && proto !== Object.prototype) {
81
- for (const method of Object.getOwnPropertyNames(proto)) {
82
- if (method === "constructor") continue;
83
- if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
84
- if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
85
- }
86
- proto = Object.getPrototypeOf(proto), nested = true;
87
- }
88
- }
89
- function bindAllMethods(owner) {
90
- onAllMethods(owner, (method, owner2) => {
91
- owner2[method] = owner2[method].bind(owner2);
92
- });
93
- }
94
- if (isDef(window)) {
95
- window.t007 ??= {};
96
- t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
97
- window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
98
- window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
99
- window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
100
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
101
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
102
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
103
- }
104
-
105
- // src/index.js
106
- var T007_Toast = class {
107
- #autoCloseInterval;
108
- #progressInterval;
109
- #timeVisible = 0;
110
- #isPaused = false;
111
- #shouldUnPause;
112
- queue = [];
113
- destroyed = true;
114
- #visiblityChange = () => this.#shouldUnPause = document.visibilityState === "visible";
115
- constructor(options) {
116
- bindAllMethods(this);
117
- this.opts = { ...options };
118
- this.id = this.opts.id ??= uid(this.opts.idPrefix ?? "t007_toast_");
119
- t007.toasts.set(this.id, this);
120
- !isNum(this.opts.delay) ? this.init() : this.queue.push(setTimeout(this.init, this.opts.delay));
121
- this.update(this.opts);
122
- }
123
- init() {
124
- this.toastElement = createEl("div", { className: "t007-toast", id: this.id, ariaAtomic: "true" }, { idPrefix: this.opts.idPrefix });
125
- requestAnimationFrame(() => this.toastElement.classList.add("t007-toast-show"));
126
- this.destroyed = false;
127
- }
128
- update(options) {
129
- if (!options || !isObj(options)) return this.opts.id;
130
- try {
131
- this.opts = { ...this.opts, ...options };
132
- const run = () => Object.keys(options).forEach((key) => this[key] = options[key]);
133
- !isNum(this.opts.delay) ? run() : this.queue.push(setTimeout(run, this.opts.delay));
134
- this.opts.delay = null;
135
- } catch (err) {
136
- console.error("toast update failed:", err);
137
- }
138
- return this.opts.id;
139
- }
140
- play = () => setTimeout(() => this.#isPaused = false);
141
- pause = () => this.#isPaused = true;
142
- set rootElement(value) {
143
- const container = value?.querySelector(`.t007-toast-container[data-position="${this.opts.position}"]`);
144
- container?.style.setProperty("--t007-toast-container-position", value === document.body ? "fixed" : "absolute");
145
- container && !value.contains(container) && value.append(container);
146
- }
147
- set type(value) {
148
- this.toastElement.classList.remove("info", "success", "error", "warning");
149
- value && this.toastElement.classList.add(value);
150
- this.toastElement.role = value === "error" || value === "warning" ? "alert" : "status";
151
- this.toastElement.ariaLive = value === "error" || value === "warning" ? "assertive" : "polite";
152
- if (value) this.icon = this.opts.icon;
153
- }
154
- set bodyHTML(value) {
155
- this.toastElement.querySelectorAll(".t007-toast > *:not(.t007-toast-cancel-button)").forEach((el) => el.remove());
156
- this.toastElement.insertAdjacentHTML("afterbegin", `${value ? isFunc(value) ? value() : value : ""}`);
157
- }
158
- set render(value) {
159
- const bodyText = () => this.toastElement.querySelector(".t007-toast-body-text");
160
- if (value) {
161
- this._setUpBodyHTML();
162
- this.toastElement.querySelector(".t007-toast-body").prepend(bodyText() || createEl("p", { className: "t007-toast-body-text" }));
163
- const text = bodyText();
164
- text.innerHTML = text.dataset.render = isFunc(value) ? value() : value;
165
- } else bodyText()?.remove();
166
- }
167
- set actions(value) {
168
- const actionsWrapper = () => this.toastElement.querySelector(".t007-toast-actions-wrapper"), values = value ? Object.entries(value) : [];
169
- if (values.length) {
170
- this._setUpBodyHTML();
171
- this.toastElement.querySelector(".t007-toast-body").insertAdjacentElement("afterend", actionsWrapper() || createEl("div", { className: "t007-toast-actions-wrapper" }));
172
- const wrapper = actionsWrapper();
173
- wrapper.innerHTML = values.map(([label]) => label ? `<button class="t007-toast-action-button" data-action="${label}">${label}</button>` : "").join("");
174
- wrapper.querySelectorAll(".t007-toast-action-button").forEach((btn, i) => btn.onclick = (e) => values[i][1]?.(e, this));
175
- } else actionsWrapper()?.remove();
176
- }
177
- set image(value) {
178
- const image = () => this.toastElement.querySelector(".t007-toast-image");
179
- if (value) {
180
- this._setUpBodyHTML();
181
- this.toastElement.querySelector(".t007-toast-image-wrapper").prepend(
182
- image() || createEl("img", {
183
- className: "t007-toast-image",
184
- alt: "toast-image"
185
- })
186
- );
187
- const img = image();
188
- img.src = value;
189
- img.onload = img.onerror = () => img.dataset.loaded = img.complete && img.naturalWidth > 0;
190
- } else image()?.remove();
191
- }
192
- get icon() {
193
- return this.opts.icon === true ? t007.TOAST_ICONS[this.opts.type] || "" : this.opts.icon || "";
194
- }
195
- set icon(value) {
196
- if (this.opts.isLoading) return;
197
- const icon = () => this.toastElement.querySelector(".t007-toast-icon:not(.t007-toast-loader)");
198
- if (value) {
199
- this._setUpBodyHTML();
200
- this.toastElement.querySelector(".t007-toast-image-wrapper").appendChild(icon() || createEl("span", { className: "t007-toast-icon" }));
201
- const icn = icon();
202
- icn.innerHTML = icn.dataset.icon = this.icon;
203
- } else icon()?.remove();
204
- }
205
- set isLoading(value) {
206
- const loader = () => this.toastElement.querySelector(".t007-toast-loader");
207
- if (value) {
208
- this._setUpBodyHTML();
209
- this.toastElement.querySelectorAll(".t007-toast-icon:not(.t007-toast-loader)").forEach((i) => i.remove());
210
- this.toastElement.querySelector(".t007-toast-image-wrapper").appendChild(
211
- loader() || createEl("span", {
212
- className: "t007-toast-icon t007-toast-loader"
213
- })
214
- );
215
- loader().innerHTML = isStr(value) ? value : t007.TOAST_ICONS.loading;
216
- } else {
217
- loader()?.remove();
218
- this.icon = this.opts.icon;
219
- }
220
- }
221
- set closeButton(value) {
222
- const btn = this.toastElement.querySelector(".t007-toast-cancel-button");
223
- if (value)
224
- this.toastElement.appendChild(
225
- btn || createEl("button", {
226
- title: "Close",
227
- ariaLabel: "Close notification",
228
- className: "t007-toast-cancel-button",
229
- innerHTML: "&times;",
230
- onclick: this._remove
231
- })
232
- );
233
- else btn?.remove();
234
- }
235
- get animation() {
236
- if (this.opts.animation === true || this.opts.animation === "slide")
237
- switch (this.opts.position) {
238
- case "top-right":
239
- case "center-right":
240
- case "bottom-right":
241
- return "slide-left";
242
- case "top-center":
243
- case "center-center":
244
- case "bottom-center":
245
- return this.opts.position === "top-center" ? "slide-down" : "slide-up";
246
- case "top-left":
247
- case "center-left":
248
- case "bottom-left":
249
- default:
250
- return "slide-right";
251
- }
252
- return this.opts.animation;
253
- }
254
- set animation(value) {
255
- this.toastElement.dataset.animation = this.animation;
256
- }
257
- get autoClose() {
258
- return this.opts.autoClose === true ? t007.TOAST_DURATIONS[this.opts.type] || t007.TOAST_DURATIONS.info : this.opts.autoClose;
259
- }
260
- set autoClose(value) {
261
- cancelAnimationFrame(this.#autoCloseInterval);
262
- this.#timeVisible = 0;
263
- let lastTime;
264
- const loop = (time) => {
265
- if (this.#shouldUnPause) {
266
- lastTime = null;
267
- this.#shouldUnPause = false;
268
- }
269
- if (lastTime == null) {
270
- lastTime = time;
271
- return this.#autoCloseInterval = requestAnimationFrame(loop);
272
- }
273
- if (!this.#isPaused) {
274
- this.#timeVisible += time - lastTime;
275
- this.onTimeUpdate?.(this.#timeVisible);
276
- if (isNum(this.autoClose) && this.#timeVisible >= this.autoClose) return this._remove("smooth", true);
277
- }
278
- lastTime = time;
279
- this.#autoCloseInterval = requestAnimationFrame(loop);
280
- };
281
- if (value) this.#autoCloseInterval = requestAnimationFrame(loop);
282
- }
283
- set position(value) {
284
- const currentContainer = this.toastElement.parentElement;
285
- const container = this.opts.rootElement?.querySelector(`.t007-toast-container[data-position="${value}"]`) || this._createContainer(value);
286
- container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
287
- if (!(currentContainer == null || currentContainer.hasChildNodes())) currentContainer.remove();
288
- }
289
- set closeOnClick(value) {
290
- this.toastElement.onclick = value ? () => this._remove() : null;
291
- }
292
- set hideProgressBar(value) {
293
- this.toastElement.classList.toggle("progress", !value);
294
- this.nprogress = 0;
295
- cancelAnimationFrame(this.#progressInterval);
296
- const loop = () => {
297
- if (isNum(this.autoClose) && !this.#isPaused) this.nprogress = 1 - this.#timeVisible / this.autoClose;
298
- this.#progressInterval = requestAnimationFrame(loop);
299
- };
300
- if (!value) this.#progressInterval = requestAnimationFrame(loop);
301
- }
302
- get nprogress() {
303
- return Number(this.toastElement.style.getProperty("--progress"));
304
- }
305
- set nprogress(value) {
306
- this.toastElement.style.setProperty("--progress", value);
307
- }
308
- set pauseOnHover(value) {
309
- this.toastElement.onmouseover = value ? this.pause : null;
310
- this.toastElement.onmouseleave = value ? this.play : null;
311
- this.toastElement[value ? "addEventListener" : "removeEventListener"]("touchend", this.play);
312
- }
313
- set pauseOnFocusLoss(value) {
314
- value ? document.addEventListener("visibilitychange", this.#visiblityChange) : document.removeEventListener("visibilitychange", this.#visiblityChange);
315
- }
316
- set tag(value) {
317
- this.toastElement.dataset.tag = value;
318
- }
319
- set renotify(value) {
320
- value && this.opts.tag && t007.toasts.entries().forEach(([id, toast2]) => id !== this.id && (toast2.opts.tag ?? 1) === (this.opts.tag ?? 0) && toast2._remove("instant"));
321
- }
322
- get vibrate() {
323
- return this.opts.vibrate === true ? t007.TOAST_VIBRATIONS[this.opts.type] || t007.TOAST_VIBRATIONS.info : this.opts.vibrate;
324
- }
325
- set vibrate(value) {
326
- value && navigator?.vibrate?.(this.vibrate);
327
- }
328
- set maxToasts(value) {
329
- const toastsInContainer = [...this.toastElement?.parentElement?.children || []];
330
- if (!toastsInContainer.length) return;
331
- for (let i = 0; i < toastsInContainer.length - value; i++) {
332
- [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?._remove("instant");
333
- }
334
- }
335
- set newestOnTop(value) {
336
- this.toastElement?.parentElement?.[value ? "prepend" : "append"](this.toastElement);
337
- }
338
- set dragToClose(value) {
339
- this.toastElement.dataset.dragToClose = this._ptrType = value;
340
- this.toastElement.onpointerdown = value ? this._handleToastPointerStart : null;
341
- this.toastElement.onpointerup = value ? this._handleToastPointerUp : null;
342
- }
343
- _handleToastPointerStart(e) {
344
- if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
345
- if (e.touches?.length > 1) return;
346
- !e.target?.matches('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])') && this.toastElement.setPointerCapture(e.pointerId);
347
- this.#isPaused = true;
348
- this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
349
- this._ptrStartX = e.clientX ?? e.targetTouches[0]?.clientX;
350
- this._ptrStartY = e.clientY ?? e.targetTouches[0]?.clientY;
351
- this.toastElement.addEventListener("pointermove", this._handleToastPointerMove, { passive: false });
352
- this.toastElement.style.setProperty("transition", "none", "important");
353
- }
354
- _handleToastPointerMove(e) {
355
- e.preventDefault();
356
- if (this._ptrTicker) return;
357
- this._ptrRAF = requestAnimationFrame(() => {
358
- const has = (str) => this.opts.dragToCloseDir.includes(str), x = e.clientX ?? e.targetTouches[0]?.clientX, y = e.clientY ?? e.targetTouches[0]?.clientY;
359
- this._ptrDir ||= Math.abs(x - this._ptrStartX) >= Math.abs(y - this._ptrStartY) ? "x" : "y";
360
- this._ptrDeltaX = (has("|") ? this._ptrDir == "x" : has("x")) && !has(x - this._ptrStartX > 0 ? "-" : "+") ? x - this._ptrStartX : 0;
361
- this._ptrDeltaY = (has("|") ? this._ptrDir == "y" : has("y")) && !has(y - this._ptrStartY > 0 ? "+" : "-") ? y - this._ptrStartY : 0;
362
- this.toastElement.style.setProperty("transform", `translate(${this._ptrDeltaX}px, ${this._ptrDeltaY}px)`, "important");
363
- const xR = Math.abs(this._ptrDeltaX) / this.toastElement.offsetWidth, yR = Math.abs(this._ptrDeltaY) / this.toastElement.offsetHeight;
364
- this.toastElement.style.setProperty("opacity", clamp(0, 1 - (yR > 0.5 ? yR : xR), 1), "important");
365
- if (!this._ptrDirSet && !xR && !yR) this._ptrDir = false;
366
- if (this._ptrDir) this._ptrDirSet = has("||");
367
- this._ptrTicker = false;
368
- });
369
- this._ptrTicker = true;
370
- }
371
- _handleToastPointerUp(e) {
372
- if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
373
- cancelAnimationFrame(this._ptrRAF);
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");
375
- this.#isPaused = this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
376
- this.toastElement.removeEventListener("pointermove", this._handleToastPointerMove, { passive: false });
377
- this.toastElement.style.removeProperty("transition");
378
- this.toastElement.style.removeProperty("transform");
379
- this.toastElement.style.removeProperty("opacity");
380
- }
381
- _remove(manner = "smooth", timeElapsed = false) {
382
- if (!this.opts.isLoading) t007.toasts.delete(this.id);
383
- this.queue.forEach(clearTimeout);
384
- document.removeEventListener("visibilitychange", this.#visiblityChange);
385
- cancelAnimationFrame(this.#autoCloseInterval);
386
- cancelAnimationFrame(this.#progressInterval);
387
- if (this.destroyed || manner === "instant" || !this.animation) this._cleanUpToast();
388
- else this.toastElement.onanimationend = this._cleanUpToast;
389
- this.toastElement.classList.remove("t007-toast-show");
390
- this.onClose?.(timeElapsed);
391
- }
392
- _createContainer(position) {
393
- const container = document.createElement("div");
394
- container.classList.add("t007-toast-container");
395
- container.style.setProperty("--t007-toast-container-position", this.opts.rootElement === document.body ? "fixed" : "absolute");
396
- container.dataset.position = position;
397
- this.opts.rootElement?.append(container);
398
- return container;
399
- }
400
- _setUpBodyHTML() {
401
- 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());
402
- const imageWrapper = () => this.toastElement.querySelector(".t007-toast-image-wrapper");
403
- if (!imageWrapper()) this.toastElement.prepend(createEl("div", { className: "t007-toast-image-wrapper" }));
404
- if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
405
- }
406
- _cleanUpToast() {
407
- const container = this.toastElement.parentElement;
408
- this.toastElement.remove();
409
- if (!container?.hasChildNodes()) container?.remove();
410
- this.destroyed = true;
411
- }
412
- };
413
- var toasting = {
414
- update(base, id, options) {
415
- const toast2 = t007.toasts.get(id);
416
- toast2?.queue.forEach(clearTimeout);
417
- return !!toast2 && (toast2.destroyed ? base(options.render, { ...toast2.opts, id, ...options }) : toast2.update(options));
418
- },
419
- message: (base, defaults, action) => base[action] = (renderOrId, options = {}) => {
420
- options = { ...options, type: action === "warn" ? "warning" : action };
421
- if (!t007.toasts.get(renderOrId)) return base(renderOrId, options);
422
- const { autoClose, closeButton, closeOnClick, dragToClose } = defaults();
423
- return base.update(renderOrId, {
424
- ...t007.toasts.get(renderOrId)?.opts.isLoading ? { autoClose, closeButton, closeOnClick, dragToClose } : {},
425
- ...options,
426
- isLoading: false
427
- });
428
- },
429
- loading: (base, renderOrId, options = {}) => (t007.toasts.get(renderOrId) ? base.update : base)(renderOrId, {
430
- autoClose: false,
431
- closeButton: false,
432
- closeOnClick: false,
433
- dragToClose: false,
434
- ...options,
435
- isLoading: options.isLoading || true,
436
- type: ""
437
- }),
438
- promise(base, promise = new Promise((res, rej) => setTimeout(Math.round(Math.random()) ? res : rej, 3e3)), { pending, success, error } = {}) {
439
- if (!promise || !isFunc(promise.then)) return console.error("toast.promise() requires a valid promise");
440
- const NFC = (input, type) => isStr(input) ? { render: input, type } : isObj(input) ? { ...input, type } : { type };
441
- const pendingConfig = NFC(pending);
442
- const pendingToastId = base.loading(pendingConfig.render || "Promise pending...", { ...pendingConfig });
443
- promise.then(
444
- (response) => {
445
- const successConfig = NFC(success || "Promise resolved", "success");
446
- const { render, bodyHTML } = successConfig;
447
- if (isFunc(render)) successConfig.render = (response2) => render(response2);
448
- if (isFunc(bodyHTML)) successConfig.bodyHTML = (response2) => bodyHTML(response2);
449
- base.success(pendingToastId, successConfig);
450
- return response;
451
- },
452
- (err) => {
453
- const errorConfig = NFC(error || "Promise rejected", "error");
454
- const { render, bodyHTML } = errorConfig;
455
- if (isFunc(render)) errorConfig.render = (err2) => render(err2);
456
- if (isFunc(bodyHTML)) errorConfig.bodyHTML = (err2) => bodyHTML(err2);
457
- base.error(pendingToastId, errorConfig);
458
- return Promise.reject(err);
459
- }
460
- );
461
- return promise;
462
- },
463
- dismiss(base, id, manner, timeElapsed) {
464
- return !arguments.length ? base.dismissAll() : t007.toasts.get(id)?._remove(manner, timeElapsed);
465
- },
466
- dismissAll(base, idPrefix) {
467
- t007.toasts.values().forEach((toast2) => (!arguments.length ? true : toast2.id.startsWith(idPrefix)) && toast2._remove());
468
- },
469
- doForAll(base, action, options, idPrefix) {
470
- t007.toasts.keys().forEach((id) => (!arguments.length ? true : id.startsWith(idPrefix)) && base[action]?.(id, options));
471
- },
472
- getAll(base, idPrefix) {
473
- return t007.toasts.values().filter((toast2) => !arguments.length ? true : toast2.id.startsWith(idPrefix));
474
- }
475
- };
476
- var toaster = (defOptions = {}, idPrefix = "t007_toast_") => {
477
- const defaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (render, options = {}) => new T007_Toast({
478
- ...defaults(),
479
- ...options,
480
- id: render?.startsWith?.(idPrefix) ? render : options.id,
481
- render: render?.startsWith?.(idPrefix) ? options.render : render,
482
- idPrefix
483
- }).id;
484
- base.update = (id, options) => toasting.update(base, id, options);
485
- ["info", "success", "warn", "error"].forEach((action) => toasting.message(base, defaults, action));
486
- base.loading = (render, options) => toasting.loading(base, render, options);
487
- base.promise = (promise, options) => toasting.promise(base, promise, options);
488
- base.dismiss = (id, manner, timeElapsed) => toasting.dismiss(base, id, manner, timeElapsed);
489
- base.dismissAll = (idPrefix2) => toasting.dismissAll(base, idPrefix2);
490
- base.doForAll = (action, options, idPrefix2) => toasting.doForAll(base, action, options, idPrefix2);
491
- base.getAll = (idPrefix2) => toasting.getAll(base, idPrefix2);
492
- return base;
493
- };
494
- var toast = toaster();
495
- var src_default = toast;
496
- if (isDef(window)) {
497
- t007.toast = toast;
498
- t007.toasting = toasting;
499
- t007.toaster = toaster;
500
- t007.toasts = /* @__PURE__ */ new Map();
501
- t007.TOAST_DEFAULT_OPTIONS ??= {};
502
- t007.TOAST_DURATIONS ??= {};
503
- t007.TOAST_VIBRATIONS ??= {};
504
- t007.TOAST_ICONS ??= {};
505
- t007.TOAST_DEFAULT_OPTIONS.rootElement ??= document.body;
506
- t007.TOAST_DEFAULT_OPTIONS.render ??= "";
507
- t007.TOAST_DEFAULT_OPTIONS.type ??= "";
508
- t007.TOAST_DEFAULT_OPTIONS.icon ??= true;
509
- t007.TOAST_DEFAULT_OPTIONS.image ??= false;
510
- t007.TOAST_DEFAULT_OPTIONS.autoClose ??= true;
511
- t007.TOAST_DEFAULT_OPTIONS.position ??= "top-right";
512
- t007.TOAST_DEFAULT_OPTIONS.isLoading ??= false;
513
- t007.TOAST_DEFAULT_OPTIONS.closeButton ??= !/Mobi|Android|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
514
- t007.TOAST_DEFAULT_OPTIONS.closeOnClick ??= false;
515
- t007.TOAST_DEFAULT_OPTIONS.hideProgressBar ??= false;
516
- t007.TOAST_DEFAULT_OPTIONS.pauseOnHover ??= true;
517
- t007.TOAST_DEFAULT_OPTIONS.pauseOnFocusLoss ??= true;
518
- t007.TOAST_DEFAULT_OPTIONS.dragToClose ??= true;
519
- t007.TOAST_DEFAULT_OPTIONS.dragToClosePercent ??= 40;
520
- t007.TOAST_DEFAULT_OPTIONS.dragToCloseDir ??= "x";
521
- t007.TOAST_DEFAULT_OPTIONS.renotify ??= true;
522
- t007.TOAST_DEFAULT_OPTIONS.vibrate ??= false;
523
- t007.TOAST_DEFAULT_OPTIONS.animation ??= true;
524
- t007.TOAST_DEFAULT_OPTIONS.newestOnTop ??= false;
525
- t007.TOAST_DEFAULT_OPTIONS.maxToasts ??= 1e3;
526
- t007.TOAST_DURATIONS.success ??= 2500;
527
- t007.TOAST_DURATIONS.error ??= 4500;
528
- t007.TOAST_DURATIONS.warning ??= 3500;
529
- t007.TOAST_DURATIONS.info ??= 4e3;
530
- t007.TOAST_VIBRATIONS.success ??= [100, 50, 100];
531
- t007.TOAST_VIBRATIONS.warning ??= [300, 100, 300];
532
- t007.TOAST_VIBRATIONS.error ??= [500, 200, 500];
533
- t007.TOAST_VIBRATIONS.info ??= [200];
534
- 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>`;
535
- 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>`;
536
- 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>`;
537
- 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>`;
538
- 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>`;
539
- loadResource(T007_TOAST_CSS_SRC);
540
- window.Toast ??= t007.toast;
541
- console.log("%cT007 Toasts attached to window!", "color: darkturquoise");
542
- }
543
- export {
544
- src_default as default,
545
- toaster,
546
- toasting
547
- };