@zag-js/toast 2.0.0-next.3 → 2.0.0-next.4

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 (45) hide show
  1. package/dist/index.d.mts +10 -17
  2. package/dist/index.d.ts +10 -17
  3. package/dist/index.js +18 -45
  4. package/dist/index.mjs +5 -11
  5. package/dist/toast-group.connect.d.mts +4 -8
  6. package/dist/toast-group.connect.d.ts +4 -8
  7. package/dist/toast-group.connect.js +82 -103
  8. package/dist/toast-group.connect.mjs +77 -67
  9. package/dist/toast-group.machine.d.mts +2 -8
  10. package/dist/toast-group.machine.d.ts +2 -8
  11. package/dist/toast-group.machine.js +295 -290
  12. package/dist/toast-group.machine.mjs +290 -254
  13. package/dist/toast.anatomy.d.mts +2 -6
  14. package/dist/toast.anatomy.d.ts +2 -6
  15. package/dist/toast.anatomy.js +8 -40
  16. package/dist/toast.anatomy.mjs +4 -14
  17. package/dist/toast.connect.d.mts +4 -8
  18. package/dist/toast.connect.d.ts +4 -8
  19. package/dist/toast.connect.js +176 -160
  20. package/dist/toast.connect.mjs +171 -124
  21. package/dist/toast.dom.d.mts +21 -14
  22. package/dist/toast.dom.d.ts +21 -14
  23. package/dist/toast.dom.js +50 -48
  24. package/dist/toast.dom.mjs +35 -17
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +404 -288
  28. package/dist/toast.machine.mjs +400 -253
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +345 -263
  32. package/dist/toast.store.mjs +341 -238
  33. package/dist/toast.types.d.mts +460 -427
  34. package/dist/toast.types.d.ts +460 -427
  35. package/dist/toast.types.js +4 -18
  36. package/dist/toast.types.mjs +1 -0
  37. package/dist/toast.utils.d.mts +10 -13
  38. package/dist/toast.utils.d.ts +10 -13
  39. package/dist/toast.utils.js +185 -198
  40. package/dist/toast.utils.mjs +175 -168
  41. package/dist/utils/swipe.d.mts +16 -0
  42. package/dist/utils/swipe.d.ts +16 -0
  43. package/dist/utils/swipe.js +100 -0
  44. package/dist/utils/swipe.mjs +93 -0
  45. package/package.json +8 -8
