@tamagui/toast 1.114.3 → 1.115.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 (36) hide show
  1. package/dist/cjs/Toast.cjs +166 -0
  2. package/dist/cjs/ToastAnnounce.cjs +98 -0
  3. package/dist/cjs/ToastImperative.cjs +96 -0
  4. package/dist/cjs/ToastImpl.cjs +288 -0
  5. package/dist/cjs/ToastPortal.cjs +42 -0
  6. package/dist/cjs/ToastProvider.cjs +144 -0
  7. package/dist/cjs/ToastViewport.cjs +277 -0
  8. package/dist/cjs/constants.cjs +28 -0
  9. package/dist/cjs/createNativeToast.cjs +51 -0
  10. package/dist/cjs/createNativeToast.native.cjs +39 -0
  11. package/dist/cjs/createNativeToast.native.cjs.map +6 -0
  12. package/dist/cjs/index.cjs +18 -0
  13. package/dist/cjs/types.cjs +16 -0
  14. package/package.json +18 -17
  15. package/dist/cjs/Toast.js +0 -126
  16. package/dist/cjs/ToastAnnounce.js +0 -70
  17. package/dist/cjs/ToastImperative.js +0 -66
  18. package/dist/cjs/ToastImpl.js +0 -225
  19. package/dist/cjs/ToastPortal.js +0 -28
  20. package/dist/cjs/ToastProvider.js +0 -101
  21. package/dist/cjs/ToastViewport.js +0 -256
  22. package/dist/cjs/constants.js +0 -22
  23. package/dist/cjs/createNativeToast.js +0 -44
  24. package/dist/cjs/index.js +0 -15
  25. package/dist/cjs/types.js +0 -14
  26. /package/dist/cjs/{Toast.js.map → Toast.cjs.map} +0 -0
  27. /package/dist/cjs/{ToastAnnounce.js.map → ToastAnnounce.cjs.map} +0 -0
  28. /package/dist/cjs/{ToastImperative.js.map → ToastImperative.cjs.map} +0 -0
  29. /package/dist/cjs/{ToastImpl.js.map → ToastImpl.cjs.map} +0 -0
  30. /package/dist/cjs/{ToastPortal.js.map → ToastPortal.cjs.map} +0 -0
  31. /package/dist/cjs/{ToastProvider.js.map → ToastProvider.cjs.map} +0 -0
  32. /package/dist/cjs/{ToastViewport.js.map → ToastViewport.cjs.map} +0 -0
  33. /package/dist/cjs/{constants.js.map → constants.cjs.map} +0 -0
  34. /package/dist/cjs/{createNativeToast.js.map → createNativeToast.cjs.map} +0 -0
  35. /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
  36. /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
