@zag-js/toast 2.0.0-next.2 → 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,408 @@
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.machine.ts
31
- var toast_machine_exports = {};
32
- __export(toast_machine_exports, {
33
- machine: () => machine
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
34
4
  });
35
- module.exports = __toCommonJS(toast_machine_exports);
36
- var import_core = require("@zag-js/core");
37
- var import_dom_query = require("@zag-js/dom-query");
38
- var import_utils = require("@zag-js/utils");
39
- var dom = __toESM(require("./toast.dom.js"));
40
- var import_toast = require("./toast.utils.js");
41
- var { not } = (0, import_core.createGuards)();
42
- var machine = (0, import_core.createMachine)({
43
- props({ props }) {
44
- (0, import_utils.ensureProps)(props, ["id", "type", "parent", "removeDelay"], "toast");
45
- return {
46
- closable: true,
47
- ...props,
48
- duration: (0, import_toast.getToastDuration)(props.duration, props.type)
49
- };
50
- },
51
- initialState({ prop }) {
52
- const persist = prop("type") === "loading" || prop("duration") === Infinity;
53
- return persist ? "visible:persist" : "visible";
54
- },
55
- context({ prop, bindable }) {
56
- return {
57
- remainingTime: bindable(() => ({
58
- defaultValue: (0, import_toast.getToastDuration)(prop("duration"), prop("type"))
59
- })),
60
- createdAt: bindable(() => ({
61
- defaultValue: Date.now()
62
- })),
63
- mounted: bindable(() => ({
64
- defaultValue: false
65
- })),
66
- initialHeight: bindable(() => ({
67
- defaultValue: 0
68
- }))
69
- };
70
- },
71
- refs() {
72
- return {
73
- closeTimerStartTime: Date.now(),
74
- lastCloseStartTimerStartTime: 0
75
- };
76
- },
77
- computed: {
78
- zIndex: ({ prop }) => {
79
- const toasts = prop("parent").context.get("toasts");
80
- const index = toasts.findIndex((toast) => toast.id === prop("id"));
81
- return toasts.length - index;
82
- },
83
- height: ({ prop }) => {
84
- const heights = prop("parent").context.get("heights");
85
- const height = heights.find((height2) => height2.id === prop("id"));
86
- return height?.height ?? 0;
87
- },
88
- heightIndex: ({ prop }) => {
89
- const heights = prop("parent").context.get("heights");
90
- return heights.findIndex((height) => height.id === prop("id"));
91
- },
92
- frontmost: ({ prop }) => prop("index") === 0,
93
- heightBefore: ({ prop }) => {
94
- const heights = prop("parent").context.get("heights");
95
- const heightIndex = heights.findIndex((height) => height.id === prop("id"));
96
- return heights.reduce((prev, curr, reducerIndex) => {
97
- if (reducerIndex >= heightIndex) return prev;
98
- return prev + curr.height;
99
- }, 0);
100
- },
101
- shouldPersist: ({ prop }) => prop("type") === "loading" || prop("duration") === Infinity
102
- },
103
- watch({ track, prop, send }) {
104
- track([() => prop("message")], () => {
105
- const message = prop("message");
106
- if (message) send({ type: message, src: "programmatic" });
107
- });
108
- track([() => prop("type"), () => prop("duration")], () => {
109
- send({ type: "UPDATE" });
110
- });
111
- },
112
- on: {
113
- UPDATE: [
114
- {
115
- guard: "shouldPersist",
116
- target: "visible:persist",
117
- actions: ["resetCloseTimer"]
118
- },
119
- {
120
- target: "visible:updating",
121
- actions: ["resetCloseTimer"]
122
- }
123
- ],
124
- MEASURE: {
125
- actions: ["measureHeight"]
126
- }
127
- },
128
- entry: ["setMounted", "measureHeight", "invokeOnVisible"],
129
- effects: ["trackHeight"],
130
- states: {
131
- "visible:updating": {
132
- tags: ["visible", "updating"],
133
- effects: ["waitForNextTick"],
134
- on: {
135
- SHOW: {
136
- target: "visible"
137
- }
138
- }
139
- },
140
- "visible:persist": {
141
- tags: ["visible", "paused"],
142
- on: {
143
- RESUME: {
144
- guard: not("isLoadingType"),
145
- target: "visible",
146
- actions: ["setCloseTimer"]
147
- },
148
- DISMISS: {
149
- target: "dismissing"
150
- }
151
- }
152
- },
153
- visible: {
154
- tags: ["visible"],
155
- effects: ["waitForDuration"],
156
- on: {
157
- DISMISS: {
158
- target: "dismissing"
159
- },
160
- PAUSE: {
161
- target: "visible:persist",
162
- actions: ["syncRemainingTime"]
163
- }
164
- }
165
- },
166
- dismissing: {
167
- entry: ["invokeOnDismiss"],
168
- effects: ["waitForRemoveDelay"],
169
- on: {
170
- REMOVE: {
171
- target: "unmounted",
172
- actions: ["notifyParentToRemove"]
173
- }
174
- }
175
- },
176
- unmounted: {
177
- entry: ["invokeOnUnmount"]
178
- }
179
- },
180
- implementations: {
181
- effects: {
182
- waitForRemoveDelay({ prop, send }) {
183
- return (0, import_utils.setRafTimeout)(() => {
184
- send({ type: "REMOVE", src: "timer" });
185
- }, prop("removeDelay"));
186
- },
187
- waitForDuration({ send, context, computed }) {
188
- if (computed("shouldPersist")) return;
189
- return (0, import_utils.setRafTimeout)(() => {
190
- send({ type: "DISMISS", src: "timer" });
191
- }, context.get("remainingTime"));
192
- },
193
- waitForNextTick({ send }) {
194
- return (0, import_utils.setRafTimeout)(() => {
195
- send({ type: "SHOW", src: "timer" });
196
- }, 0);
197
- },
198
- trackHeight({ scope, prop }) {
199
- let cleanup;
200
- (0, import_dom_query.raf)(() => {
201
- const rootEl = dom.getRootEl(scope);
202
- if (!rootEl) return;
203
- const syncHeight = () => {
204
- const height = measureLayoutHeight(rootEl);
205
- const item = { id: prop("id"), height };
206
- setHeight(prop("parent"), item);
207
- };
208
- const win = scope.getWin();
209
- const observer = new win.MutationObserver(syncHeight);
210
- observer.observe(rootEl, {
211
- childList: true,
212
- subtree: true,
213
- characterData: true
214
- });
215
- cleanup = () => observer.disconnect();
216
- });
217
- return () => cleanup?.();
218
- }
219
- },
220
- guards: {
221
- isLoadingType: ({ prop }) => prop("type") === "loading",
222
- shouldPersist: ({ computed }) => computed("shouldPersist")
223
- },
224
- actions: {
225
- setMounted({ context }) {
226
- (0, import_dom_query.raf)(() => {
227
- context.set("mounted", true);
228
- });
229
- },
230
- measureHeight({ scope, prop, context }) {
231
- queueMicrotask(() => {
232
- const rootEl = dom.getRootEl(scope);
233
- if (!rootEl) return;
234
- const height = measureLayoutHeight(rootEl);
235
- context.set("initialHeight", height);
236
- const item = { id: prop("id"), height };
237
- setHeight(prop("parent"), item);
238
- });
239
- },
240
- setCloseTimer({ refs }) {
241
- refs.set("closeTimerStartTime", Date.now());
242
- },
243
- resetCloseTimer({ context, refs, prop }) {
244
- refs.set("closeTimerStartTime", Date.now());
245
- context.set("remainingTime", (0, import_toast.getToastDuration)(prop("duration"), prop("type")));
246
- },
247
- syncRemainingTime({ context, refs }) {
248
- context.set("remainingTime", (prev) => {
249
- const closeTimerStartTime = refs.get("closeTimerStartTime");
250
- const elapsedTime = Date.now() - closeTimerStartTime;
251
- refs.set("lastCloseStartTimerStartTime", Date.now());
252
- return prev - elapsedTime;
253
- });
254
- },
255
- notifyParentToRemove({ prop }) {
256
- const parent = prop("parent");
257
- parent.send({ type: "TOAST.REMOVE", id: prop("id") });
258
- },
259
- invokeOnDismiss({ prop, event }) {
260
- prop("onStatusChange")?.({ status: "dismissing", src: event.src });
261
- },
262
- invokeOnUnmount({ prop }) {
263
- prop("onStatusChange")?.({ status: "unmounted" });
264
- },
265
- invokeOnVisible({ prop }) {
266
- prop("onStatusChange")?.({ status: "visible" });
267
- }
268
- }
269
- }
5
+ const require_toast_dom = require("./toast.dom.js");
6
+ const require_toast_utils = require("./toast.utils.js");
7
+ const require_utils_swipe = require("./utils/swipe.js");
8
+ let _zag_js_dom_query = require("@zag-js/dom-query");
9
+ let _zag_js_utils = require("@zag-js/utils");
10
+ let _zag_js_core = require("@zag-js/core");
11
+ // src/toast.machine.ts
12
+ const { not, and } = (0, _zag_js_core.createGuards)();
13
+ const machine = (0, _zag_js_core.createMachine)({
14
+ props({ props }) {
15
+ (0, _zag_js_utils.ensureProps)(props, [
16
+ "id",
17
+ "type",
18
+ "parent",
19
+ "removeDelay"
20
+ ], "toast");
21
+ return {
22
+ closable: true,
23
+ ...props,
24
+ duration: require_toast_utils.getToastDuration(props.duration, props.type)
25
+ };
26
+ },
27
+ initialState({ prop }) {
28
+ if (prop("message") === "DISMISS") return "dismissing";
29
+ return prop("type") === "loading" || prop("duration") === 1e400 || prop("paused") ? "visible:persist" : "visible";
30
+ },
31
+ context({ prop, bindable }) {
32
+ return {
33
+ remainingTime: bindable(() => ({ defaultValue: require_toast_utils.getToastDuration(prop("duration"), prop("type")) })),
34
+ createdAt: bindable(() => ({ defaultValue: Date.now() })),
35
+ mounted: bindable(() => ({ defaultValue: false })),
36
+ initialHeight: bindable(() => ({ defaultValue: 0 })),
37
+ rendered: bindable(() => ({ defaultValue: {
38
+ title: true,
39
+ description: true
40
+ } })),
41
+ swipeOffset: bindable(() => ({ defaultValue: {
42
+ x: 0,
43
+ y: 0
44
+ } })),
45
+ swipeDirection: bindable(() => ({ defaultValue: null }))
46
+ };
47
+ },
48
+ refs() {
49
+ return {
50
+ closeTimerStartTime: Date.now(),
51
+ lastCloseStartTimerStartTime: 0,
52
+ swipeStart: null,
53
+ mountFrame: _zag_js_dom_query.AnimationFrame.create()
54
+ };
55
+ },
56
+ computed: {
57
+ zIndex: ({ prop }) => {
58
+ const toasts = prop("parent").context.get("toasts");
59
+ const index = toasts.findIndex((toast) => toast.id === prop("id"));
60
+ return toasts.length - index;
61
+ },
62
+ height: ({ prop }) => {
63
+ return prop("parent").context.get("heights").find((height) => height.id === prop("id"))?.height ?? 0;
64
+ },
65
+ heightIndex: ({ prop }) => {
66
+ return prop("parent").context.get("heights").findIndex((height) => height.id === prop("id"));
67
+ },
68
+ frontmost: ({ prop }) => prop("index") === 0,
69
+ heightBefore: ({ prop }) => {
70
+ const heights = prop("parent").context.get("heights");
71
+ const heightIndex = heights.findIndex((height) => height.id === prop("id"));
72
+ return heights.reduce((prev, curr, reducerIndex) => {
73
+ if (reducerIndex >= heightIndex) return prev;
74
+ return prev + curr.height;
75
+ }, 0);
76
+ },
77
+ shouldPersist: ({ prop }) => prop("type") === "loading" || prop("duration") === 1e400,
78
+ swipeDirections: ({ prop }) => prop("swipeDirections") ?? require_utils_swipe.getDefaultSwipeDirections(prop("parent").computed("placement"), prop("dir"))
79
+ },
80
+ watch({ track, prop, send }) {
81
+ track([() => prop("message")], () => {
82
+ const message = prop("message");
83
+ if (message) send({
84
+ type: message,
85
+ src: "programmatic"
86
+ });
87
+ });
88
+ track([() => prop("paused")], () => {
89
+ send({ type: prop("paused") ? "PAUSE" : "RESUME" });
90
+ });
91
+ track([() => prop("type"), () => prop("duration")], () => {
92
+ send({ type: "UPDATE" });
93
+ });
94
+ },
95
+ on: {
96
+ UPDATE: [{
97
+ guard: and("isVisible", "shouldPause"),
98
+ target: "visible:persist",
99
+ actions: ["resetCloseTimer"]
100
+ }, {
101
+ guard: "isVisible",
102
+ target: "visible:updating",
103
+ actions: ["resetCloseTimer"]
104
+ }],
105
+ MEASURE: { actions: ["measureHeight"] }
106
+ },
107
+ entry: [
108
+ "setMounted",
109
+ "measureHeight",
110
+ "invokeOnVisible"
111
+ ],
112
+ exit: ["cancelMountFrame"],
113
+ effects: ["trackContent"],
114
+ states: {
115
+ "visible:updating": {
116
+ tags: ["visible", "updating"],
117
+ effects: ["waitForNextTick"],
118
+ on: {
119
+ DISMISS: { target: "dismissing" },
120
+ PAUSE: { target: "visible:persist" },
121
+ SHOW: { target: "visible" }
122
+ }
123
+ },
124
+ "visible:persist": {
125
+ tags: ["visible", "paused"],
126
+ on: {
127
+ RESUME: {
128
+ guard: not("shouldPause"),
129
+ target: "visible",
130
+ actions: ["setCloseTimer"]
131
+ },
132
+ DISMISS: { target: "dismissing" },
133
+ "SWIPE.START": {
134
+ guard: "canSwipe",
135
+ target: "visible:swiping",
136
+ actions: ["setSwipeStart"]
137
+ }
138
+ }
139
+ },
140
+ visible: {
141
+ tags: ["visible"],
142
+ effects: ["waitForDuration"],
143
+ on: {
144
+ DISMISS: { target: "dismissing" },
145
+ PAUSE: {
146
+ target: "visible:persist",
147
+ actions: ["syncRemainingTime"]
148
+ },
149
+ "SWIPE.START": {
150
+ guard: "canSwipe",
151
+ target: "visible:swiping",
152
+ actions: ["syncRemainingTime", "setSwipeStart"]
153
+ }
154
+ }
155
+ },
156
+ "visible:swiping": {
157
+ tags: ["visible", "paused"],
158
+ entry: ["pauseGroup"],
159
+ exit: ["resumeGroup"],
160
+ effects: ["trackSwipe"],
161
+ on: {
162
+ "SWIPE.MOVE": { actions: ["setSwipeOffset"] },
163
+ "SWIPE.END": [
164
+ {
165
+ guard: "isSwipeDismiss",
166
+ target: "dismissing",
167
+ actions: ["setSwipeDirection"]
168
+ },
169
+ {
170
+ guard: "shouldPause",
171
+ target: "visible:persist",
172
+ actions: ["resetSwipe"]
173
+ },
174
+ {
175
+ target: "visible",
176
+ actions: ["resetSwipe", "setCloseTimer"]
177
+ }
178
+ ],
179
+ "SWIPE.CANCEL": [{
180
+ guard: "shouldPause",
181
+ target: "visible:persist",
182
+ actions: ["resetSwipe"]
183
+ }, {
184
+ target: "visible",
185
+ actions: ["resetSwipe", "setCloseTimer"]
186
+ }],
187
+ DISMISS: {
188
+ target: "dismissing",
189
+ actions: ["resetSwipe"]
190
+ },
191
+ UPDATE: { actions: ["resetCloseTimer"] }
192
+ }
193
+ },
194
+ dismissing: {
195
+ entry: ["notifyParentOfDismiss", "invokeOnDismiss"],
196
+ effects: ["waitForRemoveDelay"],
197
+ on: { REMOVE: {
198
+ target: "unmounted",
199
+ actions: ["notifyParentToRemove"]
200
+ } }
201
+ },
202
+ unmounted: { entry: ["invokeOnUnmount"] }
203
+ },
204
+ implementations: {
205
+ effects: {
206
+ waitForRemoveDelay({ prop, send }) {
207
+ const timeout = _zag_js_dom_query.AnimationFrameTimeout.create();
208
+ timeout.start(prop("removeDelay"), () => send({
209
+ type: "REMOVE",
210
+ src: "timer"
211
+ }));
212
+ return timeout.cancel;
213
+ },
214
+ waitForDuration({ send, context, computed }) {
215
+ if (computed("shouldPersist")) return;
216
+ const timeout = _zag_js_dom_query.AnimationFrameTimeout.create();
217
+ timeout.start(context.get("remainingTime"), () => send({
218
+ type: "DISMISS",
219
+ src: "timer"
220
+ }));
221
+ return timeout.cancel;
222
+ },
223
+ waitForNextTick({ send }) {
224
+ return (0, _zag_js_dom_query.raf)(() => send({
225
+ type: "SHOW",
226
+ src: "timer"
227
+ }));
228
+ },
229
+ trackContent({ scope, prop, context, state }) {
230
+ return (0, _zag_js_dom_query.raf)(() => {
231
+ const rootEl = require_toast_dom.getRootEl(scope);
232
+ if (!rootEl) return;
233
+ const syncHeight = () => {
234
+ if (!state.hasTag("visible") || !rootEl.isConnected) return;
235
+ const height = measureLayoutHeight(rootEl);
236
+ require_toast_utils.setHeight(prop("parent"), {
237
+ id: prop("id"),
238
+ height
239
+ });
240
+ };
241
+ const syncRenderedElements = () => {
242
+ context.set("rendered", {
243
+ title: !!require_toast_dom.getTitleEl(scope),
244
+ description: !!require_toast_dom.getDescriptionEl(scope)
245
+ });
246
+ };
247
+ syncRenderedElements();
248
+ const contentEl = require_toast_dom.getContentEl(scope);
249
+ if (!contentEl) {
250
+ (0, _zag_js_utils.warn)("[zag-js/toast] Render the content part (`api.getContentProps()`) so the toast height follows its content.");
251
+ return;
252
+ }
253
+ return require_toast_dom.observeContent(contentEl, {
254
+ onChange: syncHeight,
255
+ onMutate: syncRenderedElements
256
+ });
257
+ });
258
+ },
259
+ trackSwipe({ scope, refs, send, computed }) {
260
+ const rootEl = require_toast_dom.getRootEl(scope);
261
+ const start = refs.get("swipeStart");
262
+ if (!rootEl || !start) return;
263
+ const doc = scope.getDoc();
264
+ const tracker = require_utils_swipe.createSwipeTracker(computed("swipeDirections"), start.point);
265
+ try {
266
+ rootEl.setPointerCapture(start.pointerId);
267
+ } catch {}
268
+ const isActivePointer = (event) => event.pointerId === start.pointerId;
269
+ const onPointerMove = (event) => {
270
+ if (!isActivePointer(event)) return;
271
+ event.preventDefault();
272
+ const { offset, direction } = tracker.move({
273
+ x: event.clientX,
274
+ y: event.clientY
275
+ });
276
+ send({
277
+ type: "SWIPE.MOVE",
278
+ offset,
279
+ direction
280
+ });
281
+ };
282
+ const onPointerUp = (event) => {
283
+ if (!isActivePointer(event)) return;
284
+ send({
285
+ type: "SWIPE.END",
286
+ direction: tracker.end()
287
+ });
288
+ };
289
+ const onPointerCancel = (event) => {
290
+ if (!isActivePointer(event)) return;
291
+ send({ type: "SWIPE.CANCEL" });
292
+ };
293
+ const onVisibilityChange = () => {
294
+ if (doc.visibilityState === "hidden") send({ type: "SWIPE.CANCEL" });
295
+ };
296
+ const onTouchMove = (event) => event.preventDefault();
297
+ return (0, _zag_js_utils.callAll)((0, _zag_js_dom_query.addDomEvent)(doc, "pointermove", onPointerMove), (0, _zag_js_dom_query.addDomEvent)(doc, "pointerup", onPointerUp), (0, _zag_js_dom_query.addDomEvent)(doc, "pointercancel", onPointerCancel), (0, _zag_js_dom_query.addDomEvent)(doc, "visibilitychange", onVisibilityChange), (0, _zag_js_dom_query.addDomEvent)(rootEl, "touchmove", onTouchMove, { passive: false }));
298
+ }
299
+ },
300
+ guards: {
301
+ isVisible: ({ state }) => state.hasTag("visible"),
302
+ shouldPause: ({ computed, prop }) => computed("shouldPersist") || !!prop("paused"),
303
+ canSwipe: ({ computed }) => computed("swipeDirections").length > 0,
304
+ isSwipeDismiss: ({ event }) => event.direction != null
305
+ },
306
+ actions: {
307
+ setSwipeStart({ refs, event }) {
308
+ refs.set("swipeStart", {
309
+ point: event.point,
310
+ pointerId: event.pointerId
311
+ });
312
+ },
313
+ setSwipeOffset({ context, event }) {
314
+ context.set("swipeOffset", event.offset);
315
+ context.set("swipeDirection", event.direction);
316
+ },
317
+ setSwipeDirection({ context, event }) {
318
+ context.set("swipeDirection", event.direction);
319
+ },
320
+ resetSwipe({ context, refs }) {
321
+ context.set("swipeOffset", {
322
+ x: 0,
323
+ y: 0
324
+ });
325
+ context.set("swipeDirection", null);
326
+ refs.set("swipeStart", null);
327
+ },
328
+ pauseGroup({ prop }) {
329
+ prop("parent").send({ type: "TOAST.PAUSE" });
330
+ },
331
+ resumeGroup({ prop }) {
332
+ prop("parent").send({ type: "TOAST.SWIPE_END" });
333
+ },
334
+ setMounted({ context, refs }) {
335
+ refs.get("mountFrame").request(() => {
336
+ context.set("mounted", true);
337
+ });
338
+ },
339
+ cancelMountFrame({ refs }) {
340
+ refs.get("mountFrame").cancel();
341
+ },
342
+ measureHeight({ scope, prop, context }) {
343
+ queueMicrotask(() => {
344
+ const rootEl = require_toast_dom.getRootEl(scope);
345
+ if (!rootEl) return;
346
+ const height = measureLayoutHeight(rootEl);
347
+ context.set("initialHeight", height);
348
+ const item = {
349
+ id: prop("id"),
350
+ height
351
+ };
352
+ require_toast_utils.setHeight(prop("parent"), item);
353
+ });
354
+ },
355
+ setCloseTimer({ refs }) {
356
+ refs.set("closeTimerStartTime", Date.now());
357
+ },
358
+ resetCloseTimer({ context, refs, prop }) {
359
+ refs.set("closeTimerStartTime", Date.now());
360
+ context.set("remainingTime", require_toast_utils.getToastDuration(prop("duration"), prop("type")));
361
+ },
362
+ syncRemainingTime({ context, refs }) {
363
+ context.set("remainingTime", (prev) => {
364
+ const closeTimerStartTime = refs.get("closeTimerStartTime");
365
+ const elapsedTime = Date.now() - closeTimerStartTime;
366
+ refs.set("lastCloseStartTimerStartTime", Date.now());
367
+ return prev - elapsedTime;
368
+ });
369
+ },
370
+ notifyParentToRemove({ prop }) {
371
+ prop("parent").send({
372
+ type: "TOAST.REMOVE",
373
+ id: prop("id")
374
+ });
375
+ },
376
+ notifyParentOfDismiss({ prop, scope }) {
377
+ const activeEl = scope.getActiveElement();
378
+ if (!(0, _zag_js_dom_query.contains)(require_toast_dom.getRootEl(scope), activeEl)) return;
379
+ const focusVisible = !!activeEl?.matches(":focus-visible");
380
+ prop("parent").send({
381
+ type: "TOAST.DISMISS",
382
+ focusVisible
383
+ });
384
+ },
385
+ invokeOnDismiss({ prop, event }) {
386
+ prop("parent").prop("store").dismiss(prop("id"));
387
+ prop("onStatusChange")?.({
388
+ status: "dismissing",
389
+ src: event.src
390
+ });
391
+ },
392
+ invokeOnUnmount({ prop }) {
393
+ prop("onStatusChange")?.({ status: "unmounted" });
394
+ },
395
+ invokeOnVisible({ prop }) {
396
+ prop("onStatusChange")?.({ status: "visible" });
397
+ }
398
+ }
399
+ }
270
400
  });
271
401
  function measureLayoutHeight(el) {
272
- const prevHeight = el.style.height;
273
- el.style.height = "auto";
274
- const height = el.offsetHeight;
275
- el.style.height = prevHeight;
276
- return height;
402
+ const prevHeight = el.style.height;
403
+ el.style.height = "auto";
404
+ const height = el.offsetHeight;
405
+ el.style.height = prevHeight;
406
+ return height;
277
407
  }
278
- function setHeight(parent, item) {
279
- const { id, height } = item;
280
- parent.context.set("heights", (prev) => {
281
- const alreadyExists = prev.find((i) => i.id === id);
282
- if (!alreadyExists) {
283
- return [{ id, height }, ...prev];
284
- } else {
285
- return prev.map((i) => i.id === id ? { ...i, height } : i);
286
- }
287
- });
288
- }
289
- // Annotate the CommonJS export names for ESM import in node:
290
- 0 && (module.exports = {
291
- machine
292
- });
408
+ exports.machine = machine;