@t007/toast 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ export interface ToastOptions {
71
71
  onClose?: (timeElapsed?: boolean | false) => void;
72
72
  /** Callback fired as the toast auto-close timer advances. */
73
73
  onTimeUpdate?: (timeVisible: number) => void;
74
- [key: string]: any; // To allow arbitrary overrides internally if needed
74
+ // [key: string]: any; // To allow arbitrary overrides internally if needed
75
75
  }
76
76
 
77
77
  /** Live toast instance returned by the runtime. */
@@ -1,28 +1,11 @@
1
1
  "use strict";
2
2
  (() => {
3
- // ../../../sia-reactor/dist/chunk-IBAPWB27.js
3
+ // ../../../sia-reactor/dist/chunk-JGEI2Q4M.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
- // ../../../sia-reactor/dist/chunk-RI45W4O6.js
9
- function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
10
- return assignEl(el, props, dataset, styles), el;
11
- }
12
- function assignEl(el, props, dataset, styles) {
13
- if (!el) return;
14
- if (props) {
15
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
16
- }
17
- if (dataset) {
18
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
19
- }
20
- if (styles) {
21
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
22
- }
23
- }
24
-
25
- // ../../../sia-reactor/dist/chunk-3OT72G7R.js
8
+ // ../../../sia-reactor/dist/chunk-243U74PP.js
26
9
  function onAllMethods(owner, callback, skipOwn = true, nested = false) {
27
10
  let proto = owner;
28
11
  while (proto && proto !== Object.prototype) {
@@ -39,53 +22,82 @@
39
22
  owner2[method] = owner2[method].bind(owner2);
40
23
  });
41
24
  }
25
+ function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
26
+ return assignEl(el, props, dataset, styles);
27
+ }
28
+ function assignEl(el, props, dataset, styles) {
29
+ if (!el) return null;
30
+ if (props) {
31
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
32
+ }
33
+ if (dataset) {
34
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
35
+ }
36
+ if (styles) {
37
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
38
+ }
39
+ return el;
40
+ }
42
41
 
43
- // ../../../sia-reactor/dist/chunk-4PLMBUCP.js
42
+ // ../../../sia-reactor/dist/chunk-2ZYYYSZ4.js
43
+ var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
44
+ var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
45
+ var NIL = Object.freeze({});
44
46
  var CTX = {
45
47
  /** Flag indicating whether the application is running in development mode. */
46
48
  isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
47
- /** Flag indicating whether a cascade is currently ongoing so reactors can allow all writes. */
48
- isCascading: false,
49
+ /** Flag indicating whether an operation is bypassing checks so reactors can allow all writes. */
50
+ usingForce: false,
49
51
  /** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
50
- autotracker: null
52
+ autotracker: null,
53
+ /** Extensible meta context for payloads and cross-cutting concerns. */
54
+ meta: null,
55
+ /** Default configuration for new `Reactor` instances and also fallback for utils that need and are called without these options. */
56
+ defaults: {
57
+ crossRealms: false,
58
+ smartCloning: false,
59
+ eventBubbling: true,
60
+ eventCapturing: "auto",
61
+ lineageTracing: false,
62
+ preserveContext: false,
63
+ equalityFunction: Object.is,
64
+ batchingFunction: RTR_BATCH
65
+ }
51
66
  };
52
- var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
53
- var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
54
- var NIL = Object.freeze({});
55
67
  function isObj(obj, arraycheck = true) {
56
68
  return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
57
69
  }
58
70
 
59
- // ../utils/dist/chunk-4O76EZJ4.js
60
- var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable='true'],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
71
+ // ../utils/dist/chunk-HGUYOV3P.js
72
+ var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
61
73
  var isInteractive = (target) => target instanceof HTMLElement && target.matches(INTERACTIVE_SELECTOR);
