@hanzogui/toast 2.0.0-rc.41-hanzoai.3

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