@o/helpers 0.16.19 → 0.16.20

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 (256) hide show
  1. package/README.md +2 -0
  2. package/dist/array/getRandomItem.d.ts +2 -0
  3. package/dist/array/getRandomItem.d.ts.map +1 -0
  4. package/dist/array/getRandomItem.js +7 -0
  5. package/dist/array/getRandomItem.js.map +1 -0
  6. package/dist/array/takeLast.d.ts +2 -0
  7. package/dist/array/takeLast.d.ts.map +1 -0
  8. package/dist/array/takeLast.js +4 -0
  9. package/dist/array/takeLast.js.map +1 -0
  10. package/dist/array/uniqBy.d.ts +8 -0
  11. package/dist/array/uniqBy.d.ts.map +1 -0
  12. package/dist/array/uniqBy.js +17 -0
  13. package/dist/array/uniqBy.js.map +1 -0
  14. package/dist/async/asyncContext.d.ts +15 -0
  15. package/dist/async/asyncContext.d.ts.map +1 -0
  16. package/dist/async/asyncContext.js +115 -0
  17. package/dist/async/asyncContext.js.map +1 -0
  18. package/dist/async/asyncContext.native.d.ts +8 -0
  19. package/dist/async/asyncContext.native.d.ts.map +1 -0
  20. package/dist/async/asyncContext.native.js +63 -0
  21. package/dist/async/asyncContext.native.js.map +1 -0
  22. package/dist/async/idle.d.ts +7 -0
  23. package/dist/async/idle.d.ts.map +1 -0
  24. package/dist/async/idle.js +46 -0
  25. package/dist/async/idle.js.map +1 -0
  26. package/dist/async/interval.d.ts +2 -0
  27. package/dist/async/interval.d.ts.map +1 -0
  28. package/dist/async/interval.js +8 -0
  29. package/dist/async/interval.js.map +1 -0
  30. package/dist/async/isAborted.d.ts +2 -0
  31. package/dist/async/isAborted.d.ts.map +1 -0
  32. package/dist/async/isAborted.js +2 -0
  33. package/dist/async/isAborted.js.map +1 -0
  34. package/dist/async/useAsync.d.ts +2 -0
  35. package/dist/async/useAsync.d.ts.map +1 -0
  36. package/dist/async/useAsync.js +31 -0
  37. package/dist/async/useAsync.js.map +1 -0
  38. package/dist/async/useAsyncEffect.native.js +99 -0
  39. package/dist/async/useLazyMount.d.ts +8 -0
  40. package/dist/async/useLazyMount.d.ts.map +1 -0
  41. package/dist/async/useLazyMount.js +20 -0
  42. package/dist/async/useLazyMount.js.map +1 -0
  43. package/dist/async/useLazyMount.native.js +20 -0
  44. package/dist/async/useLazyValue.d.ts +5 -0
  45. package/dist/async/useLazyValue.d.ts.map +1 -0
  46. package/dist/async/useLazyValue.js +18 -0
  47. package/dist/async/useLazyValue.js.map +1 -0
  48. package/dist/async/useLazyValue.native.js +18 -0
  49. package/dist/browser/clearIndexedDB.d.ts +2 -0
  50. package/dist/browser/clearIndexedDB.d.ts.map +1 -0
  51. package/dist/browser/clearIndexedDB.js +17 -0
  52. package/dist/browser/clearIndexedDB.js.map +1 -0
  53. package/dist/client-only.d.ts +2 -0
  54. package/dist/client-only.d.ts.map +1 -0
  55. package/dist/client-only.js +5 -0
  56. package/dist/client-only.js.map +1 -0
  57. package/dist/clipboard/clipboard.d.ts +2 -0
  58. package/dist/clipboard/clipboard.d.ts.map +1 -0
  59. package/dist/clipboard/clipboard.js +10 -0
  60. package/dist/clipboard/clipboard.js.map +1 -0
  61. package/dist/clipboard/clipboard.native.d.ts +2 -0
  62. package/dist/clipboard/clipboard.native.d.ts.map +1 -0
  63. package/dist/clipboard/clipboard.native.js +11 -0
  64. package/dist/clipboard/clipboard.native.js.map +1 -0
  65. package/dist/color/extractOpacityFromColor.d.ts +2 -0
  66. package/dist/color/extractOpacityFromColor.d.ts.map +1 -0
  67. package/dist/color/extractOpacityFromColor.js +18 -0
  68. package/dist/color/extractOpacityFromColor.js.map +1 -0
  69. package/dist/color/generateColors.d.ts +10 -0
  70. package/dist/color/generateColors.d.ts.map +1 -0
  71. package/dist/color/generateColors.js +48 -0
  72. package/dist/color/generateColors.js.map +1 -0
  73. package/dist/color/lum.d.ts +2 -0
  74. package/dist/color/lum.d.ts.map +1 -0
  75. package/dist/color/lum.js +67 -0
  76. package/dist/color/lum.js.map +1 -0
  77. package/dist/color/toHex.d.ts +3 -0
  78. package/dist/color/toHex.d.ts.map +1 -0
  79. package/dist/color/toHex.js +10 -0
  80. package/dist/color/toHex.js.map +1 -0
  81. package/dist/constants.native.js +22 -0
  82. package/dist/debug/debugLog.d.ts +10 -0
  83. package/dist/debug/debugLog.d.ts.map +1 -0
  84. package/dist/debug/debugLog.js +14 -0
  85. package/dist/debug/debugLog.js.map +1 -0
  86. package/dist/debug/debugUseState.d.ts +2 -0
  87. package/dist/debug/debugUseState.d.ts.map +1 -0
  88. package/dist/debug/debugUseState.js +29 -0
  89. package/dist/debug/debugUseState.js.map +1 -0
  90. package/dist/emitter.d.ts.map +1 -1
  91. package/dist/emitter.js +18 -2
  92. package/dist/emitter.js.map +1 -1
  93. package/dist/emitter.native.js +289 -0
  94. package/dist/ensure/ensure.d.ts +5 -0
  95. package/dist/ensure/ensure.d.ts.map +1 -0
  96. package/dist/ensure/ensure.js +22 -0
  97. package/dist/ensure/ensure.js.map +1 -0
  98. package/dist/ensure/ensureOne.d.ts +2 -0
  99. package/dist/ensure/ensureOne.d.ts.map +1 -0
  100. package/dist/ensure/ensureOne.js +14 -0
  101. package/dist/ensure/ensureOne.js.map +1 -0
  102. package/dist/function/emptyFn.d.ts +2 -0
  103. package/dist/function/emptyFn.d.ts.map +1 -0
  104. package/dist/function/emptyFn.js +2 -0
  105. package/dist/function/emptyFn.js.map +1 -0
  106. package/dist/function/identityFn.d.ts +2 -0
  107. package/dist/function/identityFn.d.ts.map +1 -0
  108. package/dist/function/identityFn.js +2 -0
  109. package/dist/function/identityFn.js.map +1 -0
  110. package/dist/function/throttle.d.ts +22 -0
  111. package/dist/function/throttle.d.ts.map +1 -0
  112. package/dist/function/throttle.js +40 -0
  113. package/dist/function/throttle.js.map +1 -0
  114. package/dist/global/globalEffect.d.ts +2 -0
  115. package/dist/global/globalEffect.d.ts.map +1 -0
  116. package/dist/global/globalEffect.js +12 -0
  117. package/dist/global/globalEffect.js.map +1 -0
  118. package/dist/index.native.js +1 -1
  119. package/dist/number/formatNumber.d.ts +12 -0
  120. package/dist/number/formatNumber.d.ts.map +1 -0
  121. package/dist/number/formatNumber.js +39 -0
  122. package/dist/number/formatNumber.js.map +1 -0
  123. package/dist/object/decorateObject.d.ts +2 -0
  124. package/dist/object/decorateObject.d.ts.map +1 -0
  125. package/dist/object/decorateObject.js +15 -0
  126. package/dist/object/decorateObject.js.map +1 -0
  127. package/dist/object/isEqualDeep.d.ts +5 -0
  128. package/dist/object/isEqualDeep.d.ts.map +1 -0
  129. package/dist/object/isEqualDeep.js +5 -0
  130. package/dist/object/isEqualDeep.js.map +1 -0
  131. package/dist/object/isEqualJSON.d.ts +2 -0
  132. package/dist/object/isEqualJSON.d.ts.map +1 -0
  133. package/dist/object/isEqualJSON.js +2 -0
  134. package/dist/object/isEqualJSON.js.map +1 -0
  135. package/dist/object/mapObject.d.ts +4 -0
  136. package/dist/object/mapObject.d.ts.map +1 -0
  137. package/dist/object/mapObject.js +10 -0
  138. package/dist/object/mapObject.js.map +1 -0
  139. package/dist/object/object.d.ts +10 -0
  140. package/dist/object/object.d.ts.map +1 -0
  141. package/dist/object/object.js +13 -0
  142. package/dist/object/object.js.map +1 -0
  143. package/dist/object/objectUniqueKey.d.ts +2 -0
  144. package/dist/object/objectUniqueKey.d.ts.map +1 -0
  145. package/dist/object/objectUniqueKey.js +10 -0
  146. package/dist/object/objectUniqueKey.js.map +1 -0
  147. package/dist/server/ensureEnv.d.ts +2 -0
  148. package/dist/server/ensureEnv.d.ts.map +1 -0
  149. package/dist/server/ensureEnv.js +20 -0
  150. package/dist/server/ensureEnv.js.map +1 -0
  151. package/dist/server/getHeaders.d.ts +2 -0
  152. package/dist/server/getHeaders.d.ts.map +1 -0
  153. package/dist/server/getHeaders.js +8 -0
  154. package/dist/server/getHeaders.js.map +1 -0
  155. package/dist/server/prettyPrintRequest.d.ts +2 -0
  156. package/dist/server/prettyPrintRequest.d.ts.map +1 -0
  157. package/dist/server/prettyPrintRequest.js +14 -0
  158. package/dist/server/prettyPrintRequest.js.map +1 -0
  159. package/dist/server/prettyPrintResponse.d.ts +2 -0
  160. package/dist/server/prettyPrintResponse.d.ts.map +1 -0
  161. package/dist/server/prettyPrintResponse.js +13 -0
  162. package/dist/server/prettyPrintResponse.js.map +1 -0
  163. package/dist/server/streamToString.d.ts +2 -0
  164. package/dist/server/streamToString.d.ts.map +1 -0
  165. package/dist/server/streamToString.js +21 -0
  166. package/dist/server/streamToString.js.map +1 -0
  167. package/dist/server-only.d.ts +2 -0
  168. package/dist/server-only.d.ts.map +1 -0
  169. package/dist/server-only.js +5 -0
  170. package/dist/server-only.js.map +1 -0
  171. package/dist/shared.d.ts +59 -4
  172. package/dist/shared.d.ts.map +1 -1
  173. package/dist/shared.js +59 -3
  174. package/dist/shared.js.map +1 -1
  175. package/dist/shared.native.js +73 -0
  176. package/dist/string/dedent.d.ts +2 -0
  177. package/dist/string/dedent.d.ts.map +1 -0
  178. package/dist/string/dedent.js +24 -0
  179. package/dist/string/dedent.js.map +1 -0
  180. package/dist/string/ellipsis.d.ts +2 -0
  181. package/dist/string/ellipsis.d.ts.map +1 -0
  182. package/dist/string/ellipsis.js +10 -0
  183. package/dist/string/ellipsis.js.map +1 -0
  184. package/dist/string/hash.d.ts +3 -0
  185. package/dist/string/hash.d.ts.map +1 -0
  186. package/dist/string/hash.js +16 -0
  187. package/dist/string/hash.js.map +1 -0
  188. package/dist/string/insertAtIndex.d.ts +2 -0
  189. package/dist/string/insertAtIndex.d.ts.map +1 -0
  190. package/dist/string/insertAtIndex.js +7 -0
  191. package/dist/string/insertAtIndex.js.map +1 -0
  192. package/dist/string/nbspLastWord.d.ts +6 -0
  193. package/dist/string/nbspLastWord.d.ts.map +1 -0
  194. package/dist/string/nbspLastWord.js +13 -0
  195. package/dist/string/nbspLastWord.js.map +1 -0
  196. package/dist/string/pickLast.d.ts +2 -0
  197. package/dist/string/pickLast.d.ts.map +1 -0
  198. package/dist/string/pickLast.js +10 -0
  199. package/dist/string/pickLast.js.map +1 -0
  200. package/dist/string/pluralize.d.ts +4 -0
  201. package/dist/string/pluralize.d.ts.map +1 -0
  202. package/dist/string/pluralize.js +19 -0
  203. package/dist/string/pluralize.js.map +1 -0
  204. package/dist/string/pluralize.native.d.ts +3 -0
  205. package/dist/string/pluralize.native.d.ts.map +1 -0
  206. package/dist/string/pluralize.native.js +5 -0
  207. package/dist/string/pluralize.native.js.map +1 -0
  208. package/dist/string/truncateList.d.ts +16 -0
  209. package/dist/string/truncateList.d.ts.map +1 -0
  210. package/dist/string/truncateList.js +23 -0
  211. package/dist/string/truncateList.js.map +1 -0
  212. package/dist/time/formatDate.d.ts +4 -0
  213. package/dist/time/formatDate.d.ts.map +1 -0
  214. package/dist/time/formatDate.js +40 -0
  215. package/dist/time/formatDate.js.map +1 -0
  216. package/dist/time/formatDateRelative.d.ts +8 -0
  217. package/dist/time/formatDateRelative.d.ts.map +1 -0
  218. package/dist/time/formatDateRelative.js +55 -0
  219. package/dist/time/formatDateRelative.js.map +1 -0
  220. package/dist/time/formatDistanceToNow.d.ts +2 -0
  221. package/dist/time/formatDistanceToNow.d.ts.map +1 -0
  222. package/dist/time/formatDistanceToNow.js +21 -0
  223. package/dist/time/formatDistanceToNow.js.map +1 -0
  224. package/dist/time/useTimer.d.ts +10 -0
  225. package/dist/time/useTimer.d.ts.map +1 -0
  226. package/dist/time/useTimer.js +60 -0
  227. package/dist/time/useTimer.js.map +1 -0
  228. package/dist/types/NullToOptional.d.ts +6 -0
  229. package/dist/types/NullToOptional.d.ts.map +1 -0
  230. package/dist/types/NullToOptional.js +2 -0
  231. package/dist/types/NullToOptional.js.map +1 -0
  232. package/dist/types/object.d.ts +24 -0
  233. package/dist/types/object.d.ts.map +1 -0
  234. package/dist/types/object.js +3 -0
  235. package/dist/types/object.js.map +1 -0
  236. package/dist/types/react.d.ts +2 -0
  237. package/dist/types/react.d.ts.map +1 -0
  238. package/dist/types/react.js +2 -0
  239. package/dist/types/react.js.map +1 -0
  240. package/dist/types/timer.d.ts +2 -0
  241. package/dist/types/timer.d.ts.map +1 -0
  242. package/dist/types/timer.js +2 -0
  243. package/dist/types/timer.js.map +1 -0
  244. package/dist/types/tuple.d.ts +2 -0
  245. package/dist/types/tuple.d.ts.map +1 -0
  246. package/dist/types/tuple.js +2 -0
  247. package/dist/types/tuple.js.map +1 -0
  248. package/dist/url/urlSanitize.d.ts +2 -0
  249. package/dist/url/urlSanitize.d.ts.map +1 -0
  250. package/dist/url/urlSanitize.js +21 -0
  251. package/dist/url/urlSanitize.js.map +1 -0
  252. package/dist/url/urlValidate.d.ts +2 -0
  253. package/dist/url/urlValidate.d.ts.map +1 -0
  254. package/dist/url/urlValidate.js +8 -0
  255. package/dist/url/urlValidate.js.map +1 -0
  256. package/package.json +30 -4
