@zag-js/toast 0.2.6 → 0.2.8

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.
@@ -0,0 +1,28 @@
1
+ import { Toaster, GroupState, GroupSend, Service, Placement, Options, PromiseOptions, GroupProps, GroupMachineContext } from './toast.types.js';
2
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import '@zag-js/core';
4
+
5
+ declare let toaster: Toaster;
6
+ declare function groupConnect<T extends PropTypes>(state: GroupState, send: GroupSend, normalize: NormalizeProps<T>): {
7
+ count: number;
8
+ toasts: Service[];
9
+ toastsByPlacement: Partial<Record<Placement, Service[]>>;
10
+ isVisible(id: string): boolean;
11
+ create(options: Options): string | undefined;
12
+ upsert(options: Options): string | undefined;
13
+ dismiss(id?: string): void;
14
+ remove(id?: string): void;
15
+ dismissByPlacement(placement: Placement): void;
16
+ update(id: string, options: Options): string | undefined;
17
+ loading(options: Options): string | undefined;
18
+ success(options: Options): string | undefined;
19
+ error(options: Options): string | undefined;
20
+ promise<T_1>(promise: Promise<T_1>, options: PromiseOptions<T_1>, shared?: Options): Promise<T_1>;
21
+ pause(id?: string): void;
22
+ resume(id?: string): void;
23
+ getGroupProps(options: GroupProps): T["element"];
24
+ createPortal(): HTMLElement;
25
+ subscribe(fn: (toasts: GroupMachineContext["toasts"]) => void): () => void;
26
+ };
27
+
28
+ export { groupConnect, toaster };
@@ -0,0 +1,278 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/toast-group.connect.ts
21
+ var toast_group_connect_exports = {};
22
+ __export(toast_group_connect_exports, {
23
+ groupConnect: () => groupConnect,
24
+ toaster: () => toaster
25
+ });
26
+ module.exports = __toCommonJS(toast_group_connect_exports);
27
+ var import_core = require("@zag-js/core");
28
+
29
+ // ../../utilities/core/src/functions.ts
30
+ var runIfFn = (v, ...a) => {
31
+ const res = typeof v === "function" ? v(...a) : v;
32
+ return res != null ? res : void 0;
33
+ };
34
+ var uuid = /* @__PURE__ */ (() => {
35
+ let id = 0;
36
+ return () => {
37
+ id++;
38
+ return id.toString(36);
39
+ };
40
+ })();
41
+
42
+ // src/toast.anatomy.ts
43
+ var import_anatomy = require("@zag-js/anatomy");
44
+ var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
45
+ var parts = anatomy.build();
46
+
47
+ // ../../utilities/dom/src/query.ts
48
+ function isDocument(el) {
49
+ return el.nodeType === Node.DOCUMENT_NODE;
50
+ }
51
+ function isWindow(value) {
52
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
53
+ }
54
+ function getDocument(el) {
55
+ var _a;
56
+ if (isWindow(el))
57
+ return el.document;
58
+ if (isDocument(el))
59
+ return el;
60
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
61
+ }
62
+ function defineDomHelpers(helpers) {
63
+ const dom2 = {
64
+ getRootNode: (ctx) => {
65
+ var _a, _b;
66
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
67
+ },
68
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
69
+ getWin: (ctx) => {
70
+ var _a;
71
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
72
+ },
73
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
74
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
75
+ };
76
+ return {
77
+ ...dom2,
78
+ ...helpers
79
+ };
80
+ }
81
+
82
+ // src/toast.dom.ts
83
+ var dom = defineDomHelpers({
84
+ getGroupId: (placement) => `toast-group:${placement}`,
85
+ getRootId: (ctx) => `toast:${ctx.id}`,
86
+ getTitleId: (ctx) => `toast:${ctx.id}:title`,
87
+ getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
88
+ getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
89
+ getPortalId: (ctx) => `toast-portal:${ctx.id}`,
90
+ getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
91
+ createPortalEl: (ctx) => {
92
+ const existing = dom.getPortalEl(ctx);
93
+ if (existing)
94
+ return existing;
95
+ const portal = dom.getDoc(ctx).createElement("toast-portal");
96
+ portal.id = dom.getPortalId(ctx);
97
+ return portal;
98
+ }
99
+ });
100
+
101
+ // src/toast.utils.ts
102
+ function getToastsByPlacement(toasts) {
103
+ const result = {};
104
+ for (const toast of toasts) {
105
+ const placement = toast.state.context.placement;
106
+ result[placement] || (result[placement] = []);
107
+ result[placement].push(toast);
108
+ }
109
+ return result;
110
+ }
111
+ function getGroupPlacementStyle(ctx, placement) {
112
+ const offset = ctx.offsets;
113
+ const __offset = typeof offset === "string" ? { left: offset, right: offset, bottom: offset, top: offset } : offset;
114
+ const rtl = ctx.dir === "rtl";
115
+ const __placement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
116
+ const isRighty = __placement.includes("right");
117
+ const isLefty = __placement.includes("left");
118
+ const styles = {
119
+ position: "fixed",
120
+ pointerEvents: ctx.count > 0 ? void 0 : "none",
121
+ display: "flex",
122
+ flexDirection: "column",
123
+ "--toast-gutter": ctx.gutter,
124
+ zIndex: ctx.zIndex
125
+ };
126
+ let alignItems = "center";
127
+ if (isRighty)
128
+ alignItems = "flex-end";
129
+ if (isLefty)
130
+ alignItems = "flex-start";
131
+ styles.alignItems = alignItems;
132
+ if (__placement.includes("top")) {
133
+ const offset2 = __offset.top;
134
+ styles.top = `calc(env(safe-area-inset-top, 0px) + ${offset2})`;
135
+ }
136
+ if (__placement.includes("bottom")) {
137
+ const offset2 = __offset.bottom;
138
+ styles.bottom = `calc(env(safe-area-inset-bottom, 0px) + ${offset2})`;
139
+ }
140
+ if (!__placement.includes("left")) {
141
+ const offset2 = __offset.right;
142
+ styles.right = `calc(env(safe-area-inset-right, 0px) + ${offset2})`;
143
+ }
144
+ if (!__placement.includes("right")) {
145
+ const offset2 = __offset.left;
146
+ styles.left = `calc(env(safe-area-inset-left, 0px) + ${offset2})`;
147
+ }
148
+ return styles;
149
+ }
150
+
151
+ // src/toast-group.connect.ts
152
+ var toaster = {};
153
+ function groupConnect(state, send, normalize) {
154
+ const group = {
155
+ count: state.context.count,
156
+ toasts: state.context.toasts,
157
+ toastsByPlacement: getToastsByPlacement(state.context.toasts),
158
+ isVisible(id) {
159
+ if (!state.context.toasts.length)
160
+ return false;
161
+ return !!state.context.toasts.find((toast) => toast.id == id);
162
+ },
163
+ create(options) {
164
+ const uid = `toast:${uuid()}`;
165
+ const id = options.id ? options.id : uid;
166
+ if (group.isVisible(id))
167
+ return;
168
+ send({ type: "ADD_TOAST", toast: { ...options, id } });
169
+ return id;
170
+ },
171
+ upsert(options) {
172
+ const { id } = options;
173
+ const isVisible = id ? group.isVisible(id) : false;
174
+ if (isVisible && id != null) {
175
+ return group.update(id, options);
176
+ } else {
177
+ return group.create(options);
178
+ }
179
+ },
180
+ dismiss(id) {
181
+ if (id == null) {
182
+ send("DISMISS_ALL");
183
+ } else if (group.isVisible(id)) {
184
+ send({ type: "DISMISS_TOAST", id });
185
+ }
186
+ },
187
+ remove(id) {
188
+ if (id == null) {
189
+ send("REMOVE_ALL");
190
+ } else if (group.isVisible(id)) {
191
+ send({ type: "REMOVE_TOAST", id });
192
+ }
193
+ },
194
+ dismissByPlacement(placement) {
195
+ const toasts = group.toastsByPlacement[placement];
196
+ if (toasts) {
197
+ toasts.forEach((toast) => group.dismiss(toast.id));
198
+ }
199
+ },
200
+ update(id, options) {
201
+ if (!group.isVisible(id))
202
+ return;
203
+ send({ type: "UPDATE_TOAST", id, toast: options });
204
+ return id;
205
+ },
206
+ loading(options) {
207
+ options.type = "loading";
208
+ return group.upsert(options);
209
+ },
210
+ success(options) {
211
+ options.type = "success";
212
+ return group.upsert(options);
213
+ },
214
+ error(options) {
215
+ options.type = "error";
216
+ return group.upsert(options);
217
+ },
218
+ promise(promise, options, shared = {}) {
219
+ const id = group.loading({ ...shared, ...options.loading });
220
+ promise.then((response) => {
221
+ const successOptions = runIfFn(options.success, response);
222
+ group.success({ ...shared, ...successOptions, id });
223
+ }).catch((error) => {
224
+ const errorOptions = runIfFn(options.error, error);
225
+ group.error({ ...shared, ...errorOptions, id });
226
+ });
227
+ return promise;
228
+ },
229
+ pause(id) {
230
+ if (id == null) {
231
+ send("PAUSE_ALL");
232
+ } else if (group.isVisible(id)) {
233
+ send({ type: "PAUSE_TOAST", id });
234
+ }
235
+ },
236
+ resume(id) {
237
+ if (id == null) {
238
+ send("RESUME_ALL");
239
+ } else if (group.isVisible(id)) {
240
+ send({ type: "RESUME_TOAST", id });
241
+ }
242
+ },
243
+ getGroupProps(options) {
244
+ const { placement, label = "Notifications" } = options;
245
+ return normalize.element({
246
+ ...parts.group.attrs,
247
+ tabIndex: -1,
248
+ "aria-label": label,
249
+ id: dom.getGroupId(placement),
250
+ "data-placement": placement,
251
+ "aria-live": "polite",
252
+ role: "region",
253
+ style: getGroupPlacementStyle(state.context, placement)
254
+ });
255
+ },
256
+ createPortal() {
257
+ const doc = dom.getDoc(state.context);
258
+ const exist = dom.getPortalEl(state.context);
259
+ if (exist)
260
+ return exist;
261
+ const portal = dom.createPortalEl(state.context);
262
+ doc.body.appendChild(portal);
263
+ return portal;
264
+ },
265
+ subscribe(fn) {
266
+ return (0, import_core.subscribe)(state.context.toasts, () => fn(state.context.toasts));
267
+ }
268
+ };
269
+ if (!state.matches("unknown")) {
270
+ Object.assign(toaster, group);
271
+ }
272
+ return group;
273
+ }
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ groupConnect,
277
+ toaster
278
+ });
@@ -0,0 +1,12 @@
1
+ import {
2
+ groupConnect,
3
+ toaster
4
+ } from "./chunk-MCVNSXDU.mjs";
5
+ import "./chunk-GQHI2OMI.mjs";
6
+ import "./chunk-YVYADWQR.mjs";
7
+ import "./chunk-LOJTIJID.mjs";
8
+ import "./chunk-SMQXX7JA.mjs";
9
+ export {
10
+ groupConnect,
11
+ toaster
12
+ };
@@ -0,0 +1,7 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { UserDefinedGroupContext, GroupMachineContext } from './toast.types.js';
3
+ import '@zag-js/types';
4
+
5
+ declare function groupMachine(userContext: UserDefinedGroupContext): _zag_js_core.Machine<GroupMachineContext, _zag_js_core.StateMachine.StateSchema, _zag_js_core.StateMachine.AnyEventObject>;
6
+
7
+ export { groupMachine };
@@ -0,0 +1,383 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/toast-group.machine.ts
21
+ var toast_group_machine_exports = {};
22
+ __export(toast_group_machine_exports, {
23
+ groupMachine: () => groupMachine
24
+ });
25
+ module.exports = __toCommonJS(toast_group_machine_exports);
26
+ var import_core2 = require("@zag-js/core");
27
+
28
+ // ../../utilities/dom/src/constants.ts
29
+ var MAX_Z_INDEX = 2147483647;
30
+
31
+ // ../../utilities/core/src/functions.ts
32
+ var runIfFn = (v, ...a) => {
33
+ const res = typeof v === "function" ? v(...a) : v;
34
+ return res != null ? res : void 0;
35
+ };
36
+ var cast = (v) => v;
37
+
38
+ // ../../utilities/core/src/guard.ts
39
+ var isArray = (v) => Array.isArray(v);
40
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
41
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
42
+
43
+ // ../../utilities/core/src/object.ts
44
+ function compact(obj) {
45
+ if (obj === void 0)
46
+ return obj;
47
+ return Object.fromEntries(
48
+ Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
49
+ );
50
+ }
51
+
52
+ // ../../utilities/dom/src/query.ts
53
+ function isDocument(el) {
54
+ return el.nodeType === Node.DOCUMENT_NODE;
55
+ }
56
+ function isWindow(value) {
57
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
58
+ }
59
+ function getDocument(el) {
60
+ var _a;
61
+ if (isWindow(el))
62
+ return el.document;
63
+ if (isDocument(el))
64
+ return el;
65
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
66
+ }
67
+ function defineDomHelpers(helpers) {
68
+ const dom2 = {
69
+ getRootNode: (ctx) => {
70
+ var _a, _b;
71
+ return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
72
+ },
73
+ getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
74
+ getWin: (ctx) => {
75
+ var _a;
76
+ return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
77
+ },
78
+ getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
79
+ getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
80
+ };
81
+ return {
82
+ ...dom2,
83
+ ...helpers
84
+ };
85
+ }
86
+
87
+ // ../../utilities/dom/src/listener.ts
88
+ var isRef = (v) => hasProp(v, "current");
89
+ function addDomEvent(target, eventName, handler, options) {
90
+ const node = isRef(target) ? target.current : runIfFn(target);
91
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
92
+ return () => {
93
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
94
+ };
95
+ }
96
+
97
+ // ../../utilities/dom/src/visibility-event.ts
98
+ function trackDocumentVisibility(_doc, callback) {
99
+ const doc = cast(_doc);
100
+ return addDomEvent(doc, "visibilitychange", () => {
101
+ const hidden = doc.hidden || doc.msHidden || doc.webkitHidden;
102
+ callback(!!hidden);
103
+ });
104
+ }
105
+
106
+ // src/toast.machine.ts
107
+ var import_core = require("@zag-js/core");
108
+
109
+ // src/toast.dom.ts
110
+ var dom = defineDomHelpers({
111
+ getGroupId: (placement) => `toast-group:${placement}`,
112
+ getRootId: (ctx) => `toast:${ctx.id}`,
113
+ getTitleId: (ctx) => `toast:${ctx.id}:title`,
114
+ getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
115
+ getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
116
+ getPortalId: (ctx) => `toast-portal:${ctx.id}`,
117
+ getPortalEl: (ctx) => dom.getDoc(ctx).getElementById(dom.getPortalId(ctx)),
118
+ createPortalEl: (ctx) => {
119
+ const existing = dom.getPortalEl(ctx);
120
+ if (existing)
121
+ return existing;
122
+ const portal = dom.getDoc(ctx).createElement("toast-portal");
123
+ portal.id = dom.getPortalId(ctx);
124
+ return portal;
125
+ }
126
+ });
127
+
128
+ // src/toast.utils.ts
129
+ var defaultTimeouts = {
130
+ info: 5e3,
131
+ error: 5e3,
132
+ success: 2e3,
133
+ loading: Infinity,
134
+ custom: 5e3
135
+ };
136
+ function getToastDuration(duration, type) {
137
+ return duration != null ? duration : defaultTimeouts[type];
138
+ }
139
+
140
+ // src/toast.machine.ts
141
+ var { not, and, or } = import_core.guards;
142
+ function createToastMachine(options = {}) {
143
+ const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
144
+ const ctx = compact(restProps);
145
+ const computedDuration = getToastDuration(duration, type);
146
+ return (0, import_core.createMachine)(
147
+ {
148
+ id,
149
+ entry: "invokeOnOpen",
150
+ initial: type === "loading" ? "persist" : "active",
151
+ context: {
152
+ id,
153
+ type,
154
+ remaining: computedDuration,
155
+ duration: computedDuration,
156
+ removeDelay,
157
+ createdAt: Date.now(),
158
+ placement,
159
+ ...ctx
160
+ },
161
+ on: {
162
+ UPDATE: [
163
+ {
164
+ guard: and("hasTypeChanged", "isChangingToLoading"),
165
+ target: "persist",
166
+ actions: ["setContext", "invokeOnUpdate"]
167
+ },
168
+ {
169
+ guard: or("hasDurationChanged", "hasTypeChanged"),
170
+ target: "active:temp",
171
+ actions: ["setContext", "invokeOnUpdate"]
172
+ },
173
+ {
174
+ actions: ["setContext", "invokeOnUpdate"]
175
+ }
176
+ ]
177
+ },
178
+ states: {
179
+ "active:temp": {
180
+ tags: ["visible", "updating"],
181
+ after: {
182
+ 0: "active"
183
+ }
184
+ },
185
+ persist: {
186
+ tags: ["visible", "paused"],
187
+ activities: "trackDocumentVisibility",
188
+ on: {
189
+ RESUME: {
190
+ guard: not("isLoadingType"),
191
+ target: "active",
192
+ actions: ["setCreatedAt"]
193
+ },
194
+ DISMISS: "dismissing"
195
+ }
196
+ },
197
+ active: {
198
+ tags: ["visible"],
199
+ activities: "trackDocumentVisibility",
200
+ after: {
201
+ VISIBLE_DURATION: "dismissing"
202
+ },
203
+ on: {
204
+ DISMISS: "dismissing",
205
+ PAUSE: {
206
+ target: "persist",
207
+ actions: "setRemainingDuration"
208
+ }
209
+ }
210
+ },
211
+ dismissing: {
212
+ entry: "invokeOnClosing",
213
+ after: {
214
+ REMOVE_DELAY: {
215
+ target: "inactive",
216
+ actions: "notifyParentToRemove"
217
+ }
218
+ }
219
+ },
220
+ inactive: {
221
+ entry: "invokeOnClose",
222
+ type: "final"
223
+ }
224
+ }
225
+ },
226
+ {
227
+ activities: {
228
+ trackDocumentVisibility(ctx2, _evt, { send }) {
229
+ if (!ctx2.pauseOnPageIdle)
230
+ return;
231
+ return trackDocumentVisibility(dom.getDoc(ctx2), function(hidden) {
232
+ send(hidden ? "PAUSE" : "RESUME");
233
+ });
234
+ }
235
+ },
236
+ guards: {
237
+ isChangingToLoading: (_, evt) => {
238
+ var _a;
239
+ return ((_a = evt.toast) == null ? void 0 : _a.type) === "loading";
240
+ },
241
+ isLoadingType: (ctx2) => ctx2.type === "loading",
242
+ hasTypeChanged: (ctx2, evt) => {
243
+ var _a;
244
+ return ((_a = evt.toast) == null ? void 0 : _a.type) !== ctx2.type;
245
+ },
246
+ hasDurationChanged: (ctx2, evt) => {
247
+ var _a;
248
+ return ((_a = evt.toast) == null ? void 0 : _a.duration) !== ctx2.duration;
249
+ }
250
+ },
251
+ delays: {
252
+ VISIBLE_DURATION: (ctx2) => ctx2.remaining,
253
+ REMOVE_DELAY: (ctx2) => ctx2.removeDelay
254
+ },
255
+ actions: {
256
+ setRemainingDuration(ctx2) {
257
+ ctx2.remaining -= Date.now() - ctx2.createdAt;
258
+ },
259
+ setCreatedAt(ctx2) {
260
+ ctx2.createdAt = Date.now();
261
+ },
262
+ notifyParentToRemove(_ctx, _evt, { self }) {
263
+ self.sendParent({ type: "REMOVE_TOAST", id: self.id });
264
+ },
265
+ invokeOnClosing(ctx2) {
266
+ var _a;
267
+ (_a = ctx2.onClosing) == null ? void 0 : _a.call(ctx2);
268
+ },
269
+ invokeOnClose(ctx2) {
270
+ var _a;
271
+ (_a = ctx2.onClose) == null ? void 0 : _a.call(ctx2);
272
+ },
273
+ invokeOnOpen(ctx2) {
274
+ var _a;
275
+ (_a = ctx2.onOpen) == null ? void 0 : _a.call(ctx2);
276
+ },
277
+ invokeOnUpdate(ctx2) {
278
+ var _a;
279
+ (_a = ctx2.onUpdate) == null ? void 0 : _a.call(ctx2);
280
+ },
281
+ setContext(ctx2, evt) {
282
+ const { duration: duration2, type: type2 } = evt.toast;
283
+ const time = getToastDuration(duration2, type2);
284
+ Object.assign(ctx2, { ...evt.toast, duration: time, remaining: time });
285
+ }
286
+ }
287
+ }
288
+ );
289
+ }
290
+
291
+ // src/toast-group.machine.ts
292
+ function groupMachine(userContext) {
293
+ const ctx = compact(userContext);
294
+ return (0, import_core2.createMachine)({
295
+ id: "toaster",
296
+ initial: "active",
297
+ context: {
298
+ dir: "ltr",
299
+ max: Number.MAX_SAFE_INTEGER,
300
+ toasts: [],
301
+ gutter: "1rem",
302
+ zIndex: MAX_Z_INDEX,
303
+ pauseOnPageIdle: false,
304
+ pauseOnInteraction: true,
305
+ offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
306
+ ...ctx
307
+ },
308
+ computed: {
309
+ count: (ctx2) => ctx2.toasts.length
310
+ },
311
+ on: {
312
+ SETUP: {},
313
+ PAUSE_TOAST: {
314
+ actions: (_ctx, evt, { self }) => {
315
+ self.sendChild("PAUSE", evt.id);
316
+ }
317
+ },
318
+ PAUSE_ALL: {
319
+ actions: (ctx2) => {
320
+ ctx2.toasts.forEach((toast) => toast.send("PAUSE"));
321
+ }
322
+ },
323
+ RESUME_TOAST: {
324
+ actions: (_ctx, evt, { self }) => {
325
+ self.sendChild("RESUME", evt.id);
326
+ }
327
+ },
328
+ RESUME_ALL: {
329
+ actions: (ctx2) => {
330
+ ctx2.toasts.forEach((toast) => toast.send("RESUME"));
331
+ }
332
+ },
333
+ ADD_TOAST: {
334
+ guard: (ctx2) => ctx2.toasts.length < ctx2.max,
335
+ actions: (ctx2, evt, { self }) => {
336
+ const options = {
337
+ ...evt.toast,
338
+ pauseOnPageIdle: ctx2.pauseOnPageIdle,
339
+ pauseOnInteraction: ctx2.pauseOnInteraction,
340
+ dir: ctx2.dir,
341
+ getRootNode: ctx2.getRootNode
342
+ };
343
+ const toast = createToastMachine(options);
344
+ const actor = self.spawn(toast);
345
+ ctx2.toasts.push(actor);
346
+ }
347
+ },
348
+ UPDATE_TOAST: {
349
+ actions: (_ctx, evt, { self }) => {
350
+ self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
351
+ }
352
+ },
353
+ DISMISS_TOAST: {
354
+ actions: (_ctx, evt, { self }) => {
355
+ self.sendChild("DISMISS", evt.id);
356
+ }
357
+ },
358
+ DISMISS_ALL: {
359
+ actions: (ctx2) => {
360
+ ctx2.toasts.forEach((toast) => toast.send("DISMISS"));
361
+ }
362
+ },
363
+ REMOVE_TOAST: {
364
+ actions: (ctx2, evt, { self }) => {
365
+ self.stopChild(evt.id);
366
+ const index = ctx2.toasts.findIndex((toast) => toast.id === evt.id);
367
+ ctx2.toasts.splice(index, 1);
368
+ }
369
+ },
370
+ REMOVE_ALL: {
371
+ actions: (ctx2, _evt, { self }) => {
372
+ ctx2.toasts.forEach((toast) => self.stopChild(toast.id));
373
+ while (ctx2.toasts.length)
374
+ ctx2.toasts.pop();
375
+ }
376
+ }
377
+ }
378
+ });
379
+ }
380
+ // Annotate the CommonJS export names for ESM import in node:
381
+ 0 && (module.exports = {
382
+ groupMachine
383
+ });