@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
@@ -2,33 +2,35 @@ var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
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, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
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);
32
34
  var ToastViewport_exports = {};
33
35
  __export(ToastViewport_exports, {
34
36
  ToastViewport: () => ToastViewport,
@@ -37,242 +39,281 @@ __export(ToastViewport_exports, {
37
39
  VIEWPORT_RESUME: () => VIEWPORT_RESUME
38
40
  });
39
41
  module.exports = __toCommonJS(ToastViewport_exports);
40
- var import_gui_animate_presence = require("@hanzogui/animate-presence"),
41
- import_gui_compose_refs = require("@hanzogui/compose-refs"),
42
- import_gui_constants = require("@hanzogui/constants"),
43
- import_gui_core = require("@hanzogui/core"),
44
- import_gui_portal = require("@hanzogui/portal"),
45
- import_gui_stacks = require("@hanzogui/stacks"),
46
- import_gui_visually_hidden = require("@hanzogui/visually-hidden"),
47
- React = __toESM(require("react"), 1),
48
- import_constants = require("./constants.cjs"),
49
- import_ToastPortal = require("./ToastPortal.cjs"),
50
- import_ToastProvider = require("./ToastProvider.cjs"),
51
- import_jsx_runtime = require("react/jsx-runtime");
52
- const VIEWPORT_NAME = "ToastViewport",
53
- VIEWPORT_DEFAULT_HOTKEY = ["F8"],
54
- VIEWPORT_PAUSE = "toast.viewportPause",
55
- VIEWPORT_RESUME = "toast.viewportResume",
56
- ToastViewportWrapperFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
57
- name: "ViewportWrapper",
58
- variants: {
59
- unstyled: {
60
- false: {
61
- pointerEvents: "box-none",
62
- top: 0,
63
- bottom: 0,
64
- left: 0,
65
- right: 0,
66
- position: "fixed",
67
- maxWidth: "100%",
68
- tabIndex: 0,
69
- zIndex: 1e5
70
- }
42
+ var import_animate_presence = require("@hanzogui/animate-presence");
43
+ var import_compose_refs = require("@hanzogui/compose-refs");
44
+ var import_constants = require("@hanzogui/constants");
45
+ var import_core = require("@hanzogui/core");
46
+ var import_portal = require("@hanzogui/portal");
47
+ var import_stacks = require("@hanzogui/stacks");
48
+ var import_visually_hidden = require("@hanzogui/visually-hidden");
49
+ var React = __toESM(require("react"), 1);
50
+ var import_constants2 = require("./constants.cjs");
51
+ var import_ToastPortal = require("./ToastPortal.cjs");
52
+ var import_ToastProvider = require("./ToastProvider.cjs");
53
+ var import_jsx_runtime = require("react/jsx-runtime");
54
+ const VIEWPORT_NAME = "ToastViewport";
55
+ const VIEWPORT_DEFAULT_HOTKEY = ["F8"];
56
+ const VIEWPORT_PAUSE = "toast.viewportPause";
57
+ const VIEWPORT_RESUME = "toast.viewportResume";
58
+ const ToastViewportWrapperFrame = (0, import_core.styled)(import_stacks.YStack, {
59
+ name: "ViewportWrapper",
60
+ variants: {
61
+ unstyled: {
62
+ false: {
63
+ pointerEvents: "box-none",
64
+ top: 0,
65
+ bottom: 0,
66
+ left: 0,
67
+ right: 0,
68
+ position: import_constants.isWeb ? "fixed" : "absolute",
69
+ maxWidth: "100%",
70
+ tabIndex: 0,
71
+ zIndex: 1e5
71
72
  }
72
- },
73
- defaultVariants: {
74
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
75
73
  }
76
- }),
77
- ToastViewportFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
78
- name: VIEWPORT_NAME,
79
- variants: {
80
- unstyled: {
81
- false: {
82
- pointerEvents: "box-none",
83
- position: "fixed",
84
- maxWidth: "100%"
85
- }
74
+ },
75
+ defaultVariants: {
76
+ unstyled: process.env.GUI_HEADLESS === "1"
77
+ }
78
+ });
79
+ const ToastViewportFrame = (0, import_core.styled)(import_stacks.YStack, {
80
+ name: VIEWPORT_NAME,
81
+ variants: {
82
+ unstyled: {
83
+ false: {
84
+ pointerEvents: "box-none",
85
+ position: import_constants.isWeb ? "fixed" : "absolute",
86
+ maxWidth: "100%"
86
87
  }
87
- },
88
- defaultVariants: {
89
- unstyled: process.env.HANZO_GUI_HEADLESS === "1"
90
88
  }
91
- }),
92
- ToastViewport = React.memo(React.forwardRef((props, forwardedRef) => {
93
- const {
94
- scope,
95
- hotkey = VIEWPORT_DEFAULT_HOTKEY,
96
- label = "Notifications ({hotkey})",
97
- name = "default",
98
- multipleToasts,
99
- zIndex,
100
- portalToRoot,
101
- ...viewportProps
102
- } = props,
103
- context = (0, import_ToastProvider.useToastProviderContext)(scope),
104
- getItems = (0, import_ToastProvider.useCollection)(scope || import_constants.TOAST_CONTEXT),
105
- headFocusProxyRef = React.useRef(null),
106
- tailFocusProxyRef = React.useRef(null),
107
- wrapperRef = React.useRef(null),
108
- ref = React.useRef(null),
109
- onViewportChange = React.useCallback(el => {
110
- context.viewports[name] !== el && context.onViewportChange(name, el);
111
- }, [name, context.viewports]),
112
- composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, ref, onViewportChange),
113
- hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""),
114
- hasToasts = context.toastCount > 0;
115
- React.useEffect(() => {
116
- if (!import_gui_constants.isWeb || context.toastCount === 0) return;
117
- const handleKeyDown = event => {
118
- hotkey.every(key => event[key] || event.code === key) && ref.current?.focus();
89
+ },
90
+ defaultVariants: {
91
+ unstyled: process.env.GUI_HEADLESS === "1"
92
+ }
93
+ });
94
+ const ToastViewport = React.memo(React.forwardRef((props, forwardedRef) => {
95
+ const {
96
+ scope,
97
+ hotkey = VIEWPORT_DEFAULT_HOTKEY,
98
+ label = "Notifications ({hotkey})",
99
+ name = "default",
100
+ multipleToasts,
101
+ zIndex,
102
+ portalToRoot,
103
+ ...viewportProps
104
+ } = props;
105
+ const context = (0, import_ToastProvider.useToastProviderContext)(scope);
106
+ const getItems = (0, import_ToastProvider.useCollection)(scope || import_constants2.TOAST_CONTEXT);
107
+ const headFocusProxyRef = React.useRef(null);
108
+ const tailFocusProxyRef = React.useRef(null);
109
+ const wrapperRef = React.useRef(null);
110
+ const ref = React.useRef(null);
111
+ const onViewportChange = React.useCallback(el => {
112
+ if (context.viewports[name] !== el) context.onViewportChange(name, el);
113
+ }, [name, context.viewports]);
114
+ const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, onViewportChange);
115
+ const hotkeyLabel = hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, "");
116
+ const hasToasts = context.toastCount > 0;
117
+ React.useEffect(() => {
118
+ if (!import_constants.isWeb) return;
119
+ if (context.toastCount === 0) return;
120
+ const handleKeyDown = event => {
121
+ const isHotkeyPressed = hotkey.every(key => event[key] || event.code === key);
122
+ if (isHotkeyPressed) ref.current?.focus();
123
+ };
124
+ document.addEventListener("keydown", handleKeyDown);
125
+ return () => {
126
+ document.removeEventListener("keydown", handleKeyDown);
127
+ };
128
+ }, [hotkey, context.toastCount]);
129
+ React.useEffect(() => {
130
+ if (!import_constants.isWeb) return;
131
+ if (context.toastCount === 0) return;
132
+ const wrapper = wrapperRef.current;
133
+ const viewport = ref.current;
134
+ if (hasToasts && wrapper && viewport) {
135
+ const handlePause = () => {
136
+ if (!context.isClosePausedRef.current) {
137
+ const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
138
+ viewport.dispatchEvent(pauseEvent);
139
+ context.isClosePausedRef.current = true;
140
+ }
119
141
  };
120
- return document.addEventListener("keydown", handleKeyDown), () => {
121
- document.removeEventListener("keydown", handleKeyDown);
142
+ const handleResume = () => {
143
+ if (context.isClosePausedRef.current) {
144
+ const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
145
+ viewport.dispatchEvent(resumeEvent);
146
+ context.isClosePausedRef.current = false;
147
+ }
122
148
  };
123
- }, [hotkey, context.toastCount]), React.useEffect(() => {
124
- if (!import_gui_constants.isWeb || context.toastCount === 0) return;
125
- const wrapper = wrapperRef.current,
126
- viewport = ref.current;
127
- if (hasToasts && wrapper && viewport) {
128
- const handlePause = () => {
129
- if (!context.isClosePausedRef.current) {
130
- const pauseEvent = new CustomEvent(VIEWPORT_PAUSE);
131
- viewport.dispatchEvent(pauseEvent), context.isClosePausedRef.current = !0;
132
- }
133
- },
134
- handleResume = () => {
135
- if (context.isClosePausedRef.current) {
136
- const resumeEvent = new CustomEvent(VIEWPORT_RESUME);
137
- viewport.dispatchEvent(resumeEvent), context.isClosePausedRef.current = !1;
138
- }
139
- },
140
- handleFocusOutResume = event => {
141
- !wrapper.contains(event.relatedTarget) && handleResume();
142
- },
143
- handlePointerLeaveResume = () => {
144
- wrapper.contains(document.activeElement) || handleResume();
145
- };
146
- return wrapper.addEventListener("focusin", handlePause), wrapper.addEventListener("focusout", handleFocusOutResume), wrapper.addEventListener("pointermove", handlePause), wrapper.addEventListener("pointerleave", handlePointerLeaveResume), window.addEventListener("blur", handlePause), window.addEventListener("focus", handleResume), () => {
147
- wrapper.removeEventListener("focusin", handlePause), wrapper.removeEventListener("focusout", handleFocusOutResume), wrapper.removeEventListener("pointermove", handlePause), wrapper.removeEventListener("pointerleave", handlePointerLeaveResume), window.removeEventListener("blur", handlePause), window.removeEventListener("focus", handleResume);
148
- };
149
- }
150
- }, [hasToasts, context.isClosePausedRef, context.toastCount]);
151
- const getSortedTabbableCandidates = React.useCallback(({
152
- tabbingDirection
153
- }) => {
154
- const tabbableCandidates = getItems().map(toastItem => {
155
- const toastNode = toastItem.ref.current,
156
- toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
157
- return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
158
- });
159
- return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
160
- }, [getItems]);
161
- React.useEffect(() => {
162
- if (!import_gui_constants.isWeb || context.toastCount === 0) return;
163
- const viewport = ref.current;
164
- if (viewport) {
165
- const handleKeyDown = event => {
166
- const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
167
- if (event.key === "Tab" && !isMetaKey) {
168
- const focusedElement = document.activeElement,
169
- isTabbingBackwards = event.shiftKey;
170
- if (event.target === viewport && isTabbingBackwards) {
171
- headFocusProxyRef.current?.focus();
172
- return;
173
- }
174
- const sortedCandidates = getSortedTabbableCandidates({
175
- tabbingDirection: isTabbingBackwards ? "backwards" : "forwards"
176
- }),
177
- index = sortedCandidates.findIndex(candidate => candidate === focusedElement);
178
- focusFirst(sortedCandidates.slice(index + 1)) ? event.preventDefault() : isTabbingBackwards ?
149
+ const handleFocusOutResume = event => {
150
+ const isFocusMovingOutside = !wrapper.contains(event.relatedTarget);
151
+ if (isFocusMovingOutside) handleResume();
152
+ };
153
+ const handlePointerLeaveResume = () => {
154
+ const isFocusInside = wrapper.contains(document.activeElement);
155
+ if (!isFocusInside) handleResume();
156
+ };
157
+ wrapper.addEventListener("focusin", handlePause);
158
+ wrapper.addEventListener("focusout", handleFocusOutResume);
159
+ wrapper.addEventListener("pointermove", handlePause);
160
+ wrapper.addEventListener("pointerleave", handlePointerLeaveResume);
161
+ window.addEventListener("blur", handlePause);
162
+ window.addEventListener("focus", handleResume);
163
+ return () => {
164
+ wrapper.removeEventListener("focusin", handlePause);
165
+ wrapper.removeEventListener("focusout", handleFocusOutResume);
166
+ wrapper.removeEventListener("pointermove", handlePause);
167
+ wrapper.removeEventListener("pointerleave", handlePointerLeaveResume);
168
+ window.removeEventListener("blur", handlePause);
169
+ window.removeEventListener("focus", handleResume);
170
+ };
171
+ }
172
+ }, [hasToasts, context.isClosePausedRef, context.toastCount]);
173
+ const getSortedTabbableCandidates = React.useCallback(({
174
+ tabbingDirection
175
+ }) => {
176
+ const toastItems = getItems();
177
+ const tabbableCandidates = toastItems.map(toastItem => {
178
+ const toastNode = toastItem.ref.current;
179
+ const toastTabbableCandidates = [toastNode, ...getTabbableCandidates(toastNode)];
180
+ return tabbingDirection === "forwards" ? toastTabbableCandidates : toastTabbableCandidates.reverse();
181
+ });
182
+ return (tabbingDirection === "forwards" ? tabbableCandidates.reverse() : tabbableCandidates).flat();
183
+ }, [getItems]);
184
+ React.useEffect(() => {
185
+ if (!import_constants.isWeb) return;
186
+ if (context.toastCount === 0) return;
187
+ const viewport = ref.current;
188
+ if (viewport) {
189
+ const handleKeyDown = event => {
190
+ const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
191
+ const isTabKey = event.key === "Tab" && !isMetaKey;
192
+ if (isTabKey) {
193
+ const focusedElement = document.activeElement;
194
+ const isTabbingBackwards = event.shiftKey;
195
+ const targetIsViewport = event.target === viewport;
196
+ if (targetIsViewport && isTabbingBackwards) {
197
+ headFocusProxyRef.current?.focus();
198
+ return;
199
+ }
200
+ const tabbingDirection = isTabbingBackwards ? "backwards" : "forwards";
201
+ const sortedCandidates = getSortedTabbableCandidates({
202
+ tabbingDirection
203
+ });
204
+ const index = sortedCandidates.findIndex(candidate => candidate === focusedElement);
205
+ if (focusFirst(sortedCandidates.slice(index + 1))) {
206
+ event.preventDefault();
207
+ } else {
208
+ isTabbingBackwards ?
179
209
  // @ts-ignore ali TODO type
180
210
  headFocusProxyRef.current?.focus() :
181
211
  // @ts-ignore ali TODO type
182
212
  tailFocusProxyRef.current?.focus();
183
213
  }
184
- };
185
- return viewport.addEventListener("keydown", handleKeyDown), () => viewport.removeEventListener("keydown", handleKeyDown);
186
- }
187
- }, [getItems, getSortedTabbableCandidates, context.toastCount]);
188
- const contents = /* @__PURE__ */(0, import_jsx_runtime.jsxs)(ToastViewportWrapperFrame, {
189
- ref: wrapperRef,
190
- role: "region",
191
- "aria-label": label.replace("{hotkey}", hotkeyLabel),
192
- tabIndex: -1,
193
- children: [hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
194
- context,
195
- viewportName: name,
196
- ref: headFocusProxyRef,
197
- onFocusFromOutsideViewport: () => {
198
- const tabbableCandidates = getSortedTabbableCandidates({
199
- tabbingDirection: "forwards"
200
- });
201
- focusFirst(tabbableCandidates);
202
214
  }
203
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.Slot, {
204
- scope: context.toastScope,
205
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
206
- focusable: context.toastCount > 0,
207
- ref: composedRefs,
208
- ...viewportProps,
209
- children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_portal.PortalHost, {
210
- render: children => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_animate_presence.AnimatePresence, {
211
- exitBeforeEnter: !multipleToasts,
212
- children
213
- }),
214
- name: name ?? "default"
215
- })
215
+ };
216
+ viewport.addEventListener("keydown", handleKeyDown);
217
+ return () => viewport.removeEventListener("keydown", handleKeyDown);
218
+ }
219
+ }, [getItems, getSortedTabbableCandidates, context.toastCount]);
220
+ const contents = /* @__PURE__ */(0, import_jsx_runtime.jsxs)(ToastViewportWrapperFrame, {
221
+ ref: wrapperRef,
222
+ role: "region",
223
+ "aria-label": label.replace("{hotkey}", hotkeyLabel),
224
+ tabIndex: -1,
225
+ children: [hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
226
+ context,
227
+ viewportName: name,
228
+ ref: headFocusProxyRef,
229
+ onFocusFromOutsideViewport: () => {
230
+ const tabbableCandidates = getSortedTabbableCandidates({
231
+ tabbingDirection: "forwards"
232
+ });
233
+ focusFirst(tabbableCandidates);
234
+ }
235
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.Slot, {
236
+ scope: context.toastScope,
237
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastViewportFrame, {
238
+ focusable: context.toastCount > 0,
239
+ ref: composedRefs,
240
+ ...viewportProps,
241
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalHost, {
242
+ render: children => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_animate_presence.AnimatePresence, {
243
+ exitBeforeEnter: !multipleToasts,
244
+ children
245
+ }),
246
+ name: name ?? "default"
216
247
  })
217
- }), hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
218
- context,
219
- viewportName: name,
220
- ref: tailFocusProxyRef,
221
- onFocusFromOutsideViewport: () => {
222
- const tabbableCandidates = getSortedTabbableCandidates({
223
- tabbingDirection: "backwards"
224
- });
225
- focusFirst(tabbableCandidates);
226
- }
227
- })]
228
- });
229
- return portalToRoot ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastPortal.ToastPortal, {
248
+ })
249
+ }), hasToasts && /* @__PURE__ */(0, import_jsx_runtime.jsx)(FocusProxy, {
250
+ context,
251
+ viewportName: name,
252
+ ref: tailFocusProxyRef,
253
+ onFocusFromOutsideViewport: () => {
254
+ const tabbableCandidates = getSortedTabbableCandidates({
255
+ tabbingDirection: "backwards"
256
+ });
257
+ focusFirst(tabbableCandidates);
258
+ }
259
+ })]
260
+ });
261
+ if (portalToRoot) {
262
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastPortal.ToastPortal, {
230
263
  context,
231
- ...(typeof zIndex == "number" ? {
264
+ ...(typeof zIndex === "number" ? {
232
265
  zIndex
233
266
  } : {}),
234
267
  children: contents
235
- }) : contents;
236
- }));
237
- ToastViewport.displayName = VIEWPORT_NAME;
238
- const FOCUS_PROXY_NAME = "ToastFocusProxy",
239
- FocusProxy = React.forwardRef((props, forwardedRef) => {
240
- const {
241
- onFocusFromOutsideViewport,
242
- viewportName,
243
- context,
244
- ...proxyProps
245
- } = props,
246
- viewport = context.viewports[viewportName];
247
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_visually_hidden.VisuallyHidden, {
248
- "aria-hidden": !0,
249
- tabIndex: 0,
250
- ...proxyProps,
251
- ref: forwardedRef,
252
- position: "fixed",
253
- onFocus: event => {
254
- if (!import_gui_constants.isWeb) return;
255
- const prevFocusedElement = event.relatedTarget;
256
- !viewport?.contains(prevFocusedElement) && onFocusFromOutsideViewport();
257
- }
258
268
  });
269
+ }
270
+ return contents;
271
+ }));
272
+ ToastViewport.displayName = VIEWPORT_NAME;
273
+ const FOCUS_PROXY_NAME = "ToastFocusProxy";
274
+ const FocusProxy = React.forwardRef((props, forwardedRef) => {
275
+ const {
276
+ onFocusFromOutsideViewport,
277
+ viewportName,
278
+ context,
279
+ ...proxyProps
280
+ } = props;
281
+ const viewport = context.viewports[viewportName];
282
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_visually_hidden.VisuallyHidden, {
283
+ "aria-hidden": true,
284
+ tabIndex: 0,
285
+ ...proxyProps,
286
+ ref: forwardedRef,
287
+ position: import_constants.isWeb ? "fixed" : "absolute",
288
+ onFocus: event => {
289
+ if (!import_constants.isWeb) return;
290
+ const prevFocusedElement = event.relatedTarget;
291
+ const isFocusFromOutsideViewport = !viewport?.contains(prevFocusedElement);
292
+ if (isFocusFromOutsideViewport) onFocusFromOutsideViewport();
293
+ }
259
294
  });
295
+ });
260
296
  FocusProxy.displayName = FOCUS_PROXY_NAME;
