@stacksjs/composables 0.70.88 → 0.70.90

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 (333) hide show
  1. package/dist/_shared.d.ts +49 -0
  2. package/dist/_shared.js +23 -0
  3. package/dist/cloneFnJSON.d.ts +5 -0
  4. package/dist/cloneFnJSON.js +3 -0
  5. package/dist/computedAsync.d.ts +28 -0
  6. package/dist/computedAsync.js +20 -0
  7. package/dist/computedEager.d.ts +27 -0
  8. package/dist/computedEager.js +10 -0
  9. package/dist/createEventHook.d.ts +16 -0
  10. package/dist/createEventHook.js +15 -0
  11. package/dist/createFetch.d.ts +14 -0
  12. package/dist/createFetch.js +8 -0
  13. package/dist/createGlobalState.d.ts +17 -0
  14. package/dist/createGlobalState.js +10 -0
  15. package/dist/createSharedComposable.d.ts +8 -0
  16. package/dist/createSharedComposable.js +9 -0
  17. package/dist/extendRef.d.ts +9 -0
  18. package/dist/extendRef.js +6 -0
  19. package/dist/formatTimeAgo.d.ts +23 -0
  20. package/dist/formatTimeAgo.js +33 -0
  21. package/dist/index.d.ts +271 -0
  22. package/dist/index.js +210 -0
  23. package/dist/isDefined.d.ts +5 -0
  24. package/dist/isDefined.js +3 -0
  25. package/dist/makeDestructurable.d.ts +18 -0
  26. package/dist/makeDestructurable.js +16 -0
  27. package/dist/onClickOutside.d.ts +14 -0
  28. package/dist/onClickOutside.js +25 -0
  29. package/dist/onKeyStroke.d.ts +26 -0
  30. package/dist/onKeyStroke.js +31 -0
  31. package/dist/onLongPress.d.ts +14 -0
  32. package/dist/onLongPress.js +43 -0
  33. package/dist/onStartTyping.d.ts +8 -0
  34. package/dist/onStartTyping.js +23 -0
  35. package/dist/refAutoReset.d.ts +11 -0
  36. package/dist/refAutoReset.js +15 -0
  37. package/dist/refDefault.d.ts +9 -0
  38. package/dist/refDefault.js +8 -0
  39. package/dist/resolveRef.d.ts +7 -0
  40. package/dist/resolveRef.js +7 -0
  41. package/dist/ssrHandlers.d.ts +13 -0
  42. package/dist/ssrHandlers.js +8 -0
  43. package/dist/syncRef.d.ts +21 -0
  44. package/dist/syncRef.js +35 -0
  45. package/dist/tryOnMounted.d.ts +22 -0
  46. package/dist/tryOnMounted.js +22 -0
  47. package/dist/unrefElement.d.ts +6 -0
  48. package/dist/unrefElement.js +9 -0
  49. package/dist/until.d.ts +34 -0
  50. package/dist/until.js +62 -0
  51. package/dist/useActiveElement.d.ts +6 -0
  52. package/dist/useActiveElement.js +19 -0
  53. package/dist/useAnimate.d.ts +18 -0
  54. package/dist/useAnimate.js +48 -0
  55. package/dist/useArrayUtils.d.ts +42 -0
  56. package/dist/useArrayUtils.js +114 -0
  57. package/dist/useAsyncQueue.d.ts +18 -0
  58. package/dist/useAsyncQueue.js +22 -0
  59. package/dist/useAsyncState.d.ts +23 -0
  60. package/dist/useAsyncState.js +35 -0
  61. package/dist/useBase64.d.ts +12 -0
  62. package/dist/useBase64.js +45 -0
  63. package/dist/useBattery.d.ts +15 -0
  64. package/dist/useBattery.js +38 -0
  65. package/dist/useBreakpoints.d.ts +96 -0
  66. package/dist/useBreakpoints.js +97 -0
  67. package/dist/useBroadcastChannel.d.ts +14 -0
  68. package/dist/useBroadcastChannel.js +31 -0
  69. package/dist/useBrowserLocation.d.ts +18 -0
  70. package/dist/useBrowserLocation.js +64 -0
  71. package/dist/useClipboard.d.ts +17 -0
  72. package/dist/useClipboard.js +32 -0
  73. package/dist/useClipboardItems.d.ts +11 -0
  74. package/dist/useClipboardItems.js +15 -0
  75. package/dist/useCloned.d.ts +15 -0
  76. package/dist/useCloned.js +16 -0
  77. package/dist/useColorMode.d.ts +18 -0
  78. package/dist/useColorMode.js +60 -0
  79. package/dist/useConfirmDialog.d.ts +14 -0
  80. package/dist/useConfirmDialog.js +34 -0
  81. package/dist/useCounter.d.ts +20 -0
  82. package/dist/useCounter.js +28 -0
  83. package/dist/useCssVar.d.ts +10 -0
  84. package/dist/useCssVar.js +23 -0
  85. package/dist/useCycleList.d.ts +18 -0
  86. package/dist/useCycleList.js +27 -0
  87. package/dist/useDark.d.ts +11 -0
  88. package/dist/useDark.js +38 -0
  89. package/dist/useDateFormat.d.ts +10 -0
  90. package/dist/useDateFormat.js +11 -0
  91. package/dist/useDebounce.d.ts +10 -0
  92. package/dist/useDebounce.js +16 -0
  93. package/dist/useDebounceFn.d.ts +10 -0
  94. package/dist/useDebounceFn.js +18 -0
  95. package/dist/useDebouncedRef.d.ts +11 -0
  96. package/dist/useDebouncedRef.js +22 -0
  97. package/dist/useDebouncedRefHistory.d.ts +5 -0
  98. package/dist/useDebouncedRefHistory.js +36 -0
  99. package/dist/useDeviceMotion.d.ts +27 -0
  100. package/dist/useDeviceMotion.js +53 -0
  101. package/dist/useDeviceOrientation.d.ts +15 -0
  102. package/dist/useDeviceOrientation.js +23 -0
  103. package/dist/useDevicePixelRatio.d.ts +5 -0
  104. package/dist/useDevicePixelRatio.js +24 -0
  105. package/dist/useDocumentVisibility.d.ts +5 -0
  106. package/dist/useDocumentVisibility.js +16 -0
  107. package/dist/useDraggable.d.ts +23 -0
  108. package/dist/useDraggable.js +58 -0
  109. package/dist/useDropZone.d.ts +15 -0
  110. package/dist/useDropZone.js +52 -0
  111. package/dist/useElementBounding.d.ts +21 -0
  112. package/dist/useElementBounding.js +59 -0
  113. package/dist/useElementByPoint.d.ts +10 -0
  114. package/dist/useElementByPoint.js +18 -0
  115. package/dist/useElementHover.d.ts +9 -0
  116. package/dist/useElementHover.js +28 -0
  117. package/dist/useElementSize.d.ts +19 -0
  118. package/dist/useElementSize.js +34 -0
  119. package/dist/useElementVisibility.d.ts +10 -0
  120. package/dist/useElementVisibility.js +10 -0
  121. package/dist/useEventBus.d.ts +14 -0
  122. package/dist/useEventBus.js +41 -0
  123. package/dist/useEventListener.d.ts +14 -0
  124. package/dist/useEventListener.js +29 -0
  125. package/dist/useEventSource.d.ts +32 -0
  126. package/dist/useEventSource.js +72 -0
  127. package/dist/useEyeDropper.d.ts +10 -0
  128. package/dist/useEyeDropper.js +17 -0
  129. package/dist/useFavicon.d.ts +8 -0
  130. package/dist/useFavicon.js +22 -0
  131. package/dist/useFetch.d.ts +35 -0
  132. package/dist/useFetch.js +61 -0
  133. package/dist/useFileDialog.d.ts +15 -0
  134. package/dist/useFileDialog.js +24 -0
  135. package/dist/useFocus.d.ts +13 -0
  136. package/dist/useFocus.js +42 -0
  137. package/dist/useFocusWithin.d.ts +9 -0
  138. package/dist/useFocusWithin.js +29 -0
  139. package/dist/useForm.d.ts +97 -0
  140. package/dist/useForm.js +182 -0
  141. package/dist/useFps.d.ts +7 -0
  142. package/dist/useFps.js +22 -0
  143. package/dist/useFullscreen.d.ts +16 -0
  144. package/dist/useFullscreen.js +67 -0
  145. package/dist/useGeolocation.d.ts +26 -0
  146. package/dist/useGeolocation.js +55 -0
  147. package/dist/useIdle.d.ts +18 -0
  148. package/dist/useIdle.js +46 -0
  149. package/dist/useImage.d.ts +18 -0
  150. package/dist/useImage.js +32 -0
  151. package/dist/useInfiniteScroll.d.ts +11 -0
  152. package/dist/useInfiniteScroll.js +50 -0
  153. package/dist/useIntersectionObserver.d.ts +16 -0
  154. package/dist/useIntersectionObserver.js +27 -0
  155. package/dist/useInterval.d.ts +13 -0
  156. package/dist/useInterval.js +32 -0
  157. package/dist/useIntervalFn.d.ts +16 -0
  158. package/dist/useIntervalFn.js +24 -0
  159. package/dist/useKeyModifier.d.ts +6 -0
  160. package/dist/useKeyModifier.js +22 -0
  161. package/dist/useLastChanged.d.ts +11 -0
  162. package/dist/useLastChanged.js +8 -0
  163. package/dist/useLocalStorage.d.ts +17 -0
  164. package/dist/useLocalStorage.js +4 -0
  165. package/dist/useMagicKeys.d.ts +16 -0
  166. package/dist/useMagicKeys.js +81 -0
  167. package/dist/useManualRefHistory.d.ts +27 -0
  168. package/dist/useManualRefHistory.js +64 -0
  169. package/dist/useMath.d.ts +17 -0
  170. package/dist/useMath.js +52 -0
  171. package/dist/useMediaQuery.d.ts +9 -0
  172. package/dist/useMediaQuery.js +19 -0
  173. package/dist/useMemoize.d.ts +13 -0
  174. package/dist/useMemoize.js +24 -0
  175. package/dist/useMounted.d.ts +6 -0
  176. package/dist/useMounted.js +8 -0
  177. package/dist/useMouse.d.ts +19 -0
  178. package/dist/useMouse.js +67 -0
  179. package/dist/useMouseInElement.d.ts +17 -0
  180. package/dist/useMouseInElement.js +31 -0
  181. package/dist/useMousePressed.d.ts +10 -0
  182. package/dist/useMousePressed.js +31 -0
  183. package/dist/useMutationObserver.d.ts +16 -0
  184. package/dist/useMutationObserver.js +27 -0
  185. package/dist/useNavigatorLanguage.d.ts +5 -0
  186. package/dist/useNavigatorLanguage.js +17 -0
  187. package/dist/useNetwork.d.ts +18 -0
  188. package/dist/useNetwork.js +58 -0
  189. package/dist/useNow.d.ts +8 -0
  190. package/dist/useNow.js +10 -0
  191. package/dist/useObjectUrl.d.ts +8 -0
  192. package/dist/useObjectUrl.js +23 -0
  193. package/dist/useOffsetPagination.d.ts +21 -0
  194. package/dist/useOffsetPagination.js +45 -0
  195. package/dist/useOnline.d.ts +7 -0
  196. package/dist/useOnline.js +20 -0
  197. package/dist/usePageLeave.d.ts +9 -0
  198. package/dist/usePageLeave.js +27 -0
  199. package/dist/useParallax.d.ts +15 -0
  200. package/dist/useParallax.js +33 -0
  201. package/dist/useParentElement.d.ts +6 -0
  202. package/dist/useParentElement.js +8 -0
  203. package/dist/usePermission.d.ts +7 -0
  204. package/dist/usePermission.js +21 -0
  205. package/dist/usePointer.d.ts +15 -0
  206. package/dist/usePointer.js +32 -0
  207. package/dist/usePointerLock.d.ts +13 -0
  208. package/dist/usePointerLock.js +33 -0
  209. package/dist/usePointerSwipe.d.ts +20 -0
  210. package/dist/usePointerSwipe.js +52 -0
  211. package/dist/usePreferredColorScheme.d.ts +6 -0
  212. package/dist/usePreferredColorScheme.js +25 -0
  213. package/dist/usePreferredContrast.d.ts +6 -0
  214. package/dist/usePreferredContrast.js +29 -0
  215. package/dist/usePreferredLanguages.d.ts +5 -0
  216. package/dist/usePreferredLanguages.js +16 -0
  217. package/dist/usePreferredReducedMotion.d.ts +6 -0
  218. package/dist/usePreferredReducedMotion.js +18 -0
  219. package/dist/usePrevious.d.ts +9 -0
  220. package/dist/usePrevious.js +8 -0
  221. package/dist/useQuery.d.ts +106 -0
  222. package/dist/useQuery.js +265 -0
  223. package/dist/useRafFn.d.ts +19 -0
  224. package/dist/useRafFn.js +37 -0
  225. package/dist/useRefHistory.d.ts +28 -0
  226. package/dist/useRefHistory.js +72 -0
  227. package/dist/useResizeObserver.d.ts +16 -0
  228. package/dist/useResizeObserver.js +27 -0
  229. package/dist/useScreenOrientation.d.ts +13 -0
  230. package/dist/useScreenOrientation.js +27 -0
  231. package/dist/useScreenSafeArea.d.ts +12 -0
  232. package/dist/useScreenSafeArea.js +25 -0
  233. package/dist/useScriptTag.d.ts +20 -0
  234. package/dist/useScriptTag.js +52 -0
  235. package/dist/useScroll.d.ts +36 -0
  236. package/dist/useScroll.js +116 -0
  237. package/dist/useScrollLock.d.ts +10 -0
  238. package/dist/useScrollLock.js +39 -0
  239. package/dist/useSessionStorage.d.ts +17 -0
  240. package/dist/useSessionStorage.js +4 -0
  241. package/dist/useShare.d.ts +15 -0
  242. package/dist/useShare.js +11 -0
  243. package/dist/useSorted.d.ts +10 -0
  244. package/dist/useSorted.js +10 -0
  245. package/dist/useStepper.d.ts +23 -0
  246. package/dist/useStepper.js +46 -0
  247. package/dist/useStorage.d.ts +18 -0
  248. package/dist/useStorage.js +54 -0
  249. package/dist/useStyleTag.d.ts +17 -0
  250. package/dist/useStyleTag.js +39 -0
  251. package/dist/useSupported.d.ts +8 -0
  252. package/dist/useSupported.js +10 -0
  253. package/dist/useSwipe.d.ts +20 -0
  254. package/dist/useSwipe.js +58 -0
  255. package/dist/useTextDirection.d.ts +9 -0
  256. package/dist/useTextDirection.js +16 -0
  257. package/dist/useTextSelection.d.ts +10 -0
  258. package/dist/useTextSelection.js +27 -0
  259. package/dist/useTextareaAutosize.d.ts +10 -0
  260. package/dist/useTextareaAutosize.js +20 -0
  261. package/dist/useThrottle.d.ts +9 -0
  262. package/dist/useThrottle.js +23 -0
  263. package/dist/useThrottleFn.d.ts +11 -0
  264. package/dist/useThrottleFn.js +36 -0
  265. package/dist/useThrottledRef.d.ts +11 -0
  266. package/dist/useThrottledRef.js +30 -0
  267. package/dist/useThrottledRefHistory.d.ts +5 -0
  268. package/dist/useThrottledRefHistory.js +43 -0
  269. package/dist/useTimeAgo.d.ts +16 -0
  270. package/dist/useTimeAgo.js +58 -0
  271. package/dist/useTimeout.d.ts +12 -0
  272. package/dist/useTimeout.js +32 -0
  273. package/dist/useTimeoutFn.d.ts +16 -0
  274. package/dist/useTimeoutFn.js +27 -0
  275. package/dist/useTimeoutPoll.d.ts +10 -0
  276. package/dist/useTimeoutPoll.js +33 -0
  277. package/dist/useTimestamp.d.ts +15 -0
  278. package/dist/useTimestamp.js +43 -0
  279. package/dist/useTitle.d.ts +10 -0
  280. package/dist/useTitle.js +12 -0
  281. package/dist/useToNumber.d.ts +11 -0
  282. package/dist/useToNumber.js +25 -0
  283. package/dist/useToString.d.ts +6 -0
  284. package/dist/useToString.js +10 -0
  285. package/dist/useToggle.d.ts +6 -0
  286. package/dist/useToggle.js +12 -0
  287. package/dist/useTransition.d.ts +28 -0
  288. package/dist/useTransition.js +89 -0
  289. package/dist/useUrlSearchParams.d.ts +18 -0
  290. package/dist/useUrlSearchParams.js +72 -0
  291. package/dist/useVibrate.d.ts +13 -0
  292. package/dist/useVibrate.js +14 -0
  293. package/dist/useVirtualList.d.ts +23 -0
  294. package/dist/useVirtualList.js +49 -0
  295. package/dist/useWakeLock.d.ts +12 -0
  296. package/dist/useWakeLock.js +32 -0
  297. package/dist/useWebNotification.d.ts +25 -0
  298. package/dist/useWebNotification.js +39 -0
  299. package/dist/useWebSocket.d.ts +38 -0
  300. package/dist/useWebSocket.js +103 -0
  301. package/dist/useWebWorker.d.ts +18 -0
  302. package/dist/useWebWorker.js +56 -0
  303. package/dist/useWindowFocus.d.ts +5 -0
  304. package/dist/useWindowFocus.js +20 -0
  305. package/dist/useWindowScroll.d.ts +9 -0
  306. package/dist/useWindowScroll.js +17 -0
  307. package/dist/useWindowSize.d.ts +15 -0
  308. package/dist/useWindowSize.js +28 -0
  309. package/dist/watchArray.d.ts +5 -0
  310. package/dist/watchArray.js +9 -0
  311. package/dist/watchAtMost.d.ts +5 -0
  312. package/dist/watchAtMost.js +12 -0
  313. package/dist/watchDebounced.d.ts +23 -0
  314. package/dist/watchDebounced.js +20 -0
  315. package/dist/watchDeep.d.ts +7 -0
  316. package/dist/watchDeep.js +13 -0
  317. package/dist/watchIgnorable.d.ts +12 -0
  318. package/dist/watchIgnorable.js +19 -0
  319. package/dist/watchImmediate.d.ts +5 -0
  320. package/dist/watchImmediate.js +7 -0
  321. package/dist/watchOnce.d.ts +19 -0
  322. package/dist/watchOnce.js +17 -0
  323. package/dist/watchPausable.d.ts +13 -0
  324. package/dist/watchPausable.js +23 -0
  325. package/dist/watchThrottled.d.ts +23 -0
  326. package/dist/watchThrottled.js +37 -0
  327. package/dist/watchTriggerable.d.ts +5 -0
  328. package/dist/watchTriggerable.js +10 -0
  329. package/dist/watchWithFilter.d.ts +7 -0
  330. package/dist/watchWithFilter.js +6 -0
  331. package/dist/whenever.d.ts +18 -0
  332. package/dist/whenever.js +7 -0
  333. package/package.json +2 -2
