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