@t007/utils 0.0.22 → 0.0.24

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.d.cts CHANGED
@@ -1,54 +1,93 @@
1
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
+ /** Configuration for the vertical edge-scrolling helper. */
3
4
  interface ScrolleratorOptions {
5
+ /** Starting lines-per-second speed. */
4
6
  baseSpeed?: number;
7
+ /** Maximum accelerated speed. */
5
8
  maxSpeed?: number;
9
+ /** Delay before acceleration kicks in. */
6
10
  stepDelay?: number;
11
+ /** Base frame rate used to estimate movement. */
7
12
  baseRate?: number;
13
+ /** Approximate line height in pixels. */
8
14
  lineHeight?: number;
15
+ /** Edge margin that triggers scrolling. */
9
16
  margin?: number;
17
+ /** Scroll container or window target. */
10
18
  car?: Window | HTMLElement;
11
19
  }
20
+ /** Scrolling controls returned by initVScrollerator. */
12
21
  interface Scrollerator {
22
+ /** Trigger a scroll frame and return the computed distance. */
13
23
  drive: (clientY: number, brake?: boolean, offsetY?: number) => number;
24
+ /** Reset speed and timers. */
14
25
  reset: () => void;
15
26
  }
27
+ /** Create an edge-driven vertical scrolling controller.
28
+ * @param options Scrollerator configuration.
29
+ * @returns Drive and reset controls for the controller.
30
+ */
16
31
  declare function initVScrollerator({ baseSpeed, maxSpeed, stepDelay, baseRate, lineHeight, margin, car }?: ScrolleratorOptions): Scrollerator;
32
+ /** Scroll assist control object returned by initScrollAssist. */
17
33
  interface ScrollAssistControl {
34
+ /** Recompute assist visibility. */
18
35
  update: () => void;
36
+ /** Tear down observers and assist elements. */
19
37
  destroy: () => void;
20
38
  }
39
+ /** Configuration for scroll assist overlays. */
21
40
  interface ScrollAssistOptions {
41
+ /** Scroll speed in pixels per second. */
22
42
  pxPerSecond?: number;
43
+ /** Class name applied to assist overlays. */
23
44
  assistClassName?: string;
45
+ /** Enable vertical assist overlays. */
24
46
  vertical?: boolean;
47
+ /** Enable horizontal assist overlays. */
25
48
  horizontal?: boolean;
26
49
  }
50
+ /** Attach directional scroll assist overlays to an element.
51
+ * @param el Scrollable element to enhance.
52
+ * @param options Scroll assist configuration.
53
+ * @returns Scroll assist controls or void when the element is already managed.
54
+ */
27
55
  declare function initScrollAssist(el: HTMLElement, { pxPerSecond, assistClassName, vertical, horizontal }?: ScrollAssistOptions): ScrollAssistControl | void;
56
+ /** Remove scroll assist from an element.
57
+ * @param el Target element.
58
+ */
28
59
  declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
29
60
 
30
61
  declare global {
31
62
  interface T007Namespace {
63
+ /** Symbol used to mark virtual resources that should not load a real asset. */
32
64
  VIRTUAL_RESOURCE: symbol;
33
-
65
+ /** Cache used to deduplicate resource loading promises. */
34
66
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
67
+ /** Active scroll assist controllers keyed by element. */
35
68
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
69
+ /** Resize observer used by scroll assist controllers. */
36
70
  _scroller_r_observer?: ResizeObserver;
71
+ /** Mutation observer used by scroll assist controllers. */
37
72
  _scroller_m_observer?: MutationObserver;
38
73
  }
39
-
40
74
  interface Window {
75
+ /** Shared T007 namespace. */
41
76
  t007: T007Namespace;
42
-
77
+ /** CDN entrypoint for @t007/toast. */
43
78
  T007_TOAST_JS_SRC?: string;
79
+ /** CDN entrypoint for @t007/input. */
44
80
  T007_INPUT_JS_SRC?: string;
81
+ /** CDN entrypoint for @t007/dialog. */
45
82
  T007_DIALOG_JS_SRC?: string;
46
-
83
+ /** CDN stylesheet for @t007/toast. */
47
84
  T007_TOAST_CSS_SRC?: string;
85
+ /** CDN stylesheet for @t007/input. */
48
86
  T007_INPUT_CSS_SRC?: string;
87
+ /** CDN stylesheet for @t007/dialog. */
49
88
  T007_DIALOG_CSS_SRC?: string;
50
89
  }
51
-
90
+ /** Shared T007 namespace on the global object. */
52
91
  var t007: T007Namespace;
53
92
  }
54
93
 
@@ -64,40 +103,98 @@ declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
64
103
  declare function isFunc<T extends Function = Function>(val: any): val is T;
