@t007/toast 0.0.1 → 0.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.
@@ -1,5 +1,6 @@
1
- "use strict";
2
- (() => {
1
+ (function (exports) {
2
+ 'use strict';
3
+
3
4
  // ../utils/dist/index.js
4
5
  function clamp(min = 0, val, max = Infinity) {
5
6
  return Math.min(Math.max(val, min), max);
@@ -26,7 +27,7 @@
26
27
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
27
28
  }
28
29
  function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
29
- w.t007 ??= {}, w.t007._resourceCache ??= {};
30
+ w.t007._resourceCache ??= {};
30
31
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
31
32
  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;
32
33
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -66,17 +67,15 @@
66
67
  owner2[method] = owner2[method].bind(owner2);
67
68
  });
68
69
  }
69
- var _SCROLLERS = /* @__PURE__ */ new WeakMap();
70
- var _SCROLLER_R_OBSERVER = typeof window !== "undefined" ? new ResizeObserver((entries) => entries.forEach(({ target }) => _SCROLLERS.get(target)?.update())) : null;
71
- var _SCROLLER_M_OBSERVER = typeof window !== "undefined" ? new MutationObserver((entries) => {
72
- const els = /* @__PURE__ */ new Set();
73
- for (const entry of entries) {
74
- let node = entry.target instanceof Element ? entry.target : null;
75
- while (node && !_SCROLLERS.has(node)) node = node.parentElement;
76
- if (node) els.add(node);
77
- }
78
- for (const el of els) _SCROLLERS.get(el)?.update();
79
- }) : null;
70
+ if (typeof window !== "undefined") {
71
+ window.t007 ??= {};
72
+ window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
73
+ window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
74
+ window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
75
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
76
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
77
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
78
+ }
80
79
 
81
80
  // src/index.js
82
81
  var T007_Toast = class {
@@ -470,7 +469,6 @@
470
469
  var toast = toaster();
471
470
  var index_default = toast;
472
471
  if (typeof window !== "undefined") {
473
- window.t007 ??= {};
474
472
  t007.toast = toast;
475
473
  t007.toasting = toasting;
476
474
  t007.toaster = toaster;
@@ -513,9 +511,17 @@
513
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>`;
514
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>`;
515
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>`;
516
- window.T007_TOAST_CSS_SRC ??= `https://unpkg.com/@t007/toast@latest/style.css`;
517
514
  loadResource(T007_TOAST_CSS_SRC);
518
515
  window.Toast ??= t007.toast;
519
516
  console.log("%cT007 Toasts attached to window!", "color: darkturquoise");
520
517
  }
521
- })();
518
+
519
+ exports.default = index_default;
520
+ exports.toaster = toaster;
521
+ exports.toasting = toasting;
522
+
523
+ Object.defineProperty(exports, '__esModule', { value: true });
524
+
525
+ return exports;
526
+
527
+ })({});
package/dist/index.js CHANGED
@@ -1,5 +1,80 @@
1
+ // ../utils/dist/index.js
2
+ function clamp(min = 0, val, max = Infinity) {
3
+ return Math.min(Math.max(val, min), max);
4
+ }
5
+ function uid(prefix = "") {
6
+ return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
7
+ }
8
+ function isSameURL(src1, src2) {
9
+ if (typeof src1 !== "string" || typeof src2 !== "string" || !src1 || !src2) return false;
10
+ try {
11
+ const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
12
+ return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
13
+ } catch {
14
+ return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
15
+ }
16
+ }
17
+ function createEl(tag, props = {}, dataset = {}, styles = {}) {
18
+ return assignEl(tag ? document?.createElement(tag) : void 0, props, dataset, styles) ?? null;
19
+ }
20
+ function assignEl(el, props = {}, dataset = {}, styles = {}) {
21
+ if (!el) return;
22
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
23
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
24
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
25
+ }
26
+ function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
27
+ w.t007._resourceCache ??= {};
28
+ if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
29
+ 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;
30
+ if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
31
+ w.t007._resourceCache[src] = new Promise((resolve, reject) => {
32
+ (function tryLoad(remaining, el) {
33
+ const onerror = () => {
34
+ el?.remove?.();
35
+ if (remaining > 1) {
36
+ setTimeout(tryLoad, 1e3, remaining - 1);
37
+ console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
38
+ } else {
39
+ delete w.t007._resourceCache[src];
40
+ reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
41
+ }
42
+ };
43
+ const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
44
+ 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 }) || "");
45
+ 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 }) || "");
46
+ else reject(new Error(`Unsupported resource type: ${type}`));
47
+ })(attempts);
48
+ });
49
+ return w.t007._resourceCache[src];
50
+ }
51
+ function onAllMethods(owner, callback) {
52
+ let proto = owner;
53
+ while (proto && proto !== Object.prototype) {
54
+ for (const method of Object.getOwnPropertyNames(proto)) {
55
+ if (method === "constructor") continue;
56
+ if ("function" !== typeof Object.getOwnPropertyDescriptor(proto, method)?.value) continue;
57
+ callback(method, owner);
58
+ }
59
+ proto = Object.getPrototypeOf(proto);
60
+ }
61
+ }
62
+ function bindAllMethods(owner) {
63
+ onAllMethods(owner, (method, owner2) => {
64
+ owner2[method] = owner2[method].bind(owner2);
65
+ });
66
+ }
67
+ if (typeof window !== "undefined") {
68
+ window.t007 ??= {};
69
+ window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
70
+ window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
71
+ window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
72
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
73
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
74
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
75
+ }
76
+
1
77
  // src/index.js