@@ -1,292 +1,297 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/toast-group.machine.ts
31
- var toast_group_machine_exports = {};
32
- __export(toast_group_machine_exports, {
33
- groupMachine: () => groupMachine
34
- });
35
- module.exports = __toCommonJS(toast_group_machine_exports);
36
- var import_core = require("@zag-js/core");
37
- var import_dismissable = require("@zag-js/dismissable");
38
- var import_dom_query = require("@zag-js/dom-query");
39
- var import_utils = require("@zag-js/utils");
40
- var dom = __toESM(require("./toast.dom.js"));
41
- var { guards, createMachine } = (0, import_core.setup)();
42
- var { and } = guards;
43
- var groupMachine = createMachine({
44
- props({ props }) {
45
- return {
46
- dir: "ltr",
47
- id: (0, import_utils.uuid)(),
48
- ...props,
49
- store: props.store
50
- };
51
- },
52
- initialState({ prop }) {
53
- return prop("store").attrs.overlap ? "overlap" : "stack";
54
- },
55
- refs() {
56
- return {
57
- lastFocusedEl: null,
58
- isFocusWithin: false,
59
- isPointerWithin: false,
60
- ignoreMouseTimer: import_dom_query.AnimationFrame.create(),
61
- dismissableCleanup: void 0
62
- };
63
- },
64
- context({ bindable }) {
65
- return {
66
- toasts: bindable(() => ({
67
- defaultValue: [],
68
- sync: true,
69
- hash: (toasts) => toasts.map((t) => t.id).join(",")
70
- })),
71
- heights: bindable(() => ({
72
- defaultValue: [],
73
- sync: true
74
- }))
75
- };
76
- },
77
- computed: {
78
- count: ({ context }) => context.get("toasts").length,
79
- overlap: ({ prop }) => prop("store").attrs.overlap,
80
- placement: ({ prop }) => prop("store").attrs.placement
81
- },
82
- effects: ["subscribeToStore", "trackDocumentVisibility", "trackHotKeyPress"],
83
- watch({ track, context, action }) {
84
- track([() => context.hash("toasts")], () => {
85
- queueMicrotask(() => {
86
- action(["collapsedIfEmpty", "setDismissableBranch"]);
87
- });
88
- });
89
- },
90
- exit: ["clearDismissableBranch", "clearLastFocusedEl", "clearMouseEventTimer"],
91
- on: {
92
- "DOC.HOTKEY": {
93
- actions: ["focusRegionEl"]
94
- },
95
- "REGION.BLUR": [
96
- {
97
- guard: and("isOverlapping", "isPointerOut"),
98
- target: "overlap",
99
- actions: ["collapseToasts", "resumeToasts", "restoreFocusIfPointerOut"]
100
- },
101
- {
102
- guard: "isPointerOut",
103
- target: "stack",
104
- actions: ["resumeToasts", "restoreFocusIfPointerOut"]
105
- },
106
- {
107
- actions: ["clearFocusWithin"]
108
- }
109
- ],
110
- "TOAST.REMOVE": {
111
- actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
112
- },
113
- "TOAST.PAUSE": {
114
- actions: ["pauseToasts"]
115
- }
116
- },
117
- states: {
118
- stack: {
119
- on: {
120
- "REGION.POINTER_LEAVE": [
121
- {
122
- guard: "isOverlapping",
123
- target: "overlap",
124
- actions: ["clearPointerWithin", "resumeToasts", "collapseToasts"]
125
- },
126
- {
127
- actions: ["clearPointerWithin", "resumeToasts"]
128
- }
129
- ],
130
- "REGION.OVERLAP": {
131
- target: "overlap",
132
- actions: ["collapseToasts"]
133
- },
134
- "REGION.FOCUS": {
135
- actions: ["setLastFocusedEl", "pauseToasts"]
136
- },
137
- "REGION.POINTER_ENTER": {
138
- actions: ["setPointerWithin", "pauseToasts"]
139
- }
140
- }
141
- },
142
- overlap: {
143
- on: {
144
- "REGION.STACK": {
145
- target: "stack",
146
- actions: ["expandToasts"]
147
- },
148
- "REGION.POINTER_ENTER": {
149
- target: "stack",
150
- actions: ["setPointerWithin", "pauseToasts", "expandToasts"]
151
- },
152
- "REGION.FOCUS": {
153
- target: "stack",
154
- actions: ["setLastFocusedEl", "pauseToasts", "expandToasts"]
155
- }
156
- }
157
- }
158
- },
159
- implementations: {
160
- guards: {
161
- isOverlapping: ({ computed }) => computed("overlap"),
162
- isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
163
- },
164
- effects: {
165
- subscribeToStore({ context, prop }) {
166
- const store = prop("store");
167
- context.set("toasts", store.getVisibleToasts());
168
- return store.subscribe((toast) => {
169
- if (toast.dismiss) {
170
- context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
171
- return;
172
- }
173
- context.set("toasts", (prev) => {
174
- const index = prev.findIndex((t) => t.id === toast.id);
175
- if (index !== -1) {
176
- return [...prev.slice(0, index), { ...prev[index], ...toast }, ...prev.slice(index + 1)];
177
- }
178
- return [toast, ...prev];
179
- });
180
- });
181
- },
182
- trackHotKeyPress({ prop, send }) {
183
- const handleKeyDown = (event) => {
184
- const { hotkey } = prop("store").attrs;
185
- const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
186
- if (!isHotkeyPressed) return;
187
- send({ type: "DOC.HOTKEY" });
188
- };
189
- return (0, import_dom_query.addDomEvent)(document, "keydown", handleKeyDown, { capture: true });
190
- },
191
- trackDocumentVisibility({ prop, send, scope }) {
192
- const { pauseOnPageIdle } = prop("store").attrs;
193
- if (!pauseOnPageIdle) return;
194
- const doc = scope.getDoc();
195
- return (0, import_dom_query.addDomEvent)(doc, "visibilitychange", () => {
196
- const isHidden = doc.visibilityState === "hidden";
197
- send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
198
- });
199
- }
200
- },
201
- actions: {
202
- setDismissableBranch({ refs, context, computed, scope }) {
203
- const toasts = context.get("toasts");
204
- const placement = computed("placement");
205
- const hasToasts = toasts.length > 0;
206
- if (!hasToasts) {
207
- refs.get("dismissableCleanup")?.();
208
- return;
209
- }
210
- if (hasToasts && refs.get("dismissableCleanup")) {
211
- return;
212
- }
213
- const groupEl = () => dom.getRegionEl(scope, placement);
214
- const cleanup = (0, import_dismissable.trackDismissableBranch)(groupEl, { defer: true });
215
- refs.set("dismissableCleanup", cleanup);
216
- },
217
- clearDismissableBranch({ refs }) {
218
- refs.get("dismissableCleanup")?.();
219
- },
220
- focusRegionEl({ scope, computed }) {
221
- queueMicrotask(() => {
222
- dom.getRegionEl(scope, computed("placement"))?.focus();
223
- });
224
- },
225
- pauseToasts({ prop }) {
226
- prop("store").pause();
227
- },
228
- resumeToasts({ prop }) {
229
- prop("store").resume();
230
- },
231
- expandToasts({ prop }) {
232
- prop("store").expand();
233
- },
234
- collapseToasts({ prop }) {
235
- prop("store").collapse();
236
- },
237
- removeToast({ prop, event }) {
238
- prop("store").remove(event.id);
239
- },
240
- removeHeight({ event, context }) {
241
- if (event?.id == null) return;
242
- queueMicrotask(() => {
243
- context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
244
- });
245
- },
246
- collapsedIfEmpty({ send, computed }) {
247
- if (!computed("overlap") || computed("count") > 1) return;
248
- send({ type: "REGION.OVERLAP" });
249
- },
250
- setLastFocusedEl({ refs, event }) {
251
- if (refs.get("isFocusWithin") || !event.target) return;
252
- refs.set("isFocusWithin", true);
253
- refs.set("lastFocusedEl", event.target);
254
- },
255
- restoreFocusIfPointerOut({ refs }) {
256
- if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
257
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
258
- refs.set("lastFocusedEl", null);
259
- refs.set("isFocusWithin", false);
260
- },
261
- setPointerWithin({ refs }) {
262
- refs.set("isPointerWithin", true);
263
- },
264
- clearPointerWithin({ refs }) {
265
- refs.set("isPointerWithin", false);
266
- if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
267
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
268
- refs.set("lastFocusedEl", null);
269
- }
270
- },
271
- clearFocusWithin({ refs }) {
272
- refs.set("isFocusWithin", false);
273
- },
274
- clearLastFocusedEl({ refs }) {
275
- if (!refs.get("lastFocusedEl")) return;
276
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
277
- refs.set("lastFocusedEl", null);
278
- refs.set("isFocusWithin", false);
279
- },
280
- ignoreMouseEventsTemporarily({ refs }) {
281
- refs.get("ignoreMouseTimer").request();
282
- },
283
- clearMouseEventTimer({ refs }) {
284
- refs.get("ignoreMouseTimer").cancel();
285
- }
286
- }
287
- }
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
288
4
  });
