@t007/utils 0.0.16 → 0.0.21

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,15 +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_utils4.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
- createEl: () => createEl,
28
+ clamp: () => import_utils3.clamp,
29
+ cleanKeyCombo: () => import_utils5.cleanKeyCombo,
30
+ createEl: () => import_utils.createEl,
30
31
  deepBreath: () => deepBreath,
31
- guardAllMethods: () => import_utils4.guardAllMethods,
32
- guardMethod: () => import_utils4.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,
33
37
  inBoolArrOpt: () => inBoolArrOpt,
34
38
  initScrollAssist: () => initScrollAssist,
35
39
  initVScrollerator: () => initVScrollerator,
@@ -39,39 +43,30 @@ __export(index_exports, {
39
43
  isFunc: () => isFunc,
40
44
  isIter: () => isIter,
41
45
  isNum: () => isNum,
42
- isObj: () => import_utils.isObj,
46
+ isObj: () => import_utils2.isObj,
43
47
  isPOJO: () => isPOJO,
44
48
  isSameURL: () => isSameURL,
45
49
  isStr: () => isStr,
46
50
  isSym: () => isSym,
51
+ keyEventAllowed: () => import_utils5.keyEventAllowed,
47
52
  limited: () => limited,
48
53
  loadResource: () => loadResource,
54
+ matchKeys: () => import_utils5.matchKeys,
49
55
  mockAsync: () => mockAsync,
50
- onAllMethods: () => import_utils4.onAllMethods,
56
+ onAllMethods: () => import_utils6.onAllMethods,
57
+ parseForARIAKS: () => import_utils5.parseForARIAKS,
58
+ parseKeyCombo: () => import_utils5.parseKeyCombo,
51
59
  removeScrollAssist: () => removeScrollAssist,
52
- requestAnimationFrame: () => import_utils3.requestAnimationFrame,
53
- setInterval: () => import_utils3.setInterval,
54
- setTimeout: () => import_utils3.setTimeout,
60
+ requestAnimationFrame: () => import_utils4.requestAnimationFrame,
61
+ setInterval: () => import_utils4.setInterval,
62
+ setTimeout: () => import_utils4.setTimeout,
63
+ stringifyKeyEvent: () => import_utils5.stringifyKeyEvent,
55
64
  uid: () => uid
56
65
  });
57
66
  module.exports = __toCommonJS(index_exports);
58
67
 
59
68
  // src/core/dom.ts
60
- function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
61
- return assignEl(el, props, dataset, styles), el;
62
- }
63
- function assignEl(el, props, dataset, styles) {
64
- if (!el) return;
65
- if (props) {
66
- for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
67
- }
68
- if (dataset) {
69
- for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
70
- }
71
- if (styles) {
72
- for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
73
- }
74
- }
69
+ var import_utils = require("sia-reactor/utils");
75
70
  var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
76
71
  function loadResource(req, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
77
72
  w.t007 ??= {}, w.t007._resourceCache ??= {};
@@ -93,8 +88,8 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
93
88
  }
94
89
  };
95
90
  const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
96
- 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 }) || "");
97
- 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 }) || "");
98
93
  else reject(new Error(`Unsupported resource type: ${type}`));
99
94
  })(attempts);
100
95
  });
@@ -102,7 +97,7 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
102
97
  }
103
98
 
104
99
  // src/core/obj.ts
105
- var import_utils = require("sia-reactor/utils");
100
+ var import_utils2 = require("sia-reactor/utils");
106
101
  function isDef(val) {
107
102
  return "undefined" !== typeof val;
108
103
  }
@@ -122,7 +117,7 @@ function isArr(obj) {
122
117
  return Array.isArray(obj);
123
118
  }
124
119
  function isPOJO(obj, crossRealms = false, typecheck = true) {
125
- 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);
126
121
  }