62
74
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
63
- function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
64
- w.t007 ??= {}, w.t007._resourceCache ??= {};
75
+ function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, win = window) {
76
+ win.t007 ??= {}, win.t007._resourceCache ??= {};
65
77
  if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
66
78
  const src = req;
67
- if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
68
- 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;
69
- if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
70
- w.t007._resourceCache[src] = new Promise((resolve, reject) => {
79
+ if (win.t007._resourceCache[src]) return win.t007._resourceCache[src];
80
+ const existing = type === "script" ? Array.prototype.find.call(win.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(win.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
81
+ if (existing) return win.t007._resourceCache[src] = Promise.resolve(existing);
82
+ win.t007._resourceCache[src] = new Promise((resolve, reject) => {
71
83
  (function tryLoad(remaining, el) {
72
84
  const onerror = () => {
73
85
  el?.remove?.();
74
86
  if (remaining > 1) {
75
87
  setTimeout(tryLoad, 1e3, remaining - 1);
76
- console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
88
+ console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
77
89
  } else {
78
- delete w.t007._resourceCache[src];
79
- reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
90
+ delete win.t007._resourceCache[src];
91
+ reject(new Error(`${capitalize(type)} load failed for "${src}" after ${attempts - 1} attempts`));
80
92
  }
81
93
  };
82
94
  const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
83
- 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 }) || "");
84
- 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 }) || "");
95
+ if (type === "script") win.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
96
+ else if (type === "style") win.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
85
97
  else reject(new Error(`Unsupported resource type: ${type}`));
86
98
  })(attempts);
87
99
  });
88
- return w.t007._resourceCache[src];
100
+ return win.t007._resourceCache[src];
89
101
  }
