@t007/utils 0.0.18 → 0.0.22

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.cjs CHANGED
@@ -21,19 +21,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  VIRTUAL_RESOURCE: () => VIRTUAL_RESOURCE,
24
- assignEl: () => assignEl,
25
- bindAllMethods: () => import_utils5.bindAllMethods,
24
+ assignEl: () => import_utils.assignEl,
25
+ bindAllMethods: () => import_utils6.bindAllMethods,
26
26
  bindCleanupToSignal: () => bindCleanupToSignal,
27
27
  breath: () => breath,
28
- clamp: () => import_utils2.clamp,
29
- cleanKeyCombo: () => import_utils4.cleanKeyCombo,
30
- createEl: () => createEl,
28
+ clamp: () => import_utils3.clamp,
29
+ cleanKeyCombo: () => import_utils5.cleanKeyCombo,
30
+ createEl: () => import_utils.createEl,
31
31
  deepBreath: () => deepBreath,
32
- formatKeyForDisplay: () => import_utils4.formatKeyForDisplay,
33
- formatKeyShortcutsForDisplay: () => import_utils4.formatKeyShortcutsForDisplay,
34
- getTermsForKey: () => import_utils4.getTermsForKey,
35
- guardAllMethods: () => import_utils5.guardAllMethods,
36
- guardMethod: () => import_utils5.guardMethod,
32
+ formatKeyForDisplay: () => import_utils5.formatKeyForDisplay,
33
+ formatKeyShortcutsForDisplay: () => import_utils5.formatKeyShortcutsForDisplay,
34
+ getTermsForKey: () => import_utils5.getTermsForKey,
35
+ guardAllMethods: () => import_utils6.guardAllMethods,
36
+ guardMethod: () => import_utils6.guardMethod,
37
37
  inBoolArrOpt: () => inBoolArrOpt,
38
38
  initScrollAssist: () => initScrollAssist,
39
39
  initVScrollerator: () => initVScrollerator,
@@ -43,44 +43,30 @@ __export(index_exports, {
43
43
  isFunc: () => isFunc,
44
44
  isIter: () => isIter,
45
45
  isNum: () => isNum,
46
- isObj: () => import_utils.isObj,
46
+ isObj: () => import_utils2.isObj,
47
47
  isPOJO: () => isPOJO,
48
48
  isSameURL: () => isSameURL,
49
49
  isStr: () => isStr,
50
50
  isSym: () => isSym,
51
- keyEventAllowed: () => import_utils4.keyEventAllowed,
51
+ keyEventAllowed: () => import_utils5.keyEventAllowed,
52
52
  limited: () => limited,
53
53
  loadResource: () => loadResource,
54
- matchKeys: () => import_utils4.matchKeys,
54
+ matchKeys: () => import_utils5.matchKeys,
55
55
  mockAsync: () => mockAsync,
56
- onAllMethods: () => import_utils5.onAllMethods,
57
- parseForARIAKS: () => import_utils4.parseForARIAKS,
58
- parseKeyCombo: () => import_utils4.parseKeyCombo,
56
+ onAllMethods: () => import_utils6.onAllMethods,
57
+ parseForARIAKS: () => import_utils5.parseForARIAKS,
58
+ parseKeyCombo: () => import_utils5.parseKeyCombo,
59
59
  removeScrollAssist: () => removeScrollAssist,
60
- requestAnimationFrame: () => import_utils3.requestAnimationFrame,
61
- setInterval: () => import_utils3.setInterval,
62
- setTimeout: () => import_utils3.setTimeout,
63
- stringifyKeyEvent: () => import_utils4.stringifyKeyEvent,
60
+ requestAnimationFrame: () => import_utils4.requestAnimationFrame,
61
+ setInterval: () => import_utils4.setInterval,
62
+ setTimeout: () => import_utils4.setTimeout,
63
+ stringifyKeyEvent: () => import_utils5.stringifyKeyEvent,
64
64
  uid: () => uid
65
65
  });
66
66
  module.exports = __toCommonJS(index_exports);
67
67
 
68
68
  // src/core/dom.ts
