hys-ui 0.4.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 (152) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/components/HysAnimatedNumber/HysAnimatedNumber.vue.js +3 -3
  3. package/dist/components/HysAnimatedNumber/HysAnimatedNumber2.vue.js +440 -119
  4. package/dist/components/HysAnimatedNumber/NumberAnimationCanvas/NumberAnimationCanvas.vue.js +7 -0
  5. package/dist/components/HysAnimatedNumber/NumberAnimationCanvas/NumberAnimationCanvas2.vue.js +166 -0
  6. package/dist/components/HysAnimatedNumber/NumberDigits/NumberDigits.vue.js +7 -0
  7. package/dist/components/HysAnimatedNumber/NumberDigits/NumberDigits2.vue.js +105 -0
  8. package/dist/components/HysAnimatedNumber/animation/digital.js +186 -0
  9. package/dist/components/HysAnimatedNumber/animation/morph.js +110 -0
  10. package/dist/components/HysAnimatedNumber/animation/paint.js +34 -0
  11. package/dist/components/HysAnimatedNumber/animation/particles.js +51 -0
  12. package/dist/components/HysAnimatedNumber/animation/paths.js +165 -0
  13. package/dist/components/HysAnimatedNumber/animation/physics.js +66 -0
  14. package/dist/components/HysAnimatedNumber/animation/render.js +89 -0
  15. package/dist/components/HysAnimatedNumber/animation/reveal.js +125 -0
  16. package/dist/components/HysAnimatedNumber/animation/rolling.js +66 -0
  17. package/dist/components/HysAnimatedNumber/animation/scenarios.js +217 -0
  18. package/dist/components/HysAnimatedNumber/animation/spatial.js +112 -0
  19. package/dist/components/HysAnimatedNumber/useNumberCountdown.js +58 -0
  20. package/dist/components/HysAnimatedNumber/useNumberVisuals.js +60 -0
  21. package/dist/components/HysDrawer/HysDrawer.vue.js +1 -1
  22. package/dist/components/HysDrawer/HysDrawer2.vue.js +2 -2
  23. package/dist/components/HysFormItem/HysFormItem.vue.js +1 -1
  24. package/dist/components/HysFormItem/HysFormItem2.vue.js +231 -229
  25. package/dist/components/HysInput/HysInput.vue.js +2 -2
  26. package/dist/components/HysInput/HysInput2.vue.js +327 -274
  27. package/dist/components/HysModal/HysModal.vue.js +2 -2
  28. package/dist/components/HysModal/HysModal2.vue.js +38 -38
  29. package/dist/components/HysSearch/HysSearch.vue.js +2 -2
  30. package/dist/components/HysSortableList/HysSortableList.vue.js +2 -2
  31. package/dist/components/HysSortableList/HysSortableList2.vue.js +498 -129
  32. package/dist/components/HysSortableList/SortableGhost/SortableGhost.vue.js +7 -0
  33. package/dist/components/HysSortableList/SortableGhost/SortableGhost2.vue.js +43 -0
  34. package/dist/components/HysSortableList/SortableGhost/useSortGhost.js +54 -0
  35. package/dist/components/HysSortableList/geometry.js +230 -0
  36. package/dist/components/HysSortableList/model.js +254 -0
  37. package/dist/components/HysSortableList/transactions.js +281 -0
  38. package/dist/components/HysSortableList/useSortDrag.js +270 -0
  39. package/dist/components/HysSortableList/useSortKeyboard.js +72 -0
  40. package/dist/components/HysSortableList/useSortWindow.js +144 -0
  41. package/dist/components/HysTextarea/HysTextarea.vue.js +56 -32
  42. package/dist/components/HysToast/HysToast.vue.js +3 -3
  43. package/dist/components/HysToast/HysToast2.vue.js +379 -107
  44. package/dist/components/HysToast/ToastViewport/ToastViewport.vue.js +7 -0
  45. package/dist/components/HysToast/ToastViewport/ToastViewport2.vue.js +211 -0
  46. package/dist/components/HysToast/ToastViewport/useToastStackDisclosure.js +71 -0
  47. package/dist/components/HysToast/toastPresentation.js +98 -0
  48. package/dist/components/HysToast/useToastActions.js +62 -0
  49. package/dist/components/HysToast/useToastSwipe.js +48 -0
  50. package/dist/components/HysToast/useToastTimer.js +90 -0
  51. package/dist/composables/animatedNumberDigits.js +106 -0
  52. package/dist/composables/animatedNumberFormat.js +222 -0
  53. package/dist/composables/animatedNumberTiming.js +66 -0
  54. package/dist/composables/numberAnimation.js +72 -0
  55. package/dist/composables/numberAnimationCatalog.js +301 -0
  56. package/dist/composables/numberAnimationSequence.js +45 -0
  57. package/dist/composables/popupReferenceBinding.js +41 -0
  58. package/dist/composables/textInput.js +23 -14
  59. package/dist/composables/toastEscape.js +18 -10
  60. package/dist/composables/toastQueue.js +276 -0
  61. package/dist/composables/toastQueueModel.js +86 -0
  62. package/dist/composables/toastTasks.js +58 -0
  63. package/dist/composables/useHysAnimatedNumber.js +264 -0
  64. package/dist/composables/useHysNumberAnimationGroup.js +23 -0
  65. package/dist/composables/useHysToast.js +117 -135
  66. package/dist/composables/usePopupSurface.js +190 -356
  67. package/dist/composables/usePopupSurfaceInteractions.js +172 -0
  68. package/dist/composables/useTextareaSize.js +62 -46
  69. package/dist/index.js +125 -111
  70. package/dist/style.css +1 -1
  71. package/dist/types/components/HysAnimatedNumber/HysAnimatedNumber.vue.d.ts +88 -49
  72. package/dist/types/components/HysAnimatedNumber/NumberAnimationCanvas/NumberAnimationCanvas.vue.d.ts +19 -0
  73. package/dist/types/components/HysAnimatedNumber/NumberDigits/NumberDigits.vue.d.ts +31 -0
  74. package/dist/types/components/HysAnimatedNumber/animation/digital.d.ts +3 -0
  75. package/dist/types/components/HysAnimatedNumber/animation/morph.d.ts +2 -0
  76. package/dist/types/components/HysAnimatedNumber/animation/paint.d.ts +44 -0
  77. package/dist/types/components/HysAnimatedNumber/animation/particles.d.ts +5 -0
  78. package/dist/types/components/HysAnimatedNumber/animation/paths.d.ts +12 -0
  79. package/dist/types/components/HysAnimatedNumber/animation/physics.d.ts +2 -0
  80. package/dist/types/components/HysAnimatedNumber/animation/render.d.ts +2 -0
  81. package/dist/types/components/HysAnimatedNumber/animation/reveal.d.ts +2 -0
  82. package/dist/types/components/HysAnimatedNumber/animation/rolling.d.ts +2 -0
  83. package/dist/types/components/HysAnimatedNumber/animation/scenarios.d.ts +4 -0
  84. package/dist/types/components/HysAnimatedNumber/animation/spatial.d.ts +2 -0
  85. package/dist/types/components/HysAnimatedNumber/useNumberCountdown.d.ts +8 -0
  86. package/dist/types/components/HysAnimatedNumber/useNumberVisuals.d.ts +12 -0
  87. package/dist/types/components/HysAutocomplete/HysAutocomplete.vue.d.ts +11 -2
  88. package/dist/types/components/HysAvatarGroup/HysAvatarGroup.vue.d.ts +2 -2
  89. package/dist/types/components/HysCard/HysCard.vue.d.ts +1 -1
  90. package/dist/types/components/HysCascader/HysCascader.vue.d.ts +3 -3
  91. package/dist/types/components/HysCascader/HysCascaderColumn.vue.d.ts +2 -2
  92. package/dist/types/components/HysColorPicker/HysColorPicker.vue.d.ts +2 -2
  93. package/dist/types/components/HysDatePicker/HysDatePicker.vue.d.ts +3 -3
  94. package/dist/types/components/HysDatePicker/HysDatePickerControl.vue.d.ts +5 -5
  95. package/dist/types/components/HysDateRangePicker/HysDateRangePicker.vue.d.ts +3 -3
  96. package/dist/types/components/HysDrawer/HysDrawer.vue.d.ts +1 -1
  97. package/dist/types/components/HysFormItem/HysFormItem.vue.d.ts +1 -1
  98. package/dist/types/components/HysGantt/HysGantt.vue.d.ts +1 -1
  99. package/dist/types/components/HysInput/HysInput.vue.d.ts +13 -1
  100. package/dist/types/components/HysModal/HysModal.vue.d.ts +1 -1
  101. package/dist/types/components/HysNumberInput/HysNumberInput.vue.d.ts +2 -2
  102. package/dist/types/components/HysPopover/HysPopover.vue.d.ts +1 -1
  103. package/dist/types/components/HysSearch/HysSearch.vue.d.ts +1 -1
  104. package/dist/types/components/HysSkeleton/HysSkeleton.vue.d.ts +2 -2
  105. package/dist/types/components/HysSortableList/HysSortableList.vue.d.ts +48 -25
  106. package/dist/types/components/HysSortableList/SortableGhost/SortableGhost.vue.d.ts +31 -0
  107. package/dist/types/components/HysSortableList/SortableGhost/useSortGhost.d.ts +23 -0
  108. package/dist/types/components/HysSortableList/geometry.d.ts +35 -0
  109. package/dist/types/components/HysSortableList/model.d.ts +61 -0
  110. package/dist/types/components/HysSortableList/sortableList.d.ts +151 -0
  111. package/dist/types/components/HysSortableList/transactions.d.ts +10 -0
  112. package/dist/types/components/HysSortableList/useSortDrag.d.ts +25 -0
  113. package/dist/types/components/HysSortableList/useSortKeyboard.d.ts +17 -0
  114. package/dist/types/components/HysSortableList/useSortWindow.d.ts +16 -0
  115. package/dist/types/components/HysSteps/HysSteps.vue.d.ts +1 -1
  116. package/dist/types/components/HysTabs/HysTabs.vue.d.ts +1 -1
  117. package/dist/types/components/HysTagInput/HysTagInput.vue.d.ts +1 -1
  118. package/dist/types/components/HysTextarea/HysTextarea.vue.d.ts +13 -2
  119. package/dist/types/components/HysToast/HysToast.vue.d.ts +44 -46
  120. package/dist/types/components/HysToast/ToastViewport/ToastViewport.vue.d.ts +25 -0
  121. package/dist/types/components/HysToast/ToastViewport/useToastStackDisclosure.d.ts +16 -0
  122. package/dist/types/components/HysToast/toastPresentation.d.ts +8 -0
  123. package/dist/types/components/HysToast/toastTypes.d.ts +212 -0
  124. package/dist/types/components/HysToast/useToastActions.d.ts +18 -0
  125. package/dist/types/components/HysToast/useToastSwipe.d.ts +11 -0
  126. package/dist/types/components/HysToast/useToastTimer.d.ts +22 -0
  127. package/dist/types/components/HysTooltip/HysTooltip.vue.d.ts +1 -1
  128. package/dist/types/components/HysTour/HysTour.vue.d.ts +1 -1
  129. package/dist/types/components/HysTreeSelect/HysTreeSelect.vue.d.ts +3 -3
  130. package/dist/types/components/HysUpload/HysUpload.vue.d.ts +2 -2
  131. package/dist/types/composables/animatedNumber.d.ts +220 -0
  132. package/dist/types/composables/animatedNumberDigits.d.ts +32 -0
  133. package/dist/types/composables/animatedNumberFormat.d.ts +16 -0
  134. package/dist/types/composables/animatedNumberTiming.d.ts +21 -0
  135. package/dist/types/composables/drawer.d.ts +1 -1
  136. package/dist/types/composables/numberAnimation.d.ts +29 -0
  137. package/dist/types/composables/numberAnimationCatalog.d.ts +58 -0
  138. package/dist/types/composables/numberAnimationSequence.d.ts +13 -0
  139. package/dist/types/composables/popupReferenceBinding.d.ts +9 -0
  140. package/dist/types/composables/textInput.d.ts +39 -4
  141. package/dist/types/composables/toastEscape.d.ts +1 -1
  142. package/dist/types/composables/toastQueue.d.ts +121 -0
  143. package/dist/types/composables/toastQueueModel.d.ts +116 -0
  144. package/dist/types/composables/toastTasks.d.ts +2 -0
  145. package/dist/types/composables/useHysAnimatedNumber.d.ts +37 -0
  146. package/dist/types/composables/useHysNumberAnimationGroup.d.ts +4 -0
  147. package/dist/types/composables/useHysToast.d.ts +4 -48
  148. package/dist/types/composables/usePopupSurface.d.ts +20 -20
  149. package/dist/types/composables/usePopupSurfaceInteractions.d.ts +33 -0
  150. package/dist/types/composables/useTextareaSize.d.ts +5 -2
  151. package/dist/types/index.d.ts +15 -6
  152. package/package.json +1 -1
