@zag-js/toast 1.47.0 → 1.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.d.mts +10 -17
  2. package/dist/index.d.ts +10 -17
  3. package/dist/index.js +18 -45
  4. package/dist/index.mjs +5 -11
  5. package/dist/toast-group.connect.d.mts +4 -8
  6. package/dist/toast-group.connect.d.ts +4 -8
  7. package/dist/toast-group.connect.js +73 -97
  8. package/dist/toast-group.connect.mjs +68 -61
  9. package/dist/toast-group.machine.d.mts +2 -8
  10. package/dist/toast-group.machine.d.ts +2 -8
  11. package/dist/toast-group.machine.js +292 -346
  12. package/dist/toast-group.machine.mjs +287 -310
  13. package/dist/toast.anatomy.d.mts +2 -6
  14. package/dist/toast.anatomy.d.ts +2 -6
  15. package/dist/toast.anatomy.js +8 -40
  16. package/dist/toast.anatomy.mjs +4 -14
  17. package/dist/toast.connect.d.mts +4 -8
  18. package/dist/toast.connect.d.ts +4 -8
  19. package/dist/toast.connect.js +133 -158
  20. package/dist/toast.connect.mjs +128 -122
  21. package/dist/toast.dom.d.mts +19 -23
  22. package/dist/toast.dom.d.ts +19 -23
  23. package/dist/toast.dom.js +54 -83
  24. package/dist/toast.dom.mjs +39 -47
  25. package/dist/toast.machine.d.mts +2 -8
  26. package/dist/toast.machine.d.ts +2 -8
  27. package/dist/toast.machine.js +272 -300
  28. package/dist/toast.machine.mjs +267 -264
  29. package/dist/toast.store.d.mts +2 -8
  30. package/dist/toast.store.d.ts +2 -8
  31. package/dist/toast.store.js +344 -306
  32. package/dist/toast.store.mjs +340 -281
  33. package/dist/toast.types.d.mts +372 -374
  34. package/dist/toast.types.d.ts +372 -374
  35. package/dist/toast.types.js +4 -18
  36. package/dist/toast.types.mjs +1 -0
  37. package/dist/toast.utils.d.mts +10 -14
  38. package/dist/toast.utils.d.ts +10 -14
  39. package/dist/toast.utils.js +167 -217
  40. package/dist/toast.utils.mjs +157 -186
  41. package/package.json +9 -9
