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