@hanzogui/toast 7.0.0 → 7.3.0

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