@zag-js/toast 0.10.2 → 0.10.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.
@@ -1,9 +1,95 @@
1
- import {
2
- groupMachine
3
- } from "./chunk-TCF4OLIQ.mjs";
4
- import "./chunk-EQTV3BNM.mjs";
5
- import "./chunk-DBPKSADW.mjs";
6
- import "./chunk-DUZD3NLM.mjs";
7
- export {
8
- groupMachine
9
- };
1
+ import { createMachine } from '@zag-js/core';
2
+ import { MAX_Z_INDEX } from '@zag-js/dom-query';
3
+ import { compact } from '@zag-js/utils';
4
+ import { createToastMachine } from './toast.machine.mjs';
5
+
6
+ function groupMachine(userContext) {
7
+ const ctx = compact(userContext);
8
+ return createMachine({
9
+ id: "toaster",
10
+ initial: "active",
11
+ context: {
12
+ dir: "ltr",
13
+ max: Number.MAX_SAFE_INTEGER,
14
+ toasts: [],
15
+ gutter: "1rem",
16
+ zIndex: MAX_Z_INDEX,
17
+ pauseOnPageIdle: false,
18
+ pauseOnInteraction: true,
19
+ offsets: { left: "0px", right: "0px", top: "0px", bottom: "0px" },
20
+ ...ctx
21
+ },
22
+ computed: {
23
+ count: (ctx2) => ctx2.toasts.length
24
+ },
25
+ on: {
26
+ SETUP: {},
27
+ PAUSE_TOAST: {
28
+ actions: (_ctx, evt, { self }) => {
29
+ self.sendChild("PAUSE", evt.id);
30
+ }
31
+ },
32
+ PAUSE_ALL: {
33
+ actions: (ctx2) => {
34
+ ctx2.toasts.forEach((toast) => toast.send("PAUSE"));
35
+ }
36
+ },
37
+ RESUME_TOAST: {
38
+ actions: (_ctx, evt, { self }) => {
39
+ self.sendChild("RESUME", evt.id);
40
+ }
41
+ },
42
+ RESUME_ALL: {
43
+ actions: (ctx2) => {
44
+ ctx2.toasts.forEach((toast) => toast.send("RESUME"));
45
+ }
46
+ },
47
+ ADD_TOAST: {
48
+ guard: (ctx2) => ctx2.toasts.length < ctx2.max,
49
+ actions: (ctx2, evt, { self }) => {
50
+ const options = {
51
+ ...evt.toast,
52
+ pauseOnPageIdle: ctx2.pauseOnPageIdle,
53
+ pauseOnInteraction: ctx2.pauseOnInteraction,
54
+ dir: ctx2.dir,
55
+ getRootNode: ctx2.getRootNode
56
+ };
57
+ const toast = createToastMachine(options);
58
+ const actor = self.spawn(toast);
59
+ ctx2.toasts.push(actor);
60
+ }
61
+ },
62
+ UPDATE_TOAST: {
63
+ actions: (_ctx, evt, { self }) => {
64
+ self.sendChild({ type: "UPDATE", toast: evt.toast }, evt.id);
65
+ }
66
+ },
67
+ DISMISS_TOAST: {
68
+ actions: (_ctx, evt, { self }) => {
69
+ self.sendChild("DISMISS", evt.id);
70
+ }
71
+ },
72
+ DISMISS_ALL: {
73
+ actions: (ctx2) => {
74
+ ctx2.toasts.forEach((toast) => toast.send("DISMISS"));
75
+ }
76
+ },
77
+ REMOVE_TOAST: {
78
+ actions: (ctx2, evt, { self }) => {
79
+ self.stopChild(evt.id);
80
+ const index = ctx2.toasts.findIndex((toast) => toast.id === evt.id);
81
+ ctx2.toasts.splice(index, 1);
82
+ }
83
+ },
84
+ REMOVE_ALL: {
85
+ actions: (ctx2, _evt, { self }) => {
86
+ ctx2.toasts.forEach((toast) => self.stopChild(toast.id));
87
+ while (ctx2.toasts.length)
88
+ ctx2.toasts.pop();
89
+ }
90
+ }
91
+ }
92
+ });
93
+ }
94
+
95
+ export { groupMachine };
@@ -1,6 +1,3 @@
1
- import * as _zag_js_anatomy from '@zag-js/anatomy';
2
-
3
- declare const anatomy: _zag_js_anatomy.AnatomyInstance<"title" | "group" | "root" | "description" | "closeTrigger">;
4
- declare const parts: Record<"title" | "group" | "root" | "description" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
5
-
6
- export { anatomy, parts };
1
+ import { AnatomyInstance, AnatomyPart } from '@zag-js/anatomy';
2
+ export declare const anatomy: AnatomyInstance<"title" | "group" | "root" | "description" | "closeTrigger">;
3
+ export declare const parts: Record<"title" | "group" | "root" | "description" | "closeTrigger", AnatomyPart>;
@@ -1,34 +1,11 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/toast.anatomy.ts
21
- var toast_anatomy_exports = {};
22
- __export(toast_anatomy_exports, {
23
- anatomy: () => anatomy,
24
- parts: () => parts
25
- });
26
- module.exports = __toCommonJS(toast_anatomy_exports);
27
- var import_anatomy = require("@zag-js/anatomy");
28
- var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
29
- var parts = anatomy.build();
30
- // Annotate the CommonJS export names for ESM import in node:
31
- 0 && (module.exports = {
32
- anatomy,
33
- parts
34
- });
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const anatomy$1 = require('@zag-js/anatomy');
6
+
7
+ const anatomy = anatomy$1.createAnatomy("toast").parts("group", "root", "title", "description", "closeTrigger");
8
+ const parts = anatomy.build();
9
+
10
+ exports.anatomy = anatomy;
11
+ exports.parts = parts;
@@ -1,8 +1,6 @@
1
- import {
2
- anatomy,
3
- parts
4
- } from "./chunk-GQHI2OMI.mjs";
5
- export {
6
- anatomy,
7
- parts
8
- };
1
+ import { createAnatomy } from '@zag-js/anatomy';
2
+
3
+ const anatomy = createAnatomy("toast").parts("group", "root", "title", "description", "closeTrigger");
4
+ const parts = anatomy.build();
5
+
6
+ export { anatomy, parts };
@@ -1,8 +1,6 @@
1
- import { State, Send, Type, Placement } from './toast.types.js';
2
- import { PropTypes, NormalizeProps } from '@zag-js/types';
3
- import '@zag-js/core';
4
-
5
- declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
1
+ import type { NormalizeProps, PropTypes } from "@zag-js/types";
2
+ import { Type, Placement, Send, State } from './toast.types';
3
+ export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
6
4
  /**
7
5
  * The type of the toast.
8
6
  */
