@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,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToastProviderContext = exports.useCollection = exports.ToastProvider = exports.Collection = void 0;
4
+ exports.ReprogapateToastProvider = ReprogapateToastProvider;
5
+ const tslib_1 = require("tslib");
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const collection_1 = require("@hanzogui/collection");
8
+ const core_1 = require("@hanzogui/core");
9
+ const start_transition_1 = require("@hanzogui/start-transition");
10
+ const React = tslib_1.__importStar(require("react"));
11
+ const constants_ts_1 = require("./constants.js");
12
+ const ToastImperative_tsx_1 = require("./ToastImperative.js");
13
+ /* -------------------------------------------------------------------------------------------------
14
+ * ToastProvider
15
+ * -----------------------------------------------------------------------------------------------*/
16
+ const PROVIDER_NAME = 'ToastProvider';
17
+ const [Collection, useCollection] = (0, collection_1.createCollection)('Toast');
18
+ exports.Collection = Collection;
19
+ exports.useCollection = useCollection;
20
+ const { Provider: ToastProviderProvider, useStyledContext: useToastProviderContext } = (0, core_1.createStyledContext)(
21
+ // since we always provide this we can avoid setting here
22
+ {}, 'Toast__');
23
+ exports.useToastProviderContext = useToastProviderContext;
24
+ const ToastProvider = (props) => {
25
+ const { scope = constants_ts_1.TOAST_CONTEXT, id: providedId, burntOptions, native, notificationOptions, label = 'Notification', duration = 5000, swipeDirection = 'right', swipeThreshold = 50, children, } = props;
26
+ const backupId = React.useId();
27
+ const id = providedId ?? backupId;
28
+ const [viewports, setViewports] = React.useState({});
29
+ const [toastCount, setToastCount] = React.useState(0);
30
+ const isFocusedToastEscapeKeyDownRef = React.useRef(false);
31
+ const isClosePausedRef = React.useRef(false);
32
+ const handleViewportChange = React.useCallback((name, viewport) => {
33
+ (0, start_transition_1.startTransition)(() => {
34
+ setViewports((prev) => ({ ...prev, [name]: viewport }));
35
+ });
36
+ }, []);
37
+ // memo context to avoid expensive re-renders
38
+ const options = React.useMemo(() => {
39
+ return {
40
+ duration,
41
+ burntOptions,
42
+ native,
43
+ notificationOptions,
44
+ };
45
+ // nested simple object so JSON.stringify
46
+ }, [JSON.stringify([duration, burntOptions, native, notificationOptions])]);
47
+ return ((0, jsx_runtime_1.jsx)(Collection.Provider, { scope: scope, children: (0, jsx_runtime_1.jsx)(ToastProviderProvider, { scope: scope, id: id, label: label, duration: duration, swipeDirection: swipeDirection, swipeThreshold: swipeThreshold, toastCount: toastCount, viewports: viewports, onViewportChange: handleViewportChange, onToastAdd: React.useCallback(() => {
48
+ (0, start_transition_1.startTransition)(() => {
49
+ setToastCount((prevCount) => prevCount + 1);
50
+ });
51
+ }, []), onToastRemove: React.useCallback(() => {
52
+ (0, start_transition_1.startTransition)(() => {
53
+ setToastCount((prevCount) => prevCount - 1);
54
+ });
55
+ }, []), isFocusedToastEscapeKeyDownRef: isFocusedToastEscapeKeyDownRef, isClosePausedRef: isClosePausedRef, options: options, children: (0, jsx_runtime_1.jsx)(ToastImperative_tsx_1.ToastImperativeProvider, { options: options, children: children }) }) }));
56
+ };
57
+ exports.ToastProvider = ToastProvider;
58
+ function ReprogapateToastProvider(props) {
59
+ const { children, context } = props;
60
+ return ((0, jsx_runtime_1.jsx)(Collection.Provider, { scope: context.toastScope, children: (0, jsx_runtime_1.jsx)(ToastProviderProvider, { ...context, children: (0, jsx_runtime_1.jsx)(ToastImperative_tsx_1.ToastImperativeProvider, { options: context.options, children: children }) }) }));
61
+ }
62
+ ToastProvider.propTypes = {
63
+ label(props) {
64
+ if (props.label && typeof props.label === 'string' && !props.label.trim()) {
65
+ const error = `Invalid prop \`label\` supplied to \`${PROVIDER_NAME}\`. Expected non-empty \`string\`.`;
66
+ return new Error(error);
67
+ }
68
+ return null;
69
+ },
70
+ };
71
+ ToastProvider.displayName = PROVIDER_NAME;
72
+ //# sourceMappingURL=ToastProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastProvider.js","sourceRoot":"","sources":["../../src/ToastProvider.tsx"],"names":[],"mappings":";;;;;;AAAA,qDAAuD;AAEvD,yCAAoD;AACpD,iEAA4D;AAC5D,MAAY,KAAK,0CAAa;AAE9B,iDAA8C;AAE9C,8DAA+D;AAG/D;;oGAEoG;AAEpG,MAAM,aAAa,GAAG,eAAe,CAAA;AAErC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,IAAA,6BAAgB,EAAa,OAAO,CAAC,CAAA;QAyLhE,UAAU;QAAiB,aAAa;AAzJjD,MAAM,EAAE,QAAQ,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,GAClF,IAAA,0BAAmB;AACjB,yDAAyD;AACzD,EAA+B,EAC/B,SAAS,CACV,CAAA;QAoJgD,uBAAuB;AAxG1E,MAAM,aAAa,GAAiC,CAClD,KAAsC,EACtC,EAAE;IACF,MAAM,EACJ,KAAK,GAAG,4BAAa,EACrB,EAAE,EAAE,UAAU,EACd,YAAY,EACZ,MAAM,EACN,mBAAmB,EACnB,KAAK,GAAG,cAAc,EACtB,QAAQ,GAAG,IAAI,EACf,cAAc,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K,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1E,MAAM,KAAK,GAAG,wCAAwC,aAAa,oCAAoC,CAAA;YACvG,OAAO,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF,CAAA;AAED,aAAa,CAAC,WAAW,GAAG,aAAa,CAAA"}
@@ -0,0 +1,284 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toast = exports.ToastState = void 0;
4
+ // counter for generating unique toast ids
5
+ let toastsCounter = 1;
6
+ /**
7
+ * Observer class that manages toast state globally.
8
+ * Follows the pattern from Sonner for a clean, decoupled architecture.
9
+ */
10
+ class Observer {
11
+ constructor() {
12
+ this.subscribers = [];
13
+ this.toasts = [];
14
+ this.dismissedToasts = new Set();
15
+ /**
16
+ * Subscribe to toast state changes.
17
+ * Returns an unsubscribe function.
18
+ */
19
+ this.subscribe = (subscriber) => {
20
+ this.subscribers.push(subscriber);
21
+ return () => {
22
+ const index = this.subscribers.indexOf(subscriber);
23
+ if (index > -1) {
24
+ this.subscribers.splice(index, 1);
25
+ }
26
+ };
27
+ };
28
+ /**
29
+ * Publish a toast to all subscribers
30
+ */
31
+ this.publish = (data) => {
32
+ this.subscribers.forEach((subscriber) => subscriber(data));
33
+ };
34
+ /**
35
+ * Add a new toast to the internal array and publish to subscribers
36
+ */
37
+ this.addToast = (data) => {
38
+ this.publish(data);
39
+ this.toasts = [...this.toasts, data];
40
+ };
41
+ /**
42
+ * Create or update a toast
43
+ */
44
+ this.create = (data) => {
45
+ const { title, ...rest } = data;
46
+ const id = typeof data?.id === 'number' || (typeof data?.id === 'string' && data.id.length > 0)
47
+ ? data.id
48
+ : toastsCounter++;
49
+ const alreadyExists = this.toasts.find((toast) => toast.id === id);
50
+ const dismissible = data.dismissible ?? true;
51
+ // if this toast was previously dismissed, clear that
52
+ if (this.dismissedToasts.has(id)) {
53
+ this.dismissedToasts.delete(id);
54
+ }
55
+ if (alreadyExists) {
56
+ // update existing toast
57
+ this.toasts = this.toasts.map((toast) => {
58
+ if (toast.id === id) {
59
+ this.publish({ ...toast, ...data, id, title, dismissible });
60
+ return { ...toast, ...data, id, title, dismissible };
61
+ }
62
+ return toast;
63
+ });
64
+ }
65
+ else {
66
+ this.addToast({ title, ...rest, dismissible, id });
67
+ }
68
+ return id;
69
+ };
70
+ /**
71
+ * Dismiss a toast by id, or all toasts if no id provided
72
+ */
73
+ this.dismiss = (id) => {
74
+ if (id !== undefined) {
75
+ this.dismissedToasts.add(id);
76
+ // use requestAnimationFrame to batch updates
77
+ requestAnimationFrame(() => {
78
+ this.subscribers.forEach((subscriber) => subscriber({ id, dismiss: true }));
79
+ });
80
+ }
81
+ else {
82
+ // dismiss all
83
+ this.toasts.forEach((toast) => {
84
+ this.subscribers.forEach((subscriber) => subscriber({ id: toast.id, dismiss: true }));
85
+ });
86
+ }
87
+ return id;
88
+ };
89
+ /**
90
+ * Show a basic toast message
91
+ */
92
+ this.message = (title, data) => {
93
+ return this.create({ ...data, title, type: 'default' });
94
+ };
95
+ /**
96
+ * Show a success toast
97
+ */
98
+ this.success = (title, data) => {
99
+ return this.create({ ...data, title, type: 'success' });
100
+ };
101
+ /**
102
+ * Show an error toast
103
+ */
104
+ this.error = (title, data) => {
105
+ return this.create({ ...data, title, type: 'error' });
106
+ };
107
+ /**
108
+ * Show a warning toast
109
+ */
110
+ this.warning = (title, data) => {
111
+ return this.create({ ...data, title, type: 'warning' });
112
+ };
113
+ /**
114
+ * Show an info toast
115
+ */
116
+ this.info = (title, data) => {
117
+ return this.create({ ...data, title, type: 'info' });
118
+ };
119
+ /**
120
+ * Show a loading toast
121
+ */
122
+ this.loading = (title, data) => {
123
+ return this.create({ ...data, title, type: 'loading' });
124
+ };
125
+ /**
126
+ * Show a toast for a promise, automatically transitioning through
127
+ * loading -> success/error states
128
+ */
129
+ this.promise = (promise, data) => {
130
+ if (!data) {
131
+ return;
132
+ }
133
+ let id = undefined;
134
+ // show loading state if provided
135
+ if (data.loading !== undefined) {
136
+ id = this.create({
137
+ promise,
138
+ type: 'loading',
139
+ title: data.loading,
140
+ description: typeof data.description !== 'function' ? data.description : undefined,
141
+ // loading toasts shouldn't auto-dismiss
142
+ duration: Number.POSITIVE_INFINITY,
143
+ });
144
+ }
145
+ const p = Promise.resolve(promise instanceof Function ? promise() : promise);
146
+ let shouldDismiss = id !== undefined;
147
+ let result;
148
+ const originalPromise = p
149
+ .then(async (response) => {
150
+ result = ['resolve', response];
151
+ // check if response is an HTTP error
152
+ if (isHttpResponse(response) && !response.ok) {
153
+ shouldDismiss = false;
154
+ const errorMsg = typeof data.error === 'function'
155
+ ? await data.error(`HTTP error! status: ${response.status}`)
156
+ : data.error;
157
+ const description = typeof data.description === 'function'
158
+ ? await data.description(`HTTP error! status: ${response.status}`)
159
+ : data.description;
160
+ this.create({ id, type: 'error', title: errorMsg, description });
161
+ }
162
+ else if (data.success !== undefined) {
163
+ shouldDismiss = false;
164
+ const successMsg = typeof data.success === 'function'
165
+ ? await data.success(response)
166
+ : data.success;
167
+ const description = typeof data.description === 'function'
168
+ ? await data.description(response)
169
+ : data.description;
170
+ this.create({ id, type: 'success', title: successMsg, description });
171
+ }
172
+ })
173
+ .catch(async (error) => {
174
+ result = ['reject', error];
175
+ if (data.error !== undefined) {
176
+ shouldDismiss = false;
177
+ const errorMsg = typeof data.error === 'function' ? await data.error(error) : data.error;
178
+ const description = typeof data.description === 'function'
179
+ ? await data.description(error)
180
+ : data.description;
181
+ this.create({ id, type: 'error', title: errorMsg, description });
182
+ }
183
+ })
184
+ .finally(() => {
185
+ if (shouldDismiss) {
186
+ // toast is still in load state, dismiss it
187
+ this.dismiss(id);
188
+ id = undefined;
189
+ }
190
+ data.finally?.();
191
+ });
192
+ // return a promise that can be unwrapped
193
+ const unwrap = () => new Promise((resolve, reject) => originalPromise
194
+ .then(() => (result[0] === 'reject' ? reject(result[1]) : resolve(result[1])))
195
+ .catch(reject));
196
+ if (typeof id !== 'string' && typeof id !== 'number') {
197
+ return { unwrap };
198
+ }
199
+ else {
200
+ return Object.assign(id, { unwrap });
201
+ }
202
+ };
203
+ /**
204
+ * Show a custom JSX toast
205
+ */
206
+ this.custom = (jsx, data) => {
207
+ const id = data?.id ?? toastsCounter++;
208
+ this.create({ jsx: jsx(id), ...data, id });
209
+ return id;
210
+ };
211
+ /**
212
+ * Get all active (non-dismissed) toasts
213
+ */
214
+ this.getActiveToasts = () => {
215
+ return this.toasts.filter((toast) => !this.dismissedToasts.has(toast.id));
216
+ };
217
+ /**
218
+ * Get full toast history
219
+ */
220
+ this.getHistory = () => {
221
+ return this.toasts;
222
+ };
223
+ }
224
+ }
225
+ function isHttpResponse(data) {
226
+ return (data &&
227
+ typeof data === 'object' &&
228
+ 'ok' in data &&
229
+ typeof data.ok === 'boolean' &&
230
+ 'status' in data &&
231
+ typeof data.status === 'number');
232
+ }
233
+ // singleton instance
234
+ exports.ToastState = new Observer();
235
+ // basic toast function
236
+ const toastFunction = (title, data) => {
237
+ return exports.ToastState.create({ ...data, title });
238
+ };
239
+ // getters
240
+ const getHistory = () => exports.ToastState.getHistory();
241
+ const getToasts = () => exports.ToastState.getActiveToasts();
242
+ /**
243
+ * Main toast API - call directly or use methods like toast.success()
244
+ *
245
+ * @example
246
+ * // basic usage
247
+ * toast('Hello world')
248
+ *
249
+ * // with type
250
+ * toast.success('Saved!')
251
+ * toast.error('Something went wrong')
252
+ *
253
+ * // with options
254
+ * toast('Hello', { duration: 5000 })
255
+ *
256
+ * // promise toast
257
+ * toast.promise(fetch('/api'), {
258
+ * loading: 'Loading...',
259
+ * success: 'Done!',
260
+ * error: 'Failed'
261
+ * })
262
+ *
263
+ * // custom JSX
264
+ * toast.custom((id) => <MyToast id={id} />)
265
+ *
266
+ * // dismiss
267
+ * const id = toast('Hello')
268
+ * toast.dismiss(id)
269
+ * toast.dismiss() // dismiss all
270
+ */
271
+ exports.toast = Object.assign(toastFunction, {
272
+ success: exports.ToastState.success,
273
+ error: exports.ToastState.error,
274
+ warning: exports.ToastState.warning,
275
+ info: exports.ToastState.info,
276
+ loading: exports.ToastState.loading,
277
+ promise: exports.ToastState.promise,
278
+ custom: exports.ToastState.custom,
279
+ dismiss: exports.ToastState.dismiss,
280
+ message: exports.ToastState.message,
281
+ getHistory,
282
+ getToasts,
283
+ });
284
+ //# sourceMappingURL=ToastState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToastState.js","sourceRoot":"","sources":["../../src/ToastState.ts"],"names":[],"mappings":";;;AAGA,0CAA0C;AAC1C,IAAI,aAAa,GAAG,CAAC,CAAA;AA4DrB;;;GAGG;AACH,MAAM,QAAQ;IAAd;QACE,gBAAW,GAAoD,EAAE,CAAA;QACjE,WAAM,GAAa,EAAE,CAAA;QACrB,oBAAe,GAAyB,IAAI,GAAG,EAAE,CAAA;QAEjD;;;WAGG;QACH,cAAS,GAAG,CAAC,UAAoD,EAAE,EAAE;YACnE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;YAEjC,OAAO,GAAG,EAAE;gBACV,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;gBAClD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;oBACf,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACnC,CAAC;YACH,CAAC,CAAA;QACH,CAAC,CAAA;QAED;;WAEG;QACH,YAAO,GAAG,CAAC,IAAY,EAAE,EAAE;YACzB,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;QAC5D,CAAC,CAAA;QAED;;WAEG;QACH,aAAQ,GAAG,CAAC,IAA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AAE,QAAA,UAAU,CAAC,IAAI;IACrB,OAAO,EAAE,QAAA,UAAU,CAAC,OAAO;IAC3B,OAAO,EAAE,QAAA,UAAU,CAAC,OAAO;IAC3B,MAAM,EAAE,QAAA,UAAU,CAAC,MAAM;IACzB,OAAO,EAAE,QAAA,UAAU,CAAC,OAAO;IAC3B,OAAO,EAAE,QAAA,UAAU,CAAC,OAAO;IAC3B,UAAU;IACV,SAAS;CACV,CAAC,CAAA"}
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VIEWPORT_RESUME = exports.VIEWPORT_PAUSE = exports.VIEWPORT_DEFAULT_HOTKEY = exports.ToastViewport = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const animate_presence_1 = require("@hanzogui/animate-presence");
7
+ const compose_refs_1 = require("@hanzogui/compose-refs");
8
+ const constants_1 = require("@hanzogui/constants");
9
+ const core_1 = require("@hanzogui/core");
10
+ const portal_1 = require("@hanzogui/portal");
11
+ const stacks_1 = require("@hanzogui/stacks");
12
+ const visually_hidden_1 = require("@hanzogui/visually-hidden");
13
+ const React = tslib_1.__importStar(require("react"));
14
+ const constants_ts_1 = require("./constants.js");
15
+ const ToastPortal_tsx_1 = require("./ToastPortal.js");
16
+ const ToastProvider_tsx_1 = require("./ToastProvider.js");
17
+ const VIEWPORT_NAME = 'ToastViewport';
18
+ const VIEWPORT_DEFAULT_HOTKEY = ['F8'];
19
+ exports.VIEWPORT_DEFAULT_HOTKEY = VIEWPORT_DEFAULT_HOTKEY;
20
+ const VIEWPORT_PAUSE = 'toast.viewportPause';
21
+ exports.VIEWPORT_PAUSE = VIEWPORT_PAUSE;
22
+ const VIEWPORT_RESUME = 'toast.viewportResume';
23
+ exports.VIEWPORT_RESUME = VIEWPORT_RESUME;
24
+ const ToastViewportWrapperFrame = (0, core_1.styled)(stacks_1.YStack, {
25
+ name: 'ViewportWrapper',
26
+ variants: {
27
+ unstyled: {
28
+ false: {
29
+ pointerEvents: 'box-none',
30
+ top: 0,
31
+ bottom: 0,
32
+ left: 0,
33
+ right: 0,
34
+ position: constants_1.isWeb ? 'fixed' : 'absolute',
35
+ maxWidth: '100%',
36
+ tabIndex: 0,
37
+ zIndex: 100000,
38
+ },
39
+ },
40
+ },
41
+ defaultVariants: {
42
+ unstyled: process.env.GUI_HEADLESS === '1',
43
+ },
44
+ });
45
+ const ToastViewportFrame = (0, core_1.styled)(stacks_1.YStack, {
46
+ name: VIEWPORT_NAME,
47
+ variants: {
48
+ unstyled: {
49
+ false: {
50
+ pointerEvents: 'box-none',
51
+ position: constants_1.isWeb ? 'fixed' : 'absolute',
52
+ maxWidth: '100%',
53
+ },
54
+ },
55
+ },
56
+ defaultVariants: {
57
+ unstyled: process.env.GUI_HEADLESS === '1',
58
+ },
59
+ });
60
+ const ToastViewport = React.memo(React.forwardRef((props, forwardedRef) => {
61
+ const { scope, hotkey = VIEWPORT_DEFAULT_HOTKEY, label = 'Notifications ({hotkey})', name = 'default', multipleToasts, zIndex, portalToRoot, ...viewportProps } = props;
62
+ const context = (0, ToastProvider_tsx_1.useToastProviderContext)(scope);
63
+ const getItems = (0, ToastProvider_tsx_1.useCollection)(scope || constants_ts_1.TOAST_CONTEXT);
64
+ const headFocusProxyRef = React.useRef(null);
65
+ const tailFocusProxyRef = React.useRef(null);
66
+ const wrapperRef = React.useRef(null);
67
+ const ref = React.useRef(null);
68
+ const onViewportChange = React.useCallback((el) => {
69
+ if (context.viewports[name] !== el)
70
+ context.onViewportChange(name, el);
71
+ }, [name, context.viewports]);
72
+ // @ts-ignore TODO react 19 type needs fix
73
+ const composedRefs = (0, compose_refs_1.useComposedRefs)(forwardedRef, ref, onViewportChange);
74
+ const hotkeyLabel = hotkey.join('+').replace(/Key/g, '').replace(/Digit/g, '');
75
+ const hasToasts = context.toastCount > 0;
76
+ React.useEffect(() => {
77
+ if (!constants_1.isWeb)
78
+ return;
79
+ if (context.toastCount === 0)
80
+ return;
81
+ const handleKeyDown = (event) => {
82
+ // we use `event.code` as it is consistent regardless of meta keys that were pressed.
83
+ // for example, `event.key` for `Control+Alt+t` is `†` and `t !== †`
84
+ const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
85
+ if (isHotkeyPressed)
86
+ ref.current?.focus();
87
+ };
88
+ document.addEventListener('keydown', handleKeyDown);
89
+ return () => {
90
+ document.removeEventListener('keydown', handleKeyDown);
91
+ };
92
+ }, [hotkey, context.toastCount]);
93
+ React.useEffect(() => {
94
+ if (!constants_1.isWeb)
95
+ return;
96
+ if (context.toastCount === 0)
97
+ return;
98
+ const wrapper = wrapperRef.current;
99
+ const viewport = ref.current;
100
+ if (hasToasts && wrapper && viewport) {
101
+ const handlePause = () => {
102
+ if (!context.isClosePausedRef.current) {
103
+ const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
104
+ viewport.dispatchEvent(pauseEvent);
105
+ context.isClosePausedRef.current = true;
106
+ }
107
+ };
108
+ const handleResume = () => {
109
+ if (context.isClosePausedRef.current) {
110
+ const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
111
+ viewport.dispatchEvent(resumeEvent);
112
+ context.isClosePausedRef.current = false;
113
+ }
114
+ };
115
+ const handleFocusOutResume = (event) => {
116
+ const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
117
+ if (isFocusMovingOutside)
118
+ handleResume();
119
+ };
120
+ const handlePointerLeaveResume = () => {
121
+ const isFocusInside = wrapper.contains(document.activeElement);
122
+ if (!isFocusInside)
123
+ handleResume();
124
+ };
125
+ // Toasts are not in the viewport React tree so we need to bind DOM events
126
+ wrapper.addEventListener('focusin', handlePause);
127
+ wrapper.addEventListener('focusout', handleFocusOutResume);
128
+ wrapper.addEventListener('pointermove', handlePause);
129
+ wrapper.addEventListener('pointerleave', handlePointerLeaveResume);
130
+ window.addEventListener('blur', handlePause);
131
+ window.addEventListener('focus', handleResume);
132
+ return () => {
133
+ wrapper.removeEventListener('focusin', handlePause);
134
+ wrapper.removeEventListener('focusout', handleFocusOutResume);
135
+ wrapper.removeEventListener('pointermove', handlePause);
136
+ wrapper.removeEventListener('pointerleave', handlePointerLeaveResume);
137
+ window.removeEventListener('blur', handlePause);
138
+ window.removeEventListener('focus', handleResume);
139
+ };
140
+ }
141
+ }, [hasToasts, context.isClosePausedRef, context.toastCount]);
142
+ const getSortedTabbableCandidates = React.useCallback(({ tabbingDirection }) => {
143
+ const toastItems = getItems();
144
+ const tabbableCandidates = toastItems.map((toastItem) => {
145
+ const toastNode = toastItem.ref.current;
146
+ const toastTabbableCandidates = [
147
+ toastNode,
148
+ ...getTabbableCandidates(toastNode),
149
+ ];
150
+ return tabbingDirection === 'forwards'
151
+ ? toastTabbableCandidates
152
+ : toastTabbableCandidates.reverse();
153
+ });
154
+ return (tabbingDirection === 'forwards'
155
+ ? tabbableCandidates.reverse()
156
+ : tabbableCandidates).flat();
157
+ }, [getItems]);
158
+ React.useEffect(() => {
159
+ if (!constants_1.isWeb)
160
+ return;
161
+ if (context.toastCount === 0)
162
+ return;
163
+ const viewport = ref.current;
164
+ // We programmatically manage tabbing as we are unable to influence
165
+ // the source order with portals, this allows us to reverse the
166
+ // tab order so that it runs from most recent toast to least
167
+ if (viewport) {
168
+ const handleKeyDown = (event) => {
169
+ const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
170
+ const isTabKey = event.key === 'Tab' && !isMetaKey;
171
+ if (isTabKey) {
172
+ const focusedElement = document.activeElement;
173
+ const isTabbingBackwards = event.shiftKey;
174
+ const targetIsViewport = event.target === viewport;
175
+ // If we're back tabbing after jumping to the viewport then we simply
176
+ // proxy focus out to the preceding document
177
+ if (targetIsViewport && isTabbingBackwards) {
178
+ // @ts-ignore ali TODO type
179
+ headFocusProxyRef.current?.focus();
180
+ return;
181
+ }
182
+ const tabbingDirection = isTabbingBackwards ? 'backwards' : 'forwards';
183
+ const sortedCandidates = getSortedTabbableCandidates({ tabbingDirection });
184
+ const index = sortedCandidates.findIndex((candidate) => candidate === focusedElement);
185
+ if (focusFirst(sortedCandidates.slice(index + 1))) {
186
+ event.preventDefault();
187
+ }
188
+ else {
189
+ // If we can't focus that means we're at the edges so we
190
+ // proxy to the corresponding exit point and let the browser handle
191
+ // tab/shift+tab keypress and implicitly pass focus to the next valid element in the document
192
+ isTabbingBackwards
193
+ ? // @ts-ignore ali TODO type
194
+ headFocusProxyRef.current?.focus()
195
+ : // @ts-ignore ali TODO type
196
+ tailFocusProxyRef.current?.focus();
197
+ }
198
+ }
199
+ };
200
+ // Toasts are not in the viewport React tree so we need to bind DOM events
201
+ viewport.addEventListener('keydown', handleKeyDown);
202
+ return () => viewport.removeEventListener('keydown', handleKeyDown);
203
+ }
204
+ }, [getItems, getSortedTabbableCandidates, context.toastCount]);
205
+ const contents = ((0, jsx_runtime_1.jsxs)(ToastViewportWrapperFrame, { ref: wrapperRef,
206
+ // biome-ignore lint/a11y/useSemanticElements: <explanation>
207
+ role: "region", "aria-label": label.replace('{hotkey}', hotkeyLabel),
208
+ // // Ensure virtual cursor from landmarks menus triggers focus/blur for pause/resume
209
+ tabIndex: -1, children: [hasToasts && ((0, jsx_runtime_1.jsx)(FocusProxy, { context: context, viewportName: name, ref: headFocusProxyRef, onFocusFromOutsideViewport: () => {
210
+ const tabbableCandidates = getSortedTabbableCandidates({
211
+ tabbingDirection: 'forwards',
212
+ });
213
+ focusFirst(tabbableCandidates);
214
+ } })), (0, jsx_runtime_1.jsx)(ToastProvider_tsx_1.Collection.Slot, { scope: context.toastScope, children: (0, jsx_runtime_1.jsx)(ToastViewportFrame, { focusable: context.toastCount > 0, ref: composedRefs, ...viewportProps, children: (0, jsx_runtime_1.jsx)(portal_1.PortalHost, { render: (children) => ((0, jsx_runtime_1.jsx)(animate_presence_1.AnimatePresence, { exitBeforeEnter: !multipleToasts, children: children })), name: name ?? 'default' }) }) }), hasToasts && ((0, jsx_runtime_1.jsx)(FocusProxy, { context: context, viewportName: name, ref: tailFocusProxyRef, onFocusFromOutsideViewport: () => {
215
+ const tabbableCandidates = getSortedTabbableCandidates({
216
+ tabbingDirection: 'backwards',
217
+ });
218
+ focusFirst(tabbableCandidates);
219
+ } }))] }));
220
+ if (portalToRoot) {
221
+ return ((0, jsx_runtime_1.jsx)(ToastPortal_tsx_1.ToastPortal, { context: context, ...(typeof zIndex === 'number' ? { zIndex } : {}), children: contents }));
222
+ }
223
+ return contents;
224
+ }));
225
+ exports.ToastViewport = ToastViewport;
226
+ ToastViewport.displayName = VIEWPORT_NAME;
227
+ /* -----------------------------------------------------------------------------------------------*/
228
+ const FOCUS_PROXY_NAME = 'ToastFocusProxy';
229
+ const FocusProxy = React.forwardRef((props, forwardedRef) => {
230
+ const { onFocusFromOutsideViewport, viewportName, context, ...proxyProps } = props;
231
+ const viewport = context.viewports[viewportName];
232
+ return ((0, jsx_runtime_1.jsx)(visually_hidden_1.VisuallyHidden, { "aria-hidden": true, tabIndex: 0, ...proxyProps, ref: forwardedRef,
233
+ // Avoid page scrolling when focus is on the focus proxy
234
+ position: constants_1.isWeb ? 'fixed' : 'absolute', onFocus: (event) => {
235
+ if (!constants_1.isWeb)
236
+ return;
237
+ const prevFocusedElement = event.relatedTarget;
238
+ const isFocusFromOutsideViewport = !viewport?.contains(prevFocusedElement);
239
+ if (isFocusFromOutsideViewport)
240
+ onFocusFromOutsideViewport();
241
+ } }));
242
+ });
243
+ FocusProxy.displayName = FOCUS_PROXY_NAME;
244
+ /* -----------------------------------------------------------------------------------------------*/
245
+ function focusFirst(candidates) {
246
+ if (!constants_1.isWeb)
247
+ return;
248
+ const previouslyFocusedElement = document.activeElement;
249
+ return candidates.some((candidate) => {
250
+ // if focus is already where we want to go, we don't want to keep going through the candidates
251
+ if (candidate === previouslyFocusedElement)
252
+ return true;
253
+ candidate.focus();
254
+ return document.activeElement !== previouslyFocusedElement;
255
+ });
256
+ }
257
+ /**
258
+ * Returns a list of potential tabbable candidates.
259
+ *
260
+ * NOTE: This is only a close approximation. For example it doesn't take into account cases like when
261
+ * elements are not visible. This cannot be worked out easily by just reading a property, but rather
262
+ * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
263
+ *
264
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
265
+ * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
266
+ */
267
+ function getTabbableCandidates(container) {
268
+ if (!constants_1.isWeb)
269
+ return [];
270
+ const containerHtml = container;
271
+ const nodes = [];
272
+ const walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {
273
+ acceptNode: (node) => {
274
+ const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
275
+ if (node.disabled || node.hidden || isHiddenInput)
276
+ return NodeFilter.FILTER_SKIP;
277
+ // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
278
+ // runtime's understanding of tabbability, so this automatically accounts
279
+ // for any kind of element that could be tabbed to.
280
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
281
+ },
282
+ });
283
+ while (walker.nextNode())
284
+ nodes.push(walker.currentNode);
285
+ // we do not take into account the order of nodes with positive `tabIndex` as it
286
+ // hinders accessibility to have tab order different from visual order.
287
+ return nodes;
288
+ }
289
+ //# sourceMappingURL=ToastViewport.js.map