261
297
  function focusFirst(candidates) {
262
- if (!import_gui_constants.isWeb) return;
298
+ if (!import_constants.isWeb) return;
263
299
  const previouslyFocusedElement = document.activeElement;
264
- return candidates.some(candidate => candidate === previouslyFocusedElement ? !0 : (candidate.focus(), document.activeElement !== previouslyFocusedElement));
300
+ return candidates.some(candidate => {
301
+ if (candidate === previouslyFocusedElement) return true;
302
+ candidate.focus();
303
+ return document.activeElement !== previouslyFocusedElement;
304
+ });
265
305
  }
266
306
  function getTabbableCandidates(container) {
267
- if (!import_gui_constants.isWeb) return [];
268
- const containerHtml = container,
269
- nodes = [],
270
- walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {
271
- acceptNode: node => {
272
- const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
273
- return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
274
- }
275
- });
276
- for (; walker.nextNode();) nodes.push(walker.currentNode);
307
+ if (!import_constants.isWeb) return [];
308
+ const containerHtml = container;
309
+ const nodes = [];
310
+ const walker = document.createTreeWalker(containerHtml, NodeFilter.SHOW_ELEMENT, {
311
+ acceptNode: node => {
312
+ const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
313
+ if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP;
314
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
315
+ }
316
+ });
317
+ while (walker.nextNode()) nodes.push(walker.currentNode);
277
318
  return nodes;
278
319
  }