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