@@ -1,18 +1,4 @@
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 __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/toast.types.ts
17
- var toast_types_exports = {};
18
- module.exports = __toCommonJS(toast_types_exports);
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,10 @@
1
- import { Service } from '@zag-js/core';
2
- import { Style } from '@zag-js/types';
3
- import { Type, ToastSchema, ToastGroupService, Placement, ToastGroupSchema, ToastHeight } from './toast.types.mjs';
4
- import '@zag-js/dom-query';
5
-
6
- declare const defaultTimeouts: Record<Type, number>;
7
- declare function getToastDuration(duration: number | undefined, type: Type): number;
8
- declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
9
- declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
10
- declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
11
- declare function getGhostAfterStyle(): Style;
12
- declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
13
-
14
- export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration, setHeight };
1
+ import { Placement, ToastGroupSchema, ToastGroupService, ToastHeight, ToastSchema, Type } from "./toast.types.mjs";
2
+ import { Service } from "@zag-js/core";
3
+ import { Style } from "@zag-js/types";
4
+ export declare const defaultTimeouts: Record<Type, number>;
5
+ export declare function getToastDuration(duration: number | undefined, type: Type): number;
6
+ export declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
7
+ export declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
8
+ export declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
9
+ export declare function getGhostAfterStyle(): Style;
10
+ export declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
@@ -1,14 +1,10 @@
1
- import { Service } from '@zag-js/core';
2
- import { Style } from '@zag-js/types';
3
- import { Type, ToastSchema, ToastGroupService, Placement, ToastGroupSchema, ToastHeight } from './toast.types.js';
4
- import '@zag-js/dom-query';
5
-
6
- declare const defaultTimeouts: Record<Type, number>;
7
- declare function getToastDuration(duration: number | undefined, type: Type): number;
8
- declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
9
- declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
10
- declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
11
- declare function getGhostAfterStyle(): Style;
12
- declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
13
-
14
- export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration, setHeight };
1
+ import { Placement, ToastGroupSchema, ToastGroupService, ToastHeight, ToastSchema, Type } from "./toast.types.js";
2
+ import { Style } from "@zag-js/types";
3
+ import { Service } from "@zag-js/core";
4
+ export declare const defaultTimeouts: Record<Type, number>;
5
+ export declare function getToastDuration(duration: number | undefined, type: Type): number;
6
+ export declare function getGroupPlacementStyle(service: ToastGroupService, placement: Placement): Style;
7
+ export declare function getPlacementStyle(service: Service<ToastSchema>, visible: boolean): Style;
8
+ export declare function getGhostBeforeStyle(service: Service<ToastSchema>, visible: boolean): Style;
9
+ export declare function getGhostAfterStyle(): Style;
10
+ export declare function setHeight(parent: Service<ToastGroupSchema>, item: ToastHeight): void;
@@ -1,231 +1,181 @@
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.utils.ts
21
- var toast_utils_exports = {};
22
- __export(toast_utils_exports, {
23
- defaultTimeouts: () => defaultTimeouts,
24
- getGhostAfterStyle: () => getGhostAfterStyle,
25
- getGhostBeforeStyle: () => getGhostBeforeStyle,
26
- getGroupPlacementStyle: () => getGroupPlacementStyle,
27
- getPlacementStyle: () => getPlacementStyle,
28
- getToastDuration: () => getToastDuration,
29
- setHeight: () => setHeight
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
30
4
  });