90
102
  function isDef(val) {
91
103
  return "undefined" !== typeof val;
@@ -105,6 +117,9 @@
105
117
  function uid(prefix = "") {
106
118
  return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
107
119
  }
120
+ function capitalize(word = "") {
121
+ return word.replace(/^(\s*)([a-z])/i, (_, s, l) => s + l.toUpperCase());
122
+ }
108
123
  function cleanURL(url) {
109
124
  try {
110
125
  const u = new URL(url, window.location.href);
@@ -114,6 +129,7 @@
114
129
  }
115
130
  }
116
131
  function isSameURL(url1, url2) {
132
+ if (url1 === url2) return true;
117
133
  if (!isStr(url1) || !isStr(url2) || !url1 || !url2) return false;
118
134
  return cleanURL(url1) === cleanURL(url2);
119
135
  }
@@ -358,6 +374,8 @@
358
374
  e.preventDefault();
359
375
  if (this._ptrTicker) return;
360
376
  this._ptrRAF = requestAnimationFrame(() => {
377
+ const selection = window.getSelection();
378
+ if (selection?.toString().length && this.toastElement.contains(selection.anchorNode)) return this._handleToastPointerUp(e);
361
379
  const has = (str) => this.opts.dragToCloseDir.includes(str), x = e.clientX ?? e.targetTouches[0]?.clientX, y = e.clientY ?? e.targetTouches[0]?.clientY;
362
380
  this._ptrDir ||= Math.abs(x - this._ptrStartX) >= Math.abs(y - this._ptrStartY) ? "x" : "y";
363
381
  this._ptrDeltaX = (has("|") ? this._ptrDir == "x" : has("x")) && !has(x - this._ptrStartX > 0 ? "-" : "+") ? x - this._ptrStartX : 0;
@@ -401,8 +419,8 @@
401
419
  if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
402
420
  }
403
421
  _cleanUpToast() {
404
- const container = this.toastElement.parentElement;
405
- this.toastElement.remove();
422
+ const container = this.toastElement?.parentElement;
423
+ this.toastElement?.remove();
406
424
  if (!container?.hasChildNodes()) container?.remove();
407
425
  this.inactive = true;
408
426
  }
@@ -436,16 +454,16 @@
436
454
  (response) => {
437
455
  const successConfig = NFC(success || "Promise resolved", "success");
438
456
  const { render, bodyHTML } = successConfig;
439
- if (isFunc(render)) successConfig.render = (response2) => render(response2);
440
- if (isFunc(bodyHTML)) successConfig.bodyHTML = (response2) => bodyHTML(response2);
457
+ if (isFunc(render)) successConfig.render = (txt = response) => render(txt);
458
+ if (isFunc(bodyHTML)) successConfig.bodyHTML = (txt = response) => bodyHTML(txt);
441
459
  base.success(pendingId, successConfig);
442
460
  return response;
443
461
  },
444
462
  (err) => {
445
463
  const errorConfig = NFC(error || "Promise rejected", "error");
446
464
  const { render, bodyHTML } = errorConfig;
447
- if (isFunc(render)) errorConfig.render = (err2) => render(err2);
448
- if (isFunc(bodyHTML)) errorConfig.bodyHTML = (err2) => bodyHTML(err2);
465
+ if (isFunc(render)) errorConfig.render = (txt = err) => render(txt);
466
+ if (isFunc(bodyHTML)) errorConfig.bodyHTML = (txt = err) => bodyHTML(txt);
449
467
  base.error(pendingId, errorConfig);
450
468
  return Promise.reject(err);
451
469
  }
package/dist/index.js CHANGED
@@ -230,6 +230,8 @@ var T007_Toast = class {
230
230
  e.preventDefault();
231
231
  if (this._ptrTicker) return;
232
232
  this._ptrRAF = requestAnimationFrame(() => {
233
+ const selection = window.getSelection();
234
+ if (selection?.toString().length && this.toastElement.contains(selection.anchorNode)) return this._handleToastPointerUp(e);
233
235
  const has = (str) => this.opts.dragToCloseDir.includes(str), x = e.clientX ?? e.targetTouches[0]?.clientX, y = e.clientY ?? e.targetTouches[0]?.clientY;
234
236
  this._ptrDir ||= Math.abs(x - this._ptrStartX) >= Math.abs(y - this._ptrStartY) ? "x" : "y";
235
237
  this._ptrDeltaX = (has("|") ? this._ptrDir == "x" : has("x")) && !has(x - this._ptrStartX > 0 ? "-" : "+") ? x - this._ptrStartX : 0;
@@ -273,8 +275,8 @@ var T007_Toast = class {
273
275
  if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
274
276
  }
275
277
  _cleanUpToast() {
276
- const container = this.toastElement.parentElement;
277
- this.toastElement.remove();
278
+ const container = this.toastElement?.parentElement;
279
+ this.toastElement?.remove();
278
280
  if (!container?.hasChildNodes()) container?.remove();
279
281
  this.inactive = true;
280
282
  }
@@ -308,16 +310,16 @@ var toasting = {
308
310
  (response) => {
309
311
  const successConfig = NFC(success || "Promise resolved", "success");
310
312
  const { render, bodyHTML } = successConfig;
311
- if (isFunc(render)) successConfig.render = (response2) => render(response2);
312
- if (isFunc(bodyHTML)) successConfig.bodyHTML = (response2) => bodyHTML(response2);
313
+ if (isFunc(render)) successConfig.render = (txt = response) => render(txt);
314
+ if (isFunc(bodyHTML)) successConfig.bodyHTML = (txt = response) => bodyHTML(txt);
313
315
  base.success(pendingId, successConfig);
314
316
  return response;
315
317
  },
316
318
  (err) => {
317
319
  const errorConfig = NFC(error || "Promise rejected", "error");
318
320
  const { render, bodyHTML } = errorConfig;
319
- if (isFunc(render)) errorConfig.render = (err2) => render(err2);
320
- if (isFunc(bodyHTML)) errorConfig.bodyHTML = (err2) => bodyHTML(err2);
321
+ if (isFunc(render)) errorConfig.render = (txt = err) => render(txt);
322
+ if (isFunc(bodyHTML)) errorConfig.bodyHTML = (txt = err) => bodyHTML(txt);
321
323
  base.error(pendingId, errorConfig);
322
324
  return Promise.reject(err);
323
325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/toast",
3
- "version": "0.0.30",
3
+ "version": "0.0.32",
4
4
  "description": "A lightweight, pure JS toast system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -21,7 +21,8 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "style": "./dist/index.css",
23
23
  "sideEffects": [
24
- "*.css"
24
+ "**/*.css",
25
+ "**/*.scss"
25
26
  ],
26
27
  "exports": {
27
28
  ".": {
@@ -54,7 +55,7 @@
54
55
  "promise"
55
56
  ],
56
57
  "dependencies": {
57
- "@t007/utils": "^0.0.32"
58
+ "@t007/utils": "^0.0.34"
58
59
  },
59
60
  "devDependencies": {
60
61
  "esbuild-sass-plugin": "^3.7.0"