@t007/utils 0.0.15 → 0.0.18

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
@@ -22,14 +22,18 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  VIRTUAL_RESOURCE: () => VIRTUAL_RESOURCE,
24
24
  assignEl: () => assignEl,
25
- bindAllMethods: () => bindAllMethods,
25
+ bindAllMethods: () => import_utils5.bindAllMethods,
26
26
  bindCleanupToSignal: () => bindCleanupToSignal,
27
27
  breath: () => breath,
28
- clamp: () => clamp,
28
+ clamp: () => import_utils2.clamp,
29
+ cleanKeyCombo: () => import_utils4.cleanKeyCombo,
29
30
  createEl: () => createEl,
30
31
  deepBreath: () => deepBreath,
31
- guardAllMethods: () => guardAllMethods,
32
- guardMethod: () => guardMethod,
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,
33
37
  inBoolArrOpt: () => inBoolArrOpt,
34
38
  initScrollAssist: () => initScrollAssist,
35
39
  initVScrollerator: () => initVScrollerator,
@@ -39,58 +43,28 @@ __export(index_exports, {
39
43
  isFunc: () => isFunc,
40
44
  isIter: () => isIter,
41
45
  isNum: () => isNum,
42
- isObj: () => isObj,
46
+ isObj: () => import_utils.isObj,
43
47
  isPOJO: () => isPOJO,
44
48
  isSameURL: () => isSameURL,
45
49
  isStr: () => isStr,
46
50
  isSym: () => isSym,
51
+ keyEventAllowed: () => import_utils4.keyEventAllowed,
47
52
  limited: () => limited,
48
53
  loadResource: () => loadResource,
54
+ matchKeys: () => import_utils4.matchKeys,
49
55
  mockAsync: () => mockAsync,
50
- onAllMethods: () => onAllMethods,
56
+ onAllMethods: () => import_utils5.onAllMethods,
57
+ parseForARIAKS: () => import_utils4.parseForARIAKS,
58
+ parseKeyCombo: () => import_utils4.parseKeyCombo,
51
59
  removeScrollAssist: () => removeScrollAssist,
52
- requestAnimationFrame: () => requestAnimationFrame2,
53
- setInterval: () => setInterval,
54
- setTimeout: () => setTimeout2,
60
+ requestAnimationFrame: () => import_utils3.requestAnimationFrame,
61
+ setInterval: () => import_utils3.setInterval,
62
+ setTimeout: () => import_utils3.setTimeout,
63
+ stringifyKeyEvent: () => import_utils4.stringifyKeyEvent,
55
64
  uid: () => uid
56
65
  });
57
66
  module.exports = __toCommonJS(index_exports);
58
67
 
59
- // src/core/obj.ts
60
- function isDef(val) {
61
- return "undefined" !== typeof val;
62
- }
63
- function isSym(val) {
64
- return "symbol" === typeof val;
65
- }
66
- function isBool(val) {
67
- return "boolean" === typeof val;
68
- }
69
- function isNum(val) {
70
- return "number" === typeof val;
71
- }
72
- function isStr(val) {
73
- return "string" === typeof val;
74
- }
75
- function isArr(obj) {
76
- return Array.isArray(obj);
77
- }
78
- function isObj(obj, arraycheck = true) {
79
- return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
80
- }
81
- function isPOJO(obj, crossRealms = false, typecheck = true) {
82
- return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
83
- }
84
- function isIter(obj) {
85
- return obj != null && "function" === typeof obj[Symbol.iterator];
86
- }
87
- function isFunc(val) {
88
- return "function" === typeof val;
89
- }
90
- function inBoolArrOpt(opt, str) {
91
- return opt?.includes?.(str) ?? opt;
92
- }
93
-
94
68
  // src/core/dom.ts
95
69
  function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
96
70
  return assignEl(el, props, dataset, styles), el;