@@ -0,0 +1,264 @@
1
+ import { shallowRef as ue, watch as w, onMounted as le, onActivated as re, onDeactivated as fe, onBeforeUnmount as de, computed as ce, readonly as pe, toValue as me } from "vue";
2
+ import { useMotion as ve } from "../motion/useMotion.js";
3
+ import { listenVisibility as ye, unlistenVisibility as ge, unsubscribe as he, subscribe as be, makeEasing as Ae } from "./animatedNumberTiming.js";
4
+ import { numberDirection as D, numberValue as y, bounded as d, createNumberInterpolator as Me } from "./animatedNumberFormat.js";
5
+ function Pe(Q = {}, S) {
6
+ const i = () => me(Q), r = () => y(i().value), Y = () => y(i().from ?? r()), { effectiveMotion: Z } = ve(), g = () => i().disabled || Z.value === "off" || !_(), _ = () => d(i().duration ?? 650, 0, 0, Number.MAX_SAFE_INTEGER), N = Y(), a = ue({
7
+ value: N,
8
+ from: N,
9
+ to: r(),
10
+ progress: 0,
11
+ easedProgress: 0,
12
+ direction: D(N, r()),
13
+ status: "idle",
14
+ iteration: 1
15
+ });
16
+ let n, c = [N, r()], f = c, p = [], k = !1, A = !1, W = !1, l = !1, T, E = 0, B = -1 / 0, R, F;
17
+ const U = () => !A || W || i().pauseWhenHidden !== !1 && document.hidden, m = (e) => S == null ? void 0 : S(e, { ...a.value });
18
+ function v() {
19
+ he(C), T = void 0, E = 0;
20
+ }
21
+ function V() {
22
+ !n || l || U() || be(C);
23
+ }
24
+ function $(e, t, o) {
25
+ let s = t;
26
+ if (t > 0 && t < 1)
27
+ try {
28
+ s = d(e.easing(t), t, -4, 5);
29
+ } catch {
30
+ e.easing = (u) => u;
31
+ }
32
+ a.value = {
33
+ ...a.value,
34
+ status: o,
35
+ progress: t,
36
+ easedProgress: s,
37
+ value: t === 0 ? e.from : t === 1 ? e.to : e.interpolate(t, s)
38
+ };
39
+ }
40
+ function h() {
41
+ p = [], R = void 0, clearTimeout(F), F = void 0;
42
+ }
43
+ function L() {
44
+ const e = !!n;
45
+ n = void 0, l = !1, v(), e && (a.value = { ...a.value, status: "stopped" }, m("cancel"));
46
+ }
47
+ function q(e, t, o, s, u, P) {
48
+ return {
49
+ from: e,
50
+ to: t,
51
+ iteration: o,
52
+ loops: s,
53
+ duration: u,
54
+ elapsed: -P,
55
+ interpolate: Me(e, t, i().interpolate),
56
+ easing: Ae(i().easing),
57
+ alternate: i().alternate ?? !1,
58
+ started: !1
59
+ };
60
+ }
61
+ function x(e) {
62
+ n = e, a.value = {
63
+ from: e.from,
64
+ to: e.to,
65
+ value: e.from,
66
+ progress: 0,
67
+ easedProgress: 0,
68
+ direction: D(e.from, e.to),
69
+ status: e.elapsed < 0 ? "delayed" : "playing",
70
+ iteration: e.iteration
71
+ };
72
+ }
73
+ function j(e) {
74
+ e.started || (e.started = !0, m("start"));
75
+ }
76
+ function G(e, t, o) {
77
+ $(e, t, o), m("update"), n === e && m("progress");
78
+ }
79
+ function z(e, t = !1) {
80
+ if (n === e) {
81
+ if (!t && e.iteration < e.loops) {
82
+ const [o, s] = e.alternate ? [e.to, e.from] : c;
83
+ x(
84
+ q(
85
+ o,
86
+ s,
87
+ e.iteration + 1,
88
+ e.loops,
89
+ e.duration,
90
+ 0
91
+ )
92
+ ), m("loop");
93
+ return;
94
+ }
95
+ if (n = void 0, l = !1, v(), a.value = { ...a.value, status: "finished" }, m("end"), !n && p.length) {
96
+ const o = p.shift();
97
+ M(a.value.value, o);
98
+ }
99
+ }
100
+ }
101
+ function I() {
102
+ if (!n) return;
103
+ const e = n;
104
+ j(e), n === e && (G(e, 1, "playing"), z(e, !0));
105
+ }
106
+ function M(e, t, o = {}) {
107
+ if (L(), n) return;
108
+ c = [e, t], f = o.endpoints ?? c;
109
+ const s = i().loop, u = s === !0 ? 1 / 0 : Math.floor(
110
+ d(
111
+ typeof s == "number" ? s : void 0,
112
+ 1,
113
+ 1,
114
+ Number.MAX_SAFE_INTEGER
115
+ )
116
+ ), P = q(
117
+ e,
118
+ t,
119
+ 1,
120
+ u,
121
+ _(),
122
+ o.delay ?? d(i().delay, 0, 0, Number.MAX_SAFE_INTEGER)
123
+ );
124
+ x(P), o.immediate || g() || !P.duration || a.value.direction === "none" && e !== t ? I() : V();
125
+ }
126
+ function C(e) {
127
+ const t = n;
128
+ if (!t || l || U()) {
129
+ v();
130
+ return;
131
+ }
132
+ if (g() || !t.duration) {
133
+ I();
134
+ return;
135
+ }
136
+ const o = d(i().speed, 1, 0.01, 100);
137
+ if (t.elapsed += (T === void 0 ? 0 : e - T) * o, T = e, t.elapsed < 0 || (j(t), n !== t || l)) return;
138
+ const s = Math.min(1, t.elapsed / t.duration), u = i().fps;
139
+ s < 1 && E && u !== void 0 && e - E < 1e3 / d(u, 60, 1, 120) - 1 || (E = e, G(t, s, "playing"), s === 1 && !l && z(t));
140
+ }
141
+ function J(e) {
142
+ const t = y(e), o = i().interrupt ?? "retarget";
143
+ if (o === "queue" && n && !g()) {
144
+ (p.at(-1) ?? n.to) !== t && p.push(t);
145
+ const s = Math.floor(d(i().queueLimit, 32, 1, 256));
146
+ p.length > s && p.splice(0, p.length - s);
147
+ return;
148
+ }
149
+ h(), !(t === a.value.value && !n) && (B = performance.now(), M(
150
+ o === "restart" ? y(i().from ?? c[0]) : a.value.value,
151
+ t,
152
+ { immediate: o === "snap" }
153
+ ));
154
+ }
155
+ function K(e) {
156
+ if (!k) return;
157
+ const t = i().interrupt ?? "retarget", o = d(i().updateInterval, 0, 0, 6e4), s = B + o - performance.now();
158
+ (t === "retarget" || t === "restart") && s > 0 && !g() ? (R = e, F ?? (F = setTimeout(() => {
159
+ const u = R;
160
+ u !== void 0 && J(u);
161
+ }, s))) : J(e);
162
+ }
163
+ function H() {
164
+ h(), M(y(i().from ?? f[0]), r());
165
+ }
166
+ function ee() {
167
+ if (n) {
168
+ O();
169
+ return;
170
+ }
171
+ a.value.to !== r() || a.value.status === "stopped" ? (h(), M(a.value.value, r())) : H();
172
+ }
173
+ function te() {
174
+ !n || l || (l = !0, v(), a.value = { ...a.value, status: "paused" }, m("pause"));
175
+ }
176
+ function O() {
177
+ !n || !l || (l = !1, a.value = {
178
+ ...a.value,
179
+ status: n.elapsed < 0 ? "delayed" : "playing"
180
+ }, m("resume"), V());
181
+ }
182
+ function X() {
183
+ h(), L();
184
+ }
185
+ function ne() {
186
+ if (X(), n) return;
187
+ const e = y(i().from ?? f[0]), t = r();
188
+ c = f = [e, t], a.value = {
189
+ from: e,
190
+ to: t,
191
+ value: e,
192
+ progress: 0,
193
+ easedProgress: 0,
194
+ status: "idle",
195
+ direction: D(e, t),
196
+ iteration: 1
197
+ };
198
+ }
199
+ function ie() {
200
+ if (X(), n) return;
201
+ const e = r();
202
+ c = f = [y(i().from ?? e), e], a.value = {
203
+ from: e,
204
+ to: e,
205
+ value: e,
206
+ direction: "none",
207
+ progress: 1,
208
+ easedProgress: 1,
209
+ status: "idle",
210
+ iteration: 1
211
+ };
212
+ }
213
+ function ae() {
214
+ h();
215
+ const e = a.value.to === f[0] ? f[1] : f[0], t = a.value.value;
216
+ M(t, e, { delay: 0, endpoints: f });
217
+ }
218
+ function oe(e) {
219
+ if (!Number.isFinite(e)) return;
220
+ if (!n) {
221
+ const [s, u] = c;
222
+ x(q(s, u, 1, 1, _(), 0)), l = !0;
223
+ }
224
+ const t = n, o = d(e, 0, 0, 1);
225
+ t.elapsed = o * t.duration, G(t, o, l ? "paused" : "playing");
226
+ }
227
+ function b() {
228
+ U() ? v() : V();
229
+ }
230
+ function se(e) {
231
+ W = e, b();
232
+ }
233
+ return w(r, (e) => {
234
+ i().autoUpdate !== !1 && K(e);
235
+ }), w(g, (e) => {
236
+ e && I();
237
+ }), w(() => i().pauseWhenHidden, b), le(() => {
238
+ k = A = !0, ye(b), i().autoPlay ?? i().from !== void 0 ? H() : b();
239
+ }), re(() => {
240
+ A = !0, b();
241
+ }), fe(() => {
242
+ A = !1, v();
243
+ }), de(() => {
244
+ k = A = !1, h(), v(), n = void 0, ge(b);
245
+ }), {
246
+ frame: pe(a),
247
+ motionEnabled: ce(() => !g()),
248
+ play: ee,
249
+ pause: te,
250
+ resume: O,
251
+ stop: X,
252
+ restart: H,
253
+ reset: ne,
254
+ reverse: ae,
255
+ seek: oe,
256
+ finishAnimation: I,
257
+ updateTarget: K,
258
+ sync: ie,
259
+ hold: se
260
+ };
261
+ }
262
+ export {
263
+ Pe as useHysAnimatedNumber
264
+ };
@@ -0,0 +1,23 @@
1
+ import { toValue as n } from "vue";
2
+ function u(r) {
3
+ const o = () => new Set(n(r));
4
+ function e(t) {
5
+ for (const s of o()) s == null || s[t]();
6
+ }
7
+ return {
8
+ play: () => e("play"),
9
+ pause: () => e("pause"),
10
+ resume: () => e("resume"),
11
+ stop: () => e("stop"),
12
+ restart: () => e("restart"),
13
+ reset: () => e("reset"),
14
+ reverse: () => e("reverse"),
15
+ finishAnimation: () => e("finishAnimation"),
16
+ seek: (t) => {
17
+ for (const s of o()) s == null || s.seek(t);
18
+ }
19
+ };
20
+ }
21
+ export {
22
+ u as useHysNumberAnimationGroup
23
+ };
@@ -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
  };