@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,9 @@
1
+ import { unref } from "./_shared";
2
+ export function unrefElement(elRef) {
3
+ const plain = unref(elRef);
4
+ if (!plain)
5
+ return plain;
6
+ if (plain.$el)
7
+ return plain.$el;
8
+ return plain;
9
+ }
@@ -0,0 +1,34 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Promise-based utility to wait for a ref to meet a condition.
4
+ *
5
+ * @param r - The reactive ref to watch
6
+ * @returns A chainable instance with condition methods
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const ready = ref(false)
11
+ * await until(ready).toBe(true)
12
+ * ```
13
+ */
14
+ export declare function until<T>(r: Ref<T>): UntilBaseInstance<T>;
15
+ export declare interface UntilToMatchOptions {
16
+ timeout?: number
17
+ throwOnTimeout?: boolean
18
+ }
19
+ export declare interface UntilBaseInstance<T> {
20
+ toMatch: (condition: (v: T) => boolean, options?: UntilToMatchOptions) => Promise<T>
21
+ toBe: (value: T, options?: UntilToMatchOptions) => Promise<T>
22
+ toBeTruthy: (options?: UntilToMatchOptions) => Promise<T>
23
+ toBeNull: (options?: UntilToMatchOptions) => Promise<T>
24
+ toBeUndefined: (options?: UntilToMatchOptions) => Promise<T>
25
+ toBeNaN: (options?: UntilToMatchOptions) => Promise<T>
26
+ changed: (options?: UntilToMatchOptions) => Promise<T>
27
+ not: {
28
+ toBe: (value: T, options?: UntilToMatchOptions) => Promise<T>
29
+ toBeTruthy: (options?: UntilToMatchOptions) => Promise<T>
30
+ toBeNull: (options?: UntilToMatchOptions) => Promise<T>
31
+ toBeUndefined: (options?: UntilToMatchOptions) => Promise<T>
32
+ toBeNaN: (options?: UntilToMatchOptions) => Promise<T>
33
+ }
34
+ }
package/dist/until.js ADDED
@@ -0,0 +1,62 @@
1
+ import { watch } from "@stacksjs/stx";
2
+ export function until(r) {
3
+ function toMatch(condition, options = {}) {
4
+ const { timeout, throwOnTimeout = !1 } = options;
5
+ if (condition(r.value))
6
+ return Promise.resolve(r.value);
7
+ return new Promise((resolve, reject) => {
8
+ let timer = null;
9
+ const unwatch = watch(r, (newVal) => {
10
+ if (condition(newVal)) {
11
+ unwatch();
12
+ if (timer !== null)
13
+ clearTimeout(timer);
14
+ resolve(newVal);
15
+ }
16
+ });
17
+ if (timeout !== void 0)
18
+ timer = setTimeout(() => {
19
+ unwatch();
20
+ if (throwOnTimeout)
21
+ reject(Error("Timeout"));
22
+ else
23
+ resolve(r.value);
24
+ }, timeout);
25
+ });
26
+ }
27
+ function toBe(value, options) {
28
+ return toMatch((v) => v === value, options);
29
+ }
30
+ function toBeTruthy(options) {
31
+ return toMatch((v) => Boolean(v), options);
32
+ }
33
+ function toBeNull(options) {
34
+ return toMatch((v) => v === null, options);
35
+ }
36
+ function toBeUndefined(options) {
37
+ return toMatch((v) => v === void 0, options);
38
+ }
39
+ function toBeNaN(options) {
40
+ return toMatch((v) => Number.isNaN(v), options);
41
+ }
42
+ function changed(options) {
43
+ const initial = r.value;
44
+ return toMatch((v) => v !== initial, options);
45
+ }
46
+ return {
47
+ toMatch,
48
+ toBe,
49
+ toBeTruthy,
50
+ toBeNull,
51
+ toBeUndefined,
52
+ toBeNaN,
53
+ changed,
54
+ not: {
55
+ toBe: (value, options) => toMatch((v) => v !== value, options),
56
+ toBeTruthy: (options) => toMatch((v) => !v, options),
57
+ toBeNull: (options) => toMatch((v) => v !== null, options),
58
+ toBeUndefined: (options) => toMatch((v) => v !== void 0, options),
59
+ toBeNaN: (options) => toMatch((v) => !Number.isNaN(v), options)
60
+ }
61
+ };
62
+ }
@@ -0,0 +1,6 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Reactive `document.activeElement`.
4
+ * Tracks which element currently has focus.
5
+ */
6
+ export declare function useActiveElement(): Ref<Element | null>;
@@ -0,0 +1,19 @@
1
+ import { onUnmounted, ref } from "@stacksjs/stx";
2
+ export function useActiveElement() {
3
+ const activeElement = ref(null);
4
+ if (typeof document > "u")
5
+ return activeElement;
6
+ activeElement.value = document.activeElement;
7
+ const handler = () => {
8
+ activeElement.value = document.activeElement;
9
+ };
10
+ document.addEventListener("focusin", handler, { passive: !0 });
11
+ document.addEventListener("focusout", handler, { passive: !0 });
12
+ try {
13
+ onUnmounted(() => {
14
+ document.removeEventListener("focusin", handler);
15
+ document.removeEventListener("focusout", handler);
16
+ });
17
+ } catch {}
18
+ return activeElement;
19
+ }
@@ -0,0 +1,18 @@
1
+ import type { MaybeRef } from './_shared';
2
+ import type { Ref } from '@stacksjs/stx';
3
+ /**
4
+ * Reactive Web Animations API.
5
+ */
6
+ export declare function useAnimate(target: MaybeRef<HTMLElement | null | undefined>, keyframes: Keyframe[] | PropertyIndexedKeyframes, options?: number | KeyframeAnimationOptions): UseAnimateReturn;
7
+ export declare interface UseAnimateReturn {
8
+ isSupported: Ref<boolean>
9
+ animate: Ref<Animation | undefined>
10
+ play: () => void
11
+ pause: () => void
12
+ reverse: () => void
13
+ finish: () => void
14
+ cancel: () => void
15
+ pending: Ref<boolean>
16
+ playState: Ref<AnimationPlayState>
17
+ currentTime: Ref<number | null>
18
+ }
@@ -0,0 +1,48 @@
1
+ import { onUnmounted, ref } from "@stacksjs/stx";
2
+ import { unref } from "./_shared";
3
+ export function useAnimate(target, keyframes, options) {
4
+ const isSupported = ref(typeof HTMLElement < "u" && "animate" in HTMLElement.prototype), animate = ref(void 0), pending = ref(!1), playState = ref("idle"), currentTime = ref(null);
5
+ function syncState() {
6
+ if (animate.value) {
7
+ pending.value = animate.value.pending;
8
+ playState.value = animate.value.playState;
9
+ currentTime.value = animate.value.currentTime;
10
+ }
11
+ }
12
+ function init() {
13
+ const el = unref(target);
14
+ if (!el || !isSupported.value)
15
+ return;
16
+ animate.value = el.animate(keyframes, options);
17
+ animate.value.addEventListener("finish", syncState);
18
+ animate.value.addEventListener("cancel", syncState);
19
+ syncState();
20
+ }
21
+ function play() {
22
+ animate.value?.play();
23
+ syncState();
24
+ }
25
+ function pause() {
26
+ animate.value?.pause();
27
+ syncState();
28
+ }
29
+ function reverse() {
30
+ animate.value?.reverse();
31
+ syncState();
32
+ }
33
+ function finish() {
34
+ animate.value?.finish();
35
+ syncState();
36
+ }
37
+ function cancel() {
38
+ animate.value?.cancel();
39
+ syncState();
40
+ }
41
+ init();
42
+ try {
43
+ onUnmounted(() => {
44
+ animate.value?.cancel();
45
+ });
46
+ } catch {}
47
+ return { isSupported, animate, play, pause, reverse, finish, cancel, pending, playState, currentTime };
48
+ }
@@ -0,0 +1,42 @@
1
+ import type { MaybeRef } from './_shared';
2
+ import type { Ref } from '@stacksjs/stx';
3
+ /**
4
+ * Reactive array difference: items in list but not in other.
5
+ */
6
+ export declare function useArrayDifference<T>(list: MaybeRef<T[]>, other: MaybeRef<T[]>, compareFn?: (a: T, b: T) => boolean): Ref<T[]>;
7
+ /**
8
+ * Reactive Array.every.
9
+ */
10
+ export declare function useArrayEvery<T>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => boolean): Ref<boolean>;
11
+ /**
12
+ * Reactive Array.filter.
13
+ */
14
+ export declare function useArrayFilter<T>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => boolean): Ref<T[]>;
15
+ /**
16
+ * Reactive Array.find.
17
+ */
18
+ export declare function useArrayFind<T>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => boolean): Ref<T | undefined>;
19
+ /**
20
+ * Reactive Array.findIndex.
21
+ */
22
+ export declare function useArrayFindIndex<T>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => boolean): Ref<number>;
23
+ /**
24
+ * Reactive Array.includes.
25
+ */
26
+ export declare function useArrayIncludes<T>(list: MaybeRef<T[]>, value: MaybeRef<T>, compareFn?: (a: T, b: T) => boolean): Ref<boolean>;
27
+ /**
28
+ * Reactive Array.map.
29
+ */
30
+ export declare function useArrayMap<T, U>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => U): Ref<U[]>;
31
+ /**
32
+ * Reactive Array.reduce.
33
+ */
34
+ export declare function useArrayReduce<T, U>(list: MaybeRef<T[]>, fn: (accumulator: U, current: T, index: number, array: T[]) => U, initialValue: U): Ref<U>;
35
+ /**
36
+ * Reactive Array.some.
37
+ */
38
+ export declare function useArraySome<T>(list: MaybeRef<T[]>, fn: (element: T, index: number, array: T[]) => boolean): Ref<boolean>;
39
+ /**
40
+ * Reactive unique array values.
41
+ */
42
+ export declare function useArrayUnique<T>(list: MaybeRef<T[]>, compareFn?: (a: T, b: T) => boolean): Ref<T[]>;
@@ -0,0 +1,114 @@
1
+ import { computed, ref, watch } from "@stacksjs/stx";
2
+ import { isRef, unref } from "./_shared";
3
+ function watchSource(source, cb) {
4
+ if (isRef(source))
5
+ watch(source, cb);
6
+ }
7
+ function getArray(source) {
8
+ return unref(source);
9
+ }
10
+ export function useArrayDifference(list, other, compareFn) {
11
+ const result = ref([]);
12
+ function update() {
13
+ const arr = getArray(list), otherArr = getArray(other);
14
+ if (compareFn)
15
+ result.value = arr.filter((item) => !otherArr.some((o) => compareFn(item, o)));
16
+ else
17
+ result.value = arr.filter((item) => !otherArr.includes(item));
18
+ }
19
+ update();
20
+ watchSource(list, update);
21
+ watchSource(other, update);
22
+ return result;
23
+ }
24
+ export function useArrayEvery(list, fn) {
25
+ const result = ref(!1);
26
+ function update() {
27
+ result.value = getArray(list).every(fn);
28
+ }
29
+ update();
30
+ watchSource(list, update);
31
+ return result;
32
+ }
33
+ export function useArrayFilter(list, fn) {
34
+ const result = ref([]);
35
+ function update() {
36
+ result.value = getArray(list).filter(fn);
37
+ }
38
+ update();
39
+ watchSource(list, update);
40
+ return result;
41
+ }
42
+ export function useArrayFind(list, fn) {
43
+ const result = ref(void 0);
44
+ function update() {
45
+ result.value = getArray(list).find(fn);
46
+ }
47
+ update();
48
+ watchSource(list, update);
49
+ return result;
50
+ }
51
+ export function useArrayFindIndex(list, fn) {
52
+ const result = ref(-1);
53
+ function update() {
54
+ result.value = getArray(list).findIndex(fn);
55
+ }
56
+ update();
57
+ watchSource(list, update);
58
+ return result;
59
+ }
60
+ export function useArrayIncludes(list, value, compareFn) {
61
+ const result = ref(!1);
62
+ function update() {
63
+ const arr = getArray(list), v = unref(value);
64
+ if (compareFn)
65
+ result.value = arr.some((item) => compareFn(item, v));
66
+ else
67
+ result.value = arr.includes(v);
68
+ }
69
+ update();
70
+ watchSource(list, update);
71
+ if (isRef(value))
72
+ watch(value, update);
73
+ return result;
74
+ }
75
+ export function useArrayMap(list, fn) {
76
+ const result = ref([]);
77
+ function update() {
78
+ result.value = getArray(list).map(fn);
79
+ }
80
+ update();
81
+ watchSource(list, update);
82
+ return result;
83
+ }
84
+ export function useArrayReduce(list, fn, initialValue) {
85
+ const result = ref(initialValue);
86
+ function update() {
87
+ result.value = getArray(list).reduce(fn, initialValue);
88
+ }
89
+ update();
90
+ watchSource(list, update);
91
+ return result;
92
+ }
93
+ export function useArraySome(list, fn) {
94
+ const result = ref(!1);
95
+ function update() {
96
+ result.value = getArray(list).some(fn);
97
+ }
98
+ update();
99
+ watchSource(list, update);
100
+ return result;
101
+ }
102
+ export function useArrayUnique(list, compareFn) {
103
+ const result = ref([]);
104
+ function update() {
105
+ const arr = getArray(list);
106
+ if (compareFn)
107
+ result.value = arr.filter((item, index) => arr.findIndex((other) => compareFn(item, other)) === index);
108
+ else
109
+ result.value = [...new Set(arr)];
110
+ }
111
+ update();
112
+ watchSource(list, update);
113
+ return result;
114
+ }
@@ -0,0 +1,18 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Sequential async task queue.
4
+ * Runs tasks one after another, tracking status and results.
5
+ *
6
+ * @param tasks - Array of async task functions to execute sequentially
7
+ */
8
+ export declare function useAsyncQueue<T>(tasks: UseAsyncQueueTask<T>[]): UseAsyncQueueReturn<T>;
9
+ export declare interface UseAsyncQueueResult<T> {
10
+ state: 'fulfilled' | 'rejected' | 'pending'
11
+ data?: T
12
+ }
13
+ export declare interface UseAsyncQueueReturn<T> {
14
+ activeIndex: Ref<number>
15
+ result: Ref<UseAsyncQueueResult<T>[]>
16
+ isFinished: Ref<boolean>
17
+ }
18
+ export type UseAsyncQueueTask<T> = () => Promise<T>;
@@ -0,0 +1,22 @@
1
+ import { ref } from "@stacksjs/stx";
2
+ export function useAsyncQueue(tasks) {
3
+ const activeIndex = ref(-1), isFinished = ref(!1), result = ref(tasks.map(() => ({ state: "pending" })));
4
+ async function runTasks() {
5
+ for (let i = 0;i < tasks.length; i++) {
6
+ activeIndex.value = i;
7
+ const task = tasks[i];
8
+ if (!task)
9
+ continue;
10
+ try {
11
+ const data = await task();
12
+ result.value = result.value.map((r, idx) => idx === i ? { state: "fulfilled", data } : r);
13
+ } catch (e) {
14
+ result.value = result.value.map((r, idx) => idx === i ? { state: "rejected", data: e } : r);
15
+ }
16
+ }
17
+ activeIndex.value = tasks.length;
18
+ isFinished.value = !0;
19
+ }
20
+ runTasks();
21
+ return { activeIndex, result, isFinished };
22
+ }
@@ -0,0 +1,23 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Reactive async state management.
4
+ * Wraps an async function or promise with reactive loading/error/ready state.
5
+ *
6
+ * @param promise - Async function or promise to execute
7
+ * @param initialState - Initial state value
8
+ * @param options - Execution options
9
+ */
10
+ export declare function useAsyncState<T>(promise: (() => Promise<T>) | Promise<T>, initialState: T, options?: UseAsyncStateOptions<T>): UseAsyncStateReturn<T>;
11
+ export declare interface UseAsyncStateOptions<T> {
12
+ immediate?: boolean
13
+ onError?: (e: unknown) => void
14
+ resetOnExecute?: boolean
15
+ delay?: number
16
+ }
17
+ export declare interface UseAsyncStateReturn<T> {
18
+ state: Ref<T>
19
+ isReady: Ref<boolean>
20
+ isLoading: Ref<boolean>
21
+ error: Ref<unknown>
22
+ execute: (delay?: number) => Promise<T>
23
+ }
@@ -0,0 +1,35 @@
1
+ import { ref } from "@stacksjs/stx";
2
+ export function useAsyncState(promise, initialState, options = {}) {
3
+ const {
4
+ immediate = !0,
5
+ onError,
6
+ resetOnExecute = !0,
7
+ delay = 0
8
+ } = options, state = ref(initialState), isReady = ref(!1), isLoading = ref(!1), error = ref(void 0);
9
+ async function execute(executeDelay) {
10
+ const delayMs = executeDelay ?? delay;
11
+ if (resetOnExecute)
12
+ state.value = initialState;
13
+ error.value = void 0;
14
+ isReady.value = !1;
15
+ isLoading.value = !0;
16
+ if (delayMs > 0)
17
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
18
+ try {
19
+ const result = typeof promise === "function" ? await promise() : await promise;
20
+ state.value = result;
21
+ isReady.value = !0;
22
+ return result;
23
+ } catch (e) {
24
+ error.value = e;
25
+ if (onError)
26
+ onError(e);
27
+ return state.value;
28
+ } finally {
29
+ isLoading.value = !1;
30
+ }
31
+ }
32
+ if (immediate)
33
+ execute();
34
+ return { state, isReady, isLoading, error, execute };
35
+ }
@@ -0,0 +1,12 @@
1
+ import type { MaybeRef } from './_shared';
2
+ import type { Ref } from '@stacksjs/stx';
3
+ /**
4
+ * Reactive Base64 encoding.
5
+ *
6
+ * @param source - The value to encode (string, Blob, ArrayBuffer, or canvas)
7
+ */
8
+ export declare function useBase64(source: MaybeRef<string | Blob | ArrayBuffer | HTMLCanvasElement>): UseBase64Return;
9
+ export declare interface UseBase64Return {
10
+ base64: Ref<string>
11
+ execute: () => Promise<string>
12
+ }
@@ -0,0 +1,45 @@
1
+ import { ref, watch } from "@stacksjs/stx";
2
+ import { isRef, unref } from "./_shared";
3
+ export function useBase64(source) {
4
+ const base64 = ref("");
5
+ async function encode(input) {
6
+ if (typeof input === "string") {
7
+ if (typeof btoa < "u")
8
+ return btoa(input);
9
+ return Buffer.from(input).toString("base64");
10
+ }
11
+ if (input instanceof ArrayBuffer) {
12
+ const bytes = new Uint8Array(input);
13
+ let binary = "";
14
+ for (const byte of bytes)
15
+ binary += String.fromCharCode(byte);
16
+ if (typeof btoa < "u")
17
+ return btoa(binary);
18
+ return Buffer.from(input).toString("base64");
19
+ }
20
+ if (typeof Blob < "u" && input instanceof Blob)
21
+ return new Promise((resolve, reject) => {
22
+ const reader = new FileReader;
23
+ reader.onload = () => {
24
+ const result = reader.result, base64Part = result.split(",")[1] ?? result;
25
+ resolve(base64Part);
26
+ };
27
+ reader.onerror = reject;
28
+ reader.readAsDataURL(input);
29
+ });
30
+ if (typeof HTMLCanvasElement < "u" && input instanceof HTMLCanvasElement)
31
+ return input.toDataURL().split(",")[1] ?? "";
32
+ return "";
33
+ }
34
+ async function execute() {
35
+ const val = unref(source), result = await encode(val);
36
+ base64.value = result;
37
+ return result;
38
+ }
39
+ execute().catch(() => {});
40
+ if (isRef(source))
41
+ watch(source, () => {
42
+ execute().catch(() => {});
43
+ });
44
+ return { base64, execute };
45
+ }
@@ -0,0 +1,15 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Reactive battery status.
4
+ * Tracks battery charging state, charge/discharge times, and level using the Battery Status API.
5
+ *
6
+ * @returns Reactive battery properties and support status
7
+ */
8
+ export declare function useBattery(): UseBatteryReturn;
9
+ export declare interface UseBatteryReturn {
10
+ charging: Ref<boolean>
11
+ chargingTime: Ref<number>
12
+ dischargingTime: Ref<number>
13
+ level: Ref<number>
14
+ isSupported: Ref<boolean>
15
+ }
@@ -0,0 +1,38 @@
1
+ import { onUnmounted, ref } from "@stacksjs/stx";
2
+ import { noop } from "./_shared";
3
+ export function useBattery() {
4
+ const nav = typeof navigator < "u" ? navigator : void 0, isSupported = ref(!!nav?.getBattery), charging = ref(!1), chargingTime = ref(0), dischargingTime = ref(0), level = ref(1), cleanups = [];
5
+ let cleanup = noop;
6
+ if (isSupported.value && nav?.getBattery)
7
+ nav.getBattery().then((battery) => {
8
+ const updateBatteryInfo = () => {
9
+ charging.value = battery.charging;
10
+ chargingTime.value = battery.chargingTime;
11
+ dischargingTime.value = battery.dischargingTime;
12
+ level.value = battery.level;
13
+ };
14
+ updateBatteryInfo();
15
+ battery.addEventListener("chargingchange", updateBatteryInfo);
16
+ battery.addEventListener("chargingtimechange", updateBatteryInfo);
17
+ battery.addEventListener("dischargingtimechange", updateBatteryInfo);
18
+ battery.addEventListener("levelchange", updateBatteryInfo);
19
+ cleanups.push(() => {
20
+ battery.removeEventListener("chargingchange", updateBatteryInfo);
21
+ battery.removeEventListener("chargingtimechange", updateBatteryInfo);
22
+ battery.removeEventListener("dischargingtimechange", updateBatteryInfo);
23
+ battery.removeEventListener("levelchange", updateBatteryInfo);
24
+ });
25
+ cleanup = () => {
26
+ for (const fn of cleanups)
27
+ fn();
28
+ cleanups.length = 0;
29
+ cleanup = noop;
30
+ };
31
+ }).catch(() => {
32
+ isSupported.value = !1;
33
+ });
34
+ try {
35
+ onUnmounted(() => cleanup());
36
+ } catch {}
37
+ return { charging, chargingTime, dischargingTime, level, isSupported };
38
+ }
@@ -0,0 +1,96 @@
1
+ import type { Ref } from '@stacksjs/stx';
2
+ /**
3
+ * Reactive responsive breakpoints.
4
+ * Observe viewport width changes and query breakpoint states.
5
+ */
6
+ export declare function useBreakpoints<K extends string>(breakpoints: Breakpoints<K>): UseBreakpointsReturn<K>;
7
+ /**
8
+ * Tailwind CSS default breakpoints.
9
+ */
10
+ export declare const breakpointsTailwind: {
11
+ sm: 640;
12
+ md: 768;
13
+ lg: 1024;
14
+ xl: 1280;
15
+ '2xl': 1536
16
+ };
17
+ /**
18
+ * Bootstrap default breakpoints.
19
+ */
20
+ export declare const breakpointsBootstrap: {
21
+ sm: 576;
22
+ md: 768;
23
+ lg: 992;
24
+ xl: 1200;
25
+ xxl: 1400
26
+ };
27
+ /** Alias for breakpointsBootstrap */
28
+ export declare const breakpointsBootstrapV5: unknown;
29
+ /**
30
+ * Ant Design breakpoints.
31
+ */
32
+ export declare const breakpointsAntDesign: {
33
+ xs: 480;
34
+ sm: 576;
35
+ md: 768;
36
+ lg: 992;
37
+ xl: 1200;
38
+ xxl: 1600
39
+ };
40
+ /**
41
+ * Vuetify breakpoints.
42
+ */
43
+ export declare const breakpointsVuetify: {
44
+ xs: 600;
45
+ sm: 960;
46
+ md: 1264;
47
+ lg: 1904
48
+ };
49
+ /**
50
+ * Quasar breakpoints.
51
+ */
52
+ export declare const breakpointsQuasar: {
53
+ xs: 600;
54
+ sm: 1024;
55
+ md: 1440;
56
+ lg: 1920
57
+ };
58
+ /**
59
+ * Master CSS breakpoints.
60
+ */
61
+ export declare const breakpointsMasterCss: {
62
+ '3xs': 360;
63
+ '2xs': 480;
64
+ 'xs': 600;
65
+ 'sm': 768;
66
+ 'md': 1024;
67
+ 'lg': 1280;
68
+ 'xl': 1440;
69
+ '2xl': 1600;
70
+ '3xl': 1920;
71
+ '4xl': 2560
72
+ };
73
+ /**
74
+ * Semantic UI breakpoints.
75
+ */
76
+ export declare const breakpointsSematic: {
77
+ mobileS: 320;
78
+ mobileM: 375;
79
+ mobileL: 425;
80
+ tablet: 768;
81
+ laptop: 1024;
82
+ laptopL: 1440;
83
+ desktop: 2560
84
+ };
85
+ export declare interface UseBreakpointsReturn<K extends string> {
86
+ greaterOrEqual: (k: K) => Ref<boolean>
87
+ smallerOrEqual: (k: K) => Ref<boolean>
88
+ between: (a: K, b: K) => Ref<boolean>
89
+ isGreater: (k: K) => Ref<boolean>
90
+ isSmaller: (k: K) => Ref<boolean>
91
+ current: () => Ref<K[]>
92
+ }
93
+ /**
94
+ * Breakpoints map type: key names to pixel widths.
95
+ */
96
+ export type Breakpoints<K extends string = string> = Record<K, number>;