@zag-js/toast 1.46.0 → 1.48.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 (41) 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 +73 -97
  8. package/dist/toast-group.connect.mjs +68 -61
  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 +294 -302
  12. package/dist/toast-group.machine.mjs +289 -266
  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 +133 -158
  20. package/dist/toast.connect.mjs +128 -122
  21. package/dist/toast.dom.d.mts +21 -16
  22. package/dist/toast.dom.d.ts +21 -16
  23. package/dist/toast.dom.js +56 -53
  24. package/dist/toast.dom.mjs +42 -20
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +272 -311
  28. package/dist/toast.machine.mjs +268 -276
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +344 -299
  32. package/dist/toast.store.mjs +340 -274
  33. package/dist/toast.types.d.mts +372 -374
  34. package/dist/toast.types.d.ts +372 -374
  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 +169 -198
  40. package/dist/toast.utils.mjs +159 -168
  41. package/package.json +9 -9
@@ -1,304 +1,296 @@
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
- PAUSE_ALL: {
93
- actions: ["pauseToasts"]
94
- },
95
- RESUME_ALL: {
96
- actions: ["resumeToasts"]
97
- },
98
- "DOC.HOTKEY": {
99
- actions: ["focusRegionEl"]
100
- },
101
- "REGION.BLUR": [
102
- {
103
- guard: and("isOverlapping", "isPointerOut"),
104
- target: "overlap",
105
- actions: ["collapseToasts", "resumeToasts", "restoreFocusIfPointerOut"]
106
- },
107
- {
108
- guard: "isPointerOut",
109
- target: "stack",
110
- actions: ["resumeToasts", "restoreFocusIfPointerOut"]
111
- },
112
- {
113
- actions: ["clearFocusWithin"]
114
- }
115
- ],
116
- "TOAST.REMOVE": {
117
- actions: ["removeToast", "removeHeight", "ignoreMouseEventsTemporarily"]
118
- },
119
- "TOAST.PAUSE": {
120
- actions: ["pauseToasts"]
121
- }
122
- },
123
- states: {
124
- stack: {
125
- on: {
126
- "REGION.POINTER_LEAVE": [
127
- {
128
- guard: "isOverlapping",
129
- target: "overlap",
130
- actions: ["clearPointerWithin", "resumeToasts", "collapseToasts"]
131
- },
132
- {
133
- actions: ["clearPointerWithin", "resumeToasts"]
134
- }
135
- ],
136
- "REGION.OVERLAP": {
137
- target: "overlap",
138
- actions: ["collapseToasts"]
139
- },
140
- "REGION.FOCUS": {
141
- actions: ["setLastFocusedEl", "pauseToasts"]
142
- },
143
- "REGION.POINTER_ENTER": {
144
- actions: ["setPointerWithin", "pauseToasts"]
145
- }
146
- }
147
- },
148
- overlap: {
149
- on: {
150
- "REGION.STACK": {
151
- target: "stack",
152
- actions: ["expandToasts"]
153
- },
154
- "REGION.POINTER_ENTER": {
155
- target: "stack",
156
- actions: ["setPointerWithin", "pauseToasts", "expandToasts"]
157
- },
158
- "REGION.FOCUS": {
159
- target: "stack",
160
- actions: ["setLastFocusedEl", "pauseToasts", "expandToasts"]
161
- }
162
- }
163
- }
164
- },
165
- implementations: {
166
- guards: {
167
- isOverlapping: ({ computed }) => computed("overlap"),
168
- isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
169
- },
170
- effects: {
171
- subscribeToStore({ context, prop }) {
172
- const store = prop("store");
173
- context.set("toasts", store.getVisibleToasts());
174
- return store.subscribe((toast) => {
175
- if (toast.dismiss) {
176
- context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
177
- return;
178
- }
179
- context.set("toasts", (prev) => {
180
- const index = prev.findIndex((t) => t.id === toast.id);
181
- if (index !== -1) {
182
- return [...prev.slice(0, index), { ...prev[index], ...toast }, ...prev.slice(index + 1)];
183
- }
184
- return [toast, ...prev];
185
- });
186
- });
187
- },
188
- trackHotKeyPress({ prop, send }) {
189
- const handleKeyDown = (event) => {
190
- const { hotkey } = prop("store").attrs;
191
- const isHotkeyPressed = hotkey.every((key) => event[key] || event.code === key);
192
- if (!isHotkeyPressed) return;
193
- send({ type: "DOC.HOTKEY" });
194
- };
195
- return (0, import_dom_query.addDomEvent)(document, "keydown", handleKeyDown, { capture: true });
196
- },
197
- trackDocumentVisibility({ prop, send, scope }) {
198
- const { pauseOnPageIdle } = prop("store").attrs;
199
- if (!pauseOnPageIdle) return;
200
- const doc = scope.getDoc();
201
- if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
202
- return (0, import_dom_query.addDomEvent)(doc, "visibilitychange", () => {
203
- const isHidden = doc.visibilityState === "hidden";
204
- send({ type: isHidden ? "PAUSE_ALL" : "RESUME_ALL" });
205
- });
206
- }
207
- },
208
- actions: {
209
- setDismissableBranch({ refs, context, computed, scope }) {
210
- const toasts = context.get("toasts");
211
- const placement = computed("placement");
212
- const hasToasts = toasts.length > 0;
213
- if (!hasToasts) {
214
- refs.get("dismissableCleanup")?.();
215
- refs.set("dismissableCleanup", void 0);
216
- return;
217
- }
218
- if (hasToasts && refs.get("dismissableCleanup")) {
219
- return;
220
- }
221
- const groupEl = () => dom.getRegionEl(scope, placement);
222
- const cleanup = (0, import_dismissable.trackDismissableBranch)(groupEl, { defer: true });
223
- refs.set("dismissableCleanup", cleanup);
224
- },
225
- clearDismissableBranch({ refs }) {
226
- refs.get("dismissableCleanup")?.();
227
- refs.set("dismissableCleanup", void 0);
228
- },
229
- focusRegionEl({ scope, computed }) {
230
- queueMicrotask(() => {
231
- dom.getRegionEl(scope, computed("placement"))?.focus();
232
- });
233
- },
234
- pauseToasts({ prop }) {
235
- prop("store").pause();
236
- },
237
- resumeToasts({ prop, refs, scope, event }) {
238
- if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
239
- const idle = prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden";
240
- if (idle || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
241
- prop("store").resume();
242
- },
243
- expandToasts({ prop }) {
244
- prop("store").expand();
245
- },
246
- collapseToasts({ prop }) {
247
- prop("store").collapse();
248
- },
249
- removeToast({ prop, event }) {
250
- prop("store").remove(event.id);
251
- },
252
- removeHeight({ event, context }) {
253
- if (event?.id == null) return;
254
- queueMicrotask(() => {
255
- context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
256
- });
257
- },
258
- collapsedIfEmpty({ send, computed }) {
259
- if (!computed("overlap") || computed("count") > 1) return;
260
- send({ type: "REGION.OVERLAP" });
261
- },
262
- setLastFocusedEl({ refs, event }) {
263
- if (refs.get("isFocusWithin")) return;
264
- refs.set("isFocusWithin", true);
265
- refs.set("lastFocusedEl", event.target ?? null);
266
- },
267
- restoreFocusIfPointerOut({ refs }) {
268
- if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
269
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
270
- refs.set("lastFocusedEl", null);
271
- refs.set("isFocusWithin", false);
272
- },
273
- setPointerWithin({ refs }) {
274
- refs.set("isPointerWithin", true);
275
- },
276
- clearPointerWithin({ refs }) {
277
- refs.set("isPointerWithin", false);
278
- if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
279
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
280
- refs.set("lastFocusedEl", null);
281
- }
282
- },
283
- clearFocusWithin({ refs }) {
284
- refs.set("isFocusWithin", false);
285
- },
286
- clearLastFocusedEl({ refs }) {
287
- if (!refs.get("lastFocusedEl")) return;
288
- refs.get("lastFocusedEl")?.focus({ preventScroll: true });
289
- refs.set("lastFocusedEl", null);
290
- refs.set("isFocusWithin", false);
291
- },
292
- ignoreMouseEventsTemporarily({ refs }) {
293
- refs.get("ignoreMouseTimer").request();
294
- },
295
- clearMouseEventTimer({ refs }) {
296
- refs.get("ignoreMouseTimer").cancel();
297
- }
298
- }
299
- }
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
300
4
  });
