@t007/dialog 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 isSameURL(src1, src2) {
5
6
  if (typeof src1 !== "string" || typeof src2 !== "string" || !src1 || !src2) return false;
@@ -20,7 +21,7 @@
20
21
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
21
22
  }
22
23
  function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
23
- w.t007 ??= {}, w.t007._resourceCache ??= {};
24
+ w.t007._resourceCache ??= {};
24
25
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
25
26
  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;
26
27
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -60,17 +61,15 @@
60
61
  owner2[method] = owner2[method].bind(owner2);
61
62
  });
62
63
  }
63
- var _SCROLLERS = /* @__PURE__ */ new WeakMap();
64
- var _SCROLLER_R_OBSERVER = typeof window !== "undefined" ? new ResizeObserver((entries) => entries.forEach(({ target }) => _SCROLLERS.get(target)?.update())) : null;
65
- var _SCROLLER_M_OBSERVER = typeof window !== "undefined" ? new MutationObserver((entries) => {
66
- const els = /* @__PURE__ */ new Set();
67
- for (const entry of entries) {
68
- let node = entry.target instanceof Element ? entry.target : null;
69
- while (node && !_SCROLLERS.has(node)) node = node.parentElement;
70
- if (node) els.add(node);
71
- }
72
- for (const el of els) _SCROLLERS.get(el)?.update();
73
- }) : null;
64
+ if (typeof window !== "undefined") {
65
+ window.t007 ??= {};
66
+ window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
67
+ window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
68
+ window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
69
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
70
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
71
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
72
+ }
74
73
 
75
74
  // src/index.js
76
75
  var T007_Dialog = class {
@@ -197,9 +196,6 @@
197
196
  return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
198
197
  }
199
198
  if (typeof window !== "undefined") {
200
- window.t007 ??= {};
201
- window.T007_DIALOG_CSS_SRC ??= `https://unpkg.com/@t007/dialog@latest/style.css`;
202
- window.T007_INPUT_JS_SRC ??= `https://unpkg.com/@t007/input@latest`;
203
199
  t007.alert = alert;
204
200
  t007.confirm = confirm;
205
201
  t007.prompt = prompt;
@@ -209,4 +205,11 @@
209
205
  window.Prompt ??= t007.prompt;
210
206
  console.log("%cT007 Dialogs attached to window!", "color: darkturquoise");
211
207
  }
212
- })();
208
+
209
+ exports.alert = alert;
210
+ exports.confirm = confirm;
211
+ exports.prompt = prompt;
212
+
213
+ return exports;
214
+
215
+ })({});
package/dist/index.js CHANGED
@@ -1,5 +1,74 @@
1
+ // ../utils/dist/index.js
2
+ function isSameURL(src1, src2) {
3
+ if (typeof src1 !== "string" || typeof src2 !== "string" || !src1 || !src2) return false;
4
+ try {
5
+ const u1 = new URL(src1, window.location.href), u2 = new URL(src2, window.location.href);
6
+ return decodeURIComponent(u1.origin + u1.pathname) === decodeURIComponent(u2.origin + u2.pathname);
7
+ } catch {
8
+ return src1.replace(/\\/g, "/").split("?")[0].trim() === src2.replace(/\\/g, "/").split("?")[0].trim();
9
+ }
10
+ }
11
+ function createEl(tag, props = {}, dataset = {}, styles = {}) {
12
+ return assignEl(tag ? document?.createElement(tag) : void 0, props, dataset, styles) ?? null;
13
+ }
14
+ function assignEl(el, props = {}, dataset = {}, styles = {}) {
15
+ if (!el) return;
16
+ for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
17
+ for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
18
+ for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
19
+ }
20
+ function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
21
+ w.t007._resourceCache ??= {};
22
+ if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
23
+ 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;
24
+ if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
25
+ w.t007._resourceCache[src] = new Promise((resolve, reject) => {
26
+ (function tryLoad(remaining, el) {
27
+ const onerror = () => {
28
+ el?.remove?.();
29
+ if (remaining > 1) {
30
+ setTimeout(tryLoad, 1e3, remaining - 1);
31
+ console.warn(`Retrying ${type} load (${attempts - remaining + 1}): ${src}...`);
32
+ } else {
33
+ delete w.t007._resourceCache[src];
34
+ reject(new Error(`${type} load failed after ${attempts} attempts: ${src}`));
35
+ }
36
+ };
37
+ const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
38
+ 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 }) || "");
39
+ 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 }) || "");
40
+ else reject(new Error(`Unsupported resource type: ${type}`));
41
+ })(attempts);
42
+ });
43
+ return w.t007._resourceCache[src];
44
+ }
45
+ function onAllMethods(owner, callback) {
46
+ let proto = owner;
47
+ while (proto && proto !== Object.prototype) {
48
+ for (const method of Object.getOwnPropertyNames(proto)) {
49
+ if (method === "constructor") continue;
50
+ if ("function" !== typeof Object.getOwnPropertyDescriptor(proto, method)?.value) continue;
51
+ callback(method, owner);
52
+ }
53
+ proto = Object.getPrototypeOf(proto);
54
+ }
55
+ }
56
+ function bindAllMethods(owner) {
57
+ onAllMethods(owner, (method, owner2) => {
58
+ owner2[method] = owner2[method].bind(owner2);
59
+ });
60
+ }
61
+ if (typeof window !== "undefined") {
62
+ window.t007 ??= {};
63
+ window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
64
+ window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
65
+ window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
66
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/style.css`;
67
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/style.css`;
68
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/style.css`;
69
+ }
70
+
1
71
  // src/index.js
2
- import { bindAllMethods, createEl, loadResource } from "@t007/utils";
3
72
  var T007_Dialog = class {
4
73
  dialog;
5
74
  confirmBtn;
@@ -124,9 +193,6 @@ function prompt(question, defaultValue, options) {
124
193
  return new Promise((resolve) => new T007_Prompt_Dialog({ question, defaultValue, resolve, options }));
125
194
  }
126
195
  if (typeof window !== "undefined") {
127
- window.t007 ??= {};
128
- window.T007_DIALOG_CSS_SRC ??= `https://unpkg.com/@t007/dialog@latest/style.css`;
129
- window.T007_INPUT_JS_SRC ??= `https://unpkg.com/@t007/input@latest`;
130
196
  t007.alert = alert;
131
197
  t007.confirm = confirm;
132
198
  t007.prompt = prompt;
@@ -136,8 +202,5 @@ if (typeof window !== "undefined") {
136
202
  window.Prompt ??= t007.prompt;
137
203
  console.log("%cT007 Dialogs attached to window!", "color: darkturquoise");
138
204
  }
139
- export {
140
- alert,
141
- confirm,
142
- prompt
143
- };
205
+
206
+ export { alert, confirm, prompt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/dialog",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A lightweight, pure JS dialog 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,14 +31,19 @@
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",
39
43
  "./src/ts/types/index.d.ts",
40
44
  "./src/css/index.css"
41
45
  ],
42
- "keywords": [
46
+ "keywords": [
43
47
  "t007",
44
48
  "dialog",
45
49
  "modal",
@@ -24,11 +24,6 @@ declare global {
24
24
  }
25
25
 
26
26
  interface Window {
27
- t007: T007Namespace;
28
-
29
- T007_DIALOG_CSS_SRC?: string;
30
- T007_INPUT_JS_SRC?: string;
31
-
32
27
  Alert?: T007Namespace["alert"];
33
28
  Confirm?: T007Namespace["confirm"];
34
29
  Prompt?: T007Namespace["prompt"];