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