juice-toast 1.3.1 → 1.3.2

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.
@@ -1,15 +1,8 @@
1
- /* JuiceToast v1.3.1
1
+ /* JuiceToast v1.3.2
2
2
  * (C) 2026 OpenDN Foundation
3
3
  * Type Definitions
4
4
  */
5
-
6
- export type ToastType =
7
- | "success"
8
- | "error"
9
- | "warning"
10
- | "info"
11
- | "loading"
12
- | string
5
+ /* ================= CORE TYPES ================= */
13
6
 
14
7
  export type ToastPosition =
15
8
  | "top-left"
@@ -17,113 +10,111 @@ export type ToastPosition =
17
10
  | "bottom-left"
18
11
  | "bottom-right"
19
12
  | "top-center"
20
- | "bottom-center"
21
-
22
- export type ToastSize = "sm" | "md" | "lg"
13
+ | "bottom-center";
23
14
 
24
- export type AnimationType =
25
- | "spin"
26
- | "pulse"
27
- | "shake"
28
- | "bounce"
29
- | "wiggle"
30
- | "pop"
31
- | string
15
+ export type ToastSize = "sm" | "md" | "lg";
32
16
 
33
17
  export interface ToastAction {
34
- label: string
35
- onClick?: (event: MouseEvent) => void
36
- closeOnClick?: boolean
18
+ label: string;
19
+ onClick?: (ev: MouseEvent) => void;
20
+ closeOnClick?: boolean;
37
21
  }
38
22
 
39
23
  export interface ToastOptions {
40
- /* content */
41
- title?: string
42
- message?: string
43
-
44
- /* icon */
45
- icon?: string
46
- iconPack?: string
47
- iconSize?: string | number
48
- iconPosition?: "left" | "right" | "top"
49
- iconLink?: string
50
- iconAnimate?: AnimationType
51
-
52
- /* layout */
53
- position?: ToastPosition
54
- size?: ToastSize
55
- width?: string
56
- height?: string
57
- compact?: boolean
58
-
59
- /* behavior */
60
- duration?: number
61
- closable?: boolean
62
- progress?: boolean
63
- progressColor?: string
64
- swipeThreshold?: number
65
-
66
- /* style */
67
- theme?: string
68
- bg?: string
69
- color?: string
70
- border?: string
71
- glassUI?: boolean | number
72
-
73
- /* animation */
74
- animation?: AnimationType
75
- enterAnimation?: AnimationType
76
-
77
- /* actions */
78
- actions?: ToastAction[]
79
-
80
- /* sound */
81
- playSound?: string | null
82
- }
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[];
83
62
 
84
- export interface JuiceToastConfig {
85
- duration?: number
86
- maxVisible?: number
87
- swipeThreshold?: number
88
- glassUI?: number | boolean
89
- playSound?: string | null
90
- dev?: boolean
91
- injectCSS?: boolean
92
- css?: string
93
-
94
- [type: string]: any
63
+ /* TTS */
64
+ tts?: boolean;
65
+ ttsLang?: string;
66
+ ttsRate?: number;
95
67
  }
96
68
 
97
- export interface ToastPluginContext {
98
- toast: HTMLElement
99
- cfg: ToastOptions
100
- type: ToastType
101
- root: HTMLElement
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;
102
80
  }
103
81
 
104
- export type JuiceToastPlugin = (ctx: ToastPluginContext) => void
105
-
106
- export interface JuiceToast {
107
- /* core */
108
- setup(config?: JuiceToastConfig): void
109
- clear(): void
110
- destroy(): void
111
-
112
- /* toast types */
113
- [key: string]: any
114
-
115
- /* extension */
116
- use(plugin: JuiceToastPlugin): void
117
- addType(type: ToastType, defaults?: Partial<ToastOptions>): void
118
- defineTheme(name: string, theme: {
119
- bg?: string
120
- color?: string
121
- border?: string
122
- }): void
123
- setTheme(name: string): void
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;
124
110
  }
125
111
 
