hys-ui 0.5.0 → 0.6.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 (66) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/components/HysDrawer/HysDrawer.vue.js +1 -1
  3. package/dist/components/HysDrawer/HysDrawer2.vue.js +2 -2
  4. package/dist/components/HysModal/HysModal.vue.js +2 -2
  5. package/dist/components/HysModal/HysModal2.vue.js +38 -38
  6. package/dist/components/HysSearch/HysSearch.vue.js +2 -2
  7. package/dist/components/HysSortableList/HysSortableList.vue.js +2 -2
  8. package/dist/components/HysSortableList/HysSortableList2.vue.js +498 -129
  9. package/dist/components/HysSortableList/SortableGhost/SortableGhost.vue.js +7 -0
  10. package/dist/components/HysSortableList/SortableGhost/SortableGhost2.vue.js +43 -0
  11. package/dist/components/HysSortableList/SortableGhost/useSortGhost.js +54 -0
  12. package/dist/components/HysSortableList/geometry.js +230 -0
  13. package/dist/components/HysSortableList/model.js +254 -0
  14. package/dist/components/HysSortableList/transactions.js +281 -0
  15. package/dist/components/HysSortableList/useSortDrag.js +270 -0
  16. package/dist/components/HysSortableList/useSortKeyboard.js +72 -0
  17. package/dist/components/HysSortableList/useSortWindow.js +144 -0
  18. package/dist/components/HysToast/HysToast.vue.js +3 -3
  19. package/dist/components/HysToast/HysToast2.vue.js +379 -107
  20. package/dist/components/HysToast/ToastViewport/ToastViewport.vue.js +7 -0
  21. package/dist/components/HysToast/ToastViewport/ToastViewport2.vue.js +211 -0
  22. package/dist/components/HysToast/ToastViewport/useToastStackDisclosure.js +71 -0
  23. package/dist/components/HysToast/toastPresentation.js +98 -0
  24. package/dist/components/HysToast/useToastActions.js +62 -0
  25. package/dist/components/HysToast/useToastSwipe.js +48 -0
  26. package/dist/components/HysToast/useToastTimer.js +90 -0
  27. package/dist/composables/popupReferenceBinding.js +41 -0
  28. package/dist/composables/toastEscape.js +18 -10
  29. package/dist/composables/toastQueue.js +276 -0
  30. package/dist/composables/toastQueueModel.js +86 -0
  31. package/dist/composables/toastTasks.js +58 -0
  32. package/dist/composables/useHysToast.js +117 -135
  33. package/dist/composables/usePopupSurface.js +190 -356
  34. package/dist/composables/usePopupSurfaceInteractions.js +172 -0
  35. package/dist/index.js +59 -57
  36. package/dist/style.css +1 -1
  37. package/dist/types/components/HysGantt/HysGantt.vue.d.ts +1 -1
  38. package/dist/types/components/HysModal/HysModal.vue.d.ts +1 -1
  39. package/dist/types/components/HysSortableList/HysSortableList.vue.d.ts +48 -25
  40. package/dist/types/components/HysSortableList/SortableGhost/SortableGhost.vue.d.ts +31 -0
  41. package/dist/types/components/HysSortableList/SortableGhost/useSortGhost.d.ts +23 -0
  42. package/dist/types/components/HysSortableList/geometry.d.ts +35 -0
  43. package/dist/types/components/HysSortableList/model.d.ts +61 -0
  44. package/dist/types/components/HysSortableList/sortableList.d.ts +151 -0
  45. package/dist/types/components/HysSortableList/transactions.d.ts +10 -0
  46. package/dist/types/components/HysSortableList/useSortDrag.d.ts +25 -0
  47. package/dist/types/components/HysSortableList/useSortKeyboard.d.ts +17 -0
  48. package/dist/types/components/HysSortableList/useSortWindow.d.ts +16 -0
  49. package/dist/types/components/HysToast/HysToast.vue.d.ts +44 -46
  50. package/dist/types/components/HysToast/ToastViewport/ToastViewport.vue.d.ts +25 -0
  51. package/dist/types/components/HysToast/ToastViewport/useToastStackDisclosure.d.ts +16 -0
  52. package/dist/types/components/HysToast/toastPresentation.d.ts +8 -0
  53. package/dist/types/components/HysToast/toastTypes.d.ts +212 -0
  54. package/dist/types/components/HysToast/useToastActions.d.ts +18 -0
  55. package/dist/types/components/HysToast/useToastSwipe.d.ts +11 -0
  56. package/dist/types/components/HysToast/useToastTimer.d.ts +22 -0
  57. package/dist/types/composables/popupReferenceBinding.d.ts +9 -0
  58. package/dist/types/composables/toastEscape.d.ts +1 -1
  59. package/dist/types/composables/toastQueue.d.ts +121 -0
  60. package/dist/types/composables/toastQueueModel.d.ts +116 -0
  61. package/dist/types/composables/toastTasks.d.ts +2 -0
  62. package/dist/types/composables/useHysToast.d.ts +4 -48
  63. package/dist/types/composables/usePopupSurface.d.ts +20 -20
  64. package/dist/types/composables/usePopupSurfaceInteractions.d.ts +33 -0
  65. package/dist/types/index.d.ts +3 -4
  66. package/package.json +1 -1