69
- function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
70
- return assignEl(el, props, dataset, styles), el;
71
- }
72
- function assignEl(el, props, dataset, styles) {
73
- if (!el) return;
74
- if (props) {
75
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
76
- }
77
- if (dataset) {
78
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
79
- }
80
- if (styles) {
81
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
82
- }
83
- }
69
+ var import_utils = require("sia-reactor/utils");
84
70
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
85
71
  function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
86
72
  w.t007 ??= {}, w.t007._resourceCache ??= {};
@@ -102,8 +88,8 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
102
88
  }
103
89
  };
104
90
  const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
105
- if (type === "script") w.document.body.append(el = createEl("script", { src: url, type: module2 ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
106
- 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 }) || "");
91
+ if (type === "script") w.document.body.append(el = (0, import_utils.createEl)("script", { src: url, type: module2 ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
92
+ else if (type === "style") w.document.head.append(el = (0, import_utils.createEl)("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
107
93
  else reject(new Error(`Unsupported resource type: ${type}`));
108
94
  })(attempts);
109
95
  });
@@ -111,7 +97,7 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
111
97
  }
112
98
 
113
99
  // src/core/obj.ts
114
- var import_utils = require("sia-reactor/utils");
100
+ var import_utils2 = require("sia-reactor/utils");
115
101
  function isDef(val) {
116
102
  return "undefined" !== typeof val;
117
103
  }
@@ -131,7 +117,7 @@ function isArr(obj) {
131
117
  return Array.isArray(obj);
132
118
  }