126
- declare const juiceToast: JuiceToast
112
+ /* ================= FINAL TYPE ================= */
113
+
114
+ export type JuiceToast<T extends string = string> =
115
+ JuiceToastBase<T> & DynamicToastMethods<T>;
116
+
117
+ declare const juiceToast: JuiceToast;
127
118
 
128
- export default juiceToast
129
- export { juiceToast }
119
+ export default juiceToast;
120
+ export { juiceToast };
@@ -1,312 +1,6 @@
1
1
  /**
2
2
  * 2026 (C) OpenDN Foundation
3
- * v1.3.1 (STABLE)
3
+ * v1.3.2 (STABLE)
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,TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"},__cssInjected=!1,BASE_CSS=`
7
- #juice-toast-root {
8
- position: fixed;
9
- z-index: 9999;
10
- display: flex;
11
- gap: 10px;
12
- pointer-events: none;
13
- }
14
-
15
- /* bottom (default) */
16
- #juice-toast-root[data-position="bottom"] {
17
- bottom: 20px;
18
- left: 50%;
19
- transform: translateX(-50%);
20
- flex-direction: column;
21
- align-items: center;
22
- }
23
-
24
- /* top */
25
- #juice-toast-root[data-position="top"] {
26
- top: 20px;
27
- left: 50%;
28
- transform: translateX(-50%);
29
- flex-direction: column;
30
- align-items: center;
31
- }
32
-
33
- /* center */
34
- #juice-toast-root[data-position="center"] {
35
- top: 50%;
36
- left: 50%;
37
- transform: translate(-50%, -50%);
38
- flex-direction: column;
39
- align-items: center;
40
- }
41
-
42
- [id^="juice-toast-root-"] {
43
- position: fixed;
44
- z-index: 9999;
45
- display: flex;
46
- gap: 10px;
47
- pointer-events: none;
48
- }
49
-
50
-
51
- /* ================= TOAST ================= */
52
-
53
- .juice-toast {
54
- /* animation vars (safe for swipe) */
55
- --jt-x: 0px;
56
- --jt-y: 12px;
57
-
58
- pointer-events: auto;
59
- display: flex;
60
- gap: 12px;
61
- align-items: flex-start;
62
-
63
- min-width: 220px;
64
- max-width: 420px;
65
- padding: 12px 16px;
66
- margin: 6px 0;
67
-
68
- border-radius: 8px;
69
- background: #333;
70
- color: #fff;
71
-
72
- font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial;
73
- font-size: 14px;
74
-
75
- opacity: 0;
76
- transform: translate(var(--jt-x), var(--jt-y));
77
- transition:
78
- opacity .25s ease,
79
- transform .25s ease,
80
- background .25s ease,
81
- color .25s ease,
82
- box-shadow .25s ease;
83
-
84
- position: relative;
85
- box-sizing: border-box;
86
- overflow: hidden;
87
- }
88
-
89
- /* visible */
90
- .juice-toast.show {
91
- opacity: 1;
92
- --jt-y: 0px;
93
- }
94
-
95
- /* ================= ICON ================= */
96
-
97
- .juice-toast .icon {
98
- width: 28px;
99
- height: 28px;
100
- display: inline-flex;
101
- align-items: center;
102
- justify-content: center;
103
- font-size: 16px;
104
- line-height: 1;
105
- flex: 0 0 28px;
106
- }
107
-
108
- /* clickable icon */
109
- .icon-clickable {
110
- opacity: 0.85;
111
- cursor: pointer;
112
- }
113
-
114
- .icon-clickable:hover {
115
- opacity: 1;
116
- }
117
-
118
- /* ================= CONTENT ================= */
119
-
120
- .juice-toast .jt-content {
121
- display: flex;
122
- flex-direction: column;
123
- gap: 4px;
124
- flex: 1 1 auto;
125
- }
126
-
127
- /* title */
128
- .juice-toast .jt-title {
129
- font-weight: 700;
130
- font-size: 13px;
131
- line-height: 1.1;
132
- }
133
-
134
- /* message */
135
- .juice-toast .jt-message {
136
- font-size: 13px;
137
- line-height: 1.3;
138
- opacity: 0.95;
139
- }
140
-
141
- /* ================= ICON POSITION ================= */
142
-
143
- .jt-icon-top {
144
- flex-direction: column;
145
- align-items: flex-start;
146
- }
147
-
148
- .jt-icon-top .icon {
149
- align-self: center;
150
- margin-bottom: 6px;
151
- }
152
-
153
- /* ================= CLOSE ================= */
154
-
155
- .juice-toast-close {
156
- position: absolute;
157
- top: 6px;
158
- right: 8px;
159
- cursor: pointer;
160
- font-size: 16px;
161
- opacity: 0.75;
162
- padding: 4px;
163
- border-radius: 4px;
164
- }
165
-
166
- .juice-toast-close:hover {
167
- opacity: 1;
168
- background: rgba(255,255,255,0.06);
169
- }
170
-
171
- /* ================= ACTIONS ================= */
172
-
173
- .jt-actions {
174
- display: flex;
175
- gap: 8px;
176
- margin-top: 10px;
177
- }
178
-
179
- .jt-action {
180
- background: transparent;
181
- border: 1px solid currentColor;
182
- padding: 4px 10px;
183
- border-radius: 6px;
184
- cursor: pointer;
185
- font-size: 12px;
186
- }
187
-
188
- /* ================= COMPACT ================= */
189
-
190
- .jt-compact {
191
- padding: 8px 10px;
192
- gap: 8px;
193
- font-size: 0.9em;
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: rgba(255,255,255,.7);
237
- transform-origin: left;
238
- transform: scaleX(1);
239
- opacity: .85;
240
- }
241
-
242
- /* ================= ANIMATIONS ================= */
243
-
244
- @keyframes jt-spin {
245
- to { transform: rotate(360deg); }
246
- }
247
-
248
- @keyframes jt-pulse {
249
- 50% { transform: scale(1.15); }
250
- }
251
-
252
- @keyframes jt-shake {
253
- 25% { transform: translateX(-3px); }
254
- 50% { transform: translateX(3px); }
255
- 75% { transform: translateX(-3px); }
256
- }
257
-
258
- @keyframes jt-bounce {
259
- 0% { transform: scale(1); }
260
- 30% { transform: scale(1.25); }
261
- 60% { transform: scale(.95); }
262
- 100% { transform: scale(1); }
263
- }
264
-
265
- @keyframes jt-wiggle {
266
- 0% { transform: rotate(0); }
267
- 25% { transform: rotate(-10deg); }
268
- 50% { transform: rotate(10deg); }
269
- 75% { transform: rotate(-6deg); }
270
- 100% { transform: rotate(0); }
271
- }
272
-
273
- @keyframes jt-pop {
274
- 0% { transform: scale(.7); opacity: 0; }
275
- 70% { transform: scale(1.05); opacity: 1; }
276
- 100% { transform: scale(1); }
277
- }
278
-
279
- /* ================= CLASSES ================= */
280
-
281
- .spin { animation: jt-spin .6s linear; }
282
- .pulse { animation: jt-pulse .4s ease; }
283
- .shake { animation: jt-shake .4s ease; }
284
- .bounce { animation: jt-bounce .45s ease; }
285
- .wiggle { animation: jt-wiggle .5s ease; }
286
- .pop { animation: jt-pop .35s ease-out; }
287
-
288
- /* ================= ICON INTERACTION ================= */
289
-
290
- .icon-clickable {
291
- cursor: pointer;
292
- transition: transform .15s ease, opacity .15s ease;
293
- }
294
-
295
- .icon-clickable:hover {
296
- transform: scale(1.1);
297
- opacity: .85;
298
- }
299
-
300
- /* ================= ACCESSIBILITY ================= */
301
-
302
- @media (prefers-reduced-motion: reduce) {
303
- .spin,
304
- .pulse,
305
- .shake,
306
- .bounce,
307
- .wiggle,
308
- .pop {
309
- animation: none !important;
310
- }
311
- }
312
- `;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)"}},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={}){this._config=e,this._defaults={...this._defaults,...e},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","polite"),n.tabIndex=0,a.size&&sizePreset[a.size]){let l=sizePreset[a.size];l.width&&(n.style.width=l.width),l.padding&&(n.style.padding=l.padding)}let c=null;a.progress&&(a.duration??this._defaults.duration)>0&&((c=document.createElement("div")).className="jt-progress",a.progressColor&&(c.style.background=a.progressColor||"rgba(255,255,255,.7)"),n.appendChild(c));let p=this._normalizeGlass(a.glassUI??this._defaults.glassUI);p>0&&(n.classList.add("jt-glass"),n.style.setProperty("--jt-glass",p)),p||(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.glassUI??this._defaults.glassUI)&&n.classList.add("jt-glass"),a.width&&(n.style.width=a.width),a.height&&(n.style.height=a.height);let d=null;if(a.icon){(d=document.createElement("i")).className=["icon",a.iconPack||"",a.icon].join(" ").trim(),a.iconSize&&(d.style.fontSize=a.iconSize),(a.iconLink||a.iconAnimate)&&(d.classList.add("icon-clickable"),d.onclick=e=>{e.stopPropagation(),a.iconAnimate&&(d.classList.remove(a.iconAnimate),d.offsetWidth,d.classList.add(a.iconAnimate)),a.iconLink&&window.open(a.iconLink,"_blank","noopener")});let u=a.iconAnimate??TYPE_ANIMATION[e];u&&(d.classList.add(u),d.addEventListener("click",()=>{d.classList.remove(u),d.offsetWidth,d.classList.add(u)}))}reduceMotion&&(n.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),d?.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 h=0,m=0;n.addEventListener("touchstart",e=>{h=e.touches[0].clientX}),n.addEventListener("touchmove",e=>{m=e.touches[0].clientX-h,n.style.transform=`translateX(${m}px)`}),n.addEventListener("touchend",()=>{Math.abs(m)>this._defaults.swipeThreshold?(n.style.transform=`translateX(${m>0?1e3:-1e3}px)`,setTimeout(()=>{n.remove(),this._next()},200)):n.style.transform="",h=m=0});let f=document.createElement("div");f.className="jt-content";let g=a.enterAnimation??"pop";if(g&&!reduceMotion&&n.classList.add(g),a.title){let $=document.createElement("div");$.className="jt-title",$.textContent=a.title,f.appendChild($)}let x=document.createElement("div");if(x.className="jt-message",x.textContent=a.message||"",f.appendChild(x),d&&"top"===a.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(d),n.appendChild(f)):d&&"right"===a.iconPosition?(n.appendChild(f),n.appendChild(d)):(d&&n.appendChild(d),n.appendChild(f)),Array.isArray(a.actions)&&a.actions.length){let b=document.createElement("div");b.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())},b.appendChild(t)}),f.appendChild(b)}if(a.closable){let y=document.createElement("span");y.className="juice-toast-close",y.innerHTML="\xd7",y.onclick=()=>{n.remove(),this._next()},n.appendChild(y)}let _=this._getRoot(a.position),j=this._defaults.maxVisible;j&&_.children.length>=j&&_.firstChild.remove(),_.appendChild(n),this._runPlugins({toast:n,cfg:a,type:e,root:_}),requestAnimationFrame(()=>n.classList.add("show"));let w=a.duration??2500;if(0===w)return;let k=Date.now(),v=a.duration??this._defaults.duration,C,E=()=>{if(n.__paused)k=Date.now();else{let e=Date.now();v-=e-k,k=e}v<=0?(n.classList.remove("show"),setTimeout(()=>{n.remove(),this._next()},300)):C=requestAnimationFrame(E),c&&(c.style.transform=`scaleX(${Math.max(0,v/w)})`)};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(E)}};export default juiceToast;export{juiceToast};
6
+ const isBrowser="undefined"!=typeof window&&"undefined"!=typeof document,reduceMotion=isBrowser&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"};let __cssInjected=!1;const BASE_CSS='\n#juice-toast-root {\n position: fixed;\n z-index: 9999;\n display: flex;\n gap: 10px;\n pointer-events: none;\n}\n\n/* bottom (default) */\n#juice-toast-root[data-position="bottom"] {\n bottom: 20px;\n left: 50%;\n transform: translateX(-50%);\n flex-direction: column;\n align-items: center;\n}\n\n/* top */\n#juice-toast-root[data-position="top"] {\n top: 20px;\n left: 50%;\n transform: translateX(-50%);\n flex-direction: column;\n align-items: center;\n}\n\n/* center */\n#juice-toast-root[data-position="center"] {\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n flex-direction: column;\n align-items: center;\n}\n\n[id^="juice-toast-root-"] {\n position: fixed;\n z-index: 9999;\n display: flex;\n gap: 10px;\n pointer-events: none;\n}\n\n\n/* ================= TOAST ================= */\n\n.juice-toast {\n /* animation vars (safe for swipe) */\n --jt-x: 0px;\n --jt-y: 12px;\n\n pointer-events: auto;\n display: flex;\n gap: 12px;\n align-items: flex-start;\n\n min-width: 220px;\n max-width: 420px;\n padding: 12px 16px;\n margin: 6px 0;\n\n border-radius: 8px;\n background: #333;\n color: #fff;\n\n font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial;\n font-size: 14px;\n\n opacity: 0;\n transform: translate(var(--jt-x), var(--jt-y));\n transition:\n opacity .25s ease,\n transform .25s ease,\n background .25s ease,\n color .25s ease,\n box-shadow .25s ease;\n\n position: relative;\n box-sizing: border-box;\n overflow: hidden;\n}\n\n/* visible */\n.juice-toast.show {\n opacity: 1;\n transform: translate(var(--jt-x), 0px) scale(1);\n transition: transform 0.35s ease, opacity 0.35s ease;\n}\n\n/* hide */\n.juice-toast.hide {\n opacity: 0;\n transform: translate(var(--jt-x), 12px) scale(0.95);\n}\n\n\n/* ================= ICON ================= */\n\n.juice-toast .icon {\n width: 28px;\n height: 28px;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n font-size: 16px;\n line-height: 1;\n flex: 0 0 28px;\n}\n\n/* clickable icon */\n.icon-clickable {\n opacity: 0.85;\n cursor: pointer;\n}\n\n.icon-clickable:hover {\n opacity: 1;\n}\n\n/* ================= CONTENT ================= */\n\n.juice-toast .jt-content {\n display: flex;\n flex-direction: column;\n gap: 4px;\n flex: 1 1 auto;\n}\n\n/* title */\n.juice-toast .jt-title {\n font-weight: 700;\n font-size: 13px;\n line-height: 1.1;\n}\n\n/* message */\n.juice-toast .jt-message {\n font-size: 13px;\n line-height: 1.3;\n opacity: 0.95;\n}\n\n/* ================= ICON POSITION ================= */\n\n.jt-icon-top {\n flex-direction: column;\n align-items: flex-start;\n}\n\n.jt-icon-top .icon {\n align-self: center;\n margin-bottom: 6px;\n}\n\n/* ================= CLOSE ================= */\n\n.juice-toast-close {\n position: absolute;\n top: 6px;\n right: 8px;\n cursor: pointer;\n font-size: 16px;\n opacity: 0.75;\n padding: 4px;\n border-radius: 4px;\n}\n\n.juice-toast-close:hover {\n opacity: 1;\n background: rgba(255,255,255,0.06);\n}\n\n/* ================= ACTIONS ================= */\n\n.jt-actions {\n display: flex;\n gap: 8px;\n margin-top: 10px;\n}\n\n.jt-action {\n background: transparent;\n border: 1px solid currentColor;\n padding: 4px 10px;\n border-radius: 6px;\n cursor: pointer;\n font-size: 12px;\n}\n\n/* ================= COMPACT ================= */\n\n.jt-compact {\n padding: 6px 8px;\n font-size: 0.85em;\n gap: 6px;\n max-width: 280px;\n}\n\n/* ================= GLASS UI ================= */\n\n.jt-glass {\n --g: calc(var(--jt-glass, 60) / 100);\n\n background: rgba(30, 30, 30, calc(0.2 + var(--g)));\n backdrop-filter: blur(calc(6px + (14px * var(--g))))\n saturate(calc(1 + (0.4 * var(--g))));\n -webkit-backdrop-filter: blur(calc(6px + (14px * var(--g))))\n saturate(calc(1 + (0.4 * var(--g))));\n}\n\n/* light theme support */\n[data-theme="light"] .jt-glass {\n background:\n linear-gradient(\n rgba(255,255,255, calc(0.6 * var(--g))),\n rgba(255,255,255, calc(0.35 * var(--g)))\n ),\n rgba(255,255,255, calc(0.55 - (0.25 * var(--g))));\n\n color: #111;\n\n border:\n 1px solid rgba(0,0,0, calc(0.05 + 0.12 * var(--g)));\n\n box-shadow:\n 0 10px 30px rgba(0,0,0, calc(0.08 + 0.18 * var(--g))),\n inset 0 1px 0 rgba(255,255,255, calc(0.4 * var(--g)));\n}\n\n/* ================= PROGRESS BAR ================= */\n.jt-progress {\n position: absolute;\n left: 0;\n bottom: 0;\n\n height: 3px;\n width: 100%;\n\n background: linear-gradient(to right, #FFFFFF, #FAFAFA);\n height: 4px;\n transform-origin: left;\n transition: transform linear;\n border-radius: 2px;\n transform: scaleX(1);\n opacity: .85;\n}\n\n/* ================= BACKGROUND IMAGE ================= */\n\n.juice-toast.bg-image {\n background-size: cover;\n background-position: center;\n background-repeat: no-repeat;\n color: #fff;\n text-shadow: 0 1px 2px rgba(0,0,0,0.6);\n}\n\n/* ================= ANIMATIONS ================= */\n\n@keyframes jt-spin {\n to { transform: rotate(360deg); }\n}\n\n@keyframes jt-pulse {\n 50% { transform: scale(1.15); }\n}\n\n@keyframes jt-shake {\n 25% { transform: translateX(-3px); }\n 50% { transform: translateX(3px); }\n 75% { transform: translateX(-3px); }\n}\n\n@keyframes jt-bounce {\n 0% { transform: scale(1); }\n 30% { transform: scale(1.25); }\n 60% { transform: scale(.95); }\n 100% { transform: scale(1); }\n}\n\n@keyframes jt-wiggle {\n 0% { transform: rotate(0); }\n 25% { transform: rotate(-10deg); }\n 50% { transform: rotate(10deg); }\n 75% { transform: rotate(-6deg); }\n 100% { transform: rotate(0); }\n}\n\n@keyframes jt-pop {\n 0% { transform: scale(.7); opacity: 0; }\n 70% { transform: scale(1.05); opacity: 1; }\n 100% { transform: scale(1); }\n}\n\n/* ================= CLASSES ================= */\n\n.spin { animation: jt-spin .6s linear; }\n.pulse { animation: jt-pulse .4s ease; }\n.shake { animation: jt-shake .4s ease; }\n.bounce { animation: jt-bounce .45s ease; }\n.wiggle { animation: jt-wiggle .5s ease; }\n.pop { animation: jt-pop .35s ease-out; }\n\n/* ================= ICON INTERACTION ================= */\n\n.icon-clickable {\n cursor: pointer;\n transition: transform .15s ease, opacity .15s ease;\n}\n\n.icon-clickable:hover {\n transform: scale(1.1);\n opacity: .85;\n}\n\n/* ================= ACCESSIBILITY ================= */\n\n@media (prefers-reduced-motion: reduce) {\n .spin,\n .pulse,\n .shake,\n .bounce,\n .wiggle,\n .pop {\n animation: none !important;\n }\n}\n';function injectCSS(n){if(!isBrowser||__cssInjected)return;const e=document.createElement("style");e.id="juice-toast-style",e.textContent=n,document.head.appendChild(e),__cssInjected=!0}const 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(n={}){this._config=n,this._defaults={...this._defaults,...n},this._registerTypes()},use(n){"function"==typeof n&&this._plugins.push(n)},addType(n,e={}){this._config[n]=e,this._registerTypes()},defineTheme(n,e={}){themes[n]={...themes[n]||{},...e}},setTheme(n){if(this._theme=n,!isBrowser)return;const e=document.getElementById("juice-toast-root");e&&(e.dataset.theme=n)},clear(){this._queue.length=0},destroy(){this.clear(),isBrowser&&document.getElementById("juice-toast-root")?.remove()},_registerTypes(){Object.keys(this._config).forEach((n=>{if("function"==typeof this[n]&&!this[n].__auto)return;const e=e=>this._enqueue(n,e);e.__auto=!0,this[n]=e}))},_enqueue(n,e){this._queue.push({type:n,payload:e}),this._showing||this._next()},_next(){if(!this._queue.length)return void(this._showing=!1);this._showing=!0;const n=this._queue.shift();this._showToast(n.type,n.payload)},_runPlugins(n){this._plugins.forEach((e=>{try{e(n)}catch(n){this._warn("Plugin error: "+n.message)}}))},_normalizeGlass(n){if(!0===n)return 60;if(!1===n||null==n)return 0;const e=Number(n);return Number.isFinite(e)?Math.max(0,Math.min(100,e)):0},_getRoot(n="bottom-right"){if(!isBrowser)return null;let e=document.getElementById(`juice-toast-root-${n}`);if(!e){switch(e=document.createElement("div"),e.id=`juice-toast-root-${n}`,e.dataset.position=n,e.dataset.theme=this._theme,e.style.position="fixed",e.style.zIndex=9999,n){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%)"}document.body.appendChild(e)}return e},_defaults:{duration:2500,maxVisible:3,swipeThreshold:60,glassUI:0,playSound:null,dev:!1,injectCSS:!0,css:null},_warn(n){this._defaults.dev&&"undefined"!=typeof console&&console.warn("[JuiceToast]",n)},_playSound(n){if(!isBrowser)return;const e="string"==typeof n&&n?n:this._defaults.playSound;if(e)try{const n=new Audio(e);n.volume=.6,n.play().catch((()=>{}))}catch{}},_showToast(n,e){if(!isBrowser)return;!1!==this._defaults.injectCSS&&injectCSS(this._defaults.css||BASE_CSS);const t={...this._config[n]||{},..."object"==typeof e?e:{message:String(e)}};t.icon=t.icon??t.icon_left_top,t.iconPack=t.iconPack??t.icon_config,t.iconLink=t.iconLink??t.icon_onClick_url,t.iconAnimate=t.iconAnimate??t.icon_onClick_animate,t.position=t.position??t.toast,t.closable=t.closable??t.closeable,t.iconPosition=t.iconPosition||"left",t.compact=!!t.compact;const s=themes[t.theme||this._theme]||{},o=document.createElement("div");o.className="juice-toast";const i=t.animation||"slide-in";if(t.enterAnimation||(o.style.animation=`${i} 0.4s ease forwards`),o.setAttribute("role","alert"),o.setAttribute("aria-live","error"===n?"assertive":"polite"),o.setAttribute("aria-atomic","true"),o.tabIndex=0,t.closable&&(close.tabIndex=0,close.addEventListener("keydown",(n=>{"Enter"!==n.key&&" "!==n.key||(o.remove(),this._next())}))),t.size&&sizePreset[t.size]){const n=sizePreset[t.size];n.width&&(o.style.width=n.width),n.padding&&(o.style.padding=n.padding)}let a=null;if(t.progress&&(t.duration??this._defaults.duration)>0&&(a=document.createElement("div"),a.className="jt-progress",t.progressColor&&(a.style.background=t.progressColor||"rgba(255,255,255,.7)"),o.appendChild(a)),t.tts&&"speechSynthesis"in window)try{const n=new SpeechSynthesisUtterance(t.message||t.title||"");n.lang=t.ttsLang||"en-US",n.rate=t.ttsRate??1,window.speechSynthesis.speak(n)}catch(n){this._warn("TTS failed: "+n.message)}const r=this._normalizeGlass(t.glassUI??this._defaults.glassUI);r>0&&(o.style.setProperty("--jt-glass",t.glassUI??50),o.classList.add("jt-glass")),r||(o.style.background=t.bg||s.bg),o.style.color=t.color||s.color,o.style.border=t.border||s.border,t.compact&&o.classList.add("jt-compact"),(t.glassUI??this._defaults.glassUI)&&o.classList.add("jt-glass"),t.width&&(o.style.width=t.width),t.height&&(o.style.height=t.height),t.bgImage&&(o.style.backgroundImage=`url(${t.bgImage})`,o.classList.add("bg-image"));let c=null;if(t.icon){c=document.createElement("i"),c.className=["icon",t.iconPack||"",t.icon].join(" ").trim(),t.iconSize&&(c.style.fontSize=t.iconSize),(t.iconLink||t.iconAnimate)&&(c.classList.add("icon-clickable"),c.onclick=n=>{n.stopPropagation(),t.iconAnimate&&(c.classList.remove(t.iconAnimate),c.offsetWidth,c.classList.add(t.iconAnimate)),t.iconLink&&window.open(t.iconLink,"_blank","noopener")});const e=t.iconAnimate??TYPE_ANIMATION[n];e&&(c.classList.add(e),c.addEventListener("click",(()=>{c.classList.remove(e),c.offsetWidth,c.classList.add(e)})))}reduceMotion&&(o.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),c?.classList.remove("bounce","shake","wiggle","pulse","spin")),t.message||t.title||this._warn("Toast created without message or title"),t.icon&&!t.iconPack&&this._warn("icon provided without iconPack"),t.duration<0&&this._warn("duration cannot be negative");let l=0,d=0;o.addEventListener("touchstart",(n=>{l=n.touches[0].clientX})),o.addEventListener("touchmove",(n=>{d=n.touches[0].clientX-l,o.style.transform=`translateX(${d}px)`})),o.addEventListener("touchend",(()=>{Math.abs(d)>this._defaults.swipeThreshold?(o.style.transform=`translateX(${d>0?1e3:-1e3}px)`,setTimeout((()=>{o.remove(),this._next()}),200)):o.style.transform="",l=d=0}));const p=document.createElement("div");p.className="jt-content";const u=t.enterAnimation??"pop";if(u&&!reduceMotion&&o.classList.add(u),t.title){const n=document.createElement("div");n.className="jt-title",n.textContent=t.title,p.appendChild(n)}const m=document.createElement("div");if(m.className="jt-message",m.textContent=t.message||"",p.appendChild(m),c&&"top"===t.iconPosition?(o.classList.add("jt-icon-top"),o.appendChild(c),o.appendChild(p)):c&&"right"===t.iconPosition?(o.appendChild(p),o.appendChild(c)):(c&&o.appendChild(c),o.appendChild(p)),Array.isArray(t.actions)&&t.actions.length){const n=document.createElement("div");n.className="jt-actions",t.actions.forEach((e=>{const t=document.createElement("button");t.className="jt-action",t.textContent=e.label,t.onclick=n=>{n.stopPropagation(),e.onClick?.(n),e.closeOnClick&&(o.remove(),this._next())},n.appendChild(t)})),p.appendChild(n)}if(t.closable){const n=document.createElement("span");n.className="juice-toast-close",n.innerHTML="×",n.onclick=()=>{o.remove(),this._next()},o.appendChild(n)}const f=this._getRoot(t.position),g=this._defaults.maxVisible;g&&f.children.length>=g&&f.firstChild.remove(),f.appendChild(o),this._runPlugins({toast:o,cfg:t,type:n,root:f}),requestAnimationFrame((()=>o.classList.add("show")));const h=t.duration??2500;if(0===h)return;let b,x=Date.now(),y=t.duration??this._defaults.duration;const _=()=>{if(o.__paused)x=Date.now();else{const n=Date.now();y-=n-x,x=n}y<=0?(o.classList.remove("show"),setTimeout((()=>{o.remove(),this._next()}),300)):b=requestAnimationFrame(_),a&&(a.style.transform=`scaleX(${Math.max(0,y/h)})`)};o.addEventListener("mouseenter",(()=>o.__paused=!0)),o.addEventListener("mouseleave",(()=>o.__paused=!1)),o.addEventListener("touchstart",(()=>o.__paused=!0)),o.addEventListener("touchend",(()=>o.__paused=!1)),requestAnimationFrame(_)}};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};