31
- module.exports = __toCommonJS(toast_utils_exports);
32
- var import_dom_query = require("@zag-js/dom-query");
33
- var defaultTimeouts = {
34
- info: 5e3,
35
- error: 5e3,
36
- success: 2e3,
37
- loading: Infinity,
38
- warning: 5e3,
39
- DEFAULT: 5e3
5
+ let _zag_js_dom_query = require("@zag-js/dom-query");
6
+ // src/toast.utils.ts
7
+ const defaultTimeouts = {
8
+ info: 5e3,
9
+ error: 5e3,
10
+ success: 2e3,
11
+ loading: 1e400,
12
+ warning: 5e3,
13
+ DEFAULT: 5e3
40
14
  };
41
15
  function getToastDuration(duration, type) {
42
- return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
16
+ return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
43
17
  }
44
- var getOffsets = (offsets) => typeof offsets === "string" ? { left: offsets, right: offsets, bottom: offsets, top: offsets } : offsets;
18
+ const getOffsets = (offsets) => typeof offsets === "string" ? {
19
+ left: offsets,
20
+ right: offsets,
21
+ bottom: offsets,
22
+ top: offsets
23
+ } : offsets;
45
24
  function getGroupPlacementStyle(service, placement) {
46
- const { prop, computed, context } = service;
47
- const { offsets, gap } = prop("store").attrs;
48
- const heights = context.get("heights");
49
- const computedOffset = getOffsets(offsets);
50
- const rtl = prop("dir") === "rtl";
51
- const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
52
- const isRighty = computedPlacement.includes("right");
53
- const isLefty = computedPlacement.includes("left");
54
- const styles = {
55
- position: "fixed",
56
- pointerEvents: computed("count") > 0 ? void 0 : "none",
57
- display: "flex",
58
- flexDirection: "column",
59
- "--gap": `${gap}px`,
60
- "--first-height": `${heights[0]?.height || 0}px`,
61
- "--viewport-offset-left": computedOffset.left,
62
- "--viewport-offset-right": computedOffset.right,
63
- "--viewport-offset-top": computedOffset.top,
64
- "--viewport-offset-bottom": computedOffset.bottom,
65
- zIndex: import_dom_query.MAX_Z_INDEX
66
- };
67
- let alignItems = "center";
68
- if (isRighty) alignItems = "flex-end";
69
- if (isLefty) alignItems = "flex-start";
70
- styles.alignItems = alignItems;
71
- if (computedPlacement.includes("top")) {
72
- const offset = computedOffset.top;
73
- styles.top = `max(env(safe-area-inset-top, 0px), ${offset})`;
74
- }
75
- if (computedPlacement.includes("bottom")) {
76
- const offset = computedOffset.bottom;
77
- styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${offset})`;
78
- }
79
- if (!computedPlacement.includes("left")) {
80
- const offset = computedOffset.right;
81
- styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${offset})`;
82
- }
83
- if (!computedPlacement.includes("right")) {
84
- const offset = computedOffset.left;
85
- styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${offset})`;
86
- }
87
- return styles;
25
+ const { prop, computed, context } = service;
26
+ const { offsets, gap } = prop("store").attrs;
27
+ const heights = context.get("heights");
28
+ const computedOffset = getOffsets(offsets);
29
+ const rtl = prop("dir") === "rtl";
30
+ const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
31
+ const isRighty = computedPlacement.includes("right");
32
+ const isLefty = computedPlacement.includes("left");
33
+ const styles = {
34
+ position: "fixed",
35
+ pointerEvents: computed("count") > 0 ? void 0 : "none",
36
+ display: "flex",
37
+ flexDirection: "column",
38
+ "--gap": `${gap}px`,
39
+ "--first-height": `${heights[0]?.height || 0}px`,
40
+ "--viewport-offset-left": computedOffset.left,
41
+ "--viewport-offset-right": computedOffset.right,
42
+ "--viewport-offset-top": computedOffset.top,
43
+ "--viewport-offset-bottom": computedOffset.bottom,
44
+ zIndex: _zag_js_dom_query.MAX_Z_INDEX
45
+ };
46
+ let alignItems = "center";
47
+ if (isRighty) alignItems = "flex-end";
48
+ if (isLefty) alignItems = "flex-start";
49
+ styles.alignItems = alignItems;
50
+ if (computedPlacement.includes("top")) styles.top = `max(env(safe-area-inset-top, 0px), ${computedOffset.top})`;
51
+ if (computedPlacement.includes("bottom")) styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${computedOffset.bottom})`;
52
+ if (!computedPlacement.includes("left")) styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${computedOffset.right})`;
53
+ if (!computedPlacement.includes("right")) styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${computedOffset.left})`;
54
+ return styles;
88
55
  }
