@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,354 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: true
33
+ }), mod);
34
+ var ToastImpl_exports = {};
35
+ __export(ToastImpl_exports, {
36
+ ToastImpl: () => ToastImpl,
37
+ ToastImplFrame: () => ToastImplFrame,
38
+ useToastInteractiveContext: () => useToastInteractiveContext
39
+ });
40
+ module.exports = __toCommonJS(ToastImpl_exports);
41
+ var import_animate_presence = require("@hanzogui/animate-presence");
42
+ var import_compose_refs = require("@hanzogui/compose-refs");
43
+ var import_constants = require("@hanzogui/constants");
44
+ var import_core = require("@hanzogui/core");
45
+ var import_dismissable = require("@hanzogui/dismissable");
46
+ var import_helpers = require("@hanzogui/helpers");
47
+ var import_portal = require("@hanzogui/portal");
48
+ var import_stacks = require("@hanzogui/stacks");
49
+ var React = __toESM(require("react"), 1);
50
+ var import_constants2 = require("./constants.cjs");
51
+ var import_ToastAnnounce = require("./ToastAnnounce.cjs");
52
+ var import_ToastProvider = require("./ToastProvider.cjs");
53
+ var import_ToastViewport = require("./ToastViewport.cjs");
54
+ var import_jsx_runtime = require("react/jsx-runtime");
55
+ const getPanResponder = () => {
56
+ return null;
57
+ };
58
+ const ToastImplFrame = (0, import_core.styled)(import_stacks.YStack, {
59
+ name: "ToastImpl",
60
+ tabIndex: 0,
61
+ variants: {
62
+ unstyled: {
63
+ false: {
64
+ focusStyle: {
65
+ outlineStyle: "solid",
66
+ outlineWidth: 2,
67
+ outlineColor: "$outlineColor"
68
+ },
69
+ backgroundColor: "$color6",
70
+ borderRadius: "$4",
71
+ paddingHorizontal: "$4",
72
+ paddingVertical: "$3",
73
+ marginHorizontal: "auto",
74
+ marginVertical: "$1",
75
+ elevation: "$3"
76
+ }
77
+ }
78
+ },
79
+ defaultVariants: {
80
+ unstyled: process.env.GUI_HEADLESS === "1"
81
+ }
82
+ });
83
+ const {
84
+ Provider: ToastInteractiveProvider,
85
+ useStyledContext: useToastInteractiveContext
86
+ } = (0, import_core.createStyledContext)({
87
+ onClose() {}
88
+ });
89
+ const ToastImpl = React.forwardRef((props, forwardedRef) => {
90
+ const {
91
+ scope,
92
+ type = "foreground",
93
+ duration: durationProp,
94
+ open,
95
+ onClose,
96
+ onEscapeKeyDown,
97
+ onPause,
98
+ onResume,
99
+ onSwipeStart,
100
+ onSwipeMove,
101
+ onSwipeCancel,
102
+ onSwipeEnd,
103
+ viewportName = "default",
104
+ ...toastProps
105
+ } = props;
106
+ const isPresent = (0, import_animate_presence.useIsPresent)();
107
+ const context = (0, import_ToastProvider.useToastProviderContext)(scope);
108
+ const [node, setNode] = React.useState(null);
109
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setNode);
110
+ const duration = durationProp || context.duration;
111
+ const closeTimerStartTimeRef = React.useRef(0);
112
+ const closeTimerRemainingTimeRef = React.useRef(duration);
113
+ const closeTimerRef = React.useRef(0);
114
+ const {
115
+ onToastAdd,
116
+ onToastRemove
117
+ } = context;
118
+ const viewport = React.useMemo(() => {
119
+ return context.viewports[viewportName];
120
+ }, [context.viewports, viewportName]);
121
+ const handleClose = (0, import_core.useEvent)(() => {
122
+ if (!isPresent) return;
123
+ if (import_constants.isWeb) {
124
+ if (node?.contains(document.activeElement)) viewport?.focus();
125
+ }
126
+ onClose();
127
+ });
128
+ const startTimer = React.useCallback(duration2 => {
129
+ if (!duration2 || duration2 === Number.POSITIVE_INFINITY) return;
130
+ clearTimeout(closeTimerRef.current);
131
+ closeTimerStartTimeRef.current = (/* @__PURE__ */new Date()).getTime();
132
+ closeTimerRef.current = setTimeout(handleClose, duration2);
133
+ }, [handleClose]);
134
+ const handleResume = React.useCallback(() => {
135
+ startTimer(closeTimerRemainingTimeRef.current);
136
+ onResume?.();
137
+ }, [onResume, startTimer]);
138
+ const handlePause = React.useCallback(() => {
139
+ const elapsedTime = (/* @__PURE__ */new Date()).getTime() - closeTimerStartTimeRef.current;
140
+ closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime;
141
+ window.clearTimeout(closeTimerRef.current);
142
+ onPause?.();
143
+ }, [onPause]);
144
+ React.useEffect(() => {
145
+ if (!import_constants.isWeb) return;
146
+ if (viewport) {
147
+ viewport.addEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause);
148
+ viewport.addEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
149
+ return () => {
150
+ viewport.removeEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause);
151
+ viewport.removeEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
152
+ };
153
+ }
154
+ }, [viewport, duration, onPause, onResume, startTimer]);
155
+ React.useEffect(() => {
156
+ if (open && !context.isClosePausedRef.current) startTimer(duration);
157
+ }, [open, duration, context.isClosePausedRef, startTimer]);
158
+ React.useEffect(() => {
159
+ onToastAdd();
160
+ return () => onToastRemove();
161
+ }, [onToastAdd, onToastRemove]);
162
+ const announceTextContent = React.useMemo(() => {
163
+ if (!import_constants.isWeb) return null;
164
+ return node ? getAnnounceTextContent(node) : null;
165
+ }, [node]);
166
+ const isHorizontalSwipe = ["left", "right", "horizontal"].includes(context.swipeDirection);
167
+ const {
168
+ animationDriver
169
+ } = (0, import_core.useConfiguration)();
170
+ if (!animationDriver) throw new Error("Must set animations in gui.config.ts");
171
+ const {
172
+ useAnimatedNumber,
173
+ useAnimatedNumberStyle
174
+ } = animationDriver;
175
+ const animatedNumber = useAnimatedNumber(0);
176
+ const AnimatedView = animationDriver["NumberView"] ?? animationDriver.View ?? import_core.View;
177
+ const animatedStyles = useAnimatedNumberStyle(animatedNumber, val => {
178
+ "worklet";
179
+
180
+ return {
181
+ transform: [isHorizontalSwipe ? {
182
+ translateX: val
183
+ } : {
184
+ translateY: val
185
+ }]
186
+ };
187
+ });
188
+ const panResponder = React.useMemo(() => {
189
+ const PanResponder = getPanResponder();
190
+ if (!PanResponder) return null;
191
+ return PanResponder.create({
192
+ onMoveShouldSetPanResponder: (e, gesture) => {
193
+ if (shouldGrantGestureMove(context.swipeDirection, gesture)) {
194
+ onSwipeStart?.(e);
195
+ return true;
196
+ }
197
+ return false;
198
+ },
199
+ onPanResponderGrant: e => {
200
+ if (!import_constants.isWeb) handlePause?.();
201
+ },
202
+ onPanResponderMove: (e, gesture) => {
203
+ const {
204
+ x,
205
+ y
206
+ } = getGestureDistance(context.swipeDirection, gesture);
207
+ const delta = {
208
+ x,
209
+ y
210
+ };
211
+ animatedNumber.setValue(isHorizontalSwipe ? x : y, {
212
+ type: "direct"
213
+ });
214
+ if (isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold)) onSwipeEnd?.(e);
215
+ onSwipeMove?.(e);
216
+ },
217
+ onPanResponderEnd: (e, {
218
+ dx,
219
+ dy
220
+ }) => {
221
+ if (!isDeltaInDirection({
222
+ x: dx,
223
+ y: dy
224
+ }, context.swipeDirection, context.swipeThreshold)) {
225
+ if (!import_constants.isWeb) handleResume?.();
226
+ onSwipeCancel?.(e);
227
+ animatedNumber.setValue(0, {
228
+ type: "spring"
229
+ });
230
+ }
231
+ }
232
+ });
233
+ }, [handlePause, handleResume]);
234
+ const themeName = (0, import_core.useThemeName)();
235
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
236
+ children: [announceTextContent && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounce, {
237
+ scope,
238
+ role: "status",
239
+ "aria-live": type === "foreground" ? "assertive" : "polite",
240
+ "aria-atomic": true,
241
+ children: announceTextContent
242
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
243
+ hostName: viewportName ?? "default",
244
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastInteractiveProvider, {
245
+ scope,
246
+ onClose: () => {
247
+ handleClose();
248
+ },
249
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
250
+ onEscapeKeyDown: (0, import_helpers.composeEventHandlers)(onEscapeKeyDown, () => {
251
+ if (!context.isFocusedToastEscapeKeyDownRef.current) handleClose();
252
+ context.isFocusedToastEscapeKeyDownRef.current = false;
253
+ }),
254
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
255
+ contain: true,
256
+ forceClassName: true,
257
+ name: themeName,
258
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
259
+ ...panResponder?.panHandlers,
260
+ style: [{
261
+ margin: "auto"
262
+ }, animatedStyles],
263
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.ItemSlot, {
264
+ scope: context.toastScope,
265
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastImplFrame, {
266
+ role: "status",
267
+ "aria-live": "off",
268
+ "aria-atomic": true,
269
+ "data-state": open ? "open" : "closed",
270
+ "data-swipe-direction": context.swipeDirection,
271
+ pointerEvents: "auto",
272
+ "$platform-web": {
273
+ touchAction: "none",
274
+ userSelect: "none"
275
+ },
276
+ ...toastProps,
277
+ ref: composedRefs,
278
+ ...(import_constants.isWeb && {
279
+ onKeyDown: (0, import_helpers.composeEventHandlers)(props.onKeyDown, event => {
280
+ if (event.key !== "Escape") return;
281
+ onEscapeKeyDown?.(event);
282
+ if (!event.defaultPrevented) {
283
+ context.isFocusedToastEscapeKeyDownRef.current = true;
284
+ handleClose();
285
+ }
286
+ })
287
+ })
288
+ })
289
+ })
290
+ })
291
+ })
292
+ })
293
+ }, props.id)
294
+ })]
295
+ });
296
+ });
297
+ ToastImpl.propTypes = {
298
+ type(props) {
299
+ if (props.type && !["foreground", "background"].includes(props.type)) {
300
+ const error = `Invalid prop \`type\` supplied to \`${import_constants2.TOAST_NAME}\`. Expected \`foreground | background\`.`;
301
+ return new Error(error);
302
+ }
303
+ return null;
304
+ }
305
+ };
306
+ const isDeltaInDirection = (delta, direction, threshold = 0) => {
307
+ const deltaX = Math.abs(delta.x);
308
+ const deltaY = Math.abs(delta.y);
309
+ const isDeltaX = deltaX > deltaY;
310
+ if (direction === "left" || direction === "right" || direction === "horizontal") return isDeltaX && deltaX > threshold;
311
+ return !isDeltaX && deltaY > threshold;
312
+ };
313
+ function getAnnounceTextContent(container) {
314
+ if (!import_constants.isWeb) return "";
315
+ const textContent = [];
316
+ Array.from(container.childNodes).forEach(node => {
317
+ if (node.nodeType === node.TEXT_NODE && node.textContent) textContent.push(node.textContent);
318
+ if (isHTMLElement(node)) {
319
+ const isHidden = node.ariaHidden || node.hidden || node.style.display === "none";
320
+ const isExcluded = node.dataset.toastAnnounceExclude === "";
321
+ if (!isHidden) if (isExcluded) {
322
+ const altText = node.dataset.toastAnnounceAlt;
323
+ if (altText) textContent.push(altText);
324
+ } else textContent.push(...getAnnounceTextContent(node));
325
+ }
326
+ });
327
+ return textContent;
328
+ }
329
+ function isHTMLElement(node) {
330
+ return node.nodeType === node.ELEMENT_NODE;
331
+ }
332
+ const GESTURE_GRANT_THRESHOLD = 10;
333
+ const shouldGrantGestureMove = (dir, {
334
+ dx,
335
+ dy
336
+ }) => {
337
+ if ((dir === "horizontal" || dir === "left") && dx < -GESTURE_GRANT_THRESHOLD) return true;
338
+ if ((dir === "horizontal" || dir === "right") && dx > GESTURE_GRANT_THRESHOLD) return true;
339
+ if ((dir === "vertical" || dir === "up") && dy > -GESTURE_GRANT_THRESHOLD) return true;
340
+ if ((dir === "vertical" || dir === "down") && dy < GESTURE_GRANT_THRESHOLD) return true;
341
+ return false;
342
+ };
343
+ const getGestureDistance = (dir, {
344
+ dx,
345
+ dy
346
+ }) => {
347
+ let y = 0;
348
+ let x = 0;
349
+ if (dir === "horizontal") x = dx;else if (dir === "left") x = Math.min(0, dx);else if (dir === "right") x = Math.max(0, dx);else if (dir === "vertical") y = dy;else if (dir === "up") y = Math.min(0, dy);else if (dir === "down") y = Math.max(0, dy);
350
+ return {
351
+ x,
352
+ y
353
+ };
354
+ };