@t007/utils 0.0.25 → 0.0.26

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.
@@ -0,0 +1,72 @@
1
+ type KeyEvent = Partial<KeyboardEvent> & Pick<KeyboardEvent, "key">;
2
+ type Config = {
3
+ /** Enables or disables navigation logic. Defaults to `null`. */
4
+ enabled?: boolean | null;
5
+ /** CSS selector used to collect focusable nav items. Defaults to `"[data-arrow-item]"` */
6
+ selector?: string;
7
+ /** Whether hover should also move active selection. Defaults to `true`. */
8
+ focusOnHover?: boolean;
9
+ /** Whether directional movement wraps around edges. Defaults to `true`. */
10
+ loop?: boolean;
11
+ /** Enables virtual focus (aria-activedescendant) mode. Defaults to `false`. */
12
+ virtual?: boolean;
13
+ /** Enables alphanumeric type-ahead matching. Defaults to `false`. */
14
+ typeahead?: boolean;
15
+ /** Idle timeout before clearing type-ahead buffer (ms). Defaults to `500`. */
16
+ resetMs?: number;
17
+ /** Explicit RTL override; null auto-detects from computed style. Defaults to `null`. */
18
+ rtl?: boolean | null;
19
+ /** Enables roving tabindex when not in virtual mode. Defaults to `null`. */
20
+ rovingTab?: boolean | null;
21
+ /** Default tabbable index when no active item is selected. Defaults to `null`. */
22
+ defaultTabbableIndex?: number | null;
23
+ /** Base tabindex for non-active items, use `"-1"` to kill virtual list. Defaults to `"0"`. */
24
+ baseTabIndex?: string;
25
+ /** Class applied to active item in virtual mode. Defaults to `"focus-outlined"`. */
26
+ activeClass?: string;
27
+ /** Selector used for keyboard event source in virtual mode. Defaults to `"input[value],textarea,[contenteditable='true']"`. */
28
+ inputSelector?: string;
29
+ /** Scroll behavior options used when moving active item. Defaults to `{ block: "nearest", inline: "nearest" }`. */
30
+ scrollIntoView?: ScrollIntoViewOptions;
31
+ /** Focus behavior options used in non-virtual mode. Defaults to `{ preventScroll: false }`. */
32
+ focusOptions?: FocusOptions;
33
+ /** Explicit or computed grid dimensions for navigation math. Defaults to `{}`. */
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
+ type ScrollDir = "left" | "right" | "up" | "down";
42
+ /** Scroll assist control object returned by initScrollAssist. */
43
+ interface ScrollAssistHandle {
44
+ /** Recompute assist visibility. */
45
+ update: () => void;
46
+ /** Tear down observers and assist elements. */
47
+ destroy: () => void;
48
+ }
49
+ /** Configuration for scroll assist overlays. */
50
+ interface ScrollAssistConfig {
51
+ /** Scroll speed in pixels per second. Defaults to `80`. */
52
+ pxPerSecond?: number;
53
+ /** Class name applied to assist overlays. Defaults to `"t007-scroll-assist"`. */
54
+ assistClassName?: string;
55
+ /** Enable vertical assist overlays. Defaults to `true`. */
56
+ vertical?: boolean;
57
+ /** Enable horizontal assist overlays. Defaults to `true`. */
58
+ horizontal?: boolean;
59
+ }
60
+ /** 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.
61
+ * The assist is automatically disabled when the element is too small or contains interactive elements near the edges to prevent interference.
62
+ * @param el Scrollable element to enhance.
63
+ * @param options Scroll assist configuration.
64
+ * @returns Scroll assist controls or void when the element is already managed.
65
+ */
66
+ declare function initScrollAssist(el: HTMLElement, { pxPerSecond, assistClassName, vertical, horizontal }?: ScrollAssistConfig): ScrollAssistHandle | void;
67
+ /** Remove scroll assist from an element.
68
+ * @param el Target element.
69
+ */
70
+ declare const removeScrollAssist: (el: HTMLElement) => void | undefined;
71
+
72
+ export { type Config as C, type KeyEvent as K, type ScrollAssistHandle as S, type ScrollAssistConfig as a, type ScrollDir as b, initScrollAssist as i, removeScrollAssist as r };
@@ -0,0 +1,55 @@
1
+ :root {
2
+ --t007-ripple-initial-opacity: 0.4;
3
+ --t007-ripple-initial-scale: 0.5;
4
+ --t007-ripple-expand-scale: 2.05;
5
+ --t007-ripple-color: rgb(0 0 0 / 0.3);
6
+ --t007-ripple-expand-duration: 350ms;
7
+ --t007-ripple-fade-duration: 350ms;
8
+ }
9
+
10
+ :where(*:has(> .t007-ripple-wrapper)) {
11
+ position: relative;
12
+ }
13
+
14
+ .t007-ripple-wrapper {
15
+ position: absolute;
16
+ inset: 0;
17
+ overflow: hidden;
18
+ pointer-events: none;
19
+ border-radius: inherit;
20
+ contain: strict;
21
+ }
22
+
23
+ .t007-ripple {
24
+ position: absolute;
25
+ border-radius: 50%;
26
+ z-index: 0;
27
+ background-color: var(--t007-ripple-color);
28
+ transform: scale(0);
29
+ }
30
+
31
+ .t007-ripple-hold {
32
+ animation: t007-ripple-expand var(--t007-ripple-expand-duration) ease-out forwards;
33
+ }
34
+
35
+ .t007-ripple-fade {
36
+ animation: t007-ripple-fade var(--t007-ripple-fade-duration) ease-in forwards;
37
+ }
38
+
39
+ @keyframes t007-ripple-expand {
40
+ 50% {
41
+ transform: scale(var(--t007-ripple-initial-scale));
42
+ }
43
+ to {
44
+ transform: scale(var(--t007-ripple-expand-scale));
45
+ }
46
+ }
47
+
48
+ @keyframes t007-ripple-fade {
49
+ from {
50
+ opacity: var(--t007-ripple-initial-opacity);
51
+ }
52
+ to {
53
+ opacity: 0;
54
+ }
55
+ }
@@ -0,0 +1,44 @@
1
+ :root {
2
+ --t007-scroll-assist-color: rgb(0 0 0 / 1);
3
+ --t007-scroll-assist-opacity: 0.5;
4
+ --t007-scroll-assist-min-width: 2rem;
5
+ --t007-scroll-assist-height: 2rem;
6
+ --t007-scroll-assist-inline-offset: -0.35rem;
7
+ --t007-scroll-assist-block-offset: 0;
8
+ }
9
+
10
+ .t007-scroll-assist {
11
+ --t007-scroll-assist-gradient-dir: to right;
12
+ position: absolute;
13
+ min-width: var(--t007-scroll-assist-min-width);
14
+ height: 100%;
15
+ opacity: var(--t007-scroll-assist-opacity);
16
+ background: linear-gradient(var(--t007-scroll-assist-gradient-dir), transparent 0, var(--t007-scroll-assist-color) 30%, transparent);
17
+ z-index: 2;
18
+ }
19
+
20
+ .t007-scroll-assist[data-scroll-direction="left"] {
21
+ --t007-scroll-assist-gradient-dir: to right;
22
+ top: 0;
23
+ left: var(--t007-scroll-assist-inline-offset);
24
+ }
25
+
26
+ .t007-scroll-assist[data-scroll-direction="right"] {
27
+ --t007-scroll-assist-gradient-dir: to left;
28
+ top: 0;
29
+ right: var(--t007-scroll-assist-inline-offset);
30
+ }
31
+
32
+ .t007-scroll-assist[data-scroll-direction="up"] {
33
+ --t007-scroll-assist-gradient-dir: to bottom;
34
+ top: var(--t007-scroll-assist-block-offset);
35
+ height: var(--t007-scroll-assist-height);
36
+ width: 100%;
37
+ }
38
+
39
+ .t007-scroll-assist[data-scroll-direction="down"] {
40
+ --t007-scroll-assist-gradient-dir: to top;
41
+ bottom: var(--t007-scroll-assist-block-offset);
42
+ height: var(--t007-scroll-assist-height);
43
+ width: 100%;
44
+ }
@@ -0,0 +1,19 @@
1
+ interface HighlightOptions {
2
+ /** Whether to trim individual query strings. Defaults to `true`. */
3
+ trimQuery?: boolean;
4
+ /** Whether to match whole words only. Defaults to `false`. */
5
+ wholeWord?: boolean;
6
+ }
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.
8
+ * @param text The text to be processed.
9
+ * @param query The string or array of strings to match and highlight within the text.
10
+ * @param ignoreCase Whether the matching should be case-insensitive.
11
+ * @param options Additional options for the highlighting behavior.
12
+ * @returns An array of text chunks with highlight information.
13
+ */
14
+ declare function useHighlight(text: string, query: string | string[], ignoreCase?: boolean, options?: HighlightOptions): {
15
+ text: string;
16
+ match: boolean;
17
+ }[];
18
+
19
+ export { type HighlightOptions as H, useHighlight as u };
@@ -0,0 +1,19 @@
1
+ interface HighlightOptions {
2
+ /** Whether to trim individual query strings. Defaults to `true`. */
3
+ trimQuery?: boolean;
4
+ /** Whether to match whole words only. Defaults to `false`. */
5
+ wholeWord?: boolean;
6
+ }
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.
8
+ * @param text The text to be processed.
9
+ * @param query The string or array of strings to match and highlight within the text.
10
+ * @param ignoreCase Whether the matching should be case-insensitive.
11
+ * @param options Additional options for the highlighting behavior.
12
+ * @returns An array of text chunks with highlight information.
13
+ */
14
+ declare function useHighlight(text: string, query: string | string[], ignoreCase?: boolean, options?: HighlightOptions): {
15
+ text: string;
16
+ match: boolean;
17
+ }[];
18
+
19
+ export { type HighlightOptions as H, useHighlight as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/utils",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
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",
@@ -15,20 +15,42 @@
15
15
  "module": "./dist/index.js",
16
16
  "browser": "./dist/index.js",
17
17
  "types": "./dist/index.d.ts",
18
- "sideEffects": false,
18
+ "sideEffects": [
19
+ "*.css"
20
+ ],
19
21
  "exports": {
20
22
  ".": {
21
23
  "types": "./dist/index.d.ts",
22
24
  "import": "./dist/index.js",
23
25
  "require": "./dist/index.cjs",
24
26
  "default": "./dist/index.js"
25
- }
27
+ },
28
+ "./hooks/react": {
29
+ "types": "./dist/hooks/react.d.ts",
30
+ "import": "./dist/hooks/react.js",
31
+ "require": "./dist/hooks/react.cjs",
32
+ "default": "./dist/hooks/react.js"
33
+ },
34
+ "./hooks/vanilla": {
35
+ "types": "./dist/hooks/vanilla.d.ts",
36
+ "import": "./dist/hooks/vanilla.js",
37
+ "require": "./dist/hooks/vanilla.cjs",
38
+ "default": "./dist/hooks/vanilla.js"
39
+ },
40
+ "./components/react": {
41
+ "types": "./dist/components/react.d.ts",
42
+ "import": "./dist/components/react.js",
43
+ "require": "./dist/components/react.cjs",
44
+ "default": "./dist/components/react.js"
45
+ },
46
+ "./styles/ripple.css": "./dist/styles/ripple.css",
47
+ "./styles/scroll-assist.css": "./dist/styles/scroll-assist.css"
26
48
  },
27
49
  "publishConfig": {
28
50
  "access": "public"
29
51
  },
30
52
  "scripts": {
31
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
53
+ "build": "tsup --config tsup.config.ts && shx cp src/styles/ripple.css dist/styles/ripple.css && shx cp src/styles/scroll-assist.css dist/styles/scroll-assist.css",
32
54
  "prepublishOnly": "shx cp ../../LICENSE ."
33
55
  },
34
56
  "files": [
@@ -38,13 +60,29 @@
38
60
  "t007",
39
61
  "ecosystem",
40
62
  "vanilla-js",
63
+ "react",
41
64
  "utils",
42
65
  "helpers",
43
66
  "dom-manipulation",
44
67
  "shared-logic",
45
68
  "performance"
46
69
  ],
70
+ "devDependencies": {
71
+ "@types/react": "^18.0.0",
72
+ "@types/react-dom": "^18.0.0",
73
+ "react": "^18.3.1",
74
+ "react-dom": "^18.3.1"
75
+ },
47
76
  "dependencies": {
77
+ "@t007/input": "^0.0.24",
48
78
  "sia-reactor": "^0.0.30"
79
+ },
80
+ "peerDependencies": {
81
+ "react": "^18.0.0"
82
+ },
83
+ "peerDependenciesMeta": {
84
+ "react": {
85
+ "optional": true
86
+ }
49
87
  }
50
88
  }