133
119
  function isPOJO(obj, crossRealms = false, typecheck = true) {
134
- return (typecheck ? (0, import_utils.isObj)(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
120
+ return (typecheck ? (0, import_utils2.isObj)(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
135
121
  }
136
122
  function isIter(obj) {
137
123
  return obj != null && "function" === typeof obj[Symbol.iterator];
@@ -144,7 +130,7 @@ function inBoolArrOpt(opt, str) {
144
130
  }
145
131
 
146
132
  // src/core/num.ts
147
- var import_utils2 = require("sia-reactor/utils");
133
+ var import_utils3 = require("sia-reactor/utils");
148
134
 
149
135
  // src/core/str.ts
150
136
  function uid(prefix = "") {
@@ -161,7 +147,7 @@ function isSameURL(src1, src2) {
161
147
  }
162
148
 
163
149
  // src/core/fn.ts
164
- var import_utils3 = require("sia-reactor/utils");
150
+ var import_utils4 = require("sia-reactor/utils");
165
151
  function limited(FN_KEY, fn, opts = {}) {
166
152
  let count = 0, { key, maxTimes: max = 1 } = isStr(opts) ? { key: opts } : opts;
167
153
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
@@ -185,10 +171,10 @@ function bindCleanupToSignal(cleanup, signal) {
185
171
  }
186
172
 
187
173
  // src/core/keys.ts
188
- var import_utils4 = require("sia-reactor/utils");
174
+ var import_utils5 = require("sia-reactor/utils");
189
175
 
190
176
  // src/mixins/methd.ts
191
- var import_utils5 = require("sia-reactor/utils");
177
+ var import_utils6 = require("sia-reactor/utils");
192
178
 
193
179
  // src/quirks/scroll.ts
194
180
  function initVScrollerator({ baseSpeed = 3, maxSpeed = 10, stepDelay = 2e3, baseRate = 16, lineHeight = 80, margin = 80, car = window } = {}) {
@@ -252,7 +238,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
252
238
  };
253
239
  const stop = () => (cancelAnimationFrame(scrollId ?? 0), scrollId = null);
254
240
  const addAssist = (dir) => {
255
- const div = createEl("div", { className: assistClassName }, { scrollDirection: dir }, { display: "none" });
241
+ const div = (0, import_utils.createEl)("div", { className: assistClassName }, { scrollDirection: dir }, { display: "none" });
256
242
  if (!div) return;
257
243
  ["pointerenter", "dragenter"].forEach((evt) => div.addEventListener(evt, () => scroll(dir)));
258
244
  ["pointerleave", "pointerup", "pointercancel", "dragleave", "dragend"].forEach((evt) => div.addEventListener(evt, stop));
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { KeyStruct, bindAllMethods, clamp, cleanKeyCombo, formatKeyForDisplay, formatKeyShortcutsForDisplay, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, keysSettings, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
1
+ export { KeyStruct, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, keysSettings, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
2
2
 
3
3
  interface ScrolleratorOptions {
4
4
  baseSpeed?: number;
@@ -29,7 +29,7 @@ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
29
29
 
30
30
  declare global {
31
31
  interface T007Namespace {
32
- VIRTUAL_RESOURCE: unique symbol;
32
+ VIRTUAL_RESOURCE: symbol;
33
33
 
34
34
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
35
35
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
@@ -84,8 +84,6 @@ declare const breath: (w?: Window & typeof globalThis) => Promise<unknown>;
84
84
  declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
85
85
  declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
86
86
 
87
- type Dataset = Record<string, string | number>;
88
- type Style = Partial<CSSStyleDeclaration>;
89
87
  type ResourceType = "style" | "script" | string;
90
88
  type LoadResourceOptions = Partial<{
91
89
  module: boolean;
@@ -98,11 +96,8 @@ type LoadResourceOptions = Partial<{
98
96
  attempts: number;
99
97
  retryKey: boolean | string;
100
98
  }>;
101
- declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
102
- declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
103
- declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
104
- declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
105
- declare const VIRTUAL_RESOURCE: unique symbol;
99
+
100
+ declare const VIRTUAL_RESOURCE: symbol;
106
101
  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>;
107
102
 
108
- export { type Dataset, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindCleanupToSignal, breath, createEl, deepBreath, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, removeScrollAssist, uid };
103
+ export { type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, deepBreath, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, removeScrollAssist, uid };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { KeyStruct, bindAllMethods, clamp, cleanKeyCombo, formatKeyForDisplay, formatKeyShortcutsForDisplay, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, keysSettings, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
1
+ export { KeyStruct, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, keysSettings, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
2
2
 
3
3
  interface ScrolleratorOptions {
4
4
  baseSpeed?: number;
@@ -29,7 +29,7 @@ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
29
29
 
30
30
  declare global {
31
31
  interface T007Namespace {
32
- VIRTUAL_RESOURCE: unique symbol;
32
+ VIRTUAL_RESOURCE: symbol;
33
33
 
34
34
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
35
35
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
@@ -84,8 +84,6 @@ declare const breath: (w?: Window & typeof globalThis) => Promise<unknown>;
84
84
  declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
85
85
  declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
86
86
 
87
- type Dataset = Record<string, string | number>;
88
- type Style = Partial<CSSStyleDeclaration>;
89
87
  type ResourceType = "style" | "script" | string;
90
88
  type LoadResourceOptions = Partial<{
91
89
  module: boolean;
@@ -98,11 +96,8 @@ type LoadResourceOptions = Partial<{
98
96
  attempts: number;
99
97
  retryKey: boolean | string;
100
98
  }>;
101
- declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
102
- declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
103
- declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
104
- declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
105
- declare const VIRTUAL_RESOURCE: unique symbol;
99
+
100
+ declare const VIRTUAL_RESOURCE: symbol;
106
101
  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>;
107
102
 
108
- export { type Dataset, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindCleanupToSignal, breath, createEl, deepBreath, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, removeScrollAssist, uid };
103
+ export { type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, deepBreath, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, removeScrollAssist, uid };
package/dist/index.js CHANGED
@@ -1,19 +1,5 @@
1
1
  // src/core/dom.ts
2
- function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
3
- return assignEl(el, props, dataset, styles), el;
4
- }
5
- function assignEl(el, props, dataset, styles) {
6
- if (!el) return;
7
- if (props) {
8
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
9
- }
10
- if (dataset) {
11
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
12
- }
13
- if (styles) {
14
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
15
- }
16
- }
2
+ import { createEl, assignEl } from "sia-reactor/utils";
17
3
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
18
4
  function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
19
5
  w.t007 ??= {}, w.t007._resourceCache ??= {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.18",
3
+ "version": "0.0.22",
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",
@@ -45,6 +45,6 @@
45
45
  "performance"
46
46
  ],
47
47
  "dependencies": {
48
- "sia-reactor": "^0.0.17"
48
+ "sia-reactor": "^0.0.25"
49
49
  }
50
50
  }