2
- import { clamp, uid, bindAllMethods, createEl, loadResource } from "@t007/utils";
3
78
  var T007_Toast = class {
4
79
  #autoCloseInterval;
5
80
  #progressInterval;
@@ -391,7 +466,6 @@ var toaster = (defOptions = {}, idPrefix = "t007_toast_") => {
391
466
  var toast = toaster();
392
467
  var index_default = toast;
393
468
  if (typeof window !== "undefined") {
394
- window.t007 ??= {};
395
469
  t007.toast = toast;
396
470
  t007.toasting = toasting;
397
471
  t007.toaster = toaster;
@@ -434,13 +508,9 @@ if (typeof window !== "undefined") {
434
508
  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>`;
435
509
  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>`;
436
510
  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>`;
437
- window.T007_TOAST_CSS_SRC ??= `https://unpkg.com/@t007/toast@latest/style.css`;
438
511
  loadResource(T007_TOAST_CSS_SRC);
439
512
  window.Toast ??= t007.toast;
440
513
  console.log("%cT007 Toasts attached to window!", "color: darkturquoise");
441
514
  }
442
- export {
443
- index_default as default,
444
- toaster,
445
- toasting
446
- };
515
+
516
+ export { index_default as default, toaster, toasting };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/toast",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A lightweight, pure JS toast system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -17,7 +17,6 @@
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.js",
19
19
  "browser": "./dist/index.global.js",
20
- "unpkg": "./dist/index.global.js",
21
20
  "types": "./src/ts/types/index.d.ts",
22
21
  "style": "./src/css/index.css",
23
22
  "sideEffects": [
@@ -32,7 +31,12 @@
32
31
  "./style.css": "./src/css/index.css"
33
32
  },
34
33
  "scripts": {
35
- "build": "tsup src/index.js --format esm,iife --clean"
34
+ "build": "tsup src/index.js --format esm,iife --clean --treeshake"
35
+ },
36
+ "tsup": {
37
+ "noExternal": [
38
+ "@t007/utils"
39
+ ]
36
40
  },
37
41
  "files": [
38
42
  "dist",
@@ -139,9 +139,6 @@ declare global {
139
139
  }
140
140
 
141
141
  interface Window {
142
- T007_TOAST_CSS_SRC?: string;
143
- T007_TOAST_JS_SRC?: string;
144
-
145
142
  Toast?: Toast;
146
143
  }
147
144
  }