@@ -52,5 +50,3 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
52
50
  descriptionProps: T["element"];
53
51
  closeTriggerProps: T["button"];
54
52
  };
55
-
56
- export { connect };
@@ -1,47 +1,11 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/toast.connect.ts
21
- var toast_connect_exports = {};
22
- __export(toast_connect_exports, {
23
- connect: () => connect
24
- });
25
- module.exports = __toCommonJS(toast_connect_exports);
26
- var import_dom_query2 = require("@zag-js/dom-query");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
27
4
 
28
- // src/toast.anatomy.ts
29
- var import_anatomy = require("@zag-js/anatomy");
30
- var anatomy = (0, import_anatomy.createAnatomy)("toast").parts("group", "root", "title", "description", "closeTrigger");
31
- var parts = anatomy.build();
5
+ const domQuery = require('@zag-js/dom-query');
6
+ const toast_anatomy = require('./toast.anatomy.js');
7
+ const toast_dom = require('./toast.dom.js');
32
8
 
33
- // src/toast.dom.ts
34
- var import_dom_query = require("@zag-js/dom-query");
35
- var dom = (0, import_dom_query.createScope)({
36
- getGroupId: (placement) => `toast-group:${placement}`,
37
- getRootId: (ctx) => `toast:${ctx.id}`,
38
- getTitleId: (ctx) => `toast:${ctx.id}:title`,
39
- getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
40
- getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
41
- getPortalId: (ctx) => `toast-portal:${ctx.id}`
42
- });
43
-
44
- // src/toast.connect.ts
45
9
  function connect(state, send, normalize) {
46
10
  const isVisible = state.hasTag("visible");
47
11
  const isPaused = state.hasTag("paused");
@@ -111,10 +75,10 @@ function connect(state, send, normalize) {
111
75
  });
112
76
  },
113
77
  rootProps: normalize.element({
114
- ...parts.root.attrs,
78
+ ...toast_anatomy.parts.root.attrs,
115
79
  dir: state.context.dir,
116
- id: dom.getRootId(state.context),
117
- "data-open": (0, import_dom_query2.dataAttr)(isVisible),
80
+ id: toast_dom.dom.getRootId(state.context),
81
+ "data-open": domQuery.dataAttr(isVisible),
118
82
  "data-type": state.context.type,
119
83
  "data-placement": placement,
120
84
  role: "status",
@@ -155,16 +119,16 @@ function connect(state, send, normalize) {
155
119
  }
156
120
  }),
