@hanzogui/toast 8.3.1 → 8.3.2

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 (400) hide show
  1. package/dist/cjs/Toast.js +122 -0
  2. package/dist/cjs/Toast.js.map +1 -0
  3. package/dist/cjs/ToastAnnounce.js +55 -0
  4. package/dist/cjs/ToastAnnounce.js.map +1 -0
  5. package/dist/cjs/ToastComposable.js +849 -0
  6. package/dist/cjs/ToastComposable.js.map +1 -0
  7. package/dist/cjs/ToastImperative.js +90 -0
  8. package/dist/cjs/ToastImperative.js.map +1 -0
  9. package/dist/cjs/ToastImpl.js +307 -0
  10. package/dist/cjs/ToastImpl.js.map +1 -0
  11. package/dist/cjs/ToastItemFrame.js +121 -0
  12. package/dist/cjs/ToastItemFrame.js.map +1 -0
  13. package/dist/cjs/ToastPortal.js +16 -0
  14. package/dist/cjs/ToastPortal.js.map +1 -0
  15. package/dist/cjs/ToastProvider.js +72 -0
  16. package/dist/cjs/ToastProvider.js.map +1 -0
  17. package/dist/cjs/ToastState.js +284 -0
  18. package/dist/cjs/ToastState.js.map +1 -0
  19. package/dist/cjs/ToastViewport.js +289 -0
  20. package/dist/cjs/ToastViewport.js.map +1 -0
  21. package/dist/cjs/Toaster.js +13 -0
  22. package/dist/cjs/Toaster.js.map +1 -0
  23. package/dist/cjs/constants.js +6 -0
  24. package/dist/cjs/constants.js.map +1 -0
  25. package/dist/cjs/createNativeToast.js +42 -0
  26. package/dist/cjs/createNativeToast.js.map +1 -0
  27. package/dist/cjs/dispatchNativeToast.js +31 -0
  28. package/dist/cjs/dispatchNativeToast.js.map +1 -0
  29. package/dist/cjs/index.js +5 -0
  30. package/dist/cjs/index.js.map +1 -0
  31. package/dist/cjs/package.json +1 -0
  32. package/dist/cjs/types.js +3 -0
  33. package/dist/cjs/types.js.map +1 -0
  34. package/dist/cjs/useAnimatedDragGesture.js +251 -0
  35. package/dist/cjs/useAnimatedDragGesture.js.map +1 -0
  36. package/dist/cjs/useReducedMotion.js +52 -0
  37. package/dist/cjs/useReducedMotion.js.map +1 -0
  38. package/dist/cjs/useToastAnimations.js +252 -0
  39. package/dist/cjs/useToastAnimations.js.map +1 -0
  40. package/dist/cjs/v2.js +17 -0
  41. package/dist/cjs/v2.js.map +1 -0
  42. package/dist/esm/Toast.js +117 -0
  43. package/dist/esm/Toast.js.map +1 -0
  44. package/dist/esm/ToastAnnounce.js +50 -0
  45. package/dist/esm/ToastAnnounce.js.map +1 -0
  46. package/dist/esm/ToastComposable.js +843 -0
  47. package/dist/esm/ToastComposable.js.map +1 -0
  48. package/dist/esm/ToastImperative.js +82 -0
  49. package/dist/esm/ToastImperative.js.map +1 -0
  50. package/dist/esm/ToastImpl.js +301 -0
  51. package/dist/esm/ToastImpl.js.map +1 -0
  52. package/dist/esm/ToastItemFrame.js +117 -0
  53. package/dist/esm/ToastItemFrame.js.map +1 -0
  54. package/dist/esm/ToastPortal.js +13 -0
  55. package/dist/esm/ToastPortal.js.map +1 -0
  56. package/dist/esm/ToastProvider.js +64 -0
  57. package/dist/esm/ToastProvider.js.map +1 -0
  58. package/dist/esm/ToastState.js +281 -0
  59. package/dist/esm/ToastState.js.map +1 -0
  60. package/dist/esm/ToastViewport.js +282 -0
  61. package/dist/esm/ToastViewport.js.map +1 -0
  62. package/dist/esm/Toaster.js +9 -0
  63. package/dist/esm/Toaster.js.map +1 -0
  64. package/dist/esm/constants.js +3 -0
  65. package/dist/esm/constants.js.map +1 -0
  66. package/dist/esm/createNativeToast.js +36 -0
  67. package/dist/esm/createNativeToast.js.map +1 -0
  68. package/dist/esm/dispatchNativeToast.js +28 -0
  69. package/dist/esm/dispatchNativeToast.js.map +1 -0
  70. package/dist/esm/index.js +2 -2
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/esm/types.js +2 -0
  73. package/dist/esm/types.js.map +1 -0
  74. package/dist/esm/useAnimatedDragGesture.js +247 -0
  75. package/dist/esm/useAnimatedDragGesture.js.map +1 -0
  76. package/dist/esm/useReducedMotion.js +48 -0
  77. package/dist/esm/useReducedMotion.js.map +1 -0
  78. package/dist/esm/useToastAnimations.js +248 -0
  79. package/dist/esm/useToastAnimations.js.map +1 -0
  80. package/dist/esm/v2.js +8 -0
  81. package/dist/esm/v2.js.map +1 -0
  82. package/dist/native/Toast.js +117 -0
  83. package/dist/native/Toast.js.map +1 -0
  84. package/dist/native/ToastAnnounce.js +50 -0
  85. package/dist/native/ToastAnnounce.js.map +1 -0
  86. package/dist/native/ToastComposable.js +843 -0
  87. package/dist/native/ToastComposable.js.map +1 -0
  88. package/dist/native/ToastImperative.js +82 -0
  89. package/dist/native/ToastImperative.js.map +1 -0
  90. package/dist/native/ToastImpl.js +301 -0
  91. package/dist/native/ToastImpl.js.map +1 -0
  92. package/dist/native/ToastItemFrame.js +117 -0
  93. package/dist/native/ToastItemFrame.js.map +1 -0
  94. package/dist/native/ToastPortal.js +13 -0
  95. package/dist/native/ToastPortal.js.map +1 -0
  96. package/dist/native/ToastProvider.js +64 -0
  97. package/dist/native/ToastProvider.js.map +1 -0
  98. package/dist/native/ToastState.js +281 -0
  99. package/dist/native/ToastState.js.map +1 -0
  100. package/dist/native/ToastViewport.js +282 -0
  101. package/dist/native/ToastViewport.js.map +1 -0
  102. package/dist/native/Toaster.js +9 -0
  103. package/dist/native/Toaster.js.map +1 -0
  104. package/dist/native/constants.js +3 -0
  105. package/dist/native/constants.js.map +1 -0
  106. package/dist/native/createNativeToast.js +25 -0
  107. package/dist/native/createNativeToast.js.map +1 -0
  108. package/dist/native/dispatchNativeToast.js +28 -0
  109. package/dist/native/dispatchNativeToast.js.map +1 -0
  110. package/dist/native/index.js +2 -0
  111. package/dist/native/index.js.map +1 -0
  112. package/dist/native/types.js +2 -0
  113. package/dist/native/types.js.map +1 -0
  114. package/dist/native/useAnimatedDragGesture.js +210 -0
  115. package/dist/native/useAnimatedDragGesture.js.map +1 -0
  116. package/dist/native/useReducedMotion.js +48 -0
  117. package/dist/native/useReducedMotion.js.map +1 -0
  118. package/dist/native/useToastAnimations.js +248 -0
  119. package/dist/native/useToastAnimations.js.map +1 -0
  120. package/dist/native/v2.js +8 -0
  121. package/dist/native/v2.js.map +1 -0
  122. package/package.json +48 -44
  123. package/src/Toast.tsx +9 -9
  124. package/src/ToastAnnounce.tsx +2 -2
  125. package/src/ToastComposable.tsx +9 -9
  126. package/src/ToastImperative.tsx +2 -2
  127. package/src/ToastImpl.tsx +5 -5
  128. package/src/ToastPortal.tsx +4 -1
  129. package/src/ToastProvider.tsx +4 -4
  130. package/src/ToastState.ts +1 -1
  131. package/src/ToastViewport.tsx +4 -4
  132. package/src/Toaster.tsx +5 -5
  133. package/src/createNativeToast.native.tsx +1 -1
  134. package/src/createNativeToast.tsx +1 -1
  135. package/src/dispatchNativeToast.ts +3 -3
  136. package/src/index.ts +7 -3
  137. package/src/useAnimatedDragGesture.native.ts +1 -1
  138. package/src/useAnimatedDragGesture.ts +1 -1
  139. package/src/v2.ts +13 -9
  140. package/types/Toast.d.ts +19 -19
  141. package/types/Toast.d.ts.map +1 -1
  142. package/types/ToastAnnounce.d.ts +1 -1
  143. package/types/ToastAnnounce.d.ts.map +1 -1
  144. package/types/ToastComposable.d.ts +14 -14
  145. package/types/ToastComposable.d.ts.map +1 -1
  146. package/types/ToastImperative.d.ts +3 -3
  147. package/types/ToastImperative.d.ts.map +1 -1
  148. package/types/ToastImpl.d.ts +7 -7
  149. package/types/ToastImpl.d.ts.map +1 -1
  150. package/types/ToastItemFrame.d.ts +4 -4
  151. package/types/ToastItemFrame.d.ts.map +1 -1
  152. package/types/ToastPortal.d.ts +2 -2
  153. package/types/ToastPortal.d.ts.map +1 -1
  154. package/types/ToastProvider.d.ts +3 -3
  155. package/types/ToastProvider.d.ts.map +1 -1
  156. package/types/ToastState.d.ts +15 -12
  157. package/types/ToastState.d.ts.map +1 -1
  158. package/types/ToastViewport.d.ts +5 -5
  159. package/types/Toaster.d.ts +4 -4
  160. package/types/Toaster.d.ts.map +1 -1
  161. package/types/createNativeToast.d.ts +1 -1
  162. package/types/createNativeToast.d.ts.map +1 -1
  163. package/types/createNativeToast.native.d.ts +1 -1
  164. package/types/createNativeToast.native.d.ts.map +1 -1
  165. package/types/dispatchNativeToast.d.ts +2 -2
  166. package/types/dispatchNativeToast.d.ts.map +1 -1
  167. package/types/index.d.ts +3 -3
  168. package/types/index.d.ts.map +1 -1
  169. package/types/useAnimatedDragGesture.d.ts +1 -1
  170. package/types/useAnimatedDragGesture.d.ts.map +1 -1
  171. package/types/useAnimatedDragGesture.native.d.ts +1 -1
  172. package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
  173. package/types/v2.d.ts +9 -9
  174. package/types/v2.d.ts.map +1 -1
  175. package/dist/cjs/Toast.cjs +0 -178
  176. package/dist/cjs/Toast.native.js +0 -181
  177. package/dist/cjs/Toast.native.js.map +0 -1
  178. package/dist/cjs/ToastAnnounce.cjs +0 -103
  179. package/dist/cjs/ToastAnnounce.native.js +0 -111
  180. package/dist/cjs/ToastAnnounce.native.js.map +0 -1
  181. package/dist/cjs/ToastComposable.cjs +0 -947
  182. package/dist/cjs/ToastComposable.native.js +0 -1055
  183. package/dist/cjs/ToastComposable.native.js.map +0 -1
  184. package/dist/cjs/ToastImperative.cjs +0 -119
  185. package/dist/cjs/ToastImperative.native.js +0 -130
  186. package/dist/cjs/ToastImperative.native.js.map +0 -1
  187. package/dist/cjs/ToastImpl.cjs +0 -354
  188. package/dist/cjs/ToastImpl.native.js +0 -364
  189. package/dist/cjs/ToastImpl.native.js.map +0 -1
  190. package/dist/cjs/ToastItemFrame.cjs +0 -143
  191. package/dist/cjs/ToastItemFrame.native.js +0 -148
  192. package/dist/cjs/ToastItemFrame.native.js.map +0 -1
  193. package/dist/cjs/ToastPortal.cjs +0 -49
  194. package/dist/cjs/ToastPortal.native.js +0 -52
  195. package/dist/cjs/ToastPortal.native.js.map +0 -1
  196. package/dist/cjs/ToastProvider.cjs +0 -150
  197. package/dist/cjs/ToastProvider.native.js +0 -161
  198. package/dist/cjs/ToastProvider.native.js.map +0 -1
  199. package/dist/cjs/ToastState.cjs +0 -311
  200. package/dist/cjs/ToastState.native.js +0 -324
  201. package/dist/cjs/ToastState.native.js.map +0 -1
  202. package/dist/cjs/ToastViewport.cjs +0 -319
  203. package/dist/cjs/ToastViewport.native.js +0 -343
  204. package/dist/cjs/ToastViewport.native.js.map +0 -1
  205. package/dist/cjs/Toaster.cjs +0 -87
  206. package/dist/cjs/Toaster.native.js +0 -91
  207. package/dist/cjs/Toaster.native.js.map +0 -1
  208. package/dist/cjs/constants.cjs +0 -30
  209. package/dist/cjs/constants.native.js +0 -33
  210. package/dist/cjs/constants.native.js.map +0 -1
  211. package/dist/cjs/createNativeToast.cjs +0 -59
  212. package/dist/cjs/createNativeToast.native.js +0 -60
  213. package/dist/cjs/createNativeToast.native.js.map +0 -1
  214. package/dist/cjs/dispatchNativeToast.cjs +0 -47
  215. package/dist/cjs/dispatchNativeToast.native.js +0 -52
  216. package/dist/cjs/dispatchNativeToast.native.js.map +0 -1
  217. package/dist/cjs/index.cjs +0 -20
  218. package/dist/cjs/index.native.js +0 -23
  219. package/dist/cjs/index.native.js.map +0 -1
  220. package/dist/cjs/types.cjs +0 -18
  221. package/dist/cjs/types.native.js +0 -21
  222. package/dist/cjs/types.native.js.map +0 -1
  223. package/dist/cjs/useAnimatedDragGesture.cjs +0 -214
  224. package/dist/cjs/useAnimatedDragGesture.native.js +0 -224
  225. package/dist/cjs/useAnimatedDragGesture.native.js.map +0 -1
  226. package/dist/cjs/useReducedMotion.cjs +0 -74
  227. package/dist/cjs/useReducedMotion.native.js +0 -83
  228. package/dist/cjs/useReducedMotion.native.js.map +0 -1
  229. package/dist/cjs/useToastAnimations.cjs +0 -292
  230. package/dist/cjs/useToastAnimations.native.js +0 -302
  231. package/dist/cjs/useToastAnimations.native.js.map +0 -1
  232. package/dist/cjs/v2.cjs +0 -36
  233. package/dist/cjs/v2.native.js +0 -39
  234. package/dist/cjs/v2.native.js.map +0 -1
  235. package/dist/esm/Toast.mjs +0 -137
  236. package/dist/esm/Toast.mjs.map +0 -1
  237. package/dist/esm/Toast.native.js +0 -137
  238. package/dist/esm/Toast.native.js.map +0 -1
  239. package/dist/esm/ToastAnnounce.mjs +0 -66
  240. package/dist/esm/ToastAnnounce.mjs.map +0 -1
  241. package/dist/esm/ToastAnnounce.native.js +0 -71
  242. package/dist/esm/ToastAnnounce.native.js.map +0 -1
  243. package/dist/esm/ToastComposable.mjs +0 -909
  244. package/dist/esm/ToastComposable.mjs.map +0 -1
  245. package/dist/esm/ToastComposable.native.js +0 -1014
  246. package/dist/esm/ToastComposable.native.js.map +0 -1
  247. package/dist/esm/ToastImperative.mjs +0 -80
  248. package/dist/esm/ToastImperative.mjs.map +0 -1
  249. package/dist/esm/ToastImperative.native.js +0 -88
  250. package/dist/esm/ToastImperative.native.js.map +0 -1
  251. package/dist/esm/ToastImpl.mjs +0 -316
  252. package/dist/esm/ToastImpl.mjs.map +0 -1
  253. package/dist/esm/ToastImpl.native.js +0 -329
  254. package/dist/esm/ToastImpl.native.js.map +0 -1
  255. package/dist/esm/ToastItemFrame.mjs +0 -114
  256. package/dist/esm/ToastItemFrame.mjs.map +0 -1
  257. package/dist/esm/ToastItemFrame.native.js +0 -116
  258. package/dist/esm/ToastItemFrame.native.js.map +0 -1
  259. package/dist/esm/ToastPortal.mjs +0 -24
  260. package/dist/esm/ToastPortal.mjs.map +0 -1
  261. package/dist/esm/ToastPortal.native.js +0 -24
  262. package/dist/esm/ToastPortal.native.js.map +0 -1
  263. package/dist/esm/ToastProvider.mjs +0 -110
  264. package/dist/esm/ToastProvider.mjs.map +0 -1
  265. package/dist/esm/ToastProvider.native.js +0 -118
  266. package/dist/esm/ToastProvider.native.js.map +0 -1
  267. package/dist/esm/ToastState.mjs +0 -285
  268. package/dist/esm/ToastState.mjs.map +0 -1
  269. package/dist/esm/ToastState.native.js +0 -295
  270. package/dist/esm/ToastState.native.js.map +0 -1
  271. package/dist/esm/ToastViewport.mjs +0 -280
  272. package/dist/esm/ToastViewport.mjs.map +0 -1
  273. package/dist/esm/ToastViewport.native.js +0 -301
  274. package/dist/esm/ToastViewport.native.js.map +0 -1
  275. package/dist/esm/Toaster.mjs +0 -51
  276. package/dist/esm/Toaster.mjs.map +0 -1
  277. package/dist/esm/Toaster.native.js +0 -52
  278. package/dist/esm/Toaster.native.js.map +0 -1
  279. package/dist/esm/constants.mjs +0 -4
  280. package/dist/esm/constants.mjs.map +0 -1
  281. package/dist/esm/constants.native.js +0 -4
  282. package/dist/esm/constants.native.js.map +0 -1
  283. package/dist/esm/createNativeToast.mjs +0 -32
  284. package/dist/esm/createNativeToast.mjs.map +0 -1
  285. package/dist/esm/createNativeToast.native.js +0 -30
  286. package/dist/esm/createNativeToast.native.js.map +0 -1
  287. package/dist/esm/dispatchNativeToast.mjs +0 -22
  288. package/dist/esm/dispatchNativeToast.mjs.map +0 -1
  289. package/dist/esm/dispatchNativeToast.native.js +0 -24
  290. package/dist/esm/dispatchNativeToast.native.js.map +0 -1
  291. package/dist/esm/index.mjs +0 -2
  292. package/dist/esm/index.mjs.map +0 -1
  293. package/dist/esm/index.native.js +0 -2
  294. package/dist/esm/index.native.js.map +0 -1
  295. package/dist/esm/types.mjs +0 -2
  296. package/dist/esm/types.mjs.map +0 -1
  297. package/dist/esm/types.native.js +0 -2
  298. package/dist/esm/types.native.js.map +0 -1
  299. package/dist/esm/useAnimatedDragGesture.mjs +0 -178
  300. package/dist/esm/useAnimatedDragGesture.mjs.map +0 -1
  301. package/dist/esm/useAnimatedDragGesture.native.js +0 -185
  302. package/dist/esm/useAnimatedDragGesture.native.js.map +0 -1
  303. package/dist/esm/useReducedMotion.mjs +0 -38
  304. package/dist/esm/useReducedMotion.mjs.map +0 -1
  305. package/dist/esm/useReducedMotion.native.js +0 -44
  306. package/dist/esm/useReducedMotion.native.js.map +0 -1
  307. package/dist/esm/useToastAnimations.mjs +0 -256
  308. package/dist/esm/useToastAnimations.mjs.map +0 -1
  309. package/dist/esm/useToastAnimations.native.js +0 -263
  310. package/dist/esm/useToastAnimations.native.js.map +0 -1
  311. package/dist/esm/v2.mjs +0 -6
  312. package/dist/esm/v2.mjs.map +0 -1
  313. package/dist/esm/v2.native.js +0 -6
  314. package/dist/esm/v2.native.js.map +0 -1
  315. package/dist/jsx/Toast.mjs +0 -137
  316. package/dist/jsx/Toast.mjs.map +0 -1
  317. package/dist/jsx/Toast.native.js +0 -181
  318. package/dist/jsx/Toast.native.js.map +0 -1
  319. package/dist/jsx/ToastAnnounce.mjs +0 -66
  320. package/dist/jsx/ToastAnnounce.mjs.map +0 -1
  321. package/dist/jsx/ToastAnnounce.native.js +0 -111
  322. package/dist/jsx/ToastAnnounce.native.js.map +0 -1
  323. package/dist/jsx/ToastComposable.mjs +0 -909
  324. package/dist/jsx/ToastComposable.mjs.map +0 -1
  325. package/dist/jsx/ToastComposable.native.js +0 -1055
  326. package/dist/jsx/ToastComposable.native.js.map +0 -1
  327. package/dist/jsx/ToastImperative.mjs +0 -80
  328. package/dist/jsx/ToastImperative.mjs.map +0 -1
  329. package/dist/jsx/ToastImperative.native.js +0 -130
  330. package/dist/jsx/ToastImperative.native.js.map +0 -1
  331. package/dist/jsx/ToastImpl.mjs +0 -316
  332. package/dist/jsx/ToastImpl.mjs.map +0 -1
  333. package/dist/jsx/ToastImpl.native.js +0 -364
  334. package/dist/jsx/ToastImpl.native.js.map +0 -1
  335. package/dist/jsx/ToastItemFrame.mjs +0 -114
  336. package/dist/jsx/ToastItemFrame.mjs.map +0 -1
  337. package/dist/jsx/ToastItemFrame.native.js +0 -148
  338. package/dist/jsx/ToastItemFrame.native.js.map +0 -1
  339. package/dist/jsx/ToastPortal.mjs +0 -24
  340. package/dist/jsx/ToastPortal.mjs.map +0 -1
  341. package/dist/jsx/ToastPortal.native.js +0 -52
  342. package/dist/jsx/ToastPortal.native.js.map +0 -1
  343. package/dist/jsx/ToastProvider.mjs +0 -110
  344. package/dist/jsx/ToastProvider.mjs.map +0 -1
  345. package/dist/jsx/ToastProvider.native.js +0 -161
  346. package/dist/jsx/ToastProvider.native.js.map +0 -1
  347. package/dist/jsx/ToastState.mjs +0 -285
  348. package/dist/jsx/ToastState.mjs.map +0 -1
  349. package/dist/jsx/ToastState.native.js +0 -324
  350. package/dist/jsx/ToastState.native.js.map +0 -1
  351. package/dist/jsx/ToastViewport.mjs +0 -280
  352. package/dist/jsx/ToastViewport.mjs.map +0 -1
  353. package/dist/jsx/ToastViewport.native.js +0 -343
  354. package/dist/jsx/ToastViewport.native.js.map +0 -1
  355. package/dist/jsx/Toaster.mjs +0 -51
  356. package/dist/jsx/Toaster.mjs.map +0 -1
  357. package/dist/jsx/Toaster.native.js +0 -91
  358. package/dist/jsx/Toaster.native.js.map +0 -1
  359. package/dist/jsx/constants.mjs +0 -4
  360. package/dist/jsx/constants.mjs.map +0 -1
  361. package/dist/jsx/constants.native.js +0 -33
  362. package/dist/jsx/constants.native.js.map +0 -1
  363. package/dist/jsx/createNativeToast.mjs +0 -32
  364. package/dist/jsx/createNativeToast.mjs.map +0 -1
  365. package/dist/jsx/createNativeToast.native.js +0 -60
  366. package/dist/jsx/createNativeToast.native.js.map +0 -1
  367. package/dist/jsx/dispatchNativeToast.mjs +0 -22
  368. package/dist/jsx/dispatchNativeToast.mjs.map +0 -1
  369. package/dist/jsx/dispatchNativeToast.native.js +0 -52
  370. package/dist/jsx/dispatchNativeToast.native.js.map +0 -1
  371. package/dist/jsx/index.js +0 -2
  372. package/dist/jsx/index.js.map +0 -1
  373. package/dist/jsx/index.mjs +0 -2
  374. package/dist/jsx/index.mjs.map +0 -1
  375. package/dist/jsx/index.native.js +0 -23
  376. package/dist/jsx/index.native.js.map +0 -1
  377. package/dist/jsx/types.mjs +0 -2
  378. package/dist/jsx/types.mjs.map +0 -1
  379. package/dist/jsx/types.native.js +0 -21
  380. package/dist/jsx/types.native.js.map +0 -1
  381. package/dist/jsx/useAnimatedDragGesture.mjs +0 -178
  382. package/dist/jsx/useAnimatedDragGesture.mjs.map +0 -1
  383. package/dist/jsx/useAnimatedDragGesture.native.js +0 -224
  384. package/dist/jsx/useAnimatedDragGesture.native.js.map +0 -1
  385. package/dist/jsx/useReducedMotion.mjs +0 -38
  386. package/dist/jsx/useReducedMotion.mjs.map +0 -1
  387. package/dist/jsx/useReducedMotion.native.js +0 -83
  388. package/dist/jsx/useReducedMotion.native.js.map +0 -1
  389. package/dist/jsx/useToastAnimations.mjs +0 -256
  390. package/dist/jsx/useToastAnimations.mjs.map +0 -1
  391. package/dist/jsx/useToastAnimations.native.js +0 -302
  392. package/dist/jsx/useToastAnimations.native.js.map +0 -1
  393. package/dist/jsx/v2.mjs +0 -6
  394. package/dist/jsx/v2.mjs.map +0 -1
  395. package/dist/jsx/v2.native.js +0 -39
  396. package/dist/jsx/v2.native.js.map +0 -1
  397. package/v2/index.cjs +0 -2
  398. package/v2/index.js +0 -2
  399. package/v2/index.native.cjs +0 -2
  400. package/v2/index.native.js +0 -2