127
122
  function isIter(obj) {
128
123
  return obj != null && "function" === typeof obj[Symbol.iterator];
@@ -135,7 +130,7 @@ function inBoolArrOpt(opt, str) {
135
130
  }
136
131
 
137
132
  // src/core/num.ts
138
- var import_utils2 = require("sia-reactor/utils");
133
+ var import_utils3 = require("sia-reactor/utils");
139
134
 
140
135
  // src/core/str.ts
141
136
  function uid(prefix = "") {
@@ -152,7 +147,7 @@ function isSameURL(src1, src2) {
152
147
  }
153
148
 
154
149
  // src/core/fn.ts
155
- var import_utils3 = require("sia-reactor/utils");
150
+ var import_utils4 = require("sia-reactor/utils");
156
151
  function limited(FN_KEY, fn, opts = {}) {
157
152
  let count = 0, { key, maxTimes: max = 1 } = isStr(opts) ? { key: opts } : opts;
158
153
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
@@ -175,8 +170,11 @@ function bindCleanupToSignal(cleanup, signal) {
175
170
  return cleanup;
176
171
  }
177
172
 
178
- // src/core/methd.ts
179
- var import_utils4 = require("sia-reactor/utils");
173
+ // src/core/keys.ts
174
+ var import_utils5 = require("sia-reactor/utils");
175
+
176
+ // src/mixins/methd.ts
177
+ var import_utils6 = require("sia-reactor/utils");
180
178
 
181
179
  // src/quirks/scroll.ts
182
180
  function initVScrollerator({ baseSpeed = 3, maxSpeed = 10, stepDelay = 2e3, baseRate = 16, lineHeight = 80, margin = 80, car = window } = {}) {
@@ -240,7 +238,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
240
238
  };
241
239
  const stop = () => (cancelAnimationFrame(scrollId ?? 0), scrollId = null);
242
240
  const addAssist = (dir) => {
243
- const div = createEl("div", { className: assistClassName }, { scrollDirection: dir }, { display: "none" });
241
+ const div = (0, import_utils.createEl)("div", { className: assistClassName }, { scrollDirection: dir }, { display: "none" });
244
242
  if (!div) return;
245
243
  ["pointerenter", "dragenter"].forEach((evt) => div.addEventListener(evt, () => scroll(dir)));
246
244
  ["pointerleave", "pointerup", "pointercancel", "dragleave", "dragend"].forEach((evt) => div.addEventListener(evt, stop));
@@ -285,8 +283,12 @@ if ("undefined" !== typeof window) {
285
283
  bindCleanupToSignal,
286
284
  breath,
287
285
  clamp,
286
+ cleanKeyCombo,
288
287
  createEl,
289
288
  deepBreath,
289
+ formatKeyForDisplay,
290
+ formatKeyShortcutsForDisplay,
291
+ getTermsForKey,
290
292
  guardAllMethods,
291
293
  guardMethod,
292
294
  inBoolArrOpt,
@@ -303,13 +305,18 @@ if ("undefined" !== typeof window) {
303
305
  isSameURL,
304
306
  isStr,
305
307
  isSym,
308
+ keyEventAllowed,
306
309
  limited,
307
310
  loadResource,
311
+ matchKeys,
308
312
  mockAsync,
309
313
  onAllMethods,
314
+ parseForARIAKS,
315
+ parseKeyCombo,
310
316
  removeScrollAssist,
311
317
  requestAnimationFrame,
312
318
  setInterval,
313
319
  setTimeout,
320
+ stringifyKeyEvent,
314
321
  uid
315
322
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { bindAllMethods, clamp, guardAllMethods, guardMethod, isObj, onAllMethods, requestAnimationFrame, setInterval, setTimeout } 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;
@@ -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;
99
+
105
100
  declare const VIRTUAL_RESOURCE: unique 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 { bindAllMethods, clamp, guardAllMethods, guardMethod, isObj, onAllMethods, requestAnimationFrame, setInterval, setTimeout } 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;
@@ -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;
99
+
105
100
  declare const VIRTUAL_RESOURCE: unique 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 ??= {};
@@ -117,7 +103,10 @@ function bindCleanupToSignal(cleanup, signal) {
117
103
  return cleanup;
118
104
  }
119
105
 
120
- // src/core/methd.ts
106
+ // src/core/keys.ts
107
+ import { parseKeyCombo, stringifyKeyEvent, cleanKeyCombo, matchKeys, getTermsForKey, keyEventAllowed, formatKeyForDisplay, formatKeyShortcutsForDisplay, parseForARIAKS } from "sia-reactor/utils";
108
+
109
+ // src/mixins/methd.ts
121
110
  import { onAllMethods, bindAllMethods, guardAllMethods, guardMethod } from "sia-reactor/utils";
122
111
 
123
112
  // src/quirks/scroll.ts
@@ -226,8 +215,12 @@ export {
226
215
  bindCleanupToSignal,
227
216
  breath,
228
217
  clamp,
218
+ cleanKeyCombo,
229
219
  createEl,
230
220
  deepBreath,
221
+ formatKeyForDisplay,
222
+ formatKeyShortcutsForDisplay,
223
+ getTermsForKey,
231
224
  guardAllMethods,
232
225
  guardMethod,
233
226
  inBoolArrOpt,
@@ -244,13 +237,18 @@ export {
244
237
  isSameURL,
245
238
  isStr,
246
239
  isSym,
240
+ keyEventAllowed,
247
241
  limited,
248
242
  loadResource,
243
+ matchKeys,
249
244
  mockAsync,
250
245
  onAllMethods,
246
+ parseForARIAKS,
247
+ parseKeyCombo,
251
248
  removeScrollAssist,
252
249
  requestAnimationFrame2 as requestAnimationFrame,
253
250
  setInterval,
254
251
  setTimeout2 as setTimeout,
252
+ stringifyKeyEvent,
255
253
  uid
256
254
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.16",
3
+ "version": "0.0.21",
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.16"
48
+ "sia-reactor": "^0.0.20"
49
49
  }
50
50
  }