@@ -136,10 +110,41 @@ function loadResource(req, type = "style", { module: module2, media, crossOrigin
136
110
  return w.t007._resourceCache[src];
137
111
  }
138
112
 
139
- // src/core/num.ts
140
- function clamp(min = 0, val, max = Infinity) {
141
- return Math.min(Math.max(val, min), max);
113
+ // src/core/obj.ts
114
+ var import_utils = require("sia-reactor/utils");
115
+ function isDef(val) {
116
+ return "undefined" !== typeof val;
117
+ }
118
+ function isSym(val) {
119
+ return "symbol" === typeof val;
142
120
  }
121
+ function isBool(val) {
122
+ return "boolean" === typeof val;
123
+ }
124
+ function isNum(val) {
125
+ return "number" === typeof val;
126
+ }
127
+ function isStr(val) {
128
+ return "string" === typeof val;
129
+ }
130
+ function isArr(obj) {
131
+ return Array.isArray(obj);
132
+ }
133
+ 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);
135
+ }
136
+ function isIter(obj) {
137
+ return obj != null && "function" === typeof obj[Symbol.iterator];
138
+ }
139
+ function isFunc(val) {
140
+ return "function" === typeof val;
141
+ }
142
+ function inBoolArrOpt(opt, str) {
143
+ return opt?.includes?.(str) ?? opt;
144
+ }
145
+
146
+ // src/core/num.ts
147
+ var import_utils2 = require("sia-reactor/utils");
143
148
 
144
149
  // src/core/str.ts