@@ -0,0 +1,276 @@
1
+ import { shallowRef as oe, shallowReactive as H, nextTick as J } from "vue";
2
+ import { finite as f, toastDuration as L, normalizeToastPosition as N } from "../components/HysToast/toastPresentation.js";
3
+ import { context as U, matches as V, snapshot as D, defaults as se, toastStackKey as X, asOptions as W, nextToastSequence as ie } from "./toastQueueModel.js";
4
+ import { createToastTaskRunner as ne } from "./toastTasks.js";
5
+ function de(Y, j, B) {
6
+ const l = oe({ ...Y }), a = H(/* @__PURE__ */ new Map()), c = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map(), q = /* @__PURE__ */ new Set();
7
+ let p = !0, K = !1, v = 0, Q = !1, A = !1;
8
+ function m(e, ...t) {
9
+ try {
10
+ e == null || e(...t);
11
+ } catch (o) {
12
+ B(o);
13
+ }
14
+ }
15
+ function k(e, t) {
16
+ e.status = t, m(e.options.onStateChange, D(e));
17
+ }
18
+ function P() {
19
+ return Math.max(1, Math.floor(f(l.value.maxCount, 5)));
20
+ }
21
+ function C(e) {
22
+ switch (l.value.queueScope) {
23
+ case "position":
24
+ return N(e.options.position);
25
+ case "type":
26
+ return e.options.type ?? "info";
27
+ case "group":
28
+ return e.options.group ?? "";
29
+ default:
30
+ return "";
31
+ }
32
+ }
33
+ function M(e, t) {
34
+ return f(t.options.priority, 0) - f(e.options.priority, 0) || (l.value.queueOrder === "lifo" ? t.serial - e.serial : e.serial - t.serial);
35
+ }
36
+ function g() {
37
+ if (!(!p || v)) {
38
+ if (Q) {
39
+ A = !0;
40
+ return;
41
+ }
42
+ Q = !0;
43
+ try {
44
+ A = !1;
45
+ const e = /* @__PURE__ */ new Map(), t = [], o = l.value.overflow === "queue";
46
+ for (const s of a.values())
47
+ if (s.status === "queued") t.push(s);
48
+ else if (s.status === "visible" || s.status === "closing" && o) {
49
+ const i = C(s);
50
+ e.set(i, (e.get(i) ?? 0) + 1);
51
+ }
52
+ for (const s of t.sort(M)) {
53
+ if (!p || s.status !== "queued") continue;
54
+ const i = C(s), u = e.get(i) ?? 0;
55
+ u >= P() || (e.set(i, u + 1), k(s, "visible"));
56
+ }
57
+ } finally {
58
+ Q = !1;
59
+ }
60
+ A && g();
61
+ }
62
+ }
63
+ function R(e, t) {
64
+ e.status === "closing" || e.status === "closed" || (e.closeContext = t, k(e, "closing"), m(e.options.onClose, t));
65
+ }
66
+ function S(e) {
67
+ if (e.status === "closed") return;
68
+ const t = e.closeContext;
69
+ a.get(e.id) === e && a.delete(e.id), c.delete(e.serial), x.delete(e.serial), q.delete(e), k(e, "closed"), e.resolve(), t && m(e.options.onAfterClose, t), g(), a.size || j.empty();
70
+ }
71
+ async function w(e, t = "api", o = !1) {
72
+ if (e.status === "closing" || e.status === "closed" || !o && q.has(e))
73
+ return;
74
+ const s = c.get(e.serial);
75
+ if (s) {
76
+ await s.close(t, void 0, o);
77
+ return;
78
+ }
79
+ const i = { ...U(e), reason: t };
80
+ if (!o && e.options.beforeClose) {
81
+ q.add(e);
82
+ try {
83
+ if (await e.options.beforeClose(i) === !1) return;
84
+ } catch {
85
+ return;
86
+ } finally {
87
+ q.delete(e);
88
+ }
89
+ if (e.status === "closed" || e.status === "closing")
90
+ return;
91
+ const u = c.get(e.serial);
92
+ if (u) {
93
+ await u.close(t, void 0, !0);
94
+ return;
95
+ }
96
+ }
97
+ R(e, i), S(e);
98
+ }
99
+ function T(e, t) {
100
+ var u;
101
+ if (!p || e.status === "closing" || e.status === "closed")
102
+ return;
103
+ const o = e.options, s = W(t), i = { ...o, ...s, id: e.id };
104
+ s.type && s.type !== o.type && !("duration" in s) && (i.duration = s.type === "loading" ? 0 : l.value.duration), i.message !== o.message || L(i) !== L(o) ? e.clock = void 0 : X(i) !== X(o) && (e.clock ?? (e.clock = (u = c.get(e.serial)) == null ? void 0 : u.snapshotClock())), e.options = i, (i.type !== o.type || i.group !== o.group || i.position !== o.position || i.priority !== o.priority) && (m(e.options.onStateChange, D(e)), g());
105
+ }
106
+ function Z(e) {
107
+ if (!(e.dedupe ?? (e.grouping ? "merge" : void 0)) || !e.dedupeKey && (!e.message || e.content !== void 0))
108
+ return;
109
+ const o = Date.now(), s = Math.max(0, f(e.dedupeWindow, 1 / 0));
110
+ return [...a.values()].find(
111
+ (i) => i.status !== "closing" && i.status !== "closed" && o - i.lastSeen <= s && i.options.group === e.group && (e.dedupeKey ? i.options.dedupeKey === e.dedupeKey : i.options.message === e.message && i.options.type === e.type && N(i.options.position) === N(e.position))
112
+ );
113
+ }
114
+ function b(e) {
115
+ var E;
116
+ const t = W(e), o = {
117
+ type: "info",
118
+ ...se(l.value),
119
+ ...t
120
+ };
121
+ o.type === "loading" && t.duration === void 0 && (o.duration = 0);
122
+ const s = t.id === void 0 ? void 0 : a.get(t.id);
123
+ if (s && s.status !== "closing" && s.status !== "closed")
124
+ return s.lastSeen = Date.now(), T(s, t), s.clock = void 0, J(() => {
125
+ var n;
126
+ return (n = c.get(s.serial)) == null ? void 0 : n.restart();
127
+ }), s.handle;
128
+ const i = Z(o);
129
+ if (i)
130
+ return i.lastSeen = Date.now(), o.dedupe !== "ignore" && (i.repeat++, T(i, t), (E = c.get(i.serial)) == null || E.restart()), i.handle;
131
+ const u = ie(), F = t.id ?? "hys-toast-" + u;
132
+ let O;
133
+ const y = new Promise((n) => {
134
+ O = n;
135
+ }), I = {
136
+ id: F,
137
+ closed: y,
138
+ close: () => {
139
+ w(d);
140
+ },
141
+ update: (n) => T(d, n),
142
+ extend: (n) => {
143
+ if (!Number.isFinite(n) || n <= 0 || !L(d.options))
144
+ return;
145
+ const r = c.get(u);
146
+ r ? r.extend(n) : d.extending += n;
147
+ },
148
+ pause: () => {
149
+ d.paused = !0;
150
+ },
151
+ resume: () => {
152
+ d.paused = !1;
153
+ }
154
+ }, d = H({
155
+ id: F,
156
+ serial: u,
157
+ options: o,
158
+ status: "queued",
159
+ repeat: 1,
160
+ paused: !1,
161
+ lastSeen: Date.now(),
162
+ extending: 0,
163
+ handle: I,
164
+ resolve: O
165
+ });
166
+ if (K || !p || typeof document > "u" || !o.message && !o.title && o.content == null && o.header == null)
167
+ return O(), I;
168
+ j.mount(), v++;
169
+ try {
170
+ (s == null ? void 0 : s.status) === "closing" && S(s), a.set(F, d);
171
+ const n = [...a.values()].filter(
172
+ (r) => r.status === "visible" && C(r) === C(d)
173
+ );
174
+ if (l.value.overflow !== "queue" && n.length >= P()) {
175
+ n.sort(
176
+ (r, G) => f(r.options.priority, 0) - f(G.options.priority, 0) || r.serial - G.serial
177
+ );
178
+ for (const r of n.slice(
179
+ 0,
180
+ n.length - P() + 1
181
+ ))
182
+ w(r, "overflow", !0);
183
+ }
184
+ k(d, "queued");
185
+ } finally {
186
+ v--;
187
+ }
188
+ g();
189
+ const ee = [...a.values()].filter((n) => n.status === "queued").sort(M), te = Math.max(
190
+ 0,
191
+ Math.floor(f(l.value.maxQueue, 1e3))
192
+ );
193
+ for (const n of ee.slice(te))
194
+ w(n, "overflow", !0);
195
+ return I;
196
+ }
197
+ function _(e, t, o) {
198
+ if (!t) {
199
+ x.get(e.serial) === o && (x.delete(e.serial), c.delete(e.serial));
200
+ return;
201
+ }
202
+ if (c.set(e.serial, t), x.set(e.serial, o), e.clock) {
203
+ const s = e.clock;
204
+ J(() => {
205
+ c.get(e.serial) !== t || e.clock !== s || (e.clock = void 0, t.restoreClock(s));
206
+ });
207
+ }
208
+ e.extending && (t.extend(e.extending), e.extending = 0);
209
+ }
210
+ async function z(e, t = !1) {
211
+ v++;
212
+ try {
213
+ await Promise.all(
214
+ [...a.values()].filter((o) => V(o, e)).map((o) => w(o, "api", t))
215
+ );
216
+ } finally {
217
+ v--, g();
218
+ }
219
+ }
220
+ function $(e = !1) {
221
+ p = !1, K || (K = e);
222
+ for (const t of [...a.values()])
223
+ R(t, { ...U(t), reason: "dispose" }), S(t);
224
+ }
225
+ const h = (e) => (t) => b({ ...W(t), type: e });
226
+ return {
227
+ api: {
228
+ show: b,
229
+ promise: ne(b, B),
230
+ success: h("success"),
231
+ info: h("info"),
232
+ warning: h("warning"),
233
+ error: h("error"),
234
+ loading: h("loading"),
235
+ close: (e) => {
236
+ const t = a.get(e);
237
+ t && w(t);
238
+ },
239
+ update: (e, t) => {
240
+ const o = a.get(e);
241
+ o && T(o, t);
242
+ },
243
+ find: (e) => {
244
+ const t = a.get(e);
245
+ return t && D(t);
246
+ },
247
+ list: (e) => [...a.values()].filter((t) => V(t, e)).sort(M).map(D),
248
+ closeAll: (e) => {
249
+ z(e);
250
+ },
251
+ closeType: (e) => {
252
+ z({ type: e });
253
+ },
254
+ clearQueue: () => {
255
+ z({ status: "queued" }, !0);
256
+ },
257
+ configure: (e) => {
258
+ l.value = { ...l.value, ...e }, g();
259
+ }
260
+ },
261
+ records: a,
262
+ settings: l,
263
+ order: M,
264
+ notify: m,
265
+ begin: R,
266
+ finish: S,
267
+ setInstance: _,
268
+ suspend: $,
269
+ resume: () => {
270
+ K || (p = !0);
271
+ }
272
+ };
273
+ }
274
+ export {
275
+ de as createToastQueue
276
+ };
@@ -0,0 +1,86 @@
1
+ import { normalizeToastPosition as e, finite as C } from "../components/HysToast/toastPresentation.js";
2
+ let S = 0;
3
+ const O = () => ++S, k = (o) => typeof o == "string" ? { message: o } : o;
4
+ function z(o) {
5
+ const {
6
+ id: t,
7
+ content: s,
8
+ icon: i,
9
+ header: p,
10
+ footer: u,
11
+ renderActions: a,
12
+ priority: r,
13
+ group: d,
14
+ grouping: c,
15
+ dedupe: f,
16
+ dedupeKey: g,
17
+ dedupeWindow: n,
18
+ onShow: x,
19
+ onAfterShow: l,
20
+ onClose: q,
21
+ onAfterClose: w,
22
+ onClick: A,
23
+ onAction: T,
24
+ onStateChange: v,
25
+ ...m
26
+ } = o;
27
+ return m;
28
+ }
29
+ function K(o) {
30
+ return JSON.stringify([
31
+ e(o.position),
32
+ o.offsetX ?? o.offset ?? 24,
33
+ o.offsetY ?? o.offset ?? 24,
34
+ o.zIndex ?? 2e3,
35
+ o.coordinates
36
+ ]);
37
+ }
38
+ function I(o) {
39
+ const {
40
+ maxCount: t,
41
+ maxQueue: s,
42
+ overflow: i,
43
+ queueOrder: p,
44
+ queueScope: u,
45
+ layout: a,
46
+ gap: r,
47
+ collapsedCount: d,
48
+ layerCount: c,
49
+ layerTrigger: f,
50
+ appendTo: g,
51
+ ...n
52
+ } = o;
53
+ return n;
54
+ }
55
+ function h(o) {
56
+ return {
57
+ id: o.id,
58
+ message: o.options.message ?? "",
59
+ title: o.options.title,
60
+ type: o.options.type ?? "info"
61
+ };
62
+ }
63
+ function J(o) {
64
+ return {
65
+ ...h(o),
66
+ id: o.id,
67
+ status: o.status,
68
+ position: e(o.options.position),
69
+ group: o.options.group,
70
+ priority: C(o.options.priority, 0),
71
+ repeat: o.repeat
72
+ };
73
+ }
74
+ function N(o, t = {}) {
75
+ return (t.type === void 0 || t.type === o.options.type) && (t.group === void 0 || t.group === o.options.group) && (t.status === void 0 || t.status === o.status) && (t.position === void 0 || e(t.position) === e(o.options.position));
76
+ }
77
+ export {
78
+ k as asOptions,
79
+ h as context,
80
+ I as defaults,
81
+ N as matches,
82
+ O as nextToastSequence,
83
+ z as presentation,
84
+ J as snapshot,
85
+ K as toastStackKey
86
+ };
@@ -0,0 +1,58 @@
1
+ import { feedback as l } from "../components/HysToast/useToastActions.js";
2
+ import { asOptions as k } from "./toastQueueModel.js";
3
+ function v(d, u) {
4
+ const t = /* @__PURE__ */ new WeakMap();
5
+ function c(a, r = {}) {
6
+ var p;
7
+ const s = d({
8
+ actions: void 0,
9
+ progress: void 0,
10
+ ...r.options,
11
+ id: r.id ?? ((p = r.options) == null ? void 0 : p.id),
12
+ type: "loading",
13
+ message: "正在处理…",
14
+ duration: 0,
15
+ ...k(r.loading ?? {})
16
+ }), o = Symbol();
17
+ t.set(s, o);
18
+ const n = (e) => {
19
+ t.get(s) === o && s.update(e);
20
+ };
21
+ function i(e, f) {
22
+ try {
23
+ return l(e, f);
24
+ } catch (g) {
25
+ u(g);
26
+ }
27
+ }
28
+ const m = Promise.resolve().then(
29
+ () => typeof a == "function" ? a({
30
+ handle: s,
31
+ update: n,
32
+ progress: (e) => n({ progress: e })
33
+ }) : a
34
+ ).then(
35
+ (e) => (t.get(s) === o && (n({
36
+ type: "success",
37
+ message: "操作成功",
38
+ progress: void 0,
39
+ persistent: !1,
40
+ ...i(r.success, e)
41
+ }), t.delete(s)), e),
42
+ (e) => {
43
+ throw t.get(s) === o && (n({
44
+ type: "error",
45
+ message: "操作失败",
46
+ progress: void 0,
47
+ persistent: !1,
48
+ ...i(r.error, e)
49
+ }), t.delete(s)), e;
50
+ }
51
+ );
52
+ return { handle: s, promise: m };
53
+ }
54
+ return c;
55
+ }
56
+ export {
57
+ v as createToastTaskRunner
58
+ };
@@ -1,148 +1,130 @@
1
- import { defineComponent as k, createApp as F, h as m, getCurrentInstance as Q, shallowReactive as A, Fragment as R, onDeactivated as B, onActivated as N, onScopeDispose as P, nextTick as W, render as b } from "vue";
2
- import X from "../components/HysToast/HysToast.vue.js";
3
- import { provideHysConfig as z, useHysRootAttrs as G } from "../config.js";
4
- let J = 0;
5
- const g = (n = "top-center") => n === "top" ? "top-center" : n === "bottom" ? "bottom-center" : n;
6
- function K(n = {}) {
7
- const l = Q();
8
- if (!l) throw new Error("useHysToast must be called during component setup");
9
- const p = G(), a = A([]), d = /* @__PURE__ */ new Map();
10
- let r, x = !0, v = !1;
11
- const M = Number.isFinite(n.maxCount) ? Math.max(1, Math.floor(n.maxCount)) : 5, w = (e) => typeof e == "string" ? { message: e } : e;
12
- function C(e) {
1
+ import { defineComponent as T, createApp as C, h as H, getCurrentInstance as x, onDeactivated as E, onActivated as I, onScopeDispose as k, shallowRef as g, toValue as l, nextTick as q, render as h } from "vue";
2
+ import { provideHysConfig as Q, useHysRootAttrs as D } from "../config.js";
3
+ import R from "../components/HysToast/ToastViewport/ToastViewport.vue.js";
4
+ import { createToastQueue as A } from "./toastQueue.js";
5
+ function V(t = {}) {
6
+ const s = x();
7
+ if (!s)
8
+ throw new Error("useHysToast must be called during component setup");
9
+ const m = D();
10
+ let o;
11
+ const p = (n) => {
13
12
  try {
14
- e == null || e();
15
- } catch (o) {
16
- try {
17
- l.appContext.config.errorHandler ? l.appContext.config.errorHandler(o, l.proxy, "HysToast callback") : console.error(o);
18
- } catch (s) {
19
- console.error(s);
20
- }
13
+ s.appContext.config.errorHandler ? s.appContext.config.errorHandler(
14
+ n,
15
+ s.proxy,
16
+ "HysToast callback"
17
+ ) : console.error(n);
18
+ } catch (i) {
19
+ console.error(i);
21
20
  }
21
+ };
22
+ function a() {
23
+ o && (h(null, o), o.remove(), o = void 0);
22
24
  }
23
- function H(e) {
24
- if (e.finished) return;
25
- e.finished = !0;
26
- const o = a.indexOf(e);
27
- o >= 0 && a.splice(o, 1), d.delete(e.token), e.resolve(), C(e.onAfterClose);
28
- const s = r;
29
- W(() => {
30
- s && s === r && !a.length && (b(null, s), s.remove(), r = void 0);
31
- });
32
- }
33
- function h(e) {
34
- if (!(e.closing || e.finished)) {
35
- e.closing = !0;
36
- try {
37
- C(e.onClose);
38
- } finally {
39
- const o = d.get(e.token);
40
- o ? o.close() : H(e);
41
- }
25
+ function c() {
26
+ const n = r.settings.value.appendTo, i = typeof n == "string" ? document.querySelector(n) : n ?? document.body;
27
+ if (!i) throw new Error("Toast appendTo target was not found");
28
+ if (o) {
29
+ o.parentNode !== i && i.appendChild(o);
30
+ return;
42
31
  }
32
+ o = document.createElement("div"), o.dataset.hysToastHost = "", i.appendChild(o);
33
+ const y = H(R, { queue: r, skin: () => m.value });
34
+ y.appContext = s.appContext, h(y, o);
43
35
  }
44
- function I(e, o) {
45
- if (e.closing || e.finished || v) return;
46
- const s = w(o), t = e.type;
47
- Object.assign(e, s, { id: e.id }), s.type && s.type !== t && s.duration === void 0 && (e.duration = s.type === "loading" ? 0 : n.duration), W(() => {
48
- var f;
49
- e.closing || (f = d.get(e.token)) == null || f.restart();
50
- });
36
+ const r = A(
37
+ t,
38
+ {
39
+ mount: c,
40
+ empty: () => {
41
+ q(() => {
42
+ r.records.size || a();
43
+ });
44
+ }
45
+ },
46
+ p
47
+ );
48
+ function f(n = !1) {
49
+ r.suspend(n), a();
51
50
  }
52
- function j(e) {
53
- const o = g(e.position), s = Math.max(0, e.offset ?? 24) + "px", t = { position: "fixed", width: "max-content", display: "flex", flexDirection: o.startsWith("bottom") ? "column-reverse" : "column", gap: "10px", alignItems: o.endsWith("left") ? "flex-start" : o.endsWith("right") ? "flex-end" : "center", maxWidth: `calc(100vw - ${Math.max(16, e.offset ?? 24) * 2}px)`, pointerEvents: "none", zIndex: e.zIndex ?? 2e3 };
54
- return o === "center" ? Object.assign(t, { left: "50%", top: "50%", transform: "translate(-50%,-50%)" }) : (o.startsWith("bottom") ? t.bottom = `max(${s},env(safe-area-inset-bottom))` : t.top = `max(${s},env(safe-area-inset-top))`, o.endsWith("left") ? t.left = `max(${s},env(safe-area-inset-left))` : o.endsWith("right") ? t.right = `max(${s},env(safe-area-inset-right))` : Object.assign(t, { left: "50%", transform: "translateX(-50%)" })), t;
51
+ return E(() => f()), I(r.resume), k(() => f(!0)), {
52
+ ...r.api,
53
+ configure(n) {
54
+ r.api.configure(n), o && "appendTo" in n && c();
55
+ }
56
+ };
57
+ }
58
+ function w(t = {}) {
59
+ const { theme: s, motion: m, buttonAutoInsertSpace: o, ...p } = t;
60
+ if (typeof document > "u") {
61
+ const n = A(
62
+ p,
63
+ { mount() {
64
+ }, empty() {
65
+ } },
66
+ () => {
67
+ }
68
+ );
69
+ return { ...n.api, dispose: () => n.suspend(!0) };
55
70
  }
56
- const q = k({
57
- name: "HysToastQueue",
71
+ let a, c = !1;
72
+ const r = T({
58
73
  setup() {
59
- return z({ theme: () => p.value["data-hys-theme"], motion: () => p.value["data-hys-motion"] }), () => {
60
- const e = /* @__PURE__ */ new Map();
61
- for (const o of a) {
62
- const s = `${g(o.position)}:${o.offset ?? 24}:${o.zIndex ?? 2e3}`, t = e.get(s) || [];
63
- t.push(o), e.set(s, t);
64
- }
65
- return m(R, [...e].map(([o, s]) => m("div", { key: o, ...p.value, class: "hys-ui-toast-stack", style: j(s[0]) }, s.map((t) => m(X, {
66
- key: t.token,
67
- ref: (f) => {
68
- f ? d.set(t.token, f) : d.delete(t.token);
69
- },
70
- "data-toast-id": t.id,
71
- message: t.message,
72
- type: t.type,
73
- duration: t.duration,
74
- closable: t.closable ?? !0,
75
- showIcon: t.showIcon ?? !0,
76
- pauseOnHover: t.pauseOnHover ?? !0,
77
- closeOnEscape: t.closeOnEscape,
78
- position: t.position,
79
- offset: t.offset,
80
- zIndex: t.zIndex,
81
- plain: t.plain,
82
- repeat: t.repeat,
83
- teleport: !1,
84
- onClose: () => h(t),
85
- onAfterClose: () => H(t)
86
- }, {
87
- ...t.content !== void 0 ? { default: () => typeof t.content == "function" ? t.content() : t.content } : {},
88
- ...t.icon !== void 0 ? { icon: () => typeof t.icon == "function" ? t.icon() : t.icon } : {}
89
- })))));
90
- };
74
+ return a = V(p), () => null;
91
75
  }
92
- });
93
- function D() {
94
- if (r) return;
95
- const e = typeof n.appendTo == "string" ? document.querySelector(n.appendTo) : n.appendTo ?? document.body;
96
- if (!e) throw new Error("Toast appendTo target was not found");
97
- r = document.createElement("div"), r.dataset.hysToastHost = "", e.appendChild(r);
98
- const o = m(q);
99
- o.appContext = l.appContext, b(o, r);
100
- }
101
- function O(e) {
102
- const o = w(e), s = { type: "info", ...n, ...o };
103
- s.type === "loading" && o.duration === void 0 && (s.duration = 0);
104
- const t = a.find((i) => !i.closing && (o.id && i.id === o.id || s.grouping && o.message && o.content === void 0 && i.message === o.message && i.type === s.type && g(i.position) === g(s.position)));
105
- if (t)
106
- return o.id || t.repeat++, I(t, o), t.handle;
107
- const f = "hys-toast-" + ++J, $ = o.id ?? f;
108
- let T;
109
- const S = new Promise((i) => {
110
- T = i;
111
- }), c = A({ ...s, token: f, id: $, repeat: 1, closing: !1, finished: !1, resolve: T });
112
- if (c.handle = { id: $, closed: S, close: () => h(c), update: (i) => I(c, i) }, v || !x || !c.message && (c.content == null || c.content === !1 || c.content === ""))
113
- return c.finished = !0, T(), c.handle;
114
- for (; a.filter((i) => !i.closing).length >= M; ) h(a.find((i) => !i.closing));
115
- return D(), a.push(c), c.handle;
116
- }
117
- function E() {
118
- for (const e of [...a])
119
- e.closing || (e.closing = !0, C(e.onClose)), H(e);
120
- r && (b(null, r), r.remove(), r = void 0);
121
- }
122
- B(() => {
123
- x = !1, E();
124
- }), N(() => {
125
- x = !0;
126
- }), P(() => {
127
- v = !0, E();
128
- });
129
- const u = (e) => (o) => O({ ...w(o), type: e });
130
- return { show: O, success: u("success"), info: u("info"), warning: u("warning"), error: u("error"), loading: u("loading"), closeAll: () => {
131
- for (const e of [...a]) h(e);
132
- } };
76
+ }), f = C(
77
+ T({
78
+ setup() {
79
+ return Q({ theme: s, motion: m, buttonAutoInsertSpace: o }), () => H(r);
80
+ }
81
+ })
82
+ );
83
+ return f.mount(document.createElement("div")), {
84
+ ...a,
85
+ dispose() {
86
+ c || (c = !0, f.unmount());
87
+ }
88
+ };
133
89
  }
134
- function Y(n = {}) {
135
- let l, p = !1;
136
- const a = k({ setup() {
137
- return l = K(n), () => null;
138
- } }), d = F(k({ setup() {
139
- return z(n), () => m(a);
140
- } }));
141
- return d.mount(document.createElement("div")), { ...l, dispose() {
142
- p || (p = !0, d.unmount());
143
- } };
90
+ let e;
91
+ const d = g({});
92
+ function u() {
93
+ return typeof document > "u" ? w() : e ?? (e = w({
94
+ ...d.value,
95
+ theme: () => l(d.value.theme) ?? "blue",
96
+ motion: () => l(d.value.motion) ?? "subtle",
97
+ buttonAutoInsertSpace: () => l(d.value.buttonAutoInsertSpace) ?? !0
98
+ }));
144
99
  }
100
+ function v(t) {
101
+ if (typeof document > "u") return;
102
+ const { theme: s, motion: m, buttonAutoInsertSpace: o, ...p } = t;
103
+ d.value = { ...d.value, ...t }, e == null || e.configure(p);
104
+ }
105
+ const B = {
106
+ show: (t) => u().show(t),
107
+ success: (t) => u().success(t),
108
+ info: (t) => u().info(t),
109
+ warning: (t) => u().warning(t),
110
+ error: (t) => u().error(t),
111
+ loading: (t) => u().loading(t),
112
+ promise: (t, s) => u().promise(t, s),
113
+ close: (t) => e == null ? void 0 : e.close(t),
114
+ update: (t, s) => e == null ? void 0 : e.update(t, s),
115
+ find: (t) => e == null ? void 0 : e.find(t),
116
+ list: (t) => (e == null ? void 0 : e.list(t)) ?? [],
117
+ closeAll: (t) => e == null ? void 0 : e.closeAll(t),
118
+ closeType: (t) => e == null ? void 0 : e.closeType(t),
119
+ clearQueue: () => e == null ? void 0 : e.clearQueue(),
120
+ configure: v,
121
+ dispose() {
122
+ e == null || e.dispose(), e = void 0;
123
+ }
124
+ };
145
125
  export {
146
- Y as createHysToast,
147
- K as useHysToast
126
+ v as configureHysToast,
127
+ w as createHysToast,
128
+ B as hysToast,
129
+ V as useHysToast
148
130
  };