@@ -0,0 +1,49 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Unwrap a MaybeRef to its raw value.
4
+ */
5
+ export declare function unref<T>(val: MaybeRef<T>): T;
6
+ /**
7
+ * Unwrap a MaybeRefOrGetter to its raw value.
8
+ */
9
+ export declare function toValue<T>(val: MaybeRefOrGetter<T>): T;
10
+ /**
11
+ * Check if a value is a Ref.
12
+ */
13
+ export declare function isRef<T>(val: MaybeRef<T>): val is Ref<T>;
14
+ /**
15
+ * No-op function for default callbacks.
16
+ */
17
+ export declare function noop(): void;
18
+ /**
19
+ * Get the default window, SSR-safe.
20
+ */
21
+ export declare function defaultWindow(): Window | undefined;
22
+ /**
23
+ * Get the default document, SSR-safe.
24
+ */
25
+ export declare function defaultDocument(): Document | undefined;
26
+ /**
27
+ * Get the default navigator, SSR-safe.
28
+ */
29
+ export declare function defaultNavigator(): Navigator | undefined;
30
+ /**
31
+ * Type helper for configurable window.
32
+ */
33
+ export declare interface ConfigurableWindow {
34
+ window?: Window
35
+ }
36
+ /**
37
+ * Type helper for configurable document.
38
+ */
39
+ export declare interface ConfigurableDocument {
40
+ document?: Document
41
+ }
42
+ /**
43
+ * A value that may be a raw value or a Ref.
44
+ */
45
+ export type MaybeRef<T> = T | Ref<T>;
46
+ /**
47
+ * A value that may be a raw value, a Ref, or a getter function.
48
+ */
49
+ export type MaybeRefOrGetter<T> = T | Ref<T> | (() => T);
@@ -0,0 +1,23 @@
1
+ export function unref(val) {
2
+ if (val && typeof val === "object" && "value" in val && "subscribe" in val)
3
+ return val.value;
4
+ return val;
5
+ }
6
+ export function toValue(val) {
7
+ if (typeof val === "function")
8
+ return val();
9
+ return unref(val);
10
+ }
11
+ export function isRef(val) {
12
+ return val !== null && typeof val === "object" && "value" in val && "subscribe" in val;
13
+ }
14
+ export function noop() {}
15
+ export function defaultWindow() {
16
+ return typeof window < "u" ? window : void 0;
17
+ }
18
+ export function defaultDocument() {
19
+ return typeof document < "u" ? document : void 0;
20
+ }
21
+ export function defaultNavigator() {
22
+ return typeof navigator < "u" ? navigator : void 0;
23
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Clone a value using JSON serialization.
3
+ * Works for JSON-serializable values (no functions, symbols, etc).
4
+ */
5
+ export declare function cloneFnJSON<T>(value: T): T;
@@ -0,0 +1,3 @@
1
+ export function cloneFnJSON(value) {
2
+ return JSON.parse(JSON.stringify(value));
3
+ }
@@ -0,0 +1,28 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Create an async computed ref.
4
+ *
5
+ * Returns a ref whose value is the result of an asynchronous evaluation function.
6
+ * Since stx does not auto-track dependencies like Vue's watchEffect, you can
7
+ * provide an optional array of dependency refs. When any dependency changes,
8
+ * the evaluation callback is re-run.
9
+ *
10
+ * @param evaluationCallback - An async function that returns the computed value
11
+ * @param initialState - The initial value before the first evaluation completes
12
+ * @param deps - Optional array of reactive refs to watch for re-evaluation
13
+ * @returns A ref containing the async computed value
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * const userId = ref(1)
18
+ * const user = computedAsync(
19
+ * async () => {
20
+ * const response = await fetch(`/api/users/${userId.value}`)
21
+ * return response.json()
22
+ * },
23
+ * null,
24
+ * [userId],
25
+ * )
26
+ * ```
27
+ */
28
+ export declare function computedAsync<T>(evaluationCallback: () => Promise<T>, initialState: T, deps?: Ref<any>[]): Ref<T>;
@@ -0,0 +1,20 @@
1
+ import { ref, watch } from "@stacksjs/stx";
2
+ export function computedAsync(evaluationCallback, initialState, deps) {
3
+ const result = ref(initialState);
4
+ let currentEvalId = 0;
5
+ async function evaluate() {
6
+ const evalId = ++currentEvalId;
7
+ try {
8
+ const value = await evaluationCallback();
9
+ if (evalId === currentEvalId)
10
+ result.value = value;
11
+ } catch {}
12
+ }
13
+ evaluate();
14
+ if (deps && deps.length > 0)
15
+ for (const dep of deps)
16
+ watch(dep, () => {
17
+ evaluate();
18
+ });
19
+ return result;
20
+ }
@@ -0,0 +1,27 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Create an eagerly evaluated computed ref.
4
+ *
5
+ * Unlike the standard lazy `computed()`, this evaluates the function immediately
6
+ * whenever any watched dependency changes, rather than deferring evaluation
7
+ * until `.value` is accessed. This is useful when you want to precompute values
8
+ * eagerly.
9
+ *
10
+ * Since stx does not auto-track dependencies in the same way as Vue's computed,
11
+ * this accepts an optional array of dependency refs to watch. When any dependency
12
+ * changes, the function is re-evaluated immediately.
13
+ *
14
+ * @param fn - A synchronous function that returns the computed value
15
+ * @param deps - Optional array of reactive refs to watch for re-evaluation
16
+ * @returns A ref containing the eagerly computed value
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const list = ref([1, 2, 3, 4, 5])
21
+ * const sum = computedEager(() => list.value.reduce((a, b) => a + b, 0), [list])
22
+ * console.log(sum.value) // 15
23
+ * list.value = [10, 20]
24
+ * console.log(sum.value) // 30
25
+ * ```
26
+ */
27
+ export declare function computedEager<T>(fn: () => T, deps?: Ref<any>[]): Ref<T>;
@@ -0,0 +1,10 @@
1
+ import { ref, watch } from "@stacksjs/stx";
2
+ export function computedEager(fn, deps) {
3
+ const result = ref(fn());
4
+ if (deps && deps.length > 0)
5
+ for (const dep of deps)
6
+ watch(dep, () => {
7
+ result.value = fn();
8
+ });
9
+ return result;
10
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Create a typed event hook that can be triggered and subscribed to.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const onFetch = createEventHook<Response>()
7
+ * onFetch.on((response) => console.log(response))
8
+ * onFetch.trigger(new Response())
9
+ * ```
10
+ */
11
+ export declare function createEventHook<T = any>(): EventHookOn<T>;
12
+ export declare interface EventHookOn<T = any> {
13
+ on: (fn: (param: T) => void) => { off: () => void }
14
+ off: (fn: (param: T) => void) => void
15
+ trigger: (param: T) => void
16
+ }
@@ -0,0 +1,15 @@
1
+ export function createEventHook() {
2
+ const fns = new Set;
3
+ function on(fn) {
4
+ fns.add(fn);
5
+ return { off: () => fns.delete(fn) };
6
+ }
7
+ function off(fn) {
8
+ fns.delete(fn);
9
+ }
10
+ function trigger(param) {
11
+ for (const fn of fns)
12
+ fn(param);
13
+ }
14
+ return { on, off, trigger };
15
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Create a pre-configured useFetch instance with a base URL and default options.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const useMyFetch = createFetch({ baseUrl: '/api' })
7
+ * const { data, error } = await useMyFetch('/users').get().json()
8
+ * ```
9
+ */
10
+ export declare function createFetch(config?: CreateFetchOptions): void;
11
+ export declare interface CreateFetchOptions {
12
+ baseUrl?: string
13
+ options?: RequestInit
14
+ }
@@ -0,0 +1,8 @@
1
+ import { useFetch } from "./useFetch";
2
+ export function createFetch(config = {}) {
3
+ const { baseUrl = "" } = config;
4
+ return function(url) {
5
+ const fullUrl = baseUrl ? `${baseUrl.replace(/\/$/, "")}/${url.replace(/^\//, "")}` : url;
6
+ return useFetch(fullUrl);
7
+ };
8
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Keep state in the global scope to be reusable across components.
3
+ *
4
+ * @param stateFactory - A function that creates the state
5
+ * @returns A function that returns the shared state
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const useGlobalCount = createGlobalState(() => {
10
+ * const count = ref(0)
11
+ * return { count }
12
+ * })
13
+ * // In any component:
14
+ * const { count } = useGlobalCount()
15
+ * ```
16
+ */
17
+ export declare function createGlobalState<T>(stateFactory: () => T): () => T;
@@ -0,0 +1,10 @@
1
+ export function createGlobalState(stateFactory) {
2
+ let initialized = !1, state;
3
+ return () => {
4
+ if (!initialized) {
5
+ state = stateFactory();
6
+ initialized = !0;
7
+ }
8
+ return state;
9
+ };
10
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Make a composable function usable with multiple consumers.
3
+ * The composable is only invoked once, and the result is shared.
4
+ *
5
+ * @param composable - The composable function to share
6
+ * @returns A shared version of the composable
7
+ */
8
+ export declare function createSharedComposable<Fn extends (...args: any[]) => any>(composable: Fn): Fn;
@@ -0,0 +1,9 @@
1
+ export function createSharedComposable(composable) {
2
+ let subscribers = 0, state;
3
+ return (...args) => {
4
+ subscribers++;
5
+ if (!state)
6
+ state = composable(...args);
7
+ return state;
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Extend a ref with additional properties.
4
+ *
5
+ * @param ref - The ref to extend
6
+ * @param extend - The properties to add
7
+ * @returns The extended ref
8
+ */
9
+ export declare function extendRef<T, E extends Record<string, any>>(r: Ref<T>, extend: E): Ref<T> & E;
@@ -0,0 +1,6 @@
1
+ export function extendRef(r, extend) {
2
+ for (const [key, value] of Object.entries(extend))
3
+ if (key !== "value")
4
+ r[key] = value;
5
+ return r;
6
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Format a date to a human-readable time-ago string.
3
+ *
4
+ * @param date - The date to format
5
+ * @param options - Formatting options
6
+ */
7
+ export declare function formatTimeAgo(date: Date | number | string, options?: FormatTimeAgoOptions): string;
8
+ export declare interface FormatTimeAgoOptions {
9
+ max?: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'
10
+ fullDateFormatter?: (date: Date) => string
11
+ messages?: Partial<{
12
+ justNow: string
13
+ past: (n: string) => string
14
+ future: (n: string) => string
15
+ second: (n: number) => string
16
+ minute: (n: number) => string
17
+ hour: (n: number) => string
18
+ day: (n: number) => string
19
+ week: (n: number) => string
20
+ month: (n: number) => string
21
+ year: (n: number) => string
22
+ }>
23
+ }
@@ -0,0 +1,33 @@
1
+ const defaultMessages = {
2
+ justNow: "just now",
3
+ past: (n) => `${n} ago`,
4
+ future: (n) => `in ${n}`,
5
+ second: (n) => `${n} second${n > 1 ? "s" : ""}`,
6
+ minute: (n) => `${n} minute${n > 1 ? "s" : ""}`,
7
+ hour: (n) => `${n} hour${n > 1 ? "s" : ""}`,
8
+ day: (n) => `${n} day${n > 1 ? "s" : ""}`,
9
+ week: (n) => `${n} week${n > 1 ? "s" : ""}`,
10
+ month: (n) => `${n} month${n > 1 ? "s" : ""}`,
11
+ year: (n) => `${n} year${n > 1 ? "s" : ""}`
12
+ };
13
+ export function formatTimeAgo(date, options = {}) {
14
+ const messages = { ...defaultMessages, ...options.messages }, d = date instanceof Date ? date : new Date(date), diff = Date.now() - d.getTime(), absDiff = Math.abs(diff), seconds = Math.floor(absDiff / 1000), minutes = Math.floor(seconds / 60), hours = Math.floor(minutes / 60), days = Math.floor(hours / 24), weeks = Math.floor(days / 7), months = Math.floor(days / 30), years = Math.floor(days / 365), isFuture = diff < 0;
15
+ function format(value) {
16
+ return isFuture ? messages.future(value) : messages.past(value);
17
+ }
18
+ if (seconds < 5)
19
+ return messages.justNow;
20
+ if (seconds < 60)
21
+ return format(messages.second(seconds));
22
+ if (minutes < 60)
23
+ return format(messages.minute(minutes));
24
+ if (hours < 24)
25
+ return format(messages.hour(hours));
26
+ if (days < 7)
27
+ return format(messages.day(days));
28
+ if (weeks < 4)
29
+ return format(messages.week(weeks));
30
+ if (months < 12)
31
+ return format(messages.month(months));
32
+ return format(messages.year(years));
33
+ }
@@ -0,0 +1,271 @@
1
+ export type { ConfigurableDocument, ConfigurableWindow, MaybeRef, MaybeRefOrGetter } from './_shared';
2
+ export type {
3
+ QueryClient,
4
+ QueryKey,
5
+ UseMutationOptions,
6
+ UseMutationResult,
7
+ UseQueryOptions,
8
+ UseQueryResult,
9
+ } from './useQuery';
10
+ export type {
11
+ FormFieldAccessor,
12
+ FormValidator,
13
+ UseFormOptions,
14
+ UseFormResult,
15
+ ValidationMode,
16
+ } from './useForm';
17
+ // Shared utilities & types
18
+ export { defaultDocument, defaultNavigator, defaultWindow, isRef, noop, toValue, unref } from './_shared';
19
+ export { getSSRHandler, setSSRHandler, customStorageEventName } from './ssrHandlers';
20
+ // Storage
21
+ export { useStorage } from './useStorage';
22
+ export { useLocalStorage } from './useLocalStorage';
23
+ export { useSessionStorage } from './useSessionStorage';
24
+ // Color mode / Dark mode
25
+ export { useDark, usePreferredDark } from './useDark';
26
+ export { useColorMode } from './useColorMode';
27
+ export { usePreferredColorScheme } from './usePreferredColorScheme';
28
+ export { usePreferredContrast } from './usePreferredContrast';
29
+ export { usePreferredReducedMotion } from './usePreferredReducedMotion';
30
+ // Online / Network
31
+ export { useOnline } from './useOnline';
32
+ export { useNetwork } from './useNetwork';
33
+ // Toggle
34
+ export { useToggle } from './useToggle';
35
+ // Fetch
36
+ export { useFetch } from './useFetch';
37
+ export { createFetch } from './createFetch';
38
+ // Query / Mutation (stacksjs/stacks#1939)
39
+ export { createQueryClient, queryClient, useMutation, useQuery } from './useQuery';
40
+ // Form primitive (stacksjs/stacks#1940)
41
+ export { useForm } from './useForm';
42
+ // Date / Time
43
+ export { useDateFormat } from './useDateFormat';
44
+ export { useNow } from './useNow';
45
+ export { useTimestamp } from './useTimestamp';
46
+ export { useTimeAgo } from './useTimeAgo';
47
+ // Event listeners
48
+ export { useEventListener } from './useEventListener';
49
+ export { useEventBus } from './useEventBus';
50
+ export { createEventHook } from './createEventHook';
51
+ // Debounce / Throttle
52
+ export { useDebounceFn } from './useDebounceFn';
53
+ export { useThrottleFn } from './useThrottleFn';
54
+ export { useDebouncedRef } from './useDebouncedRef';
55
+ export { useThrottledRef } from './useThrottledRef';
56
+ export { useDebounce } from './useDebounce';
57
+ export { useThrottle } from './useThrottle';
58
+ // Timing
59
+ export { useInterval } from './useInterval';
60
+ export { useIntervalFn } from './useIntervalFn';
61
+ export { useTimeout } from './useTimeout';
62
+ export { useTimeoutFn } from './useTimeoutFn';
63
+ export { useTimeoutPoll } from './useTimeoutPoll';
64
+ export { useRafFn } from './useRafFn';
65
+ export { useFps } from './useFps';
66
+ // Clipboard
67
+ export { useClipboard } from './useClipboard';
68
+ export { useClipboardItems } from './useClipboardItems';
69
+ // Media / Responsive
70
+ export { useMediaQuery } from './useMediaQuery';
71
+ export {
72
+ breakpointsAntDesign,
73
+ breakpointsBootstrap,
74
+ breakpointsBootstrapV5,
75
+ breakpointsMasterCss,
76
+ breakpointsQuasar,
77
+ breakpointsSematic,
78
+ breakpointsTailwind,
79
+ breakpointsVuetify,
80
+ useBreakpoints,
81
+ } from './useBreakpoints';
82
+ // Document / Page
83
+ export { useTitle } from './useTitle';
84
+ export { useFavicon } from './useFavicon';
85
+ export { useDocumentVisibility } from './useDocumentVisibility';
86
+ export { useTextDirection } from './useTextDirection';
87
+ export { useTextSelection } from './useTextSelection';
88
+ // URL / Location
89
+ export { useUrlSearchParams } from './useUrlSearchParams';
90
+ export { useBrowserLocation } from './useBrowserLocation';
91
+ // Window
92
+ export { useWindowSize } from './useWindowSize';
93
+ export { useWindowFocus } from './useWindowFocus';
94
+ export { useWindowScroll } from './useWindowScroll';
95
+ // Scroll
96
+ export { useScroll } from './useScroll';
97
+ export { useScrollLock } from './useScrollLock';
98
+ export { useInfiniteScroll } from './useInfiniteScroll';
99
+ // Fullscreen
100
+ export { useFullscreen } from './useFullscreen';
101
+ // Click / Keyboard / Interaction
102
+ export { onClickOutside } from './onClickOutside';
103
+ export { onKeyStroke, onKeyDown, onKeyUp } from './onKeyStroke';
104
+ export { onLongPress } from './onLongPress';
105
+ export { onStartTyping } from './onStartTyping';
106
+ export { useKeyModifier } from './useKeyModifier';
107
+ export { useMagicKeys } from './useMagicKeys';
108
+ // Math / Logic
109
+ export {
110
+ and,
111
+ logicNot,
112
+ logicOr,
113
+ or,
114
+ useAbs,
115
+ useAverage,
116
+ useCeil,
117
+ useClamp,
118
+ useFloor,
119
+ useMax,
120
+ useMin,
121
+ usePrecision,
122
+ useRound,
123
+ useSum,
124
+ useTrunc,
125
+ } from './useMath';
126
+ // State / Counter / History
127
+ export { useCounter } from './useCounter';
128
+ export { usePrevious } from './usePrevious';
129
+ export { useLastChanged } from './useLastChanged';
130
+ export { useStepper } from './useStepper';
131
+ export { useCycleList } from './useCycleList';
132
+ export { useSorted } from './useSorted';
133
+ export { useCloned } from './useCloned';
134
+ export { useManualRefHistory } from './useManualRefHistory';
135
+ export { useRefHistory } from './useRefHistory';
136
+ export { useDebouncedRefHistory } from './useDebouncedRefHistory';
137
+ export { useThrottledRefHistory } from './useThrottledRefHistory';
138
+ // Async
139
+ export { useAsyncState } from './useAsyncState';
140
+ export { useAsyncQueue } from './useAsyncQueue';
141
+ // Watchers
142
+ export { whenever } from './whenever';
143
+ export { watchOnce } from './watchOnce';
144
+ export { watchDebounced } from './watchDebounced';
145
+ export { watchThrottled } from './watchThrottled';
146
+ export { watchPausable, pausableWatch } from './watchPausable';
147
+ export { watchIgnorable, ignorableWatch } from './watchIgnorable';
148
+ export { watchArray } from './watchArray';
149
+ export { watchAtMost } from './watchAtMost';
150
+ export { watchDeep } from './watchDeep';
151
+ export { watchImmediate } from './watchImmediate';
152
+ export { watchTriggerable } from './watchTriggerable';
153
+ export { watchWithFilter } from './watchWithFilter';
154
+ // WebSocket / EventSource
155
+ export { useWebSocket } from './useWebSocket';
156
+ export { useEventSource } from './useEventSource';
157
+ export { useBroadcastChannel } from './useBroadcastChannel';
158
+ // Computed
159
+ export { computedAsync } from './computedAsync';
160
+ export { computedEager } from './computedEager';
161
+ // Observers
162
+ export { useIntersectionObserver } from './useIntersectionObserver';
163
+ export { useResizeObserver } from './useResizeObserver';
164
+ export { useMutationObserver } from './useMutationObserver';
165
+ // Element
166
+ export { useElementSize } from './useElementSize';
167
+ export { useElementBounding } from './useElementBounding';
168
+ export { useElementVisibility } from './useElementVisibility';
169
+ export { useElementHover } from './useElementHover';
170
+ export { useElementByPoint } from './useElementByPoint';
171
+ export { useCssVar } from './useCssVar';
172
+ export { unrefElement } from './unrefElement';
173
+ // Mouse / Pointer
174
+ export { useMouse } from './useMouse';
175
+ export { useMouseInElement } from './useMouseInElement';
176
+ export { useMousePressed } from './useMousePressed';
177
+ export { usePointer } from './usePointer';
178
+ export { useSwipe } from './useSwipe';
179
+ export { usePointerSwipe } from './usePointerSwipe';
180
+ export { usePointerLock } from './usePointerLock';
181
+ export { useParallax } from './useParallax';
182
+ // Sensors / Device
183
+ export { useGeolocation } from './useGeolocation';
184
+ export { useDeviceMotion } from './useDeviceMotion';
185
+ export { useDeviceOrientation } from './useDeviceOrientation';
186
+ export { useDevicePixelRatio } from './useDevicePixelRatio';
187
+ export { useBattery } from './useBattery';
188
+ // Focus
189
+ export { useFocus } from './useFocus';
190
+ export { useFocusWithin } from './useFocusWithin';
191
+ export { useActiveElement } from './useActiveElement';
192
+ // Idle / Page
193
+ export { useIdle } from './useIdle';
194
+ export { usePageLeave } from './usePageLeave';
195
+ export { useMounted } from './useMounted';
196
+ // Drag / Drop
197
+ export { useDraggable } from './useDraggable';
198
+ export { useDropZone } from './useDropZone';
199
+ // Navigation
200
+ export { useNavigatorLanguage } from './useNavigatorLanguage';
201
+ export { usePreferredLanguages } from './usePreferredLanguages';
202
+ export { useScreenOrientation } from './useScreenOrientation';
203
+ export { useScreenSafeArea } from './useScreenSafeArea';
204
+ export { useParentElement } from './useParentElement';
205
+ // Permissions / Share
206
+ export { usePermission } from './usePermission';
207
+ export { useShare } from './useShare';
208
+ // Object / Blob
209
+ export { useObjectUrl } from './useObjectUrl';
210
+ export { useImage } from './useImage';
211
+ export { useBase64 } from './useBase64';
212
+ // Animate / Transition
213
+ export { useAnimate } from './useAnimate';
214
+ export { useTransition, executeTransition, TransitionPresets } from './useTransition';
215
+ // Script / Style
216
+ export { useScriptTag } from './useScriptTag';
217
+ export { useStyleTag } from './useStyleTag';
218
+ // Dialogs / Files
219
+ export { useConfirmDialog } from './useConfirmDialog';
220
+ export { useFileDialog } from './useFileDialog';
221
+ export { useEyeDropper } from './useEyeDropper';
222
+ export { useTextareaAutosize } from './useTextareaAutosize';
223
+ // Notifications / Vibration / Wake
224
+ export { useWebNotification } from './useWebNotification';
225
+ export { useVibrate } from './useVibrate';
226
+ export { useWakeLock } from './useWakeLock';
227
+ // Workers
228
+ export { useWebWorker, useWebWorkerFn } from './useWebWorker';
229
+ // Virtual list / Pagination
230
+ export { useVirtualList } from './useVirtualList';
231
+ export { useOffsetPagination } from './useOffsetPagination';
232
+ // Utility composables
233
+ export { isDefined } from './isDefined';
234
+ export { useSupported } from './useSupported';
235
+ export { useToNumber } from './useToNumber';
236
+ export { useToString } from './useToString';
237
+ export { refDefault } from './refDefault';
238
+ export { refAutoReset, autoResetRef } from './refAutoReset';
239
+ export { cloneFnJSON } from './cloneFnJSON';
240
+ export { formatTimeAgo } from './formatTimeAgo';
241
+ export { until } from './until';
242
+ export { resolveRef } from './resolveRef';
243
+ export { extendRef } from './extendRef';
244
+ export { useMemoize } from './useMemoize';
245
+ export { makeDestructurable } from './makeDestructurable';
246
+ export { syncRef, syncRefs } from './syncRef';
247
+ export { createGlobalState } from './createGlobalState';
248
+ export { createSharedComposable } from './createSharedComposable';
249
+ export { tryOnMounted, tryOnBeforeMount, tryOnUnmounted, tryOnBeforeUnmount, tryOnScopeDispose } from './tryOnMounted';
250
+ // Array utilities
251
+ export {
252
+ useArrayDifference,
253
+ useArrayEvery,
254
+ useArrayFilter,
255
+ useArrayFind,
256
+ useArrayFindIndex,
257
+ useArrayIncludes,
258
+ useArrayMap,
259
+ useArrayReduce,
260
+ useArraySome,
261
+ useArrayUnique,
262
+ } from './useArrayUtils';
263
+ // Aliases (matching VueUse naming)
264
+ export { computedAsync as asyncComputed } from './computedAsync';
265
+ export { computedEager as eagerComputed } from './computedEager';
266
+ export { useDebouncedRef as debouncedRef } from './useDebouncedRef';
267
+ export { useDebouncedRef as refDebounced } from './useDebouncedRef';
268
+ export { useThrottledRef as throttledRef } from './useThrottledRef';
269
+ export { useThrottledRef as refThrottled } from './useThrottledRef';
270
+ export { watchDebounced as debouncedWatch } from './watchDebounced';
271
+ export { watchThrottled as throttledWatch } from './watchThrottled';