145
150
  function uid(prefix = "") {
@@ -156,26 +161,7 @@ function isSameURL(src1, src2) {
156
161
  }
157
162
 
158
163
  // src/core/fn.ts
159
- function setTimeout2(handler, timeout, ...args) {
160
- const sig = args[0] instanceof AbortSignal ? args.shift() : void 0;
161
- if (sig?.aborted) return -1;
162
- const w = args[0] instanceof Window ? args.shift() : window;
163
- if (!sig) return w.setTimeout(handler, timeout, ...args);
164
- const id = w.setTimeout(() => (sig.removeEventListener("abort", kill), isStr(handler) ? new Function(handler) : handler(...args)), timeout), kill = () => w.clearTimeout(id);
165
- return sig.addEventListener("abort", kill, { once: true }), id;
166
- }
167
- function setInterval(handler, timeout, ...args) {
168
- const sig = args[0] instanceof AbortSignal ? args.shift() : void 0;
169
- if (sig?.aborted) return -1;
170
- const w = args[0] instanceof Window ? args.shift() : window, id = w.setInterval(handler, timeout, ...args);
171
- return sig?.addEventListener("abort", () => w.clearInterval(id), { once: true }), id;
172
- }
173
- function requestAnimationFrame2(callback, sig, w = window) {
174
- if (sig?.aborted) return -1;
175
- if (!sig) return w.requestAnimationFrame(callback);
176
- const id = w.requestAnimationFrame((t) => (sig.removeEventListener("abort", kill), callback(t))), kill = () => w.cancelAnimationFrame(id);
177
- return sig.addEventListener("abort", kill, { once: true }), id;
178
- }
164
+ var import_utils3 = require("sia-reactor/utils");
179
165
  function limited(FN_KEY, fn, opts = {}) {
180
166
  let count = 0, { key, maxTimes: max = 1 } = isStr(opts) ? { key: opts } : opts;
181
167
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
@@ -189,7 +175,7 @@ function limited(FN_KEY, fn, opts = {}) {
189
175
  handle.block = () => (count = max, key && ((r) => (r[key] = max, setReg(r)))(getReg()));
190
176
  return handle;
191
177
  }
192
- var mockAsync = (timeout = 250) => new Promise((resolve) => setTimeout2(resolve, timeout));
178
+ var mockAsync = (timeout = 250) => new Promise((resolve) => setTimeout(resolve, timeout));
193
179
  var breath = (w = window) => new Promise((res) => w.requestAnimationFrame(res));
194
180
  var deepBreath = (w = window) => new Promise((res) => w.requestAnimationFrame(() => w.requestAnimationFrame(res)));
195
181
  function bindCleanupToSignal(cleanup, signal) {
@@ -198,38 +184,11 @@ function bindCleanupToSignal(cleanup, signal) {
198
184
  return cleanup;
199
185
  }
200
186
 
201
- // src/mixins/methodist.ts
202
- function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
203
- let proto = owner;
204
- while (proto && proto !== Object.prototype) {
205
- for (const method of Object.getOwnPropertyNames(proto)) {
206
- if (method === "constructor") continue;
207
- if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
208
- if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
209
- }
210
- proto = Object.getPrototypeOf(proto), nested = true;
211
- }
212
- }
213
- function bindAllMethods(owner) {
214
- onAllMethods(owner, (method, owner2) => {
215
- owner2[method] = owner2[method].bind(owner2);
216
- });
217
- }
218
- function guardAllMethods(owner, guardFn = guardMethod, bound = true) {
219
- onAllMethods(owner, (method, owner2) => {
220
- owner2[method] = guardFn(bound ? owner2[method].bind(owner2) : owner2[method]);
221
- });
222
- }
223
- function guardMethod(fn, onError = (e) => console.error(e)) {
224
- return ((...args) => {
225
- try {
226
- const result = fn(...args);
227
- return result instanceof Promise ? result.catch((e) => onError(e)) : result;
228
- } catch (e) {
229
- onError(e);
230
- }
231
- });
232
- }
187
+ // src/core/keys.ts
188
+ var import_utils4 = require("sia-reactor/utils");
189
+
190
+ // src/mixins/methd.ts
191
+ var import_utils5 = require("sia-reactor/utils");
233
192
 
234
193
  // src/quirks/scroll.ts
235
194
  function initVScrollerator({ baseSpeed = 3, maxSpeed = 10, stepDelay = 2e3, baseRate = 16, lineHeight = 80, margin = 80, car = window } = {}) {
@@ -320,7 +279,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
320
279
  var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
321
280
 
322
281
  // src/index.ts
323
- if (isDef(window)) {
282
+ if ("undefined" !== typeof window) {
324
283
  window.t007 ??= {};
325
284
  t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
326
285
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
@@ -338,8 +297,12 @@ if (isDef(window)) {
338
297
  bindCleanupToSignal,
339
298
  breath,
340
299
  clamp,
300
+ cleanKeyCombo,
341
301
  createEl,
342
302
  deepBreath,
303
+ formatKeyForDisplay,
304
+ formatKeyShortcutsForDisplay,
305
+ getTermsForKey,
343
306
  guardAllMethods,
344
307
  guardMethod,
345
308
  inBoolArrOpt,
@@ -356,13 +319,18 @@ if (isDef(window)) {
356
319
  isSameURL,
357
320
  isStr,
358
321
  isSym,
322
+ keyEventAllowed,
359
323
  limited,
360
324
  loadResource,
325
+ matchKeys,
361
326
  mockAsync,
362
327
  onAllMethods,
328
+ parseForARIAKS,
329
+ parseKeyCombo,
363
330
  removeScrollAssist,
364
331
  requestAnimationFrame,
365
332
  setInterval,
366
333
  setTimeout,
334
+ stringifyKeyEvent,
367
335
  uid
368
336
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
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';
2
+
1
3
  interface ScrolleratorOptions {
2
4
  baseSpeed?: number;
3
5
  maxSpeed?: number;
@@ -56,20 +58,15 @@ declare function isBool<T extends boolean = boolean>(val: any): val is T;
56
58
  declare function isNum<T extends number = number>(val: any): val is T;
57
59
  declare function isStr<T extends string = string>(val: any): val is T;
58
60
  declare function isArr<T = unknown>(obj: any): obj is T[];
59
- declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
61
+
60
62
  declare function isPOJO<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
61
63
  declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
62
64
  declare function isFunc<T extends Function = Function>(val: any): val is T;
63
65
  declare function inBoolArrOpt(opt: any, str: string): boolean;
64
66
 
65
- declare function clamp(min: number | undefined, val: number, max?: number): number;
66
-
67
67
  declare function uid(prefix?: string): string;
68
68
  declare function isSameURL(src1: unknown, src2: unknown): boolean;
69
69
 
70
- declare function setTimeout(handler: TimerHandler, timeout?: number, ...args: any[]): number;
71
- declare function setInterval(handler: TimerHandler, timeout?: number, ...args: any[]): number;
72
- declare function requestAnimationFrame(callback: FrameRequestCallback, sig?: AbortSignal, w?: Window & typeof globalThis): number;
73
70
  interface LimitedOptions {
74
71
  key?: string /** Key for localStorage persistence (if omitted, uses session-only) */;
75
72
  maxTimes?: number /** Max times to call (default: 1) */;
@@ -108,9 +105,4 @@ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>,
108
105
  declare const VIRTUAL_RESOURCE: unique symbol;
109
106
  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>;
110
107
 
111
- declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void, skipNestedOwn?: boolean, nested?: boolean): void;
112
- declare function bindAllMethods(owner: any): void;
113
- declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
114
- declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
115
-
116
- export { type Dataset, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, bindCleanupToSignal, breath, clamp, createEl, deepBreath, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, onAllMethods, removeScrollAssist, requestAnimationFrame, setInterval, setTimeout, uid };
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 };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
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';
2
+
1
3
  interface ScrolleratorOptions {
2
4
  baseSpeed?: number;
3
5
  maxSpeed?: number;
@@ -56,20 +58,15 @@ declare function isBool<T extends boolean = boolean>(val: any): val is T;
56
58
  declare function isNum<T extends number = number>(val: any): val is T;
57
59
  declare function isStr<T extends string = string>(val: any): val is T;
58
60
  declare function isArr<T = unknown>(obj: any): obj is T[];
59
- declare function isObj<T extends object = object>(obj: any, arraycheck?: boolean): obj is T;
61
+
60
62
  declare function isPOJO<T extends object = object>(obj: any, crossRealms?: boolean, typecheck?: boolean): obj is T;
61
63
  declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
62
64
  declare function isFunc<T extends Function = Function>(val: any): val is T;
63
65
  declare function inBoolArrOpt(opt: any, str: string): boolean;
64
66
 
65
- declare function clamp(min: number | undefined, val: number, max?: number): number;
66
-
67
67
  declare function uid(prefix?: string): string;
68
68
  declare function isSameURL(src1: unknown, src2: unknown): boolean;
69
69
 
70
- declare function setTimeout(handler: TimerHandler, timeout?: number, ...args: any[]): number;
71
- declare function setInterval(handler: TimerHandler, timeout?: number, ...args: any[]): number;
72
- declare function requestAnimationFrame(callback: FrameRequestCallback, sig?: AbortSignal, w?: Window & typeof globalThis): number;
73
70
  interface LimitedOptions {
74
71
  key?: string /** Key for localStorage persistence (if omitted, uses session-only) */;
75
72
  maxTimes?: number /** Max times to call (default: 1) */;
@@ -108,9 +105,4 @@ declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>,
108
105
  declare const VIRTUAL_RESOURCE: unique symbol;
109
106
  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>;
110
107
 
111
- declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void, skipNestedOwn?: boolean, nested?: boolean): void;
112
- declare function bindAllMethods(owner: any): void;
113
- declare function guardAllMethods(owner: any, guardFn?: (fn: Function) => Function, bound?: boolean): void;
114
- declare function guardMethod<T extends Function>(fn: T, onError?: (e: any) => void): T;
115
-
116
- export { type Dataset, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, type ScrollAssistControl, type Style, VIRTUAL_RESOURCE, assignEl, bindAllMethods, bindCleanupToSignal, breath, clamp, createEl, deepBreath, guardAllMethods, guardMethod, inBoolArrOpt, initScrollAssist, initVScrollerator, isArr, isBool, isDef, isFunc, isIter, isNum, isObj, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, onAllMethods, removeScrollAssist, requestAnimationFrame, setInterval, setTimeout, uid };
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 };
package/dist/index.js CHANGED
@@ -1,38 +1,3 @@
1
- // src/core/obj.ts
2
- function isDef(val) {
3
- return "undefined" !== typeof val;
4
- }
5
- function isSym(val) {
6
- return "symbol" === typeof val;
7
- }
8
- function isBool(val) {
9
- return "boolean" === typeof val;
10
- }
11
- function isNum(val) {
12
- return "number" === typeof val;
13
- }
14
- function isStr(val) {
15
- return "string" === typeof val;
16
- }
17
- function isArr(obj) {
18
- return Array.isArray(obj);
19
- }
20
- function isObj(obj, arraycheck = true) {
21
- return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
22
- }
23
- function isPOJO(obj, crossRealms = false, typecheck = true) {
24
- return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
25
- }
26
- function isIter(obj) {
27
- return obj != null && "function" === typeof obj[Symbol.iterator];
28
- }
29
- function isFunc(val) {
30
- return "function" === typeof val;
31
- }
32
- function inBoolArrOpt(opt, str) {
33
- return opt?.includes?.(str) ?? opt;
34
- }
35
-
36
1
  // src/core/dom.ts
37
2
  function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
38
3
  return assignEl(el, props, dataset, styles), el;
@@ -78,10 +43,41 @@ function loadResource(req, type = "style", { module, media, crossOrigin, integri
78
43
  return w.t007._resourceCache[src];
79
44
  }
80
45
 
81
- // src/core/num.ts
82
- function clamp(min = 0, val, max = Infinity) {
83
- return Math.min(Math.max(val, min), max);
46
+ // src/core/obj.ts
47
+ import { isObj } from "sia-reactor/utils";
48
+ function isDef(val) {
49
+ return "undefined" !== typeof val;
50
+ }
51
+ function isSym(val) {
52
+ return "symbol" === typeof val;
84
53
  }
54
+ function isBool(val) {
55
+ return "boolean" === typeof val;
56
+ }
57
+ function isNum(val) {
58
+ return "number" === typeof val;
59
+ }
60
+ function isStr(val) {
61
+ return "string" === typeof val;
62
+ }
63
+ function isArr(obj) {
64
+ return Array.isArray(obj);
65
+ }
66
+ function isPOJO(obj, crossRealms = false, typecheck = true) {
67
+ return (typecheck ? isObj(obj, false) : true) && (crossRealms ? Object.prototype.toString.call(obj) === "[object Object]" : obj.constructor === Object);
68
+ }
69
+ function isIter(obj) {
70
+ return obj != null && "function" === typeof obj[Symbol.iterator];
71
+ }
72
+ function isFunc(val) {
73
+ return "function" === typeof val;
74
+ }
75
+ function inBoolArrOpt(opt, str) {
76
+ return opt?.includes?.(str) ?? opt;
77
+ }
78
+
79
+ // src/core/num.ts
80
+ import { clamp } from "sia-reactor/utils";
85
81
 
86
82
  // src/core/str.ts
87
83
  function uid(prefix = "") {
@@ -98,26 +94,7 @@ function isSameURL(src1, src2) {
98
94
  }
99
95
 
100
96
  // src/core/fn.ts
101
- function setTimeout2(handler, timeout, ...args) {
102
- const sig = args[0] instanceof AbortSignal ? args.shift() : void 0;
103
- if (sig?.aborted) return -1;
104
- const w = args[0] instanceof Window ? args.shift() : window;
105
- if (!sig) return w.setTimeout(handler, timeout, ...args);
106
- const id = w.setTimeout(() => (sig.removeEventListener("abort", kill), isStr(handler) ? new Function(handler) : handler(...args)), timeout), kill = () => w.clearTimeout(id);
107
- return sig.addEventListener("abort", kill, { once: true }), id;
108
- }
109
- function setInterval(handler, timeout, ...args) {
110
- const sig = args[0] instanceof AbortSignal ? args.shift() : void 0;
111
- if (sig?.aborted) return -1;
112
- const w = args[0] instanceof Window ? args.shift() : window, id = w.setInterval(handler, timeout, ...args);
113
- return sig?.addEventListener("abort", () => w.clearInterval(id), { once: true }), id;
114
- }
115
- function requestAnimationFrame2(callback, sig, w = window) {
116
- if (sig?.aborted) return -1;
117
- if (!sig) return w.requestAnimationFrame(callback);
118
- const id = w.requestAnimationFrame((t) => (sig.removeEventListener("abort", kill), callback(t))), kill = () => w.cancelAnimationFrame(id);
119
- return sig.addEventListener("abort", kill, { once: true }), id;
120
- }
97
+ import { setTimeout as setTimeout2, setInterval, requestAnimationFrame as requestAnimationFrame2 } from "sia-reactor/utils";
121
98
  function limited(FN_KEY, fn, opts = {}) {
122
99
  let count = 0, { key, maxTimes: max = 1 } = isStr(opts) ? { key: opts } : opts;
123
100
  const getReg = () => JSON.parse(localStorage.getItem(FN_KEY) || "{}"), setReg = (r) => localStorage.setItem(FN_KEY, JSON.stringify(r));
@@ -131,7 +108,7 @@ function limited(FN_KEY, fn, opts = {}) {
131
108
  handle.block = () => (count = max, key && ((r) => (r[key] = max, setReg(r)))(getReg()));
132
109
  return handle;
133
110
  }
134
- var mockAsync = (timeout = 250) => new Promise((resolve) => setTimeout2(resolve, timeout));
111
+ var mockAsync = (timeout = 250) => new Promise((resolve) => setTimeout(resolve, timeout));
135
112
  var breath = (w = window) => new Promise((res) => w.requestAnimationFrame(res));
136
113
  var deepBreath = (w = window) => new Promise((res) => w.requestAnimationFrame(() => w.requestAnimationFrame(res)));
137
114
  function bindCleanupToSignal(cleanup, signal) {
@@ -140,38 +117,11 @@ function bindCleanupToSignal(cleanup, signal) {
140
117
  return cleanup;
141
118
  }
142
119
 
143
- // src/mixins/methodist.ts
144
- function onAllMethods(owner, callback, skipNestedOwn = true, nested = false) {
145
- let proto = owner;
146
- while (proto && proto !== Object.prototype) {
147
- for (const method of Object.getOwnPropertyNames(proto)) {
148
- if (method === "constructor") continue;
149
- if (nested && skipNestedOwn && Object.prototype.hasOwnProperty.call(owner, method)) continue;
150
- if (isFunc(Object.getOwnPropertyDescriptor(proto, method)?.value)) callback(method, owner);
151
- }
152
- proto = Object.getPrototypeOf(proto), nested = true;
153
- }
154
- }
155
- function bindAllMethods(owner) {
156
- onAllMethods(owner, (method, owner2) => {
157
- owner2[method] = owner2[method].bind(owner2);
158
- });
159
- }
160
- function guardAllMethods(owner, guardFn = guardMethod, bound = true) {
161
- onAllMethods(owner, (method, owner2) => {
162
- owner2[method] = guardFn(bound ? owner2[method].bind(owner2) : owner2[method]);
163
- });
164
- }
165
- function guardMethod(fn, onError = (e) => console.error(e)) {
166
- return ((...args) => {
167
- try {
168
- const result = fn(...args);
169
- return result instanceof Promise ? result.catch((e) => onError(e)) : result;
170
- } catch (e) {
171
- onError(e);
172
- }
173
- });
174
- }
120
+ // src/core/keys.ts
121
+ import { parseKeyCombo, stringifyKeyEvent, cleanKeyCombo, matchKeys, getTermsForKey, keyEventAllowed, formatKeyForDisplay, formatKeyShortcutsForDisplay, parseForARIAKS } from "sia-reactor/utils";
122
+
123
+ // src/mixins/methd.ts
124
+ import { onAllMethods, bindAllMethods, guardAllMethods, guardMethod } from "sia-reactor/utils";
175
125
 
176
126
  // src/quirks/scroll.ts
177
127
  function initVScrollerator({ baseSpeed = 3, maxSpeed = 10, stepDelay = 2e3, baseRate = 16, lineHeight = 80, margin = 80, car = window } = {}) {
@@ -262,7 +212,7 @@ function initScrollAssist(el, { pxPerSecond = 80, assistClassName = "tmg-video-c
262
212
  var removeScrollAssist = (el) => t007._scrollers.get(el)?.destroy();
263
213
 
264
214
  // src/index.ts
265
- if (isDef(window)) {
215
+ if ("undefined" !== typeof window) {
266
216
  window.t007 ??= {};
267
217
  t007.VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
268
218
  window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
@@ -279,8 +229,12 @@ export {
279
229
  bindCleanupToSignal,
280
230
  breath,
281
231
  clamp,
232
+ cleanKeyCombo,
282
233
  createEl,
283
234
  deepBreath,
235
+ formatKeyForDisplay,
236
+ formatKeyShortcutsForDisplay,
237
+ getTermsForKey,
284
238
  guardAllMethods,
285
239
  guardMethod,
286
240
  inBoolArrOpt,
@@ -297,13 +251,18 @@ export {
297
251
  isSameURL,
298
252
  isStr,
299
253
  isSym,
254
+ keyEventAllowed,
300
255
  limited,
301
256
  loadResource,
257
+ matchKeys,
302
258
  mockAsync,
303
259
  onAllMethods,
260
+ parseForARIAKS,
261
+ parseKeyCombo,
304
262
  removeScrollAssist,
305
263
  requestAnimationFrame2 as requestAnimationFrame,
306
264
  setInterval,
307
265
  setTimeout2 as setTimeout,
266
+ stringifyKeyEvent,
308
267
  uid
309
268
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.15",
3
+ "version": "0.0.18",
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",
@@ -43,5 +43,8 @@
43
43
  "dom-manipulation",
44
44
  "shared-logic",
45
45
  "performance"
46
- ]
46
+ ],
47
+ "dependencies": {
48
+ "sia-reactor": "^0.0.17"
49
+ }
47
50
  }