289
- // Annotate the CommonJS export names for ESM import in node:
290
- 0 && (module.exports = {
291
- groupMachine
5
+ const require_toast_dom = require("./toast.dom.js");
6
+ let _zag_js_dom_query = require("@zag-js/dom-query");
7
+ let _zag_js_utils = require("@zag-js/utils");
8
+ let _zag_js_core = require("@zag-js/core");
9
+ let _zag_js_dismissable = require("@zag-js/dismissable");
10
+ // src/toast-group.machine.ts
11
+ const { guards, createMachine } = (0, _zag_js_core.setup)();
12
+ const { and } = guards;
13
+ const groupMachine = createMachine({
14
+ props({ props }) {
15
+ return {
16
+ dir: "ltr",
17
+ id: (0, _zag_js_utils.uuid)(),
18
+ ...props,
19
+ store: props.store
20
+ };
21
+ },
22
+ initialState({ prop }) {
23
+ return prop("store").attrs.overlap ? "overlap" : "stack";
24
+ },
25
+ refs() {
26
+ return {
27
+ lastFocusedEl: null,
28
+ isFocusWithin: false,
29
+ isPointerWithin: false,
30
+ ignoreMouseTimer: _zag_js_dom_query.AnimationFrame.create(),
31
+ dismissableCleanup: void 0
32
+ };
33
+ },
34
+ context({ bindable }) {
35
+ return {
36
+ toasts: bindable(() => ({
37
+ defaultValue: [],
38
+ sync: true,
39
+ hash: (toasts) => toasts.map((t) => t.id).join(",")
40
+ })),
41
+ heights: bindable(() => ({
42
+ defaultValue: [],
43
+ sync: true
44
+ }))
45
+ };
46
+ },
47
+ computed: {
48
+ count: ({ context }) => context.get("toasts").length,
49
+ overlap: ({ prop }) => prop("store").attrs.overlap,
50
+ placement: ({ prop }) => prop("store").attrs.placement
51
+ },
52
+ effects: [
53
+ "subscribeToStore",
54
+ "subscribeToLayout",
55
+ "trackDocumentVisibility",
56
+ "trackHotKeyPress"
57
+ ],
58
+ watch({ track, context, action }) {
59
+ track([() => context.hash("toasts")], () => {
60
+ queueMicrotask(() => {
61
+ action([
62
+ "collapsedIfEmpty",
63
+ "setDismissableBranch",
64
+ "resetInteractionIfEmpty"
65
+ ]);
66
+ });
67
+ });
68
+ },
69
+ exit: [
70
+ "clearDismissableBranch",
71
+ "clearLastFocusedEl",
72
+ "clearMouseEventTimer"
73
+ ],
74
+ on: {
75
+ PAUSE_ALL: { actions: ["pauseToasts"] },
76
+ RESUME_ALL: { actions: ["resumeToasts"] },
77
+ "DOC.HOTKEY": { actions: ["focusRegionEl"] },
78
+ "REGION.BLUR": [
79
+ {
80
+ guard: and("isOverlapping", "isPointerOut"),
81
+ target: "overlap",
82
+ actions: ["resumeToasts", "restoreFocusIfPointerOut"]
83
+ },
84
+ {
85
+ guard: "isPointerOut",
86
+ target: "stack",
87
+ actions: ["resumeToasts", "restoreFocusIfPointerOut"]
88
+ },
89
+ { actions: ["clearFocusWithin"] }
90
+ ],
91
+ "TOAST.DISMISS": { actions: ["moveFocusOnDismiss"] },
92
+ "TOAST.REMOVE": { actions: [
93
+ "removeToast",
94
+ "removeHeight",
95
+ "ignoreMouseEventsTemporarily"
96
+ ] },
97
+ "TOAST.PAUSE": { actions: ["pauseToasts"] },
98
+ "TOAST.SWIPE_END": { actions: ["resumeToasts"] }
99
+ },
100
+ states: {
101
+ stack: { on: {
102
+ "REGION.POINTER_LEAVE": [{
103
+ guard: "isOverlapping",
104
+ target: "overlap",
105
+ actions: ["clearPointerWithin", "resumeToasts"]
106
+ }, { actions: ["clearPointerWithin", "resumeToasts"] }],
107
+ "REGION.OVERLAP": { target: "overlap" },
108
+ "REGION.FOCUS": { actions: ["setLastFocusedEl", "pauseToasts"] },
109
+ "REGION.POINTER_ENTER": { actions: ["setPointerWithin", "pauseToasts"] }
110
+ } },
111
+ overlap: { on: {
112
+ "REGION.STACK": { target: "stack" },
113
+ "REGION.POINTER_ENTER": {
114
+ target: "stack",
115
+ actions: ["setPointerWithin", "pauseToasts"]
116
+ },
117
+ "REGION.POINTER_LEAVE": { actions: ["clearPointerWithin", "resumeToasts"] },
118
+ "REGION.FOCUS": {
119
+ target: "stack",
120
+ actions: ["setLastFocusedEl", "pauseToasts"]
121
+ }
122
+ } }
123
+ },
124
+ implementations: {
125
+ guards: {
126
+ isOverlapping: ({ computed }) => computed("overlap"),
127
+ isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
128
+ },
129
+ effects: {
130
+ subscribeToStore({ context, prop }) {
131
+ const store = prop("store");
132
+ context.set("toasts", store.getVisibleToasts());
133
+ return store.subscribe((toast) => {
134
+ if (toast.dismiss) {
135
+ context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
136
+ return;
137
+ }
138
+ context.set("toasts", (prev) => {
139
+ const index = prev.findIndex((t) => t.id === toast.id);
140
+ if (index !== -1) return [
141
+ ...prev.slice(0, index),
142
+ {
143
+ ...prev[index],
144
+ ...toast
145
+ },
146
+ ...prev.slice(index + 1)
147
+ ];
148
+ return [toast, ...prev];
149
+ });
150
+ });
151
+ },
152
+ subscribeToLayout({ prop, send }) {
153
+ return prop("store").subscribeLayout((stacked) => {
154
+ send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
155
+ });
156
+ },
157
+ trackHotKeyPress({ prop, send }) {
158
+ const handleKeyDown = (event) => {
159
+ const { hotkey } = prop("store").attrs;
160
+ if (!hotkey.every((key) => event[key] || event.code === key)) return;
161
+ send({ type: "DOC.HOTKEY" });
162
+ };
163
+ return (0, _zag_js_dom_query.addDomEvent)(document, "keydown", handleKeyDown, { capture: true });
164
+ },
165
+ trackDocumentVisibility({ prop, send, scope }) {
166
+ const { pauseOnPageIdle } = prop("store").attrs;
167
+ if (!pauseOnPageIdle) return;
168
+ const doc = scope.getDoc();
169
+ if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
170
+ return (0, _zag_js_dom_query.addDomEvent)(doc, "visibilitychange", () => {
171
+ send({ type: doc.visibilityState === "hidden" ? "PAUSE_ALL" : "RESUME_ALL" });
172
+ });
173
+ }
174
+ },
175
+ actions: {
176
+ setDismissableBranch({ refs, context, computed, scope }) {
177
+ const toasts = context.get("toasts");
178
+ const placement = computed("placement");
179
+ const hasToasts = toasts.length > 0;
180
+ if (!hasToasts) {
181
+ refs.get("dismissableCleanup")?.();
182
+ refs.set("dismissableCleanup", void 0);
183
+ return;
184
+ }
185
+ if (hasToasts && refs.get("dismissableCleanup")) return;
186
+ const groupEl = () => require_toast_dom.getRegionEl(scope, placement);
187
+ const cleanup = (0, _zag_js_dismissable.trackDismissableBranch)(groupEl, {
188
+ defer: true,
189
+ getRootNode: scope.getRootNode
190
+ });
191
+ refs.set("dismissableCleanup", cleanup);
192
+ },
193
+ clearDismissableBranch({ refs }) {
194
+ refs.get("dismissableCleanup")?.();
195
+ refs.set("dismissableCleanup", void 0);
196
+ },
197
+ focusRegionEl({ scope, computed }) {
198
+ queueMicrotask(() => {
199
+ require_toast_dom.getRegionEl(scope, computed("placement"))?.focus();
200
+ });
201
+ },
202
+ pauseToasts({ prop }) {
203
+ prop("store").pause();
204
+ },
205
+ resumeToasts({ prop, refs, scope, event }) {
206
+ if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
207
+ if (prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden" || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
208
+ prop("store").resume();
209
+ },
210
+ removeToast({ prop, event }) {
211
+ prop("store").remove(event.id);
212
+ },
213
+ removeHeight({ event, context }) {
214
+ if (event?.id == null) return;
215
+ queueMicrotask(() => {
216
+ context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
217
+ });
218
+ },
219
+ collapsedIfEmpty({ send, computed }) {
220
+ if (!computed("overlap") || computed("count") > 1) return;
221
+ send({ type: "REGION.OVERLAP" });
222
+ },
223
+ setLastFocusedEl({ refs, event }) {
224
+ if (refs.get("isFocusWithin")) return;
225
+ refs.set("isFocusWithin", true);
226
+ refs.set("lastFocusedEl", event.target ?? null);
227
+ },
228
+ moveFocusOnDismiss({ refs, scope, computed, event }) {
229
+ if (event.focusVisible) {
230
+ const toastEls = require_toast_dom.getToastEls(scope, computed("placement"));
231
+ const index = toastEls.findIndex((el) => (0, _zag_js_dom_query.contains)(el, scope.getActiveElement()));
232
+ const nextEl = findOpenToast(toastEls, index + 1, 1) ?? findOpenToast(toastEls, index - 1, -1);
233
+ if (nextEl) {
234
+ nextEl.focus({ preventScroll: true });
235
+ return;
236
+ }
237
+ }
238
+ const lastFocusedEl = refs.get("lastFocusedEl");
239
+ if (event.focusVisible && lastFocusedEl) lastFocusedEl.focus({ preventScroll: true });
240
+ else scope.getActiveElement()?.blur();
241
+ },
242
+ resetInteractionIfEmpty({ refs, prop, scope, computed }) {
243
+ if (computed("count") > 0) return;
244
+ refs.set("isFocusWithin", false);
245
+ refs.set("isPointerWithin", false);
246
+ refs.set("lastFocusedEl", null);
247
+ if (!(prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden")) prop("store").resume();
248
+ },
249
+ restoreFocusIfPointerOut({ refs }) {
250
+ if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
251
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
252
+ refs.set("lastFocusedEl", null);
253
+ refs.set("isFocusWithin", false);
254
+ },
255
+ setPointerWithin({ refs }) {
256
+ refs.set("isPointerWithin", true);
257
+ },
258
+ clearPointerWithin({ refs }) {
259
+ refs.set("isPointerWithin", false);
260
+ if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
261
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
262
+ refs.set("lastFocusedEl", null);
263
+ }
264
+ },
265
+ clearFocusWithin({ refs }) {
266
+ refs.set("isFocusWithin", false);
267
+ },
268
+ clearLastFocusedEl({ refs }) {
269
+ if (!refs.get("lastFocusedEl")) return;
270
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
271
+ refs.set("lastFocusedEl", null);
272
+ refs.set("isFocusWithin", false);
273
+ },
274
+ ignoreMouseEventsTemporarily({ refs, scope, computed, send }) {
275
+ refs.get("ignoreMouseTimer").request(() => {
276
+ return (0, _zag_js_dom_query.addDomEvent)(scope.getDoc(), "pointermove", (event) => {
277
+ if (!refs.get("isPointerWithin")) return;
278
+ const regionEl = require_toast_dom.getRegionEl(scope, computed("placement"));
279
+ if ((0, _zag_js_dom_query.contains)(regionEl, (0, _zag_js_dom_query.getEventTarget)(event))) return;
280
+ send({
281
+ type: "REGION.POINTER_LEAVE",
282
+ placement: computed("placement")
283
+ });
284
+ }, { once: true });
285
+ });
286
+ },
287
+ clearMouseEventTimer({ refs }) {
288
+ refs.get("ignoreMouseTimer").cancel();
289
+ }
290
+ }
291
+ }
292
292
  });
293
+ function findOpenToast(toastEls, from, step) {
294
+ for (let i = from; i >= 0 && i < toastEls.length; i += step) if (toastEls[i].dataset.state === "open") return toastEls[i];
295
+ return null;
296
+ }
297
+ exports.groupMachine = groupMachine;