89
56
  function getPlacementStyle(service, visible) {
90
- const { prop, context, computed } = service;
91
- const parent = prop("parent");
92
- const placement = parent.computed("placement");
93
- const { gap } = parent.prop("store").attrs;
94
- const [side] = placement.split("-");
95
- const mounted = context.get("mounted");
96
- const remainingTime = context.get("remainingTime");
97
- const height = computed("height");
98
- const frontmost = computed("frontmost");
99
- const sibling = !frontmost;
100
- const stacked = prop("parent").state.matches("stack");
101
- const overlap = !stacked;
102
- const type = prop("type");
103
- const duration = type === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
104
- const offset = computed("heightIndex") * gap + computed("heightBefore");
105
- const styles = {
106
- position: "absolute",
107
- pointerEvents: "auto",
108
- "--opacity": "0",
109
- "--remove-delay": `${prop("removeDelay")}ms`,
110
- "--duration": `${duration}ms`,
111
- "--initial-height": `${height}px`,
112
- "--offset": `${offset}px`,
113
- "--index": prop("index"),
114
- "--z-index": computed("zIndex"),
115
- "--lift-amount": "calc(var(--lift) * var(--gap))",
116
- "--y": "100%",
117
- "--x": "0"
118
- };
119
- const assign = (overrides) => Object.assign(styles, overrides);
120
- if (side === "top") {
121
- assign({
122
- top: "0",
123
- "--sign": "-1",
124
- "--y": "-100%",
125
- "--lift": "1"
126
- });
127
- } else if (side === "bottom") {
128
- assign({
129
- bottom: "0",
130
- "--sign": "1",
131
- "--y": "100%",
132
- "--lift": "-1"
133
- });
134
- }
135
- if (mounted) {
136
- assign({
137
- "--y": "0",
138
- "--opacity": "1"
139
- });
140
- if (stacked) {
141
- assign({
142
- "--y": "calc(var(--lift) * var(--offset))",
143
- "--height": "var(--initial-height)"
144
- });
145
- }
146
- }
147
- if (!visible) {
148
- assign({
149
- "--opacity": "0",
150
- pointerEvents: "none"
151
- });
152
- }
153
- if (sibling && overlap) {
154
- assign({
155
- "--base-scale": "var(--index) * 0.05 + 1",
156
- "--y": "calc(var(--lift-amount) * var(--index))",
157
- "--scale": "calc(-1 * var(--base-scale))",
158
- "--height": "var(--first-height)"
159
- });
160
- if (!visible) {
161
- assign({
162
- "--y": "calc(var(--sign) * 40%)"
163
- });
164
- }
165
- }
166
- if (sibling && stacked && !visible) {
167
- assign({
168
- "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)"
169
- });
170
- }
171
- if (frontmost && !visible) {
172
- assign({
173
- "--y": "calc(var(--lift) * -100%)"
174
- });
175
- }
176
- return styles;
57
+ const { prop, context, computed } = service;
58
+ const parent = prop("parent");
59
+ const placement = parent.computed("placement");
60
+ const { gap } = parent.prop("store").attrs;
61
+ const [side] = placement.split("-");
62
+ const mounted = context.get("mounted");
63
+ const remainingTime = context.get("remainingTime");
64
+ const height = computed("height");
65
+ const frontmost = computed("frontmost");
66
+ const sibling = !frontmost;
67
+ const stacked = prop("parent").state.matches("stack");
68
+ const overlap = !stacked;
69
+ const duration = prop("type") === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
70
+ const offset = computed("heightIndex") * gap + computed("heightBefore");
71
+ const styles = {
72
+ position: "absolute",
73
+ pointerEvents: "auto",
74
+ "--opacity": "0",
75
+ "--remove-delay": `${prop("removeDelay")}ms`,
76
+ "--duration": `${duration}ms`,
77
+ "--initial-height": `${height}px`,
78
+ "--offset": `${offset}px`,
79
+ "--index": prop("index"),
80
+ "--z-index": computed("zIndex"),
81
+ "--lift-amount": "calc(var(--lift) * var(--gap))",
82
+ "--y": "100%",
83
+ "--x": "0"
84
+ };
85
+ const assign = (overrides) => Object.assign(styles, overrides);
86
+ if (side === "top") assign({
87
+ top: "0",
88
+ "--sign": "-1",
89
+ "--y": "-100%",
90
+ "--lift": "1"
91
+ });
92
+ else if (side === "bottom") assign({
93
+ bottom: "0",
94
+ "--sign": "1",
95
+ "--y": "100%",
96
+ "--lift": "-1"
97
+ });
98
+ if (mounted) {
99
+ assign({
100
+ "--y": "0",
101
+ "--opacity": "1"
102
+ });
103
+ if (stacked) assign({
104
+ "--y": "calc(var(--lift) * var(--offset))",
105
+ "--height": "var(--initial-height)"
106
+ });
107
+ }
108
+ if (!visible) assign({
109
+ "--opacity": "0",
110
+ pointerEvents: "none"
111
+ });
112
+ if (sibling && overlap) {
113
+ assign({
114
+ "--base-scale": "var(--index) * 0.05 + 1",
115
+ "--y": "calc(var(--lift-amount) * var(--index))",
116
+ "--scale": "calc(-1 * var(--base-scale))",
117
+ "--height": "var(--first-height)"
118
+ });
119
+ if (!visible) assign({ "--y": "calc(var(--sign) * 40%)" });
120
+ }
121
+ if (sibling && stacked && !visible) assign({ "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)" });
122
+ if (frontmost && !visible) assign({ "--y": "calc(var(--lift) * -100%)" });
123
+ return styles;
177
124
  }