65
104
  declare function inBoolArrOpt(opt: any, str: string): boolean;
66
105
 
106
+ /** Create a short unique string with an optional prefix.
107
+ * @param prefix Prefix added to the generated id.
108
+ * @returns A browser-safe unique id string.
109
+ */
67
110
  declare function uid(prefix?: string): string;
111
+ /** Compare two URLs after normalizing origin, pathname, and separators.
112
+ * @param src1 First URL or path.
113
+ * @param src2 Second URL or path.
114
+ * @returns True when both references point to the same resource.
115
+ */
68
116
  declare function isSameURL(src1: unknown, src2: unknown): boolean;
69
117
 
70
118
  interface LimitedOptions {
71
- key?: string /** Key for localStorage persistence (if omitted, uses session-only) */;
72
- maxTimes?: number /** Max times to call (default: 1) */;
119
+ /** Storage key used to persist call counts. */
120
+ key?: string;
121
+ /** Maximum number of allowed calls. */
122
+ maxTimes?: number;
73
123
  }
74
124
  interface LimitedHandle<T extends (...args: any[]) => any> {
125
+ /** Call the wrapped function with the original arguments. */
75
126
  (...args: Parameters<T>): ReturnType<T> | void;
127
+ /** Number of calls already consumed in the current session. */
76
128
  count: number;
129
+ /** Number of calls left before the limit is reached. */
77
130
  left: number;
131
+ /** Reset the call counter. */
78
132
  reset: () => void;
133
+ /** Consume the full allowance and block further calls. */
79
134
  block: () => void;
80
135
  }
136
+ /** Limit how many times a function may run.
137
+ * @param FN_KEY Storage namespace used to persist the counter.
138
+ * @param fn Function to wrap.
139
+ * @param opts Call limit settings or a storage key string.
140
+ * @returns Wrapped function with count, reset, and block helpers.
141
+ */
81
142
  declare function limited<T extends (...args: any[]) => any>(FN_KEY: string, fn: T, opts?: LimitedOptions | string): LimitedHandle<T>;
143
+ /** Resolve on the next task tick.
144
+ * @param timeout Delay in milliseconds.
145
+ * @returns Promise that resolves after the timeout.
146
+ */
82
147
  declare const mockAsync: (timeout?: number) => Promise<void>;
148
+ /** Resolve on the next animation frame.
149
+ * @param w Window-like object used for scheduling.
150
+ * @returns Promise that resolves on the next frame.
151
+ */
83
152
  declare const breath: (w?: Window & typeof globalThis) => Promise<unknown>;
153
+ /** Resolve after two animation frames.
154
+ * @param w Window-like object used for scheduling.
155
+ * @returns Promise that resolves after layout has had two frames to settle.
156
+ */
84
157
  declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
158
+ /** Run cleanup immediately or on abort, then return the callable cleanup.
159
+ * @param cleanup Cleanup function to protect.
160
+ * @param signal Optional abort signal.
161
+ * @returns The wrapped cleanup function.
162
+ */
85
163
  declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
86
164
 
165
+ /** Resource type accepted by loadResource. */
87
166
  type ResourceType = "style" | "script" | string;
167
+ /** Options used when loading a script or stylesheet resource. */
88
168
  type LoadResourceOptions = Partial<{
169
+ /** Load the script as a module. */
89
170
  module: boolean;
171
+ /** Media query applied to loaded stylesheets. */
90
172
  media: string;
173
+ /** crossorigin attribute for the resource element. */
91
174
  crossOrigin: "anonymous" | "use-credentials" | string | null;
175
+ /** Subresource integrity hash. */
92
176
  integrity: string;
177
+ /** Referrer policy for the resource element. */
93
178
  referrerPolicy: "no-referrer" | "origin" | "strict-origin-when-cross-origin" | string;
179
+ /** nonce attribute for CSP-enabled environments. */
94
180
  nonce: string;
181
+ /** fetchpriority hint for the browser. */
95
182
  fetchPriority: "high" | "low" | "auto";
183
+ /** Number of attempts before rejecting. */
96
184
  attempts: number;
185
+ /** Cache-busting retry token key. */
97
186
  retryKey: boolean | string;
98
187
  }>;
99
188
 
189
+ /** Virtual resource marker used to skip real network loading. */
100
190
  declare const VIRTUAL_RESOURCE: symbol;
191
+ /** Load a stylesheet or script into the current document with retry support.
192
+ * @param req Resource URL or virtual resource symbol.
193
+ * @param type Resource type to load.
194
+ * @param options Resource loading options.
195
+ * @param w Window-like target used for DOM insertion.
196
+ * @returns Promise resolving to the created element or void.
197
+ */
101
198
  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>;
102
199
 
103
200
  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,54 +1,93 @@
