@arolariu/components 1.0.0 → 1.1.0

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.
Files changed (218) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/EXAMPLES.md +2510 -0
  3. package/dist/components/ui/alert-dialog.d.ts +4 -16
  4. package/dist/components/ui/alert-dialog.d.ts.map +1 -1
  5. package/dist/components/ui/alert-dialog.js +18 -14
  6. package/dist/components/ui/alert-dialog.js.map +1 -1
  7. package/dist/components/ui/avatar.d.ts +3 -12
  8. package/dist/components/ui/avatar.d.ts.map +1 -1
  9. package/dist/components/ui/avatar.js +18 -15
  10. package/dist/components/ui/avatar.js.map +1 -1
  11. package/dist/components/ui/button-group.d.ts +1 -1
  12. package/dist/components/ui/button-group.d.ts.map +1 -1
  13. package/dist/components/ui/calendar.d.ts +1 -4
  14. package/dist/components/ui/calendar.d.ts.map +1 -1
  15. package/dist/components/ui/calendar.js +7 -7
  16. package/dist/components/ui/calendar.js.map +1 -1
  17. package/dist/components/ui/carousel.d.ts.map +1 -1
  18. package/dist/components/ui/carousel.js.map +1 -1
  19. package/dist/components/ui/chart.d.ts.map +1 -1
  20. package/dist/components/ui/chart.js +125 -59
  21. package/dist/components/ui/chart.js.map +1 -1
  22. package/dist/components/ui/checkbox-group.d.ts +2 -6
  23. package/dist/components/ui/checkbox-group.d.ts.map +1 -1
  24. package/dist/components/ui/checkbox-group.js +8 -7
  25. package/dist/components/ui/checkbox-group.js.map +1 -1
  26. package/dist/components/ui/checkbox.d.ts +3 -1
  27. package/dist/components/ui/checkbox.d.ts.map +1 -1
  28. package/dist/components/ui/checkbox.js +4 -1
  29. package/dist/components/ui/checkbox.js.map +1 -1
  30. package/dist/components/ui/collapsible.d.ts.map +1 -1
  31. package/dist/components/ui/collapsible.js.map +1 -1
  32. package/dist/components/ui/combobox.d.ts +335 -0
  33. package/dist/components/ui/combobox.d.ts.map +1 -0
  34. package/dist/components/ui/combobox.js +206 -0
  35. package/dist/components/ui/combobox.js.map +1 -0
  36. package/dist/components/ui/combobox.module.js +23 -0
  37. package/dist/components/ui/combobox.module.js.map +1 -0
  38. package/dist/components/ui/combobox_module.css +142 -0
  39. package/dist/components/ui/combobox_module.css.map +1 -0
  40. package/dist/components/ui/command.d.ts.map +1 -1
  41. package/dist/components/ui/command.js +25 -16
  42. package/dist/components/ui/command.js.map +1 -1
  43. package/dist/components/ui/context-menu.d.ts.map +1 -1
  44. package/dist/components/ui/context-menu.js.map +1 -1
  45. package/dist/components/ui/drawer.d.ts.map +1 -1
  46. package/dist/components/ui/drawer.js.map +1 -1
  47. package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
  48. package/dist/components/ui/dropdown-menu.js.map +1 -1
  49. package/dist/components/ui/dropdrawer.d.ts +10 -16
  50. package/dist/components/ui/dropdrawer.d.ts.map +1 -1
  51. package/dist/components/ui/dropdrawer.js +28 -20
  52. package/dist/components/ui/dropdrawer.js.map +1 -1
  53. package/dist/components/ui/item.d.ts +1 -1
  54. package/dist/components/ui/item.d.ts.map +1 -1
  55. package/dist/components/ui/menubar.d.ts +11 -13
  56. package/dist/components/ui/menubar.d.ts.map +1 -1
  57. package/dist/components/ui/menubar.js.map +1 -1
  58. package/dist/components/ui/meter.d.ts +8 -24
  59. package/dist/components/ui/meter.d.ts.map +1 -1
  60. package/dist/components/ui/meter.js +23 -19
  61. package/dist/components/ui/meter.js.map +1 -1
  62. package/dist/components/ui/navigation-menu.d.ts +3 -12
  63. package/dist/components/ui/navigation-menu.d.ts.map +1 -1
  64. package/dist/components/ui/navigation-menu.js +14 -11
  65. package/dist/components/ui/navigation-menu.js.map +1 -1
  66. package/dist/components/ui/number-field.d.ts +6 -12
  67. package/dist/components/ui/number-field.d.ts.map +1 -1
  68. package/dist/components/ui/number-field.js.map +1 -1
  69. package/dist/components/ui/progress.d.ts +1 -4
  70. package/dist/components/ui/progress.d.ts.map +1 -1
  71. package/dist/components/ui/progress.js +10 -9
  72. package/dist/components/ui/progress.js.map +1 -1
  73. package/dist/components/ui/radio-group.d.ts +2 -4
  74. package/dist/components/ui/radio-group.d.ts.map +1 -1
  75. package/dist/components/ui/radio-group.js.map +1 -1
  76. package/dist/components/ui/resizable.d.ts +3 -3
  77. package/dist/components/ui/resizable.d.ts.map +1 -1
  78. package/dist/components/ui/resizable.js.map +1 -1
  79. package/dist/components/ui/scratcher.d.ts +1 -1
  80. package/dist/components/ui/scratcher.d.ts.map +1 -1
  81. package/dist/components/ui/scratcher.js +5 -4
  82. package/dist/components/ui/scratcher.js.map +1 -1
  83. package/dist/components/ui/scroll-area.d.ts +2 -4
  84. package/dist/components/ui/scroll-area.d.ts.map +1 -1
  85. package/dist/components/ui/scroll-area.js.map +1 -1
  86. package/dist/components/ui/separator.d.ts +1 -4
  87. package/dist/components/ui/separator.d.ts.map +1 -1
  88. package/dist/components/ui/separator.js +9 -8
  89. package/dist/components/ui/separator.js.map +1 -1
  90. package/dist/components/ui/sheet.d.ts.map +1 -1
  91. package/dist/components/ui/sheet.js.map +1 -1
  92. package/dist/components/ui/sidebar.d.ts +1 -1
  93. package/dist/components/ui/sidebar.d.ts.map +1 -1
  94. package/dist/components/ui/sidebar.js.map +1 -1
  95. package/dist/components/ui/sonner.d.ts +5 -4
  96. package/dist/components/ui/sonner.d.ts.map +1 -1
  97. package/dist/components/ui/sonner.js +7 -6
  98. package/dist/components/ui/sonner.js.map +1 -1
  99. package/dist/components/ui/toggle-group.d.ts +2 -8
  100. package/dist/components/ui/toggle-group.d.ts.map +1 -1
  101. package/dist/components/ui/toggle-group.js +12 -10
  102. package/dist/components/ui/toggle-group.js.map +1 -1
  103. package/dist/components/ui/toolbar.d.ts +10 -30
  104. package/dist/components/ui/toolbar.d.ts.map +1 -1
  105. package/dist/components/ui/toolbar.js +28 -23
  106. package/dist/components/ui/toolbar.js.map +1 -1
  107. package/dist/hooks/useClipboard.d.ts +77 -0
  108. package/dist/hooks/useClipboard.d.ts.map +1 -0
  109. package/dist/hooks/useClipboard.js +42 -0
  110. package/dist/hooks/useClipboard.js.map +1 -0
  111. package/dist/hooks/useControllableState.d.ts +54 -0
  112. package/dist/hooks/useControllableState.d.ts.map +1 -0
  113. package/dist/hooks/useControllableState.js +29 -0
  114. package/dist/hooks/useControllableState.js.map +1 -0
  115. package/dist/hooks/useDebounce.d.ts +33 -0
  116. package/dist/hooks/useDebounce.d.ts.map +1 -0
  117. package/dist/hooks/useDebounce.js +20 -0
  118. package/dist/hooks/useDebounce.js.map +1 -0
  119. package/dist/hooks/useEventCallback.d.ts +34 -0
  120. package/dist/hooks/useEventCallback.d.ts.map +1 -0
  121. package/dist/hooks/useEventCallback.js +12 -0
  122. package/dist/hooks/useEventCallback.js.map +1 -0
  123. package/dist/hooks/useId.d.ts +30 -0
  124. package/dist/hooks/useId.d.ts.map +1 -0
  125. package/dist/hooks/useId.js +9 -0
  126. package/dist/hooks/useId.js.map +1 -0
  127. package/dist/hooks/useIntersectionObserver.d.ts +51 -0
  128. package/dist/hooks/useIntersectionObserver.d.ts.map +1 -0
  129. package/dist/hooks/useIntersectionObserver.js +25 -0
  130. package/dist/hooks/useIntersectionObserver.js.map +1 -0
  131. package/dist/hooks/useInterval.d.ts +55 -0
  132. package/dist/hooks/useInterval.d.ts.map +1 -0
  133. package/dist/hooks/useInterval.js +24 -0
  134. package/dist/hooks/useInterval.js.map +1 -0
  135. package/dist/hooks/useLocalStorage.d.ts +43 -0
  136. package/dist/hooks/useLocalStorage.d.ts.map +1 -0
  137. package/dist/hooks/useLocalStorage.js +53 -0
  138. package/dist/hooks/useLocalStorage.js.map +1 -0
  139. package/dist/hooks/useMergedRefs.d.ts +27 -0
  140. package/dist/hooks/useMergedRefs.d.ts.map +1 -0
  141. package/dist/hooks/useMergedRefs.js +11 -0
  142. package/dist/hooks/useMergedRefs.js.map +1 -0
  143. package/dist/hooks/useOnClickOutside.d.ts +32 -0
  144. package/dist/hooks/useOnClickOutside.d.ts.map +1 -0
  145. package/dist/hooks/useOnClickOutside.js +23 -0
  146. package/dist/hooks/useOnClickOutside.js.map +1 -0
  147. package/dist/hooks/usePrevious.d.ts +33 -0
  148. package/dist/hooks/usePrevious.d.ts.map +1 -0
  149. package/dist/hooks/usePrevious.js +14 -0
  150. package/dist/hooks/usePrevious.js.map +1 -0
  151. package/dist/hooks/useThrottle.d.ts +37 -0
  152. package/dist/hooks/useThrottle.d.ts.map +1 -0
  153. package/dist/hooks/useThrottle.js +34 -0
  154. package/dist/hooks/useThrottle.js.map +1 -0
  155. package/dist/hooks/useTimeout.d.ts +28 -0
  156. package/dist/hooks/useTimeout.d.ts.map +1 -0
  157. package/dist/hooks/useTimeout.js +24 -0
  158. package/dist/hooks/useTimeout.js.map +1 -0
  159. package/dist/index.d.ts +14 -0
  160. package/dist/index.d.ts.map +1 -1
  161. package/dist/index.js +14 -0
  162. package/dist/lib/utilities.d.ts +2 -3
  163. package/dist/lib/utilities.d.ts.map +1 -1
  164. package/dist/lib/utilities.js.map +1 -1
  165. package/dist/motion/tokens.js +5 -5
  166. package/dist/motion/tokens.js.map +1 -1
  167. package/dist/rslib-runtime.js +39 -0
  168. package/dist/rslib-runtime.js.map +1 -0
  169. package/package.json +82 -3
  170. package/src/components/ui/alert-dialog.tsx +15 -8
  171. package/src/components/ui/avatar.tsx +9 -6
  172. package/src/components/ui/calendar.tsx +7 -13
  173. package/src/components/ui/carousel.tsx +2 -0
  174. package/src/components/ui/chart.tsx +63 -60
  175. package/src/components/ui/checkbox-group.tsx +4 -5
  176. package/src/components/ui/checkbox.tsx +10 -2
  177. package/src/components/ui/collapsible.tsx +1 -0
  178. package/src/components/ui/combobox.module.css +158 -0
  179. package/src/components/ui/combobox.tsx +569 -0
  180. package/src/components/ui/command.tsx +31 -15
  181. package/src/components/ui/context-menu.tsx +3 -0
  182. package/src/components/ui/drawer.tsx +2 -0
  183. package/src/components/ui/dropdown-menu.tsx +3 -0
  184. package/src/components/ui/dropdrawer.tsx +80 -62
  185. package/src/components/ui/menubar.tsx +9 -10
  186. package/src/components/ui/meter.tsx +16 -17
  187. package/src/components/ui/navigation-menu.tsx +41 -33
  188. package/src/components/ui/number-field.tsx +6 -13
  189. package/src/components/ui/progress.tsx +3 -2
  190. package/src/components/ui/radio-group.tsx +2 -5
  191. package/src/components/ui/resizable.tsx +2 -2
  192. package/src/components/ui/scratcher.tsx +6 -10
  193. package/src/components/ui/scroll-area.tsx +2 -5
  194. package/src/components/ui/separator.tsx +4 -3
  195. package/src/components/ui/sheet.tsx +3 -0
  196. package/src/components/ui/sidebar.tsx +1 -0
  197. package/src/components/ui/sonner.tsx +20 -12
  198. package/src/components/ui/toggle-group.tsx +6 -4
  199. package/src/components/ui/toolbar.tsx +20 -21
  200. package/src/hooks/useClipboard.tsx +137 -0
  201. package/src/hooks/useControllableState.tsx +81 -0
  202. package/src/hooks/useDebounce.tsx +50 -0
  203. package/src/hooks/useEventCallback.tsx +47 -0
  204. package/src/hooks/useId.tsx +36 -0
  205. package/src/hooks/useIntersectionObserver.tsx +81 -0
  206. package/src/hooks/useInterval.tsx +80 -0
  207. package/src/hooks/useLocalStorage.tsx +111 -0
  208. package/src/hooks/useMergedRefs.tsx +48 -0
  209. package/src/hooks/useOnClickOutside.tsx +55 -0
  210. package/src/hooks/usePrevious.tsx +44 -0
  211. package/src/hooks/useThrottle.tsx +78 -0
  212. package/src/hooks/useTimeout.tsx +51 -0
  213. package/src/index.ts +23 -0
  214. package/src/lib/utilities.ts +4 -4
  215. package/src/motion/tokens.ts +4 -4
  216. package/src/stories/DesignPrinciples.mdx +48 -0
  217. package/src/stories/GettingStarted.mdx +92 -0
  218. package/src/stories/Welcome.mdx +44 -0
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Options for the `useClipboard` hook.
3
+ */
4
+ export interface UseClipboardOptions {
5
+ /**
6
+ * The duration in milliseconds after which the `copied` state resets to `false`.
7
+ *
8
+ * @defaultValue 2000
9
+ */
10
+ timeout?: number;
11
+ }
12
+ /**
13
+ * Return type for the `useClipboard` hook.
14
+ */
15
+ export interface UseClipboardReturn {
16
+ /**
17
+ * Whether the text was successfully copied to the clipboard.
18
+ */
19
+ copied: boolean;
20
+ /**
21
+ * Copies the provided text to the clipboard.
22
+ *
23
+ * @param text - The text to copy.
24
+ * @returns A promise that resolves when the copy operation completes.
25
+ */
26
+ copy: (text: string) => Promise<void>;
27
+ /**
28
+ * The error that occurred during the copy operation, or `null` if no error occurred.
29
+ */
30
+ error: Error | null;
31
+ }
32
+ /**
33
+ * Copies text to the clipboard with success/error state management.
34
+ *
35
+ * @remarks
36
+ * This hook provides a simple interface for copying text to the clipboard using
37
+ * the Clipboard API. It manages the `copied` state that automatically resets
38
+ * after a configurable timeout, and handles errors gracefully when the Clipboard
39
+ * API is unavailable or the operation fails.
40
+ *
41
+ * The hook is SSR-safe and will handle the case where `navigator.clipboard` is
42
+ * not available (e.g., in non-secure contexts or older browsers).
43
+ *
44
+ * @param options - Configuration options for the hook.
45
+ * @returns An object containing the copied state, copy function, and any error.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * function CopyButton({textToCopy}: {textToCopy: string}) {
50
+ * const {copied, copy, error} = useClipboard({timeout: 3000});
51
+ *
52
+ * return (
53
+ * <div>
54
+ * <button onClick={() => copy(textToCopy)}>
55
+ * {copied ? "Copied!" : "Copy to clipboard"}
56
+ * </button>
57
+ * {error && <span>Failed to copy: {error.message}</span>}
58
+ * </div>
59
+ * );
60
+ * }
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * function ShareLink({url}: {url: string}) {
66
+ * const {copied, copy} = useClipboard();
67
+ *
68
+ * return (
69
+ * <button onClick={() => copy(url)} disabled={copied}>
70
+ * {copied ? "✓ Copied" : "Share link"}
71
+ * </button>
72
+ * );
73
+ * }
74
+ * ```
75
+ */
76
+ export declare function useClipboard(options?: UseClipboardOptions): UseClipboardReturn;
77
+ //# sourceMappingURL=useClipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useClipboard.d.ts","sourceRoot":"","sources":["../../src/hooks/useClipboard.tsx"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtC;;OAEG;IACH,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CAqDlF"}
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ function useClipboard(options = {}) {
4
+ const { timeout = 2000 } = options;
5
+ const [copied, setCopied] = useState(false);
6
+ const [error, setError] = useState(null);
7
+ const timeoutRef = useRef(null);
8
+ const copy = useCallback(async (text)=>{
9
+ if (null !== timeoutRef.current) {
10
+ clearTimeout(timeoutRef.current);
11
+ timeoutRef.current = null;
12
+ }
13
+ setError(null);
14
+ try {
15
+ if (void 0 === globalThis.navigator || !globalThis.navigator.clipboard) throw new Error("Clipboard API is not available");
16
+ await globalThis.navigator.clipboard.writeText(text);
17
+ setCopied(true);
18
+ timeoutRef.current = setTimeout(()=>{
19
+ setCopied(false);
20
+ timeoutRef.current = null;
21
+ }, timeout);
22
+ } catch (err) {
23
+ const errorMessage = err instanceof Error ? err : new Error("Failed to copy to clipboard");
24
+ setError(errorMessage);
25
+ setCopied(false);
26
+ console.error("Copy to clipboard failed:", errorMessage);
27
+ }
28
+ }, [
29
+ timeout
30
+ ]);
31
+ useEffect(()=>()=>{
32
+ if (null !== timeoutRef.current) clearTimeout(timeoutRef.current);
33
+ }, []);
34
+ return {
35
+ copied,
36
+ copy,
37
+ error
38
+ };
39
+ }
40
+ export { useClipboard };
41
+
42
+ //# sourceMappingURL=useClipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useClipboard.js","sources":["../../src/hooks/useClipboard.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Options for the `useClipboard` hook.\r\n */\r\nexport interface UseClipboardOptions {\r\n /**\r\n * The duration in milliseconds after which the `copied` state resets to `false`.\r\n *\r\n * @defaultValue 2000\r\n */\r\n timeout?: number;\r\n}\r\n\r\n/**\r\n * Return type for the `useClipboard` hook.\r\n */\r\nexport interface UseClipboardReturn {\r\n /**\r\n * Whether the text was successfully copied to the clipboard.\r\n */\r\n copied: boolean;\r\n\r\n /**\r\n * Copies the provided text to the clipboard.\r\n *\r\n * @param text - The text to copy.\r\n * @returns A promise that resolves when the copy operation completes.\r\n */\r\n copy: (text: string) => Promise<void>;\r\n\r\n /**\r\n * The error that occurred during the copy operation, or `null` if no error occurred.\r\n */\r\n error: Error | null;\r\n}\r\n\r\n/**\r\n * Copies text to the clipboard with success/error state management.\r\n *\r\n * @remarks\r\n * This hook provides a simple interface for copying text to the clipboard using\r\n * the Clipboard API. It manages the `copied` state that automatically resets\r\n * after a configurable timeout, and handles errors gracefully when the Clipboard\r\n * API is unavailable or the operation fails.\r\n *\r\n * The hook is SSR-safe and will handle the case where `navigator.clipboard` is\r\n * not available (e.g., in non-secure contexts or older browsers).\r\n *\r\n * @param options - Configuration options for the hook.\r\n * @returns An object containing the copied state, copy function, and any error.\r\n *\r\n * @example\r\n * ```tsx\r\n * function CopyButton({textToCopy}: {textToCopy: string}) {\r\n * const {copied, copy, error} = useClipboard({timeout: 3000});\r\n *\r\n * return (\r\n * <div>\r\n * <button onClick={() => copy(textToCopy)}>\r\n * {copied ? \"Copied!\" : \"Copy to clipboard\"}\r\n * </button>\r\n * {error && <span>Failed to copy: {error.message}</span>}\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * function ShareLink({url}: {url: string}) {\r\n * const {copied, copy} = useClipboard();\r\n *\r\n * return (\r\n * <button onClick={() => copy(url)} disabled={copied}>\r\n * {copied ? \"✓ Copied\" : \"Share link\"}\r\n * </button>\r\n * );\r\n * }\r\n * ```\r\n */\r\nexport function useClipboard(options: UseClipboardOptions = {}): UseClipboardReturn {\r\n const {timeout = 2000} = options;\r\n\r\n const [copied, setCopied] = React.useState(false);\r\n const [error, setError] = React.useState<Error | null>(null);\r\n const timeoutRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);\r\n\r\n const copy = React.useCallback(\r\n async (text: string): Promise<void> => {\r\n // Clear any existing timeout\r\n if (timeoutRef.current !== null) {\r\n clearTimeout(timeoutRef.current);\r\n timeoutRef.current = null;\r\n }\r\n\r\n // Reset error state\r\n setError(null);\r\n\r\n try {\r\n // Check if Clipboard API is available\r\n if (typeof globalThis.navigator === \"undefined\" || !globalThis.navigator.clipboard) {\r\n throw new Error(\"Clipboard API is not available\");\r\n }\r\n\r\n await globalThis.navigator.clipboard.writeText(text);\r\n setCopied(true);\r\n\r\n // Reset copied state after timeout\r\n timeoutRef.current = setTimeout(() => {\r\n setCopied(false);\r\n timeoutRef.current = null;\r\n }, timeout);\r\n } catch (err) {\r\n const errorMessage = err instanceof Error ? err : new Error(\"Failed to copy to clipboard\");\r\n\r\n setError(errorMessage);\r\n setCopied(false);\r\n console.error(\"Copy to clipboard failed:\", errorMessage);\r\n }\r\n },\r\n [timeout],\r\n );\r\n\r\n // Cleanup timeout on unmount\r\n React.useEffect(() => {\r\n return () => {\r\n if (timeoutRef.current !== null) {\r\n clearTimeout(timeoutRef.current);\r\n }\r\n };\r\n }, []);\r\n\r\n return {copied, copy, error};\r\n}\r\n"],"names":["useClipboard","options","timeout","copied","setCopied","React","error","setError","timeoutRef","copy","text","clearTimeout","globalThis","Error","setTimeout","err","errorMessage","console"],"mappings":";;AAmFO,SAASA,aAAaC,UAA+B,CAAC,CAAC;IAC5D,MAAM,EAACC,UAAU,IAAI,EAAC,GAAGD;IAEzB,MAAM,CAACE,QAAQC,UAAU,GAAGC,SAAe;IAC3C,MAAM,CAACC,OAAOC,SAAS,GAAGF,SAA6B;IACvD,MAAMG,aAAaH,OAAmD;IAEtE,MAAMI,OAAOJ,YACX,OAAOK;QAEL,IAAIF,AAAuB,SAAvBA,WAAW,OAAO,EAAW;YAC/BG,aAAaH,WAAW,OAAO;YAC/BA,WAAW,OAAO,GAAG;QACvB;QAGAD,SAAS;QAET,IAAI;YAEF,IAAI,AAAgC,WAAzBK,WAAW,SAAS,IAAoB,CAACA,WAAW,SAAS,CAAC,SAAS,EAChF,MAAM,IAAIC,MAAM;YAGlB,MAAMD,WAAW,SAAS,CAAC,SAAS,CAAC,SAAS,CAACF;YAC/CN,UAAU;YAGVI,WAAW,OAAO,GAAGM,WAAW;gBAC9BV,UAAU;gBACVI,WAAW,OAAO,GAAG;YACvB,GAAGN;QACL,EAAE,OAAOa,KAAK;YACZ,MAAMC,eAAeD,eAAeF,QAAQE,MAAM,IAAIF,MAAM;YAE5DN,SAASS;YACTZ,UAAU;YACVa,QAAQ,KAAK,CAAC,6BAA6BD;QAC7C;IACF,GACA;QAACd;KAAQ;IAIXG,UAAgB,IACP;YACL,IAAIG,AAAuB,SAAvBA,WAAW,OAAO,EACpBG,aAAaH,WAAW,OAAO;QAEnC,GACC,EAAE;IAEL,OAAO;QAACL;QAAQM;QAAMH;IAAK;AAC7B"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Options for configuring controllable state behavior.
3
+ *
4
+ * @typeParam T - The type of the state value.
5
+ */
6
+ export interface UseControllableStateOptions<T> {
7
+ /**
8
+ * The controlled value from props. When provided, the component operates in controlled mode.
9
+ */
10
+ controlled?: T;
11
+ /**
12
+ * The default value used when the component is uncontrolled.
13
+ */
14
+ defaultValue: T;
15
+ /**
16
+ * Callback fired when the internal state changes in controlled mode.
17
+ *
18
+ * @param value - The new state value.
19
+ */
20
+ onChange?: (value: T) => void;
21
+ }
22
+ /**
23
+ * Manages state that can be either controlled or uncontrolled.
24
+ *
25
+ * @remarks
26
+ * This hook enables components to support both controlled and uncontrolled patterns
27
+ * seamlessly. When a `controlled` value is provided, it takes precedence; otherwise,
28
+ * the hook manages internal state initialized with `defaultValue`.
29
+ *
30
+ * @typeParam T - The type of the state value.
31
+ * @param options - Configuration object for controllable state.
32
+ * @returns A tuple containing the current state value and a setter function.
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * function CustomInput({value, defaultValue = "", onChange}) {
37
+ * const [internalValue, setValue] = useControllableState({
38
+ * controlled: value,
39
+ * defaultValue,
40
+ * onChange,
41
+ * });
42
+ *
43
+ * return (
44
+ * <input
45
+ * type="text"
46
+ * value={internalValue}
47
+ * onChange={(e) => setValue(e.target.value)}
48
+ * />
49
+ * );
50
+ * }
51
+ * ```
52
+ */
53
+ export declare function useControllableState<T>(options: UseControllableStateOptions<T>): [T, (value: T | ((prev: T) => T)) => void];
54
+ //# sourceMappingURL=useControllableState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useControllableState.d.ts","sourceRoot":"","sources":["../../src/hooks/useControllableState.tsx"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,WAAW,2BAA2B,CAAC,CAAC;IAC5C;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,CAAC;IACf;;OAEG;IACH,YAAY,EAAE,CAAC,CAAC;IAChB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,OAAO,EAAE,2BAA2B,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAuB3H"}
@@ -0,0 +1,29 @@
1
+ "use client";
2
+ import { useCallback, useState } from "react";
3
+ function useControllableState(options) {
4
+ const { controlled, defaultValue, onChange } = options;
5
+ const [uncontrolledState, setUncontrolledState] = useState(defaultValue);
6
+ const isControlled = void 0 !== controlled;
7
+ const value = isControlled ? controlled : uncontrolledState;
8
+ const setValue = useCallback((nextValue)=>{
9
+ if (isControlled) {
10
+ const resolvedValue = "function" == typeof nextValue ? nextValue(controlled) : nextValue;
11
+ onChange?.(resolvedValue);
12
+ } else setUncontrolledState((currentValue)=>{
13
+ const resolvedValue = "function" == typeof nextValue ? nextValue(currentValue) : nextValue;
14
+ onChange?.(resolvedValue);
15
+ return resolvedValue;
16
+ });
17
+ }, [
18
+ isControlled,
19
+ onChange,
20
+ controlled
21
+ ]);
22
+ return [
23
+ value,
24
+ setValue
25
+ ];
26
+ }
27
+ export { useControllableState };
28
+
29
+ //# sourceMappingURL=useControllableState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useControllableState.js","sources":["../../src/hooks/useControllableState.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Options for configuring controllable state behavior.\r\n *\r\n * @typeParam T - The type of the state value.\r\n */\r\nexport interface UseControllableStateOptions<T> {\r\n /**\r\n * The controlled value from props. When provided, the component operates in controlled mode.\r\n */\r\n controlled?: T;\r\n /**\r\n * The default value used when the component is uncontrolled.\r\n */\r\n defaultValue: T;\r\n /**\r\n * Callback fired when the internal state changes in controlled mode.\r\n *\r\n * @param value - The new state value.\r\n */\r\n onChange?: (value: T) => void;\r\n}\r\n\r\n/**\r\n * Manages state that can be either controlled or uncontrolled.\r\n *\r\n * @remarks\r\n * This hook enables components to support both controlled and uncontrolled patterns\r\n * seamlessly. When a `controlled` value is provided, it takes precedence; otherwise,\r\n * the hook manages internal state initialized with `defaultValue`.\r\n *\r\n * @typeParam T - The type of the state value.\r\n * @param options - Configuration object for controllable state.\r\n * @returns A tuple containing the current state value and a setter function.\r\n *\r\n * @example\r\n * ```tsx\r\n * function CustomInput({value, defaultValue = \"\", onChange}) {\r\n * const [internalValue, setValue] = useControllableState({\r\n * controlled: value,\r\n * defaultValue,\r\n * onChange,\r\n * });\r\n *\r\n * return (\r\n * <input\r\n * type=\"text\"\r\n * value={internalValue}\r\n * onChange={(e) => setValue(e.target.value)}\r\n * />\r\n * );\r\n * }\r\n * ```\r\n */\r\nexport function useControllableState<T>(options: UseControllableStateOptions<T>): [T, (value: T | ((prev: T) => T)) => void] {\r\n const {controlled, defaultValue, onChange} = options;\r\n const [uncontrolledState, setUncontrolledState] = React.useState<T>(defaultValue);\r\n const isControlled = controlled !== undefined;\r\n const value = isControlled ? controlled : uncontrolledState;\r\n\r\n const setValue = React.useCallback(\r\n (nextValue: T | ((prev: T) => T)) => {\r\n if (!isControlled) {\r\n setUncontrolledState((currentValue) => {\r\n const resolvedValue = typeof nextValue === \"function\" ? (nextValue as (prev: T) => T)(currentValue) : nextValue;\r\n onChange?.(resolvedValue);\r\n return resolvedValue;\r\n });\r\n } else {\r\n const resolvedValue = typeof nextValue === \"function\" ? (nextValue as (prev: T) => T)(controlled as T) : nextValue;\r\n onChange?.(resolvedValue);\r\n }\r\n },\r\n [isControlled, onChange, controlled],\r\n );\r\n\r\n return [value, setValue];\r\n}\r\n"],"names":["useControllableState","options","controlled","defaultValue","onChange","uncontrolledState","setUncontrolledState","React","isControlled","undefined","value","setValue","nextValue","resolvedValue","currentValue"],"mappings":";;AAyDO,SAASA,qBAAwBC,OAAuC;IAC7E,MAAM,EAACC,UAAU,EAAEC,YAAY,EAAEC,QAAQ,EAAC,GAAGH;IAC7C,MAAM,CAACI,mBAAmBC,qBAAqB,GAAGC,SAAkBJ;IACpE,MAAMK,eAAeN,AAAeO,WAAfP;IACrB,MAAMQ,QAAQF,eAAeN,aAAaG;IAE1C,MAAMM,WAAWJ,YACf,CAACK;QACC,IAAKJ,cAME;YACL,MAAMK,gBAAgB,AAAqB,cAArB,OAAOD,YAA4BA,UAA6BV,cAAmBU;YACzGR,WAAWS;QACb,OAREP,qBAAqB,CAACQ;YACpB,MAAMD,gBAAgB,AAAqB,cAArB,OAAOD,YAA4BA,UAA6BE,gBAAgBF;YACtGR,WAAWS;YACX,OAAOA;QACT;IAKJ,GACA;QAACL;QAAcJ;QAAUF;KAAW;IAGtC,OAAO;QAACQ;QAAOC;KAAS;AAC1B"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Debounces a value, delaying updates until after the specified delay has elapsed.
3
+ *
4
+ * @remarks
5
+ * This hook returns a debounced version of the provided value that only updates
6
+ * after the value has stopped changing for the specified delay. Useful for optimizing
7
+ * performance in scenarios like search inputs, where you want to avoid triggering
8
+ * expensive operations on every keystroke.
9
+ *
10
+ * The debounce timer resets on every value change and cleans up automatically on unmount.
11
+ *
12
+ * @typeParam T - The type of the value being debounced.
13
+ * @param value - The value to debounce.
14
+ * @param delay - The delay in milliseconds before the debounced value updates.
15
+ * @returns The debounced value.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function SearchInput() {
20
+ * const [searchTerm, setSearchTerm] = useState("");
21
+ * const debouncedSearchTerm = useDebounce(searchTerm, 500);
22
+ *
23
+ * useEffect(() => {
24
+ * // Expensive search operation
25
+ * performSearch(debouncedSearchTerm);
26
+ * }, [debouncedSearchTerm]);
27
+ *
28
+ * return <input value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} />;
29
+ * }
30
+ * ```
31
+ */
32
+ export declare function useDebounce<T>(value: T, delay: number): T;
33
+ //# sourceMappingURL=useDebounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.d.ts","sourceRoot":"","sources":["../../src/hooks/useDebounce.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAczD"}
@@ -0,0 +1,20 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ function useDebounce(value, delay) {
4
+ const [debouncedValue, setDebouncedValue] = useState(value);
5
+ useEffect(()=>{
6
+ const timeoutId = globalThis.setTimeout(()=>{
7
+ setDebouncedValue(value);
8
+ }, delay);
9
+ return ()=>{
10
+ globalThis.clearTimeout(timeoutId);
11
+ };
12
+ }, [
13
+ value,
14
+ delay
15
+ ]);
16
+ return debouncedValue;
17
+ }
18
+ export { useDebounce };
19
+
20
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useDebounce.js","sources":["../../src/hooks/useDebounce.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Debounces a value, delaying updates until after the specified delay has elapsed.\r\n *\r\n * @remarks\r\n * This hook returns a debounced version of the provided value that only updates\r\n * after the value has stopped changing for the specified delay. Useful for optimizing\r\n * performance in scenarios like search inputs, where you want to avoid triggering\r\n * expensive operations on every keystroke.\r\n *\r\n * The debounce timer resets on every value change and cleans up automatically on unmount.\r\n *\r\n * @typeParam T - The type of the value being debounced.\r\n * @param value - The value to debounce.\r\n * @param delay - The delay in milliseconds before the debounced value updates.\r\n * @returns The debounced value.\r\n *\r\n * @example\r\n * ```tsx\r\n * function SearchInput() {\r\n * const [searchTerm, setSearchTerm] = useState(\"\");\r\n * const debouncedSearchTerm = useDebounce(searchTerm, 500);\r\n *\r\n * useEffect(() => {\r\n * // Expensive search operation\r\n * performSearch(debouncedSearchTerm);\r\n * }, [debouncedSearchTerm]);\r\n *\r\n * return <input value={searchTerm} onChange={(e) => setSearchTerm(e.target.value)} />;\r\n * }\r\n * ```\r\n */\r\nexport function useDebounce<T>(value: T, delay: number): T {\r\n const [debouncedValue, setDebouncedValue] = React.useState<T>(value);\r\n\r\n React.useEffect(() => {\r\n const timeoutId = globalThis.setTimeout(() => {\r\n setDebouncedValue(value);\r\n }, delay);\r\n\r\n return () => {\r\n globalThis.clearTimeout(timeoutId);\r\n };\r\n }, [value, delay]);\r\n\r\n return debouncedValue;\r\n}\r\n"],"names":["useDebounce","value","delay","debouncedValue","setDebouncedValue","React","timeoutId","globalThis"],"mappings":";;AAmCO,SAASA,YAAeC,KAAQ,EAAEC,KAAa;IACpD,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGC,SAAkBJ;IAE9DI,UAAgB;QACd,MAAMC,YAAYC,WAAW,UAAU,CAAC;YACtCH,kBAAkBH;QACpB,GAAGC;QAEH,OAAO;YACLK,WAAW,YAAY,CAACD;QAC1B;IACF,GAAG;QAACL;QAAOC;KAAM;IAEjB,OAAOC;AACT"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Creates a stable callback reference that always calls the latest version of the provided function.
3
+ *
4
+ * @remarks
5
+ * Unlike `useCallback`, this hook returns a stable function reference that never changes,
6
+ * but always invokes the most recent version of the callback. This is useful when you need
7
+ * to pass callbacks to optimized child components or effects without triggering re-renders
8
+ * when dependencies change.
9
+ *
10
+ * The returned function is safe to use in dependency arrays because its identity never changes.
11
+ *
12
+ * @typeParam Args - The tuple type of the callback's arguments.
13
+ * @typeParam Return - The return type of the callback.
14
+ * @param callback - The function to wrap with a stable reference.
15
+ * @returns A stable function reference that invokes the latest callback.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function SearchInput({onSearch}) {
20
+ * const [query, setQuery] = useState("");
21
+ * // stableOnSearch never changes identity, but always calls the latest onSearch
22
+ * const stableOnSearch = useEventCallback(onSearch);
23
+ *
24
+ * useEffect(() => {
25
+ * const timer = setTimeout(() => stableOnSearch(query), 500);
26
+ * return () => clearTimeout(timer);
27
+ * }, [query, stableOnSearch]); // Safe to include in deps
28
+ *
29
+ * return <input value={query} onChange={(e) => setQuery(e.target.value)} />;
30
+ * }
31
+ * ```
32
+ */
33
+ export declare function useEventCallback<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return;
34
+ //# sourceMappingURL=useEventCallback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useEventCallback.d.ts","sourceRoot":"","sources":["../../src/hooks/useEventCallback.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAU/H"}
@@ -0,0 +1,12 @@
1
+ "use client";
2
+ import { useCallback, useLayoutEffect, useRef } from "react";
3
+ function useEventCallback(callback) {
4
+ const callbackRef = useRef(callback);
5
+ useLayoutEffect(()=>{
6
+ callbackRef.current = callback;
7
+ });
8
+ return useCallback((...args)=>callbackRef.current(...args), []);
9
+ }
10
+ export { useEventCallback };
11
+
12
+ //# sourceMappingURL=useEventCallback.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useEventCallback.js","sources":["../../src/hooks/useEventCallback.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Creates a stable callback reference that always calls the latest version of the provided function.\r\n *\r\n * @remarks\r\n * Unlike `useCallback`, this hook returns a stable function reference that never changes,\r\n * but always invokes the most recent version of the callback. This is useful when you need\r\n * to pass callbacks to optimized child components or effects without triggering re-renders\r\n * when dependencies change.\r\n *\r\n * The returned function is safe to use in dependency arrays because its identity never changes.\r\n *\r\n * @typeParam Args - The tuple type of the callback's arguments.\r\n * @typeParam Return - The return type of the callback.\r\n * @param callback - The function to wrap with a stable reference.\r\n * @returns A stable function reference that invokes the latest callback.\r\n *\r\n * @example\r\n * ```tsx\r\n * function SearchInput({onSearch}) {\r\n * const [query, setQuery] = useState(\"\");\r\n * // stableOnSearch never changes identity, but always calls the latest onSearch\r\n * const stableOnSearch = useEventCallback(onSearch);\r\n *\r\n * useEffect(() => {\r\n * const timer = setTimeout(() => stableOnSearch(query), 500);\r\n * return () => clearTimeout(timer);\r\n * }, [query, stableOnSearch]); // Safe to include in deps\r\n *\r\n * return <input value={query} onChange={(e) => setQuery(e.target.value)} />;\r\n * }\r\n * ```\r\n */\r\nexport function useEventCallback<Args extends unknown[], Return>(callback: (...args: Args) => Return): (...args: Args) => Return {\r\n const callbackRef = React.useRef(callback);\r\n\r\n React.useLayoutEffect(() => {\r\n callbackRef.current = callback;\r\n });\r\n\r\n return React.useCallback((...args: Args) => {\r\n return callbackRef.current(...args);\r\n }, []);\r\n}\r\n"],"names":["useEventCallback","callback","callbackRef","React","args"],"mappings":";;AAoCO,SAASA,iBAAiDC,QAAmC;IAClG,MAAMC,cAAcC,OAAaF;IAEjCE,gBAAsB;QACpBD,YAAY,OAAO,GAAGD;IACxB;IAEA,OAAOE,YAAkB,CAAC,GAAGC,OACpBF,YAAY,OAAO,IAAIE,OAC7B,EAAE;AACP"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Generates a unique, stable identifier that is safe for server-side rendering.
3
+ *
4
+ * @remarks
5
+ * This hook wraps React's `useId` and optionally prepends a custom prefix.
6
+ * The generated ID remains stable across re-renders and matches between server
7
+ * and client, making it ideal for associating form labels with inputs or
8
+ * managing accessible ARIA relationships.
9
+ *
10
+ * @param prefix - Optional string to prepend to the generated ID.
11
+ * @returns A unique identifier string.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * function FormField({label}) {
16
+ * const id = useId("field");
17
+ *
18
+ * return (
19
+ * <div>
20
+ * <label htmlFor={id}>{label}</label>
21
+ * <input id={id} type="text" />
22
+ * </div>
23
+ * );
24
+ * }
25
+ * ```
26
+ *
27
+ * @see {@link https://react.dev/reference/react/useId | React useId}
28
+ */
29
+ export declare function useId(prefix?: string): string;
30
+ //# sourceMappingURL=useId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useId.d.ts","sourceRoot":"","sources":["../../src/hooks/useId.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7C"}
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { useId } from "react";
3
+ function useId_useId(prefix) {
4
+ const reactId = useId();
5
+ return prefix ? `${prefix}-${reactId}` : reactId;
6
+ }
7
+ export { useId_useId as useId };
8
+
9
+ //# sourceMappingURL=useId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useId.js","sources":["../../src/hooks/useId.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Generates a unique, stable identifier that is safe for server-side rendering.\r\n *\r\n * @remarks\r\n * This hook wraps React's `useId` and optionally prepends a custom prefix.\r\n * The generated ID remains stable across re-renders and matches between server\r\n * and client, making it ideal for associating form labels with inputs or\r\n * managing accessible ARIA relationships.\r\n *\r\n * @param prefix - Optional string to prepend to the generated ID.\r\n * @returns A unique identifier string.\r\n *\r\n * @example\r\n * ```tsx\r\n * function FormField({label}) {\r\n * const id = useId(\"field\");\r\n *\r\n * return (\r\n * <div>\r\n * <label htmlFor={id}>{label}</label>\r\n * <input id={id} type=\"text\" />\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n *\r\n * @see {@link https://react.dev/reference/react/useId | React useId}\r\n */\r\nexport function useId(prefix?: string): string {\r\n const reactId = React.useId();\r\n return prefix ? `${prefix}-${reactId}` : reactId;\r\n}\r\n"],"names":["useId","prefix","reactId","React"],"mappings":";;AAgCO,SAASA,YAAMC,MAAe;IACnC,MAAMC,UAAUC;IAChB,OAAOF,SAAS,GAAGA,OAAO,CAAC,EAAEC,SAAS,GAAGA;AAC3C"}
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+ /**
3
+ * Observes element visibility using the Intersection Observer API.
4
+ *
5
+ * @remarks
6
+ * This hook creates an IntersectionObserver that watches the provided element
7
+ * reference and returns the latest `IntersectionObserverEntry`. It's useful
8
+ * for implementing lazy loading, infinite scroll, animations on scroll, and
9
+ * tracking element visibility.
10
+ *
11
+ * The observer automatically disconnects when the component unmounts or when
12
+ * the element reference changes. The hook is SSR-safe and returns `null` when
13
+ * running on the server or when the observer is not yet initialized.
14
+ *
15
+ * @param ref - A React ref object pointing to the element to observe.
16
+ * @param options - Optional IntersectionObserver configuration (threshold, root, rootMargin).
17
+ * @returns The latest IntersectionObserverEntry or null if not intersecting yet.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * function LazyImage({src, alt}: {src: string; alt: string}) {
22
+ * const imageRef = useRef<HTMLImageElement>(null);
23
+ * const entry = useIntersectionObserver(imageRef, {threshold: 0.1});
24
+ *
25
+ * return (
26
+ * <img
27
+ * ref={imageRef}
28
+ * src={entry?.isIntersecting ? src : undefined}
29
+ * alt={alt}
30
+ * />
31
+ * );
32
+ * }
33
+ * ```
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * function AnimateOnScroll({children}: {children: React.ReactNode}) {
38
+ * const ref = useRef<HTMLDivElement>(null);
39
+ * const entry = useIntersectionObserver(ref, {threshold: 0.5});
40
+ * const isVisible = entry?.isIntersecting ?? false;
41
+ *
42
+ * return (
43
+ * <div ref={ref} className={isVisible ? "fade-in" : "hidden"}>
44
+ * {children}
45
+ * </div>
46
+ * );
47
+ * }
48
+ * ```
49
+ */
50
+ export declare function useIntersectionObserver(ref: React.RefObject<Element | null>, options?: IntersectionObserverInit): IntersectionObserverEntry | null;
51
+ //# sourceMappingURL=useIntersectionObserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntersectionObserver.d.ts","sourceRoot":"","sources":["../../src/hooks/useIntersectionObserver.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,EACpC,OAAO,CAAC,EAAE,wBAAwB,GACjC,yBAAyB,GAAG,IAAI,CAyBlC"}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { useEffect, useState } from "react";
3
+ function useIntersectionObserver(ref, options) {
4
+ const [entry, setEntry] = useState(null);
5
+ useEffect(()=>{
6
+ const element = ref.current;
7
+ if (void 0 === globalThis.IntersectionObserver || !element) return;
8
+ const observer = new globalThis.IntersectionObserver(([observerEntry])=>{
9
+ if (observerEntry) setEntry(observerEntry);
10
+ }, options);
11
+ observer.observe(element);
12
+ return ()=>{
13
+ observer.disconnect();
14
+ };
15
+ }, [
16
+ ref,
17
+ options?.threshold,
18
+ options?.root,
19
+ options?.rootMargin
20
+ ]);
21
+ return entry;
22
+ }
23
+ export { useIntersectionObserver };
24
+
25
+ //# sourceMappingURL=useIntersectionObserver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useIntersectionObserver.js","sources":["../../src/hooks/useIntersectionObserver.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Observes element visibility using the Intersection Observer API.\r\n *\r\n * @remarks\r\n * This hook creates an IntersectionObserver that watches the provided element\r\n * reference and returns the latest `IntersectionObserverEntry`. It's useful\r\n * for implementing lazy loading, infinite scroll, animations on scroll, and\r\n * tracking element visibility.\r\n *\r\n * The observer automatically disconnects when the component unmounts or when\r\n * the element reference changes. The hook is SSR-safe and returns `null` when\r\n * running on the server or when the observer is not yet initialized.\r\n *\r\n * @param ref - A React ref object pointing to the element to observe.\r\n * @param options - Optional IntersectionObserver configuration (threshold, root, rootMargin).\r\n * @returns The latest IntersectionObserverEntry or null if not intersecting yet.\r\n *\r\n * @example\r\n * ```tsx\r\n * function LazyImage({src, alt}: {src: string; alt: string}) {\r\n * const imageRef = useRef<HTMLImageElement>(null);\r\n * const entry = useIntersectionObserver(imageRef, {threshold: 0.1});\r\n *\r\n * return (\r\n * <img\r\n * ref={imageRef}\r\n * src={entry?.isIntersecting ? src : undefined}\r\n * alt={alt}\r\n * />\r\n * );\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * function AnimateOnScroll({children}: {children: React.ReactNode}) {\r\n * const ref = useRef<HTMLDivElement>(null);\r\n * const entry = useIntersectionObserver(ref, {threshold: 0.5});\r\n * const isVisible = entry?.isIntersecting ?? false;\r\n *\r\n * return (\r\n * <div ref={ref} className={isVisible ? \"fade-in\" : \"hidden\"}>\r\n * {children}\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n */\r\nexport function useIntersectionObserver(\r\n ref: React.RefObject<Element | null>,\r\n options?: IntersectionObserverInit,\r\n): IntersectionObserverEntry | null {\r\n const [entry, setEntry] = React.useState<IntersectionObserverEntry | null>(null);\r\n\r\n React.useEffect(() => {\r\n const element = ref.current;\r\n\r\n // SSR safety: IntersectionObserver is not available on server\r\n if (typeof globalThis.IntersectionObserver === \"undefined\" || !element) {\r\n return;\r\n }\r\n\r\n const observer = new globalThis.IntersectionObserver(([observerEntry]) => {\r\n if (observerEntry) {\r\n setEntry(observerEntry);\r\n }\r\n }, options);\r\n\r\n observer.observe(element);\r\n\r\n return () => {\r\n observer.disconnect();\r\n };\r\n }, [ref, options?.threshold, options?.root, options?.rootMargin]);\r\n\r\n return entry;\r\n}\r\n"],"names":["useIntersectionObserver","ref","options","entry","setEntry","React","element","globalThis","observer","observerEntry"],"mappings":";;AAoDO,SAASA,wBACdC,GAAoC,EACpCC,OAAkC;IAElC,MAAM,CAACC,OAAOC,SAAS,GAAGC,SAAiD;IAE3EA,UAAgB;QACd,MAAMC,UAAUL,IAAI,OAAO;QAG3B,IAAI,AAA2C,WAApCM,WAAW,oBAAoB,IAAoB,CAACD,SAC7D;QAGF,MAAME,WAAW,IAAID,WAAW,oBAAoB,CAAC,CAAC,CAACE,cAAc;YACnE,IAAIA,eACFL,SAASK;QAEb,GAAGP;QAEHM,SAAS,OAAO,CAACF;QAEjB,OAAO;YACLE,SAAS,UAAU;QACrB;IACF,GAAG;QAACP;QAAKC,SAAS;QAAWA,SAAS;QAAMA,SAAS;KAAW;IAEhE,OAAOC;AACT"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Executes a callback function at specified intervals with automatic cleanup.
3
+ *
4
+ * @remarks
5
+ * This hook provides a declarative interface for `setInterval` that automatically
6
+ * handles cleanup on unmount and ensures the latest callback is always invoked
7
+ * (preventing stale closures). Setting the delay to `null` pauses the interval,
8
+ * which is useful for implementing play/pause functionality.
9
+ *
10
+ * Unlike raw `setInterval`, this hook guarantees that the interval is cleared
11
+ * when the component unmounts or when the delay changes, preventing memory leaks
12
+ * and unexpected behavior.
13
+ *
14
+ * @param callback - The function to execute at each interval.
15
+ * @param delay - The interval delay in milliseconds, or `null` to pause the interval.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * function Timer() {
20
+ * const [count, setCount] = useState(0);
21
+ *
22
+ * useInterval(() => {
23
+ * setCount((c) => c + 1);
24
+ * }, 1000);
25
+ *
26
+ * return <div>Count: {count}</div>;
27
+ * }
28
+ * ```
29
+ *
30
+ * @example
31
+ * ```tsx
32
+ * function PausableTimer() {
33
+ * const [count, setCount] = useState(0);
34
+ * const [isRunning, setIsRunning] = useState(true);
35
+ *
36
+ * useInterval(
37
+ * () => {
38
+ * setCount((c) => c + 1);
39
+ * },
40
+ * isRunning ? 1000 : null,
41
+ * );
42
+ *
43
+ * return (
44
+ * <div>
45
+ * <div>Count: {count}</div>
46
+ * <button onClick={() => setIsRunning(!isRunning)}>
47
+ * {isRunning ? "Pause" : "Resume"}
48
+ * </button>
49
+ * </div>
50
+ * );
51
+ * }
52
+ * ```
53
+ */
54
+ export declare function useInterval(callback: () => void, delay: number | null): void;
55
+ //# sourceMappingURL=useInterval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInterval.d.ts","sourceRoot":"","sources":["../../src/hooks/useInterval.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAsB5E"}
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useEffect, useRef } from "react";
3
+ function useInterval(callback, delay) {
4
+ const savedCallback = useRef(callback);
5
+ useEffect(()=>{
6
+ savedCallback.current = callback;
7
+ }, [
8
+ callback
9
+ ]);
10
+ useEffect(()=>{
11
+ if (null === delay) return;
12
+ const intervalId = globalThis.setInterval(()=>{
13
+ savedCallback.current();
14
+ }, delay);
15
+ return ()=>{
16
+ globalThis.clearInterval(intervalId);
17
+ };
18
+ }, [
19
+ delay
20
+ ]);
21
+ }
22
+ export { useInterval };
23
+
24
+ //# sourceMappingURL=useInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks/useInterval.js","sources":["../../src/hooks/useInterval.tsx"],"sourcesContent":["\"use client\";\r\n\r\nimport * as React from \"react\";\r\n\r\n/**\r\n * Executes a callback function at specified intervals with automatic cleanup.\r\n *\r\n * @remarks\r\n * This hook provides a declarative interface for `setInterval` that automatically\r\n * handles cleanup on unmount and ensures the latest callback is always invoked\r\n * (preventing stale closures). Setting the delay to `null` pauses the interval,\r\n * which is useful for implementing play/pause functionality.\r\n *\r\n * Unlike raw `setInterval`, this hook guarantees that the interval is cleared\r\n * when the component unmounts or when the delay changes, preventing memory leaks\r\n * and unexpected behavior.\r\n *\r\n * @param callback - The function to execute at each interval.\r\n * @param delay - The interval delay in milliseconds, or `null` to pause the interval.\r\n *\r\n * @example\r\n * ```tsx\r\n * function Timer() {\r\n * const [count, setCount] = useState(0);\r\n *\r\n * useInterval(() => {\r\n * setCount((c) => c + 1);\r\n * }, 1000);\r\n *\r\n * return <div>Count: {count}</div>;\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```tsx\r\n * function PausableTimer() {\r\n * const [count, setCount] = useState(0);\r\n * const [isRunning, setIsRunning] = useState(true);\r\n *\r\n * useInterval(\r\n * () => {\r\n * setCount((c) => c + 1);\r\n * },\r\n * isRunning ? 1000 : null,\r\n * );\r\n *\r\n * return (\r\n * <div>\r\n * <div>Count: {count}</div>\r\n * <button onClick={() => setIsRunning(!isRunning)}>\r\n * {isRunning ? \"Pause\" : \"Resume\"}\r\n * </button>\r\n * </div>\r\n * );\r\n * }\r\n * ```\r\n */\r\nexport function useInterval(callback: () => void, delay: number | null): void {\r\n const savedCallback = React.useRef(callback);\r\n\r\n // Update ref to latest callback on every render to avoid stale closures\r\n React.useEffect(() => {\r\n savedCallback.current = callback;\r\n }, [callback]);\r\n\r\n React.useEffect(() => {\r\n // Don't schedule if delay is null\r\n if (delay === null) {\r\n return;\r\n }\r\n\r\n const intervalId = globalThis.setInterval(() => {\r\n savedCallback.current();\r\n }, delay);\r\n\r\n return () => {\r\n globalThis.clearInterval(intervalId);\r\n };\r\n }, [delay]);\r\n}\r\n"],"names":["useInterval","callback","delay","savedCallback","React","intervalId","globalThis"],"mappings":";;AAyDO,SAASA,YAAYC,QAAoB,EAAEC,KAAoB;IACpE,MAAMC,gBAAgBC,OAAaH;IAGnCG,UAAgB;QACdD,cAAc,OAAO,GAAGF;IAC1B,GAAG;QAACA;KAAS;IAEbG,UAAgB;QAEd,IAAIF,AAAU,SAAVA,OACF;QAGF,MAAMG,aAAaC,WAAW,WAAW,CAAC;YACxCH,cAAc,OAAO;QACvB,GAAGD;QAEH,OAAO;YACLI,WAAW,aAAa,CAACD;QAC3B;IACF,GAAG;QAACH;KAAM;AACZ"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Persists state to localStorage with SSR safety and JSON serialization.
3
+ *
4
+ * @remarks
5
+ * This hook synchronizes state with localStorage, allowing data to persist
6
+ * across page refreshes and browser sessions. It is SSR-safe and returns the
7
+ * initial value on the server until hydration completes. The hook also syncs
8
+ * state across tabs/windows via the `storage` event and handles JSON parse
9
+ * errors gracefully by falling back to the initial value.
10
+ *
11
+ * @typeParam T - The type of the value being stored.
12
+ * @param key - The localStorage key to store the value under.
13
+ * @param initialValue - The default value to use if no value is found in localStorage.
14
+ * @returns A tuple containing the current value and a setter function.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * function UserSettings() {
19
+ * const [theme, setTheme] = useLocalStorage("theme", "light");
20
+ *
21
+ * return (
22
+ * <button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>
23
+ * Toggle theme (current: {theme})
24
+ * </button>
25
+ * );
26
+ * }
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```tsx
31
+ * function ShoppingCart() {
32
+ * const [cart, setCart] = useLocalStorage<Product[]>("cart", []);
33
+ *
34
+ * return (
35
+ * <button onClick={() => setCart((prev) => [...prev, newProduct])}>
36
+ * Add to cart ({cart.length} items)
37
+ * </button>
38
+ * );
39
+ * }
40
+ * ```
41
+ */
42
+ export declare function useLocalStorage<T>(key: string, initialValue: T): [T, (value: T | ((prev: T) => T)) => void];
43
+ //# sourceMappingURL=useLocalStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocalStorage.d.ts","sourceRoot":"","sources":["../../src/hooks/useLocalStorage.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAiE3G"}