178
125
  function getGhostBeforeStyle(service, visible) {
179
- const { computed } = service;
180
- const styles = {
181
- position: "absolute",
182
- inset: "0",
183
- scale: "1 2",
184
- pointerEvents: visible ? "none" : "auto"
185
- };
186
- const assign = (overrides) => Object.assign(styles, overrides);
187
- if (computed("frontmost") && !visible) {
188
- assign({
189
- height: "calc(var(--initial-height) + 80%)"
190
- });
191
- }
192
- return styles;
126
+ const { computed } = service;
127
+ const styles = {
128
+ position: "absolute",
129
+ inset: "0",
130
+ scale: "1 2",
131
+ pointerEvents: visible ? "none" : "auto"
132
+ };
133
+ const assign = (overrides) => Object.assign(styles, overrides);
134
+ if (computed("frontmost") && !visible) assign({ height: "calc(var(--initial-height) + 80%)" });
135
+ return styles;
193
136
  }
194
137
  function getGhostAfterStyle() {
195
- return {
196
- position: "absolute",
197
- left: "0",
198
- height: "calc(var(--gap) + 2px)",
199
- bottom: "100%",
200
- width: "100%"
201
- };
138
+ return {
139
+ position: "absolute",
140
+ left: "0",
141
+ height: "calc(var(--gap) + 2px)",
142
+ bottom: "100%",
143
+ width: "100%"
144
+ };
202
145
  }
203
146
  function setHeight(parent, item) {
204
- const { id, height } = item;
205
- parent.context.set("heights", (prev) => {
206
- const existing = prev.find((i) => i.id === id);
207
- if (existing) {
208
- if (existing.height === height) return prev;
209
- return prev.map((i) => i.id === id ? { ...i, height } : i);
210
- }
211
- const toasts = parent.context.get("toasts");
212
- const rank = (id2) => toasts.findIndex((t) => t.id === id2);
213
- const index = rank(id);
214
- let insertAt = prev.findIndex((i) => {
215
- const r = rank(i.id);
216
- return r === -1 || r > index;
217
- });
218
- if (insertAt === -1) insertAt = prev.length;
219
- return [...prev.slice(0, insertAt), { id, height }, ...prev.slice(insertAt)];
220
- });
147
+ const { id, height } = item;
148
+ parent.context.set("heights", (prev) => {
149
+ const existing = prev.find((i) => i.id === id);
150
+ if (existing) {
151
+ if (existing.height === height) return prev;
152
+ return prev.map((i) => i.id === id ? {
153
+ ...i,
154
+ height
155
+ } : i);
156
+ }
157
+ const toasts = parent.context.get("toasts");
158
+ const rank = (id) => toasts.findIndex((t) => t.id === id);
159
+ const index = rank(id);
160
+ let insertAt = prev.findIndex((i) => {
161
+ const r = rank(i.id);
162
+ return r === -1 || r > index;
163
+ });
164
+ if (insertAt === -1) insertAt = prev.length;
165
+ return [
166
+ ...prev.slice(0, insertAt),
167
+ {
168
+ id,
169
+ height
170
+ },
171
+ ...prev.slice(insertAt)
172
+ ];
173
+ });
221
174
  }
222
- // Annotate the CommonJS export names for ESM import in node:
223
- 0 && (module.exports = {
224
- defaultTimeouts,
225
- getGhostAfterStyle,
226
- getGhostBeforeStyle,
227
- getGroupPlacementStyle,
228
- getPlacementStyle,
229
- getToastDuration,
230
- setHeight
231
- });
175
+ exports.defaultTimeouts = defaultTimeouts;
176
+ exports.getGhostAfterStyle = getGhostAfterStyle;
177
+ exports.getGhostBeforeStyle = getGhostBeforeStyle;
178
+ exports.getGroupPlacementStyle = getGroupPlacementStyle;
179
+ exports.getPlacementStyle = getPlacementStyle;
180
+ exports.getToastDuration = getToastDuration;
181
+ exports.setHeight = setHeight;