1
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
+ /** Configuration for the vertical edge-scrolling helper. */
3
4
  interface ScrolleratorOptions {
5
+ /** Starting lines-per-second speed. */
4
6
  baseSpeed?: number;
7
+ /** Maximum accelerated speed. */
5
8
  maxSpeed?: number;
9
+ /** Delay before acceleration kicks in. */
6
10
  stepDelay?: number;
11
+ /** Base frame rate used to estimate movement. */
7
12
  baseRate?: number;
13
+ /** Approximate line height in pixels. */
8
14
  lineHeight?: number;
15
+ /** Edge margin that triggers scrolling. */
9
16
  margin?: number;
17
+ /** Scroll container or window target. */
10
18
  car?: Window | HTMLElement;
11
19
  }
20
+ /** Scrolling controls returned by initVScrollerator. */
12
21
  interface Scrollerator {
22
+ /** Trigger a scroll frame and return the computed distance. */
13
23
  drive: (clientY: number, brake?: boolean, offsetY?: number) => number;
24
+ /** Reset speed and timers. */
14
25
  reset: () => void;
15
26
  }
27
+ /** Create an edge-driven vertical scrolling controller.
28
+ * @param options Scrollerator configuration.
29
+ * @returns Drive and reset controls for the controller.
30
+ */
16
31
  declare function initVScrollerator({ baseSpeed, maxSpeed, stepDelay, baseRate, lineHeight, margin, car }?: ScrolleratorOptions): Scrollerator;
32
+ /** Scroll assist control object returned by initScrollAssist. */
17
33
  interface ScrollAssistControl {
34
+ /** Recompute assist visibility. */
18
35
  update: () => void;
36
+ /** Tear down observers and assist elements. */
19
37
  destroy: () => void;
20
38
  }
39
+ /** Configuration for scroll assist overlays. */
21
40
  interface ScrollAssistOptions {
41
+ /** Scroll speed in pixels per second. */
22
42
  pxPerSecond?: number;
43
+ /** Class name applied to assist overlays. */
23
44
  assistClassName?: string;
45
+ /** Enable vertical assist overlays. */
24
46
  vertical?: boolean;
47
+ /** Enable horizontal assist overlays. */
25
48
  horizontal?: boolean;
26
49
  }
50
+ /** Attach directional scroll assist overlays to an element.
51
+ * @param el Scrollable element to enhance.
52
+ * @param options Scroll assist configuration.
53
+ * @returns Scroll assist controls or void when the element is already managed.
54
+ */
27
55
  declare function initScrollAssist(el: HTMLElement, { pxPerSecond, assistClassName, vertical, horizontal }?: ScrollAssistOptions): ScrollAssistControl | void;
56
+ /** Remove scroll assist from an element.
57
+ * @param el Target element.
58
+ */
28
59
  declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
29
60
 
30
61
  declare global {
31
62
  interface T007Namespace {
63
+ /** Symbol used to mark virtual resources that should not load a real asset. */
32
64
  VIRTUAL_RESOURCE: symbol;
33
-
65
+ /** Cache used to deduplicate resource loading promises. */
34
66
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
67
+ /** Active scroll assist controllers keyed by element. */
35
68
  _scrollers?: WeakMap<HTMLElement, ScrollAssistControl>;
69
+ /** Resize observer used by scroll assist controllers. */
36
70
  _scroller_r_observer?: ResizeObserver;
71
+ /** Mutation observer used by scroll assist controllers. */
37
72
  _scroller_m_observer?: MutationObserver;
38
73
  }
39
-
40
74
  interface Window {
75
+ /** Shared T007 namespace. */
41
76
  t007: T007Namespace;
42
-
77
+ /** CDN entrypoint for @t007/toast. */
43
78
  T007_TOAST_JS_SRC?: string;
79
+ /** CDN entrypoint for @t007/input. */
44
80
  T007_INPUT_JS_SRC?: string;
81
+ /** CDN entrypoint for @t007/dialog. */
45
82
  T007_DIALOG_JS_SRC?: string;
46
-
83
+ /** CDN stylesheet for @t007/toast. */
47
84
  T007_TOAST_CSS_SRC?: string;
85
+ /** CDN stylesheet for @t007/input. */
48
86
  T007_INPUT_CSS_SRC?: string;
87
+ /** CDN stylesheet for @t007/dialog. */
49
88
  T007_DIALOG_CSS_SRC?: string;
50
89
  }
51
-
90
+ /** Shared T007 namespace on the global object. */
52
91
  var t007: T007Namespace;
53
92
  }
54
93
 
@@ -64,40 +103,98 @@ declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
64
103
  declare function isFunc<T extends Function = Function>(val: any): val is T;
65
104
  declare function inBoolArrOpt(opt: any, str: string): boolean;
