@t007/utils 0.0.33 → 0.0.35

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.ts CHANGED
@@ -1,19 +1,22 @@
1
- import { A as ArrowNavigationHandle } from './arrowNavigation-VenvPI4H.js';
2
- import { S as ScrollAssistHandle } from './scrollAssist-y9wFmYgt.js';
1
+ import { A as ArrowNavigationHandle } from './arrowNavigation-B9bEdoqR.js';
2
+ import { F as FocusTrapHandle, S as ScrollAssistHandle } from './scrollAssist-BNvPnsJq.js';
3
3
  export { NIL, NOOP } from 'sia-reactor';
4
- export { KeyStruct, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getActiveEl, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, keysSettings, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
4
+ export { KEYS_BLOCKS, KeyStruct, KeysSettings, assignEl, bindAllMethods, clamp, cleanKeyCombo, createEl, formatKeyForDisplay, formatKeyShortcutsForDisplay, getActiveEl, getTermsForKey, guardAllMethods, guardMethod, isObj, keyEventAllowed, matchKeys, onAllMethods, parseForARIAKS, parseKeyCombo, requestAnimationFrame, setInterval, setTimeout, stringifyKeyEvent } from 'sia-reactor/utils';
5
5
 
6
6
  declare global {
7
7
  interface T007Namespace {
8
8
  /** Symbol used to mark virtual resources that should not load a real asset. */
9
9
  VIRTUAL_RESOURCE: symbol;
10
10
  _resourceCache: Partial<Record<string, Promise<HTMLElement | void>>>;
11
- _ftrappers?: WeakMap<HTMLElement, () => void>;
11
+ _throttlers?: Map<string, number>;
12
+ _debouncers?: Map<string, number>;
13
+ _RAFLoopers?: Map<string, Function>;
14
+ _ftrappers?: WeakMap<HTMLElement, FocusTrapHandle>;
12
15
  _outsiders?: WeakMap<HTMLElement, () => void>;
13
16
  _arrownavs?: WeakMap<HTMLElement, ArrowNavigationHandle>;
14
17
  _scrollers?: WeakMap<HTMLElement, ScrollAssistHandle>;
15
- _ftrappers_stacks?: WeakMap<EventTarget, HTMLElement[]>;
16
- _outsiders_stacks?: WeakMap<EventTarget, HTMLElement[]>;
18
+ _ftrappers_stack?: HTMLElement[];
19
+ _outsiders_stack?: HTMLElement[];
17
20
  _scrollers_r_observer?: ResizeObserver;
18
21
  _scrollers_m_observer?: MutationObserver;
19
22
  }
@@ -37,6 +40,27 @@ declare global {
37
40
  var t007: T007Namespace;
38
41
  }
39
42
 
43
+ type TitleCase<S extends string> = S extends `${infer First}${infer Rest}`
44
+ ? `${Uppercase<First>}${Rest}`
45
+ : S;
46
+
47
+ type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${infer P3}`
48
+ ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
49
+ : S extends `${infer P1}-${infer P2}${infer P3}`
50
+ ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
51
+ : S extends `${infer P1} ${infer P2}${infer P3}`
52
+ ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
53
+ : Lowercase<S>;
54
+
55
+ type NoCamelCase<
56
+ S extends string,
57
+ Sep extends string = " "
58
+ > = S extends `${infer First}${infer Rest}`
59
+ ? First extends Uppercase<First>
60
+ ? `${Sep}${Lowercase<First>}${NoCamelCase<Rest, Sep>}`
61
+ : `${First}${NoCamelCase<Rest, Sep>}`
62
+ : S;
63
+
40
64
  declare function isDef(val: any): boolean;
41
65
  declare function isSym<T extends symbol = symbol>(val: any): val is T;
42
66
  declare function isBool<T extends boolean = boolean>(val: any): val is T;
@@ -49,20 +73,52 @@ declare function isIter<T = unknown>(obj: any): obj is Iterable<T>;
49
73
  declare function isFunc<T extends Function = Function>(val: any): val is T;
50
74
  declare function inBoolArrOpt(opt: any, str: string): boolean;
51
75
 
76
+ /**
77
+ * Finds the longest increasing subsequence in an array of numbers.
78
+ * @param array The input array of numbers
79
+ * @returns An array of indices representing the longest increasing subsequence
80
+ */
81
+ declare function longestIncreasingSubsequence(array: number[]): number[];
82
+
52
83
  /** Create a short unique string with an optional prefix.
53
84
  * @param prefix Prefix added to the generated id.
54
85
  * @returns A browser-safe unique id string.
55
86
  */
56
87
  declare function uid(prefix?: string): string;
88
+ /** Capitalize the first letter of a string, leaving the rest unchanged.
89
+ * @param word The string to capitalize.
90
+ * @returns The input string with the first letter capitalized.
91
+ */
92
+ declare function capitalize<T extends string>(word?: T): TitleCase<T>;
93
+ /** Convert a string to camelCase by removing separators and capitalizing subsequent words.
94
+ * @param str The input string to convert.
95
+ * @param options.source A regex or string defining word separators. @default whitespace, underscores, and hyphens (`[\s_-]+`).
96
+ * @param options.preserveInnerCase If true, preserves the original casing of letters; if false, converts the entire string to lowercase before processing. @default `true`.
97
+ * @param options.upperFirst If true, capitalizes the first letter of the resulting string (PascalCase); if false, lowercases the first letter (camelCase). @default `false`.
98
+ * @returns The camelCase version of the input string.
99
+ */
100
+ declare function camelize<T extends string>(str?: T, { source }?: RegExp, { preserveInnerCase: pIC, upperFirst: uF }?: {
101
+ preserveInnerCase?: boolean | undefined;
102
+ upperFirst?: boolean | undefined;
103
+ }): CamelCase<T>;
104
+ /** Convert a camelCase or PascalCase string to a separator-based format (e.g. "helloWorld" to "hello-world").
105
+ * @param str The camelCase or PascalCase string to convert.
106
+ * @param separator The string to insert between words. @default a hyphen ("-").
107
+ * @returns The uncamelized version of the input string with separators.
108
+ * @example
109
+ * uncamelize("helloWorld") // "hello-world"
110
+ * uncamelize("HelloWorld", "_") // "hello_world"
111
+ */
112
+ declare function uncamelize<T extends string, S extends string = " ">(str: T, separator?: S): NoCamelCase<T, S>;
57
113
  /** Convert a rem value to pixels based on the font size of a given element.
58
114
  * @param rem The rem value to convert.
59
- * @param el The element to use for font size reference. Defaults to the root element.
115
+ * @param el The element to use for font size reference. @default the root element.
60
116
  * @returns The equivalent pixel value.
61
117
  */
62
118
  declare function remToPx(rem: number, el?: HTMLElement): number;
63
119
  /** Convert a pixel value to rem based on the font size of a given element.
64
120
  * @param px The pixel value to convert.
65
- * @param el The element to use for font size reference. Defaults to the root element.
121
+ * @param el The element to use for font size reference. @default the root element.
66
122
  * @returns The equivalent rem value.
67
123
  */
68
124
  declare function pxToRem(px: number, el?: HTMLElement): number;
@@ -73,7 +129,7 @@ declare function pxToRem(px: number, el?: HTMLElement): number;
73
129
  declare function parseCSSTime(time: any): number;
74
130
  /** Parse a CSS size value (i.e. "16px" or "1.5rem") into pixels.
75
131
  * @param size The CSS size string to parse.
76
- * @param el The element to use for rem reference if needed. Defaults to the root element.
132
+ * @param el The element to use for rem reference if needed. @default the root element.
77
133
  * @returns The equivalent value in pixels.
78
134
  */
79
135
  declare function parseCSSSize(size: any, el?: HTMLElement): number;
@@ -89,11 +145,45 @@ declare function cleanURL(url: string): string;
89
145
  */
90
146
  declare function isSameURL(url1: unknown, url2: unknown): boolean;
91
147
 
148
+ /** Throttles a function, ensuring it's only called once within a specified delay period.
149
+ * @param key Unique identifier for the throttled function, used to track its last execution time.
150
+ * @param fn Function to be throttled.
151
+ * @param delay Time in milliseconds to wait before allowing the function to be called again. @default `30ms`.
152
+ * @param strict If `true`, exact timestamp difference between calls will be used else a `setTimeout()` will clear the throttle, allowing for more thread leniency. @default `true`.
153
+ * @param signal Optional `AbortSignal` to automatically clear the throttle when aborted.
154
+ * @param win Optional `Window` object for scheduling the throttle timeout, useful for testing or if running in a non-browser environment.
155
+ */
156
+ declare function throttle(key: string, fn: Function, delay?: number, strict?: ((fn: Function) => number) | boolean, signal?: AbortSignal, win?: Window): void;
157
+ /** Debounces a function, ensuring it's only called after a quiet period of no further calls.
158
+ * @param key Unique identifier for the debounced function, used to track pending calls.
159
+ * @param fn Function to be debounced.
160
+ * @param delay Time in milliseconds to wait after the latest call before invoking the function. @default `30ms`.
161
+ * @param strict If `true`, exact timestamp difference between calls will be used else pending timeout is reset each call for practical thread leniency. @default `true`.
162
+ * @param signal Optional `AbortSignal` to automatically clear scheduled debounce execution when aborted.
163
+ * @param win Optional `Window` object for scheduling/clearing the debounce timeout, useful for testing or if running in a non-browser environment.
164
+ */
165
+ declare function debounce(key: string, fn: Function, delay?: number, strict?: boolean, signal?: AbortSignal, win?: Window): void;
166
+ /** Creates a loop using `requestAnimationFrame`, allowing for efficient execution of a function on every frame.
167
+ * @param key Unique identifier for the loop, used to manage its execution and allow for updates or cancellation.
168
+ * @param fn Function to be executed on every frame.
169
+ * @param signal Optional `AbortSignal` to automatically cancel the loop when aborted.
170
+ * @param win Optional `Window` object for scheduling the animation frame, useful for testing or if running in a non-browser environment.
171
+ *
172
+ * Game-like loops will be our lil secret... ~ "The Smoooth Criminal" :)
173
+ */
174
+ declare function RAFLoop(key: string, fn: Function, signal?: AbortSignal, win?: Window & typeof globalThis): void;
175
+ /** Cancels a loop created by `RAFLoop`.
176
+ * @param key Unique identifier for the loop to be cancelled.
177
+ * @returns True if the loop was successfully cancelled, false if no loop with the given key exists.
178
+ */
179
+ declare const cancelRAFLoop: (key: string) => boolean;
92
180
  interface LimitedOptions {
93
181
  /** Storage key used to persist call counts. */
94
182
  key?: string;
95
- /** Maximum number of allowed calls. */
183
+ /** Maximum number of allowed calls. @default 1 */
96
184
  maxTimes?: number;
185
+ /** Only allow calling once per session, regardless of maxTimes. @default true */
186
+ oncePerSession?: boolean;
97
187
  }
98
188
  interface LimitedHandle<T extends (...args: any[]) => any> {
99
189
  /** Call the wrapped function with the original arguments. */
@@ -137,7 +227,7 @@ declare const deepBreath: (w?: Window & typeof globalThis) => Promise<unknown>;
137
227
  declare function bindCleanupToSignal<Cb extends () => any>(cleanup: Cb, signal?: AbortSignal): Cb;
138
228
 
139
229
  /** Exhaustive Selector used for interactive, tabbable UI controls. */
140
- declare const INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable='true'],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
230
+ declare const INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
141
231
  /** Check whether an event target points to an interactive element. */
142
232
  declare const isInteractive: (target: EventTarget | null) => boolean;
143
233
  /** Resource type accepted by loadResource. */
@@ -169,16 +259,53 @@ declare const VIRTUAL_RESOURCE: symbol;
169
259
  * @param req Resource URL or virtual resource symbol.
170
260
  * @param type Resource type to load.
171
261
  * @param options Resource loading options.
172
- * @param w Window-like target used for DOM insertion.
262
+ * @param win Window-like target used for DOM insertion.
173
263
  * @returns Promise resolving to the created element or void.
174
264
  */
175
- 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>;
265
+ declare function loadResource(req: string | symbol, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, win?: Window & typeof globalThis): Promise<HTMLElement | void>;
176
266
 
177
267
  /** Get the window object associated with a given element.
178
268
  * @param el The element to get the window for, defaults to the main window.
179
- * @returns The window object or undefined if none found.
269
+ * @returns The `Window` object or undefined if none found.
270
+ */
271
+ declare function getWindow(el?: any): Window & typeof globalThis;
272
+ /** Options for configuring a list renderer */
273
+ type ListRendererOptions<T, El extends HTMLElement = HTMLElement> = {
274
+ /** The container element to render the list into */
275
+ container: HTMLElement;
276
+ /** Function to extract a unique key from each item.
277
+ * @param item The item to extract the key from
278
+ * @returns A unique string key for the item
279
+ */
280
+ getKey: (item: T) => string;
281
+ /** Function to create a DOM node for an item.
282
+ * @param item The item to create a node for
283
+ * @returns An HTMLElement representing the item, or null/undefined to skip rendering
284
+ */
285
+ createNode: (item: T) => El | null | undefined;
286
+ /** Optional function to update an existing node with new item data, called when an item is reused.
287
+ * @param node The existing DOM node for the item
288
+ * @param item The new item data to update the node with
289
+ */
290
+ updateNode?: (node: El, item: T) => void;
291
+ /** Optional function to clean up a DOM node when an item is removed, called before the node is removed from the DOM.
292
+ * @param node The DOM node to be removed
293
+ * @param key The unique key of the item associated with the node
294
+ */
295
+ destroyNode?: (node: El, key: string) => void;
296
+ /** Optional function called once during initialization for each existing child node in the container.
297
+ * Allows seeding the registry with pre-existing markup so nodes are reused instead of destroyed.
298
+ * @param node The pre-existing DOM node
299
+ * @param register A callback to register the node with its corresponding item key
300
+ */
301
+ initNode?: (node: El, register: (key: string) => void) => void;
302
+ };
303
+ /**
304
+ * Creates a list renderer function for efficiently updating a DOM list based on a new array of items using the L.I.S(Longest Increasing Subsequence) algorithm.
305
+ * @param param0 The options for configuring the list renderer
306
+ * @returns A function that synchronizes the DOM with the new array of items
180
307
  */
181
- declare function getWindow(el?: any): (Window & typeof globalThis) | undefined;
308
+ declare function createListRenderer<T, El extends HTMLElement = HTMLElement>({ container, getKey, createNode, updateNode, destroyNode, initNode }: ListRendererOptions<T, El>): (array: T[], strict?: boolean) => void;
182
309
 
183
310
  /** Format a file size for display.
184
311
  * @param size Size in bytes.
@@ -188,4 +315,4 @@ declare function getWindow(el?: any): (Window & typeof globalThis) | undefined;
188
315
  */
189
316
  declare function formatSize(bytes: number, decimals?: number, base?: number): string;
190
317
 
191
- export { INTERACTIVE_SELECTOR, type LimitedHandle, type LimitedOptions, type LoadResourceOptions, type ResourceType, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, cleanURL, deepBreath, formatSize, getWindow, inBoolArrOpt, isArr, isBool, isDef, isFunc, isInteractive, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, mockAsync, parseCSSSize, parseCSSTime, pxToRem, remToPx, uid };
318
+ export { type CamelCase, INTERACTIVE_SELECTOR, type LimitedHandle, type LimitedOptions, type ListRendererOptions, type LoadResourceOptions, type NoCamelCase, RAFLoop, type ResourceType, type TitleCase, VIRTUAL_RESOURCE, bindCleanupToSignal, breath, camelize, cancelRAFLoop, capitalize, cleanURL, createListRenderer, debounce, deepBreath, formatSize, getWindow, inBoolArrOpt, isArr, isBool, isDef, isFunc, isInteractive, isIter, isNum, isPOJO, isSameURL, isStr, isSym, limited, loadResource, longestIncreasingSubsequence, mockAsync, parseCSSSize, parseCSSTime, pxToRem, remToPx, throttle, uid, uncamelize };
package/dist/index.js CHANGED
@@ -1,16 +1,23 @@
1
1
  import {
2
2
  INTERACTIVE_SELECTOR,
3
+ KEYS_BLOCKS,
3
4
  NIL,
4
5
  NOOP,
6
+ RAFLoop,
5
7
  VIRTUAL_RESOURCE,
6
8
  assignEl,
7
9
  bindAllMethods,
8
10
  bindCleanupToSignal,
9
11
  breath,
12
+ camelize,
13
+ cancelRAFLoop,
14
+ capitalize,
10
15
  clamp,
11
16
  cleanKeyCombo,
12
17
  cleanURL,
13
18
  createEl,
19
+ createListRenderer,
20
+ debounce,
14
21
  deepBreath,
15
22
  formatKeyForDisplay,
16
23
  formatKeyShortcutsForDisplay,
@@ -36,6 +43,7 @@ import {
36
43
  keyEventAllowed,
37
44
  limited,
38
45
  loadResource,
46
+ longestIncreasingSubsequence,
39
47
  matchKeys,
40
48
  mockAsync,
41
49
  onAllMethods,
@@ -49,21 +57,30 @@ import {
49
57
  setInterval,
50
58
  setTimeout,
51
59
  stringifyKeyEvent,
52
- uid
53
- } from "./chunk-4O76EZJ4.js";
60
+ throttle,
61
+ uid,
62
+ uncamelize
63
+ } from "./chunk-ZALPHCSJ.js";
54
64
  export {
55
65
  INTERACTIVE_SELECTOR,
66
+ KEYS_BLOCKS,
56
67
  NIL,
57
68
  NOOP,
69
+ RAFLoop,
58
70
  VIRTUAL_RESOURCE,
59
71
  assignEl,
60
72
  bindAllMethods,
61
73
  bindCleanupToSignal,
62
74
  breath,
75
+ camelize,
76
+ cancelRAFLoop,
77
+ capitalize,
63
78
  clamp,
64
79
  cleanKeyCombo,
65
80
  cleanURL,
66
81
  createEl,
82
+ createListRenderer,
83
+ debounce,
67
84
  deepBreath,
68
85
  formatKeyForDisplay,
69
86
  formatKeyShortcutsForDisplay,
@@ -89,6 +106,7 @@ export {
89
106
  keyEventAllowed,
90
107
  limited,
91
108
  loadResource,
109
+ longestIncreasingSubsequence,
92
110
  matchKeys,
93
111
  mockAsync,
94
112
  onAllMethods,
@@ -102,5 +120,7 @@ export {
102
120
  setInterval,
103
121
  setTimeout,
104
122
  stringifyKeyEvent,
105
- uid
123
+ throttle,
124
+ uid,
125
+ uncamelize
106
126
  };
@@ -0,0 +1,55 @@
1
+ interface OutsideClickConfig {
2
+ /** Enables or disables outside-click handling. @default `false`. */
3
+ enabled?: boolean;
4
+ /** Callback invoked when an outside interaction is detected. @default `()=>{}`. */
5
+ onOutside?: (e: MouseEvent | TouchEvent | KeyboardEvent | FocusEvent) => void;
6
+ /** Whether pointer/touch outside interactions should trigger callback. @default `true`. */
7
+ outOnClick?: boolean;
8
+ /** Whether Escape key should trigger callback. @default `true`. */
9
+ outOnEscape?: boolean;
10
+ /** Whether focus leaving the container should trigger callback. @default `false`. */
11
+ outOnFocusOut?: boolean;
12
+ /** Allow only clicks inside `el` bounding client rectangle to be considered valid, otherwise uses `el.contains(target)`. @default `false . */
13
+ allowBounds?: boolean;
14
+ /** Allow interactive elements including outsiders to bypass click callback. @default `false`. */
15
+ allowInputs?: boolean;
16
+ /** Optional root used to scope focus listeners to an element instead of the window. @default `window`. */
17
+ root?: HTMLElement | Document | Window;
18
+ /** Whether the outside click handling is scoped to the root provided it is an HTMLElement. @default `true`. */
19
+ scoped?: boolean;
20
+ /** Passed down to all event listeners used. @default `true`. */
21
+ capture?: boolean;
22
+ }
23
+ /** Hook to attach outside-click, escape, and optional focus-out handling to an element. */
24
+ declare function initOutsideClick(el: HTMLElement, { enabled, onOutside, outOnClick, outOnEscape, outOnFocusOut, allowBounds, allowInputs, root, scoped, capture }?: OutsideClickConfig): (() => void) | void;
25
+ /** Remove outside-click handling from an element. */
26
+ declare const removeOutsideClick: (el: HTMLElement) => void | undefined;
27
+
28
+ interface RippleConfig {
29
+ /** Optional explicit ripple host element. @default event currentTarget. */
30
+ target?: HTMLElement | null;
31
+ /** Forces the ripple origin to the center of the host. By default, the ripple will originate from the pointer event coordinates. */
32
+ forceCenter?: boolean;
33
+ /** CSS class added to the ripple wrapper element. @default `"t007-ripple-wrapper"`. */
34
+ wrapperClassName?: string;
35
+ /** CSS general class added to the ripple element. @default `"t007-ripple"`. */
36
+ className?: string;
37
+ /** CSS class added to the ripple element while the pointer is held down. Should contain the initial expansion animation. @default `"t007-ripple-hold"`. */
38
+ holdClassName?: string;
39
+ /** CSS class added to the ripple element when released. Should contain the fade-out animation. @default `"t007-ripple-fade"`. */
40
+ fadeClassName?: string;
41
+ /** Maximum duration for the ripple animation, force-ejects when elapsed. @default 1000ms. */
42
+ maxDuration?: number;
43
+ }
44
+ /** Render and control a material-style ripple animation on an element.
45
+ * @param e Pointer event used to place and gate the ripple.
46
+ * @param options Ripple configuration options.
47
+ * @details
48
+ * The ripple will be triggered on the event's currentTarget by default, but an explicit target can be provided.
49
+ * The ripple will originate from the pointer coordinates relative to the target, unless forceCenter is enabled.
50
+ * The ripple element will receive a hold class until the pointer is released, at which point it will switch to a fade class and be removed after the animation completes.
51
+ * Pointer events that are not left-clicks or that originate from interactive elements other than the currentTarget will be ignored to prevent interference with native behaviors.
52
+ */
53
+ declare function rippleHandler(e: Pick<PointerEvent, "target" | "currentTarget" | "button" | "clientX" | "clientY" | "stopPropagation">, { target, forceCenter, wrapperClassName, className, holdClassName, fadeClassName, maxDuration }?: RippleConfig): void;
54
+
55
+ export { type OutsideClickConfig as O, type RippleConfig as R, rippleHandler as a, initOutsideClick as i, removeOutsideClick as r };
@@ -0,0 +1,55 @@
1
+ interface OutsideClickConfig {
2
+ /** Enables or disables outside-click handling. @default `false`. */
3
+ enabled?: boolean;
4
+ /** Callback invoked when an outside interaction is detected. @default `()=>{}`. */
5
+ onOutside?: (e: MouseEvent | TouchEvent | KeyboardEvent | FocusEvent) => void;
6
+ /** Whether pointer/touch outside interactions should trigger callback. @default `true`. */
7
+ outOnClick?: boolean;
8
+ /** Whether Escape key should trigger callback. @default `true`. */
9
+ outOnEscape?: boolean;
10
+ /** Whether focus leaving the container should trigger callback. @default `false`. */
11
+ outOnFocusOut?: boolean;
12
+ /** Allow only clicks inside `el` bounding client rectangle to be considered valid, otherwise uses `el.contains(target)`. @default `false . */
13
+ allowBounds?: boolean;
14
+ /** Allow interactive elements including outsiders to bypass click callback. @default `false`. */
15
+ allowInputs?: boolean;
16
+ /** Optional root used to scope focus listeners to an element instead of the window. @default `window`. */
17
+ root?: HTMLElement | Document | Window;
18
+ /** Whether the outside click handling is scoped to the root provided it is an HTMLElement. @default `true`. */
19
+ scoped?: boolean;
20
+ /** Passed down to all event listeners used. @default `true`. */
21
+ capture?: boolean;
22
+ }
23
+ /** Hook to attach outside-click, escape, and optional focus-out handling to an element. */
24
+ declare function initOutsideClick(el: HTMLElement, { enabled, onOutside, outOnClick, outOnEscape, outOnFocusOut, allowBounds, allowInputs, root, scoped, capture }?: OutsideClickConfig): (() => void) | void;
25
+ /** Remove outside-click handling from an element. */
26
+ declare const removeOutsideClick: (el: HTMLElement) => void | undefined;
27
+
28
+ interface RippleConfig {
29
+ /** Optional explicit ripple host element. @default event currentTarget. */
30
+ target?: HTMLElement | null;
31
+ /** Forces the ripple origin to the center of the host. By default, the ripple will originate from the pointer event coordinates. */
32
+ forceCenter?: boolean;
33
+ /** CSS class added to the ripple wrapper element. @default `"t007-ripple-wrapper"`. */
34
+ wrapperClassName?: string;
35
+ /** CSS general class added to the ripple element. @default `"t007-ripple"`. */
36
+ className?: string;
37
+ /** CSS class added to the ripple element while the pointer is held down. Should contain the initial expansion animation. @default `"t007-ripple-hold"`. */
38
+ holdClassName?: string;
39
+ /** CSS class added to the ripple element when released. Should contain the fade-out animation. @default `"t007-ripple-fade"`. */
40
+ fadeClassName?: string;
41
+ /** Maximum duration for the ripple animation, force-ejects when elapsed. @default 1000ms. */
42
+ maxDuration?: number;
43
+ }
44
+ /** Render and control a material-style ripple animation on an element.
45
+ * @param e Pointer event used to place and gate the ripple.
46
+ * @param options Ripple configuration options.
47
+ * @details
48
+ * The ripple will be triggered on the event's currentTarget by default, but an explicit target can be provided.
49
+ * The ripple will originate from the pointer coordinates relative to the target, unless forceCenter is enabled.
50
+ * The ripple element will receive a hold class until the pointer is released, at which point it will switch to a fade class and be removed after the animation completes.
51
+ * Pointer events that are not left-clicks or that originate from interactive elements other than the currentTarget will be ignored to prevent interference with native behaviors.
52
+ */
53
+ declare function rippleHandler(e: Pick<PointerEvent, "target" | "currentTarget" | "button" | "clientX" | "clientY" | "stopPropagation">, { target, forceCenter, wrapperClassName, className, holdClassName, fadeClassName, maxDuration }?: RippleConfig): void;
54
+
55
+ export { type OutsideClickConfig as O, type RippleConfig as R, rippleHandler as a, initOutsideClick as i, removeOutsideClick as r };
@@ -0,0 +1,97 @@
1
+ type KeyEvent = Partial<KeyboardEvent> & Pick<KeyboardEvent, "key">;
2
+ type Config = {
3
+ /** Enables or disables navigation logic. @default `null`. */
4
+ enabled?: boolean | null;
5
+ /** CSS selector used to collect focusable nav items. @default `"[data-arrow-item]"` */
6
+ selector?: string;
7
+ /** Whether hover should also move active selection. @default `true`. */
8
+ focusOnHover?: boolean;
9
+ /** Whether directional movement wraps around edges. @default `true`. */
10
+ loop?: boolean;
11
+ /** Enables virtual focus (aria-activedescendant) mode. @default `false`. */
12
+ virtual?: boolean;
13
+ /** Enables alphanumeric type-ahead matching. @default `false`. */
14
+ typeahead?: boolean;
15
+ /** Idle timeout before clearing type-ahead buffer (ms). @default `500`. */
16
+ resetMs?: number;
17
+ /** Explicit RTL override; null auto-detects from computed style. @default `null`. */
18
+ rtl?: boolean | null;
19
+ /** Enables roving tabindex when not in virtual mode. @default `null`. */
20
+ rovingTab?: boolean | null;
21
+ /** Default tabbable index when no active item is selected. @default `null`. */
22
+ defaultTabbableIndex?: number | null;
23
+ /** Base tabindex for non-active items, use `"-1"` to kill virtual list. @default `"0"`. */
24
+ baseTabIndex?: string;
25
+ /** Class applied to active item in virtual mode. @default `"focus-outlined"`. */
26
+ activeClass?: string;
27
+ /** Selector used for keyboard event source in virtual mode. @default `"input[value],textarea,[contenteditable]"`. */
28
+ inputSelector?: string;
29
+ /** Scroll behavior options used when moving active item. @default `{ block: "nearest", inline: "nearest" }`. */
30
+ scrollIntoView?: ScrollIntoViewOptions;
31
+ /** Focus behavior options used in non-virtual mode. @default `{ preventScroll: false }`. */
32
+ focusOptions?: FocusOptions;
33
+ /** Explicit or computed grid dimensions for navigation math. @default `{}`. */
34
+ grid?: Partial<Record<"x" | "y" | "vY", number>>;
35
+ /** Callback fired when an item becomes active/selected. */
36
+ onSelect?: (el: HTMLElement, e: KeyEvent) => void;
37
+ /** Callback fired when focus leaves the navigation container. */
38
+ onFocusOut?: (e: FocusEvent) => void;
39
+ };
40
+
41
+ interface FocusTrapConfig {
42
+ /** Enables or disables the focus trap. @default `false`. */
43
+ enabled?: boolean;
44
+ /** The preferred initial focus target selector within the element, overrides whatever was focused. Try `autofocus` attribute if working with dialogs before this. @default `[data-autofocus]`. */
45
+ initialSelector?: string;
46
+ /** The class name for the initial focus ring since programmatic focus is not always visible, `autofocus` attribute in dialogs might work fine as an alternative. @default `"focus-outline"`. */
47
+ ringClassName?: string;
48
+ /** Optional root used to scope focus listeners to an element instead of the window. @default `window`. */
49
+ root?: HTMLElement | Document | Window;
50
+ /** Whether the focus trap is scoped to the root provided it is an HTMLElement. @default `true`. */
51
+ scoped?: boolean;
52
+ /** Passed down to all event listeners used. @default `true`. */
53
+ capture?: boolean;
54
+ }
55
+ interface FocusTrapHandle {
56
+ destroy: () => void;
57
+ sync: () => void;
58
+ }
59
+ /** Hook to keep focus trapped inside an element until disabled. */
60
+ declare function initFocusTrap(el: HTMLElement, { enabled, initialSelector, ringClassName, root, scoped, capture }?: FocusTrapConfig): FocusTrapHandle | void;
61
+ /** Remove the focus trap guard from an element. */
62
+ declare const removeFocusTrap: (el: HTMLElement) => void | undefined;
63
+ /** Synchronize the focus trap guards. */
64
+ declare const syncFocusTrap: (el: HTMLElement) => void | undefined;
65
+
66
+ type ScrollDir = "left" | "right" | "up" | "down";
67
+ /** Scroll assist control object returned by initScrollAssist. */
68
+ interface ScrollAssistHandle {
69
+ /** Recompute assist visibility. */
70
+ update: () => void;
71
+ /** Tear down observers and assist elements. */
72
+ destroy: () => void;
73
+ }
74
+ /** Configuration for scroll assist overlays. */
75
+ interface ScrollAssistConfig {
76
+ /** Scroll speed in pixels per second. @default `80`. */
77
+ pxPerSecond?: number;
78
+ /** Class name applied to assist overlays. @default `"t007-scroll-assist"`. */
79
+ assistClassName?: string;
80
+ /** Enable vertical assist overlays. @default `true`. */
81
+ vertical?: boolean;
82
+ /** Enable horizontal assist overlays. @default `true`. */
83
+ horizontal?: boolean;
84
+ }
85
+ /** Hook to add edge-scrolling assist to an element. It creates invisible "hot zones" at the edges of the element that, when hovered or dragged into, will scroll the element in that direction.
86
+ * The assist is automatically disabled when the element is too small or contains interactive elements near the edges to prevent interference.
87
+ * @param el Scrollable element to enhance.
88
+ * @param options Scroll assist configuration.
89
+ * @returns Scroll assist controls or void when the element is already managed.
90
+ */
91
+ declare function initScrollAssist(el: HTMLElement, { pxPerSecond, assistClassName, vertical, horizontal }?: ScrollAssistConfig): ScrollAssistHandle | void;
92
+ /** Remove scroll assist from an element.
93
+ * @param el Target element.
94
+ */
95
+ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
96
+
97
+ export { type Config as C, type FocusTrapHandle as F, type KeyEvent as K, type ScrollAssistHandle as S, type ScrollAssistConfig as a, type FocusTrapConfig as b, type ScrollDir as c, initScrollAssist as d, removeScrollAssist as e, initFocusTrap as i, removeFocusTrap as r, syncFocusTrap as s };
@@ -0,0 +1,97 @@
1
+ type KeyEvent = Partial<KeyboardEvent> & Pick<KeyboardEvent, "key">;
2
+ type Config = {
3
+ /** Enables or disables navigation logic. @default `null`. */
4
+ enabled?: boolean | null;
5
+ /** CSS selector used to collect focusable nav items. @default `"[data-arrow-item]"` */
6
+ selector?: string;
7
+ /** Whether hover should also move active selection. @default `true`. */
8
+ focusOnHover?: boolean;
9
+ /** Whether directional movement wraps around edges. @default `true`. */
10
+ loop?: boolean;
11
+ /** Enables virtual focus (aria-activedescendant) mode. @default `false`. */
12
+ virtual?: boolean;
13
+ /** Enables alphanumeric type-ahead matching. @default `false`. */
14
+ typeahead?: boolean;
15
+ /** Idle timeout before clearing type-ahead buffer (ms). @default `500`. */
16
+ resetMs?: number;
17
+ /** Explicit RTL override; null auto-detects from computed style. @default `null`. */
18
+ rtl?: boolean | null;
19
+ /** Enables roving tabindex when not in virtual mode. @default `null`. */
20
+ rovingTab?: boolean | null;
21
+ /** Default tabbable index when no active item is selected. @default `null`. */
22
+ defaultTabbableIndex?: number | null;
23
+ /** Base tabindex for non-active items, use `"-1"` to kill virtual list. @default `"0"`. */
24
+ baseTabIndex?: string;
25
+ /** Class applied to active item in virtual mode. @default `"focus-outlined"`. */
26
+ activeClass?: string;
27
+ /** Selector used for keyboard event source in virtual mode. @default `"input[value],textarea,[contenteditable]"`. */
28
+ inputSelector?: string;
29
+ /** Scroll behavior options used when moving active item. @default `{ block: "nearest", inline: "nearest" }`. */
30
+ scrollIntoView?: ScrollIntoViewOptions;
31
+ /** Focus behavior options used in non-virtual mode. @default `{ preventScroll: false }`. */
32
+ focusOptions?: FocusOptions;
33
+ /** Explicit or computed grid dimensions for navigation math. @default `{}`. */
34
+ grid?: Partial<Record<"x" | "y" | "vY", number>>;
35
+ /** Callback fired when an item becomes active/selected. */
36
+ onSelect?: (el: HTMLElement, e: KeyEvent) => void;
37
+ /** Callback fired when focus leaves the navigation container. */
38
+ onFocusOut?: (e: FocusEvent) => void;
39
+ };
40
+
41
+ interface FocusTrapConfig {
42
+ /** Enables or disables the focus trap. @default `false`. */
43
+ enabled?: boolean;
44
+ /** The preferred initial focus target selector within the element, overrides whatever was focused. Try `autofocus` attribute if working with dialogs before this. @default `[data-autofocus]`. */
45
+ initialSelector?: string;
46
+ /** The class name for the initial focus ring since programmatic focus is not always visible, `autofocus` attribute in dialogs might work fine as an alternative. @default `"focus-outline"`. */
47
+ ringClassName?: string;
48
+ /** Optional root used to scope focus listeners to an element instead of the window. @default `window`. */
49
+ root?: HTMLElement | Document | Window;
50
+ /** Whether the focus trap is scoped to the root provided it is an HTMLElement. @default `true`. */
51
+ scoped?: boolean;
52
+ /** Passed down to all event listeners used. @default `true`. */
53
+ capture?: boolean;
54
+ }
55
+ interface FocusTrapHandle {
56
+ destroy: () => void;
57
+ sync: () => void;
58
+ }
59
+ /** Hook to keep focus trapped inside an element until disabled. */
60
+ declare function initFocusTrap(el: HTMLElement, { enabled, initialSelector, ringClassName, root, scoped, capture }?: FocusTrapConfig): FocusTrapHandle | void;
61
+ /** Remove the focus trap guard from an element. */
62
+ declare const removeFocusTrap: (el: HTMLElement) => void | undefined;
63
+ /** Synchronize the focus trap guards. */
64
+ declare const syncFocusTrap: (el: HTMLElement) => void | undefined;
65
+
66
+ type ScrollDir = "left" | "right" | "up" | "down";
67
+ /** Scroll assist control object returned by initScrollAssist. */
68
+ interface ScrollAssistHandle {
69
+ /** Recompute assist visibility. */
70
+ update: () => void;
71
+ /** Tear down observers and assist elements. */
72
+ destroy: () => void;
73
+ }
74
+ /** Configuration for scroll assist overlays. */
75
+ interface ScrollAssistConfig {
76
+ /** Scroll speed in pixels per second. @default `80`. */
77
+ pxPerSecond?: number;
78
+ /** Class name applied to assist overlays. @default `"t007-scroll-assist"`. */
79
+ assistClassName?: string;
80
+ /** Enable vertical assist overlays. @default `true`. */
81
+ vertical?: boolean;
82
+ /** Enable horizontal assist overlays. @default `true`. */
83
+ horizontal?: boolean;
84
+ }
85
+ /** Hook to add edge-scrolling assist to an element. It creates invisible "hot zones" at the edges of the element that, when hovered or dragged into, will scroll the element in that direction.
86
+ * The assist is automatically disabled when the element is too small or contains interactive elements near the edges to prevent interference.
87
+ * @param el Scrollable element to enhance.
88
+ * @param options Scroll assist configuration.
89
+ * @returns Scroll assist controls or void when the element is already managed.
90
+ */
91
+ declare function initScrollAssist(el: HTMLElement, { pxPerSecond, assistClassName, vertical, horizontal }?: ScrollAssistConfig): ScrollAssistHandle | void;
92
+ /** Remove scroll assist from an element.
93
+ * @param el Target element.
94
+ */
95
+ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
96
+
97
+ export { type Config as C, type FocusTrapHandle as F, type KeyEvent as K, type ScrollAssistHandle as S, type ScrollAssistConfig as a, type FocusTrapConfig as b, type ScrollDir as c, initScrollAssist as d, removeScrollAssist as e, initFocusTrap as i, removeFocusTrap as r, syncFocusTrap as s };
@@ -1,7 +1,7 @@
1
1
  interface HighlightOptions {
2
- /** Whether to trim individual query strings. Defaults to `true`. */
2
+ /** Whether to trim individual query strings. @default `true`. */
3
3
  trimQuery?: boolean;
4
- /** Whether to match whole words only. Defaults to `false`. */
4
+ /** Whether to match whole words only. @default `false`. */
5
5
  wholeWord?: boolean;
6
6
  }
7
7
  /** React hook to process a text string and identify parts that match a given query, returning an array of text chunks with information on whether they match the query.
@@ -1,7 +1,7 @@
1
1
  interface HighlightOptions {
2
- /** Whether to trim individual query strings. Defaults to `true`. */
2
+ /** Whether to trim individual query strings. @default `true`. */
3
3
  trimQuery?: boolean;
4
- /** Whether to match whole words only. Defaults to `false`. */
4
+ /** Whether to match whole words only. @default `false`. */
5
5
  wholeWord?: boolean;
6
6
  }
7
7
  /** React hook to process a text string and identify parts that match a given query, returning an array of text chunks with information on whether they match the query.