@@ -1,947 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: () => from[key],
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
34
- var ToastComposable_exports = {};
35
- __export(ToastComposable_exports, {
36
- Toast: () => Toast,
37
- useToastItem: () => useToastItem,
38
- useToasts: () => useToasts
39
- });
40
- module.exports = __toCommonJS(ToastComposable_exports);
41
- var import_animate_presence = require("@hanzogui/animate-presence");
42
- var import_constants = require("@hanzogui/constants");
43
- var import_native = require("@hanzogui/native");
44
- var import_core = require("@hanzogui/core");
45
- var import_helpers = require("@hanzogui/helpers");
46
- var import_portal = require("@hanzogui/portal");
47
- var import_stacks = require("@hanzogui/stacks");
48
- var import_text = require("@hanzogui/text");
49
- var React = __toESM(require("react"), 1);
50
- var import_ToastState = require("./ToastState.cjs");
51
- var import_dispatchNativeToast = require("./dispatchNativeToast.cjs");
52
- var import_useAnimatedDragGesture = require("./useAnimatedDragGesture.cjs");
53
- var import_useToastAnimations = require("./useToastAnimations.cjs");
54
- var import_useReducedMotion = require("./useReducedMotion.cjs");
55
- var import_ToastItemFrame = require("./ToastItemFrame.cjs");
56
- var import_jsx_runtime = require("react/jsx-runtime");
57
- const VISIBLE_TOASTS_AMOUNT = 4;
58
- const VIEWPORT_OFFSET = 16;
59
- const TOAST_GAP = 14;
60
- const TOAST_LIFETIME = 4e3;
61
- const FIXED_TOAST_HEIGHT = 72;
62
- const TIME_BEFORE_UNMOUNT = 200;
63
- const DEFAULT_HOTKEY = ["altKey", "KeyT"];
64
- const ToastContext = (0, import_core.createStyledContext)({}, "Toast__");
65
- const useToastContextValue = ToastContext.useStyledContext;
66
- function hasToastContext(ctx) {
67
- return !!ctx && Array.isArray(ctx.toasts) && typeof ctx.setToastHeight === "function" && typeof ctx.removeToast === "function";
68
- }
69
- function useToastContext(consumerName) {
70
- const ctx = useToastContextValue();
71
- if (!hasToastContext(ctx)) {
72
- throw new Error(`\`${consumerName}\` must be used within \`Toast\``);
73
- }
74
- return ctx;
75
- }
76
- const ToastItemContext = React.createContext(null);
77
- function useToastItemContext() {
78
- const ctx = React.useContext(ToastItemContext);
79
- if (!ctx) {
80
- throw new Error("useToastItemContext must be used within Toast.Item or Toast.List");
81
- }
82
- return ctx;
83
- }
84
- function resolveSwipeDirection(direction, position) {
85
- if (direction !== "auto") return direction;
86
- const [yPosition, xPosition] = position.split("-");
87
- if (!import_constants.isWeb) {
88
- return yPosition === "top" ? "up" : "down";
89
- }
90
- if (xPosition === "left") return "left";
91
- if (xPosition === "right") return "right";
92
- return "horizontal";
93
- }
94
- const ToastRoot = React.forwardRef(function ToastRoot2(props, _ref) {
95
- const {
96
- children,
97
- position = "bottom-right",
98
- duration = TOAST_LIFETIME,
99
- gap = TOAST_GAP,
100
- visibleToasts = VISIBLE_TOASTS_AMOUNT,
101
- swipeDirection: swipeDirectionProp = "auto",
102
- swipeThreshold = 50,
103
- toastHeight = FIXED_TOAST_HEIGHT,
104
- closeButton = false,
105
- expand = false,
106
- theme: themeProp,
107
- reducedMotion: reducedMotionProp,
108
- native = false,
109
- burntOptions,
110
- notificationOptions,
111
- icons
112
- } = props;
113
- const reducedMotion = (0, import_useReducedMotion.useReducedMotion)(reducedMotionProp);
114
- const [toasts, setToasts] = React.useState([]);
115
- const [heights, setHeights] = React.useState({});
116
- const [localExpanded, setExpanded] = React.useState(false);
117
- const expanded = expand || localExpanded;
118
- const [interacting, setInteracting] = React.useState(false);
119
- const heightsLockedRef = React.useRef(false);
120
- const prevExpandedRef = React.useRef(expanded);
121
- React.useLayoutEffect(() => {
122
- if (prevExpandedRef.current !== expanded) {
123
- heightsLockedRef.current = true;
124
- prevExpandedRef.current = expanded;
125
- }
126
- const timer = setTimeout(() => {
127
- heightsLockedRef.current = false;
128
- }, 350);
129
- return () => clearTimeout(timer);
130
- }, [expanded]);
131
- const setToastHeight = React.useCallback((toastId, height) => {
132
- if (heightsLockedRef.current) return;
133
- const rounded = Math.round(height);
134
- setHeights(prev => {
135
- const existing = prev[toastId];
136
- if (existing != null && Math.abs(existing - rounded) <= 2) return prev;
137
- return {
138
- ...prev,
139
- [toastId]: rounded
140
- };
141
- });
142
- }, []);
143
- const removeToastHeight = React.useCallback(toastId => {
144
- setHeights(prev => {
145
- if (!(toastId in prev)) return prev;
146
- const next = {
147
- ...prev
148
- };
149
- delete next[toastId];
150
- return next;
151
- });
152
- }, []);
153
- const dismissCooldownRef = React.useRef(false);
154
- const dismissCooldownTimerRef = React.useRef(null);
155
- const triggerDismissCooldown = React.useCallback(() => {
156
- dismissCooldownRef.current = true;
157
- if (dismissCooldownTimerRef.current) {
158
- clearTimeout(dismissCooldownTimerRef.current);
159
- }
160
- dismissCooldownTimerRef.current = setTimeout(() => {
161
- dismissCooldownRef.current = false;
162
- }, 800);
163
- }, []);
164
- const isInDismissCooldown = React.useCallback(() => dismissCooldownRef.current, []);
165
- const burntOptionsRef = React.useRef(burntOptions);
166
- const notificationOptionsRef = React.useRef(notificationOptions);
167
- React.useEffect(() => {
168
- burntOptionsRef.current = burntOptions;
169
- }, [burntOptions]);
170
- React.useEffect(() => {
171
- notificationOptionsRef.current = notificationOptions;
172
- }, [notificationOptions]);
173
- React.useEffect(() => {
174
- return import_ToastState.ToastState.subscribe(toast => {
175
- if (toast.dismiss) {
176
- setToasts(toasts2 => toasts2.map(t => t.id === toast.id ? {
177
- ...t,
178
- delete: true
179
- } : t));
180
- return;
181
- }
182
- if (native) {
183
- const handled = (0, import_dispatchNativeToast.dispatchNativeToast)(toast, {
184
- duration,
185
- burntOptions: burntOptionsRef.current,
186
- notificationOptions: notificationOptionsRef.current
187
- });
188
- if (handled) return;
189
- }
190
- setToasts(toasts2 => {
191
- const idx = toasts2.findIndex(t => t.id === toast.id);
192
- if (idx !== -1) {
193
- return [...toasts2.slice(0, idx), {
194
- ...toasts2[idx],
195
- ...toast
196
- }, ...toasts2.slice(idx + 1)];
197
- }
198
- return [toast, ...toasts2];
199
- });
200
- });
201
- }, [native, duration]);
202
- const prevToastCountRef = React.useRef(toasts.length);
203
- React.useEffect(() => {
204
- const prevCount = prevToastCountRef.current;
205
- prevToastCountRef.current = toasts.length;
206
- if (toasts.length <= 1 && !dismissCooldownRef.current) {
207
- setExpanded(false);
208
- } else if (toasts.length > prevCount && expanded) {
209
- setExpanded(false);
210
- }
211
- }, [toasts.length, expanded]);
212
- const removeToast = React.useCallback(toastToRemove => {
213
- setToasts(toasts2 => {
214
- if (!toasts2.find(t => t.id === toastToRemove.id)?.delete) {
215
- import_ToastState.ToastState.dismiss(toastToRemove.id);
216
- }
217
- return toasts2.filter(({
218
- id
219
- }) => id !== toastToRemove.id);
220
- });
221
- }, []);
222
- const swipeDirection = resolveSwipeDirection(swipeDirectionProp, position);
223
- const currentTheme = (0, import_core.useThemeName)();
224
- const resolvedTheme = themeProp === "system" || !themeProp ? currentTheme?.includes("dark") ? "dark" : "light" : themeProp;
225
- const contextValue = {
226
- toasts,
227
- heights,
228
- setToastHeight,
229
- removeToastHeight,
230
- expanded,
231
- setExpanded,
232
- interacting,
233
- setInteracting,
234
- triggerDismissCooldown,
235
- isInDismissCooldown,
236
- removeToast,
237
- position,
238
- duration,
239
- gap,
240
- visibleToasts,
241
- swipeDirection,
242
- swipeThreshold,
243
- toastHeight,
244
- closeButton,
245
- reducedMotion,
246
- native,
247
- burntOptions,
248
- notificationOptions,
249
- icons
250
- };
251
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
252
- ...contextValue,
253
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
254
- name: resolvedTheme,
255
- children
256
- })
257
- });
258
- });
259
- const ToastViewportFrame = (0, import_core.styled)(import_core.View, {
260
- name: "ToastViewport",
261
- variants: {
262
- unstyled: {
263
- false: {
264
- position: import_constants.isWeb ? "fixed" : "absolute",
265
- zIndex: 1e5,
266
- pointerEvents: "box-none",
267
- maxWidth: "100%",
268
- ...(import_constants.isWeb && {
269
- width: 356
270
- }),
271
- minHeight: 1
272
- }
273
- }
274
- },
275
- defaultVariants: {
276
- unstyled: process.env.GUI_HEADLESS === "1"
277
- }
278
- });
279
- const ToastViewport = ToastViewportFrame.styleable(function ToastViewport2(props, ref) {
280
- const {
281
- offset = VIEWPORT_OFFSET,
282
- hotkey = DEFAULT_HOTKEY,
283
- label = "Notifications",
284
- portalToRoot = true,
285
- portalZIndex = Number.MAX_SAFE_INTEGER,
286
- children,
287
- ...rest
288
- } = props;
289
- const ctx = useToastContext("Toast.Viewport");
290
- const listRef = React.useRef(null);
291
- const hoverTimeoutRef = React.useRef(null);
292
- const hoverCooldownRef = React.useRef(false);
293
- const deferredCollapseRef = React.useRef(null);
294
- const mouseInsideRef = React.useRef(false);
295
- const [yPosition, xPosition] = ctx.position.split("-");
296
- const {
297
- insets: safeInsets
298
- } = (0, import_core.useConfiguration)();
299
- const offsetStyles = React.useMemo(() => {
300
- const styles = {};
301
- const defaultOffset = typeof offset === "number" ? offset : VIEWPORT_OFFSET;
302
- const offsetObj = typeof offset === "object" ? offset : {
303
- top: defaultOffset,
304
- right: defaultOffset,
305
- bottom: defaultOffset,
306
- left: defaultOffset
307
- };
308
- const safeTop = safeInsets?.top ?? 0;
309
- const safeBottom = safeInsets?.bottom ?? 0;
310
- const topOffset = safeTop > 0 ? safeTop : offsetObj.top ?? defaultOffset;
311
- const bottomOffset = safeBottom > 0 ? safeBottom : offsetObj.bottom ?? defaultOffset;
312
- if (yPosition === "top") styles.top = topOffset;else styles.bottom = bottomOffset;
313
- if (import_constants.isWeb) {
314
- if (xPosition === "left") styles.left = offsetObj.left ?? defaultOffset;else if (xPosition === "right") styles.right = offsetObj.right ?? defaultOffset;else {
315
- styles.left = "50%";
316
- styles.transform = "translateX(-50%)";
317
- }
318
- } else {
319
- styles.left = offsetObj.left ?? defaultOffset;
320
- styles.right = offsetObj.right ?? defaultOffset;
321
- }
322
- return styles;
323
- }, [offset, yPosition, xPosition]);
324
- React.useEffect(() => {
325
- if (!import_constants.isWeb) return;
326
- const handleKeyDown = event => {
327
- const isHotkeyPressed = hotkey.length > 0 && hotkey.every(key => event[key] || event.code === key);
328
- if (isHotkeyPressed) {
329
- ctx.setExpanded(true);
330
- listRef.current?.focus();
331
- }
332
- };
333
- document.addEventListener("keydown", handleKeyDown);
334
- return () => document.removeEventListener("keydown", handleKeyDown);
335
- }, [hotkey]);
336
- if (ctx.toasts.length === 0) return null;
337
- const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
338
- const content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
339
- ref: listRef,
340
- "aria-label": `${label} ${hotkeyLabel}`,
341
- tabIndex: -1,
342
- "aria-live": "polite",
343
- style: offsetStyles,
344
- "data-y-position": yPosition,
345
- "data-x-position": xPosition,
346
- ...(import_constants.isWeb ? {
347
- onMouseEnter: () => {
348
- mouseInsideRef.current = true;
349
- if (deferredCollapseRef.current) {
350
- clearTimeout(deferredCollapseRef.current);
351
- deferredCollapseRef.current = null;
352
- }
353
- if (ctx.toasts.length > 1 && !ctx.interacting && !hoverCooldownRef.current) {
354
- hoverTimeoutRef.current = setTimeout(() => ctx.setExpanded(true), 50);
355
- }
356
- },
357
- onMouseLeave: () => {
358
- mouseInsideRef.current = false;
359
- if (hoverTimeoutRef.current) {
360
- clearTimeout(hoverTimeoutRef.current);
361
- hoverTimeoutRef.current = null;
362
- }
363
- if (!ctx.interacting && !ctx.isInDismissCooldown()) {
364
- ctx.setExpanded(false);
365
- } else if (ctx.isInDismissCooldown()) {
366
- if (deferredCollapseRef.current) {
367
- clearTimeout(deferredCollapseRef.current);
368
- }
369
- deferredCollapseRef.current = setTimeout(() => {
370
- deferredCollapseRef.current = null;
371
- if (!mouseInsideRef.current) {
372
- ctx.setExpanded(false);
373
- }
374
- }, 1200);
375
- }
376
- },
377
- onPointerDown: () => {
378
- if (hoverTimeoutRef.current) {
379
- clearTimeout(hoverTimeoutRef.current);
380
- hoverTimeoutRef.current = null;
381
- }
382
- ctx.setInteracting(true);
383
- },
384
- onPointerUp: () => ctx.setInteracting(false),
385
- onPointerCancel: () => ctx.setInteracting(false)
386
- } : {
387
- onPress: () => {
388
- if (ctx.toasts.length > 1) {
389
- ctx.setExpanded(prev => !prev);
390
- }
391
- }
392
- }),
393
- ...(import_constants.isWeb && {
394
- onFocus: event => {
395
- if (!event.currentTarget.contains(event.relatedTarget)) {
396
- if (ctx.toasts.length > 1) {
397
- ctx.setExpanded(true);
398
- }
399
- ctx.setInteracting(true);
400
- }
401
- },
402
- onBlur: event => {
403
- if (!event.currentTarget.contains(event.relatedTarget)) {
404
- ctx.setInteracting(false);
405
- if (!ctx.isInDismissCooldown()) {
406
- ctx.setExpanded(false);
407
- }
408
- }
409
- }
410
- }),
411
- ...rest,
412
- children
413
- });
414
- if (portalToRoot) {
415
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
416
- zIndex: portalZIndex,
417
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
418
- ...ctx,
419
- children: content
420
- })
421
- });
422
- }
423
- return content;
424
- });
425
- function ToastList({
426
- renderItem
427
- }) {
428
- const ctx = useToastContext("Toast.List");
429
- const maxRender = ctx.toasts.length;
430
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
431
- children: ctx.toasts.slice(0, maxRender).map((toast, index) => {
432
- const handleClose = () => {
433
- if (toast.dismissible === false) return;
434
- toast.onDismiss?.(toast);
435
- ctx.removeToast(toast);
436
- };
437
- const itemContextValue = {
438
- toast,
439
- handleClose
440
- };
441
- if (!renderItem) {
442
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
443
- value: itemContextValue,
444
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemInner, {
445
- toast,
446
- index,
447
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DefaultToastContent, {
448
- toast
449
- })
450
- })
451
- }, toast.id);
452
- }
453
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
454
- value: itemContextValue,
455
- children: renderItem({
456
- toast,
457
- index,
458
- handleClose
459
- })
460
- }, toast.id);
461
- })
462
- });
463
- }
464
- function DefaultToastContent({
465
- toast
466
- }) {
467
- const ctx = useToastContext("Toast.Item");
468
- const {
469
- handleClose
470
- } = useToastItemContext();
471
- const toastType = toast.type ?? "default";
472
- const dismissible = toast.dismissible !== false;
473
- const title = typeof toast.title === "function" ? toast.title() : toast.title;
474
- const description = typeof toast.description === "function" ? toast.description() : toast.description;
475
- return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
476
- alignItems: "flex-start",
477
- gap: "$3",
478
- children: [/* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastIcon, {}), /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.YStack, {
479
- flex: 1,
480
- gap: "$1",
481
- children: [title && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastTitle, {
482
- children: title
483
- }), description && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastDescription, {
484
- children: description
485
- }), (toast.action || toast.cancel) && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_stacks.XStack, {
486
- gap: "$2",
487
- marginTop: "$2",
488
- children: [toast.cancel && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
489
- backgroundColor: "transparent",
490
- onPress: e => {
491
- toast.cancel?.onClick?.(e);
492
- handleClose();
493
- },
494
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
495
- size: "$2",
496
- color: "$color11",
497
- children: toast.cancel.label
498
- })
499
- }), toast.action && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
500
- backgroundColor: "$color12",
501
- hoverStyle: {
502
- backgroundColor: "$color11"
503
- },
504
- pressStyle: {
505
- backgroundColor: "$color10"
506
- },
507
- onPress: e => {
508
- toast.action?.onClick?.(e);
509
- if (!e.defaultPrevented) {
510
- handleClose();
511
- }
512
- },
513
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_text.SizableText, {
514
- size: "$2",
515
- fontWeight: "600",
516
- color: "$background",
517
- children: toast.action.label
518
- })
519
- })]
520
- })]
521
- }), ctx.closeButton && dismissible && /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastClose, {})]
522
- });
523
- }
524
- function DragWrapper({
525
- animatedStyle,
526
- gestureHandlers,
527
- gesture,
528
- AnimatedView,
529
- dragRef,
530
- children
531
- }) {
532
- if (import_constants.isWeb) {
533
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)("div", {
534
- ref: dragRef,
535
- style: {
536
- flex: 1,
537
- display: "flex",
538
- flexDirection: "column",
539
- userSelect: "none",
540
- WebkitUserSelect: "none",
541
- touchAction: "none",
542
- cursor: "default"
543
- },
544
- ...gestureHandlers,
545
- children
546
- });
547
- }
548
- if (gesture) {
549
- const gh = (0, import_native.getGestureHandler)();
550
- const GestureDetector = gh.state.GestureDetector;
551
- if (GestureDetector) {
552
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(GestureDetector, {
553
- gesture,
554
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
555
- style: {
556
- flex: 1
557
- },
558
- ...{
559
- collapsable: false
560
- },
561
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
562
- style: [{
563
- flex: 1
564
- }, animatedStyle],
565
- children
566
- })
567
- })
568
- });
569
- }
570
- }
571
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
572
- style: [{
573
- flex: 1
574
- }, animatedStyle],
575
- ...gestureHandlers,
576
- children
577
- });
578
- }
579
- const ToastItemInner = import_ToastItemFrame.ToastItemFrame.styleable(function ToastItem(props, ref) {
580
- const {
581
- toast,
582
- index,
583
- children,
584
- ...rest
585
- } = props;
586
- const ctx = useToastContext("Toast.Item");
587
- const [mounted, setMounted] = React.useState(false);
588
- const [removed, setRemoved] = React.useState(false);
589
- const [swipeOut, setSwipeOut] = React.useState(false);
590
- const [offsetBeforeRemove, setOffsetBeforeRemove] = React.useState(0);
591
- const swipeExitYRef = React.useRef(null);
592
- const closeTimerRef = React.useRef(null);
593
- const closeTimerStartRef = React.useRef(0);
594
- const lastPauseTimeRef = React.useRef(0);
595
- const remainingTimeRef = React.useRef(toast.duration ?? ctx.duration);
596
- const isFront = index === 0;
597
- const isVisible = index < ctx.visibleToasts;
598
- const toastType = toast.type ?? "default";
599
- const dismissible = toast.dismissible !== false;
600
- const duration = toast.duration ?? ctx.duration;
601
- const [yPosition] = ctx.position.split("-");
602
- const isTop = yPosition === "top";
603
- const expandedOffset = import_constants.isWeb ? (() => {
604
- let totalHeight = 0;
605
- let activeCount = 0;
606
- for (let i = 0; i < index; i++) {
607
- const toastId = ctx.toasts[i]?.id;
608
- if (toastId == null) continue;
609
- const h = ctx.heights[toastId];
610
- if (h === 0) continue;
611
- totalHeight += h ?? ctx.toastHeight;
612
- activeCount++;
613
- }
614
- return totalHeight + activeCount * ctx.gap;
615
- })() : index * (ctx.toastHeight + ctx.gap);
616
- const expandedOffsetRef = React.useRef(expandedOffset);
617
- expandedOffsetRef.current = expandedOffset;
618
- const isExpandedRef = React.useRef(ctx.expanded);
619
- isExpandedRef.current = ctx.expanded;
620
- const startTimer = React.useCallback(() => {
621
- if (duration === Number.POSITIVE_INFINITY || toastType === "loading") return;
622
- closeTimerStartRef.current = Date.now();
623
- closeTimerRef.current = setTimeout(() => {
624
- toast.onAutoClose?.(toast);
625
- setRemoved(true);
626
- setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
627
- }, remainingTimeRef.current);
628
- }, [duration, toastType, toast, ctx.removeToast]);
629
- const pauseTimer = (0, import_core.useEvent)(() => {
630
- if (closeTimerRef.current) {
631
- clearTimeout(closeTimerRef.current);
632
- }
633
- if (lastPauseTimeRef.current < closeTimerStartRef.current) {
634
- const elapsed = Date.now() - closeTimerStartRef.current;
635
- remainingTimeRef.current = Math.max(0, remainingTimeRef.current - elapsed);
636
- }
637
- lastPauseTimeRef.current = Date.now();
638
- });
639
- const resumeTimer = (0, import_core.useEvent)(() => {
640
- if (ctx.expanded || ctx.interacting) return;
641
- remainingTimeRef.current = duration;
642
- startTimer();
643
- });
644
- React.useEffect(() => {
645
- setMounted(true);
646
- }, []);
647
- React.useEffect(() => {
648
- if (toast.delete) {
649
- setRemoved(true);
650
- if (isExpandedRef.current) {
651
- setOffsetBeforeRemove(expandedOffsetRef.current);
652
- }
653
- setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
654
- }
655
- }, [toast.delete, toast, ctx.removeToast]);
656
- React.useEffect(() => {
657
- if (ctx.expanded || ctx.interacting) {
658
- pauseTimer();
659
- } else {
660
- startTimer();
661
- }
662
- return () => {
663
- if (closeTimerRef.current) clearTimeout(closeTimerRef.current);
664
- };
665
- }, [ctx.expanded, ctx.interacting, startTimer]);
666
- React.useEffect(() => {
667
- remainingTimeRef.current = duration;
668
- }, [duration]);
669
- const {
670
- setDragOffset,
671
- springBack,
672
- animateOut,
673
- animatedStyle,
674
- AnimatedView,
675
- dragRef
676
- } = (0, import_useToastAnimations.useToastAnimations)({
677
- reducedMotion: ctx.reducedMotion,
678
- swipeAxis: ctx.swipeDirection === "up" || ctx.swipeDirection === "down" || ctx.swipeDirection === "vertical" ? "vertical" : "horizontal"
679
- });
680
- const {
681
- isDragging,
682
- gestureHandlers,
683
- gesture
684
- } = (0, import_useAnimatedDragGesture.useAnimatedDragGesture)({
685
- direction: ctx.swipeDirection,
686
- threshold: ctx.swipeThreshold,
687
- disabled: !dismissible || toastType === "loading",
688
- expanded: ctx.expanded,
689
- onDragStart: pauseTimer,
690
- onDragMove: setDragOffset,
691
- onDismiss: (exitDirection, velocity) => {
692
- ctx.triggerDismissCooldown();
693
- setSwipeOut(true);
694
- toast.onDismiss?.(toast);
695
- swipeExitYRef.current = isExpandedRef.current ? isTop ? expandedOffsetRef.current : -expandedOffsetRef.current : isFront ? 0 : isTop ? ctx.gap * index : -ctx.gap * index;
696
- setRemoved(true);
697
- ctx.removeToast(toast);
698
- animateOut(exitDirection, velocity);
699
- },
700
- onCancel: () => {
701
- springBack(() => {
702
- resumeTimer();
703
- });
704
- }
705
- });
706
- const handleLayout = React.useCallback(event => {
707
- if (!import_constants.isWeb) return;
708
- if (removed) return;
709
- if (!ctx.expanded && index !== 0) return;
710
- const {
711
- height
712
- } = event.nativeEvent.layout;
713
- ctx.setToastHeight(toast.id, height);
714
- }, [toast.id, ctx.setToastHeight, index, ctx.expanded, removed]);
715
- React.useEffect(() => {
716
- if (!import_constants.isWeb) return;
717
- return () => {
718
- ctx.removeToastHeight(toast.id);
719
- };
720
- }, [toast.id, ctx.removeToastHeight]);
721
- const handleClose = React.useCallback(() => {
722
- if (!dismissible) return;
723
- ctx.triggerDismissCooldown();
724
- toast.onDismiss?.(toast);
725
- setRemoved(true);
726
- if (isExpandedRef.current) {
727
- setOffsetBeforeRemove(expandedOffsetRef.current);
728
- }
729
- setTimeout(() => ctx.removeToast(toast), TIME_BEFORE_UNMOUNT);
730
- }, [dismissible, toast, ctx.removeToast, ctx.triggerDismissCooldown]);
731
- const itemContextValue = React.useMemo(() => ({
732
- toast,
733
- handleClose
734
- }), [toast, handleClose]);
735
- let frontToastHeight = -1;
736
- if (import_constants.isWeb) {
737
- for (const t of ctx.toasts) {
738
- const h = ctx.heights[t.id];
739
- if (h != null && h > 0) {
740
- frontToastHeight = h;
741
- break;
742
- }
743
- }
744
- }
745
- const stackScale = !ctx.expanded && !isFront ? 1 - index * 0.05 : 1;
746
- const activeExpandedOffset = removed ? offsetBeforeRemove : expandedOffset;
747
- const stackY = ctx.expanded ? isTop ? activeExpandedOffset : -activeExpandedOffset : isFront ? 0 : isTop ? ctx.gap * index : -ctx.gap * index;
748
- const computedOpacity = removed && !swipeOut ? 0 : index >= ctx.visibleToasts ? 0 : 1;
749
- const computedZIndex = removed ? 0 : ctx.visibleToasts - index + 1;
750
- const computedHeight = import_constants.isWeb ? ctx.expanded ? ctx.heights[toast.id] || void 0 : !isFront && frontToastHeight > 0 ? frontToastHeight : void 0 : void 0;
751
- const computedPointerEvents = index >= ctx.visibleToasts ? "none" : "auto";
752
- const gapFillerHeight = ctx.expanded ? ctx.gap + 1 : 0;
753
- const dataAttributes = {
754
- "data-mounted": mounted ? "true" : "false",
755
- "data-removed": removed ? "true" : "false",
756
- "data-swipe-out": swipeOut ? "true" : "false",
757
- "data-visible": isVisible ? "true" : "false",
758
- "data-front": isFront ? "true" : "false",
759
- "data-index": String(index),
760
- "data-type": toastType,
761
- "data-expanded": ctx.expanded ? "true" : "false"
762
- };
763
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastPositionWrapper, {
764
- ref,
765
- testID: rest.testID,
766
- accessibilityLabel: rest.accessibilityLabel,
767
- ...dataAttributes,
768
- transition: isDragging || ctx.reducedMotion ? void 0 : removed ? "200ms" : "400ms",
769
- animateOnly: import_constants.isWeb ? ["transform", "opacity", "height"] : ["transform", "opacity"],
770
- y: stackY,
771
- scale: stackScale,
772
- opacity: computedOpacity,
773
- zIndex: computedZIndex,
774
- height: computedHeight,
775
- overflow: "visible",
776
- pointerEvents: computedPointerEvents,
777
- top: isTop ? 0 : void 0,
778
- bottom: isTop ? void 0 : 0,
779
- ...(import_constants.isWeb && !isFront && {
780
- style: {
781
- transformOrigin: isTop ? "top center" : "bottom center"
782
- }
783
- }),
784
- enterStyle: ctx.reducedMotion ? {
785
- opacity: 0
786
- } : {
787
- opacity: 0,
788
- y: isTop ? -80 : 80
789
- },
790
- exitStyle: ctx.reducedMotion ? {
791
- opacity: 0
792
- } : swipeOut ? {
793
- opacity: 0,
794
- y: swipeExitYRef.current ?? stackY,
795
- scale: stackScale
796
- } : {
797
- opacity: 0,
798
- y: stackY,
799
- scale: stackScale
800
- },
801
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(DragWrapper, {
802
- animatedStyle,
803
- gestureHandlers,
804
- gesture,
805
- AnimatedView,
806
- dragRef,
807
- children: /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_ToastItemFrame.ToastItemFrame, {
808
- "data-slot": "toast",
809
- role: "status",
810
- "aria-live": "polite",
811
- "aria-atomic": true,
812
- tabIndex: 0,
813
- onLayout: handleLayout,
814
- ...(import_constants.isWeb && {
815
- onKeyDown: event => {
816
- if (event.key === "Escape" && dismissible) {
817
- const current = event.currentTarget;
818
- const container = current.closest("[aria-label]");
819
- if (container) {
820
- const focusables = container.querySelectorAll('[tabindex="0"]');
821
- const arr = Array.from(focusables);
822
- const idx = arr.indexOf(current);
823
- const next = arr[idx + 1] || arr[idx - 1];
824
- next?.focus();
825
- }
826
- handleClose();
827
- }
828
- }
829
- }),
830
- ...rest,
831
- children: [ctx.expanded && gapFillerHeight > 0 && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
832
- position: "absolute",
833
- left: 0,
834
- right: 0,
835
- height: gapFillerHeight,
836
- pointerEvents: "auto",
837
- ...(isTop ? {
838
- top: "100%"
839
- } : {
840
- bottom: "100%"
841
- })
842
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastItemContext.Provider, {
843
- value: itemContextValue,
844
- children
845
- })]
846
- })
847
- })
848
- });
849
- });
850
- const ToastTitle = (0, import_core.styled)(import_text.SizableText, {
851
- name: "ToastTitle",
852
- variants: {
853
- unstyled: {
854
- false: {
855
- color: "$color",
856
- fontWeight: "600",
857
- size: "$4"
858
- }
859
- }
860
- },
861
- defaultVariants: {
862
- unstyled: process.env.GUI_HEADLESS === "1"
863
- }
864
- });
865
- const ToastDescription = (0, import_core.styled)(import_text.SizableText, {
866
- name: "ToastDescription",
867
- variants: {
868
- unstyled: {
869
- false: {
870
- color: "$color11",
871
- size: "$2"
872
- }
873
- }
874
- },
875
- defaultVariants: {
876
- unstyled: process.env.GUI_HEADLESS === "1"
877
- }
878
- });
879
- const ToastClose = import_ToastItemFrame.ToastCloseFrame.styleable(function ToastClose2(props, ref) {
880
- let handleClose;
881
- try {
882
- const itemCtx = useToastItemContext();
883
- handleClose = itemCtx.handleClose;
884
- } catch {}
885
- const ctx = useToastContext("Toast.Close");
886
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastCloseFrame, {
887
- ref,
888
- "aria-label": "Close toast",
889
- onPress: handleClose,
890
- ...props,
891
- children: props.children ?? ctx.icons?.close ?? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.DefaultCloseIcon, {})
892
- });
893
- });
894
- const ToastAction = import_ToastItemFrame.ToastActionFrame.styleable(function ToastAction2(props, ref) {
895
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastItemFrame.ToastActionFrame, {
896
- ref,
897
- ...props
898
- });
899
- });
900
- function ToastIcon(props) {
901
- const ctx = useToastContext("Toast.Icon");
902
- let toast;
903
- try {
904
- const itemCtx = useToastItemContext();
905
- toast = itemCtx.toast;
906
- } catch {
907
- return null;
908
- }
909
- if (!toast) return null;
910
- if (toast.icon !== void 0) {
911
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
912
- flexShrink: 0,
913
- marginTop: "$0.5",
914
- children: toast.icon
915
- });
916
- }
917
- const toastType = toast.type ?? "default";
918
- const icon = ctx.icons?.[toastType] ?? null;
919
- if (!icon) return null;
920
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
921
- flexShrink: 0,
922
- marginTop: "$0.5",
923
- children: icon
924
- });
925
- }
926
- function useToasts() {
927
- const ctx = useToastContext("useToasts");
928
- return {
929
- toasts: ctx.toasts,
930
- expanded: ctx.expanded,
931
- position: ctx.position
932
- };
933
- }
934
- function useToastItem() {
935
- return useToastItemContext();
936
- }
937
- ToastRoot.displayName = "Toast";
938
- const Toast = (0, import_helpers.withStaticProperties)(ToastRoot, {
939
- Viewport: ToastViewport,
940
- List: ToastList,
941
- Item: ToastItemInner,
942
- Title: ToastTitle,
943
- Description: ToastDescription,
944
- Close: ToastClose,
945
- Action: ToastAction,
946
- Icon: ToastIcon
947
- });