@hanzogui/toast 2.0.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 (151) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/Toast.cjs +170 -0
  3. package/dist/cjs/Toast.native.js +174 -0
  4. package/dist/cjs/Toast.native.js.map +1 -0
  5. package/dist/cjs/ToastAnnounce.cjs +97 -0
  6. package/dist/cjs/ToastAnnounce.native.js +105 -0
  7. package/dist/cjs/ToastAnnounce.native.js.map +1 -0
  8. package/dist/cjs/ToastImperative.cjs +100 -0
  9. package/dist/cjs/ToastImperative.native.js +122 -0
  10. package/dist/cjs/ToastImperative.native.js.map +1 -0
  11. package/dist/cjs/ToastImpl.cjs +292 -0
  12. package/dist/cjs/ToastImpl.native.js +326 -0
  13. package/dist/cjs/ToastImpl.native.js.map +1 -0
  14. package/dist/cjs/ToastPortal.cjs +44 -0
  15. package/dist/cjs/ToastPortal.native.js +47 -0
  16. package/dist/cjs/ToastPortal.native.js.map +1 -0
  17. package/dist/cjs/ToastProvider.cjs +146 -0
  18. package/dist/cjs/ToastProvider.native.js +159 -0
  19. package/dist/cjs/ToastProvider.native.js.map +1 -0
  20. package/dist/cjs/ToastViewport.cjs +278 -0
  21. package/dist/cjs/ToastViewport.native.js +315 -0
  22. package/dist/cjs/ToastViewport.native.js.map +1 -0
  23. package/dist/cjs/constants.cjs +28 -0
  24. package/dist/cjs/constants.native.js +31 -0
  25. package/dist/cjs/constants.native.js.map +1 -0
  26. package/dist/cjs/createNativeToast.cjs +51 -0
  27. package/dist/cjs/createNativeToast.native.js +48 -0
  28. package/dist/cjs/createNativeToast.native.js.map +1 -0
  29. package/dist/cjs/index.cjs +18 -0
  30. package/dist/cjs/index.native.js +21 -0
  31. package/dist/cjs/index.native.js.map +1 -0
  32. package/dist/cjs/types.cjs +16 -0
  33. package/dist/cjs/types.native.js +19 -0
  34. package/dist/cjs/types.native.js.map +1 -0
  35. package/dist/esm/Toast.mjs +131 -0
  36. package/dist/esm/Toast.mjs.map +1 -0
  37. package/dist/esm/Toast.native.js +132 -0
  38. package/dist/esm/Toast.native.js.map +1 -0
  39. package/dist/esm/ToastAnnounce.mjs +62 -0
  40. package/dist/esm/ToastAnnounce.mjs.map +1 -0
  41. package/dist/esm/ToastAnnounce.native.js +67 -0
  42. package/dist/esm/ToastAnnounce.native.js.map +1 -0
  43. package/dist/esm/ToastImperative.mjs +63 -0
  44. package/dist/esm/ToastImperative.mjs.map +1 -0
  45. package/dist/esm/ToastImperative.native.js +82 -0
  46. package/dist/esm/ToastImperative.native.js.map +1 -0
  47. package/dist/esm/ToastImpl.mjs +256 -0
  48. package/dist/esm/ToastImpl.mjs.map +1 -0
  49. package/dist/esm/ToastImpl.native.js +287 -0
  50. package/dist/esm/ToastImpl.native.js.map +1 -0
  51. package/dist/esm/ToastPortal.mjs +21 -0
  52. package/dist/esm/ToastPortal.mjs.map +1 -0
  53. package/dist/esm/ToastPortal.native.js +21 -0
  54. package/dist/esm/ToastPortal.native.js.map +1 -0
  55. package/dist/esm/ToastProvider.mjs +108 -0
  56. package/dist/esm/ToastProvider.mjs.map +1 -0
  57. package/dist/esm/ToastProvider.native.js +118 -0
  58. package/dist/esm/ToastProvider.native.js.map +1 -0
  59. package/dist/esm/ToastViewport.mjs +241 -0
  60. package/dist/esm/ToastViewport.mjs.map +1 -0
  61. package/dist/esm/ToastViewport.native.js +275 -0
  62. package/dist/esm/ToastViewport.native.js.map +1 -0
  63. package/dist/esm/constants.mjs +4 -0
  64. package/dist/esm/constants.mjs.map +1 -0
  65. package/dist/esm/constants.native.js +4 -0
  66. package/dist/esm/constants.native.js.map +1 -0
  67. package/dist/esm/createNativeToast.mjs +27 -0
  68. package/dist/esm/createNativeToast.mjs.map +1 -0
  69. package/dist/esm/createNativeToast.native.js +21 -0
  70. package/dist/esm/createNativeToast.native.js.map +1 -0
  71. package/dist/esm/index.js +2 -0
  72. package/dist/esm/index.js.map +1 -0
  73. package/dist/esm/index.mjs +2 -0
  74. package/dist/esm/index.mjs.map +1 -0
  75. package/dist/esm/index.native.js +2 -0
  76. package/dist/esm/index.native.js.map +1 -0
  77. package/dist/esm/types.mjs +2 -0
  78. package/dist/esm/types.mjs.map +1 -0
  79. package/dist/esm/types.native.js +2 -0
  80. package/dist/esm/types.native.js.map +1 -0
  81. package/dist/jsx/Toast.mjs +131 -0
  82. package/dist/jsx/Toast.mjs.map +1 -0
  83. package/dist/jsx/Toast.native.js +174 -0
  84. package/dist/jsx/Toast.native.js.map +1 -0
  85. package/dist/jsx/ToastAnnounce.mjs +62 -0
  86. package/dist/jsx/ToastAnnounce.mjs.map +1 -0
  87. package/dist/jsx/ToastAnnounce.native.js +105 -0
  88. package/dist/jsx/ToastAnnounce.native.js.map +1 -0
  89. package/dist/jsx/ToastImperative.mjs +63 -0
  90. package/dist/jsx/ToastImperative.mjs.map +1 -0
  91. package/dist/jsx/ToastImperative.native.js +122 -0
  92. package/dist/jsx/ToastImperative.native.js.map +1 -0
  93. package/dist/jsx/ToastImpl.mjs +256 -0
  94. package/dist/jsx/ToastImpl.mjs.map +1 -0
  95. package/dist/jsx/ToastImpl.native.js +326 -0
  96. package/dist/jsx/ToastImpl.native.js.map +1 -0
  97. package/dist/jsx/ToastPortal.mjs +21 -0
  98. package/dist/jsx/ToastPortal.mjs.map +1 -0
  99. package/dist/jsx/ToastPortal.native.js +47 -0
  100. package/dist/jsx/ToastPortal.native.js.map +1 -0
  101. package/dist/jsx/ToastProvider.mjs +108 -0
  102. package/dist/jsx/ToastProvider.mjs.map +1 -0
  103. package/dist/jsx/ToastProvider.native.js +159 -0
  104. package/dist/jsx/ToastProvider.native.js.map +1 -0
  105. package/dist/jsx/ToastViewport.mjs +241 -0
  106. package/dist/jsx/ToastViewport.mjs.map +1 -0
  107. package/dist/jsx/ToastViewport.native.js +315 -0
  108. package/dist/jsx/ToastViewport.native.js.map +1 -0
  109. package/dist/jsx/constants.mjs +4 -0
  110. package/dist/jsx/constants.mjs.map +1 -0
  111. package/dist/jsx/constants.native.js +31 -0
  112. package/dist/jsx/constants.native.js.map +1 -0
  113. package/dist/jsx/createNativeToast.mjs +27 -0
  114. package/dist/jsx/createNativeToast.mjs.map +1 -0
  115. package/dist/jsx/createNativeToast.native.js +48 -0
  116. package/dist/jsx/createNativeToast.native.js.map +1 -0
  117. package/dist/jsx/index.js +2 -0
  118. package/dist/jsx/index.js.map +1 -0
  119. package/dist/jsx/index.mjs +2 -0
  120. package/dist/jsx/index.mjs.map +1 -0
  121. package/dist/jsx/index.native.js +21 -0
  122. package/dist/jsx/index.native.js.map +1 -0
  123. package/dist/jsx/types.mjs +2 -0
  124. package/dist/jsx/types.mjs.map +1 -0
  125. package/dist/jsx/types.native.js +19 -0
  126. package/dist/jsx/types.native.js.map +1 -0
  127. package/package.json +66 -0
  128. package/src/Toast.tsx +219 -0
  129. package/src/ToastAnnounce.tsx +103 -0
  130. package/src/ToastImperative.tsx +192 -0
  131. package/src/ToastImpl.tsx +502 -0
  132. package/src/ToastPortal.tsx +19 -0
  133. package/src/ToastProvider.tsx +197 -0
  134. package/src/ToastViewport.tsx +429 -0
  135. package/src/constants.ts +2 -0
  136. package/src/createNativeToast.native.tsx +29 -0
  137. package/src/createNativeToast.tsx +48 -0
  138. package/src/index.ts +3 -0
  139. package/src/types.ts +71 -0
  140. package/types/Toast.d.ts +84 -0
  141. package/types/ToastAnnounce.d.ts +18 -0
  142. package/types/ToastImperative.d.ts +95 -0
  143. package/types/ToastImpl.d.ts +109 -0
  144. package/types/ToastPortal.d.ts +8 -0
  145. package/types/ToastProvider.d.ts +92 -0
  146. package/types/ToastViewport.d.ts +75 -0
  147. package/types/constants.d.ts +3 -0
  148. package/types/createNativeToast.d.ts +4 -0
  149. package/types/createNativeToast.native.d.ts +4 -0
  150. package/types/index.d.ts +4 -0
  151. package/types/types.d.ts +61 -0