@@ -0,0 +1,166 @@
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 Toast_exports = {};
33
+ __export(Toast_exports, {
34
+ Toast: () => Toast,
35
+ ToastProvider: () => import_ToastProvider.ToastProvider,
36
+ ToastViewport: () => import_ToastViewport.ToastViewport,
37
+ useToast: () => import_ToastImperative.useToast,
38
+ useToastController: () => import_ToastImperative.useToastController,
39
+ useToastState: () => import_ToastImperative.useToastState
40
+ });
41
+ module.exports = __toCommonJS(Toast_exports);
42
+ var import_core = require("@tamagui/core"),
43
+ import_helpers = require("@tamagui/helpers"),
44
+ import_stacks = require("@tamagui/stacks"),
45
+ import_text = require("@tamagui/text"),
46
+ import_use_controllable_state = require("@tamagui/use-controllable-state"),
47
+ React = __toESM(require("react")),
48
+ import_constants = require("./constants.cjs"),
49
+ import_ToastAnnounce = require("./ToastAnnounce.cjs"),
50
+ import_ToastImperative = require("./ToastImperative.cjs"),
51
+ import_ToastImpl = require("./ToastImpl.cjs"),
52
+ import_ToastProvider = require("./ToastProvider.cjs"),
53
+ import_ToastViewport = require("./ToastViewport.cjs"),
54
+ import_jsx_runtime = require("react/jsx-runtime");
55
+ const TITLE_NAME = "ToastTitle",
56
+ ToastTitle = (0, import_core.styled)(import_text.SizableText, {
57
+ name: TITLE_NAME,
58
+ variants: {
59
+ unstyled: {
60
+ false: {
61
+ color: "$color",
62
+ size: "$4"
63
+ }
64
+ }
65
+ },
66
+ defaultVariants: {
67
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
68
+ }
69
+ });
70
+ ToastTitle.displayName = TITLE_NAME;
71
+ const DESCRIPTION_NAME = "ToastDescription",
72
+ ToastDescription = (0, import_core.styled)(import_text.SizableText, {
73
+ name: DESCRIPTION_NAME,
74
+ variants: {
75
+ unstyled: {
76
+ false: {
77
+ color: "$color11",
78
+ size: "$1"
79
+ }
80
+ }
81
+ },
82
+ defaultVariants: {
83
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
84
+ }
85
+ });
86
+ ToastDescription.displayName = DESCRIPTION_NAME;
87
+ const ACTION_NAME = "ToastAction",
88
+ ToastAction = React.forwardRef((props, forwardedRef) => {
89
+ const {
90
+ altText,
91
+ ...actionProps
92
+ } = props;
93
+ return altText ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounceExclude, {
94
+ altText,
95
+ asChild: !0,
96
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastClose, {
97
+ ...actionProps,
98
+ ref: forwardedRef
99
+ })
100
+ }) : null;
101
+ });
102
+ ToastAction.propTypes = {
103
+ altText(props) {
104
+ return props.altText ? null : new Error(`Missing prop \`altText\` expected on \`${ACTION_NAME}\``);
105
+ }
106
+ };
107
+ ToastAction.displayName = ACTION_NAME;
108
+ const CLOSE_NAME = "ToastClose",
109
+ ToastCloseFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
110
+ name: CLOSE_NAME,
111
+ tag: "button"
112
+ }),
113
+ ToastClose = React.forwardRef((props, forwardedRef) => {
114
+ const {
115
+ __scopeToast,
116
+ ...closeProps
117
+ } = props,
118
+ interactiveContext = (0, import_ToastImpl.useToastInteractiveContext)(__scopeToast);
119
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounceExclude, {
120
+ asChild: !0,
121
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCloseFrame, {
122
+ accessibilityLabel: "Dialog Close",
123
+ ...closeProps,
124
+ ref: forwardedRef,
125
+ onPress: (0, import_helpers.composeEventHandlers)(props.onPress, interactiveContext.onClose)
126
+ })
127
+ });
128
+ });
129
+ ToastClose.displayName = CLOSE_NAME;
130
+ const ToastComponent = import_ToastImpl.ToastImplFrame.styleable((props, forwardedRef) => {
131
+ const {
132
+ forceMount,
133
+ open: openProp,
134
+ defaultOpen,
135
+ onOpenChange,
136
+ ...toastProps
137
+ } = props,
138
+ [open, setOpen] = (0, import_use_controllable_state.useControllableState)({
139
+ prop: openProp,
140
+ defaultProp: defaultOpen ?? !0,
141
+ onChange: onOpenChange,
142
+ strategy: "most-recent-wins"
143
+ }),
144
+ id = React.useId(),
145
+ onPause = (0, import_core.useEvent)(props.onPause),
146
+ onResume = (0, import_core.useEvent)(props.onResume);
147
+ return forceMount || open ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastImpl.ToastImpl, {
148
+ id,
149
+ open,
150
+ ...toastProps,
151
+ ref: forwardedRef,
152
+ onClose: () => setOpen(!1),
153
+ onPause,
154
+ onResume,
155
+ onSwipeEnd: (0, import_helpers.composeEventHandlers)(props.onSwipeEnd, event => {
156
+ setOpen(!1);
157
+ })
158
+ }) : null;
159
+ });
160
+ ToastComponent.displayName = import_constants.TOAST_NAME;
161
+ const Toast = (0, import_helpers.withStaticProperties)(ToastComponent, {
162
+ Title: ToastTitle,
163
+ Description: ToastDescription,
164
+ Action: ToastAction,
165
+ Close: ToastClose
166
+ });
@@ -0,0 +1,98 @@
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 ToastAnnounce_exports = {};
33
+ __export(ToastAnnounce_exports, {
34
+ ToastAnnounce: () => ToastAnnounce,
35
+ ToastAnnounceExclude: () => ToastAnnounceExclude
36
+ });
37
+ module.exports = __toCommonJS(ToastAnnounce_exports);
38
+ var import_constants = require("@tamagui/constants"),
39
+ import_core = require("@tamagui/core"),
40
+ import_start_transition = require("@tamagui/start-transition"),
41
+ import_portal = require("@tamagui/portal"),
42
+ import_visually_hidden = require("@tamagui/visually-hidden"),
43
+ React = __toESM(require("react")),
44
+ import_ToastProvider = require("./ToastProvider.cjs"),
45
+ import_jsx_runtime = require("react/jsx-runtime");
46
+ const ToastAnnounceExcludeFrame = (0, import_core.styled)(import_core.Stack, {
47
+ name: "ToastAnnounceExclude"
48
+ }),
49
+ ToastAnnounceExclude = React.forwardRef((props, forwardedRef) => {
50
+ const {
51
+ altText,
52
+ ...announceExcludeProps
53
+ } = props;
54
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastAnnounceExcludeFrame, {
55
+ "data-toast-announce-exclude": "",
56
+ "data-toast-announce-alt": altText || void 0,
57
+ ...announceExcludeProps,
58
+ ref: forwardedRef
59
+ });
60
+ }),
61
+ ToastAnnounce = props => {
62
+ const {
63
+ __scopeToast,
64
+ children,
65
+ ...announceProps
66
+ } = props,
67
+ context = (0, import_ToastProvider.useToastProviderContext)(__scopeToast),
68
+ [renderAnnounceText, setRenderAnnounceText] = React.useState(!1),
69
+ [isAnnounced, setIsAnnounced] = React.useState(!1);
70
+ return useNextFrame(() => {
71
+ (0, import_start_transition.startTransition)(() => {
72
+ setRenderAnnounceText(!0);
73
+ });
74
+ }), React.useEffect(() => {
75
+ const timer = setTimeout(() => setIsAnnounced(!0), 1e3);
76
+ return () => clearTimeout(timer);
77
+ }, []), isAnnounced ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
78
+ asChild: !0,
79
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_visually_hidden.VisuallyHidden, {
80
+ ...announceProps,
81
+ children: renderAnnounceText && /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_core.Text, {
82
+ children: [context.label, " ", children]
83
+ })
84
+ })
85
+ });
86
+ };
87
+ function useNextFrame(callback = () => {}) {
88
+ const fn = (0, import_core.useEvent)(callback);
89
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
90
+ let raf1 = 0,
91
+ raf2 = 0;
92
+ return raf1 = requestAnimationFrame(() => {
93
+ raf2 = requestAnimationFrame(fn);
94
+ }), () => {
95
+ cancelAnimationFrame(raf1), cancelAnimationFrame(raf2);
96
+ };
97
+ }, [fn]);
98
+ }
@@ -0,0 +1,96 @@
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_react = __toESM(require("react")),
41
+ import_core = require("@tamagui/core"),
42
+ import_react_native = require("react-native-web"),
43
+ import_createNativeToast = require("./createNativeToast.cjs"),
44
+ import_jsx_runtime = require("react/jsx-runtime");
45
+ const ToastContext = import_react.default.createContext({}),
46
+ ToastCurrentContext = import_react.default.createContext(null),
47
+ useToastController = () => import_react.default.useContext(ToastContext),
48
+ useToastState = () => import_react.default.useContext(ToastCurrentContext),
49
+ useToast = () => ({
50
+ ...useToastController(),
51
+ currentToast: useToastState()
52
+ }),
53
+ ToastImperativeProvider = ({
54
+ children,
55
+ options
56
+ }) => {
57
+ const counterRef = import_react.default.useRef(0),
58
+ [toast, setToast] = import_react.default.useState(null),
59
+ [lastNativeToastRef, setLastNativeToastRef] = import_react.default.useState(null),
60
+ show = import_react.default.useCallback((title, showOptions) => {
61
+ const native = showOptions?.native ?? options.native,
62
+ isWebNative = Array.isArray(native) ? native.includes("web") : native === "web",
63
+ isMobileNative = Array.isArray(native) ? native.includes("mobile") : native === "mobile",
64
+ isAndroidNative = isMobileNative || (Array.isArray(native) ? native.includes("android") : native === "android"),
65
+ isIosNative = isMobileNative || (Array.isArray(native) ? native.includes("ios") : native === "ios"),
66
+ isHandledNatively = native === !0 || import_core.isWeb && isWebNative || !import_core.isWeb && isMobileNative || import_react_native.Platform.OS === "android" && isAndroidNative || import_react_native.Platform.OS === "ios" && isIosNative;
67
+ if (isHandledNatively) {
68
+ const nativeToastResult = (0, import_createNativeToast.createNativeToast)(title, showOptions ?? {});
69
+ typeof nativeToastResult == "object" && nativeToastResult.nativeToastRef && setLastNativeToastRef(nativeToastResult.nativeToastRef);
70
+ }
71
+ return counterRef.current++, setToast({
72
+ ...showOptions?.customData,
73
+ ...showOptions,
74
+ viewportName: showOptions?.viewportName ?? "default",
75
+ title,
76
+ id: counterRef.current.toString(),
77
+ isHandledNatively
78
+ }), !0;
79
+ }, [setToast, JSON.stringify(options.native || null)]),
80
+ hide = import_react.default.useCallback(() => {
81
+ lastNativeToastRef?.close(), setToast(null);
82
+ }, [setToast, lastNativeToastRef]),
83
+ contextValue = import_react.default.useMemo(() => ({
84
+ show,
85
+ hide,
86
+ nativeToast: lastNativeToastRef,
87
+ options
88
+ }), [show, hide, lastNativeToastRef, JSON.stringify(options || null)]);
89
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastContext.Provider, {
90
+ value: contextValue,
91
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastCurrentContext.Provider, {
92
+ value: toast,
93
+ children
94
+ })
95
+ });
96
+ };
@@ -0,0 +1,288 @@
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_animate_presence = require("@tamagui/animate-presence"),
40
+ import_compose_refs = require("@tamagui/compose-refs"),
41
+ import_constants = require("@tamagui/constants"),
42
+ import_core = require("@tamagui/core"),
43
+ import_dismissable = require("@tamagui/dismissable"),
44
+ import_helpers = require("@tamagui/helpers"),
45
+ import_portal = require("@tamagui/portal"),
46
+ import_stacks = require("@tamagui/stacks"),
47
+ React = __toESM(require("react")),
48
+ import_react_native = require("react-native-web"),
49
+ import_constants2 = 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_core.styled)(import_stacks.ThemeableStack, {
55
+ name: "ToastImpl",
56
+ focusable: !0,
57
+ variants: {
58
+ unstyled: {
59
+ false: {
60
+ focusStyle: {
61
+ outlineStyle: "solid",
62
+ outlineWidth: 2,
63
+ outlineColor: "$outlineColor"
64
+ },
65
+ backgroundColor: "$color6",
66
+ borderRadius: "$10",
67
+ paddingHorizontal: "$5",
68
+ paddingVertical: "$2",
69
+ marginHorizontal: "auto",
70
+ marginVertical: "$1"
71
+ }
72
+ }
73
+ },
74
+ defaultVariants: {
75
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
76
+ }
77
+ }),
78
+ {
79
+ Provider: ToastInteractiveProvider,
80
+ useStyledContext: useToastInteractiveContext
81
+ } = (0, import_core.createStyledContext)({
82
+ onClose() {}
83
+ }),
84
+ ToastImpl = React.forwardRef((props, forwardedRef) => {
85
+ const {
86
+ __scopeToast,
87
+ type = "foreground",
88
+ duration: durationProp,
89
+ open,
90
+ onClose,
91
+ onEscapeKeyDown,
92
+ onPause,
93
+ onResume,
94
+ onSwipeStart,
95
+ onSwipeMove,
96
+ onSwipeCancel,
97
+ onSwipeEnd,
98
+ viewportName = "default",
99
+ ...toastProps
100
+ } = props,
101
+ isPresent = (0, import_animate_presence.useIsPresent)(),
102
+ context = (0, import_ToastProvider.useToastProviderContext)(__scopeToast),
103
+ [node, setNode] = React.useState(null),
104
+ composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, node2 => setNode(node2)),
105
+ duration = durationProp || context.duration,
106
+ closeTimerStartTimeRef = React.useRef(0),
107
+ closeTimerRemainingTimeRef = React.useRef(duration),
108
+ closeTimerRef = React.useRef(0),
109
+ {
110
+ onToastAdd,
111
+ onToastRemove
112
+ } = context,
113
+ viewport = React.useMemo(() => context.viewports[viewportName], [context.viewports, viewportName]),
114
+ handleClose = (0, import_core.useEvent)(() => {
115
+ isPresent && (import_constants.isWeb && node?.contains(document.activeElement) && viewport?.focus(), onClose());
116
+ }),
117
+ startTimer = React.useCallback(duration2 => {
118
+ !duration2 || duration2 === Number.POSITIVE_INFINITY || (clearTimeout(closeTimerRef.current), closeTimerStartTimeRef.current = (/* @__PURE__ */new Date()).getTime(), closeTimerRef.current = setTimeout(handleClose, duration2));
119
+ }, [handleClose]),
120
+ handleResume = React.useCallback(() => {
121
+ startTimer(closeTimerRemainingTimeRef.current), onResume?.();
122
+ }, [onResume, startTimer]),
123
+ handlePause = React.useCallback(() => {
124
+ const elapsedTime = (/* @__PURE__ */new Date()).getTime() - closeTimerStartTimeRef.current;
125
+ closeTimerRemainingTimeRef.current = closeTimerRemainingTimeRef.current - elapsedTime, window.clearTimeout(closeTimerRef.current), onPause?.();
126
+ }, [onPause]);
127
+ React.useEffect(() => {
128
+ if (import_constants.isWeb && viewport) return viewport.addEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause), viewport.addEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume), () => {
129
+ viewport.removeEventListener(import_ToastViewport.VIEWPORT_PAUSE, handlePause), viewport.removeEventListener(import_ToastViewport.VIEWPORT_RESUME, handleResume);
130
+ };
131
+ }, [viewport, duration, onPause, onResume, startTimer]), React.useEffect(() => {
132
+ open && !context.isClosePausedRef.current && startTimer(duration);
133
+ }, [open, duration, context.isClosePausedRef, startTimer]), React.useEffect(() => (onToastAdd(), () => onToastRemove()), [onToastAdd, onToastRemove]);
134
+ const announceTextContent = React.useMemo(() => import_constants.isWeb && node ? getAnnounceTextContent(node) : null, [node]),
135
+ isHorizontalSwipe = ["left", "right", "horizontal"].includes(context.swipeDirection),
136
+ {
137
+ animationDriver
138
+ } = (0, import_core.useConfiguration)();
139
+ if (!animationDriver) throw new Error("Must set animations in tamagui.config.ts");
140
+ const {
141
+ useAnimatedNumber,
142
+ useAnimatedNumberStyle
143
+ } = animationDriver,
144
+ animatedNumber = useAnimatedNumber(0),
145
+ AnimatedView = animationDriver.NumberView ?? animationDriver.View ?? import_core.Stack,
146
+ animatedStyles = useAnimatedNumberStyle(animatedNumber, val => {
147
+ "worklet";
148
+
149
+ return {
150
+ transform: [isHorizontalSwipe ? {
151
+ translateX: val
152
+ } : {
153
+ translateY: val
154
+ }]
155
+ };
156
+ }),
157
+ panResponder = React.useMemo(() => import_react_native.PanResponder.create({
158
+ onMoveShouldSetPanResponder: (e, gesture) => shouldGrantGestureMove(context.swipeDirection, gesture) ? (onSwipeStart?.(e), !0) : !1,
159
+ onPanResponderGrant: e => {
160
+ import_constants.isWeb || handlePause?.();
161
+ },
162
+ onPanResponderMove: (e, gesture) => {
163
+ const {
164
+ x,
165
+ y
166
+ } = getGestureDistance(context.swipeDirection, gesture),
167
+ delta = {
168
+ x,
169
+ y
170
+ };
171
+ animatedNumber.setValue(isHorizontalSwipe ? x : y, {
172
+ type: "direct"
173
+ }), isDeltaInDirection(delta, context.swipeDirection, context.swipeThreshold) && onSwipeEnd?.(e), onSwipeMove?.(e);
174
+ },
175
+ onPanResponderEnd: (e, {
176
+ dx,
177
+ dy
178
+ }) => {
179
+ isDeltaInDirection({
180
+ x: dx,
181
+ y: dy
182
+ }, context.swipeDirection, context.swipeThreshold) || (import_constants.isWeb || handleResume?.(), onSwipeCancel?.(e), animatedNumber.setValue(0, {
183
+ type: "spring"
184
+ }));
185
+ }
186
+ }), [handlePause, handleResume]),
187
+ themeName = (0, import_core.useThemeName)();
188
+ return /* @__PURE__ */(0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
189
+ children: [announceTextContent && /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastAnnounce.ToastAnnounce, {
190
+ __scopeToast,
191
+ role: "status",
192
+ "aria-live": type === "foreground" ? "assertive" : "polite",
193
+ "aria-atomic": !0,
194
+ children: announceTextContent
195
+ }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.PortalItem, {
196
+ hostName: viewportName ?? "default",
197
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastInteractiveProvider, {
198
+ scope: __scopeToast,
199
+ onClose: () => {
200
+ handleClose();
201
+ },
202
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_dismissable.Dismissable, {
203
+ onEscapeKeyDown: (0, import_helpers.composeEventHandlers)(onEscapeKeyDown, () => {
204
+ context.isFocusedToastEscapeKeyDownRef.current || handleClose(), context.isFocusedToastEscapeKeyDownRef.current = !1;
205
+ }),
206
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
207
+ forceClassName: !0,
208
+ name: themeName,
209
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(AnimatedView, {
210
+ ...panResponder?.panHandlers,
211
+ style: [{
212
+ margin: "auto"
213
+ }, animatedStyles],
214
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_ToastProvider.Collection.ItemSlot, {
215
+ __scopeCollection: __scopeToast || import_constants2.TOAST_CONTEXT,
216
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ToastImplFrame, {
217
+ role: "status",
218
+ "aria-live": "off",
219
+ "aria-atomic": !0,
220
+ "data-state": open ? "open" : "closed",
221
+ "data-swipe-direction": context.swipeDirection,
222
+ pointerEvents: "auto",
223
+ touchAction: "none",
224
+ userSelect: "none",
225
+ ...toastProps,
226
+ ref: composedRefs,
227
+ ...(import_constants.isWeb && {
228
+ onKeyDown: (0, import_helpers.composeEventHandlers)(props.onKeyDown, event => {
229
+ event.key === "Escape" && (onEscapeKeyDown?.(event), onEscapeKeyDown?.(event), event.defaultPrevented || (context.isFocusedToastEscapeKeyDownRef.current = !0, handleClose()));
230
+ })
231
+ })
232
+ })
233
+ })
234
+ })
235
+ })
236
+ })
237
+ }, props.id)
238
+ })]
239
+ });
240
+ });
241
+ ToastImpl.propTypes = {
242
+ type(props) {
243
+ if (props.type && !["foreground", "background"].includes(props.type)) {
244
+ const error = `Invalid prop \`type\` supplied to \`${import_constants2.TOAST_NAME}\`. Expected \`foreground | background\`.`;
245
+ return new Error(error);
246
+ }
247
+ return null;
248
+ }
249
+ };
250
+ const isDeltaInDirection = (delta, direction, threshold = 0) => {
251
+ const deltaX = Math.abs(delta.x),
252
+ deltaY = Math.abs(delta.y),
253
+ isDeltaX = deltaX > deltaY;
254
+ return direction === "left" || direction === "right" || direction === "horizontal" ? isDeltaX && deltaX > threshold : !isDeltaX && deltaY > threshold;
255
+ };
256
+ function getAnnounceTextContent(container) {
257
+ if (!import_constants.isWeb) return "";
258
+ const textContent = [];
259
+ return Array.from(container.childNodes).forEach(node => {
260
+ if (node.nodeType === node.TEXT_NODE && node.textContent && textContent.push(node.textContent), isHTMLElement(node)) {
261
+ const isHidden = node.ariaHidden || node.hidden || node.style.display === "none",
262
+ isExcluded = node.dataset.toastAnnounceExclude === "";
263
+ if (!isHidden) if (isExcluded) {
264
+ const altText = node.dataset.toastAnnounceAlt;
265
+ altText && textContent.push(altText);
266
+ } else textContent.push(...getAnnounceTextContent(node));
267
+ }
268
+ }), textContent;
269
+ }
270
+ function isHTMLElement(node) {
271
+ return node.nodeType === node.ELEMENT_NODE;
272
+ }
273
+ const GESTURE_GRANT_THRESHOLD = 10,
274
+ shouldGrantGestureMove = (dir, {
275
+ dx,
276
+ dy
277
+ }) => (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,
278
+ getGestureDistance = (dir, {
279
+ dx,
280
+ dy
281
+ }) => {
282
+ let y = 0,
283
+ x = 0;
284
+ 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)), {
285
+ x,
286
+ y
287
+ };
288
+ };