juice-toast 1.3.3 → 1.3.4-alpha.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 +14 -2
- package/EoL.md +4 -1
- package/dist/juice-toast.esm.js +22 -327
- package/dist/juice-toast.ios.js +42 -3
- package/dist/juice-toast.umd.js +16 -0
- package/package.json +1 -1
- package/dist/juice-toast-ios.d.ts +0 -160
- package/dist/juice-toast.d.ts +0 -120
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
## v1.
|
|
1
|
+
## v1.4.0
|
|
2
|
+
- Add Smart Queue
|
|
3
|
+
- Bugs fixed & Logic fixes
|
|
4
|
+
- Add Promise
|
|
5
|
+
- Add Universal Module Definition (UMD) Back
|
|
6
|
+
- !**Removing `.d.ts`**! (Will be added on 5 March)
|
|
7
|
+
|
|
8
|
+
v1.3.4
|
|
9
|
+
- Bug Fixes
|
|
10
|
+
- Add profile image
|
|
11
|
+
|
|
12
|
+
v1.3.3
|
|
2
13
|
- Bug Fixes on Closeable Toast & Logic
|
|
3
14
|
|
|
4
15
|
v1.3.2
|
|
5
16
|
- Improved A11Y
|
|
6
17
|
- Adding Background Image
|
|
7
18
|
- Adding more Theme
|
|
8
|
-
- Adding default toast (juiceToast.success|error|info|warning
|
|
19
|
+
- Adding default toast (juiceToast.success|error|info|warning)
|
|
9
20
|
|
|
10
21
|
v1.3.1
|
|
11
22
|
- Improved iOS / Safari (WebKit) compatibility
|
|
@@ -39,6 +50,7 @@ NEXT 120/2026
|
|
|
39
50
|
- Add Promise-based Toast API
|
|
40
51
|
- Add Stack Grouping
|
|
41
52
|
- Improve TypeScript Definitions
|
|
53
|
+
- !Remove UMD due to maintance reason!
|
|
42
54
|
|
|
43
55
|
v1.1.0
|
|
44
56
|
- Add Size Preset
|
package/EoL.md
CHANGED
|
@@ -4,6 +4,9 @@ The following versions and distributions have reached End of Life (EoL) and are
|
|
|
4
4
|
|
|
5
5
|
| EoL Version | Affected Target | Reason |
|
|
6
6
|
|--------------------|-----------------|--------|
|
|
7
|
+
| 1.2.1 | None | This version is End of Support, update to ^1.3.0 |
|
|
7
8
|
| 1.2.0-rc.2026 | UMD build | UMD distribution has been removed to simplify maintenance and reduce build complexity |
|
|
9
|
+
| 0.0.1-next.1202026 | None | This next version are ended, use Release Candidate version |
|
|
8
10
|
| 0.0.0-next.1202026 | Pre-release tag | Versioning structure became inconsistent and difficult to maintain |
|
|
9
|
-
| 1.
|
|
11
|
+
| 1.1.0 | None | This version is End of Support, update to ^1.2.0 |
|
|
12
|
+
| 1.0.0 | Unstable release | Deprecated due to outdated internal architecture and styling standards |
|
package/dist/juice-toast.esm.js
CHANGED
|
@@ -1,331 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 2026 (C) OpenDN Foundation
|
|
3
|
-
* v1.3.
|
|
3
|
+
* v1.3.4 (Nearing End of Support notifier)
|
|
4
4
|
* ESM (ECMAScript Module)
|
|
5
5
|
*/
|
|
6
|
-
let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMotion=isBrowser&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,
|
|
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
|
-
/* ================= COMPACT ================= */
|
|
188
|
-
|
|
189
|
-
.jt-compact {
|
|
190
|
-
padding: 6px 8px;
|
|
191
|
-
font-size: 0.85em;
|
|
192
|
-
gap: 6px;
|
|
193
|
-
max-width: 280px;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/* ================= GLASS UI ================= */
|
|
197
|
-
|
|
198
|
-
.jt-glass {
|
|
199
|
-
--g: calc(var(--jt-glass, 60) / 100);
|
|
200
|
-
|
|
201
|
-
background: rgba(30, 30, 30, calc(0.2 + var(--g)));
|
|
202
|
-
backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
203
|
-
saturate(calc(1 + (0.4 * var(--g))));
|
|
204
|
-
-webkit-backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
205
|
-
saturate(calc(1 + (0.4 * var(--g))));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/* light theme support */
|
|
209
|
-
[data-theme="light"] .jt-glass {
|
|
210
|
-
background:
|
|
211
|
-
linear-gradient(
|
|
212
|
-
rgba(255,255,255, calc(0.6 * var(--g))),
|
|
213
|
-
rgba(255,255,255, calc(0.35 * var(--g)))
|
|
214
|
-
),
|
|
215
|
-
rgba(255,255,255, calc(0.55 - (0.25 * var(--g))));
|
|
216
|
-
|
|
217
|
-
color: #111;
|
|
218
|
-
|
|
219
|
-
border:
|
|
220
|
-
1px solid rgba(0,0,0, calc(0.05 + 0.12 * var(--g)));
|
|
221
|
-
|
|
222
|
-
box-shadow:
|
|
223
|
-
0 10px 30px rgba(0,0,0, calc(0.08 + 0.18 * var(--g))),
|
|
224
|
-
inset 0 1px 0 rgba(255,255,255, calc(0.4 * var(--g)));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/* ================= PROGRESS BAR ================= */
|
|
228
|
-
.jt-progress {
|
|
229
|
-
position: absolute;
|
|
230
|
-
left: 0;
|
|
231
|
-
bottom: 0;
|
|
232
|
-
|
|
233
|
-
height: 3px;
|
|
234
|
-
width: 100%;
|
|
235
|
-
|
|
236
|
-
background: linear-gradient(to right, #FFFFFF, #FAFAFA);
|
|
237
|
-
height: 4px;
|
|
238
|
-
transform-origin: left;
|
|
239
|
-
transition: transform linear;
|
|
240
|
-
border-radius: 2px;
|
|
241
|
-
transform: scaleX(1);
|
|
242
|
-
opacity: .85;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/* ================= BACKGROUND IMAGE ================= */
|
|
246
|
-
|
|
247
|
-
.juice-toast.bg-image {
|
|
248
|
-
background-size: cover;
|
|
249
|
-
background-position: center;
|
|
250
|
-
background-repeat: no-repeat;
|
|
251
|
-
color: #fff;
|
|
252
|
-
text-shadow: 0 1px 2px rgba(0,0,0,0.6);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/* ================= ANIMATIONS ================= */
|
|
256
|
-
|
|
257
|
-
@keyframes jt-spin {
|
|
258
|
-
to { transform: rotate(360deg); }
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
@keyframes jt-pulse {
|
|
262
|
-
50% { transform: scale(1.15); }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
@keyframes jt-shake {
|
|
266
|
-
25% { transform: translateX(-3px); }
|
|
267
|
-
50% { transform: translateX(3px); }
|
|
268
|
-
75% { transform: translateX(-3px); }
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
@keyframes jt-bounce {
|
|
272
|
-
0% { transform: scale(1); }
|
|
273
|
-
30% { transform: scale(1.25); }
|
|
274
|
-
60% { transform: scale(.95); }
|
|
275
|
-
100% { transform: scale(1); }
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
@keyframes jt-wiggle {
|
|
279
|
-
0% { transform: rotate(0); }
|
|
280
|
-
25% { transform: rotate(-10deg); }
|
|
281
|
-
50% { transform: rotate(10deg); }
|
|
282
|
-
75% { transform: rotate(-6deg); }
|
|
283
|
-
100% { transform: rotate(0); }
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
@keyframes jt-pop {
|
|
287
|
-
0% { transform: scale(.7); opacity: 0; }
|
|
288
|
-
70% { transform: scale(1.05); opacity: 1; }
|
|
289
|
-
100% { transform: scale(1); }
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
@keyframes jt-slide {
|
|
293
|
-
from { transform: translateY(20 px);opacity: 0; }
|
|
294
|
-
to { transform: translateY(0);opacity: 1; }
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/* ================= CLASSES ================= */
|
|
298
|
-
|
|
299
|
-
.spin { animation: jt-spin .6s linear; }
|
|
300
|
-
.pulse { animation: jt-pulse .4s ease; }
|
|
301
|
-
.shake { animation: jt-shake .4s ease; }
|
|
302
|
-
.bounce { animation: jt-bounce .45s ease; }
|
|
303
|
-
.wiggle { animation: jt-wiggle .5s ease; }
|
|
304
|
-
.pop { animation: jt-pop .35s ease-out; }
|
|
305
|
-
.slide-in { animation: jt-slide .55s ease; }
|
|
306
|
-
|
|
307
|
-
/* ================= ICON INTERACTION ================= */
|
|
308
|
-
|
|
309
|
-
.icon-clickable {
|
|
310
|
-
cursor: pointer;
|
|
311
|
-
transition: transform .15s ease, opacity .15s ease;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
.icon-clickable:hover {
|
|
315
|
-
transform: scale(1.1);
|
|
316
|
-
opacity: .85;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
/* ================= ACCESSIBILITY ================= */
|
|
320
|
-
|
|
321
|
-
@media (prefers-reduced-motion: reduce) {
|
|
322
|
-
.spin,
|
|
323
|
-
.pulse,
|
|
324
|
-
.shake,
|
|
325
|
-
.bounce,
|
|
326
|
-
.wiggle,
|
|
327
|
-
.pop {
|
|
328
|
-
animation: none !important;
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
`;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=a,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]||{},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.tabIndex=0,l.className="juice-toast-close",l.textContent="\xd7",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;if(i.progress&&(i.duration??this._defaults.duration)>0&&((d=document.createElement("div")).className="jt-progress",i.progressColor&&(d.style.background=i.progressColor||"rgba(255,255,255,.7)"),n.appendChild(d)),i.tts&&"speechSynthesis"in window)try{let p=new SpeechSynthesisUtterance(i.message||i.title||"");p.lang=i.ttsLang||"en-US",p.rate=i.ttsRate??1,window.speechSynthesis.speak(p)}catch(f){this._warn("TTS failed: "+f.message)}let g=this._normalizeGlass(i.glassUI??this._defaults.glassUI);g>0&&(n.style.setProperty("--jt-glass",i.glassUI??50),n.classList.add("jt-glass")),g||(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 u=null;if(i.icon){(u=document.createElement("i")).className=["icon",i.iconPack||"",i.icon].join(" ").trim(),i.iconSize&&(u.style.fontSize=i.iconSize),(i.iconLink||i.iconAnimate)&&(u.classList.add("icon-clickable"),u.onclick=e=>{e.stopPropagation(),i.iconAnimate&&(u.classList.remove(i.iconAnimate),u.offsetWidth,u.classList.add(i.iconAnimate)),i.iconLink&&window.open(i.iconLink,"_blank","noopener")});let m=i.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")),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 h=0,$=0;n.addEventListener("touchstart",e=>{h=e.touches[0].clientX}),n.addEventListener("touchmove",e=>{$=e.touches[0].clientX-h,n.style.transform=`translateX(${$}px)`}),n.addEventListener("touchend",()=>{Math.abs($)>this._defaults.swipeThreshold?(n.style.transform=`translateX(${$>0?1e3:-1e3}px)`,setTimeout(()=>{n.remove(),this._next()},200)):n.style.transform="",h=$=0});let x=document.createElement("div");x.className="jt-content";let b=i.enterAnimation??"pop";if(b&&!reduceMotion&&n.classList.add(b),i.title){let y=document.createElement("div");y.className="jt-title",y.textContent=i.title,x.appendChild(y)}let _=document.createElement("div");if(_.className="jt-message",_.textContent=i.message||"",x.appendChild(_),u&&"top"===i.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(u),n.appendChild(x)):u&&"right"===i.iconPosition?(n.appendChild(x),n.appendChild(u)):(u&&n.appendChild(u),n.appendChild(x)),Array.isArray(i.actions)&&i.actions.length){let j=document.createElement("div");j.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.remove(),this._next())},j.appendChild(t)}),x.appendChild(j)}if(i.closable){let k=document.createElement("span");k.className="juice-toast-close",k.textContent="\xd7",k.onclick=()=>{n.remove(),this._next()},n.appendChild(k)}let w=this._getRoot(i.position),v=this._defaults.maxVisible;v&&w.children.length>=v&&w.firstChild.remove(),w.appendChild(n),this._runPlugins({toast:n,cfg:i,type:e,root:w}),requestAnimationFrame(()=>n.classList.add("show"));let C=i.duration??this._defaults.duration;if(0===C)return;let E=Date.now(),S=i.duration??this._defaults.duration,A,I=()=>{if(n.__paused)E=Date.now();else{let e=Date.now();S-=e-E,E=e}S<=0?(n.classList.remove("show"),setTimeout(()=>{n.remove(),this._next()},300)):A=requestAnimationFrame(I),d&&(d.style.transform=`scaleX(${Math.max(0,S/C)})`)};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(I)}};juiceToast.setup({success:{icon:"fa-check",iconPack:"fas",bg:"#16a34a",progress:!0,duration:3e3},error:{icon:"fa-xmark",iconPack:"fas",bg:"#dc2626",progress:!0,duration:4e3},info:{icon:"fa-circle-info",iconPack:"fas",bg:"#2563eb",progress:!0},warning:{icon:"fa-triangle-exclamation",iconPack:"fas",bg:"#f59e0b",progress:!0},loading:{icon:"fa-spinner",iconPack:"fas",iconAnimate:"spin",duration:0,progress:!1,closable:!1}});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};
|
package/dist/juice-toast.ios.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OpenDN Foundation (C) 2026
|
|
3
|
-
*
|
|
3
|
+
* Juice Toast v1.4.0 (iOS user | Nearing End of Support notifier)
|
|
4
4
|
* Read CONTRIBUTE.md To Contribute
|
|
5
5
|
*/
|
|
6
|
-
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
|
|
6
|
+
let dev=!0;dev&&console.warn("Warning: You are using JuiceToast v1.4.0 for iOS, On v1.4.3 JuiceToast iOS will be removed.");let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMotion=isBrowser&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,isTouch=isBrowser&&("ontouchstart"in window||navigator&&navigator.maxTouchPoints>0),isIOS=isBrowser&&/iPad|iPhone|iPod/.test(navigator.userAgent||""),isIOSStandalone=isBrowser&&(!0===window.navigator.standalone||window.matchMedia&&window.matchMedia("(display-mode: standalone)").matches);function speakTTS(e,t="en-US",s=1){if(!("speechSynthesis"in window))return;let i=new SpeechSynthesisUtterance(e);i.lang=t,i.rate=s;let a=()=>{window.speechSynthesis.speak(i),document.body.removeEventListener("touchstart",a),document.body.removeEventListener("click",a)},o=/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;o&&!1===window.speechSynthesis.speaking?(document.body.addEventListener("touchstart",a,{once:!0}),document.body.addEventListener("click",a,{once:!0})):a()}function normalizeState(e,t){return e?"string"==typeof e?{message:e}:e:{message:t}}function resolveState(e,t,s){return e?"function"==typeof e?{message:e(t)}:"string"==typeof e?{message:e}:e:{message:s}}let raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||(e=>setTimeout(e,16)),TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"},__cssInjected=!1,BASE_CSS=`
|
|
7
7
|
:root {
|
|
8
8
|
--jt-safe-top: env(safe-area-inset-top, 0px);
|
|
9
9
|
--jt-safe-bottom: env(safe-area-inset-bottom, 0px);
|
|
@@ -122,6 +122,15 @@ let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMot
|
|
|
122
122
|
opacity: 1;
|
|
123
123
|
}
|
|
124
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
|
+
|
|
125
134
|
/* ================= CONTENT ================= */
|
|
126
135
|
|
|
127
136
|
.juice-toast .jt-content {
|
|
@@ -294,6 +303,15 @@ let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMot
|
|
|
294
303
|
100% { transform: scale(1); }
|
|
295
304
|
}
|
|
296
305
|
|
|
306
|
+
@keyframes jt-spin {
|
|
307
|
+
from {
|
|
308
|
+
transform: rotate(0deg);
|
|
309
|
+
}
|
|
310
|
+
to {
|
|
311
|
+
transform: rotate(360deg);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
297
315
|
/* ================= CLASSES ================= */
|
|
298
316
|
|
|
299
317
|
.spin { animation: jt-spin .6s linear; }
|
|
@@ -302,6 +320,9 @@ let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMot
|
|
|
302
320
|
.bounce { animation: jt-bounce .45s ease; }
|
|
303
321
|
.wiggle { animation: jt-wiggle .5s ease; }
|
|
304
322
|
.pop { animation: jt-pop .35s ease-out; }
|
|
323
|
+
.spin {
|
|
324
|
+
animation: jt - spin 1 s linear infinite;
|
|
325
|
+
}
|
|
305
326
|
|
|
306
327
|
.icon-clickable {
|
|
307
328
|
cursor: pointer;
|
|
@@ -325,4 +346,22 @@ let isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMot
|
|
|
325
346
|
animation: none !important;
|
|
326
347
|
}
|
|
327
348
|
}
|
|
328
|
-
`;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=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,p=i.duration??this._defaults.duration;i.progress&&p>0&&((d=document.createElement("div")).className="jt-progress",i.progressColor&&(d.style.background=i.progressColor||"rgba(255,255,255,.7)"),n.appendChild(d)),i.tts&&i.message&&speakTTS(i.message,i.ttsLang??"en-US",i.ttsRate??1);let u=this._normalizeGlass(i.glassUI??this._defaults.glassUI);u>0&&(n.style.setProperty("--jt-glass",i.glassUI??50),n.classList.add("jt-glass")),u||(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 f=null;if(i.icon){(f=document.createElement("i")).className=["icon",i.iconPack||"",i.icon].join(" ").trim(),i.iconSize&&(f.style.fontSize=i.iconSize),(i.iconLink||i.iconAnimate)&&(f.classList.add("icon-clickable"),f.onclick=e=>{e.stopPropagation(),i.iconAnimate&&(f.classList.remove(i.iconAnimate),f.offsetWidth,f.classList.add(i.iconAnimate)),i.iconLink&&window.open(i.iconLink,"_blank","noopener")});let m=i.iconAnimate??TYPE_ANIMATION[e];m&&(f.classList.add(m),f.addEventListener("click",()=>{f.classList.remove(m),f.offsetWidth,f.classList.add(m)}))}reduceMotion&&(n.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),f?.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 h=0,g=0,$=!1,b=e=>{let t=e.touches?e.touches[0]:e;h=t.clientX,g=0,$=!0,n.__paused=!0},x=e=>{if(!$)return;let t=e.touches?e.touches[0]:e;g=t.clientX-h,n.style.transform=`translate3d(${g}px, 0, 0)`},y=()=>{$&&($=!1,Math.abs(g)>(this._defaults.swipeThreshold||60)?(n.style.transition="transform .25s ease, opacity .2s ease",n.style.transform=`translate3d(${g>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),h=g=0)};isTouch?(n.addEventListener("touchstart",b,{passive:!0}),n.addEventListener("touchmove",x,{passive:!0}),n.addEventListener("touchend",y),n.addEventListener("touchcancel",y)):n.addEventListener("mousedown",e=>{h=e.clientX,g=0,$=!0,n.__paused=!0;let t=e=>{g=e.clientX-h,n.style.transform=`translate3d(${g}px, 0, 0)`},s=()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",s),y()};document.addEventListener("mousemove",t),document.addEventListener("mouseup",s)});let _=document.createElement("div");_.className="jt-content";let v=i.enterAnimation??"pop";if(v&&!reduceMotion&&n.classList.add(v),i.title){let k=document.createElement("div");k.className="jt-title",k.textContent=i.title,_.appendChild(k)}let w=document.createElement("div");if(w.className="jt-message",w.textContent=i.message||"",_.appendChild(w),f&&"top"===i.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(f),n.appendChild(_)):f&&"right"===i.iconPosition?(n.appendChild(_),n.appendChild(f)):(f&&n.appendChild(f),n.appendChild(_)),Array.isArray(i.actions)&&i.actions.length){let j=document.createElement("div");j.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())},j.appendChild(t)}),_.appendChild(j)}if(i.closable){let S=document.createElement("span");S.className="juice-toast-close",S.textContent="\xd7",S.onclick=()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},n.appendChild(S)}isIOSStandalone&&(n.style.borderRadius=n.style.borderRadius||"14px");let E=this._getRoot(i.position),L=this._defaults.maxVisible;if(L&&E.children.length>=L&&E.firstChild.remove(),E.appendChild(n),this._runPlugins({toast:n,cfg:i,type:e,root:E}),requestAnimationFrame(()=>{n.classList.add("show")}),0===p)return;let C=Date.now(),I=p,T=()=>{if(n.__paused)C=Date.now();else{let e=Date.now();I-=e-C,C=e}if(I<=0?(n.classList.remove("show"),setTimeout(()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},300)):raf(T),d){let t=Math.max(0,Math.min(1,I/p));d.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}),C=Date.now(),raf(T),(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};
|
|
349
|
+
|
|
350
|
+
.jt-profile {
|
|
351
|
+
width: 40px;
|
|
352
|
+
height: 40px;
|
|
353
|
+
border-radius: 50%;
|
|
354
|
+
object-fit: cover;
|
|
355
|
+
flex-shrink: 0;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.jt-profile.square {
|
|
359
|
+
border-radius: 8px;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.juice-toast {
|
|
363
|
+
display: flex;
|
|
364
|
+
align-items: center;
|
|
365
|
+
gap: 10px;
|
|
366
|
+
}
|
|
367
|
+
`;function injectCSS(e){if(!isBrowser||__cssInjected)return;let t=document.createElement("style");t.id="juice-toast-style",t.textContent=e,document.head.appendChild(t),__cssInjected=!0}function sanitizeHTML(e){let t=document.createElement("template");t.innerHTML=e,t.content.querySelectorAll("script, [onload], [onclick], [onerror]").forEach(e=>e.remove());let s=["b","i","u","strong","em","code","pre","ul","ol","li","br","p","span","img","h1","h2","h3","h4","h5","h6"],i=e=>{e.childNodes.forEach(e=>{1===e.nodeType&&(s.includes(e.tagName.toLowerCase())?i(e):e.replaceWith(...e.childNodes))})};return i(t.content),t.innerHTML}let themes={light:{bg:"#ffffff",color:"#111",border:"1px solid #e5e7eb"},dark:{bg:"#1f2937",color:"#fff",border:"1px solid rgba(255,255,255,.08)"},glass:{bg:"rgba(30,30,30,.35)",color:"#fff",border:"1px solid rgba(255,255,255,.15)"},midnight:{bg:"#0f172a",color:"#e5e7eb",border:"1px solid rgba(255,255,255,.06)"},soft:{bg:"#f8fafc",color:"#0f172a",border:"1px solid #e2e8f0"},neutral:{bg:"#ffffff",color:"#374151",border:"1px solid #d1d5db"},brand:{bg:"#6366f1",color:"#fff",border:"none"},gradient:{bg:"linear-gradient(135deg,#6366f1,#ec4899)",color:"#fff",border:"none"},outline:{bg:"transparent",color:"#111",border:"2px solid currentColor"}},sizePreset={sm:{width:"260px",padding:"10px"},md:{width:"320px",padding:"14px"},lg:{width:"420px",padding:"18px"}},juiceToast={_config:{},_queue:[],_showing:!1,_theme:"dark",_plugins:[],_activePromises:new Map,setup(e={}){let{duration:t,maxVisible:s,...i}=e;this._defaults={...this._defaults,duration:t,maxVisible:s},this._config={...this._config,...i},isIOS&&(this._defaults.swipeThreshold=Math.min(this._defaults.swipeThreshold||60,50),this._defaults.glassUI=this._defaults.glassUI||60,this._defaults.duration=this._defaults.duration??2200),this._registerTypes()},use(e){"function"==typeof e&&this._plugins.push(e)},addType(e,t={}){this._config[e]=t,this._registerTypes()},defineTheme(e,t={}){themes[e]={...themes[e]||{},...t}},setTheme(e){if(this._theme=e,!isBrowser)return;let t=document.querySelector('[id^="juice-toast-root-"]');t&&(t.dataset.theme=e)},clear(){this._queue.length=0},destroy(){if(this.clear(),!isBrowser)return;let e=document.querySelectorAll('[id^="juice-toast-root-"]');e.forEach(e=>e.remove())},promise(e,t={}){if(!e||"function"!=typeof e.then){this._warn("promise() expects a Promise");return}let s="jt-promise-"+Date.now(),i={cancelled:!1,timer:null};return this._activePromises.set(s,i),this._enqueue("loading",{...normalizeState(t.loading,"Loading..."),groupId:s,duration:0}),t.timeout&&(i.timer=setTimeout(()=>{i.cancelled||(i.cancelled=!0,this._enqueue("error",{message:t.timeoutMessage||"Request timeout",groupId:s}),this._activePromises.delete(s))},t.timeout)),e.then(e=>{i.cancelled||(clearTimeout(i.timer),this._enqueue("success",{...resolveState(t.success,e,"Success"),groupId:s}),this._activePromises.delete(s))}).catch(e=>{i.cancelled||(clearTimeout(i.timer),this._enqueue("error",{...resolveState(t.error,e,"Error"),groupId:s}),this._activePromises.delete(s))}),{cancel:()=>{this._activePromises.has(s)&&(i.cancelled=!0,clearTimeout(i.timer),this._enqueue("info",{message:t.cancelMessage||"Cancelled",groupId:s}),this._activePromises.delete(s))}}},_registerTypes(){Object.keys(this._config).forEach(e=>{if("function"==typeof this[e]&&!this[e].__auto)return;let t=t=>this._enqueue(e,t);t.__auto=!0,this[e]=t})},_enqueue(e,t){this._queue.push({type:e,payload:t}),this._showing||this._next()},_next(){if(!this._queue.length){this._showing=!1;return}this._showing=!0;let e=this._queue.shift();this._showToast(e.type,e.payload)},_runPlugins(e){this._plugins.forEach(t=>{try{t(e)}catch(s){this._warn("Plugin error: "+(s&&s.message?s.message:String(s)))}})},_normalizeGlass(e){if(!0===e)return 60;if(!1===e||null==e)return 0;let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(100,t)):0},_getRoot(e="bottom-right"){if(!isBrowser)return null;let t=document.getElementById(`juice-toast-root-${e}`);if(!t){switch((t=document.createElement("div")).id=`juice-toast-root-${e}`,t.dataset.position=e,t.dataset.theme=this._theme,t.style.position="fixed",t.style.zIndex=9999,t.style.display="flex",t.style.flexDirection="column",t.style.gap="8px",t.style.pointerEvents="none",e){case"top-left":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.left="20px",t.style.alignItems="flex-start";break;case"top-right":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.right="20px",t.style.alignItems="flex-end";break;case"bottom-left":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.left="20px",t.style.alignItems="flex-start";break;case"bottom-right":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.right="20px",t.style.alignItems="flex-end";break;case"top-center":t.style.top="calc(20px + env(safe-area-inset-top))",t.style.left="50%",t.style.transform="translateX(-50%)",t.style.alignItems="center";break;case"bottom-center":t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.left="50%",t.style.transform="translateX(-50%)",t.style.alignItems="center";break;default:t.style.bottom="calc(20px + env(safe-area-inset-bottom))",t.style.right="20px"}document.body.appendChild(t)}return t},_defaults:{duration:2500,maxVisible:3,swipeThreshold:60,glassUI:0,playSound:null,dev:!1,injectCSS:!0,css:null},_warn(e){this._defaults.dev&&"undefined"!=typeof console&&console.warn("[JuiceToast]",e)},_playSound(e){if(!isBrowser)return;let t="string"==typeof e&&e?e:this._defaults.playSound;if(t)try{let s=new Audio(t);s.volume=.6;let i=()=>{s.play().catch(()=>{}),window.removeEventListener("touchstart",i),window.removeEventListener("click",i)};s.play().catch(()=>{window.addEventListener("touchstart",i,{once:!0}),window.addEventListener("click",i,{once:!0})})}catch(a){}},_showToast(e,t){if(!isBrowser)return;!1!==this._defaults.injectCSS&&injectCSS(this._defaults.css||BASE_CSS);let s=this._config[e]||{},i="object"==typeof t?t:{message:String(t)},a={...s,...i};a.icon=a.icon??a.icon_left_top,a.iconPack=a.iconPack??a.icon_config,a.iconLink=a.iconLink??a.icon_onClick_url,a.iconAnimate=a.iconAnimate??a.icon_onClick_animate,a.position=a.position??a.toast,a.closable=a.closable??a.closeable,a.iconPosition=a.iconPosition||"left",a.compact=!!a.compact;let o=themes[a.theme||this._theme]||{},n=document.createElement("div");n.className="juice-toast";let r=a.animation||"slide-in";if(a.enterAnimation||(n.style.animation=`${r} 0.4s ease forwards`),n.setAttribute("role","alert"),n.setAttribute("aria-live","error"===e?"assertive":"polite"),n.setAttribute("aria-atomic","true"),n.tabIndex=0,a.closable){let l=document.createElement("span");l.className="juice-toast-close",l.textContent="\xd7",l.tabIndex=0,l.addEventListener("keydown",e=>{("Enter"===e.key||" "===e.key)&&(n.remove(),this._next())})}if(a.size&&sizePreset[a.size]){let c=sizePreset[a.size];c.width&&(n.style.width=c.width),c.padding&&(n.style.padding=c.padding)}let d=null;a.profile&&((d=document.createElement("img")).src=a.profile,d.className="jt-profile","square"===a.profileShape&&d.classList.add("square"),n.appendChild(d));let p=null,u=a.duration??this._defaults.duration;a.progress&&u>0&&((p=document.createElement("div")).className="jt-progress",a.progressColor&&(p.style.background=a.progressColor||"rgba(255,255,255,.7)"),n.appendChild(p)),a.tts&&a.message&&speakTTS(a.message,a.ttsLang??"en-US",a.ttsRate??1);let m=this._normalizeGlass(a.glassUI??this._defaults.glassUI);m>0&&(n.style.setProperty("--jt-glass",a.glassUI??50),n.classList.add("jt-glass")),m||(n.style.background=a.bg||o.bg),n.style.color=a.color||o.color,n.style.border=a.border||o.border,a.compact&&n.classList.add("jt-compact"),a.width&&(n.style.width=a.width),a.height&&(n.style.height=a.height),a.bgImage&&(n.style.backgroundImage=`url(${a.bgImage})`,n.classList.add("bg-image"));let f=null;if(a.icon){(f=document.createElement("i")).className=["icon",a.iconPack||"",a.icon].join(" ").trim(),a.iconSize&&(f.style.fontSize=a.iconSize),(a.iconLink||a.iconAnimate)&&(f.classList.add("icon-clickable"),f.onclick=e=>{e.stopPropagation(),a.iconAnimate&&(f.classList.remove(a.iconAnimate),f.offsetWidth,f.classList.add(a.iconAnimate)),a.iconLink&&window.open(a.iconLink,"_blank","noopener")});let h=a.iconAnimate??TYPE_ANIMATION[e];h&&(f.classList.add(h),f.addEventListener("click",()=>{f.classList.remove(h),f.offsetWidth,f.classList.add(h)}))}let g=this._getRoot(a.position);if(a.groupId){let $=Array.from(g.children).find(e=>e.dataset.groupId===a.groupId);if($){let b=$.querySelector(".jt-count");b||((b=document.createElement("span")).className="jt-count",b.style.marginLeft="6px",$.querySelector(".jt-title").appendChild(b),b.textContent="1"),b.textContent=parseInt(b.textContent)+1;return}n.dataset.groupId=a.groupId}if(reduceMotion&&(n.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),f?.classList.remove("bounce","shake","wiggle","pulse","spin")),a.message||a.title||this._warn("Toast created without message or title"),a.html){let x=document.createElement("div");x.className="jt-message",x.innerHTML=sanitizeHTML(a.html),S.appendChild(x)}a.icon&&!a.iconPack&&this._warn("icon provided without iconPack"),a.duration<0&&this._warn("duration cannot be negative");let y=0,v=0,_=!1,k=e=>{let t=e.touches?e.touches[0]:e;y=t.clientX,v=0,_=!0,n.__paused=!0},j=e=>{if(!_)return;let t=e.touches?e.touches[0]:e;v=t.clientX-y,n.style.transform=`translate3d(${v}px, 0, 0)`},w=()=>{_&&(_=!1,Math.abs(v)>(this._defaults.swipeThreshold||60)?(n.style.transition="transform .25s ease, opacity .2s ease",n.style.transform=`translate3d(${v>0?1e3:-1e3}px, 0, 0)`,setTimeout(()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},220)):(n.style.transition="transform .2s ease",n.style.transform=""),setTimeout(()=>{n.__paused=!1},60),y=v=0)};isTouch?(n.addEventListener("touchstart",k,{passive:!0}),n.addEventListener("touchmove",j,{passive:!0}),n.addEventListener("touchend",w),n.addEventListener("touchcancel",w)):n.addEventListener("mousedown",e=>{y=e.clientX,v=0,_=!0,n.__paused=!0;let t=e=>{v=e.clientX-y,n.style.transform=`translate3d(${v}px, 0, 0)`},s=()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",s),w()};document.addEventListener("mousemove",t),document.addEventListener("mouseup",s)});let S=document.createElement("div");S.className="jt-content";let E=a.enterAnimation??"pop";if(E&&!reduceMotion&&n.classList.add(E),a.title){let L=document.createElement("div");L.className="jt-title",L.textContent=a.title,S.appendChild(L)}let C=document.createElement("div");if(C.className="jt-message",a.undo){let I=document.createElement("button");I.className="jt-action",I.textContent="Undo",I.onclick=()=>{a.undo(),n.remove(),this._next()},S.appendChild(I),a.undoTimeout&&setTimeout(()=>{n.parentNode&&n.remove()},a.undoTimeout)}if("string"==typeof a.message){let T=a.message.split(/(`[^`]+`)/g);T.forEach(e=>{if(e.startsWith("`")&&e.endsWith("`")){let t=document.createElement("code");t.textContent=e.slice(1,-1),C.appendChild(t)}else C.appendChild(document.createTextNode(e))})}if(S.appendChild(C),f&&"top"===a.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(f),n.appendChild(S)):f&&"right"===a.iconPosition?(n.appendChild(S),n.appendChild(f)):(f&&n.appendChild(f),n.appendChild(S)),Array.isArray(a.actions)&&a.actions.length){let P=document.createElement("div");P.className="jt-actions",a.actions.forEach(e=>{let t=document.createElement("button");t.className="jt-action",t.textContent=e.label,t.onclick=t=>{t.stopPropagation(),e.onClick?.(t),e.closeOnClick&&(n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next())},P.appendChild(t)}),S.appendChild(P)}if(a.closable){let A=document.createElement("span");A.className="juice-toast-close",A.textContent="\xd7",A.onclick=()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},n.appendChild(A)}isIOSStandalone&&(n.style.borderRadius=n.style.borderRadius||"14px");let N=this._defaults.maxVisible;if(N&&g.children.length>=N&&g.firstChild.remove(),g.appendChild(n),this._runPlugins({toast:n,cfg:a,type:e,root:g}),requestAnimationFrame(()=>{n.classList.add("show")}),0===u)return;let z=Date.now(),q=u,O=()=>{if(n.__paused)z=Date.now();else{let e=Date.now();q-=e-z,z=e}if(q<=0?(n.classList.remove("show"),setTimeout(()=>{n.replaceWith(),n.onclick=null,n.onmousedown=null,n.remove(),this._next()},300)):raf(O),p){let t=Math.max(0,Math.min(1,q/u));p.style.transform=`scaleX(${t})`}},M=0;n.addEventListener("mousedown",e=>{M=e.clientY,n.style.transition="none"}),n.addEventListener("mousemove",e=>{0!==M&&(n.style.transform=`translateY(${e.clientY-M}px)`)}),n.addEventListener("mouseup",e=>{n.style.transition="",n.style.transform="",M=0}),isTouch||(n.addEventListener("mouseenter",()=>n.__paused=!0),n.addEventListener("mouseleave",()=>n.__paused=!1)),n.addEventListener("touchstart",()=>{n.__paused=!0},{passive:!0}),n.addEventListener("touchend",()=>{n.__paused=!1}),z=Date.now(),raf(O),(a.playSound||this._defaults.playSound)&&this._playSound(a.playSound)}};juiceToast.setup({success:{icon:"fa-check",iconPack:"fa-solid",bg:"#16a34a",progress:!0,duration:3e3},error:{icon:"fa-xmark",iconPack:"fa-solid",bg:"#dc2626",progress:!0,duration:4e3},info:{icon:"fa-circle-info",iconPack:"fa-solid",bg:"#2563eb",progress:!0},warning:{icon:"fa-triangle-exclamation",iconPack:"fa-solid",bg:"#f59e0b",progress:!0},loading:{icon:"fa-spinner",iconPack:"fa-solid",iconAnimate:"spin",duration:0,progress:!1,closable:!1}});export default juiceToast;export{juiceToast};
|
|
@@ -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,160 +0,0 @@
|
|
|
1
|
-
/* JuiceToast v1.3.2 (iOS User)
|
|
2
|
-
* (C) 2026 OpenDN Foundation
|
|
3
|
-
* Type Definitions
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* ================= CORE ================= */
|
|
7
|
-
|
|
8
|
-
export type ToastPosition =
|
|
9
|
-
| "top-left"
|
|
10
|
-
| "top-right"
|
|
11
|
-
| "bottom-left"
|
|
12
|
-
| "bottom-right"
|
|
13
|
-
| "top-center"
|
|
14
|
-
| "bottom-center"
|
|
15
|
-
| string;
|
|
16
|
-
|
|
17
|
-
export type ToastSize = "sm" | "md" | "lg";
|
|
18
|
-
|
|
19
|
-
export type ToastAnimation =
|
|
20
|
-
| "spin"
|
|
21
|
-
| "pulse"
|
|
22
|
-
| "shake"
|
|
23
|
-
| "bounce"
|
|
24
|
-
| "wiggle"
|
|
25
|
-
| "pop"
|
|
26
|
-
| string;
|
|
27
|
-
|
|
28
|
-
/* ================= ACTIONS ================= */
|
|
29
|
-
|
|
30
|
-
export interface ToastAction {
|
|
31
|
-
label: string;
|
|
32
|
-
onClick?: (ev: MouseEvent) => void;
|
|
33
|
-
closeOnClick?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/* ================= OPTIONS ================= */
|
|
37
|
-
|
|
38
|
-
export interface ToastOptions {
|
|
39
|
-
title?: string;
|
|
40
|
-
message?: string;
|
|
41
|
-
|
|
42
|
-
theme?: string;
|
|
43
|
-
position?: ToastPosition;
|
|
44
|
-
|
|
45
|
-
duration?: number;
|
|
46
|
-
progress?: boolean;
|
|
47
|
-
progressColor?: string;
|
|
48
|
-
|
|
49
|
-
icon?: string;
|
|
50
|
-
iconPack?: string;
|
|
51
|
-
iconSize?: string;
|
|
52
|
-
iconPosition?: "left" | "right" | "top";
|
|
53
|
-
|
|
54
|
-
iconLink?: string;
|
|
55
|
-
iconAnimate?: ToastAnimation;
|
|
56
|
-
|
|
57
|
-
closable?: boolean;
|
|
58
|
-
|
|
59
|
-
bg?: string;
|
|
60
|
-
color?: string;
|
|
61
|
-
border?: string;
|
|
62
|
-
|
|
63
|
-
width?: string;
|
|
64
|
-
height?: string;
|
|
65
|
-
|
|
66
|
-
size?: ToastSize;
|
|
67
|
-
compact?: boolean;
|
|
68
|
-
|
|
69
|
-
glassUI?: number | boolean;
|
|
70
|
-
|
|
71
|
-
bgImage?: string;
|
|
72
|
-
|
|
73
|
-
enterAnimation?: ToastAnimation;
|
|
74
|
-
animation?: string;
|
|
75
|
-
|
|
76
|
-
actions?: ToastAction[];
|
|
77
|
-
|
|
78
|
-
/* AUDIO */
|
|
79
|
-
playSound?: string;
|
|
80
|
-
|
|
81
|
-
/* TTS */
|
|
82
|
-
tts?: boolean;
|
|
83
|
-
ttsLang?: string;
|
|
84
|
-
ttsRate?: number;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/* ================= INTERNAL DEFAULTS ================= */
|
|
88
|
-
|
|
89
|
-
export interface JuiceToastDefaults {
|
|
90
|
-
duration: number;
|
|
91
|
-
maxVisible: number;
|
|
92
|
-
swipeThreshold: number;
|
|
93
|
-
glassUI: number;
|
|
94
|
-
playSound: string | null;
|
|
95
|
-
dev: boolean;
|
|
96
|
-
injectCSS: boolean;
|
|
97
|
-
css: string | null;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/* ================= PLUGIN ================= */
|
|
101
|
-
|
|
102
|
-
export interface JuiceToastPluginContext<T extends string = string> {
|
|
103
|
-
toast: HTMLElement;
|
|
104
|
-
cfg: ToastOptions;
|
|
105
|
-
type: T;
|
|
106
|
-
root: HTMLElement;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export type JuiceToastPlugin<T extends string = string> = (
|
|
110
|
-
ctx: JuiceToastPluginContext<T>
|
|
111
|
-
) => void;
|
|
112
|
-
|
|
113
|
-
/* ================= CONFIG ================= */
|
|
114
|
-
|
|
115
|
-
export type ToastTypeConfig = Record<string, Partial<ToastOptions>>;
|
|
116
|
-
|
|
117
|
-
/* ================= DYNAMIC METHODS ================= */
|
|
118
|
-
|
|
119
|
-
type DynamicToastMethods<T extends string> = {
|
|
120
|
-
[K in T]: (payload?: string | ToastOptions) => void;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/* ================= CORE INSTANCE ================= */
|
|
124
|
-
|
|
125
|
-
export interface JuiceToastBase<T extends string = string> {
|
|
126
|
-
_config: ToastTypeConfig;
|
|
127
|
-
_queue: any[];
|
|
128
|
-
_showing: boolean;
|
|
129
|
-
_theme: string;
|
|
130
|
-
_plugins: JuiceToastPlugin<T>[];
|
|
131
|
-
_defaults: JuiceToastDefaults;
|
|
132
|
-
|
|
133
|
-
/* ===== PUBLIC API ===== */
|
|
134
|
-
|
|
135
|
-
setup<C extends ToastTypeConfig>(
|
|
136
|
-
config: C
|
|
137
|
-
): JuiceToastBase<keyof C & string> &
|
|
138
|
-
DynamicToastMethods<keyof C & string>;
|
|
139
|
-
|
|
140
|
-
use(plugin: JuiceToastPlugin<T>): void;
|
|
141
|
-
|
|
142
|
-
addType(name: string, cfg?: Partial<ToastOptions>): void;
|
|
143
|
-
|
|
144
|
-
defineTheme(name: string, styles: Record<string, string>): void;
|
|
145
|
-
|
|
146
|
-
setTheme(name: string): void;
|
|
147
|
-
|
|
148
|
-
clear(): void;
|
|
149
|
-
destroy(): void;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/* ================= FINAL TYPE ================= */
|
|
153
|
-
|
|
154
|
-
export type JuiceToast<T extends string = string> =
|
|
155
|
-
JuiceToastBase<T> & DynamicToastMethods<T>;
|
|
156
|
-
|
|
157
|
-
declare const juiceToast: JuiceToast;
|
|
158
|
-
|
|
159
|
-
export default juiceToast;
|
|
160
|
-
export { juiceToast };
|
package/dist/juice-toast.d.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/* JuiceToast v1.3.2
|
|
2
|
-
* (C) 2026 OpenDN Foundation
|
|
3
|
-
* Type Definitions
|
|
4
|
-
*/
|
|
5
|
-
/* ================= CORE TYPES ================= */
|
|
6
|
-
|
|
7
|
-
export type ToastPosition =
|
|
8
|
-
| "top-left"
|
|
9
|
-
| "top-right"
|
|
10
|
-
| "bottom-left"
|
|
11
|
-
| "bottom-right"
|
|
12
|
-
| "top-center"
|
|
13
|
-
| "bottom-center";
|
|
14
|
-
|
|
15
|
-
export type ToastSize = "sm" | "md" | "lg";
|
|
16
|
-
|
|
17
|
-
export interface ToastAction {
|
|
18
|
-
label: string;
|
|
19
|
-
onClick?: (ev: MouseEvent) => void;
|
|
20
|
-
closeOnClick?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface ToastOptions {
|
|
24
|
-
title?: string;
|
|
25
|
-
message?: string;
|
|
26
|
-
|
|
27
|
-
theme?: string;
|
|
28
|
-
position?: ToastPosition;
|
|
29
|
-
|
|
30
|
-
duration?: number;
|
|
31
|
-
progress?: boolean;
|
|
32
|
-
progressColor?: string;
|
|
33
|
-
|
|
34
|
-
icon?: string;
|
|
35
|
-
iconPack?: string;
|
|
36
|
-
iconSize?: string;
|
|
37
|
-
iconPosition?: "left" | "right" | "top";
|
|
38
|
-
|
|
39
|
-
iconLink?: string;
|
|
40
|
-
iconAnimate?: string;
|
|
41
|
-
|
|
42
|
-
closable?: boolean;
|
|
43
|
-
|
|
44
|
-
bg?: string;
|
|
45
|
-
color?: string;
|
|
46
|
-
border?: string;
|
|
47
|
-
|
|
48
|
-
width?: string;
|
|
49
|
-
height?: string;
|
|
50
|
-
|
|
51
|
-
size?: ToastSize;
|
|
52
|
-
compact?: boolean;
|
|
53
|
-
|
|
54
|
-
glassUI?: number | boolean;
|
|
55
|
-
|
|
56
|
-
bgImage?: string;
|
|
57
|
-
|
|
58
|
-
enterAnimation?: string;
|
|
59
|
-
animation?: string;
|
|
60
|
-
|
|
61
|
-
actions?: ToastAction[];
|
|
62
|
-
|
|
63
|
-
/* TTS */
|
|
64
|
-
tts?: boolean;
|
|
65
|
-
ttsLang?: string;
|
|
66
|
-
ttsRate?: number;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/* ================= CONFIG TYPES ================= */
|
|
70
|
-
|
|
71
|
-
export type ToastTypeConfig = Record<string, Partial<ToastOptions>>;
|
|
72
|
-
|
|
73
|
-
/* ================= PLUGIN ================= */
|
|
74
|
-
|
|
75
|
-
export interface JuiceToastPluginContext<T extends string = string> {
|
|
76
|
-
toast: HTMLElement;
|
|
77
|
-
cfg: ToastOptions;
|
|
78
|
-
type: T;
|
|
79
|
-
root: HTMLElement;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type JuiceToastPlugin<T extends string = string> = (
|
|
83
|
-
ctx: JuiceToastPluginContext<T>
|
|
84
|
-
) => void;
|
|
85
|
-
|
|
86
|
-
/* ================= MAIN INTERFACE ================= */
|
|
87
|
-
|
|
88
|
-
type DynamicToastMethods<T extends string> = {
|
|
89
|
-
[K in T]: (payload?: string | ToastOptions) => void;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export interface JuiceToastBase<T extends string = string> {
|
|
93
|
-
/* ===== PUBLIC API ===== */
|
|
94
|
-
|
|
95
|
-
setup<C extends Record<string, Partial<ToastOptions>>>(
|
|
96
|
-
config: C
|
|
97
|
-
): JuiceToastBase<keyof C & string> &
|
|
98
|
-
DynamicToastMethods<keyof C & string>;
|
|
99
|
-
|
|
100
|
-
use(plugin: JuiceToastPlugin<T>): void;
|
|
101
|
-
|
|
102
|
-
addType(name: string, cfg?: Partial<ToastOptions>): void;
|
|
103
|
-
|
|
104
|
-
defineTheme(name: string, styles: Record<string, string>): void;
|
|
105
|
-
|
|
106
|
-
setTheme(name: string): void;
|
|
107
|
-
|
|
108
|
-
clear(): void;
|
|
109
|
-
destroy(): void;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/* ================= FINAL TYPE ================= */
|
|
113
|
-
|
|
114
|
-
export type JuiceToast<T extends string = string> =
|
|
115
|
-
JuiceToastBase<T> & DynamicToastMethods<T>;
|
|
116
|
-
|
|
117
|
-
declare const juiceToast: JuiceToast;
|
|
118
|
-
|
|
119
|
-
export default juiceToast;
|
|
120
|
-
export { juiceToast };
|