juice-toast 1.3.4-alpha.1 → 1.4.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.
- package/CHANGELOG.md +3 -2
- package/package.json +15 -9
- package/dist/juice-toast.ios.js +0 -367
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
## v1.4.0
|
|
2
2
|
- Add Smart Queue
|
|
3
3
|
- Bugs fixed & Logic fixes
|
|
4
|
+
- Fix the toast speed
|
|
4
5
|
- Add Promise
|
|
5
6
|
- Add Universal Module Definition (UMD) Back
|
|
6
|
-
- !**Removing
|
|
7
|
+
- !**Removing iOS Support**!
|
|
7
8
|
|
|
8
9
|
v1.3.4
|
|
9
10
|
- Bug Fixes
|
|
@@ -16,7 +17,7 @@ v1.3.2
|
|
|
16
17
|
- Improved A11Y
|
|
17
18
|
- Adding Background Image
|
|
18
19
|
- Adding more Theme
|
|
19
|
-
- Adding default toast (juiceToast.success|error|info|warning)
|
|
20
|
+
- Adding default toast (juiceToast.success|error|info|warning|loading)
|
|
20
21
|
|
|
21
22
|
v1.3.1
|
|
22
23
|
- Improved iOS / Safari (WebKit) compatibility
|
package/package.json
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juice-toast",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Zero dependency JavaScript toast notification library with animations, dark mode, auto CSS injection, and mobile support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toast",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
7
|
+
"toast-js",
|
|
8
|
+
"toast-notification",
|
|
9
|
+
"toast-notification-js",
|
|
10
|
+
"javascript-toast",
|
|
11
|
+
"toast-library",
|
|
12
|
+
"popup-notification",
|
|
13
|
+
"ui-toast",
|
|
14
|
+
"alert-replacement",
|
|
15
|
+
"notification-library",
|
|
16
|
+
"vanilla-js-toast",
|
|
17
|
+
"frontend-ui",
|
|
18
|
+
"browser-notification"
|
|
19
|
+
],
|
|
14
20
|
"license": "MIT",
|
|
15
21
|
"author": "KhairyK",
|
|
16
22
|
"homepage": "https://github.com/KhairyK/juiceToast",
|
package/dist/juice-toast.ios.js
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenDN Foundation (C) 2026
|
|
3
|
-
* Juice Toast v1.4.0 (iOS user | Nearing End of Support notifier)
|
|
4
|
-
* Read CONTRIBUTE.md To Contribute
|
|
5
|
-
*/
|
|
6
|
-
let dev=!0;dev&&console.warn("Warning: You are using JuiceToast v1.4.0 for iOS, On v1.4.3 JuiceToast iOS will be removed.");let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMotion=isBrowser&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,isTouch=isBrowser&&("ontouchstart"in window||navigator&&navigator.maxTouchPoints>0),isIOS=isBrowser&&/iPad|iPhone|iPod/.test(navigator.userAgent||""),isIOSStandalone=isBrowser&&(!0===window.navigator.standalone||window.matchMedia&&window.matchMedia("(display-mode: standalone)").matches);function speakTTS(e,t="en-US",s=1){if(!("speechSynthesis"in window))return;let i=new SpeechSynthesisUtterance(e);i.lang=t,i.rate=s;let a=()=>{window.speechSynthesis.speak(i),document.body.removeEventListener("touchstart",a),document.body.removeEventListener("click",a)},o=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;o&&!1===window.speechSynthesis.speaking?(document.body.addEventListener("touchstart",a,{once:!0}),document.body.addEventListener("click",a,{once:!0})):a()}function normalizeState(e,t){return e?"string"==typeof e?{message:e}:e:{message:t}}function resolveState(e,t,s){return e?"function"==typeof e?{message:e(t)}:"string"==typeof e?{message:e}:e:{message:s}}let raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||(e=>setTimeout(e,16)),TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"},__cssInjected=!1,BASE_CSS=`
|
|
7
|
-
:root {
|
|
8
|
-
--jt-safe-top: env(safe-area-inset-top, 0px);
|
|
9
|
-
--jt-safe-bottom: env(safe-area-inset-bottom, 0px);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
#juice-toast-root {
|
|
13
|
-
position: fixed;
|
|
14
|
-
z-index: 9999;
|
|
15
|
-
display: flex;
|
|
16
|
-
gap: 10px;
|
|
17
|
-
pointer-events: none;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/* top */
|
|
21
|
-
#juice-toast-root[data-position="top"] {
|
|
22
|
-
top: 20px;
|
|
23
|
-
left: 50%;
|
|
24
|
-
transform: translateX(-50%);
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
align-items: center;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/* center */
|
|
30
|
-
#juice-toast-root[data-position="center"] {
|
|
31
|
-
top: 50%;
|
|
32
|
-
left: 50%;
|
|
33
|
-
transform: translate(-50%, -50%);
|
|
34
|
-
flex-direction: column;
|
|
35
|
-
align-items: center;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
[id^="juice-toast-root-"] {
|
|
39
|
-
position: fixed;
|
|
40
|
-
z-index: 9999;
|
|
41
|
-
display: flex;
|
|
42
|
-
gap: 10px;
|
|
43
|
-
pointer-events: none;
|
|
44
|
-
padding-top: var(--jt-safe-top);
|
|
45
|
-
padding-bottom: var(--jt-safe-bottom);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
/* ================= TOAST ================= */
|
|
50
|
-
|
|
51
|
-
.juice-toast {
|
|
52
|
-
--jt-x: 0px;
|
|
53
|
-
--jt-y: 12px;
|
|
54
|
-
|
|
55
|
-
pointer-events: auto;
|
|
56
|
-
display: flex;
|
|
57
|
-
gap: 12px;
|
|
58
|
-
align-items: flex-start;
|
|
59
|
-
|
|
60
|
-
min-width: 220px;
|
|
61
|
-
max-width: 420px;
|
|
62
|
-
padding: 12px 16px;
|
|
63
|
-
margin: 6px 0;
|
|
64
|
-
|
|
65
|
-
border-radius: 8px;
|
|
66
|
-
background: #333;
|
|
67
|
-
color: #fff;
|
|
68
|
-
|
|
69
|
-
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial;
|
|
70
|
-
font-size: 14px;
|
|
71
|
-
|
|
72
|
-
opacity: 0;
|
|
73
|
-
transform: translate(var(--jt-x), var(--jt-y));
|
|
74
|
-
transition:
|
|
75
|
-
opacity .25s ease,
|
|
76
|
-
transform .25s ease,
|
|
77
|
-
background .25s ease,
|
|
78
|
-
color .25s ease,
|
|
79
|
-
box-shadow .25s ease;
|
|
80
|
-
|
|
81
|
-
position: relative;
|
|
82
|
-
box-sizing: border-box;
|
|
83
|
-
overflow: hidden;
|
|
84
|
-
|
|
85
|
-
scroll-behavior: contains;
|
|
86
|
-
-webkit-overflow-scrolling: touch;
|
|
87
|
-
|
|
88
|
-
will-change: transform, opacity;
|
|
89
|
-
backface-visibility: hidden;
|
|
90
|
-
-webkit-backface-visibility: hidden;
|
|
91
|
-
|
|
92
|
-
touch-action: pan-y;
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/* visible */
|
|
97
|
-
.juice-toast.show {
|
|
98
|
-
opacity: 1;
|
|
99
|
-
--jt-y: 0px;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/* ================= ICON ================= */
|
|
103
|
-
|
|
104
|
-
.juice-toast .icon {
|
|
105
|
-
width: 28px;
|
|
106
|
-
height: 28px;
|
|
107
|
-
display: inline-flex;
|
|
108
|
-
align-items: center;
|
|
109
|
-
justify-content: center;
|
|
110
|
-
font-size: 16px;
|
|
111
|
-
line-height: 1;
|
|
112
|
-
flex: 0 0 28px;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/* clickable icon */
|
|
116
|
-
.icon-clickable {
|
|
117
|
-
opacity: 0.85;
|
|
118
|
-
cursor: pointer;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
.icon-clickable:hover {
|
|
122
|
-
opacity: 1;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
.jt-message code {
|
|
126
|
-
background: rgba(255,255,255,0.1);
|
|
127
|
-
color: #facc15; /* kuning */
|
|
128
|
-
padding: 2px 4px;
|
|
129
|
-
border-radius: 4px;
|
|
130
|
-
font-family: monospace;
|
|
131
|
-
font-size: 0.9em;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/* ================= CONTENT ================= */
|
|
135
|
-
|
|
136
|
-
.juice-toast .jt-content {
|
|
137
|
-
display: flex;
|
|
138
|
-
flex-direction: column;
|
|
139
|
-
gap: 4px;
|
|
140
|
-
flex: 1 1 auto;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/* title */
|
|
144
|
-
.juice-toast .jt-title {
|
|
145
|
-
font-weight: 700;
|
|
146
|
-
font-size: 13px;
|
|
147
|
-
line-height: 1.1;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/* message */
|
|
151
|
-
.juice-toast .jt-message {
|
|
152
|
-
font-size: 13px;
|
|
153
|
-
line-height: 1.3;
|
|
154
|
-
opacity: 0.95;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/* ================= ICON POSITION ================= */
|
|
158
|
-
|
|
159
|
-
.jt-icon-top {
|
|
160
|
-
flex-direction: column;
|
|
161
|
-
align-items: flex-start;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
.jt-icon-top .icon {
|
|
165
|
-
align-self: center;
|
|
166
|
-
margin-bottom: 6px;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/* ================= CLOSE ================= */
|
|
170
|
-
|
|
171
|
-
.juice-toast-close {
|
|
172
|
-
position: absolute;
|
|
173
|
-
top: 6px;
|
|
174
|
-
right: 8px;
|
|
175
|
-
cursor: pointer;
|
|
176
|
-
font-size: 16px;
|
|
177
|
-
opacity: 0.75;
|
|
178
|
-
padding: 4px;
|
|
179
|
-
border-radius: 4px;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
.juice-toast-close:hover {
|
|
183
|
-
opacity: 1;
|
|
184
|
-
background: rgba(255,255,255,0.06);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/* ================= ACTIONS ================= */
|
|
188
|
-
|
|
189
|
-
.jt-actions {
|
|
190
|
-
display: flex;
|
|
191
|
-
gap: 8px;
|
|
192
|
-
margin-top: 10px;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
.jt-action {
|
|
196
|
-
background: transparent;
|
|
197
|
-
border: 1px solid currentColor;
|
|
198
|
-
padding: 4px 10px;
|
|
199
|
-
border-radius: 6px;
|
|
200
|
-
cursor: pointer;
|
|
201
|
-
font-size: 12px;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/* ================= COMPACT ================= */
|
|
205
|
-
|
|
206
|
-
.jt-compact {
|
|
207
|
-
padding: 8px 10px;
|
|
208
|
-
gap: 8px;
|
|
209
|
-
font-size: 0.9em;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/* ================= GLASS UI ================= */
|
|
213
|
-
|
|
214
|
-
.jt-glass {
|
|
215
|
-
--g: calc(var(--jt-glass, 60) / 100);
|
|
216
|
-
|
|
217
|
-
background: rgba(30, 30, 30, calc(0.2 + var(--g)));
|
|
218
|
-
backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
219
|
-
saturate(calc(1 + (0.4 * var(--g))));
|
|
220
|
-
-webkit-backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
221
|
-
saturate(calc(1 + (0.4 * var(--g))));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/* light theme support */
|
|
225
|
-
[data-theme="light"] .jt-glass {
|
|
226
|
-
background:
|
|
227
|
-
linear-gradient(
|
|
228
|
-
rgba(255,255,255, calc(0.6 * var(--g))),
|
|
229
|
-
rgba(255,255,255, calc(0.35 * var(--g)))
|
|
230
|
-
),
|
|
231
|
-
rgba(255,255,255, calc(0.55 - (0.25 * var(--g))));
|
|
232
|
-
|
|
233
|
-
color: #111;
|
|
234
|
-
|
|
235
|
-
border:
|
|
236
|
-
1px solid rgba(0,0,0, calc(0.05 + 0.12 * var(--g)));
|
|
237
|
-
|
|
238
|
-
box-shadow:
|
|
239
|
-
0 10px 30px rgba(0,0,0, calc(0.08 + 0.18 * var(--g))),
|
|
240
|
-
inset 0 1px 0 rgba(255,255,255, calc(0.4 * var(--g)));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/* ================= PROGRESS BAR ================= */
|
|
244
|
-
.jt-progress {
|
|
245
|
-
position: absolute;
|
|
246
|
-
left: 0;
|
|
247
|
-
bottom: 0;
|
|
248
|
-
|
|
249
|
-
height: 3px;
|
|
250
|
-
width: 100%;
|
|
251
|
-
|
|
252
|
-
background: linear-gradient(to right, #FFFFFF, #FAFAFA);
|
|
253
|
-
height: 4px;
|
|
254
|
-
transform-origin: left;
|
|
255
|
-
transition: transform linear;
|
|
256
|
-
border-radius: 2px;
|
|
257
|
-
transform: scaleX(1);
|
|
258
|
-
opacity: .85;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
.juice-toast.bg-image {
|
|
262
|
-
background-size: cover;
|
|
263
|
-
background-position: center;
|
|
264
|
-
background-repeat: no-repeat;
|
|
265
|
-
color: #fff;
|
|
266
|
-
text-shadow: 0 1px 2px rgba(0,0,0,0.6);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/* ================= ANIMATIONS ================= */
|
|
270
|
-
|
|
271
|
-
@keyframes jt-spin {
|
|
272
|
-
to { transform: rotate(360deg); }
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
@keyframes jt-pulse {
|
|
276
|
-
50% { transform: scale(1.15); }
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
@keyframes jt-shake {
|
|
280
|
-
25% { transform: translateX(-3px); }
|
|
281
|
-
50% { transform: translateX(3px); }
|
|
282
|
-
75% { transform: translateX(-3px); }
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
@keyframes jt-bounce {
|
|
286
|
-
0% { transform: scale(1); }
|
|
287
|
-
30% { transform: scale(1.25); }
|
|
288
|
-
60% { transform: scale(.95); }
|
|
289
|
-
100% { transform: scale(1); }
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
@keyframes jt-wiggle {
|
|
293
|
-
0% { transform: rotate(0); }
|
|
294
|
-
25% { transform: rotate(-10deg); }
|
|
295
|
-
50% { transform: rotate(10deg); }
|
|
296
|
-
75% { transform: rotate(-6deg); }
|
|
297
|
-
100% { transform: rotate(0); }
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
@keyframes jt-pop {
|
|
301
|
-
0% { transform: scale(.7); opacity: 0; }
|
|
302
|
-
70% { transform: scale(1.05); opacity: 1; }
|
|
303
|
-
100% { transform: scale(1); }
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
@keyframes jt-spin {
|
|
307
|
-
from {
|
|
308
|
-
transform: rotate(0deg);
|
|
309
|
-
}
|
|
310
|
-
to {
|
|
311
|
-
transform: rotate(360deg);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/* ================= CLASSES ================= */
|
|
316
|
-
|
|
317
|
-
.spin { animation: jt-spin .6s linear; }
|
|
318
|
-
.pulse { animation: jt-pulse .4s ease; }
|
|
319
|
-
.shake { animation: jt-shake .4s ease; }
|
|
320
|
-
.bounce { animation: jt-bounce .45s ease; }
|
|
321
|
-
.wiggle { animation: jt-wiggle .5s ease; }
|
|
322
|
-
.pop { animation: jt-pop .35s ease-out; }
|
|
323
|
-
.spin {
|
|
324
|
-
animation: jt - spin 1 s linear infinite;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
.icon-clickable {
|
|
328
|
-
cursor: pointer;
|
|
329
|
-
transition: transform .15s ease, opacity .15s ease;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
.icon-clickable:hover {
|
|
333
|
-
transform: scale(1.1);
|
|
334
|
-
opacity: .85;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
/* ================= ACCESSIBILITY ================= */
|
|
338
|
-
|
|
339
|
-
@media (prefers-reduced-motion: reduce) {
|
|
340
|
-
.spin,
|
|
341
|
-
.pulse,
|
|
342
|
-
.shake,
|
|
343
|
-
.bounce,
|
|
344
|
-
.wiggle,
|
|
345
|
-
.pop {
|
|
346
|
-
animation: none !important;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
.jt-profile {
|
|
351
|
-
width: 40px;
|
|
352
|
-
height: 40px;
|
|
353
|
-
border-radius: 50%;
|
|
354
|
-
object-fit: cover;
|
|
355
|
-
flex-shrink: 0;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
.jt-profile.square {
|
|
359
|
-
border-radius: 8px;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
.juice-toast {
|
|
363
|
-
display: flex;
|
|
364
|
-
align-items: center;
|
|
365
|
-
gap: 10px;
|
|
366
|
-
}
|
|
367
|
-
`;function injectCSS(e){if(!isBrowser||__cssInjected)return;let t=document.createElement("style");t.id="juice-toast-style",t.textContent=e,document.head.appendChild(t),__cssInjected=!0}function sanitizeHTML(e){let t=document.createElement("template");t.innerHTML=e,t.content.querySelectorAll("script, [onload], [onclick], [onerror]").forEach(e=>e.remove());let s=["b","i","u","strong","em","code","pre","ul","ol","li","br","p","span","img","h1","h2","h3","h4","h5","h6"],i=e=>{e.childNodes.forEach(e=>{1===e.nodeType&&(s.includes(e.tagName.toLowerCase())?i(e):e.replaceWith(...e.childNodes))})};return i(t.content),t.innerHTML}let themes={light:{bg:"#ffffff",color:"#111",border:"1px solid #e5e7eb"},dark:{bg:"#1f2937",color:"#fff",border:"1px solid rgba(255,255,255,.08)"},glass:{bg:"rgba(30,30,30,.35)",color:"#fff",border:"1px solid rgba(255,255,255,.15)"},midnight:{bg:"#0f172a",color:"#e5e7eb",border:"1px solid rgba(255,255,255,.06)"},soft:{bg:"#f8fafc",color:"#0f172a",border:"1px solid #e2e8f0"},neutral:{bg:"#ffffff",color:"#374151",border:"1px solid #d1d5db"},brand:{bg:"#6366f1",color:"#fff",border:"none"},gradient:{bg:"linear-gradient(135deg,#6366f1,#ec4899)",color:"#fff",border:"none"},outline:{bg:"transparent",color:"#111",border:"2px solid currentColor"}},sizePreset={sm:{width:"260px",padding:"10px"},md:{width:"320px",padding:"14px"},lg:{width:"420px",padding:"18px"}},juiceToast={_config:{},_queue:[],_showing:!1,_theme:"dark",_plugins:[],_activePromises:new Map,setup(e={}){let{duration:t,maxVisible:s,...i}=e;this._defaults={...this._defaults,duration:t,maxVisible:s},this._config={...this._config,...i},isIOS&&(this._defaults.swipeThreshold=Math.min(this._defaults.swipeThreshold||60,50),this._defaults.glassUI=this._defaults.glassUI||60,this._defaults.duration=this._defaults.duration??2200),this._registerTypes()},use(e){"function"==typeof e&&this._plugins.push(e)},addType(e,t={}){this._config[e]=t,this._registerTypes()},defineTheme(e,t={}){themes[e]={...themes[e]||{},...t}},setTheme(e){if(this._theme=e,!isBrowser)return;let t=document.querySelector('[id^="juice-toast-root-"]');t&&(t.dataset.theme=e)},clear(){this._queue.length=0},destroy(){if(this.clear(),!isBrowser)return;let e=document.querySelectorAll('[id^="juice-toast-root-"]');e.forEach(e=>e.remove())},promise(e,t={}){if(!e||"function"!=typeof e.then){this._warn("promise() expects a Promise");return}let s="jt-promise-"+Date.now(),i={cancelled:!1,timer:null};return this._activePromises.set(s,i),this._enqueue("loading",{...normalizeState(t.loading,"Loading..."),groupId:s,duration:0}),t.timeout&&(i.timer=setTimeout(()=>{i.cancelled||(i.cancelled=!0,this._enqueue("error",{message:t.timeoutMessage||"Request timeout",groupId:s}),this._activePromises.delete(s))},t.timeout)),e.then(e=>{i.cancelled||(clearTimeout(i.timer),this._enqueue("success",{...resolveState(t.success,e,"Success"),groupId:s}),this._activePromises.delete(s))}).catch(e=>{i.cancelled||(clearTimeout(i.timer),this._enqueue("error",{...resolveState(t.error,e,"Error"),groupId:s}),this._activePromises.delete(s))}),{cancel:()=>{this._activePromises.has(s)&&(i.cancelled=!0,clearTimeout(i.timer),this._enqueue("info",{message:t.cancelMessage||"Cancelled",groupId:s}),this._activePromises.delete(s))}}},_registerTypes(){Object.keys(this._config).forEach(e=>{if("function"==typeof this[e]&&!this[e].__auto)return;let t=t=>this._enqueue(e,t);t.__auto=!0,this[e]=t})},_enqueue(e,t){this._queue.push({type:e,payload:t}),this._showing||this._next()},_next(){if(!this._queue.length){this._showing=!1;return}this._showing=!0;let e=this._queue.shift();this._showToast(e.type,e.payload)},_runPlugins(e){this._plugins.forEach(t=>{try{t(e)}catch(s){this._warn("Plugin error: "+(s&&s.message?s.message:String(s)))}})},_normalizeGlass(e){if(!0===e)return 60;if(!1===e||null==e)return 0;let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0},_getRoot(e="bottom-right"){if(!isBrowser)return null;let t=document.getElementById(`juice-toast-root-${e}`);if(!t){switch((t=document.createElement("div")).id=`juice-toast-root-${e}`,t.dataset.position=e,t.dataset.theme=this._theme,t.style.position="fixed",t.style.zIndex=9999,t.style.display="flex",t.style.flexDirection="column",t.style.gap="8px",t.style.pointerEvents="none",e){case"top-left":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.left="20px",t.style.alignItems="flex-start";break;case"top-right":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.right="20px",t.style.alignItems="flex-end";break;case"bottom-left":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.left="20px",t.style.alignItems="flex-start";break;case"bottom-right":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.right="20px",t.style.alignItems="flex-end";break;case"top-center":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.left="50%",t.style.transform="translateX(-50%)",t.style.alignItems="center";break;case"bottom-center":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.left="50%",t.style.transform="translateX(-50%)",t.style.alignItems="center";break;default:t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.right="20px"}document.body.appendChild(t)}return t},_defaults:{duration:2500,maxVisible:3,swipeThreshold:60,glassUI:0,playSound:null,dev:!1,injectCSS:!0,css:null},_warn(e){this._defaults.dev&&"undefined"!=typeof console&&console.warn("[JuiceToast]",e)},_playSound(e){if(!isBrowser)return;let t="string"==typeof e&&e?e:this._defaults.playSound;if(t)try{let s=new Audio(t);s.volume=.6;let i=()=>{s.play().catch(()=>{}),window.removeEventListener("touchstart",i),window.removeEventListener("click",i)};s.play().catch(()=>{window.addEventListener("touchstart",i,{once:!0}),window.addEventListener("click",i,{once:!0})})}catch(a){}},_showToast(e,t){if(!isBrowser)return;!1!==this._defaults.injectCSS&&injectCSS(this._defaults.css||BASE_CSS);let s=this._config[e]||{},i="object"==typeof t?t:{message:String(t)},a={...s,...i};a.icon=a.icon??a.icon_left_top,a.iconPack=a.iconPack??a.icon_config,a.iconLink=a.iconLink??a.icon_onClick_url,a.iconAnimate=a.iconAnimate??a.icon_onClick_animate,a.position=a.position??a.toast,a.closable=a.closable??a.closeable,a.iconPosition=a.iconPosition||"left",a.compact=!!a.compact;let o=themes[a.theme||this._theme]||{},n=document.createElement("div");n.className="juice-toast";let r=a.animation||"slide-in";if(a.enterAnimation||(n.style.animation=`${r} 0.4s ease forwards`),n.setAttribute("role","alert"),n.setAttribute("aria-live","error"===e?"assertive":"polite"),n.setAttribute("aria-atomic","true"),n.tabIndex=0,a.closable){let l=document.createElement("span");l.className="juice-toast-close",l.textContent="\xd7",l.tabIndex=0,l.addEventListener("keydown",e=>{("Enter"===e.key||" "===e.key)&&(n.remove(),this._next())})}if(a.size&&sizePreset[a.size]){let c=sizePreset[a.size];c.width&&(n.style.width=c.width),c.padding&&(n.style.padding=c.padding)}let d=null;a.profile&&((d=document.createElement("img")).src=a.profile,d.className="jt-profile","square"===a.profileShape&&d.classList.add("square"),n.appendChild(d));let p=null,u=a.duration??this._defaults.duration;a.progress&&u>0&&((p=document.createElement("div")).className="jt-progress",a.progressColor&&(p.style.background=a.progressColor||"rgba(255,255,255,.7)"),n.appendChild(p)),a.tts&&a.message&&speakTTS(a.message,a.ttsLang??"en-US",a.ttsRate??1);let m=this._normalizeGlass(a.glassUI??this._defaults.glassUI);m>0&&(n.style.setProperty("--jt-glass",a.glassUI??50),n.classList.add("jt-glass")),m||(n.style.background=a.bg||o.bg),n.style.color=a.color||o.color,n.style.border=a.border||o.border,a.compact&&n.classList.add("jt-compact"),a.width&&(n.style.width=a.width),a.height&&(n.style.height=a.height),a.bgImage&&(n.style.backgroundImage=`url(${a.bgImage})`,n.classList.add("bg-image"));let f=null;if(a.icon){(f=document.createElement("i")).className=["icon",a.iconPack||"",a.icon].join(" ").trim(),a.iconSize&&(f.style.fontSize=a.iconSize),(a.iconLink||a.iconAnimate)&&(f.classList.add("icon-clickable"),f.onclick=e=>{e.stopPropagation(),a.iconAnimate&&(f.classList.remove(a.iconAnimate),f.offsetWidth,f.classList.add(a.iconAnimate)),a.iconLink&&window.open(a.iconLink,"_blank","noopener")});let h=a.iconAnimate??TYPE_ANIMATION[e];h&&(f.classList.add(h),f.addEventListener("click",()=>{f.classList.remove(h),f.offsetWidth,f.classList.add(h)}))}let g=this._getRoot(a.position);if(a.groupId){let $=Array.from(g.children).find(e=>e.dataset.groupId===a.groupId);if($){let b=$.querySelector(".jt-count");b||((b=document.createElement("span")).className="jt-count",b.style.marginLeft="6px",$.querySelector(".jt-title").appendChild(b),b.textContent="1"),b.textContent=parseInt(b.textContent)+1;return}n.dataset.groupId=a.groupId}if(reduceMotion&&(n.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),f?.classList.remove("bounce","shake","wiggle","pulse","spin")),a.message||a.title||this._warn("Toast created without message or title"),a.html){let x=document.createElement("div");x.className="jt-message",x.innerHTML=sanitizeHTML(a.html),S.appendChild(x)}a.icon&&!a.iconPack&&this._warn("icon provided without iconPack"),a.duration<0&&this._warn("duration cannot be negative");let y=0,v=0,_=!1,k=e=>{let t=e.touches?e.touches[0]:e;y=t.clientX,v=0,_=!0,n.__paused=!0},j=e=>{if(!_)return;let t=e.touches?e.touches[0]:e;v=t.clientX-y,n.style.transform=`translate3d(${v}px, 0, 0)`},w=()=>{_&&(_=!1,Math.abs(v)>(this._defaults.swipeThreshold||60)?(n.style.transition="transform .25s ease, opacity .2s ease",n.style.transform=`translate3d(${v>0?1e3:-1e3}px, 0, 0)`,setTimeout(()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},220)):(n.style.transition="transform .2s ease",n.style.transform=""),setTimeout(()=>{n.__paused=!1},60),y=v=0)};isTouch?(n.addEventListener("touchstart",k,{passive:!0}),n.addEventListener("touchmove",j,{passive:!0}),n.addEventListener("touchend",w),n.addEventListener("touchcancel",w)):n.addEventListener("mousedown",e=>{y=e.clientX,v=0,_=!0,n.__paused=!0;let t=e=>{v=e.clientX-y,n.style.transform=`translate3d(${v}px, 0, 0)`},s=()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",s),w()};document.addEventListener("mousemove",t),document.addEventListener("mouseup",s)});let S=document.createElement("div");S.className="jt-content";let E=a.enterAnimation??"pop";if(E&&!reduceMotion&&n.classList.add(E),a.title){let L=document.createElement("div");L.className="jt-title",L.textContent=a.title,S.appendChild(L)}let C=document.createElement("div");if(C.className="jt-message",a.undo){let I=document.createElement("button");I.className="jt-action",I.textContent="Undo",I.onclick=()=>{a.undo(),n.remove(),this._next()},S.appendChild(I),a.undoTimeout&&setTimeout(()=>{n.parentNode&&n.remove()},a.undoTimeout)}if("string"==typeof a.message){let T=a.message.split(/(`[^`]+`)/g);T.forEach(e=>{if(e.startsWith("`")&&e.endsWith("`")){let t=document.createElement("code");t.textContent=e.slice(1,-1),C.appendChild(t)}else C.appendChild(document.createTextNode(e))})}if(S.appendChild(C),f&&"top"===a.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(f),n.appendChild(S)):f&&"right"===a.iconPosition?(n.appendChild(S),n.appendChild(f)):(f&&n.appendChild(f),n.appendChild(S)),Array.isArray(a.actions)&&a.actions.length){let P=document.createElement("div");P.className="jt-actions",a.actions.forEach(e=>{let t=document.createElement("button");t.className="jt-action",t.textContent=e.label,t.onclick=t=>{t.stopPropagation(),e.onClick?.(t),e.closeOnClick&&(n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next())},P.appendChild(t)}),S.appendChild(P)}if(a.closable){let A=document.createElement("span");A.className="juice-toast-close",A.textContent="\xd7",A.onclick=()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},n.appendChild(A)}isIOSStandalone&&(n.style.borderRadius=n.style.borderRadius||"14px");let N=this._defaults.maxVisible;if(N&&g.children.length>=N&&g.firstChild.remove(),g.appendChild(n),this._runPlugins({toast:n,cfg:a,type:e,root:g}),requestAnimationFrame(()=>{n.classList.add("show")}),0===u)return;let z=Date.now(),q=u,O=()=>{if(n.__paused)z=Date.now();else{let e=Date.now();q-=e-z,z=e}if(q<=0?(n.classList.remove("show"),setTimeout(()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},300)):raf(O),p){let t=Math.max(0,Math.min(1,q/u));p.style.transform=`scaleX(${t})`}},M=0;n.addEventListener("mousedown",e=>{M=e.clientY,n.style.transition="none"}),n.addEventListener("mousemove",e=>{0!==M&&(n.style.transform=`translateY(${e.clientY-M}px)`)}),n.addEventListener("mouseup",e=>{n.style.transition="",n.style.transform="",M=0}),isTouch||(n.addEventListener("mouseenter",()=>n.__paused=!0),n.addEventListener("mouseleave",()=>n.__paused=!1)),n.addEventListener("touchstart",()=>{n.__paused=!0},{passive:!0}),n.addEventListener("touchend",()=>{n.__paused=!1}),z=Date.now(),raf(O),(a.playSound||this._defaults.playSound)&&this._playSound(a.playSound)}};juiceToast.setup({success:{icon:"fa-check",iconPack:"fa-solid",bg:"#16a34a",progress:!0,duration:3e3},error:{icon:"fa-xmark",iconPack:"fa-solid",bg:"#dc2626",progress:!0,duration:4e3},info:{icon:"fa-circle-info",iconPack:"fa-solid",bg:"#2563eb",progress:!0},warning:{icon:"fa-triangle-exclamation",iconPack:"fa-solid",bg:"#f59e0b",progress:!0},loading:{icon:"fa-spinner",iconPack:"fa-solid",iconAnimate:"spin",duration:0,progress:!1,closable:!1}});export default juiceToast;export{juiceToast};
|