301
- // Annotate the CommonJS export names for ESM import in node:
302
- 0 && (module.exports = {
303
- 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
+ },
99
+ states: {
100
+ stack: { on: {
101
+ "REGION.POINTER_LEAVE": [{
102
+ guard: "isOverlapping",
103
+ target: "overlap",
104
+ actions: ["clearPointerWithin", "resumeToasts"]
105
+ }, { actions: ["clearPointerWithin", "resumeToasts"] }],
106
+ "REGION.OVERLAP": { target: "overlap" },
107
+ "REGION.FOCUS": { actions: ["setLastFocusedEl", "pauseToasts"] },
108
+ "REGION.POINTER_ENTER": { actions: ["setPointerWithin", "pauseToasts"] }
109
+ } },
110
+ overlap: { on: {
111
+ "REGION.STACK": { target: "stack" },
112
+ "REGION.POINTER_ENTER": {
113
+ target: "stack",
114
+ actions: ["setPointerWithin", "pauseToasts"]
115
+ },
116
+ "REGION.POINTER_LEAVE": { actions: ["clearPointerWithin", "resumeToasts"] },
117
+ "REGION.FOCUS": {
118
+ target: "stack",
119
+ actions: ["setLastFocusedEl", "pauseToasts"]
120
+ }
121
+ } }
122
+ },
123
+ implementations: {
124
+ guards: {
125
+ isOverlapping: ({ computed }) => computed("overlap"),
126
+ isPointerOut: ({ refs }) => !refs.get("isPointerWithin")
127
+ },
128
+ effects: {
129
+ subscribeToStore({ context, prop }) {
130
+ const store = prop("store");
131
+ context.set("toasts", store.getVisibleToasts());
132
+ return store.subscribe((toast) => {
133
+ if (toast.dismiss) {
134
+ context.set("toasts", (prev) => prev.filter((t) => t.id !== toast.id));
135
+ return;
136
+ }
137
+ context.set("toasts", (prev) => {
138
+ const index = prev.findIndex((t) => t.id === toast.id);
139
+ if (index !== -1) return [
140
+ ...prev.slice(0, index),
141
+ {
142
+ ...prev[index],
143
+ ...toast
144
+ },
145
+ ...prev.slice(index + 1)
146
+ ];
147
+ return [toast, ...prev];
148
+ });
149
+ });
150
+ },
151
+ subscribeToLayout({ prop, send }) {
152
+ return prop("store").subscribeLayout((stacked) => {
153
+ send({ type: stacked ? "REGION.STACK" : "REGION.OVERLAP" });
154
+ });
155
+ },
156
+ trackHotKeyPress({ prop, send }) {
157
+ const handleKeyDown = (event) => {
158
+ const { hotkey } = prop("store").attrs;
159
+ if (!hotkey.every((key) => event[key] || event.code === key)) return;
160
+ send({ type: "DOC.HOTKEY" });
161
+ };
162
+ return (0, _zag_js_dom_query.addDomEvent)(document, "keydown", handleKeyDown, { capture: true });
163
+ },
164
+ trackDocumentVisibility({ prop, send, scope }) {
165
+ const { pauseOnPageIdle } = prop("store").attrs;
166
+ if (!pauseOnPageIdle) return;
167
+ const doc = scope.getDoc();
168
+ if (doc.visibilityState === "hidden") send({ type: "PAUSE_ALL" });
169
+ return (0, _zag_js_dom_query.addDomEvent)(doc, "visibilitychange", () => {
170
+ send({ type: doc.visibilityState === "hidden" ? "PAUSE_ALL" : "RESUME_ALL" });
171
+ });
172
+ }
173
+ },
174
+ actions: {
175
+ setDismissableBranch({ refs, context, computed, scope }) {
176
+ const toasts = context.get("toasts");
177
+ const placement = computed("placement");
178
+ const hasToasts = toasts.length > 0;
179
+ if (!hasToasts) {
180
+ refs.get("dismissableCleanup")?.();
181
+ refs.set("dismissableCleanup", void 0);
182
+ return;
183
+ }
184
+ if (hasToasts && refs.get("dismissableCleanup")) return;
185
+ const groupEl = () => require_toast_dom.getRegionEl(scope, placement);
186
+ const cleanup = (0, _zag_js_dismissable.trackDismissableBranch)(groupEl, {
187
+ defer: true,
188
+ getRootNode: scope.getRootNode
189
+ });
190
+ refs.set("dismissableCleanup", cleanup);
191
+ },
192
+ clearDismissableBranch({ refs }) {
193
+ refs.get("dismissableCleanup")?.();
194
+ refs.set("dismissableCleanup", void 0);
195
+ },
196
+ focusRegionEl({ scope, computed }) {
197
+ queueMicrotask(() => {
198
+ require_toast_dom.getRegionEl(scope, computed("placement"))?.focus();
199
+ });
200
+ },
201
+ pauseToasts({ prop }) {
202
+ prop("store").pause();
203
+ },
204
+ resumeToasts({ prop, refs, scope, event }) {
205
+ if (event.type === "REGION.BLUR") refs.set("isFocusWithin", false);
206
+ if (prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden" || refs.get("isPointerWithin") || refs.get("isFocusWithin")) return;
207
+ prop("store").resume();
208
+ },
209
+ removeToast({ prop, event }) {
210
+ prop("store").remove(event.id);
211
+ },
212
+ removeHeight({ event, context }) {
213
+ if (event?.id == null) return;
214
+ queueMicrotask(() => {
215
+ context.set("heights", (heights) => heights.filter((height) => height.id !== event.id));
216
+ });
217
+ },
218
+ collapsedIfEmpty({ send, computed }) {
219
+ if (!computed("overlap") || computed("count") > 1) return;
220
+ send({ type: "REGION.OVERLAP" });
221
+ },
222
+ setLastFocusedEl({ refs, event }) {
223
+ if (refs.get("isFocusWithin")) return;
224
+ refs.set("isFocusWithin", true);
225
+ refs.set("lastFocusedEl", event.target ?? null);
226
+ },
227
+ moveFocusOnDismiss({ refs, scope, computed, event }) {
228
+ if (event.focusVisible) {
229
+ const toastEls = require_toast_dom.getToastEls(scope, computed("placement"));
230
+ const index = toastEls.findIndex((el) => (0, _zag_js_dom_query.contains)(el, scope.getActiveElement()));
231
+ const nextEl = findOpenToast(toastEls, index + 1, 1) ?? findOpenToast(toastEls, index - 1, -1);
232
+ if (nextEl) {
233
+ nextEl.focus({ preventScroll: true });
234
+ return;
235
+ }
236
+ }
237
+ const lastFocusedEl = refs.get("lastFocusedEl");
238
+ if (event.focusVisible && lastFocusedEl) lastFocusedEl.focus({ preventScroll: true });
239
+ else scope.getActiveElement()?.blur();
240
+ },
241
+ resetInteractionIfEmpty({ refs, prop, scope, computed }) {
242
+ if (computed("count") > 0) return;
243
+ refs.set("isFocusWithin", false);
244
+ refs.set("isPointerWithin", false);
245
+ refs.set("lastFocusedEl", null);
246
+ if (!(prop("store").attrs.pauseOnPageIdle && scope.getDoc().visibilityState === "hidden")) prop("store").resume();
247
+ },
248
+ restoreFocusIfPointerOut({ refs }) {
249
+ if (!refs.get("lastFocusedEl") || refs.get("isPointerWithin")) return;
250
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
251
+ refs.set("lastFocusedEl", null);
252
+ refs.set("isFocusWithin", false);
253
+ },
254
+ setPointerWithin({ refs }) {
255
+ refs.set("isPointerWithin", true);
256
+ },
257
+ clearPointerWithin({ refs }) {
258
+ refs.set("isPointerWithin", false);
259
+ if (refs.get("lastFocusedEl") && !refs.get("isFocusWithin")) {
260
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
261
+ refs.set("lastFocusedEl", null);
262
+ }
263
+ },
264
+ clearFocusWithin({ refs }) {
265
+ refs.set("isFocusWithin", false);
266
+ },
267
+ clearLastFocusedEl({ refs }) {
268
+ if (!refs.get("lastFocusedEl")) return;
269
+ refs.get("lastFocusedEl")?.focus({ preventScroll: true });
270
+ refs.set("lastFocusedEl", null);
271
+ refs.set("isFocusWithin", false);
272
+ },
273
+ ignoreMouseEventsTemporarily({ refs, scope, computed, send }) {
274
+ refs.get("ignoreMouseTimer").request(() => {
275
+ return (0, _zag_js_dom_query.addDomEvent)(scope.getDoc(), "pointermove", (event) => {
276
+ if (!refs.get("isPointerWithin")) return;
277
+ const regionEl = require_toast_dom.getRegionEl(scope, computed("placement"));
278
+ if ((0, _zag_js_dom_query.contains)(regionEl, (0, _zag_js_dom_query.getEventTarget)(event))) return;
279
+ send({
280
+ type: "REGION.POINTER_LEAVE",
281
+ placement: computed("placement")
282
+ });
283
+ }, { once: true });
284
+ });
285
+ },
286
+ clearMouseEventTimer({ refs }) {
287
+ refs.get("ignoreMouseTimer").cancel();
288
+ }
289
+ }
290
+ }
304
291
  });
292
+ function findOpenToast(toastEls, from, step) {
293
+ for (let i = from; i >= 0 && i < toastEls.length; i += step) if (toastEls[i].dataset.state === "open") return toastEls[i];
294
+ return null;
295
+ }
296
+ exports.groupMachine = groupMachine;