66
105
 
106
+ /** Create a short unique string with an optional prefix.
107
+ * @param prefix Prefix added to the generated id.
108
+ * @returns A browser-safe unique id string.
109
+ */
67
110
  declare function uid(prefix?: string): string;
111
+ /** Compare two URLs after normalizing origin, pathname, and separators.
112
+ * @param src1 First URL or path.
113
+ * @param src2 Second URL or path.
114
+ * @returns True when both references point to the same resource.
115
+ */
68
116
  declare function isSameURL(src1: unknown, src2: unknown): boolean;
69
117
 
70
118
  interface LimitedOptions {
71
- key?: string /** Key for localStorage persistence (if omitted, uses session-only) */;
72
- maxTimes?: number /** Max times to call (default: 1) */;
119
+ /** Storage key used to persist call counts. */
120
+ key?: string;
121
+ /** Maximum number of allowed calls. */
122
+ maxTimes?: number;
73
123
  }
74
124
  interface LimitedHandle<T extends (...args: any[]) => any> {
125
+ /** Call the wrapped function with the original arguments. */
75
126
  (...args: Parameters<T>): ReturnType<T> | void;
127
+ /** Number of calls already consumed in the current session. */
76
128
  count: number;
129
+ /** Number of calls left before the limit is reached. */
77
130
  left: number;
131
+ /** Reset the call counter. */
78
132
  reset: () => void;
133
+ /** Consume the full allowance and block further calls. */
79
134
  block: () => void;
80
135
  }
136
+ /** Limit how many times a function may run.
137
+ * @param FN_KEY Storage namespace used to persist the counter.
138
+ * @param fn Function to wrap.
139
+ * @param opts Call limit settings or a storage key string.
140
+ * @returns Wrapped function with count, reset, and block helpers.
141
+ */
81
142
  declare function limited<T extends (...args: any[]) => any>(FN_KEY: string, fn: T, opts?: LimitedOptions | string): LimitedHandle<T>;
143
+ /** Resolve on the next task tick.
144
+ * @param timeout Delay in milliseconds.
145
+ * @returns Promise that resolves after the timeout.
146
+ */
82
147
  declare const mockAsync: (timeout?: number) => Promise<void>;
148
+ /** Resolve on the next animation frame.
149
+ * @param w Window-like object used for scheduling.
150
+ * @returns Promise that resolves on the next frame.
151
+ */
83
152
  declare const breath: (w?: Window & typeof globalThis) => Promise<unknown>;
153
+ /** Resolve after two animation frames.
154
+ * @param w Window-like object used for scheduling.
155
+ * @returns Promise that resolves after layout has had two frames to settle.
156
+ */
84
157
  declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
158
+ /** Run cleanup immediately or on abort, then return the callable cleanup.
159
+ * @param cleanup Cleanup function to protect.
160
+ * @param signal Optional abort signal.
161
+ * @returns The wrapped cleanup function.
162
+ */
85
163
  declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
86
164
 
165
+ /** Resource type accepted by loadResource. */
87
166
  type ResourceType = "style" | "script" | string;
167
+ /** Options used when loading a script or stylesheet resource. */
88
168
  type LoadResourceOptions = Partial<{
169
+ /** Load the script as a module. */
89
170
  module: boolean;
171
+ /** Media query applied to loaded stylesheets. */
90
172
  media: string;
173
+ /** crossorigin attribute for the resource element. */
91
174
  crossOrigin: "anonymous" | "use-credentials" | string | null;
175
+ /** Subresource integrity hash. */
92
176
  integrity: string;
177
+ /** Referrer policy for the resource element. */
93
178
  referrerPolicy: "no-referrer" | "origin" | "strict-origin-when-cross-origin" | string;
179
+ /** nonce attribute for CSP-enabled environments. */
94
180
  nonce: string;
181
+ /** fetchpriority hint for the browser. */
95
182
  fetchPriority: "high" | "low" | "auto";
183
+ /** Number of attempts before rejecting. */
96
184
  attempts: number;
185
+ /** Cache-busting retry token key. */
97
186
  retryKey: boolean | string;
98
187
  }>;
99
188
 
189
+ /** Virtual resource marker used to skip real network loading. */
100
190
  declare const VIRTUAL_RESOURCE: symbol;
191
+ /** Load a stylesheet or script into the current document with retry support.
192
+ * @param req Resource URL or virtual resource symbol.
193
+ * @param type Resource type to load.
194
+ * @param options Resource loading options.
195
+ * @param w Window-like target used for DOM insertion.
196
+ * @returns Promise resolving to the created element or void.
197
+ */
101
198
  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>;
102
199
 
103
200
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
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.25"
48
+ "sia-reactor": "^0.0.30"
49
49
  }
50
50
  }