157
121
  titleProps: normalize.element({
158
- ...parts.title.attrs,
159
- id: dom.getTitleId(state.context)
122
+ ...toast_anatomy.parts.title.attrs,
123
+ id: toast_dom.dom.getTitleId(state.context)
160
124
  }),
161
125
  descriptionProps: normalize.element({
162
- ...parts.description.attrs,
163
- id: dom.getDescriptionId(state.context)
126
+ ...toast_anatomy.parts.description.attrs,
127
+ id: toast_dom.dom.getDescriptionId(state.context)
164
128
  }),
165
129
  closeTriggerProps: normalize.button({
166
- id: dom.getCloseTriggerId(state.context),
167
- ...parts.closeTrigger.attrs,
130
+ id: toast_dom.dom.getCloseTriggerId(state.context),
131
+ ...toast_anatomy.parts.closeTrigger.attrs,
168
132
  type: "button",
169
133
  "aria-label": "Dismiss notification",
170
134
  onClick() {
@@ -173,7 +137,5 @@ function connect(state, send, normalize) {
173
137
  })
174
138
  };
175
139
  }
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
178
- connect
179
- });
140
+
141
+ exports.connect = connect;
@@ -1,8 +1,137 @@
1
- import {
2
- connect
3
- } from "./chunk-MUJMFD4Y.mjs";
4
- import "./chunk-GQHI2OMI.mjs";
5
- import "./chunk-DUZD3NLM.mjs";
6
- export {
7
- connect
8
- };
1
+ import { dataAttr } from '@zag-js/dom-query';
2
+ import { parts } from './toast.anatomy.mjs';
3
+ import { dom } from './toast.dom.mjs';
4
+
5
+ function connect(state, send, normalize) {
6
+ const isVisible = state.hasTag("visible");
7
+ const isPaused = state.hasTag("paused");
8
+ const pauseOnInteraction = state.context.pauseOnInteraction;
9
+ const placement = state.context.placement;
10
+ return {
11
+ /**
12
+ * The type of the toast.
13
+ */
14
+ type: state.context.type,
15
+ /**
16
+ * The title of the toast.
17
+ */
18
+ title: state.context.title,
19
+ /**
20
+ * The description of the toast.
21
+ */
22
+ description: state.context.description,
23
+ /**
24
+ * The current placement of the toast.
25
+ */
26
+ placement,
27
+ /**
28
+ * Whether the toast is visible.
29
+ */
30
+ isVisible,
31
+ /**
32
+ * Whether the toast is paused.
33
+ */
34
+ isPaused,
35
+ /**
36
+ * Whether the toast is in RTL mode.
37
+ */
38
+ isRtl: state.context.dir === "rtl",
39
+ /**
40
+ * Function to pause the toast (keeping it visible).
41
+ */
42
+ pause() {
43
+ send("PAUSE");
44
+ },
45
+ /**
46
+ * Function to resume the toast dismissing.
47
+ */
48
+ resume() {
49
+ send("RESUME");
50
+ },
51
+ /**
52
+ * Function to instantly dismiss the toast.
53
+ */
54
+ dismiss() {
55
+ send("DISMISS");
56
+ },
57
+ /**
58
+ * Function render the toast in the DOM (based on the defined `render` property)
59
+ */
60
+ render() {
61
+ return state.context.render?.({
62
+ id: state.context.id,
63
+ type: state.context.type,
64
+ duration: state.context.duration,
65
+ title: state.context.title,
66
+ placement: state.context.placement,
67
+ description: state.context.description,
68
+ dismiss() {
69
+ send("DISMISS");
70
+ }
71
+ });
72
+ },
73
+ rootProps: normalize.element({
74
+ ...parts.root.attrs,
75
+ dir: state.context.dir,
76
+ id: dom.getRootId(state.context),
77
+ "data-open": dataAttr(isVisible),
78
+ "data-type": state.context.type,
79
+ "data-placement": placement,
80
+ role: "status",
81
+ "aria-atomic": "true",
82
+ tabIndex: 0,
83
+ style: {
84
+ position: "relative",
85
+ pointerEvents: "auto",
86
+ margin: "calc(var(--toast-gutter) / 2)",
87
+ "--remove-delay": `${state.context.removeDelay}ms`,
88
+ "--duration": `${state.context.duration}ms`
89
+ },
90
+ onKeyDown(event) {
91
+ if (event.key == "Escape") {
92
+ send("DISMISS");
93
+ event.preventDefault();
94
+ }
95
+ },
96
+ onFocus() {
97
+ if (pauseOnInteraction) {
98
+ send("PAUSE");
99
+ }
100
+ },
101
+ onBlur() {
102
+ if (pauseOnInteraction) {
103
+ send("RESUME");
104
+ }
105
+ },
106
+ onPointerEnter() {
107
+ if (pauseOnInteraction) {
108
+ send("PAUSE");
109
+ }
110
+ },
111
+ onPointerLeave() {
112
+ if (pauseOnInteraction) {
113
+ send("RESUME");
114
+ }
115
+ }
116
+ }),
117
+ titleProps: normalize.element({
118
+ ...parts.title.attrs,
119
+ id: dom.getTitleId(state.context)
120
+ }),
121
+ descriptionProps: normalize.element({
122
+ ...parts.description.attrs,
123
+ id: dom.getDescriptionId(state.context)
124
+ }),
125
+ closeTriggerProps: normalize.button({
126
+ id: dom.getCloseTriggerId(state.context),
127
+ ...parts.closeTrigger.attrs,
128
+ type: "button",
129
+ "aria-label": "Dismiss notification",
130
+ onClick() {
131
+ send("DISMISS");
132
+ }
133
+ })
134
+ };
135
+ }
136
+
137
+ export { connect };
@@ -1,8 +1,5 @@
1
- import { Placement, MachineContext, GroupMachineContext } from './toast.types.js';
2
- import '@zag-js/core';
3
- import '@zag-js/types';
4
-
5
- declare const dom: {
1
+ import type { GroupMachineContext as GroupCtx, MachineContext as Ctx, Placement } from "./toast.types";
2
+ export declare const dom: {
6
3
  getRootNode: (ctx: {
7
4
  getRootNode?: (() => Node | Document | ShadowRoot) | undefined;
8
5
  }) => Document | ShadowRoot;
@@ -23,11 +20,9 @@ declare const dom: {
23
20
  }, id: string) => T_1;
24
21
  } & {
25
22
  getGroupId: (placement: Placement) => string;
26
- getRootId: (ctx: MachineContext) => string;
27
- getTitleId: (ctx: MachineContext) => string;
28
- getDescriptionId: (ctx: MachineContext) => string;
29
- getCloseTriggerId: (ctx: MachineContext) => string;
30
- getPortalId: (ctx: GroupMachineContext) => string;
23
+ getRootId: (ctx: Ctx) => string;
24
+ getTitleId: (ctx: Ctx) => string;
25
+ getDescriptionId: (ctx: Ctx) => string;
26
+ getCloseTriggerId: (ctx: Ctx) => string;
27
+ getPortalId: (ctx: GroupCtx) => string;
31
28
  };
