@tamagui/toast 2.0.0-rc.8 → 2.0.0

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