juice-toast 1.3.4 → 1.4.1
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 +25 -369
- package/dist/juice-toast.umd.js +25 -0
- package/package.json +18 -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
|
@@ -1,369 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
#juice-toast-root
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/* center */
|
|
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};
|
|
1
|
+
var ht=Object.defineProperty,mt=Object.defineProperties,ft=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,ot=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,it=(e,t,o)=>t in e?ht(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,X=(e,t)=>{for(var o in t||(t={}))ot.call(t,o)&&it(e,o,t[o]);if(I)for(var o of I(t))st.call(t,o)&&it(e,o,t[o]);return e},Y=(e,t)=>mt(e,ft(t)),gt=(e,t)=>{var o={};for(var r in e)ot.call(e,r)&&t.indexOf(r)<0&&(o[r]=e[r]);if(e!=null&&I)for(var r of I(e))t.indexOf(r)<0&&st.call(e,r)&&(o[r]=e[r]);return o};const _=typeof window!="undefined"&&typeof document!="undefined",yt=_&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;class C{constructor(){this._heap=[]}get size(){return this._heap.length}_parent(t){return Math.floor((t-1)/2)}_left(t){return 2*t+1}_right(t){return 2*t+2}_swap(t,o){[this._heap[t],this._heap[o]]=[this._heap[o],this._heap[t]]}push(t,o=0){const r={item:t,priority:o,seq:C._seq=(C._seq||0)+1};this._heap.push(r),this._siftUp(this._heap.length-1)}pop(){if(!this._heap.length)return null;this._swap(0,this._heap.length-1);const t=this._heap.pop();return this._siftDown(0),t.item}peek(){return this._heap[0]?this._heap[0].item:null}_siftUp(t){for(;t>0;){const o=this._parent(t);if(this._compare(t,o)<=0)break;this._swap(t,o),t=o}}_siftDown(t){for(;;){const o=this._left(t),r=this._right(t),u=this._heap.length;let c=t;if(o<u&&this._compare(o,c)>0&&(c=o),r<u&&this._compare(r,c)>0&&(c=r),c===t)break;this._swap(t,c),t=c}}_compare(t,o){const r=this._heap[t],u=this._heap[o];return r.priority!==u.priority?r.priority-u.priority:u.seq-r.seq}}let R=!1;const at=`
|
|
2
|
+
/* JuiceToast base (v1.4.0) */
|
|
3
|
+
#juice-toast-root,[id^="juice-toast-root-"]{position:fixed;z-index:9999;display:flex;pointer-events:none;gap:10px}
|
|
4
|
+
#juice-toast-root[data-position="bottom-right"],#juice-toast-root-bottom-right{bottom:20px;right:20px;flex-direction:column-reverse;align-items:flex-end}
|
|
5
|
+
#juice-toast-root[data-position="top-right"]{top:20px;right:20px;flex-direction:column;align-items:flex-end}
|
|
6
|
+
#juice-toast-root[data-position="bottom-left"]{bottom:20px;left:20px;flex-direction:column-reverse;align-items:flex-start}
|
|
7
|
+
#juice-toast-root[data-position="top-left"]{top:20px;left:20px;flex-direction:column;align-items:flex-start}
|
|
8
|
+
#juice-toast-root[data-position="top-center"],#juice-toast-root[data-position="bottom-center"]{left:50%;transform:translateX(-50%)}
|
|
9
|
+
.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}
|
|
10
|
+
@keyframes jt-slide-in{0%{opacity:0;transform:translateY(20px) scale(0.95)}100%{opacity:1;transform:translateY(0) scale(1)}}
|
|
11
|
+
@keyframes jt-slide-out{0%{opacity:1;transform:translateY(0) scale(1)}100%{opacity:0;transform:translateY(20px) scale(0.95)}}
|
|
12
|
+
.juice-toast.show{animation:jt-slide-in .32s cubic-bezier(0.4,0,0.2,1) forwards;opacity:1;transform:translateY(0)}
|
|
13
|
+
.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}
|
|
14
|
+
.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)}
|
|
15
|
+
.jt-content{display:flex;flex-direction:column;gap:4px;flex:1}
|
|
16
|
+
.jt-title{font-weight:700;font-size:13px}
|
|
17
|
+
.jt-message{font-size:13px;opacity:.95}
|
|
18
|
+
.jt-actions{display:flex;gap:8px;margin-top:10px}
|
|
19
|
+
.jt-action{border:1px solid currentColor;padding:4px 10px;border-radius:6px;font-size:12px;cursor:pointer;background:transparent}
|
|
20
|
+
.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}
|
|
21
|
+
|
|
22
|
+
/* avatar specific */
|
|
23
|
+
.jt-avatar{width:36px;height:36px;border-radius:50%;object-fit:cover;flex-shrink:0}
|
|
24
|
+
`;function _t(e=at){if(!_||R)return;if(document.getElementById("juice-toast-style")){R=!0;return}const t=document.createElement("style");t.id="juice-toast-style",t.textContent=e,document.head.appendChild(t),R=!0}const V=(()=>{let e=1;return()=>"jt-"+e++})();function b(){return Date.now()}function W(e,t){return Object.assign({},e||{},t||{})}function bt(e,t,o){return Math.max(t,Math.min(o,e))}function vt(e){if(!e)return"";const t=document.createElement("template");t.innerHTML=e,t.content.querySelectorAll("script, style, iframe").forEach(r=>r.remove());const o=["b","i","u","strong","em","code","pre","ul","ol","li","br","p","span","img","h1","h2","h3","h4","h5","h6","a"];return(function r(u){Array.from(u.childNodes).forEach(c=>{if(c.nodeType===1){const h=c.tagName.toLowerCase();o.includes(h)?(Array.from(c.attributes||[]).forEach(x=>{const f=x.name.toLowerCase(),L=x.value||"";(f.startsWith("on")||(f==="href"||f==="src"||f==="xlink:href")&&L.trim().toLowerCase().startsWith("javascript:")||h==="img"&&f==="srcset")&&c.removeAttribute(x.name)}),r(c)):c.replaceWith(...Array.from(c.childNodes))}})})(t.content),t.innerHTML}const $={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)"}},rt={sm:{width:"260px",padding:"10px"},md:{width:"320px",padding:"14px"},lg:{width:"420px",padding:"18px"}},xt={success:"jt-bounce",error:"jt-shake",warning:"jt-shake",info:"jt-pulse",loading:"jt-spin"},v={_defaults:{duration:2500,maxVisible:3,swipeThreshold:60,glassUI:0,playSound:null,dev:!1,injectCSS:!0,css:null},_config:{},_theme:"dark",_plugins:[],_queue:new C,_queueDedupe:new Set,_activeMap:new Map,_roots:new Map,setup(e={}){const t=e,{duration:o,maxVisible:r}=t,u=gt(t,["duration","maxVisible"]);o&&(this._defaults.duration=o),r&&(this._defaults.maxVisible=r),this._config=W(this._config,u),this._registerTypes()},use(e){typeof e=="function"&&this._plugins.push(e)},addType(e,t={}){this._config[e]=t,this._registerTypes()},defineTheme(e,t={}){$[e]=W($[e]||{},t)},setTheme(e){this._theme=e,_&&this._roots.forEach(t=>t.dataset.theme=e)},clear(){this._queue=new C,this._queueDedupe.clear()},destroy(){this.clear(),_&&(this._roots.forEach(e=>e.remove()),this._roots.clear())},promise(e,t={}){if(!e||typeof e.then!="function"){this._warn("promise expects a Promise");return}const o={id:V()}.id,r=t.timeout;this._enqueue("loading",Y(X({},jt(t.loading,"Loading...")),{groupId:o,duration:0}));let u=null;r&&(u=setTimeout(()=>{this._enqueue("error",{message:t.timeoutMessage||"Request timeout",groupId:o}),c()},r));const c=()=>{u&&clearTimeout(u)};return e.then(h=>{c(),this._enqueue("success",Y(X({},lt(t.success,h,"Success")),{groupId:o}))}).catch(h=>{c(),this._enqueue("error",Y(X({},lt(t.error,h,"Error")),{groupId:o}))}),{cancel:()=>{this._enqueue("info",{message:t.cancelMessage||"Cancelled",groupId:o}),u&&clearTimeout(u)}}},_registerTypes(){Object.keys(this._config).forEach(e=>{if(typeof this[e]=="function"&&!this[e].__auto)return;const t=o=>this._enqueue(e,o);t.__auto=!0,this[e]=t})},_enqueue(e,t={}){var o,r;const u=(r=(o=this._priorityMap)==null?void 0:o[t.priority])!=null?r:2,c=t.dedupeKey;if(c&&this._queueDedupe.has(c)){this._defaults.dev&&console.log("[JuiceToast] deduped",c);return}const h={id:V(),type:e,payload:t,priority:u};c&&this._queueDedupe.add(c),this._queue.push(h,u),this._processQueue()},_processQueue(){var e;if(!_)return;const t=this._defaults.maxVisible;for(;this._queue.size>0;){const o=this._queue.pop();if(!o)break;const r=((e=o.payload)==null?void 0:e.position)||"bottom-right",u=this._getRoot(r);if(Array.from(u.children).length>=t){this._queue.push(o,o.priority-.001);break}this._showToast(o.type,o.payload,o.id)}},_getRoot(e="bottom-right"){if(!_)return null;if(this._roots.has(e))return this._roots.get(e);const 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":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%)";break;default:t.style.bottom="20px",t.style.right="20px"}return document.body.appendChild(t),this._roots.set(e,t),t},_warn(e){this._defaults.dev&&typeof console!="undefined"&&console.warn("[JuiceToast]",e)},_playSound(e){if(!_)return;const t=typeof e=="string"&&e?e:this._defaults.playSound;if(t)try{const o=new Audio(t);o.volume=.6,o.play().catch(()=>{})}catch(o){}},_updateStackPositionsFor(e){const t=Array.from(e.children);e.dataset.position&&e.dataset.position.includes("bottom"),t.forEach((o,r)=>{const u=r,c=u*12;o.style.setProperty("--jt-stack-y",`-${c}px`),o.style.setProperty("--jt-stack-scale",1-u*.04),o.style.setProperty("--jt-stack-opacity",1-u*.12),o.style.zIndex=1e3-u})},_runPlugins(e){this._plugins.forEach(t=>{try{t(e)}catch(o){this._warn("Plugin error: "+o.message)}})},_normalizeGlass(e){if(e===!0)return 60;if(!e)return 0;const t=Number(e);return Number.isFinite(t)?bt(t,0,100):0},_showToast(e,t={},o){var r,u,c,h,x,f,L,H,J,B,Q,G,K;if(!_)return;this._defaults.injectCSS!==!1&&_t(this._defaults.css||at);const ct=this._config[e]||{},ut=typeof t=="object"?t:{message:String(t)},n=W(ct,ut);n.icon=(r=n.icon)!=null?r:n.icon_left_top,n.position=(c=(u=n.position)!=null?u:n.toast)!=null?c:"bottom-right",n.closable=(x=(h=n.closable)!=null?h:n.closeable)!=null?x:!0,n.duration=(f=n.duration)!=null?f:this._defaults.duration;const z=$[n.theme||this._theme]||{},g=o||V(),s=document.createElement("div");if(s.className="juice-toast",s.dataset.toastId=g,s.dataset.position=n.position,s.tabIndex=0,s.setAttribute("role","status"),s.style.position="relative",s.style.pointerEvents="auto",s.style.background=n.bg||z.bg,s.style.color=n.color||z.color,s.style.border=n.border||z.border||"none",n.size&&rt[n.size]){const i=rt[n.size];i.width&&(s.style.width=i.width),i.padding&&(s.style.padding=i.padding)}const m=document.createElement("div");if(m.className="jt-content",n.title){const i=document.createElement("div");i.className="jt-title",i.textContent=n.title,m.appendChild(i)}const j=document.createElement("div");if(j.className="jt-message",n.html?j.innerHTML=vt(n.html):typeof n.message=="string"?n.message.split(/(`[^`]+`)/g).forEach(i=>{if(i.startsWith("`")&&i.endsWith("`")){const l=document.createElement("code");l.textContent=i.slice(1,-1),j.appendChild(l)}else j.appendChild(document.createTextNode(i))}):n.message&&(j.textContent=String(n.message)),m.appendChild(j),Array.isArray(n.actions)&&n.actions.length){const i=document.createElement("div");i.className="jt-actions",n.actions.forEach(l=>{const A=document.createElement("button");A.className="jt-action",A.textContent=l.label||"Action",A.onclick=et=>{var nt;et.stopPropagation(),(nt=l.onClick)==null||nt.call(l,et),l.closeOnClick&&k()},i.appendChild(A)}),m.appendChild(i)}let p=null;if(n.icon){if(p=document.createElement("i"),p.className=["icon",n.iconPack||"",n.icon].join(" ").trim(),n.iconSize&&(p.style.fontSize=n.iconSize),!yt){const i=n.iconAnim||xt[e];i&&p.classList.add(i)}(n.iconLink||n.iconAnimate)&&(p.classList.add("icon-clickable"),p.addEventListener("click",i=>{i.stopPropagation(),n.iconAnimate&&(p.classList.remove(n.iconAnimate),p.offsetWidth,p.classList.add(n.iconAnimate)),n.iconLink&&window.open(n.iconLink,"_blank","noopener")}))}let d=null;if(n.avatar){d=document.createElement("img");const i=typeof n.avatar=="string"&&n.avatar?n.avatar:n.avatarSrc||"";i&&(d.src=i),d.alt=n.avatarAlt||n.title||"avatar",d.className="jt-avatar",d.loading=n.avatarLazy?"lazy":"eager",d.style.width=d.style.width||"36px",d.style.height=d.style.height||"36px",d.style.borderRadius=d.style.borderRadius||"50%",d.style.objectFit=d.style.objectFit||"cover",d.style.flexShrink="0";const l=n.avatarPosition||"left";l==="left"?d.style.marginRight=(L=n.avatarSpacing)!=null?L:"10px":l==="right"?d.style.marginLeft=(H=n.avatarSpacing)!=null?H:"10px":l==="top"&&(d.style.marginBottom=(J=n.avatarSpacing)!=null?J:"8px")}const N=n.avatarPosition||"left";d&&N==="top"?(s.classList.add("jt-avatar-top"),s.style.flexDirection="column",s.style.alignItems="flex-start",s.appendChild(d),p&&n.iconPosition==="top"?(s.appendChild(p),s.appendChild(m)):p&&n.iconPosition==="right"?(s.appendChild(m),s.appendChild(p)):(p&&s.appendChild(p),s.appendChild(m))):(s.style.flexDirection="row",s.style.alignItems="center",d&&N==="left"&&s.appendChild(d),p&&n.iconPosition==="right"?(s.appendChild(m),s.appendChild(p)):p&&n.iconPosition==="top"?(s.classList.add("jt-icon-top"),s.appendChild(p),s.appendChild(m)):(p&&s.appendChild(p),s.appendChild(m)),d&&N==="right"&&s.appendChild(d));let w=null;if(n.progress&&((B=n.duration)!=null?B:this._defaults.duration)>0&&(w=document.createElement("div"),w.className="jt-progress",n.progressColor&&(w.style.background=n.progressColor),s.appendChild(w)),n.undo){const i=document.createElement("button");i.className="jt-action",i.textContent="Undo",i.onclick=()=>{try{n.undo()}catch(l){}k()},m.appendChild(i)}if(n.closable){const i=document.createElement("span");i.className="juice-toast-close",i.tabIndex=0,i.textContent="\xD7",i.addEventListener("click",l=>{l.stopPropagation(),k()}),s.appendChild(i)}const y=this._getRoot(n.position||"bottom-right");if(!y)return;if(n.groupId){const i=Array.from(y.children).find(l=>l.dataset.groupId===n.groupId);if(i){let l=i.querySelector(".jt-count");l||(l=document.createElement("span"),l.className="jt-count",l.style.marginLeft="6px",(Q=i.querySelector(".jt-title"))==null||Q.appendChild(l),l.textContent="1"),l.textContent=String(parseInt(l.textContent||"1")+1);return}s.dataset.groupId=n.groupId}const Z=this._defaults.maxVisible;Z&&y.children.length>=Z&&y.removeChild(y.firstElementChild),y.appendChild(s);const a={id:g,toast:s,cfg:n,createdAt:b(),remaining:(G=n.duration)!=null?G:this._defaults.duration,raf:null,timer:null,start:b(),paused:!1,_boundMove:null,_boundUp:null};this._activeMap.set(g,a),this._runPlugins({toast:s,cfg:n,type:e,root:y}),this._updateStackPositionsFor(y),requestAnimationFrame(()=>s.classList.add("show"));let U=0,O=0,E=0,M=0,F=!1;const S=i=>{const l=i.touches?i.touches[0]:i;U=l.clientX,O=l.clientY,F=!0,a.paused=!0,a.raf&&(cancelAnimationFrame(a.raf),a.raf=null),s.style.transition="none",a._boundMove=dt,a._boundUp=pt,document.addEventListener("touchmove",a._boundMove,{passive:!0}),document.addEventListener("mousemove",a._boundMove),document.addEventListener("touchend",a._boundUp),document.addEventListener("mouseup",a._boundUp)},dt=i=>{if(!F)return;const l=i.touches?i.touches[0]:i;E=l.clientX-U,M=l.clientY-O,Math.abs(E)>Math.abs(M)?s.style.transform=`translateX(${E}px)`:s.style.transform=`translateY(${M}px)`},pt=()=>{F=!1,a.paused=!1,s.style.transition="",Math.abs(E)>(this._defaults.swipeThreshold||60)?(s.style.transform=`translateX(${E>0?1e3:-1e3}px)`,setTimeout(k,220)):s.style.transform="",U=O=E=M=0,a._boundMove&&(document.removeEventListener("touchmove",a._boundMove,{passive:!0}),document.removeEventListener("mousemove",a._boundMove),a._boundMove=null),a._boundUp&&(document.removeEventListener("touchend",a._boundUp),document.removeEventListener("mouseup",a._boundUp),a._boundUp=null),D()};s.addEventListener("touchstart",S,{passive:!0}),s.addEventListener("mousedown",S);const P=()=>{a.paused=!0,a.raf&&(cancelAnimationFrame(a.raf),a.raf=null)},q=()=>{a.paused&&(a.paused=!1,a.start=b(),D())};s.addEventListener("mouseenter",P),s.addEventListener("mouseleave",q),s.addEventListener("focusin",P),s.addEventListener("focusout",q);const T=(K=n.duration)!=null?K:this._defaults.duration;function tt(){if(!v._activeMap.has(g))return;if(a.paused){a.raf=null,a.start=b();return}const i=b()-a.start;if(a.remaining-=i,a.start=b(),w){const l=Math.max(0,a.remaining/T);w.style.transform=`scaleX(${l})`}if(a.remaining<=0){s.classList.remove("show"),setTimeout(k,280),a.raf=null;return}a.raf=requestAnimationFrame(tt)}function D(){T<=0||a.raf||a.paused||(a.start=b(),a.raf=requestAnimationFrame(tt))}T>0&&(a.start=b(),a.remaining=T,D());function k(){if(!v._activeMap.has(g))return;s.classList.add("hide"),s.removeEventListener("touchstart",S),s.removeEventListener("mousedown",S),a._boundMove&&(document.removeEventListener("touchmove",a._boundMove,{passive:!0}),document.removeEventListener("mousemove",a._boundMove),a._boundMove=null),a._boundUp&&(document.removeEventListener("touchend",a._boundUp),document.removeEventListener("mouseup",a._boundUp),a._boundUp=null),s.removeEventListener("mouseenter",P),s.removeEventListener("mouseleave",q),s.removeEventListener("focusin",P),s.removeEventListener("focusout",q);const i=v._activeMap.get(g);i!=null&&i.raf&&(cancelAnimationFrame(i.raf),i.raf=null),i!=null&&i.timer&&(clearTimeout(i.timer),i.timer=null),v._activeMap.delete(g);const l=s.parentNode;l&&l.removeChild(s),l&&v._updateStackPositionsFor(l)}return n.undoTimeout&&(a.timer=setTimeout(k,n.undoTimeout)),(n.playSound||this._defaults.playSound)&&this._playSound(n.playSound||this._defaults.playSound),g},_priorityMap:{low:1,normal:2,high:3,urgent:4}};function jt(e,t){return e?typeof e=="string"?{message:t}:e:{message:t}}function lt(e,t,o){return e?typeof e=="function"?{message:e(t)}:typeof e=="string"?{message:e}:e:{message:o}}v.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{v as default,v as juiceToast};
|
|
25
|
+
//# sourceMappingURL=juice-toast.esm.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
(function(x,L){typeof exports=="object"&&typeof module!="undefined"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(x=typeof globalThis!="undefined"?globalThis:x||self,L(x.juiceToast={}))})(this,(function(x){"use strict";var L=Object.defineProperty,de=Object.defineProperties,pe=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertySymbols,B=Object.prototype.hasOwnProperty,Q=Object.prototype.propertyIsEnumerable,G=(t,e,o)=>e in t?L(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o,U=(t,e)=>{for(var o in e||(e={}))B.call(e,o)&&G(t,o,e[o]);if(S)for(var o of S(e))Q.call(e,o)&&G(t,o,e[o]);return t},O=(t,e)=>de(t,pe(e)),he=(t,e)=>{var o={};for(var r in t)B.call(t,r)&&e.indexOf(r)<0&&(o[r]=t[r]);if(t!=null&&S)for(var r of S(t))e.indexOf(r)<0&&Q.call(t,r)&&(o[r]=t[r]);return o};const m=typeof window!="undefined"&&typeof document!="undefined",fe=m&&window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches;class M{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,o){[this._heap[e],this._heap[o]]=[this._heap[o],this._heap[e]]}push(e,o=0){const r={item:e,priority:o,seq:M._seq=(M._seq||0)+1};this._heap.push(r),this._siftUp(this._heap.length-1)}pop(){if(!this._heap.length)return null;this._swap(0,this._heap.length-1);const 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;){const o=this._parent(e);if(this._compare(e,o)<=0)break;this._swap(e,o),e=o}}_siftDown(e){for(;;){const o=this._left(e),r=this._right(e),u=this._heap.length;let c=e;if(o<u&&this._compare(o,c)>0&&(c=o),r<u&&this._compare(r,c)>0&&(c=r),c===e)break;this._swap(e,c),e=c}}_compare(e,o){const r=this._heap[e],u=this._heap[o];return r.priority!==u.priority?r.priority-u.priority:u.seq-r.seq}}let F=!1;const K=`
|
|
2
|
+
/* JuiceToast base (v1.4.0) */
|
|
3
|
+
#juice-toast-root,[id^="juice-toast-root-"]{position:fixed;z-index:9999;display:flex;pointer-events:none;gap:10px}
|
|
4
|
+
#juice-toast-root[data-position="bottom-right"],#juice-toast-root-bottom-right{bottom:20px;right:20px;flex-direction:column-reverse;align-items:flex-end}
|
|
5
|
+
#juice-toast-root[data-position="top-right"]{top:20px;right:20px;flex-direction:column;align-items:flex-end}
|
|
6
|
+
#juice-toast-root[data-position="bottom-left"]{bottom:20px;left:20px;flex-direction:column-reverse;align-items:flex-start}
|
|
7
|
+
#juice-toast-root[data-position="top-left"]{top:20px;left:20px;flex-direction:column;align-items:flex-start}
|
|
8
|
+
#juice-toast-root[data-position="top-center"],#juice-toast-root[data-position="bottom-center"]{left:50%;transform:translateX(-50%)}
|
|
9
|
+
.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}
|
|
10
|
+
@keyframes jt-slide-in{0%{opacity:0;transform:translateY(20px) scale(0.95)}100%{opacity:1;transform:translateY(0) scale(1)}}
|
|
11
|
+
@keyframes jt-slide-out{0%{opacity:1;transform:translateY(0) scale(1)}100%{opacity:0;transform:translateY(20px) scale(0.95)}}
|
|
12
|
+
.juice-toast.show{animation:jt-slide-in .32s cubic-bezier(0.4,0,0.2,1) forwards;opacity:1;transform:translateY(0)}
|
|
13
|
+
.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}
|
|
14
|
+
.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)}
|
|
15
|
+
.jt-content{display:flex;flex-direction:column;gap:4px;flex:1}
|
|
16
|
+
.jt-title{font-weight:700;font-size:13px}
|
|
17
|
+
.jt-message{font-size:13px;opacity:.95}
|
|
18
|
+
.jt-actions{display:flex;gap:8px;margin-top:10px}
|
|
19
|
+
.jt-action{border:1px solid currentColor;padding:4px 10px;border-radius:6px;font-size:12px;cursor:pointer;background:transparent}
|
|
20
|
+
.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}
|
|
21
|
+
|
|
22
|
+
/* avatar specific */
|
|
23
|
+
.jt-avatar{width:36px;height:36px;border-radius:50%;object-fit:cover;flex-shrink:0}
|
|
24
|
+
`;function me(t=K){if(!m||F)return;if(document.getElementById("juice-toast-style")){F=!0;return}const e=document.createElement("style");e.id="juice-toast-style",e.textContent=t,document.head.appendChild(e),F=!0}const D=(()=>{let t=1;return()=>"jt-"+t++})();function g(){return Date.now()}function X(t,e){return Object.assign({},t||{},e||{})}function ge(t,e,o){return Math.max(e,Math.min(o,t))}function ye(t){if(!t)return"";const e=document.createElement("template");e.innerHTML=t,e.content.querySelectorAll("script, style, iframe").forEach(r=>r.remove());const o=["b","i","u","strong","em","code","pre","ul","ol","li","br","p","span","img","h1","h2","h3","h4","h5","h6","a"];return(function r(u){Array.from(u.childNodes).forEach(c=>{if(c.nodeType===1){const h=c.tagName.toLowerCase();o.includes(h)?(Array.from(c.attributes||[]).forEach(j=>{const _=j.name.toLowerCase(),P=j.value||"";(_.startsWith("on")||(_==="href"||_==="src"||_==="xlink:href")&&P.trim().toLowerCase().startsWith("javascript:")||h==="img"&&_==="srcset")&&c.removeAttribute(j.name)}),r(c)):c.replaceWith(...Array.from(c.childNodes))}})})(e.content),e.innerHTML}const Y={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)"}},Z={sm:{width:"260px",padding:"10px"},md:{width:"320px",padding:"14px"},lg:{width:"420px",padding:"18px"}},_e={success:"jt-bounce",error:"jt-shake",warning:"jt-shake",info:"jt-pulse",loading:"jt-spin"},y={_defaults:{duration:2500,maxVisible:3,swipeThreshold:60,glassUI:0,playSound:null,dev:!1,injectCSS:!0,css:null},_config:{},_theme:"dark",_plugins:[],_queue:new M,_queueDedupe:new Set,_activeMap:new Map,_roots:new Map,setup(t={}){const e=t,{duration:o,maxVisible:r}=e,u=he(e,["duration","maxVisible"]);o&&(this._defaults.duration=o),r&&(this._defaults.maxVisible=r),this._config=X(this._config,u),this._registerTypes()},use(t){typeof t=="function"&&this._plugins.push(t)},addType(t,e={}){this._config[t]=e,this._registerTypes()},defineTheme(t,e={}){Y[t]=X(Y[t]||{},e)},setTheme(t){this._theme=t,m&&this._roots.forEach(e=>e.dataset.theme=t)},clear(){this._queue=new M,this._queueDedupe.clear()},destroy(){this.clear(),m&&(this._roots.forEach(t=>t.remove()),this._roots.clear())},promise(t,e={}){if(!t||typeof t.then!="function"){this._warn("promise expects a Promise");return}const o={id:D()}.id,r=e.timeout;this._enqueue("loading",O(U({},be(e.loading,"Loading...")),{groupId:o,duration:0}));let u=null;r&&(u=setTimeout(()=>{this._enqueue("error",{message:e.timeoutMessage||"Request timeout",groupId:o}),c()},r));const c=()=>{u&&clearTimeout(u)};return t.then(h=>{c(),this._enqueue("success",O(U({},ee(e.success,h,"Success")),{groupId:o}))}).catch(h=>{c(),this._enqueue("error",O(U({},ee(e.error,h,"Error")),{groupId:o}))}),{cancel:()=>{this._enqueue("info",{message:e.cancelMessage||"Cancelled",groupId:o}),u&&clearTimeout(u)}}},_registerTypes(){Object.keys(this._config).forEach(t=>{if(typeof this[t]=="function"&&!this[t].__auto)return;const e=o=>this._enqueue(t,o);e.__auto=!0,this[t]=e})},_enqueue(t,e={}){var o,r;const u=(r=(o=this._priorityMap)==null?void 0:o[e.priority])!=null?r:2,c=e.dedupeKey;if(c&&this._queueDedupe.has(c)){this._defaults.dev&&console.log("[JuiceToast] deduped",c);return}const h={id:D(),type:t,payload:e,priority:u};c&&this._queueDedupe.add(c),this._queue.push(h,u),this._processQueue()},_processQueue(){var t;if(!m)return;const e=this._defaults.maxVisible;for(;this._queue.size>0;){const o=this._queue.pop();if(!o)break;const r=((t=o.payload)==null?void 0:t.position)||"bottom-right",u=this._getRoot(r);if(Array.from(u.children).length>=e){this._queue.push(o,o.priority-.001);break}this._showToast(o.type,o.payload,o.id)}},_getRoot(t="bottom-right"){if(!m)return null;if(this._roots.has(t))return this._roots.get(t);const e=document.createElement("div");switch(e.id=`juice-toast-root-${t}`,e.dataset.position=t,e.dataset.theme=this._theme,e.style.pointerEvents="none",e.style.display="flex",t){case"top-left":e.style.top="20px",e.style.left="20px";break;case"top-right":e.style.top="20px",e.style.right="20px";break;case"bottom-left":e.style.bottom="20px",e.style.left="20px";break;case"bottom-right":e.style.bottom="20px",e.style.right="20px";break;case"top-center":e.style.top="20px",e.style.left="50%",e.style.transform="translateX(-50%)";break;case"bottom-center":e.style.bottom="20px",e.style.left="50%",e.style.transform="translateX(-50%)";break;default:e.style.bottom="20px",e.style.right="20px"}return document.body.appendChild(e),this._roots.set(t,e),e},_warn(t){this._defaults.dev&&typeof console!="undefined"&&console.warn("[JuiceToast]",t)},_playSound(t){if(!m)return;const e=typeof t=="string"&&t?t:this._defaults.playSound;if(e)try{const o=new Audio(e);o.volume=.6,o.play().catch(()=>{})}catch(o){}},_updateStackPositionsFor(t){const e=Array.from(t.children);t.dataset.position&&t.dataset.position.includes("bottom"),e.forEach((o,r)=>{const u=r,c=u*12;o.style.setProperty("--jt-stack-y",`-${c}px`),o.style.setProperty("--jt-stack-scale",1-u*.04),o.style.setProperty("--jt-stack-opacity",1-u*.12),o.style.zIndex=1e3-u})},_runPlugins(t){this._plugins.forEach(e=>{try{e(t)}catch(o){this._warn("Plugin error: "+o.message)}})},_normalizeGlass(t){if(t===!0)return 60;if(!t)return 0;const e=Number(t);return Number.isFinite(e)?ge(e,0,100):0},_showToast(t,e={},o){var r,u,c,h,j,_,P,te,ne,oe,se,ie,ae;if(!m)return;this._defaults.injectCSS!==!1&&me(this._defaults.css||K);const ve=this._config[t]||{},xe=typeof e=="object"?e:{message:String(e)},n=X(ve,xe);n.icon=(r=n.icon)!=null?r:n.icon_left_top,n.position=(c=(u=n.position)!=null?u:n.toast)!=null?c:"bottom-right",n.closable=(j=(h=n.closable)!=null?h:n.closeable)!=null?j:!0,n.duration=(_=n.duration)!=null?_:this._defaults.duration;const R=Y[n.theme||this._theme]||{},b=o||D(),s=document.createElement("div");if(s.className="juice-toast",s.dataset.toastId=b,s.dataset.position=n.position,s.tabIndex=0,s.setAttribute("role","status"),s.style.position="relative",s.style.pointerEvents="auto",s.style.background=n.bg||R.bg,s.style.color=n.color||R.color,s.style.border=n.border||R.border||"none",n.size&&Z[n.size]){const i=Z[n.size];i.width&&(s.style.width=i.width),i.padding&&(s.style.padding=i.padding)}const f=document.createElement("div");if(f.className="jt-content",n.title){const i=document.createElement("div");i.className="jt-title",i.textContent=n.title,f.appendChild(i)}const w=document.createElement("div");if(w.className="jt-message",n.html?w.innerHTML=ye(n.html):typeof n.message=="string"?n.message.split(/(`[^`]+`)/g).forEach(i=>{if(i.startsWith("`")&&i.endsWith("`")){const l=document.createElement("code");l.textContent=i.slice(1,-1),w.appendChild(l)}else w.appendChild(document.createTextNode(i))}):n.message&&(w.textContent=String(n.message)),f.appendChild(w),Array.isArray(n.actions)&&n.actions.length){const i=document.createElement("div");i.className="jt-actions",n.actions.forEach(l=>{const N=document.createElement("button");N.className="jt-action",N.textContent=l.label||"Action",N.onclick=ce=>{var ue;ce.stopPropagation(),(ue=l.onClick)==null||ue.call(l,ce),l.closeOnClick&&C()},i.appendChild(N)}),f.appendChild(i)}let p=null;if(n.icon){if(p=document.createElement("i"),p.className=["icon",n.iconPack||"",n.icon].join(" ").trim(),n.iconSize&&(p.style.fontSize=n.iconSize),!fe){const i=n.iconAnim||_e[t];i&&p.classList.add(i)}(n.iconLink||n.iconAnimate)&&(p.classList.add("icon-clickable"),p.addEventListener("click",i=>{i.stopPropagation(),n.iconAnimate&&(p.classList.remove(n.iconAnimate),p.offsetWidth,p.classList.add(n.iconAnimate)),n.iconLink&&window.open(n.iconLink,"_blank","noopener")}))}let d=null;if(n.avatar){d=document.createElement("img");const i=typeof n.avatar=="string"&&n.avatar?n.avatar:n.avatarSrc||"";i&&(d.src=i),d.alt=n.avatarAlt||n.title||"avatar",d.className="jt-avatar",d.loading=n.avatarLazy?"lazy":"eager",d.style.width=d.style.width||"36px",d.style.height=d.style.height||"36px",d.style.borderRadius=d.style.borderRadius||"50%",d.style.objectFit=d.style.objectFit||"cover",d.style.flexShrink="0";const l=n.avatarPosition||"left";l==="left"?d.style.marginRight=(P=n.avatarSpacing)!=null?P:"10px":l==="right"?d.style.marginLeft=(te=n.avatarSpacing)!=null?te:"10px":l==="top"&&(d.style.marginBottom=(ne=n.avatarSpacing)!=null?ne:"8px")}const V=n.avatarPosition||"left";d&&V==="top"?(s.classList.add("jt-avatar-top"),s.style.flexDirection="column",s.style.alignItems="flex-start",s.appendChild(d),p&&n.iconPosition==="top"?(s.appendChild(p),s.appendChild(f)):p&&n.iconPosition==="right"?(s.appendChild(f),s.appendChild(p)):(p&&s.appendChild(p),s.appendChild(f))):(s.style.flexDirection="row",s.style.alignItems="center",d&&V==="left"&&s.appendChild(d),p&&n.iconPosition==="right"?(s.appendChild(f),s.appendChild(p)):p&&n.iconPosition==="top"?(s.classList.add("jt-icon-top"),s.appendChild(p),s.appendChild(f)):(p&&s.appendChild(p),s.appendChild(f)),d&&V==="right"&&s.appendChild(d));let E=null;if(n.progress&&((oe=n.duration)!=null?oe:this._defaults.duration)>0&&(E=document.createElement("div"),E.className="jt-progress",n.progressColor&&(E.style.background=n.progressColor),s.appendChild(E)),n.undo){const i=document.createElement("button");i.className="jt-action",i.textContent="Undo",i.onclick=()=>{try{n.undo()}catch(l){}C()},f.appendChild(i)}if(n.closable){const i=document.createElement("span");i.className="juice-toast-close",i.tabIndex=0,i.textContent="\xD7",i.addEventListener("click",l=>{l.stopPropagation(),C()}),s.appendChild(i)}const v=this._getRoot(n.position||"bottom-right");if(!v)return;if(n.groupId){const i=Array.from(v.children).find(l=>l.dataset.groupId===n.groupId);if(i){let l=i.querySelector(".jt-count");l||(l=document.createElement("span"),l.className="jt-count",l.style.marginLeft="6px",(se=i.querySelector(".jt-title"))==null||se.appendChild(l),l.textContent="1"),l.textContent=String(parseInt(l.textContent||"1")+1);return}s.dataset.groupId=n.groupId}const re=this._defaults.maxVisible;re&&v.children.length>=re&&v.removeChild(v.firstElementChild),v.appendChild(s);const a={id:b,toast:s,cfg:n,createdAt:g(),remaining:(ie=n.duration)!=null?ie:this._defaults.duration,raf:null,timer:null,start:g(),paused:!1,_boundMove:null,_boundUp:null};this._activeMap.set(b,a),this._runPlugins({toast:s,cfg:n,type:t,root:v}),this._updateStackPositionsFor(v),requestAnimationFrame(()=>s.classList.add("show"));let W=0,$=0,k=0,T=0,H=!1;const q=i=>{const l=i.touches?i.touches[0]:i;W=l.clientX,$=l.clientY,H=!0,a.paused=!0,a.raf&&(cancelAnimationFrame(a.raf),a.raf=null),s.style.transition="none",a._boundMove=je,a._boundUp=we,document.addEventListener("touchmove",a._boundMove,{passive:!0}),document.addEventListener("mousemove",a._boundMove),document.addEventListener("touchend",a._boundUp),document.addEventListener("mouseup",a._boundUp)},je=i=>{if(!H)return;const l=i.touches?i.touches[0]:i;k=l.clientX-W,T=l.clientY-$,Math.abs(k)>Math.abs(T)?s.style.transform=`translateX(${k}px)`:s.style.transform=`translateY(${T}px)`},we=()=>{H=!1,a.paused=!1,s.style.transition="",Math.abs(k)>(this._defaults.swipeThreshold||60)?(s.style.transform=`translateX(${k>0?1e3:-1e3}px)`,setTimeout(C,220)):s.style.transform="",W=$=k=T=0,a._boundMove&&(document.removeEventListener("touchmove",a._boundMove,{passive:!0}),document.removeEventListener("mousemove",a._boundMove),a._boundMove=null),a._boundUp&&(document.removeEventListener("touchend",a._boundUp),document.removeEventListener("mouseup",a._boundUp),a._boundUp=null),J()};s.addEventListener("touchstart",q,{passive:!0}),s.addEventListener("mousedown",q);const A=()=>{a.paused=!0,a.raf&&(cancelAnimationFrame(a.raf),a.raf=null)},I=()=>{a.paused&&(a.paused=!1,a.start=g(),J())};s.addEventListener("mouseenter",A),s.addEventListener("mouseleave",I),s.addEventListener("focusin",A),s.addEventListener("focusout",I);const z=(ae=n.duration)!=null?ae:this._defaults.duration;function le(){if(!y._activeMap.has(b))return;if(a.paused){a.raf=null,a.start=g();return}const i=g()-a.start;if(a.remaining-=i,a.start=g(),E){const l=Math.max(0,a.remaining/z);E.style.transform=`scaleX(${l})`}if(a.remaining<=0){s.classList.remove("show"),setTimeout(C,280),a.raf=null;return}a.raf=requestAnimationFrame(le)}function J(){z<=0||a.raf||a.paused||(a.start=g(),a.raf=requestAnimationFrame(le))}z>0&&(a.start=g(),a.remaining=z,J());function C(){if(!y._activeMap.has(b))return;s.classList.add("hide"),s.removeEventListener("touchstart",q),s.removeEventListener("mousedown",q),a._boundMove&&(document.removeEventListener("touchmove",a._boundMove,{passive:!0}),document.removeEventListener("mousemove",a._boundMove),a._boundMove=null),a._boundUp&&(document.removeEventListener("touchend",a._boundUp),document.removeEventListener("mouseup",a._boundUp),a._boundUp=null),s.removeEventListener("mouseenter",A),s.removeEventListener("mouseleave",I),s.removeEventListener("focusin",A),s.removeEventListener("focusout",I);const i=y._activeMap.get(b);i!=null&&i.raf&&(cancelAnimationFrame(i.raf),i.raf=null),i!=null&&i.timer&&(clearTimeout(i.timer),i.timer=null),y._activeMap.delete(b);const l=s.parentNode;l&&l.removeChild(s),l&&y._updateStackPositionsFor(l)}return n.undoTimeout&&(a.timer=setTimeout(C,n.undoTimeout)),(n.playSound||this._defaults.playSound)&&this._playSound(n.playSound||this._defaults.playSound),b},_priorityMap:{low:1,normal:2,high:3,urgent:4}};function be(t,e){return t?typeof t=="string"?{message:e}:t:{message:e}}function ee(t,e,o){return t?typeof t=="function"?{message:t(e)}:typeof t=="string"?{message:t}:t:{message:o}}y.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}}),x.default=y,x.juiceToast=y,Object.defineProperty(x,"__esModule",{value:!0})}));
|
|
25
|
+
//# sourceMappingURL=juice-toast.umd.js.map
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juice-toast",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.1",
|
|
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
|
-
"
|
|
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"
|
|
13
19
|
],
|
|
14
20
|
"license": "MIT",
|
|
15
21
|
"author": "KhairyK",
|
|
@@ -59,10 +65,9 @@
|
|
|
59
65
|
"unpkg": "dist/juice-toast.esm.js",
|
|
60
66
|
"jsdelivr": "dist/juice-toast.esm.js",
|
|
61
67
|
"devDependencies": {
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
"react-dom": "^19.2.4"
|
|
68
|
+
"esbuild": "^0.27.3",
|
|
69
|
+
"prettier": "^3.8.1",
|
|
70
|
+
"rollup": "^4.59.0",
|
|
71
|
+
"rollup-plugin-esbuild": "^6.2.1"
|
|
67
72
|
}
|
|
68
73
|
}
|
|
@@ -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};
|