@@ -0,0 +1,100 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ 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);
32
+ var ToastImperative_exports = {};
33
+ __export(ToastImperative_exports, {
34
+ ToastImperativeProvider: () => ToastImperativeProvider,
35
+ useToast: () => useToast,
36
+ useToastController: () => useToastController,
37
+ useToastState: () => useToastState
38
+ });
39
+ module.exports = __toCommonJS(ToastImperative_exports);
40
+ var import_gui_core = require("@hanzo/gui-core"),
41
+ import_react = __toESM(require("react"), 1),
42
+ import_createNativeToast = require("./createNativeToast.cjs"),
43
+ import_jsx_runtime = require("react/jsx-runtime");
44
+ const ToastContext = import_react.default.createContext({}),
45
+ ToastCurrentContext = import_react.default.createContext(null),
46
+ useToastController = () => import_react.default.useContext(ToastContext),
47
+ useToastState = () => import_react.default.useContext(ToastCurrentContext),
48
+ useToast = () => ({
49
+ ...useToastController(),
50
+ currentToast: useToastState()
51
+ }),
52
+ ToastImperativeProvider = ({
53
+ children,
54
+ options
55
+ }) => {
56
+ const counterRef = import_react.default.useRef(0),
57
+ [toast, setToast] = import_react.default.useState(null),
58
+ [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null),
59
+ show = import_react.default.useCallback((title, showOptions) => {
60
+ const native = showOptions?.native ?? options.native,
61
+ isWebNative = Array.isArray(native) ? native.includes("web") : native === "web",
62
+ isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile",
63
+ isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android"),
64
+ isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios"),
65
+ isHandledNatively = native === !0 || import_gui_core.isWeb && isWebNative || !import_gui_core.isWeb && isMobileNative || import_gui_core.isAndroid && isAndroidNative || import_gui_core.isIos && isIosNative;
66
+ if (isHandledNatively) {
67
+ const nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showOptions ?? {});
68
+ typeof nativeToastResult == "object" && nativeToastResult.nativeToastRef && setLastNativeToastRef(nativeToastResult.nativeToastRef);
69
+ }
70
+ return counterRef.current++, setToast({
71
+ ...showOptions?.customData,
72
+ ...showOptions,
73
+ viewportName: showOptions?.viewportName ?? "default",
74
+ title,
75
+ id: counterRef.current.toString(),
76
+ isHandledNatively
77
+ }), !0;
78
+ }, [setToast, JSON.stringify(options.native || null)]),
79
+ hide = import_react.default.useCallback(() => {
80
+ lastNativeToastRef?.close(), setToast(prev => prev ? {
81
+ ...prev,
82
+ hide: !0
83
+ } : null), setTimeout(() => {
84
+ setToast(null);
85
+ }, 100);
86
+ }, [setToast, lastNativeToastRef]),
87
+ contextValue = import_react.default.useMemo(() => ({
88
+ show,
89
+ hide,
90
+ nativeToast: lastNativeToastRef,
91
+ options
92
+ }), [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
93
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
94
+ value: contextValue,
95
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCurrentContext.Provider, {
96
+ value: toast,
97
+ children
98
+ })
99
+ });
100
+ };
@@ -0,0 +1,122 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: !0
13
+ });
14
+ },
15
+ __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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: !0
30
+ }) : target, mod)),
31
+ __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
+ value: !0
33
+ }), mod);
34
+ var ToastImperative_exports = {};
35
+ __export(ToastImperative_exports, {
36
+ ToastImperativeProvider: () => ToastImperativeProvider,
37
+ useToast: () => useToast,
38
+ useToastController: () => useToastController,
39
+ useToastState: () => useToastState
40
+ });
41
+ module.exports = __toCommonJS(ToastImperative_exports);
42
+ var import_jsx_runtime = require("react/jsx-runtime"),
43
+ import_gui_core = require("@hanzo/gui-core"),
44
+ import_react = __toESM(require("react"), 1),
45
+ import_createNativeToast = require("./createNativeToast.native.js");
46
+ function _type_of(obj) {
47
+ "@swc/helpers - typeof";
48
+
49
+ return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
50
+ }
51
+ var ToastContext = /* @__PURE__ */import_react.default.createContext({}),
52
+ ToastCurrentContext = /* @__PURE__ */import_react.default.createContext(null),
53
+ useToastController = function () {
54
+ return import_react.default.useContext(ToastContext);
55
+ },
56
+ useToastState = function () {
57
+ return import_react.default.useContext(ToastCurrentContext);
58
+ },
59
+ useToast = function () {
60
+ return {
61
+ ...useToastController(),
62
+ currentToast: useToastState()
63
+ };
64
+ },
65
+ ToastImperativeProvider = function (param) {
66
+ var {
67
+ children,
68
+ options
69
+ } = param,
70
+ counterRef = import_react.default.useRef(0),
71
+ [toast, setToast] = import_react.default.useState(null),
72
+ [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null),
73
+ show = import_react.default.useCallback(function (title, showOptions) {
74
+ var _showOptions_native,
75
+ native = (_showOptions_native = showOptions?.native) !== null && _showOptions_native !== void 0 ? _showOptions_native : options.native,
76
+ isWebNative = Array.isArray(native) ? native.includes("web") : native === "web",
77
+ isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile",
78
+ isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android"),
79
+ isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios"),
80
+ isHandledNatively = native === !0 || import_gui_core.isWeb && isWebNative || !import_gui_core.isWeb && isMobileNative || import_gui_core.isAndroid && isAndroidNative || import_gui_core.isIos && isIosNative;
81
+ if (isHandledNatively) {
82
+ var nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showOptions ?? {});
83
+ (typeof nativeToastResult > "u" ? "undefined" : _type_of(nativeToastResult)) === "object" && nativeToastResult.nativeToastRef && setLastNativeToastRef(nativeToastResult.nativeToastRef);
84
+ }
85
+ counterRef.current++;
86
+ var _showOptions_viewportName;
87
+ return setToast({
88
+ ...showOptions?.customData,
89
+ ...showOptions,
90
+ viewportName: (_showOptions_viewportName = showOptions?.viewportName) !== null && _showOptions_viewportName !== void 0 ? _showOptions_viewportName : "default",
91
+ title,
92
+ id: counterRef.current.toString(),
93
+ isHandledNatively
94
+ }), !0;
95
+ }, [setToast, JSON.stringify(options.native || null)]),
96
+ hide = import_react.default.useCallback(function () {
97
+ lastNativeToastRef?.close(), setToast(function (prev) {
98
+ return prev ? {
99
+ ...prev,
100
+ hide: !0
101
+ } : null;
102
+ }), setTimeout(function () {
103
+ setToast(null);
104
+ }, 100);
105
+ }, [setToast, lastNativeToastRef]),
106
+ contextValue = import_react.default.useMemo(function () {
107
+ return {
108
+ show,
109
+ hide,
110
+ nativeToast: lastNativeToastRef,
111
+ options
112
+ };
113
+ }, [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
114
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
115
+ value: contextValue,
116
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCurrentContext.Provider, {
117
+ value: toast,
118
+ children
119
+ })
120
+ });
121
+ };
122
+ //# sourceMappingURL=ToastImperative.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","ToastImperative_exports","__export","ToastImperativeProvider","useToast","useToastController","useToastState","module","exports","import_jsx_runtime","require","import_gui_core","import_react","__toESM","import_createNativeToast","_type_of","obj","Symbol","constructor","ToastContext","default","createContext","ToastCurrentContext","useContext","currentToast","param","children","options","counterRef","useRef","toast","setToast","useState","lastNativeToastRef","setLastNativeToastRef","show","useCallback","title","showOptions","_showOptions_native","native","isWebNative","Array","isArray","includes","isMobileNative","isAndroidNative","isIosNative","isHandledNatively","isWeb","isAndroid","isIos","nativeToastResult","createNativeToast","nativeToastRef","current","_showOptions_viewportName","customData","viewportName","id","toString","JSON","stringify","hide","close","prev"],"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AA,CAAAkB,iBAAA,CAAAE,cAAA;QAAA;QAChC1B,UAEK,CAAA2B,OAAA;QACT,IAAAC,yBAAA;QACA,OAACzB,QAAU,CAAK;UAGZ,GAAAO,WAAO,EAAAmB,UAAA;UACX,GAAAnB,WAAA;UAIIoB,YAAG,GAAAF,yBAAA,GAAAlB,WAAA,EAAAoB,YAAA,cAAAF,yBAAA,cAAAA,yBAAA;UACHnB,KAAA;UACFsB,EAJkB,EAAA/B,UAOpB,CAAA2B,OAAW,CAAAK,QAAM;UACfZ;QACF,IAAG,EAAG;MACR,GAAG,CAICjB,QAAA,EACA8B,IAAA,CAAAC,SAAA,CAAAnC,OAAA,CAAAa,MAAA,WACA;MAAAuB,IAAA,GAAAnD,YAAa,CAAAQ,OAAA,CAAAgB,WAAA;QACbH,kBAAA,EAAA+B,KAAA,IAAAjC,QAAA,WAAAkC,IAAA;UAED,OAAOA,IAAA,GAAM;YAEhB,GACEA,IAAA;YAMJF,IAAA","ignoreList":[]}
@@ -0,0 +1,292 @@
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
+ __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ 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);
32
+ var ToastImpl_exports = {};
33
+ __export(ToastImpl_exports, {
34
+ ToastImpl: () => ToastImpl,
35
+ ToastImplFrame: () => ToastImplFrame,
36
+ useToastInteractiveContext: () => useToastInteractiveContext
37
+ });
38
+ module.exports = __toCommonJS(ToastImpl_exports);
39
+ var import_gui_animate_presence = require("@hanzo/gui-animate-presence"),
40
+ import_gui_compose_refs = require("@hanzo/gui-compose-refs"),
41
+ import_gui_constants = require("@hanzo/gui-constants"),
42
+ import_gui_core = require("@hanzo/gui-core"),
43
+ import_gui_dismissable = require("@hanzo/gui-dismissable"),
44
+ import_gui_helpers = require("@hanzo/gui-helpers"),
45
+ import_gui_portal = require("@hanzo/gui-portal"),
46
+ import_gui_stacks = require("@hanzo/gui-stacks"),
47
+ React = __toESM(require("react"), 1),
48
+ import_react_native = require("react-native-web"),
49
+ import_constants = require("./constants.cjs"),
50
+ import_ToastAnnounce = require("./ToastAnnounce.cjs"),
51
+ import_ToastProvider = require("./ToastProvider.cjs"),
52
+ import_ToastViewport = require("./ToastViewport.cjs"),
53
+ import_jsx_runtime = require("react/jsx-runtime");
54
+ const ToastImplFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
55
+ name: "ToastImpl",
56
+ tabIndex: 0,
57
+ variants: {
58
+ unstyled: {
59
+ false: {
60
+ focusStyle: {
61
+ outlineStyle: "solid",
62
+ outlineWidth: 2,
63
+ outlineColor: "$outlineColor"
64
+ },
65
+ backgroundColor: "$color6",
66
+ borderRadius: "$4",
67
+ paddingHorizontal: "$4",
68
+ paddingVertical: "$3",
69
+ marginHorizontal: "auto",
70
+ marginVertical: "$1",
71
+ elevation: "$3"
72
+ }
73
+ }
74
+ },
75
+ defaultVariants: {
76
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
77
+ }
78
+ }),
79
+ {
80
+ Provider: ToastInteractiveProvider,
81
+ useStyledContext: useToastInteractiveContext
82
+ } = (0, import_gui_core.createStyledContext)({
83
+ onClose() {}
84
+ }),
85
+ ToastImpl = React.forwardRef((props, forwardedRef) => {
86
+ const {
87
+ scope,
88
+ type = "foreground",
89
+ duration: durationProp,
90
+ open,
91
+ onClose,
92
+ onEscapeKeyDown,
93
+ onPause,
94
+ onResume,
95
+ onSwipeStart,
96
+ onSwipeMove,
97
+ onSwipeCancel,
98
+ onSwipeEnd,
99
+ viewportName = "default",
100
+ ...toastProps
101
+ } = props,
102
+ isPresent = (0, import_gui_animate_presence.useIsPresent)(),
103
+ context = (0, import_ToastProvider.useToastProviderContext)(scope),
104
+ [node, setNode] = React.useState(null),
105
+ composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, setNode),
106
+ duration = durationProp || context.duration,
107
+ closeTimerStartTimeRef = React.useRef(0),
108
+ closeTimerRemainingTimeRef = React.useRef(duration),
109
+ closeTimerRef = React.useRef(0),
110
+ {
111
+ onToastAdd,
112
+ onToastRemove
113
+ } = context,
114
+ viewport = React.useMemo(() => context.viewports[viewportName], [context.viewports, viewportName]),
115
+ handleClose = (0, import_gui_core.useEvent)(() => {
116
+ isPresent && (import_gui_constants.isWeb && node?.contains(document.activeElement) && viewport?.focus(), onClose());
117
+ }),
118
+ startTimer = React.useCallback(duration2 => {
119
+ !duration2 || duration2 === Number.POSITIVE_INFINITY || (clearTimeout(closeTimerRef.current), closeTimerStartTimeRef.current = (/* @__PURE__ */new Date()).getTime(), closeTimerRef.current = setTimeout(handleClose, duration2));
120
+ }, [handleClose]),
121
+ handleResume = React.useCallback(() => {
122
+ startTimer(closeTimerRemainingTimeRef.current), onResume?.();
123
+ }, [onResume, startTimer]),
124
+ handlePause = React.useCallback(() => {
125
+ const elapsedTime = (/* @__PURE__ */new Date()).getTime() - closeTimerStartTimeRef.current;
126
+ closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime, window.clearTimeout(closeTimerRef.current), onPause?.();
127
+ }, [onPause]);
128
+ React.useEffect(() => {
129
+ if (import_gui_constants.isWeb && viewport) return viewport.addEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause), viewport.addEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume), () => {
130
+ viewport.removeEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause), viewport.removeEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
131
+ };
132
+ }, [viewport, duration, onPause, onResume, startTimer]), React.useEffect(() => {
133
+ open && !context.isClosePausedRef.current && startTimer(duration);
134
+ }, [open, duration, context.isClosePausedRef, startTimer]), React.useEffect(() => (onToastAdd(), () => onToastRemove()), [onToastAdd, onToastRemove]);
135
+ const announceTextContent = React.useMemo(() => import_gui_constants.isWeb && node ? getAnnounceTextContent(node) : null, [node]),
136
+ isHorizontalSwipe = ["left", "right", "horizontal"].includes(context.swipeDirection),
137
+ {
138
+ animationDriver
139
+ } = (0, import_gui_core.useConfiguration)();
140
+ if (!animationDriver) throw new Error("Must set animations in tamagui.config.ts");
141
+ const {
142
+ useAnimatedNumber,
143
+ useAnimatedNumberStyle
144
+ } = animationDriver,
145
+ animatedNumber = useAnimatedNumber(0),
146
+ AnimatedView = animationDriver.NumberView ?? animationDriver.View ?? import_gui_core.View,
147
+ animatedStyles = useAnimatedNumberStyle(animatedNumber, val => {
148
+ "worklet";
149
+
150
+ return {
151
+ transform: [isHorizontalSwipe ? {
152
+ translateX: val
153
+ } : {
154
+ translateY: val
155
+ }]
156
+ };
157
+ }),
158
+ panResponder = React.useMemo(() => import_react_native.PanResponder.create({
159
+ onMoveShouldSetPanResponder: (e, gesture) => shouldGrantGestureMove(context.swipeDirection, gesture) ? (onSwipeStart?.(e), !0) : !1,
160
+ onPanResponderGrant: e => {
161
+ import_gui_constants.isWeb || handlePause?.();
162
+ },
163
+ onPanResponderMove: (e, gesture) => {
164
+ const {
165
+ x,
166
+ y
167
+ } = getGestureDistance(context.swipeDirection, gesture),
168
+ delta = {
169
+ x,
170
+ y
171
+ };
172
+ animatedNumber.setValue(isHorizontalSwipe ? x : y, {
173
+ type: "direct"
174
+ }), isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold) && onSwipeEnd?.(e), onSwipeMove?.(e);
175
+ },
176
+ onPanResponderEnd: (e, {
177
+ dx,
178
+ dy
179
+ }) => {
180
+ isDeltaInDirection({
181
+ x: dx,
182
+ y: dy
183
+ }, context.swipeDirection, context.swipeThreshold) || (import_gui_constants.isWeb || handleResume?.(), onSwipeCancel?.(e), animatedNumber.setValue(0, {
184
+ type: "spring"
185
+ }));
186
+ }
187
+ }), [handlePause, handleResume]),
188
+ themeName = (0, import_gui_core.useThemeName)();
189
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
190
+ children: [announceTextContent && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounce, {
191
+ scope,
192
+ role: "status",
193
+ "aria-live": type === "foreground" ? "assertive" : "polite",
194
+ "aria-atomic": !0,
195
+ children: announceTextContent
196
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_portal.PortalItem, {
197
+ hostName: viewportName ?? "default",
198
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastInteractiveProvider, {
199
+ scope,
200
+ onClose: () => {
201
+ handleClose();
202
+ },
203
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_dismissable.Dismissable, {
204
+ onEscapeKeyDown: (0, import_gui_helpers.composeEventHandlers)(onEscapeKeyDown, () => {
205
+ context.isFocusedToastEscapeKeyDownRef.current || handleClose(), context.isFocusedToastEscapeKeyDownRef.current = !1;
206
+ }),
207
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.Theme, {
208
+ contain: !0,
209
+ forceClassName: !0,
210
+ name: themeName,
211
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
212
+ ...panResponder?.panHandlers,
213
+ style: [{
214
+ margin: "auto"
215
+ }, animatedStyles],
216
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.ItemSlot, {
217
+ scope: context.toastScope,
218
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastImplFrame, {
219
+ role: "status",
220
+ "aria-live": "off",
221
+ "aria-atomic": !0,
222
+ "data-state": open ? "open" : "closed",
223
+ "data-swipe-direction": context.swipeDirection,
224
+ pointerEvents: "auto",
225
+ "$platform-web": {
226
+ touchAction: "none",
227
+ userSelect: "none"
228
+ },
229
+ ...toastProps,
230
+ ref: composedRefs,
231
+ ...(import_gui_constants.isWeb && {
232
+ onKeyDown: (0, import_gui_helpers.composeEventHandlers)(props.onKeyDown, event => {
233
+ event.key === "Escape" && (onEscapeKeyDown?.(event), event.defaultPrevented || (context.isFocusedToastEscapeKeyDownRef.current = !0, handleClose()));
234
+ })
235
+ })
236
+ })
237
+ })
238
+ })
239
+ })
240
+ })
241
+ }, props.id)
242
+ })]
243
+ });
244
+ });
245
+ ToastImpl.propTypes = {
246
+ type(props) {
247
+ if (props.type && !["foreground", "background"].includes(props.type)) {
248
+ const error = `Invalid prop \`type\` supplied to \`${import_constants.TOAST_NAME}\`. Expected \`foreground | background\`.`;
249
+ return new Error(error);
250
+ }
251
+ return null;
252
+ }
253
+ };
254
+ const isDeltaInDirection = (delta, direction, threshold = 0) => {
255
+ const deltaX = Math.abs(delta.x),
256
+ deltaY = Math.abs(delta.y),
257
+ isDeltaX = deltaX > deltaY;
258
+ return direction === "left" || direction === "right" || direction === "horizontal" ? isDeltaX && deltaX > threshold : !isDeltaX && deltaY > threshold;
259
+ };
260
+ function getAnnounceTextContent(container) {
261
+ if (!import_gui_constants.isWeb) return "";
262
+ const textContent = [];
263
+ return Array.from(container.childNodes).forEach(node => {
264
+ if (node.nodeType === node.TEXT_NODE && node.textContent && textContent.push(node.textContent), isHTMLElement(node)) {
265
+ const isHidden = node.ariaHidden || node.hidden || node.style.display === "none",
266
+ isExcluded = node.dataset.toastAnnounceExclude === "";
267
+ if (!isHidden) if (isExcluded) {
268
+ const altText = node.dataset.toastAnnounceAlt;
269
+ altText && textContent.push(altText);
270
+ } else textContent.push(...getAnnounceTextContent(node));
271
+ }
272
+ }), textContent;
273
+ }
274
+ function isHTMLElement(node) {
275
+ return node.nodeType === node.ELEMENT_NODE;
276
+ }
277
+ const GESTURE_GRANT_THRESHOLD = 10,
278
+ shouldGrantGestureMove = (dir, {
279
+ dx,
280
+ dy
281
+ }) => (dir === "horizontal" || dir === "left") && dx < -GESTURE_GRANT_THRESHOLD || (dir === "horizontal" || dir === "right") && dx > GESTURE_GRANT_THRESHOLD || (dir === "vertical" || dir === "up") && dy > -GESTURE_GRANT_THRESHOLD || (dir === "vertical" || dir === "down") && dy < GESTURE_GRANT_THRESHOLD,
282
+ getGestureDistance = (dir, {
283
+ dx,
284
+ dy
285
+ }) => {
286
+ let y = 0,
287
+ x = 0;
288
+ return dir === "horizontal" ? x = dx : dir === "left" ? x = Math.min(0, dx) : dir === "right" ? x = Math.max(0, dx) : dir === "vertical" ? y = dy : dir === "up" ? y = Math.min(0, dy) : dir === "down" && (y = Math.max(0, dy)), {
289
+ x,
290
+ y
291
+ };
292
+ };