@hanzogui/toast 8.3.0 → 8.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (400) hide show
  1. package/dist/cjs/Toast.js +122 -0
  2. package/dist/cjs/Toast.js.map +1 -0
  3. package/dist/cjs/ToastAnnounce.js +55 -0
  4. package/dist/cjs/ToastAnnounce.js.map +1 -0
  5. package/dist/cjs/ToastComposable.js +849 -0
  6. package/dist/cjs/ToastComposable.js.map +1 -0
  7. package/dist/cjs/ToastImperative.js +90 -0
  8. package/dist/cjs/ToastImperative.js.map +1 -0
  9. package/dist/cjs/ToastImpl.js +307 -0
  10. package/dist/cjs/ToastImpl.js.map +1 -0
  11. package/dist/cjs/ToastItemFrame.js +121 -0
  12. package/dist/cjs/ToastItemFrame.js.map +1 -0
  13. package/dist/cjs/ToastPortal.js +16 -0
  14. package/dist/cjs/ToastPortal.js.map +1 -0
  15. package/dist/cjs/ToastProvider.js +72 -0
  16. package/dist/cjs/ToastProvider.js.map +1 -0
  17. package/dist/cjs/ToastState.js +284 -0
  18. package/dist/cjs/ToastState.js.map +1 -0
  19. package/dist/cjs/ToastViewport.js +289 -0
  20. package/dist/cjs/ToastViewport.js.map +1 -0
  21. package/dist/cjs/Toaster.js +13 -0
  22. package/dist/cjs/Toaster.js.map +1 -0
  23. package/dist/cjs/constants.js +6 -0
  24. package/dist/cjs/constants.js.map +1 -0
  25. package/dist/cjs/createNativeToast.js +42 -0
  26. package/dist/cjs/createNativeToast.js.map +1 -0
  27. package/dist/cjs/dispatchNativeToast.js +31 -0
  28. package/dist/cjs/dispatchNativeToast.js.map +1 -0
  29. package/dist/cjs/index.js +5 -0
  30. package/dist/cjs/index.js.map +1 -0
  31. package/dist/cjs/package.json +1 -0
  32. package/dist/cjs/types.js +3 -0
  33. package/dist/cjs/types.js.map +1 -0
  34. package/dist/cjs/useAnimatedDragGesture.js +251 -0
  35. package/dist/cjs/useAnimatedDragGesture.js.map +1 -0
  36. package/dist/cjs/useReducedMotion.js +52 -0
  37. package/dist/cjs/useReducedMotion.js.map +1 -0
  38. package/dist/cjs/useToastAnimations.js +252 -0
  39. package/dist/cjs/useToastAnimations.js.map +1 -0
  40. package/dist/cjs/v2.js +17 -0
  41. package/dist/cjs/v2.js.map +1 -0
  42. package/dist/esm/Toast.js +117 -0
  43. package/dist/esm/Toast.js.map +1 -0
  44. package/dist/esm/ToastAnnounce.js +50 -0
  45. package/dist/esm/ToastAnnounce.js.map +1 -0
  46. package/dist/esm/ToastComposable.js +843 -0
  47. package/dist/esm/ToastComposable.js.map +1 -0
  48. package/dist/esm/ToastImperative.js +82 -0
  49. package/dist/esm/ToastImperative.js.map +1 -0
  50. package/dist/esm/ToastImpl.js +301 -0
  51. package/dist/esm/ToastImpl.js.map +1 -0
  52. package/dist/esm/ToastItemFrame.js +117 -0
  53. package/dist/esm/ToastItemFrame.js.map +1 -0
  54. package/dist/esm/ToastPortal.js +13 -0
  55. package/dist/esm/ToastPortal.js.map +1 -0
  56. package/dist/esm/ToastProvider.js +64 -0
  57. package/dist/esm/ToastProvider.js.map +1 -0
  58. package/dist/esm/ToastState.js +281 -0
  59. package/dist/esm/ToastState.js.map +1 -0
  60. package/dist/esm/ToastViewport.js +282 -0
  61. package/dist/esm/ToastViewport.js.map +1 -0
  62. package/dist/esm/Toaster.js +9 -0
  63. package/dist/esm/Toaster.js.map +1 -0
  64. package/dist/esm/constants.js +3 -0
  65. package/dist/esm/constants.js.map +1 -0
  66. package/dist/esm/createNativeToast.js +36 -0
  67. package/dist/esm/createNativeToast.js.map +1 -0
  68. package/dist/esm/dispatchNativeToast.js +28 -0
  69. package/dist/esm/dispatchNativeToast.js.map +1 -0
  70. package/dist/esm/index.js +2 -2
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/esm/types.js +2 -0
  73. package/dist/esm/types.js.map +1 -0
  74. package/dist/esm/useAnimatedDragGesture.js +247 -0
  75. package/dist/esm/useAnimatedDragGesture.js.map +1 -0
  76. package/dist/esm/useReducedMotion.js +48 -0
  77. package/dist/esm/useReducedMotion.js.map +1 -0
  78. package/dist/esm/useToastAnimations.js +248 -0
  79. package/dist/esm/useToastAnimations.js.map +1 -0
  80. package/dist/esm/v2.js +8 -0
  81. package/dist/esm/v2.js.map +1 -0
  82. package/dist/native/Toast.js +117 -0
  83. package/dist/native/Toast.js.map +1 -0
  84. package/dist/native/ToastAnnounce.js +50 -0
  85. package/dist/native/ToastAnnounce.js.map +1 -0
  86. package/dist/native/ToastComposable.js +843 -0
  87. package/dist/native/ToastComposable.js.map +1 -0
  88. package/dist/native/ToastImperative.js +82 -0
  89. package/dist/native/ToastImperative.js.map +1 -0
  90. package/dist/native/ToastImpl.js +301 -0
  91. package/dist/native/ToastImpl.js.map +1 -0
  92. package/dist/native/ToastItemFrame.js +117 -0
  93. package/dist/native/ToastItemFrame.js.map +1 -0
  94. package/dist/native/ToastPortal.js +13 -0
  95. package/dist/native/ToastPortal.js.map +1 -0
  96. package/dist/native/ToastProvider.js +64 -0
  97. package/dist/native/ToastProvider.js.map +1 -0
  98. package/dist/native/ToastState.js +281 -0
  99. package/dist/native/ToastState.js.map +1 -0
  100. package/dist/native/ToastViewport.js +282 -0
  101. package/dist/native/ToastViewport.js.map +1 -0
  102. package/dist/native/Toaster.js +9 -0
  103. package/dist/native/Toaster.js.map +1 -0
  104. package/dist/native/constants.js +3 -0
  105. package/dist/native/constants.js.map +1 -0
  106. package/dist/native/createNativeToast.js +25 -0
  107. package/dist/native/createNativeToast.js.map +1 -0
  108. package/dist/native/dispatchNativeToast.js +28 -0
  109. package/dist/native/dispatchNativeToast.js.map +1 -0
  110. package/dist/native/index.js +2 -0
  111. package/dist/native/index.js.map +1 -0
  112. package/dist/native/types.js +2 -0
  113. package/dist/native/types.js.map +1 -0
  114. package/dist/native/useAnimatedDragGesture.js +210 -0
  115. package/dist/native/useAnimatedDragGesture.js.map +1 -0
  116. package/dist/native/useReducedMotion.js +48 -0
  117. package/dist/native/useReducedMotion.js.map +1 -0
  118. package/dist/native/useToastAnimations.js +248 -0
  119. package/dist/native/useToastAnimations.js.map +1 -0
  120. package/dist/native/v2.js +8 -0
  121. package/dist/native/v2.js.map +1 -0
  122. package/package.json +44 -45
  123. package/src/Toast.tsx +9 -9
  124. package/src/ToastAnnounce.tsx +2 -2
  125. package/src/ToastComposable.tsx +9 -9
  126. package/src/ToastImperative.tsx +2 -2
  127. package/src/ToastImpl.tsx +5 -5
  128. package/src/ToastPortal.tsx +4 -1
  129. package/src/ToastProvider.tsx +4 -4
  130. package/src/ToastState.ts +1 -1
  131. package/src/ToastViewport.tsx +4 -4
  132. package/src/Toaster.tsx +5 -5
  133. package/src/createNativeToast.native.tsx +1 -1
  134. package/src/createNativeToast.tsx +1 -1
  135. package/src/dispatchNativeToast.ts +3 -3
  136. package/src/index.ts +7 -3
  137. package/src/useAnimatedDragGesture.native.ts +1 -1
  138. package/src/useAnimatedDragGesture.ts +1 -1
  139. package/src/v2.ts +13 -9
  140. package/types/Toast.d.ts +19 -19
  141. package/types/Toast.d.ts.map +1 -1
  142. package/types/ToastAnnounce.d.ts +1 -1
  143. package/types/ToastAnnounce.d.ts.map +1 -1
  144. package/types/ToastComposable.d.ts +14 -14
  145. package/types/ToastComposable.d.ts.map +1 -1
  146. package/types/ToastImperative.d.ts +3 -3
  147. package/types/ToastImperative.d.ts.map +1 -1
  148. package/types/ToastImpl.d.ts +7 -7
  149. package/types/ToastImpl.d.ts.map +1 -1
  150. package/types/ToastItemFrame.d.ts +4 -4
  151. package/types/ToastItemFrame.d.ts.map +1 -1
  152. package/types/ToastPortal.d.ts +2 -2
  153. package/types/ToastPortal.d.ts.map +1 -1
  154. package/types/ToastProvider.d.ts +3 -3
  155. package/types/ToastProvider.d.ts.map +1 -1
  156. package/types/ToastState.d.ts +15 -12
  157. package/types/ToastState.d.ts.map +1 -1
  158. package/types/ToastViewport.d.ts +5 -5
  159. package/types/Toaster.d.ts +4 -4
  160. package/types/Toaster.d.ts.map +1 -1
  161. package/types/createNativeToast.d.ts +1 -1
  162. package/types/createNativeToast.d.ts.map +1 -1
  163. package/types/createNativeToast.native.d.ts +1 -1
  164. package/types/createNativeToast.native.d.ts.map +1 -1
  165. package/types/dispatchNativeToast.d.ts +2 -2
  166. package/types/dispatchNativeToast.d.ts.map +1 -1
  167. package/types/index.d.ts +3 -3
  168. package/types/index.d.ts.map +1 -1
  169. package/types/useAnimatedDragGesture.d.ts +1 -1
  170. package/types/useAnimatedDragGesture.d.ts.map +1 -1
  171. package/types/useAnimatedDragGesture.native.d.ts +1 -1
  172. package/types/useAnimatedDragGesture.native.d.ts.map +1 -1
  173. package/types/v2.d.ts +9 -9
  174. package/types/v2.d.ts.map +1 -1
  175. package/dist/cjs/Toast.cjs +0 -178
  176. package/dist/cjs/Toast.native.js +0 -181
  177. package/dist/cjs/Toast.native.js.map +0 -1
  178. package/dist/cjs/ToastAnnounce.cjs +0 -103
  179. package/dist/cjs/ToastAnnounce.native.js +0 -111
  180. package/dist/cjs/ToastAnnounce.native.js.map +0 -1
  181. package/dist/cjs/ToastComposable.cjs +0 -947
  182. package/dist/cjs/ToastComposable.native.js +0 -1055
  183. package/dist/cjs/ToastComposable.native.js.map +0 -1
  184. package/dist/cjs/ToastImperative.cjs +0 -119
  185. package/dist/cjs/ToastImperative.native.js +0 -130
  186. package/dist/cjs/ToastImperative.native.js.map +0 -1
  187. package/dist/cjs/ToastImpl.cjs +0 -354
  188. package/dist/cjs/ToastImpl.native.js +0 -364
  189. package/dist/cjs/ToastImpl.native.js.map +0 -1
  190. package/dist/cjs/ToastItemFrame.cjs +0 -143
  191. package/dist/cjs/ToastItemFrame.native.js +0 -148
  192. package/dist/cjs/ToastItemFrame.native.js.map +0 -1
  193. package/dist/cjs/ToastPortal.cjs +0 -49
  194. package/dist/cjs/ToastPortal.native.js +0 -52
  195. package/dist/cjs/ToastPortal.native.js.map +0 -1
  196. package/dist/cjs/ToastProvider.cjs +0 -150
  197. package/dist/cjs/ToastProvider.native.js +0 -161
  198. package/dist/cjs/ToastProvider.native.js.map +0 -1
  199. package/dist/cjs/ToastState.cjs +0 -311
  200. package/dist/cjs/ToastState.native.js +0 -324
  201. package/dist/cjs/ToastState.native.js.map +0 -1
  202. package/dist/cjs/ToastViewport.cjs +0 -319
  203. package/dist/cjs/ToastViewport.native.js +0 -343
  204. package/dist/cjs/ToastViewport.native.js.map +0 -1
  205. package/dist/cjs/Toaster.cjs +0 -87
  206. package/dist/cjs/Toaster.native.js +0 -91
  207. package/dist/cjs/Toaster.native.js.map +0 -1
  208. package/dist/cjs/constants.cjs +0 -30
  209. package/dist/cjs/constants.native.js +0 -33
  210. package/dist/cjs/constants.native.js.map +0 -1
  211. package/dist/cjs/createNativeToast.cjs +0 -59
  212. package/dist/cjs/createNativeToast.native.js +0 -60
  213. package/dist/cjs/createNativeToast.native.js.map +0 -1
  214. package/dist/cjs/dispatchNativeToast.cjs +0 -47
  215. package/dist/cjs/dispatchNativeToast.native.js +0 -52
  216. package/dist/cjs/dispatchNativeToast.native.js.map +0 -1
  217. package/dist/cjs/index.cjs +0 -20
  218. package/dist/cjs/index.native.js +0 -23
  219. package/dist/cjs/index.native.js.map +0 -1
  220. package/dist/cjs/types.cjs +0 -18
  221. package/dist/cjs/types.native.js +0 -21
  222. package/dist/cjs/types.native.js.map +0 -1
  223. package/dist/cjs/useAnimatedDragGesture.cjs +0 -214
  224. package/dist/cjs/useAnimatedDragGesture.native.js +0 -224
  225. package/dist/cjs/useAnimatedDragGesture.native.js.map +0 -1
  226. package/dist/cjs/useReducedMotion.cjs +0 -74
  227. package/dist/cjs/useReducedMotion.native.js +0 -83
  228. package/dist/cjs/useReducedMotion.native.js.map +0 -1
  229. package/dist/cjs/useToastAnimations.cjs +0 -292
  230. package/dist/cjs/useToastAnimations.native.js +0 -302
  231. package/dist/cjs/useToastAnimations.native.js.map +0 -1
  232. package/dist/cjs/v2.cjs +0 -36
  233. package/dist/cjs/v2.native.js +0 -39
  234. package/dist/cjs/v2.native.js.map +0 -1
  235. package/dist/esm/Toast.mjs +0 -137
  236. package/dist/esm/Toast.mjs.map +0 -1
  237. package/dist/esm/Toast.native.js +0 -137
  238. package/dist/esm/Toast.native.js.map +0 -1
  239. package/dist/esm/ToastAnnounce.mjs +0 -66
  240. package/dist/esm/ToastAnnounce.mjs.map +0 -1
  241. package/dist/esm/ToastAnnounce.native.js +0 -71
  242. package/dist/esm/ToastAnnounce.native.js.map +0 -1
  243. package/dist/esm/ToastComposable.mjs +0 -909
  244. package/dist/esm/ToastComposable.mjs.map +0 -1
  245. package/dist/esm/ToastComposable.native.js +0 -1014
  246. package/dist/esm/ToastComposable.native.js.map +0 -1
  247. package/dist/esm/ToastImperative.mjs +0 -80
  248. package/dist/esm/ToastImperative.mjs.map +0 -1
  249. package/dist/esm/ToastImperative.native.js +0 -88
  250. package/dist/esm/ToastImperative.native.js.map +0 -1
  251. package/dist/esm/ToastImpl.mjs +0 -316
  252. package/dist/esm/ToastImpl.mjs.map +0 -1
  253. package/dist/esm/ToastImpl.native.js +0 -329
  254. package/dist/esm/ToastImpl.native.js.map +0 -1
  255. package/dist/esm/ToastItemFrame.mjs +0 -114
  256. package/dist/esm/ToastItemFrame.mjs.map +0 -1
  257. package/dist/esm/ToastItemFrame.native.js +0 -116
  258. package/dist/esm/ToastItemFrame.native.js.map +0 -1
  259. package/dist/esm/ToastPortal.mjs +0 -24
  260. package/dist/esm/ToastPortal.mjs.map +0 -1
  261. package/dist/esm/ToastPortal.native.js +0 -24
  262. package/dist/esm/ToastPortal.native.js.map +0 -1
  263. package/dist/esm/ToastProvider.mjs +0 -110
  264. package/dist/esm/ToastProvider.mjs.map +0 -1
  265. package/dist/esm/ToastProvider.native.js +0 -118
  266. package/dist/esm/ToastProvider.native.js.map +0 -1
  267. package/dist/esm/ToastState.mjs +0 -285
  268. package/dist/esm/ToastState.mjs.map +0 -1
  269. package/dist/esm/ToastState.native.js +0 -295
  270. package/dist/esm/ToastState.native.js.map +0 -1
  271. package/dist/esm/ToastViewport.mjs +0 -280
  272. package/dist/esm/ToastViewport.mjs.map +0 -1
  273. package/dist/esm/ToastViewport.native.js +0 -301
  274. package/dist/esm/ToastViewport.native.js.map +0 -1
  275. package/dist/esm/Toaster.mjs +0 -51
  276. package/dist/esm/Toaster.mjs.map +0 -1
  277. package/dist/esm/Toaster.native.js +0 -52
  278. package/dist/esm/Toaster.native.js.map +0 -1
  279. package/dist/esm/constants.mjs +0 -4
  280. package/dist/esm/constants.mjs.map +0 -1
  281. package/dist/esm/constants.native.js +0 -4
  282. package/dist/esm/constants.native.js.map +0 -1
  283. package/dist/esm/createNativeToast.mjs +0 -32
  284. package/dist/esm/createNativeToast.mjs.map +0 -1
  285. package/dist/esm/createNativeToast.native.js +0 -30
  286. package/dist/esm/createNativeToast.native.js.map +0 -1
  287. package/dist/esm/dispatchNativeToast.mjs +0 -22
  288. package/dist/esm/dispatchNativeToast.mjs.map +0 -1
  289. package/dist/esm/dispatchNativeToast.native.js +0 -24
  290. package/dist/esm/dispatchNativeToast.native.js.map +0 -1
  291. package/dist/esm/index.mjs +0 -2
  292. package/dist/esm/index.mjs.map +0 -1
  293. package/dist/esm/index.native.js +0 -2
  294. package/dist/esm/index.native.js.map +0 -1
  295. package/dist/esm/types.mjs +0 -2
  296. package/dist/esm/types.mjs.map +0 -1
  297. package/dist/esm/types.native.js +0 -2
  298. package/dist/esm/types.native.js.map +0 -1
  299. package/dist/esm/useAnimatedDragGesture.mjs +0 -178
  300. package/dist/esm/useAnimatedDragGesture.mjs.map +0 -1
  301. package/dist/esm/useAnimatedDragGesture.native.js +0 -185
  302. package/dist/esm/useAnimatedDragGesture.native.js.map +0 -1
  303. package/dist/esm/useReducedMotion.mjs +0 -38
  304. package/dist/esm/useReducedMotion.mjs.map +0 -1
  305. package/dist/esm/useReducedMotion.native.js +0 -44
  306. package/dist/esm/useReducedMotion.native.js.map +0 -1
  307. package/dist/esm/useToastAnimations.mjs +0 -256
  308. package/dist/esm/useToastAnimations.mjs.map +0 -1
  309. package/dist/esm/useToastAnimations.native.js +0 -263
  310. package/dist/esm/useToastAnimations.native.js.map +0 -1
  311. package/dist/esm/v2.mjs +0 -6
  312. package/dist/esm/v2.mjs.map +0 -1
  313. package/dist/esm/v2.native.js +0 -6
  314. package/dist/esm/v2.native.js.map +0 -1
  315. package/dist/jsx/Toast.mjs +0 -137
  316. package/dist/jsx/Toast.mjs.map +0 -1
  317. package/dist/jsx/Toast.native.js +0 -181
  318. package/dist/jsx/Toast.native.js.map +0 -1
  319. package/dist/jsx/ToastAnnounce.mjs +0 -66
  320. package/dist/jsx/ToastAnnounce.mjs.map +0 -1
  321. package/dist/jsx/ToastAnnounce.native.js +0 -111
  322. package/dist/jsx/ToastAnnounce.native.js.map +0 -1
  323. package/dist/jsx/ToastComposable.mjs +0 -909
  324. package/dist/jsx/ToastComposable.mjs.map +0 -1
  325. package/dist/jsx/ToastComposable.native.js +0 -1055
  326. package/dist/jsx/ToastComposable.native.js.map +0 -1
  327. package/dist/jsx/ToastImperative.mjs +0 -80
  328. package/dist/jsx/ToastImperative.mjs.map +0 -1
  329. package/dist/jsx/ToastImperative.native.js +0 -130
  330. package/dist/jsx/ToastImperative.native.js.map +0 -1
  331. package/dist/jsx/ToastImpl.mjs +0 -316
  332. package/dist/jsx/ToastImpl.mjs.map +0 -1
  333. package/dist/jsx/ToastImpl.native.js +0 -364
  334. package/dist/jsx/ToastImpl.native.js.map +0 -1
  335. package/dist/jsx/ToastItemFrame.mjs +0 -114
  336. package/dist/jsx/ToastItemFrame.mjs.map +0 -1
  337. package/dist/jsx/ToastItemFrame.native.js +0 -148
  338. package/dist/jsx/ToastItemFrame.native.js.map +0 -1
  339. package/dist/jsx/ToastPortal.mjs +0 -24
  340. package/dist/jsx/ToastPortal.mjs.map +0 -1
  341. package/dist/jsx/ToastPortal.native.js +0 -52
  342. package/dist/jsx/ToastPortal.native.js.map +0 -1
  343. package/dist/jsx/ToastProvider.mjs +0 -110
  344. package/dist/jsx/ToastProvider.mjs.map +0 -1
  345. package/dist/jsx/ToastProvider.native.js +0 -161
  346. package/dist/jsx/ToastProvider.native.js.map +0 -1
  347. package/dist/jsx/ToastState.mjs +0 -285
  348. package/dist/jsx/ToastState.mjs.map +0 -1
  349. package/dist/jsx/ToastState.native.js +0 -324
  350. package/dist/jsx/ToastState.native.js.map +0 -1
  351. package/dist/jsx/ToastViewport.mjs +0 -280
  352. package/dist/jsx/ToastViewport.mjs.map +0 -1
  353. package/dist/jsx/ToastViewport.native.js +0 -343
  354. package/dist/jsx/ToastViewport.native.js.map +0 -1
  355. package/dist/jsx/Toaster.mjs +0 -51
  356. package/dist/jsx/Toaster.mjs.map +0 -1
  357. package/dist/jsx/Toaster.native.js +0 -91
  358. package/dist/jsx/Toaster.native.js.map +0 -1
  359. package/dist/jsx/constants.mjs +0 -4
  360. package/dist/jsx/constants.mjs.map +0 -1
  361. package/dist/jsx/constants.native.js +0 -33
  362. package/dist/jsx/constants.native.js.map +0 -1
  363. package/dist/jsx/createNativeToast.mjs +0 -32
  364. package/dist/jsx/createNativeToast.mjs.map +0 -1
  365. package/dist/jsx/createNativeToast.native.js +0 -60
  366. package/dist/jsx/createNativeToast.native.js.map +0 -1
  367. package/dist/jsx/dispatchNativeToast.mjs +0 -22
  368. package/dist/jsx/dispatchNativeToast.mjs.map +0 -1
  369. package/dist/jsx/dispatchNativeToast.native.js +0 -52
  370. package/dist/jsx/dispatchNativeToast.native.js.map +0 -1
  371. package/dist/jsx/index.js +0 -2
  372. package/dist/jsx/index.js.map +0 -1
  373. package/dist/jsx/index.mjs +0 -2
  374. package/dist/jsx/index.mjs.map +0 -1
  375. package/dist/jsx/index.native.js +0 -23
  376. package/dist/jsx/index.native.js.map +0 -1
  377. package/dist/jsx/types.mjs +0 -2
  378. package/dist/jsx/types.mjs.map +0 -1
  379. package/dist/jsx/types.native.js +0 -21
  380. package/dist/jsx/types.native.js.map +0 -1
  381. package/dist/jsx/useAnimatedDragGesture.mjs +0 -178
  382. package/dist/jsx/useAnimatedDragGesture.mjs.map +0 -1
  383. package/dist/jsx/useAnimatedDragGesture.native.js +0 -224
  384. package/dist/jsx/useAnimatedDragGesture.native.js.map +0 -1
  385. package/dist/jsx/useReducedMotion.mjs +0 -38
  386. package/dist/jsx/useReducedMotion.mjs.map +0 -1
  387. package/dist/jsx/useReducedMotion.native.js +0 -83
  388. package/dist/jsx/useReducedMotion.native.js.map +0 -1
  389. package/dist/jsx/useToastAnimations.mjs +0 -256
  390. package/dist/jsx/useToastAnimations.mjs.map +0 -1
  391. package/dist/jsx/useToastAnimations.native.js +0 -302
  392. package/dist/jsx/useToastAnimations.native.js.map +0 -1
  393. package/dist/jsx/v2.mjs +0 -6
  394. package/dist/jsx/v2.mjs.map +0 -1
  395. package/dist/jsx/v2.native.js +0 -39
  396. package/dist/jsx/v2.native.js.map +0 -1
  397. package/v2/index.cjs +0 -2
  398. package/v2/index.js +0 -2
  399. package/v2/index.native.cjs +0 -2
  400. package/v2/index.native.js +0 -2
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createCollection } from '@hanzogui/collection';
3
+ import { createStyledContext } from '@hanzogui/core';
4
+ import { startTransition } from '@hanzogui/start-transition';
5
+ import * as React from 'react';
6
+ import { TOAST_CONTEXT } from './constants.js';
7
+ import { ToastImperativeProvider } from './ToastImperative.js';
8
+ /* -------------------------------------------------------------------------------------------------
9
+ * ToastProvider
10
+ * -----------------------------------------------------------------------------------------------*/
11
+ const PROVIDER_NAME = 'ToastProvider';
12
+ const [Collection, useCollection] = createCollection('Toast');
13
+ const { Provider: ToastProviderProvider, useStyledContext: useToastProviderContext } = createStyledContext(
14
+ // since we always provide this we can avoid setting here
15
+ {}, 'Toast__');
16
+ const ToastProvider = (props) => {
17
+ const { scope = TOAST_CONTEXT, id: providedId, burntOptions, native, notificationOptions, label = 'Notification', duration = 5000, swipeDirection = 'right', swipeThreshold = 50, children, } = props;
18
+ const backupId = React.useId();
19
+ const id = providedId ?? backupId;
20
+ const [viewports, setViewports] = React.useState({});
21
+ const [toastCount, setToastCount] = React.useState(0);
22
+ const isFocusedToastEscapeKeyDownRef = React.useRef(false);
23
+ const isClosePausedRef = React.useRef(false);
24
+ const handleViewportChange = React.useCallback((name, viewport) => {
25
+ startTransition(() => {
26
+ setViewports((prev) => ({ ...prev, [name]: viewport }));
27
+ });
28
+ }, []);
29
+ // memo context to avoid expensive re-renders
30
+ const options = React.useMemo(() => {
31
+ return {
32
+ duration,
33
+ burntOptions,
34
+ native,
35
+ notificationOptions,
36
+ };
37
+ // nested simple object so JSON.stringify
38
+ }, [JSON.stringify([duration, burntOptions, native, notificationOptions])]);
39
+ return (_jsx(Collection.Provider, { scope: scope, children: _jsx(ToastProviderProvider, { scope: scope, id: id, label: label, duration: duration, swipeDirection: swipeDirection, swipeThreshold: swipeThreshold, toastCount: toastCount, viewports: viewports, onViewportChange: handleViewportChange, onToastAdd: React.useCallback(() => {
40
+ startTransition(() => {
41
+ setToastCount((prevCount) => prevCount + 1);
42
+ });
43
+ }, []), onToastRemove: React.useCallback(() => {
44
+ startTransition(() => {
45
+ setToastCount((prevCount) => prevCount - 1);
46
+ });
47
+ }, []), isFocusedToastEscapeKeyDownRef: isFocusedToastEscapeKeyDownRef, isClosePausedRef: isClosePausedRef, options: options, children: _jsx(ToastImperativeProvider, { options: options, children: children }) }) }));
48
+ };
49
+ export function ReprogapateToastProvider(props) {
50
+ const { children, context } = props;
51
+ return (_jsx(Collection.Provider, { scope: context.toastScope, children: _jsx(ToastProviderProvider, { ...context, children: _jsx(ToastImperativeProvider, { options: context.options, children: children }) }) }));
52
+ }
53
+ ToastProvider.propTypes = {
54
+ label(props) {
55
+ if (props.label && typeof props.label === 'string' && !props.label.trim()) {
56
+ const error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
57
+ return new Error(error);
58
+ }
59
+ return null;
60
+ },
61
+ };
62
+ ToastProvider.displayName = PROVIDER_NAME;
63
+ export { Collection, ToastProvider, useCollection, useToastProviderContext };
64
+ //# sourceMappingURL=ToastProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastProvider.js","sourceRoot":"","sources":["../../src/ToastProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAuB,CAAA;AAG/D;;oGAEoG;AAEpG,MAAM,aAAa,GAAG,eAAe,CAAA;AAErC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,gBAAgB,CAAa,OAAO,CAAC,CAAA;AAgCzE,MAAM,EAAE,QAAQ,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,GAClF,mBAAmB;AACjB,yDAAyD;AACzD,EAA+B,EAC/B,SAAS,CACV,CAAA;AA4CH,MAAM,aAAa,GAAiC,CAClD,KAAsC,EACtC,EAAE;IACF,MAAM,EACJ,KAAK,GAAG,aAAa,EACrB,EAAE,EAAE,UAAU,EACd,YAAY,EACZ,MAAM,EACN,mBAAmB,EACnB,KAAK,GAAG,cAAc,EACtB,QAAQ,GAAG,IAAI,EACf,cAAc,GAAG,OAAO,EACxB,cAAc,GAAG,EAAE,EACnB,QAAQ,GACT,GAAG,KAAK,CAAA;IACT,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,EAAE,CAAA;IAC9B,MAAM,EAAE,GAAG,UAAU,IAAI,QAAQ,CAAA;IACjC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAE9C,EAAE,CAAC,CAAA;IACL,MAAM,CAAC,UA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AAEzC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAA"}
@@ -0,0 +1,281 @@
1
+ // counter for generating unique toast ids
2
+ let toastsCounter = 1;
3
+ /**
4
+ * Observer class that manages toast state globally.
5
+ * Follows the pattern from Sonner for a clean, decoupled architecture.
6
+ */
7
+ class Observer {
8
+ constructor() {
9
+ this.subscribers = [];
10
+ this.toasts = [];
11
+ this.dismissedToasts = new Set();
12
+ /**
13
+ * Subscribe to toast state changes.
14
+ * Returns an unsubscribe function.
15
+ */
16
+ this.subscribe = (subscriber) => {
17
+ this.subscribers.push(subscriber);
18
+ return () => {
19
+ const index = this.subscribers.indexOf(subscriber);
20
+ if (index > -1) {
21
+ this.subscribers.splice(index, 1);
22
+ }
23
+ };
24
+ };
25
+ /**
26
+ * Publish a toast to all subscribers
27
+ */
28
+ this.publish = (data) => {
29
+ this.subscribers.forEach((subscriber) => subscriber(data));
30
+ };
31
+ /**
32
+ * Add a new toast to the internal array and publish to subscribers
33
+ */
34
+ this.addToast = (data) => {
35
+ this.publish(data);
36
+ this.toasts = [...this.toasts, data];
37
+ };
38
+ /**
39
+ * Create or update a toast
40
+ */
41
+ this.create = (data) => {
42
+ const { title, ...rest } = data;
43
+ const id = typeof data?.id === 'number' || (typeof data?.id === 'string' && data.id.length > 0)
44
+ ? data.id
45
+ : toastsCounter++;
46
+ const alreadyExists = this.toasts.find((toast) => toast.id === id);
47
+ const dismissible = data.dismissible ?? true;
48
+ // if this toast was previously dismissed, clear that
49
+ if (this.dismissedToasts.has(id)) {
50
+ this.dismissedToasts.delete(id);
51
+ }
52
+ if (alreadyExists) {
53
+ // update existing toast
54
+ this.toasts = this.toasts.map((toast) => {
55
+ if (toast.id === id) {
56
+ this.publish({ ...toast, ...data, id, title, dismissible });
57
+ return { ...toast, ...data, id, title, dismissible };
58
+ }
59
+ return toast;
60
+ });
61
+ }
62
+ else {
63
+ this.addToast({ title, ...rest, dismissible, id });
64
+ }
65
+ return id;
66
+ };
67
+ /**
68
+ * Dismiss a toast by id, or all toasts if no id provided
69
+ */
70
+ this.dismiss = (id) => {
71
+ if (id !== undefined) {
72
+ this.dismissedToasts.add(id);
73
+ // use requestAnimationFrame to batch updates
74
+ requestAnimationFrame(() => {
75
+ this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }));
76
+ });
77
+ }
78
+ else {
79
+ // dismiss all
80
+ this.toasts.forEach((toast) => {
81
+ this.subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true }));
82
+ });
83
+ }
84
+ return id;
85
+ };
86
+ /**
87
+ * Show a basic toast message
88
+ */
89
+ this.message = (title, data) => {
90
+ return this.create({ ...data, title, type: 'default' });
91
+ };
92
+ /**
93
+ * Show a success toast
94
+ */
95
+ this.success = (title, data) => {
96
+ return this.create({ ...data, title, type: 'success' });
97
+ };
98
+ /**
99
+ * Show an error toast
100
+ */
101
+ this.error = (title, data) => {
102
+ return this.create({ ...data, title, type: 'error' });
103
+ };
104
+ /**
105
+ * Show a warning toast
106
+ */
107
+ this.warning = (title, data) => {
108
+ return this.create({ ...data, title, type: 'warning' });
109
+ };
110
+ /**
111
+ * Show an info toast
112
+ */
113
+ this.info = (title, data) => {
114
+ return this.create({ ...data, title, type: 'info' });
115
+ };
116
+ /**
117
+ * Show a loading toast
118
+ */
119
+ this.loading = (title, data) => {
120
+ return this.create({ ...data, title, type: 'loading' });
121
+ };
122
+ /**
123
+ * Show a toast for a promise, automatically transitioning through
124
+ * loading -> success/error states
125
+ */
126
+ this.promise = (promise, data) => {
127
+ if (!data) {
128
+ return;
129
+ }
130
+ let id = undefined;
131
+ // show loading state if provided
132
+ if (data.loading !== undefined) {
133
+ id = this.create({
134
+ promise,
135
+ type: 'loading',
136
+ title: data.loading,
137
+ description: typeof data.description !== 'function' ? data.description : undefined,
138
+ // loading toasts shouldn't auto-dismiss
139
+ duration: Number.POSITIVE_INFINITY,
140
+ });
141
+ }
142
+ const p = Promise.resolve(promise instanceof Function ? promise() : promise);
143
+ let shouldDismiss = id !== undefined;
144
+ let result;
145
+ const originalPromise = p
146
+ .then(async (response) => {
147
+ result = ['resolve', response];
148
+ // check if response is an HTTP error
149
+ if (isHttpResponse(response) && !response.ok) {
150
+ shouldDismiss = false;
151
+ const errorMsg = typeof data.error === 'function'
152
+ ? await data.error(`HTTP error! status: ${response.status}`)
153
+ : data.error;
154
+ const description = typeof data.description === 'function'
155
+ ? await data.description(`HTTP error! status: ${response.status}`)
156
+ : data.description;
157
+ this.create({ id, type: 'error', title: errorMsg, description });
158
+ }
159
+ else if (data.success !== undefined) {
160
+ shouldDismiss = false;
161
+ const successMsg = typeof data.success === 'function'
162
+ ? await data.success(response)
163
+ : data.success;
164
+ const description = typeof data.description === 'function'
165
+ ? await data.description(response)
166
+ : data.description;
167
+ this.create({ id, type: 'success', title: successMsg, description });
168
+ }
169
+ })
170
+ .catch(async (error) => {
171
+ result = ['reject', error];
172
+ if (data.error !== undefined) {
173
+ shouldDismiss = false;
174
+ const errorMsg = typeof data.error === 'function' ? await data.error(error) : data.error;
175
+ const description = typeof data.description === 'function'
176
+ ? await data.description(error)
177
+ : data.description;
178
+ this.create({ id, type: 'error', title: errorMsg, description });
179
+ }
180
+ })
181
+ .finally(() => {
182
+ if (shouldDismiss) {
183
+ // toast is still in load state, dismiss it
184
+ this.dismiss(id);
185
+ id = undefined;
186
+ }
187
+ data.finally?.();
188
+ });
189
+ // return a promise that can be unwrapped
190
+ const unwrap = () => new Promise((resolve, reject) => originalPromise
191
+ .then(() => (result[0] === 'reject' ? reject(result[1]) : resolve(result[1])))
192
+ .catch(reject));
193
+ if (typeof id !== 'string' && typeof id !== 'number') {
194
+ return { unwrap };
195
+ }
196
+ else {
197
+ return Object.assign(id, { unwrap });
198
+ }
199
+ };
200
+ /**
201
+ * Show a custom JSX toast
202
+ */
203
+ this.custom = (jsx, data) => {
204
+ const id = data?.id ?? toastsCounter++;
205
+ this.create({ jsx: jsx(id), ...data, id });
206
+ return id;
207
+ };
208
+ /**
209
+ * Get all active (non-dismissed) toasts
210
+ */
211
+ this.getActiveToasts = () => {
212
+ return this.toasts.filter((toast) => !this.dismissedToasts.has(toast.id));
213
+ };
214
+ /**
215
+ * Get full toast history
216
+ */
217
+ this.getHistory = () => {
218
+ return this.toasts;
219
+ };
220
+ }
221
+ }
222
+ function isHttpResponse(data) {
223
+ return (data &&
224
+ typeof data === 'object' &&
225
+ 'ok' in data &&
226
+ typeof data.ok === 'boolean' &&
227
+ 'status' in data &&
228
+ typeof data.status === 'number');
229
+ }
230
+ // singleton instance
231
+ export const ToastState = new Observer();
232
+ // basic toast function
233
+ const toastFunction = (title, data) => {
234
+ return ToastState.create({ ...data, title });
235
+ };
236
+ // getters
237
+ const getHistory = () => ToastState.getHistory();
238
+ const getToasts = () => ToastState.getActiveToasts();
239
+ /**
240
+ * Main toast API - call directly or use methods like toast.success()
241
+ *
242
+ * @example
243
+ * // basic usage
244
+ * toast('Hello world')
245
+ *
246
+ * // with type
247
+ * toast.success('Saved!')
248
+ * toast.error('Something went wrong')
249
+ *
250
+ * // with options
251
+ * toast('Hello', { duration: 5000 })
252
+ *
253
+ * // promise toast
254
+ * toast.promise(fetch('/api'), {
255
+ * loading: 'Loading...',
256
+ * success: 'Done!',
257
+ * error: 'Failed'
258
+ * })
259
+ *
260
+ * // custom JSX
261
+ * toast.custom((id) => <MyToast id={id} />)
262
+ *
263
+ * // dismiss
264
+ * const id = toast('Hello')
265
+ * toast.dismiss(id)
266
+ * toast.dismiss() // dismiss all
267
+ */
268
+ export const toast = Object.assign(toastFunction, {
269
+ success: ToastState.success,
270
+ error: ToastState.error,
271
+ warning: ToastState.warning,
272
+ info: ToastState.info,
273
+ loading: ToastState.loading,
274
+ promise: ToastState.promise,
275
+ custom: ToastState.custom,
276
+ dismiss: ToastState.dismiss,
277
+ message: ToastState.message,
278
+ getHistory,
279
+ getToasts,
280
+ });
281
+ //# sourceMappingURL=ToastState.js.map
@@ -0,0 +1 @@
1
+ {"version":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OAAO,CACL,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;QACxB,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,CAAC,EAAE,KAAK,SAAS;QAC5B,QAAQ,IAAI,IAAI;QAChB,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAChC,CAAA;AACH,CAAC;AAED,qBAAqB;AACrB,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AAExC,uBAAuB;AACvB,MAAM,aAAa,GAAG,CAAC,KAAa,EAAE,IAAoB,EAAE,EAAE;IAC5D,OAAO,UAAU,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,UAAU;AACV,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,UAAU,EAAE,CAAA;AAChD,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,eAAe,EAAE,CAAA;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE;IAChD,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,KAAK,EAAE,UAAU,CAAC,KAAK;IACvB,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,IAAI,EAAE,UAAU,CAAC,IAAI;IACrB,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,MAAM,EAAE,UAAU,CAAC,MAAM;IACzB,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,OAAO,EAAE,UAAU,CAAC,OAAO;IAC3B,UAAU;IACV,SAAS;CACV,CAAC,CAAA"}
@@ -0,0 +1,282 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AnimatePresence } from '@hanzogui/animate-presence';
3
+ import { useComposedRefs } from '@hanzogui/compose-refs';
4
+ import { isWeb } from '@hanzogui/constants';
5
+ import { styled } from '@hanzogui/core';
6
+ import { PortalHost } from '@hanzogui/portal';
7
+ import { YStack } from '@hanzogui/stacks';
8
+ import { VisuallyHidden } from '@hanzogui/visually-hidden';
9
+ import * as React from 'react';
10
+ import { TOAST_CONTEXT } from './constants.js';
11
+ import { ToastPortal } from './ToastPortal.js';
12
+ import { Collection, useCollection, useToastProviderContext } from './ToastProvider.js';
13
+ const VIEWPORT_NAME = 'ToastViewport';
14
+ const VIEWPORT_DEFAULT_HOTKEY = ['F8'];
15
+ const VIEWPORT_PAUSE = 'toast.viewportPause';
16
+ const VIEWPORT_RESUME = 'toast.viewportResume';
17
+ const ToastViewportWrapperFrame = styled(YStack, {
18
+ name: 'ViewportWrapper',
19
+ variants: {
20
+ unstyled: {
21
+ false: {
22
+ pointerEvents: 'box-none',
23
+ top: 0,
24
+ bottom: 0,
25
+ left: 0,
26
+ right: 0,
27
+ position: isWeb ? 'fixed' : 'absolute',
28
+ maxWidth: '100%',
29
+ tabIndex: 0,
30
+ zIndex: 100000,
31
+ },
32
+ },
33
+ },
34
+ defaultVariants: {
35
+ unstyled: process.env.GUI_HEADLESS === '1',
36
+ },
37
+ });
38
+ const ToastViewportFrame = styled(YStack, {
39
+ name: VIEWPORT_NAME,
40
+ variants: {
41
+ unstyled: {
42
+ false: {
43
+ pointerEvents: 'box-none',
44
+ position: isWeb ? 'fixed' : 'absolute',
45
+ maxWidth: '100%',
46
+ },
47
+ },
48
+ },
49
+ defaultVariants: {
50
+ unstyled: process.env.GUI_HEADLESS === '1',
51
+ },
52
+ });
53
+ const ToastViewport = React.memo(React.forwardRef((props, forwardedRef) => {
54
+ const { scope, hotkey = VIEWPORT_DEFAULT_HOTKEY, label = 'Notifications ({hotkey})', name = 'default', multipleToasts, zIndex, portalToRoot, ...viewportProps } = props;
55
+ const context = useToastProviderContext(scope);
56
+ const getItems = useCollection(scope || TOAST_CONTEXT);
57
+ const headFocusProxyRef = React.useRef(null);
58
+ const tailFocusProxyRef = React.useRef(null);
59
+ const wrapperRef = React.useRef(null);
60
+ const ref = React.useRef(null);
61
+ const onViewportChange = React.useCallback((el) => {
62
+ if (context.viewports[name] !== el)
63
+ context.onViewportChange(name, el);
64
+ }, [name, context.viewports]);
65
+ // @ts-ignore TODO react 19 type needs fix
66
+ const composedRefs = useComposedRefs(forwardedRef, ref, onViewportChange);
67
+ const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
68
+ const hasToasts = context.toastCount > 0;
69
+ React.useEffect(() => {
70
+ if (!isWeb)
71
+ return;
72
+ if (context.toastCount === 0)
73
+ return;
74
+ const handleKeyDown = (event) => {
75
+ // we use `event.code` as it is consistent regardless of meta keys that were pressed.
76
+ // for example, `event.key` for `Control+Alt+t` is `†` and `t !== †`
77
+ const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
78
+ if (isHotkeyPressed)
79
+ ref.current?.focus();
80
+ };
81
+ document.addEventListener('keydown', handleKeyDown);
82
+ return () => {
83
+ document.removeEventListener('keydown', handleKeyDown);
84
+ };
85
+ }, [hotkey, context.toastCount]);
86
+ React.useEffect(() => {
87
+ if (!isWeb)
88
+ return;
89
+ if (context.toastCount === 0)
90
+ return;
91
+ const wrapper = wrapperRef.current;
92
+ const viewport = ref.current;
93
+ if (hasToasts && wrapper && viewport) {
94
+ const handlePause = () => {
95
+ if (!context.isClosePausedRef.current) {
96
+ const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
97
+ viewport.dispatchEvent(pauseEvent);
98
+ context.isClosePausedRef.current = true;
99
+ }
100
+ };
101
+ const handleResume = () => {
102
+ if (context.isClosePausedRef.current) {
103
+ const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
104
+ viewport.dispatchEvent(resumeEvent);
105
+ context.isClosePausedRef.current = false;
106
+ }
107
+ };
108
+ const handleFocusOutResume = (event) => {
109
+ const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
110
+ if (isFocusMovingOutside)
111
+ handleResume();
112
+ };
113
+ const handlePointerLeaveResume = () => {
114
+ const isFocusInside = wrapper.contains(document.activeElement);
115
+ if (!isFocusInside)
116
+ handleResume();
117
+ };
118
+ // Toasts are not in the viewport React tree so we need to bind DOM events
119
+ wrapper.addEventListener('focusin', handlePause);
120
+ wrapper.addEventListener('focusout', handleFocusOutResume);
121
+ wrapper.addEventListener('pointermove', handlePause);
122
+ wrapper.addEventListener('pointerleave', handlePointerLeaveResume);
123
+ window.addEventListener('blur', handlePause);
124
+ window.addEventListener('focus', handleResume);
125
+ return () => {
126
+ wrapper.removeEventListener('focusin', handlePause);
127
+ wrapper.removeEventListener('focusout', handleFocusOutResume);
128
+ wrapper.removeEventListener('pointermove', handlePause);
129
+ wrapper.removeEventListener('pointerleave', handlePointerLeaveResume);
130
+ window.removeEventListener('blur', handlePause);
131
+ window.removeEventListener('focus', handleResume);
132
+ };
133
+ }
134
+ }, [hasToasts, context.isClosePausedRef, context.toastCount]);
135
+ const getSortedTabbableCandidates = React.useCallback(({ tabbingDirection }) => {
136
+ const toastItems = getItems();
137
+ const tabbableCandidates = toastItems.map((toastItem) => {
138
+ const toastNode = toastItem.ref.current;
139
+ const toastTabbableCandidates = [
140
+ toastNode,
141
+ ...getTabbableCandidates(toastNode),
142
+ ];
143
+ return tabbingDirection === 'forwards'
144
+ ? toastTabbableCandidates
145
+ : toastTabbableCandidates.reverse();
146
+ });
147
+ return (tabbingDirection === 'forwards'
148
+ ? tabbableCandidates.reverse()
149
+ : tabbableCandidates).flat();
150
+ }, [getItems]);
151
+ React.useEffect(() => {
152
+ if (!isWeb)
153
+ return;
154
+ if (context.toastCount === 0)
155
+ return;
156
+ const viewport = ref.current;
157
+ // We programmatically manage tabbing as we are unable to influence
158
+ // the source order with portals, this allows us to reverse the
159
+ // tab order so that it runs from most recent toast to least
160
+ if (viewport) {
161
+ const handleKeyDown = (event) => {
162
+ const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
163
+ const isTabKey = event.key === 'Tab' && !isMetaKey;
164
+ if (isTabKey) {
165
+ const focusedElement = document.activeElement;
166
+ const isTabbingBackwards = event.shiftKey;
167
+ const targetIsViewport = event.target === viewport;
168
+ // If we're back tabbing after jumping to the viewport then we simply
169
+ // proxy focus out to the preceding document
170
+ if (targetIsViewport && isTabbingBackwards) {
171
+ // @ts-ignore ali TODO type
172
+ headFocusProxyRef.current?.focus();
173
+ return;
174
+ }
175
+ const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards';
176
+ const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection });
177
+ const index = sortedCandidates.findIndex((candidate) => candidate === focusedElement);
178
+ if (focusFirst(sortedCandidates.slice(index + 1))) {
179
+ event.preventDefault();
180
+ }
181
+ else {
182
+ // If we can't focus that means we're at the edges so we
183
+ // proxy to the corresponding exit point and let the browser handle
184
+ // tab/shift+tab keypress and implicitly pass focus to the next valid element in the document
185
+ isTabbingBackwards
186
+ ? // @ts-ignore ali TODO type
187
+ headFocusProxyRef.current?.focus()
188
+ : // @ts-ignore ali TODO type
189
+ tailFocusProxyRef.current?.focus();
190
+ }
191
+ }
192
+ };
193
+ // Toasts are not in the viewport React tree so we need to bind DOM events
194
+ viewport.addEventListener('keydown', handleKeyDown);
195
+ return () => viewport.removeEventListener('keydown', handleKeyDown);
196
+ }
197
+ }, [getItems, getSortedTabbableCandidates, context.toastCount]);
198
+ const contents = (_jsxs(ToastViewportWrapperFrame, { ref: wrapperRef,
199
+ // biome-ignore lint/a11y/useSemanticElements: <explanation>
200
+ role: "region", "aria-label": label.replace('{hotkey}', hotkeyLabel),
201
+ // // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume
202
+ tabIndex: -1, children: [hasToasts && (_jsx(FocusProxy, { context: context, viewportName: name, ref: headFocusProxyRef, onFocusFromOutsideViewport: () => {
203
+ const tabbableCandidates = getSortedTabbableCandidates({
204
+ tabbingDirection: 'forwards',
205
+ });
206
+ focusFirst(tabbableCandidates);
207
+ } })), _jsx(Collection.Slot, { scope: context.toastScope, children: _jsx(ToastViewportFrame, { focusable: context.toastCount > 0, ref: composedRefs, ...viewportProps, children: _jsx(PortalHost, { render: (children) => (_jsx(AnimatePresence, { exitBeforeEnter: !multipleToasts, children: children })), name: name ?? 'default' }) }) }), hasToasts && (_jsx(FocusProxy, { context: context, viewportName: name, ref: tailFocusProxyRef, onFocusFromOutsideViewport: () => {
208
+ const tabbableCandidates = getSortedTabbableCandidates({
209
+ tabbingDirection: 'backwards',
210
+ });
211
+ focusFirst(tabbableCandidates);
212
+ } }))] }));
213
+ if (portalToRoot) {
214
+ return (_jsx(ToastPortal, { context: context, ...(typeof zIndex === 'number' ? { zIndex } : {}), children: contents }));
215
+ }
216
+ return contents;
217
+ }));
218
+ ToastViewport.displayName = VIEWPORT_NAME;
219
+ /* -----------------------------------------------------------------------------------------------*/
220
+ const FOCUS_PROXY_NAME = 'ToastFocusProxy';
221
+ const FocusProxy = React.forwardRef((props, forwardedRef) => {
222
+ const { onFocusFromOutsideViewport, viewportName, context, ...proxyProps } = props;
223
+ const viewport = context.viewports[viewportName];
224
+ return (_jsx(VisuallyHidden, { "aria-hidden": true, tabIndex: 0, ...proxyProps, ref: forwardedRef,
225
+ // Avoid page scrolling when focus is on the focus proxy
226
+ position: isWeb ? 'fixed' : 'absolute', onFocus: (event) => {
227
+ if (!isWeb)
228
+ return;
229
+ const prevFocusedElement = event.relatedTarget;
230
+ const isFocusFromOutsideViewport = !viewport?.contains(prevFocusedElement);
231
+ if (isFocusFromOutsideViewport)
232
+ onFocusFromOutsideViewport();
233
+ } }));
234
+ });
235
+ FocusProxy.displayName = FOCUS_PROXY_NAME;
236
+ /* -----------------------------------------------------------------------------------------------*/
237
+ function focusFirst(candidates) {
238
+ if (!isWeb)
239
+ return;
240
+ const previouslyFocusedElement = document.activeElement;
241
+ return candidates.some((candidate) => {
242
+ // if focus is already where we want to go, we don't want to keep going through the candidates
243
+ if (candidate === previouslyFocusedElement)
244
+ return true;
245
+ candidate.focus();
246
+ return document.activeElement !== previouslyFocusedElement;
247
+ });
248
+ }
249
+ /**
250
+ * Returns a list of potential tabbable candidates.
251
+ *
252
+ * NOTE: This is only a close approximation. For example it doesn't take into account cases like when
253
+ * elements are not visible. This cannot be worked out easily by just reading a property, but rather
254
+ * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
255
+ *
256
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
257
+ * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
258
+ */
259
+ function getTabbableCandidates(container) {
260
+ if (!isWeb)
261
+ return [];
262
+ const containerHtml = container;
263
+ const nodes = [];
264
+ const walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {
265
+ acceptNode: (node) => {
266
+ const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
267
+ if (node.disabled || node.hidden || isHiddenInput)
268
+ return NodeFilter.FILTER_SKIP;
269
+ // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
270
+ // runtime's understanding of tabbability, so this automatically accounts
271
+ // for any kind of element that could be tabbed to.
272
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
273
+ },
274
+ });
275
+ while (walker.nextNode())
276
+ nodes.push(walker.currentNode);
277
+ // we do not take into account the order of nodes with positive `tabIndex` as it
278
+ // hinders accessibility to have tab order different from visual order.
279
+ return nodes;
280
+ }
281
+ export { ToastViewport, VIEWPORT_DEFAULT_HOTKEY, VIEWPORT_PAUSE, VIEWPORT_RESUME, };
282
+ //# sourceMappingURL=ToastViewport.js.map