@zag-js/toast 1.46.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 +294 -302
  12. package/dist/toast-group.machine.mjs +289 -266
  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 +21 -16
  22. package/dist/toast.dom.d.ts +21 -16
  23. package/dist/toast.dom.js +56 -53
  24. package/dist/toast.dom.mjs +42 -20
  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 -311
  28. package/dist/toast.machine.mjs +268 -276
  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 -299
  32. package/dist/toast.store.mjs +340 -274
  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 -13
  38. package/dist/toast.utils.d.ts +10 -13
  39. package/dist/toast.utils.js +169 -198
  40. package/dist/toast.utils.mjs +159 -168
  41. package/package.json +9 -9
@@ -1,180 +1,171 @@
1
- // src/toast.utils.ts
2
1
  import { MAX_Z_INDEX } from "@zag-js/dom-query";
3
- var defaultTimeouts = {
4
- info: 5e3,
5
- error: 5e3,
6
- success: 2e3,
7
- loading: Infinity,
8
- warning: 5e3,
9
- DEFAULT: 5e3
2
+ // src/toast.utils.ts
3
+ const defaultTimeouts = {
4
+ info: 5e3,
5
+ error: 5e3,
6
+ success: 2e3,
7
+ loading: 1e400,
8
+ warning: 5e3,
9
+ DEFAULT: 5e3
10
10
  };
11
11
  function getToastDuration(duration, type) {
12
- return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
12
+ return duration ?? defaultTimeouts[type] ?? defaultTimeouts.DEFAULT;
13
13
  }
14
- var getOffsets = (offsets) => typeof offsets === "string" ? { left: offsets, right: offsets, bottom: offsets, top: offsets } : offsets;
14
+ const getOffsets = (offsets) => typeof offsets === "string" ? {
15
+ left: offsets,
16
+ right: offsets,
17
+ bottom: offsets,
18
+ top: offsets
19
+ } : offsets;
15
20
  function getGroupPlacementStyle(service, placement) {
16
- const { prop, computed, context } = service;
17
- const { offsets, gap } = prop("store").attrs;
18
- const heights = context.get("heights");
19
- const computedOffset = getOffsets(offsets);
20
- const rtl = prop("dir") === "rtl";
21
- const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
22
- const isRighty = computedPlacement.includes("right");
23
- const isLefty = computedPlacement.includes("left");
24
- const styles = {
25
- position: "fixed",
26
- pointerEvents: computed("count") > 0 ? void 0 : "none",
27
- display: "flex",
28
- flexDirection: "column",
29
- "--gap": `${gap}px`,
30
- "--first-height": `${heights[0]?.height || 0}px`,
31
- "--viewport-offset-left": computedOffset.left,
32
- "--viewport-offset-right": computedOffset.right,
33
- "--viewport-offset-top": computedOffset.top,
34
- "--viewport-offset-bottom": computedOffset.bottom,
35
- zIndex: MAX_Z_INDEX
36
- };
37
- let alignItems = "center";
38
- if (isRighty) alignItems = "flex-end";
39
- if (isLefty) alignItems = "flex-start";
40
- styles.alignItems = alignItems;
41
- if (computedPlacement.includes("top")) {
42
- const offset = computedOffset.top;
43
- styles.top = `max(env(safe-area-inset-top, 0px), ${offset})`;
44
- }
45
- if (computedPlacement.includes("bottom")) {
46
- const offset = computedOffset.bottom;
47
- styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${offset})`;
48
- }
49
- if (!computedPlacement.includes("left")) {
50
- const offset = computedOffset.right;
51
- styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${offset})`;
52
- }
53
- if (!computedPlacement.includes("right")) {
54
- const offset = computedOffset.left;
55
- styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${offset})`;
56
- }
57
- return styles;
21
+ const { prop, computed, context } = service;
22
+ const { offsets, gap } = prop("store").attrs;
23
+ const heights = context.get("heights");
24
+ const computedOffset = getOffsets(offsets);
25
+ const rtl = prop("dir") === "rtl";
26
+ const computedPlacement = placement.replace("-start", rtl ? "-right" : "-left").replace("-end", rtl ? "-left" : "-right");
27
+ const isRighty = computedPlacement.includes("right");
28
+ const isLefty = computedPlacement.includes("left");
29
+ const styles = {
30
+ position: "fixed",
31
+ pointerEvents: computed("count") > 0 ? void 0 : "none",
32
+ display: "flex",
33
+ flexDirection: "column",
34
+ "--gap": `${gap}px`,
35
+ "--first-height": `${heights[0]?.height || 0}px`,
36
+ "--viewport-offset-left": computedOffset.left,
37
+ "--viewport-offset-right": computedOffset.right,
38
+ "--viewport-offset-top": computedOffset.top,
39
+ "--viewport-offset-bottom": computedOffset.bottom,
40
+ zIndex: MAX_Z_INDEX
41
+ };
42
+ let alignItems = "center";
43
+ if (isRighty) alignItems = "flex-end";
44
+ if (isLefty) alignItems = "flex-start";
45
+ styles.alignItems = alignItems;
46
+ if (computedPlacement.includes("top")) styles.top = `max(env(safe-area-inset-top, 0px), ${computedOffset.top})`;
47
+ if (computedPlacement.includes("bottom")) styles.bottom = `max(env(safe-area-inset-bottom, 0px), ${computedOffset.bottom})`;
48
+ if (!computedPlacement.includes("left")) styles.insetInlineEnd = `calc(env(safe-area-inset-right, 0px) + ${computedOffset.right})`;
49
+ if (!computedPlacement.includes("right")) styles.insetInlineStart = `calc(env(safe-area-inset-left, 0px) + ${computedOffset.left})`;
50
+ return styles;
58
51
  }
59
52
  function getPlacementStyle(service, visible) {
60
- const { prop, context, computed } = service;
61
- const parent = prop("parent");
62
- const placement = parent.computed("placement");
63
- const { gap } = parent.prop("store").attrs;
64
- const [side] = placement.split("-");
65
- const mounted = context.get("mounted");
66
- const remainingTime = context.get("remainingTime");
67
- const height = computed("height");
68
- const frontmost = computed("frontmost");
69
- const sibling = !frontmost;
70
- const overlap = !prop("stacked");
71
- const stacked = prop("stacked");
72
- const type = prop("type");
73
- const duration = type === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
74
- const offset = computed("heightIndex") * gap + computed("heightBefore");
75
- const styles = {
76
- position: "absolute",
77
- pointerEvents: "auto",
78
- "--opacity": "0",
79
- "--remove-delay": `${prop("removeDelay")}ms`,
80
- "--duration": `${duration}ms`,
81
- "--initial-height": `${height}px`,
82
- "--offset": `${offset}px`,
83
- "--index": prop("index"),
84
- "--z-index": computed("zIndex"),
85
- "--lift-amount": "calc(var(--lift) * var(--gap))",
86
- "--y": "100%",
87
- "--x": "0"
88
- };
89
- const assign = (overrides) => Object.assign(styles, overrides);
90
- if (side === "top") {
91
- assign({
92
- top: "0",
93
- "--sign": "-1",
94
- "--y": "-100%",
95
- "--lift": "1"
96
- });
97
- } else if (side === "bottom") {
98
- assign({
99
- bottom: "0",
100
- "--sign": "1",
101
- "--y": "100%",
102
- "--lift": "-1"
103
- });
104
- }
105
- if (mounted) {
106
- assign({
107
- "--y": "0",
108
- "--opacity": "1"
109
- });
110
- if (stacked) {
111
- assign({
112
- "--y": "calc(var(--lift) * var(--offset))",
113
- "--height": "var(--initial-height)"
114
- });
115
- }
116
- }
117
- if (!visible) {
118
- assign({
119
- "--opacity": "0",
120
- pointerEvents: "none"
121
- });
122
- }
123
- if (sibling && overlap) {
124
- assign({
125
- "--base-scale": "var(--index) * 0.05 + 1",
126
- "--y": "calc(var(--lift-amount) * var(--index))",
127
- "--scale": "calc(-1 * var(--base-scale))",
128
- "--height": "var(--first-height)"
129
- });
130
- if (!visible) {
131
- assign({
132
- "--y": "calc(var(--sign) * 40%)"
133
- });
134
- }
135
- }
136
- if (sibling && stacked && !visible) {
137
- assign({
138
- "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)"
139
- });
140
- }
141
- if (frontmost && !visible) {
142
- assign({
143
- "--y": "calc(var(--lift) * -100%)"
144
- });
145
- }
146
- return styles;
53
+ const { prop, context, computed } = service;
54
+ const parent = prop("parent");
55
+ const placement = parent.computed("placement");
56
+ const { gap } = parent.prop("store").attrs;
57
+ const [side] = placement.split("-");
58
+ const mounted = context.get("mounted");
59
+ const remainingTime = context.get("remainingTime");
60
+ const height = computed("height");
61
+ const frontmost = computed("frontmost");
62
+ const sibling = !frontmost;
63
+ const stacked = prop("parent").state.matches("stack");
64
+ const overlap = !stacked;
65
+ const duration = prop("type") === "loading" ? Number.MAX_SAFE_INTEGER : remainingTime;
66
+ const offset = computed("heightIndex") * gap + computed("heightBefore");
67
+ const styles = {
68
+ position: "absolute",
69
+ pointerEvents: "auto",
70
+ "--opacity": "0",
71
+ "--remove-delay": `${prop("removeDelay")}ms`,
72
+ "--duration": `${duration}ms`,
73
+ "--initial-height": `${height}px`,
74
+ "--offset": `${offset}px`,
75
+ "--index": prop("index"),
76
+ "--z-index": computed("zIndex"),
77
+ "--lift-amount": "calc(var(--lift) * var(--gap))",
78
+ "--y": "100%",
79
+ "--x": "0"
80
+ };
81
+ const assign = (overrides) => Object.assign(styles, overrides);
82
+ if (side === "top") assign({
83
+ top: "0",
84
+ "--sign": "-1",
85
+ "--y": "-100%",
86
+ "--lift": "1"
87
+ });
88
+ else if (side === "bottom") assign({
89
+ bottom: "0",
90
+ "--sign": "1",
91
+ "--y": "100%",
92
+ "--lift": "-1"
93
+ });
94
+ if (mounted) {
95
+ assign({
96
+ "--y": "0",
97
+ "--opacity": "1"
98
+ });
99
+ if (stacked) assign({
100
+ "--y": "calc(var(--lift) * var(--offset))",
101
+ "--height": "var(--initial-height)"
102
+ });
103
+ }
104
+ if (!visible) assign({
105
+ "--opacity": "0",
106
+ pointerEvents: "none"
107
+ });
108
+ if (sibling && overlap) {
109
+ assign({
110
+ "--base-scale": "var(--index) * 0.05 + 1",
111
+ "--y": "calc(var(--lift-amount) * var(--index))",
112
+ "--scale": "calc(-1 * var(--base-scale))",
113
+ "--height": "var(--first-height)"
114
+ });
115
+ if (!visible) assign({ "--y": "calc(var(--sign) * 40%)" });
116
+ }
117
+ if (sibling && stacked && !visible) assign({ "--y": "calc(var(--lift) * var(--offset) + var(--lift) * -100%)" });
118
+ if (frontmost && !visible) assign({ "--y": "calc(var(--lift) * -100%)" });
119
+ return styles;
147
120
  }
148
121
  function getGhostBeforeStyle(service, visible) {
149
- const { computed } = service;
150
- const styles = {
151
- position: "absolute",
152
- inset: "0",
153
- scale: "1 2",
154
- pointerEvents: visible ? "none" : "auto"
155
- };
156
- const assign = (overrides) => Object.assign(styles, overrides);
157
- if (computed("frontmost") && !visible) {
158
- assign({
159
- height: "calc(var(--initial-height) + 80%)"
160
- });
161
- }
162
- return styles;
122
+ const { computed } = service;
123
+ const styles = {
124
+ position: "absolute",
125
+ inset: "0",
126
+ scale: "1 2",
127
+ pointerEvents: visible ? "none" : "auto"
128
+ };
129
+ const assign = (overrides) => Object.assign(styles, overrides);
130
+ if (computed("frontmost") && !visible) assign({ height: "calc(var(--initial-height) + 80%)" });
131
+ return styles;
163
132
  }
164
133
  function getGhostAfterStyle() {
165
- return {
166
- position: "absolute",
167
- left: "0",
168
- height: "calc(var(--gap) + 2px)",
169
- bottom: "100%",
170
- width: "100%"
171
- };
134
+ return {
135
+ position: "absolute",
136
+ left: "0",
137
+ height: "calc(var(--gap) + 2px)",
138
+ bottom: "100%",
139
+ width: "100%"
140
+ };
172
141
  }
173
- export {
174
- defaultTimeouts,
175
- getGhostAfterStyle,
176
- getGhostBeforeStyle,
177
- getGroupPlacementStyle,
178
- getPlacementStyle,
179
- getToastDuration
180
- };
142
+ function setHeight(parent, item) {
143
+ const { id, height } = item;
144
+ parent.context.set("heights", (prev) => {
145
+ const existing = prev.find((i) => i.id === id);
146
+ if (existing) {
147
+ if (existing.height === height) return prev;
148
+ return prev.map((i) => i.id === id ? {
149
+ ...i,
150
+ height
151
+ } : i);
152
+ }
153
+ const toasts = parent.context.get("toasts");
154
+ const rank = (id) => toasts.findIndex((t) => t.id === id);
155
+ const index = rank(id);
156
+ let insertAt = prev.findIndex((i) => {
157
+ const r = rank(i.id);
158
+ return r === -1 || r > index;
159
+ });
160
+ if (insertAt === -1) insertAt = prev.length;
161
+ return [
162
+ ...prev.slice(0, insertAt),
163
+ {
164
+ id,
165
+ height
166
+ },
167
+ ...prev.slice(insertAt)
168
+ ];
169
+ });
170
+ }
171
+ export { defaultTimeouts, getGhostAfterStyle, getGhostBeforeStyle, getGroupPlacementStyle, getPlacementStyle, getToastDuration, setHeight };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/toast",
3
- "version": "1.46.0",
3
+ "version": "1.48.0",
4
4
  "description": "Core logic for the toast widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,12 +29,12 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/anatomy": "1.46.0",
33
- "@zag-js/core": "1.46.0",
34
- "@zag-js/dom-query": "1.46.0",
35
- "@zag-js/dismissable": "1.46.0",
36
- "@zag-js/utils": "1.46.0",
37
- "@zag-js/types": "1.46.0"
32
+ "@zag-js/anatomy": "1.48.0",
33
+ "@zag-js/core": "1.48.0",
34
+ "@zag-js/dom-query": "1.48.0",
35
+ "@zag-js/dismissable": "1.48.0",
36
+ "@zag-js/utils": "1.48.0",
37
+ "@zag-js/types": "1.48.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "clean-package": "2.2.0"
@@ -67,8 +67,8 @@
67
67
  "./package.json": "./package.json"
68
68
  },
69
69
  "scripts": {
70
- "build": "tsup",
71
- "lint": "eslint src",
70
+ "build": "tsdown",
71
+ "lint": "oxlint src",
72
72
  "typecheck": "tsc --noEmit"
73
73
  }
74
74
  }