32
-
33
- export { dom };
package/dist/toast.dom.js CHANGED
@@ -1,30 +1,10 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/toast.dom.ts
21
- var toast_dom_exports = {};
22
- __export(toast_dom_exports, {
23
- dom: () => dom
24
- });
25
- module.exports = __toCommonJS(toast_dom_exports);
26
- var import_dom_query = require("@zag-js/dom-query");
27
- var dom = (0, import_dom_query.createScope)({
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const domQuery = require('@zag-js/dom-query');
6
+
7
+ const dom = domQuery.createScope({
28
8
  getGroupId: (placement) => `toast-group:${placement}`,
29
9
  getRootId: (ctx) => `toast:${ctx.id}`,
30
10
  getTitleId: (ctx) => `toast:${ctx.id}:title`,
@@ -32,7 +12,5 @@ var dom = (0, import_dom_query.createScope)({
32
12
  getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
33
13
  getPortalId: (ctx) => `toast-portal:${ctx.id}`
34
14
  });
35
- // Annotate the CommonJS export names for ESM import in node:
36
- 0 && (module.exports = {
37
- dom
38
- });
15
+
16
+ exports.dom = dom;
@@ -1,6 +1,12 @@
1
- import {
2
- dom
3
- } from "./chunk-DUZD3NLM.mjs";
4
- export {
5
- dom
6
- };
1
+ import { createScope } from '@zag-js/dom-query';
2
+
3
+ const dom = createScope({
4
+ getGroupId: (placement) => `toast-group:${placement}`,
5
+ getRootId: (ctx) => `toast:${ctx.id}`,
6
+ getTitleId: (ctx) => `toast:${ctx.id}:title`,
7
+ getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
8
+ getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
9
+ getPortalId: (ctx) => `toast-portal:${ctx.id}`
10
+ });
11
+
12
+ export { dom };
@@ -1,7 +1,3 @@
1
- import * as _zag_js_core from '@zag-js/core';
2
- import { Options, MachineContext, MachineState } from './toast.types.js';
3
- import '@zag-js/types';
4
-
5
- declare function createToastMachine(options?: Options): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
6
-
7
- export { createToastMachine };
1
+ import { Machine, StateMachine } from '@zag-js/core';
2
+ import type { MachineContext, MachineState, Options } from "./toast.types";
3
+ export declare function createToastMachine(options?: Options): Machine<MachineContext, MachineState, StateMachine.AnyEventObject>;
@@ -1,62 +1,19 @@
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);
1
+ 'use strict';
19
2
 
20
- // src/toast.machine.ts
21
- var toast_machine_exports = {};
22
- __export(toast_machine_exports, {
23
- createToastMachine: () => createToastMachine
24
- });
25
- module.exports = __toCommonJS(toast_machine_exports);
26
- var import_core = require("@zag-js/core");
27
- var import_dom_event = require("@zag-js/dom-event");
28
- var import_utils = require("@zag-js/utils");
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
29
4
 
30
- // src/toast.dom.ts
31
- var import_dom_query = require("@zag-js/dom-query");
32
- var dom = (0, import_dom_query.createScope)({
33
- getGroupId: (placement) => `toast-group:${placement}`,
34
- getRootId: (ctx) => `toast:${ctx.id}`,
35
- getTitleId: (ctx) => `toast:${ctx.id}:title`,
36
- getDescriptionId: (ctx) => `toast:${ctx.id}:description`,
37
- getCloseTriggerId: (ctx) => `toast${ctx.id}:close`,
38
- getPortalId: (ctx) => `toast-portal:${ctx.id}`
39
- });
5
+ const core = require('@zag-js/core');
6
+ const domEvent = require('@zag-js/dom-event');
7
+ const utils = require('@zag-js/utils');
8
+ const toast_dom = require('./toast.dom.js');
9
+ const toast_utils = require('./toast.utils.js');
40
10
 
41
- // src/toast.utils.ts
42
- var defaultTimeouts = {
43
- info: 5e3,
44
- error: 5e3,
45
- success: 2e3,
46
- loading: Infinity,
47
- custom: 5e3
48
- };
49
- function getToastDuration(duration, type) {
50
- return duration ?? defaultTimeouts[type];
51
- }
52
-
53
- // src/toast.machine.ts
54
- var { not, and, or } = import_core.guards;
11
+ const { not, and, or } = core.guards;
55
12
  function createToastMachine(options = {}) {
56
13
  const { type = "info", duration, id = "toast", placement = "bottom", removeDelay = 0, ...restProps } = options;
57
- const ctx = (0, import_utils.compact)(restProps);
58
- const computedDuration = getToastDuration(duration, type);
59
- return (0, import_core.createMachine)(
14
+ const ctx = utils.compact(restProps);
15
+ const computedDuration = toast_utils.getToastDuration(duration, type);
16
+ return core.createMachine(
60
17
  {
61
18
  id,
62
19
  entry: "invokeOnOpen",
@@ -141,8 +98,8 @@ function createToastMachine(options = {}) {
141
98
  trackDocumentVisibility(ctx2, _evt, { send }) {
142
99
  if (!ctx2.pauseOnPageIdle)
143
100
  return;
144
- const doc = dom.getDoc(ctx2);
145
- return (0, import_dom_event.addDomEvent)(doc, "visibilitychange", () => {
101
+ const doc = toast_dom.dom.getDoc(ctx2);
102
+ return domEvent.addDomEvent(doc, "visibilitychange", () => {
146
103
  send(doc.visibilityState === "hidden" ? "PAUSE" : "RESUME");
147
104
  });
148
105
  }
@@ -181,14 +138,12 @@ function createToastMachine(options = {}) {
181
138
  },
182
139
  setContext(ctx2, evt) {
183
140
  const { duration: duration2, type: type2 } = evt.toast;
184
- const time = getToastDuration(duration2, type2);
141
+ const time = toast_utils.getToastDuration(duration2, type2);
185
142
  Object.assign(ctx2, { ...evt.toast, duration: time, remaining: time });
186
143
  }
187
144
  }
188
145
  }
189
146
  );
190
147
  }
191
- // Annotate the CommonJS export names for ESM import in node:
192
- 0 && (module.exports = {
193
- createToastMachine
194
- });
148
+
149
+ exports.createToastMachine = createToastMachine;