@t007/utils 0.0.5 → 0.0.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OLUWATOBILOBA OKETADE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # @t007/utils
2
+
3
+ > The foundational utility belt and central nervous system for the `@t007` UI ecosystem. A collection of highly optimized, zero-dependency vanilla JavaScript helpers for DOM manipulation, async resource loading, and math operations.
4
+
5
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Tobi007-del/t007-tools/blob/main/LICENSE)
6
+ [![NPM Version](https://img.shields.io/npm/v/@t007/utils.svg)](https://www.npmjs.com/package/@t007/utils)
7
+
8
+ [Report Bug](https://github.com/Tobi007-del/t007-tools/issues)
9
+
10
+ ---
11
+
12
+ ## Table of contents
13
+
14
+ - [@t007/utils](#t007utils)
15
+ - [Table of contents](#table-of-contents)
16
+ - [Overview](#overview)
17
+ - [Features](#features)
18
+ - [Tech Stack](#tech-stack)
19
+ - [Getting Started](#getting-started)
20
+ - [Usage](#usage)
21
+ - [Author](#author)
22
+ - [Acknowledgments](#acknowledgments)
23
+
24
+ ---
25
+
26
+ ## Overview
27
+
28
+ **@t007/utils** is the core engine that powers the rest of the `@t007` UI packages (`@t007/toast`, `@t007/dialog`, `@t007/input`). It abstracts away the heavy lifting of dynamic DOM creation, cross-browser event handling, and asynchronous resource injection.
29
+
30
+ ### Why @t007/utils?
31
+
32
+ - ✅ **Tree-Shakeable:** Every utility is exported individually. Modern bundlers will only compile the exact code you import, resulting in zero bloat.
33
+ - ✅ **Shared Memory:** By acting as a peer dependency for the other `@t007` packages, it ensures that your application doesn't download duplicate helper functions.
34
+ - ✅ **Zero Frameworks:** 100% pure vanilla JavaScript.
35
+
36
+ ---
37
+
38
+ ## Features
39
+
40
+ - **DOM Engineering**: High-performance element creation and attribute binding.
41
+ - **Resource Management**: Asynchronous script and stylesheet injection with duplicate-load prevention.
42
+ - **Class Management**: Automatic method binding for class-based UI components.
43
+ - **Math & Physics**: Clamping and coordinate tracking used by gesture-driven UI components.
44
+ - **Global Injection**: Safely initializes the global `t007` object across environments.
45
+
46
+ ---
47
+
48
+ ## Tech Stack
49
+
50
+ ### Built with
51
+
52
+ - Vanilla JavaScript (ES6+)
53
+ - Bundled via `tsup` (ESM, CJS, IIFE outputs)
54
+ - Built for extreme execution speed and minimal byte size.
55
+
56
+ ---
57
+
58
+ ## Getting Started
59
+
60
+ ### Installation
61
+
62
+ Install via your preferred package manager:
63
+
64
+ ```bash
65
+ npm install @t007/utils
66
+ # or
67
+ yarn add @t007/utils
68
+ # or
69
+ pnpm add @t007/utils
70
+ ````
71
+
72
+ -----
73
+
74
+ ## Usage
75
+
76
+ ### Modern Bundlers (ESM)
77
+
78
+ Because the library uses modern ECMAScript Modules, you can destruct exactly what you need.
79
+
80
+ ```javascript
81
+ // Vite / Webpack / Next.js
82
+ import { createEl, loadResource, uid } from '@t007/utils';
83
+
84
+ // Generate a complex DOM element in one line
85
+ const myBtn = createEl('button', { className: 'my-custom-btn', textContent: 'Click Me' });
86
+
87
+ // Inject a stylesheet dynamically
88
+ await loadResource('https://cdn.example.com/styles.css, 'link');
89
+ ```
90
+
91
+ -----
92
+
93
+ ## Author
94
+
95
+ - Developer - [Oketade Oluwatobiloba (Tobi007-del)](https://github.com/Tobi007-del)
96
+ - Project - [t007-tools](https://github.com/Tobi007-del/t007-tools)
97
+
98
+ ## Acknowledgments
99
+
100
+ The invisible backbone of the `@t007` ecosystem. Engineered to make complex DOM operations feel effortless.
package/dist/index.cjs CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ VIRTUAL_RESOURCE: () => VIRTUAL_RESOURCE,
23
24
  assignEl: () => assignEl,
24
25
  bindAllMethods: () => bindAllMethods,
25
26
  clamp: () => clamp,
@@ -36,11 +37,6 @@ __export(index_exports, {
36
37
  });
37
38
  module.exports = __toCommonJS(index_exports);
38
39
 
39
- // src/core/num.ts
40
- function clamp(min = 0, val, max = Infinity) {
41
- return Math.min(Math.max(val, min), max);
42
- }
43
-
44
40
  // src/core/str.ts
45
41
  function uid(prefix = "") {
46
42
  return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
@@ -71,8 +67,11 @@ function assignEl(el, props, dataset, styles) {
71
67
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
72
68
  }
73
69
  }
74
- function loadResource(src, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
75
- w.t007._resourceCache ??= {};
70
+ var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
71
+ function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
72
+ w.t007 ??= {}, w.t007._resourceCache ??= {};
73
+ if (req === VIRTUAL_RESOURCE || "symbol" === typeof req) return Promise.resolve();
74
+ const src = req;
76
75
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
77
76
  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;
78
77
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -97,6 +96,11 @@ function loadResource(src, type = "style", { module: module2, media, crossOrigin
97
96
  return w.t007._resourceCache[src];
98
97
  }
99
98
 
99
+ // src/core/num.ts
100
+ function clamp(min = 0, val, max = Infinity) {
101
+ return Math.min(Math.max(val, min), max);
102
+ }
103
+
100
104
  // src/mixins/methodist.ts
101
105
  function onAllMethods(owner, callback) {
102
106
  let proto = owner;
@@ -221,15 +225,17 @@ var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
221
225
  // src/index.ts
222
226
  if (typeof window !== "undefined") {
223
227
  window.t007 ??= {};
228
+ t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
224
229
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
225
230
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
226
231
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
227
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.css`;
228
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.css`;
229
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.css`;
232
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
233
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
234
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
230
235
  }
231
236
  // Annotate the CommonJS export names for ESM import in node:
232
237
  0 && (module.exports = {
238
+ VIRTUAL_RESOURCE,
233
239
  assignEl,
234
240
  bindAllMethods,
235
241
  clamp,
package/dist/index.d.cts CHANGED
@@ -27,6 +27,8 @@ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
27
27
 
28
28
  declare global {
29
29
  interface T007Namespace {
30
+ VIRTUAL_RESOURCE: unique symbol;
31
+
30
32
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
31
33
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
32
34
  _scroller_r_observer?: ResizeObserver;
@@ -71,11 +73,12 @@ declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?:
71
73
  declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
72
74
  declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
73
75
  declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
74
- declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
76
+ declare const VIRTUAL_RESOURCE: unique symbol;
77
+ declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
75
78
 
76
79
  declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
77
80
  declare function bindAllMethods(owner: any): void;
78
81
  declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
79
82
  declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
80
83
 
81
- export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
84
+ export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
package/dist/index.d.ts CHANGED
@@ -27,6 +27,8 @@ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
27
27
 
28
28
  declare global {
29
29
  interface T007Namespace {
30
+ VIRTUAL_RESOURCE: unique symbol;
31
+
30
32
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
31
33
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
32
34
  _scroller_r_observer?: ResizeObserver;
@@ -71,11 +73,12 @@ declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?:
71
73
  declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
72
74
  declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
73
75
  declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
74
- declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
76
+ declare const VIRTUAL_RESOURCE: unique symbol;
77
+ declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
75
78
 
76
79
  declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
77
80
  declare function bindAllMethods(owner: any): void;
78
81
  declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
79
82
  declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
80
83
 
81
- export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
84
+ export { type Dataset, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, clamp, createEl, guardAllMethods, guardMethod, initScrollAssist, initVScrollerator, isSameURL, loadResource, onAllMethods, removeScrollAssist, uid };
package/dist/index.js CHANGED
@@ -1,8 +1,3 @@
1
- // src/core/num.ts
2
- function clamp(min = 0, val, max = Infinity) {
3
- return Math.min(Math.max(val, min), max);
4
- }
5
-
6
1
  // src/core/str.ts
7
2
  function uid(prefix = "") {
8
3
  return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
@@ -33,8 +28,11 @@ function assignEl(el, props, dataset, styles) {
33
28
  for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
34
29
  }
35
30
  }
36
- function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
37
- w.t007._resourceCache ??= {};
31
+ var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
32
+ function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
33
+ w.t007 ??= {}, w.t007._resourceCache ??= {};
34
+ if (req === VIRTUAL_RESOURCE || "symbol" === typeof req) return Promise.resolve();
35
+ const src = req;
38
36
  if (w.t007._resourceCache[src]) return w.t007._resourceCache[src];
39
37
  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;
40
38
  if (existing) return w.t007._resourceCache[src] = Promise.resolve(existing);
@@ -59,6 +57,11 @@ function loadResource(src, type = "style", { module, media, crossOrigin, integri
59
57
  return w.t007._resourceCache[src];
60
58
  }
61
59
 
60
+ // src/core/num.ts
61
+ function clamp(min = 0, val, max = Infinity) {
62
+ return Math.min(Math.max(val, min), max);
63
+ }
64
+
62
65
  // src/mixins/methodist.ts
63
66
  function onAllMethods(owner, callback) {
64
67
  let proto = owner;
@@ -183,14 +186,16 @@ var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
183
186
  // src/index.ts
184
187
  if (typeof window !== "undefined") {
185
188
  window.t007 ??= {};
189
+ t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
186
190
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
187
191
  window.T007_INPUT_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest`;
188
192
  window.T007_DIALOG_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest`;
189
- window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.css`;
190
- window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.css`;
191
- window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.css`;
193
+ window.T007_TOAST_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest/dist/index.min.css`;
194
+ window.T007_INPUT_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/input@latest/dist/index.min.css`;
195
+ window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
192
196
  }
193
197
  export {
198
+ VIRTUAL_RESOURCE,
194
199
  assignEl,
195
200
  bindAllMethods,
196
201
  clamp,
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "High-performance, zero-dependency utility functions for the t007 ecosystem.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/tobi007-del/t007-tools.git",
9
+ "url": "git+https://github.com/Tobi007-del/t007-tools.git",
10
10
  "directory": "packages/utils"
11
11
  },
12
- "homepage": "https://github.com/tobi007-del/t007-tools/tree/main/packages/utils#readme",
12
+ "homepage": "https://github.com/Tobi007-del/t007-tools/blob/main/packages/utils#readme",
13
13
  "type": "module",
14
14
  "main": "./dist/index.cjs",
15
15
  "module": "./dist/index.js",
@@ -24,20 +24,24 @@
24
24
  "default": "./dist/index.js"
25
25
  }
26
26
  },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
27
30
  "scripts": {
28
- "build": "tsup src/index.ts --format esm,cjs --dts --clean"
31
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
32
+ "prepublishOnly": "shx cp ../../LICENSE ."
29
33
  },
30
34
  "files": [
31
35
  "dist"
32
36
  ],
33
37
  "keywords": [
34
38
  "t007",
39
+ "ecosystem",
40
+ "vanilla-js",
35
41
  "utils",
36
42
  "helpers",
37
43
  "dom-manipulation",
38
- "ecosystem",
39
- "zero-dependency",
40
- "performance",
41
- "shared-logic"
44
+ "shared-logic",
45
+ "performance"
42
46
  ]
43
47
  }