package/README.md CHANGED
@@ -5,3 +5,5 @@ Shared browser, React, storage, string, and timing helpers for Orez consumers.
5
5
  ```ts
6
6
  import { createEmitter, createStorageValue, time } from '@o/helpers'
7
7
  ```
8
+
9
+ `getClipboardText` lives at `@o/helpers/clipboard`, apart from the main entry: its native variant imports the optional `expo-clipboard` peer, which only an app that ships Expo modules can load.
@@ -0,0 +1,2 @@
1
+ export declare const getRandomItem: <T>(items: T[]) => T | undefined;
2
+ //# sourceMappingURL=getRandomItem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRandomItem.d.ts","sourceRoot":"","sources":["../../src/array/getRandomItem.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,OAAO,CAAC,EAAE,KAAG,CAAC,GAAG,SAIjD,CAAA"}
@@ -0,0 +1,7 @@
1
+ export const getRandomItem = (items) => {
2
+ if (items.length === 0)
3
+ return;
4
+ const randomIndex = Math.floor(Math.random() * items.length);
5
+ return items[randomIndex];
6
+ };
7
+ //# sourceMappingURL=getRandomItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRandomItem.js","sourceRoot":"","sources":["../../src/array/getRandomItem.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,CAAI,KAAU,EAAiB,EAAE;IAC5D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAM;IAC9B,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAA;IAC5D,OAAO,KAAK,CAAC,WAAW,CAAC,CAAA;AAC3B,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const takeLast: <T>(arr: T[], n: number) => T[];
2
+ //# sourceMappingURL=takeLast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"takeLast.d.ts","sourceRoot":"","sources":["../../src/array/takeLast.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,GAAG,MAAM,KAAG,CAAC,EAElD,CAAA"}
@@ -0,0 +1,4 @@
1
+ export const takeLast = (arr, n) => {
2
+ return arr.slice(-n);
3
+ };
4
+ //# sourceMappingURL=takeLast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"takeLast.js","sourceRoot":"","sources":["../../src/array/takeLast.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAI,GAAQ,EAAE,CAAS,EAAO,EAAE;IACtD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACtB,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns a new array with duplicate elements removed based on a key selector function.
3
+ * @param array The input array to remove duplicates from
4
+ * @param keyFn Function that returns the key to compare elements by
5
+ * @returns A new array with duplicates removed
6
+ */
7
+ export declare function uniqBy<T, K>(array: T[], keyFn: (item: T) => K): T[];
8
+ //# sourceMappingURL=uniqBy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniqBy.d.ts","sourceRoot":"","sources":["../../src/array/uniqBy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAWnE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Returns a new array with duplicate elements removed based on a key selector function.
3
+ * @param array The input array to remove duplicates from
4
+ * @param keyFn Function that returns the key to compare elements by
5
+ * @returns A new array with duplicates removed
6
+ */
7
+ export function uniqBy(array, keyFn) {
8
+ const seen = new Map();
9
+ for (const item of array) {
10
+ const key = keyFn(item);
11
+ if (!seen.has(key)) {
12
+ seen.set(key, item);
13
+ }
14
+ }
15
+ return Array.from(seen.values());
16
+ }
17
+ //# sourceMappingURL=uniqBy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uniqBy.js","sourceRoot":"","sources":["../../src/array/uniqBy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,UAAU,MAAM,CAAO,KAAU,EAAE,KAAqB;IAC5D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAQ,CAAA;IAE5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAA;QACvB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACnB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AAClC,CAAC"}
@@ -0,0 +1,15 @@
1
+ interface AsyncContext<T> {
2
+ get(): T | undefined;
3
+ run<R>(value: T, fn: () => R | Promise<R>): Promise<R>;
4
+ }
5
+ interface NodeAsyncLocalStorage<T> {
6
+ getStore(): T | undefined;
7
+ run<R>(store: T, callback: () => R): R;
8
+ }
9
+ interface AsyncLocalStorageConstructor {
10
+ new <T>(): NodeAsyncLocalStorage<T>;
11
+ }
12
+ export declare function setupAsyncLocalStorage(AsyncLocalStorage: AsyncLocalStorageConstructor | null): void;
13
+ export declare function createAsyncContext<T>(): AsyncContext<T>;
14
+ export {};
15
+ //# sourceMappingURL=asyncContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContext.d.ts","sourceRoot":"","sources":["../../src/async/asyncContext.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY,CAAC,CAAC;IACtB,GAAG,IAAI,CAAC,GAAG,SAAS,CAAA;IACpB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACvD;AAED,UAAU,qBAAqB,CAAC,CAAC;IAC/B,QAAQ,IAAI,CAAC,GAAG,SAAS,CAAA;IACzB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,CAAA;CACvC;AAED,UAAU,4BAA4B;IACpC,KAAK,CAAC,KAAK,qBAAqB,CAAC,CAAC,CAAC,CAAA;CACpC;AAQD,wBAAgB,sBAAsB,CACpC,iBAAiB,EAAE,4BAA4B,GAAG,IAAI,GACrD,IAAI,CAEN;AAeD,wBAAgB,kBAAkB,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAkCvD"}
@@ -0,0 +1,115 @@
1
+ import { IS_SERVER_RUNTIME } from '../platform.js';
2
+ let nodeAsyncLocalStorageCache = null;
3
+ let configuredAsyncLocalStorage = null;
4
+ // hide from vite/esbuild static analysis to avoid browser compat warning
5
+ const nodeModuleId = ['node', 'async_hooks'].join(':');
6
+ export function setupAsyncLocalStorage(AsyncLocalStorage) {
7
+ configuredAsyncLocalStorage = AsyncLocalStorage;
8
+ }
9
+ async function getNodeAsyncLocalStorage() {
10
+ if (!nodeAsyncLocalStorageCache) {
11
+ try {
12
+ const module = await import(/* @vite-ignore */ nodeModuleId);
13
+ nodeAsyncLocalStorageCache =
14
+ module.AsyncLocalStorage;
15
+ }
16
+ catch {
17
+ return null;
18
+ }
19
+ }
20
+ return nodeAsyncLocalStorageCache;
21
+ }
22
+ export function createAsyncContext() {
23
+ if (IS_SERVER_RUNTIME) {
24
+ let storage = null;
25
+ const storageReady = Promise.resolve(configuredAsyncLocalStorage)
26
+ .then((AsyncLocalStorage) => AsyncLocalStorage || getNodeAsyncLocalStorage())
27
+ .then((AsyncLocalStorage) => {
28
+ if (AsyncLocalStorage && !storage) {
29
+ storage = new AsyncLocalStorage();
30
+ }
31
+ });
32
+ return {
33
+ get() {
34
+ if (!storage) {
35
+ throw new Error(`AsyncContext storage not initialized`);
36
+ }
37
+ return storage.getStore();
38
+ },
39
+ async run(value, fn) {
40
+ if (!storage) {
41
+ await storageReady;
42
+ }
43
+ if (!storage) {
44
+ throw new Error(`AsyncContext storage unavailable in server runtime`);
45
+ }
46
+ return storage.run(value, fn);
47
+ },
48
+ };
49
+ }
50
+ else {
51
+ // browser implementation using promise patching
52
+ return createBrowserAsyncContext();
53
+ }
54
+ }
55
+ function createBrowserAsyncContext() {
56
+ let currentContext;
57
+ const contextStack = [];
58
+ return {
59
+ get() {
60
+ return currentContext;
61
+ },
62
+ async run(value, fn) {
63
+ const prevContext = currentContext;
64
+ currentContext = value;
65
+ contextStack.push(prevContext);
66
+ // store original Promise methods
67
+ const OriginalPromise = Promise;
68
+ const OriginalThen = OriginalPromise.prototype.then;
69
+ const OriginalCatch = OriginalPromise.prototype.catch;
70
+ const OriginalFinally = OriginalPromise.prototype.finally;
71
+ function wrapCallback(callback, context) {
72
+ if (!callback)
73
+ return callback;
74
+ return (...args) => {
75
+ const prevContext = currentContext;
76
+ currentContext = context;
77
+ try {
78
+ return callback(...args);
79
+ }
80
+ finally {
81
+ currentContext = prevContext;
82
+ }
83
+ };
84
+ }
85
+ // patch Promise methods to capture and restore context
86
+ // eslint-disable-next-line no-then-property -- intentional patching for context propagation
87
+ OriginalPromise.prototype.then = function (onFulfilled, onRejected) {
88
+ const context = currentContext;
89
+ return OriginalThen.call(this, wrapCallback(onFulfilled, context), wrapCallback(onRejected, context));
90
+ };
91
+ OriginalPromise.prototype.catch = function (onRejected) {
92
+ const context = currentContext;
93
+ return OriginalCatch.call(this, wrapCallback(onRejected, context));
94
+ };
95
+ OriginalPromise.prototype.finally = function (onFinally) {
96
+ const context = currentContext;
97
+ return OriginalFinally.call(this, wrapCallback(onFinally, context));
98
+ };
99
+ try {
100
+ const result = await fn();
101
+ return result;
102
+ }
103
+ finally {
104
+ // restore original Promise methods
105
+ // eslint-disable-next-line no-then-property -- restoring original methods
106
+ OriginalPromise.prototype.then = OriginalThen;
107
+ OriginalPromise.prototype.catch = OriginalCatch;
108
+ OriginalPromise.prototype.finally = OriginalFinally;
109
+ contextStack.pop();
110
+ currentContext = prevContext;
111
+ }
112
+ },
113
+ };
114
+ }
115
+ //# sourceMappingURL=asyncContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContext.js","sourceRoot":"","sources":["../../src/async/asyncContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAgBlD,IAAI,0BAA0B,GAAwC,IAAI,CAAA;AAC1E,IAAI,2BAA2B,GAAwC,IAAI,CAAA;AAE3E,yEAAyE;AACzE,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAEtD,MAAM,UAAU,sBAAsB,CACpC,iBAAsD;IAEtD,2BAA2B,GAAG,iBAAiB,CAAA;AACjD,CAAC;AAED,KAAK,UAAU,wBAAwB;IACrC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,MAA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AK,GAAG,UAEhC,UAAgB;gBAEhB,MAAM,OAAO,GAAG,cAAc,CAAA;gBAC9B,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,UAAU,EAAE,OAAO,CAAQ,CAAC,CAAA;YAC3E,CAAC,CAAA;YAED,eAAe,CAAC,SAAS,CAAC,OAAO,GAAG,UAElC,SAAe;gBAEf,MAAM,OAAO,GAAG,cAAc,CAAA;gBAC9B,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS,EAAE,OAAO,CAAQ,CAAC,CAAA;YAC5E,CAAC,CAAA;YAED,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAA;gBACzB,OAAO,MAAM,CAAA;YACf,CAAC;oBAAS,CAAC;gBACT,mCAAmC;gBACnC,0EAA0E;gBAC1E,eAAe,CAAC,SAAS,CAAC,IAAI,GAAG,YAAY,CAAA;gBAC7C,eAAe,CAAC,SAAS,CAAC,KAAK,GAAG,aAAa,CAAA;gBAC/C,eAAe,CAAC,SAAS,CAAC,OAAO,GAAG,eAAe,CAAA;gBAEnD,YAAY,CAAC,GAAG,EAAE,CAAA;gBAClB,cAAc,GAAG,WAAW,CAAA;YAC9B,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ interface AsyncContext<T> {
2
+ get(): T | undefined;
3
+ run<R>(value: T, fn: () => R | Promise<R>): Promise<R>;
4
+ }
5
+ export declare function setupAsyncLocalStorage(_AsyncLocalStorage: unknown): void;
6
+ export declare function createAsyncContext<T>(): AsyncContext<T>;
7
+ export {};
8
+ //# sourceMappingURL=asyncContext.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContext.native.d.ts","sourceRoot":"","sources":["../../src/async/asyncContext.native.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY,CAAC,CAAC;IACtB,GAAG,IAAI,CAAC,GAAG,SAAS,CAAA;IACpB,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAA;CACvD;AAED,wBAAgB,sBAAsB,CAAC,kBAAkB,EAAE,OAAO,GAAG,IAAI,CAAG;AAG5E,wBAAgB,kBAAkB,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAiFvD"}
@@ -0,0 +1,63 @@
1
+ export function setupAsyncLocalStorage(_AsyncLocalStorage) { }
2
+ // react native implementation - no node:async_hooks available
3
+ export function createAsyncContext() {
4
+ let currentContext;
5
+ const contextStack = [];
6
+ return {
7
+ get() {
8
+ return currentContext;
9
+ },
10
+ async run(value, fn) {
11
+ const prevContext = currentContext;
12
+ currentContext = value;
13
+ contextStack.push(prevContext);
14
+ // store original Promise methods
15
+ const OriginalPromise = Promise;
16
+ const OriginalThen = OriginalPromise.prototype.then;
17
+ const OriginalCatch = OriginalPromise.prototype.catch;
18
+ const OriginalFinally = OriginalPromise.prototype.finally;
19
+ function wrapCallback(callback, context) {
20
+ if (!callback)
21
+ return callback;
22
+ return (...args) => {
23
+ const prevContext = currentContext;
24
+ currentContext = context;
25
+ try {
26
+ return callback(...args);
27
+ }
28
+ finally {
29
+ currentContext = prevContext;
30
+ }
31
+ };
32
+ }
33
+ // patch Promise methods to capture and restore context
34
+ // eslint-disable-next-line no-then-property -- intentional patching for context propagation
35
+ OriginalPromise.prototype.then = function (onFulfilled, onRejected) {
36
+ const context = currentContext;
37
+ return OriginalThen.call(this, wrapCallback(onFulfilled, context), wrapCallback(onRejected, context));
38
+ };
39
+ OriginalPromise.prototype.catch = function (onRejected) {
40
+ const context = currentContext;
41
+ return OriginalCatch.call(this, wrapCallback(onRejected, context));
42
+ };
43
+ OriginalPromise.prototype.finally = function (onFinally) {
44
+ const context = currentContext;
45
+ return OriginalFinally.call(this, wrapCallback(onFinally, context));
46
+ };
47
+ try {
48
+ const result = await fn();
49
+ return result;
50
+ }
51
+ finally {
52
+ // restore original Promise methods
53
+ // eslint-disable-next-line no-then-property -- restoring original methods
54
+ OriginalPromise.prototype.then = OriginalThen;
55
+ OriginalPromise.prototype.catch = OriginalCatch;
56
+ OriginalPromise.prototype.finally = OriginalFinally;
57
+ contextStack.pop();
58
+ currentContext = prevContext;
59
+ }
60
+ },
61
+ };
62
+ }
63
+ //# sourceMappingURL=asyncContext.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asyncContext.native.js","sourceRoot":"","sources":["../../src/async/asyncContext.native.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,sBAAsB,CAAC,kBAA2B,IAAS,CAAC;AAE5E,8DAA8D;AAC9D,MAAM,UAAU,kBAAkB;IAChC,IAAI,cAA6B,CAAA;IACjC,MAAM,YAAY,GAAsB,EAAE,CAAA;IAE1C,OAAO;QACL,GAAG;YACD,OAAO,cAAc,CAAA;QACvB,CAAC;QACD,KAAK,CAAC,GAAG,CAAI,KAAQ,EAAE,EAAwB;YAC7C,MAAM,WAAW,GAAG,cAAc,CAAA;YAClC,cAAc,GAAG,KAAK,CAAA;YACtB,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YAE9B,iCAAiC;YACjC,MAAM,eAAe,GAAG,OAAO,CAAA;YAC/B,MAAM,YAAY,GAAG,eAAe,CAAC,SAAS,CAAC,IAAI,CAAA;YACnD,MAAM,aAAa,GAAG,eAAe,CAAC,SAAS,CAAC,KAAK,CAAA;YACrD,MAAM,eAAe,GAAG,eAAe,CAAC,SAAS,CAAC,OAAO,CAAA;YAEzD,SAAS,YAAY,CACnB,QAAqC,EACrC,OAAsB;gBAEtB,IAAI,CAAC,QAAQ;oBAAE,OAAO,QAAQ,CAAA;gBAC9B,OAAO,CAAC,GAAG,IAAW,EAAE,EAAE;oBACxB,MAAM,WAAW,GAAG,cAAc,CAAA;oBAClC,cAAc,GAAG,OAAO,CAAA;oBACxB,IAAI,CAAC;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Ac,GAAG,WAAW,CAAA;YAC9B,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type IdleOptions = {
2
+ max?: number;
3
+ min?: number;
4
+ fully?: boolean;
5
+ };
6
+ export declare const idle: (options?: IdleOptions, signal?: AbortSignal) => Promise<void>;
7
+ //# sourceMappingURL=idle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle.d.ts","sourceRoot":"","sources":["../../src/async/idle.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,IAAI,GACf,UAAU,WAAW,EACrB,SAAS,WAAW,KACnB,OAAO,CAAC,IAAI,CAkBd,CAAA"}
@@ -0,0 +1,46 @@
1
+ import { AbortError } from '../error/errors.js';
2
+ import { sleep } from './sleep.js';
3
+ const idleCb = typeof requestIdleCallback === 'undefined'
4
+ ? (cb) => setTimeout(cb, 1)
5
+ : requestIdleCallback;
6
+ const idleAsync = () => {
7
+ return new Promise((res) => {
8
+ idleCb(res);
9
+ });
10
+ };
11
+ export const idle = async (options, signal) => {
12
+ const { max, min, fully } = options || {};
13
+ const idleFn = fully ? fullyIdle : idleAsync;
14
+ if (max && min && min < max) {
15
+ await Promise.race([Promise.all([idleFn(), sleep(min)]), sleep(max)]);
16
+ }
17
+ else if (max) {
18
+ await Promise.race([idleFn(), sleep(max)]);
19
+ }
20
+ else if (min) {
21
+ await Promise.all([idleFn(), sleep(min)]);
22
+ }
23
+ else {
24
+ await idleFn();
25
+ }
26
+ if (signal?.aborted) {
27
+ throw new AbortError();
28
+ }
29
+ };
30
+ const fullyIdle = async (signal) => {
31
+ while (true) {
32
+ const startTime = Date.now();
33
+ await idle({}, signal);
34
+ const endTime = Date.now();
35
+ const duration = endTime - startTime;
36
+ // If idle callback took less than 15ms, consider it truly idle
37
+ if (duration < 15) {
38
+ break;
39
+ }
40
+ // Check for abort signal after each iteration
41
+ if (signal?.aborted) {
42
+ throw new AbortError();
43
+ }
44
+ }
45
+ };
46
+ //# sourceMappingURL=idle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle.js","sourceRoot":"","sources":["../../src/async/idle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AASlC,MAAM,MAAM,GACV,OAAO,mBAAmB,KAAK,WAAW;IACxC,CAAC,CAAC,CAAC,EAAc,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;IACvC,CAAC,CAAC,mBAAmB,CAAA;AAEzB,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACzB,MAAM,CAAC,GAAG,CAAC,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAQD,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,OAAqB,EACrB,MAAoB,EACL,EAAE;IACjB,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,OAAO,IAAI,EAAE,CAAA;IAEzC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAA;IAE5C,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,GAAG,EAAE,CAAC;QAC5B,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IACvE,CAAC;SAAM,IAAI,GAAG,EAAE,CAAC;QACf,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC5C,CAAC;SAAM,IAAI,GAAG,EAAE,CAAC;QACf,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,EAAE,CAAA;IAChB,CAAC;IAED,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,EAAE,CAAA;IACxB,CAAC;AACH,CAAC,CAAA;AAED,MAAM,SAAS,GAAG,KAAK,EAAE,MAAoB,EAAiB,EAAE;IAC9D,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC5B,MAAM,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAC1B,MAAM,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAA;QAEpC,+DAA+D;QAC/D,IAAI,QAAQ,GAAG,EAAE,EAAE,CAAC;YAClB,MAAK;QACP,CAAC;QAED,8CAA8C;QAC9C,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,UAAU,EAAE,CAAA;QACxB,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const interval: (callback: () => void, ms: number, signal?: AbortSignal) => Promise<never>;
2
+ //# sourceMappingURL=interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.ts","sourceRoot":"","sources":["../../src/async/interval.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,GACnB,UAAU,MAAM,IAAI,EACpB,IAAI,MAAM,EACV,SAAS,WAAW,KACnB,OAAO,CAAC,KAAK,CAKf,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { sleep } from './sleep.js';
2
+ export const interval = async (callback, ms, signal) => {
3
+ while (true) {
4
+ callback();
5
+ await sleep(ms, signal);
6
+ }
7
+ };
8
+ //# sourceMappingURL=interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.js","sourceRoot":"","sources":["../../src/async/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAElC,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,QAAoB,EACpB,EAAU,EACV,MAAoB,EACJ,EAAE;IAClB,OAAO,IAAI,EAAE,CAAC;QACZ,QAAQ,EAAE,CAAA;QACV,MAAM,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IACzB,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const isAborted: (controller?: AbortController) => boolean;
2
+ //# sourceMappingURL=isAborted.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isAborted.d.ts","sourceRoot":"","sources":["../../src/async/isAborted.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,GAAI,aAAa,eAAe,KAAG,OAC3B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const isAborted = (controller) => !!controller?.signal.aborted;
2
+ //# sourceMappingURL=isAborted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isAborted.js","sourceRoot":"","sources":["../../src/async/isAborted.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,UAA4B,EAAW,EAAE,CACjE,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function useAsync<T>(promiseFn: () => Promise<T>, args: any[]): [T, 'loading' | 'idle' | 'error', Error | null];
2
+ //# sourceMappingURL=useAsync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsync.d.ts","sourceRoot":"","sources":["../../src/async/useAsync.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,EACxB,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,IAAI,EAAE,GAAG,EAAE,GACV,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,CAgCjD"}
@@ -0,0 +1,31 @@
1
+ import { useState, useEffect } from 'react';
2
+ export function useAsync(promiseFn, args) {
3
+ const [data, setData] = useState(null);
4
+ const [error, setError] = useState(null);
5
+ const [loading, setLoading] = useState(true);
6
+ useEffect(() => {
7
+ let isMounted = true;
8
+ const fetchData = async () => {
9
+ try {
10
+ const result = await promiseFn();
11
+ if (isMounted) {
12
+ setData(result);
13
+ setLoading(false);
14
+ }
15
+ }
16
+ catch (err) {
17
+ if (isMounted) {
18
+ setError(err);
19
+ setLoading(false);
20
+ }
21
+ }
22
+ };
23
+ fetchData();
24
+ return () => {
25
+ isMounted = false;
26
+ };
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, args);
29
+ return [data, error ? 'error' : loading ? 'loading' : 'idle', error];
30
+ }
31
+ //# sourceMappingURL=useAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsync.js","sourceRoot":"","sources":["../../src/async/useAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAE3C,MAAM,UAAU,QAAQ,CACtB,SAA2B,EAC3B,IAAW;IAEX,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAW,IAAI,CAAC,CAAA;IAChD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IACtD,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAU,IAAI,CAAC,CAAA;IAErD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,GAAG,IAAI,CAAA;QAEpB,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAA;gBAChC,IAAI,SAAS,EAAE,CAAC;oBACd,OAAO,CAAC,MAAM,CAAC,CAAA;oBACf,UAAU,CAAC,KAAK,CAAC,CAAA;gBACnB,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,SAAS,EAAE,CAAC;oBACd,QAAQ,CAAC,GAAY,CAAC,CAAA;oBACtB,UAAU,CAAC,KAAK,CAAC,CAAA;gBACnB,CAAC;YACH,CAAC;QACH,CAAC,CAAA;QAED,SAAS,EAAE,CAAA;QAEX,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,KAAK,CAAA;QACnB,CAAC,CAAA;QACD,uDAAuD;IACzD,CAAC,EAAE,IAAI,CAAC,CAAA;IAER,OAAO,CAAC,IAAS,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAC3E,CAAC"}
@@ -0,0 +1,99 @@
1
+ // adopted from https://github.com/franciscop/use-async/blob/master/src/index.js
2
+ import { useEffect, useId, useLayoutEffect } from 'react';
3
+ import { EMPTY_OBJECT } from '../constants.native.js';
4
+ import { getCurrentComponentStack } from '../react/getCurrentComponentStack.js';
5
+ import { handleAbortError } from './abortable.js';
6
+ export function useAsyncEffect(cb, deps = [], options) {
7
+ useAsyncEffectImpl(false, cb, deps, options);
8
+ }
9
+ export function useAsyncLayoutEffect(cb, deps = [], options) {
10
+ useAsyncEffectImpl(true, cb, deps, options);
11
+ }
12
+ function useAsyncEffectImpl(isLayoutEffect, cb, deps = [], options = EMPTY_OBJECT) {
13
+ const effectHook = isLayoutEffect ? useLayoutEffect : useEffect;
14
+ // eslint-disable-next-line react-hooks/rules-of-hooks
15
+ const effectId = process.env.NODE_ENV === 'development' ? useId() : '';
16
+ effectHook(() => {
17
+ // Generate a unique ID for this effect instance for loop detection
18
+ checkEffectLoop(effectId, cb, deps, options.circuitBreakAfter, options.circuitBreakPeriod);
19
+ const controller = new AbortController();
20
+ const signal = controller.signal;
21
+ // wrap in try in case its not async (for simple use cases)
22
+ try {
23
+ const value = cb(signal, ...deps);
24
+ Promise.resolve(value)
25
+ .then(async (res) => {
26
+ if (res && typeof res === 'function') {
27
+ if (signal.aborted)
28
+ return res();
29
+ signal.addEventListener('abort', res);
30
+ }
31
+ })
32
+ .catch(handleAbortError);
33
+ }
34
+ catch (error) {
35
+ handleAbortError(error, options.debug);
36
+ }
37
+ return () => {
38
+ if (signal.aborted)
39
+ return;
40
+ controller.abort();
41
+ };
42
+ }, deps);
43
+ }
44
+ // loop detection in dev mode
45
+ let effectRunCounts;
46
+ let checkEffectLoop;
47
+ function formatDeps(deps) {
48
+ try {
49
+ return JSON.stringify(deps, (_, v) => {
50
+ if (typeof v === 'function')
51
+ return `[Function: ${v.name || 'anonymous'}]`;
52
+ if (typeof v === 'symbol')
53
+ return v.toString();
54
+ if (v instanceof Error)
55
+ return `[Error: ${v.message}]`;
56
+ return v;
57
+ }, 2);
58
+ }
59
+ catch {
60
+ return `[${deps.length} deps - not serializable]`;
61
+ }
62
+ }
63
+ if (process.env.NODE_ENV === 'development') {
64
+ effectRunCounts = new Map();
65
+ checkEffectLoop = (effectId, cb, deps, circuitBreakAfter = 20, circuitBreakPeriod = 1000) => {
66
+ const now = Date.now();
67
+ const runs = effectRunCounts.get(effectId) || [];
68
+ runs.push(now);
69
+ // keep only runs from the specified period
70
+ const recentRuns = runs.filter((time) => now - time < circuitBreakPeriod);
71
+ effectRunCounts.set(effectId, recentRuns);
72
+ const runCount = recentRuns.length;
73
+ if (runCount > circuitBreakAfter) {
74
+ const message = `🚨 useAsyncEffect infinite loop detected! Effect ran ${runCount} times in <${circuitBreakPeriod}ms`;
75
+ if (process.env.NODE_ENV === 'development') {
76
+ console.error(message);
77
+ console.error('Effect function:', cb.toString().slice(0, 500));
78
+ console.error('Dependencies:', formatDeps(deps));
79
+ console.error('Stack:', getCurrentComponentStack());
80
+ // eslint-disable-next-line no-debugger
81
+ debugger;
82
+ }
83
+ else {
84
+ alert(message);
85
+ throw new Error(message);
86
+ }
87
+ }
88
+ else if (runCount > circuitBreakAfter / 2) {
89
+ console.warn(`⚠️ useAsyncEffect potential loop: Effect ran ${runCount} times in <${circuitBreakPeriod}ms`);
90
+ console.warn('Effect function:', cb.toString().slice(0, 500));
91
+ console.warn('Dependencies:', formatDeps(deps));
92
+ console.warn('Stack:', getCurrentComponentStack());
93
+ }
94
+ };
95
+ }
96
+ else {
97
+ checkEffectLoop = (_id, _cb, _deps, _after, _period) => { };
98
+ }
99
+ //# sourceMappingURL=useAsyncEffect.js.map
@@ -0,0 +1,8 @@
1
+ import { type IdleOptions } from './idle.js';
2
+ import type React from 'react';
3
+ export type LazyMountProps = IdleOptions;
4
+ export declare const useLazyMount: (props?: LazyMountProps) => boolean;
5
+ export declare const LazyMount: ({ children, ...idleProps }: LazyMountProps & {
6
+ children: any;
7
+ }) => React.ReactNode;
8
+ //# sourceMappingURL=useLazyMount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyMount.d.ts","sourceRoot":"","sources":["../../src/async/useLazyMount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAGlD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,MAAM,cAAc,GAAG,WAAW,CAAA;AAExC,eAAO,MAAM,YAAY,GAAI,QAAO,cAA6B,KAAG,OAgBnE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,4BAGvB,cAAc,GAAG;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,KAAG,KAAK,CAAC,SAG7C,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { startTransition, useState } from 'react';
2
+ import { idle } from './idle.js';
3
+ import { useAsyncEffect } from './useAsyncEffect.js';
4
+ export const useLazyMount = (props = { max: 100 }) => {
5
+ const [mounted, setMounted] = useState(false);
6
+ useAsyncEffect(async (signal) => {
7
+ await idle(props, signal);
8
+ startTransition(() => {
9
+ setMounted(true);
10
+ });
11
+ }, [
12
+ // no need for deps it only ever mounts once
13
+ ]);
14
+ return mounted;
15
+ };
16
+ export const LazyMount = ({ children, ...idleProps }) => {
17
+ const mounted = useLazyMount(idleProps);
18
+ return mounted ? children : null;
19
+ };
20
+ //# sourceMappingURL=useLazyMount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyMount.js","sourceRoot":"","sources":["../../src/async/useLazyMount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEjD,OAAO,EAAE,IAAI,EAAoB,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAMpD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAwB,EAAE,GAAG,EAAE,GAAG,EAAE,EAAW,EAAE;IAC5E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAE7C,cAAc,CACZ,KAAK,EAAE,MAAM,EAAE,EAAE;QACf,MAAM,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;QACzB,eAAe,CAAC,GAAG,EAAE;YACnB,UAAU,CAAC,IAAI,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;IACJ,CAAC,EACD;IACE,4CAA4C;KAC7C,CACF,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EACxB,QAAQ,EACR,GAAG,SAAS,EACuB,EAAmB,EAAE;IACxD,MAAM,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;IACvC,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAA;AAClC,CAAC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { startTransition, useState } from 'react';
2
+ import { idle } from './idle.js';
3
+ import { useAsyncEffect } from './useAsyncEffect.native.js';
4
+ export const useLazyMount = (props = { max: 100 }) => {
5
+ const [mounted, setMounted] = useState(false);
6
+ useAsyncEffect(async (signal) => {
7
+ await idle(props, signal);
8
+ startTransition(() => {
9
+ setMounted(true);
10
+ });
11
+ }, [
12
+ // no need for deps it only ever mounts once
13
+ ]);
14
+ return mounted;
15
+ };
16
+ export const LazyMount = ({ children, ...idleProps }) => {
17
+ const mounted = useLazyMount(idleProps);
18
+ return mounted ? children : null;
19
+ };
20
+ //# sourceMappingURL=useLazyMount.js.map
@@ -0,0 +1,5 @@
1
+ import { type IdleOptions } from './idle.js';
2
+ export declare const useLazyValue: <T>(value: T, { immediateFirstUpdate, ...idleOptions }?: IdleOptions & {
3
+ immediateFirstUpdate?: boolean;
4
+ }) => T;
5
+ //# sourceMappingURL=useLazyValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLazyValue.d.ts","sourceRoot":"","sources":["../../src/async/useLazyValue.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,KAAK,WAAW,EAAE,MAAM,WAAW,CAAA;AAGlD,eAAO,MAAM,YAAY,GAAI,CAAC,EAC5B,OAAO,CAAC,EACR,2CAGG,WAAW,GAAG;IAAE,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAAO,KACvD,CAmBF,CAAA"}