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,316 +1,6 @@
1
1
  /**
2
2
  * OpenDN Foundation (C) 2026
3
- * Source Of Juice Toast v1.3.1 (NEW: For iOS user)
3
+ * Source Of Juice Toast v1.3.1 (iOS user)
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),TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"},__cssInjected=!1,BASE_CSS=`
7
- :root {
8
- --jt-safe-top: env(safe-area-inset-top, 0px);
9
- --jt-safe-bottom: env(safe-area-inset-bottom, 0px);
10
- }
11
-
12
- #juice-toast-root {
13
- position: fixed;
14
- z-index: 9999;
15
- display: flex;
16
- gap: 10px;
17
- pointer-events: none;
18
- }
19
-
20
- /* bottom (default) */
21
- #juice-toast-root[data-position="bottom"] {
22
- bottom: 20px;
23
- left: 50%;
24
- transform: translateX(-50%);
25
- flex-direction: column;
26
- align-items: center;
27
- }
28
-
29
- /* top */
30
- #juice-toast-root[data-position="top"] {
31
- top: 20px;
32
- left: 50%;
33
- transform: translateX(-50%);
34
- flex-direction: column;
35
- align-items: center;
36
- }
37
-
38
- /* center */
39
- #juice-toast-root[data-position="center"] {
40
- top: 50%;
41
- left: 50%;
42
- transform: translate(-50%, -50%);
43
- flex-direction: column;
44
- align-items: center;
45
- }
46
-
47
- [id^="juice-toast-root-"] {
48
- position: fixed;
49
- z-index: 9999;
50
- display: flex;
51
- gap: 10px;
52
- pointer-events: none;
53
- padding-top: var(--jt-safe-top);
54
- padding-bottom: var(--jt-safe-bottom);
55
- }
56
-
57
-
58
- /* ================= TOAST ================= */
59
-
60
- .juice-toast {
61
- --jt-x: 0px;
62
- --jt-y: 12px;
63
-
64
- pointer-events: auto;
65
- display: flex;
66
- gap: 12px;
67
- align-items: flex-start;
68
-
69
- min-width: 220px;
70
- max-width: 420px;
71
- padding: 12px 16px;
72
- margin: 6px 0;
73
-
74
- border-radius: 8px;
75
- background: #333;
76
- color: #fff;
77
-
78
- font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial;
79
- font-size: 14px;
80
-
81
- opacity: 0;
82
- transform: translate(var(--jt-x), var(--jt-y));
83
- transition:
84
- opacity .25s ease,
85
- transform .25s ease,
86
- background .25s ease,
87
- color .25s ease,
88
- box-shadow .25s ease;
89
-
90
- position: relative;
91
- box-sizing: border-box;
92
- overflow: hidden;
93
- }
94
-
95
- /* visible */
96
- .juice-toast.show {
97
- opacity: 1;
98
- --jt-y: 0px;
99
- }
100
-
101
- /* ================= ICON ================= */
102
-
103
- .juice-toast .icon {
104
- width: 28px;
105
- height: 28px;
106
- display: inline-flex;
107
- align-items: center;
108
- justify-content: center;
109
- font-size: 16px;
110
- line-height: 1;
111
- flex: 0 0 28px;
112
- }
113
-
114
- /* clickable icon */
115
- .icon-clickable {
116
- opacity: 0.85;
117
- cursor: pointer;
118
- }
119
-
120
- .icon-clickable:hover {
121
- opacity: 1;
122
- }
123
-
124
- /* ================= CONTENT ================= */
125
-
126
- .juice-toast .jt-content {
127
- display: flex;
128
- flex-direction: column;
129
- gap: 4px;
130
- flex: 1 1 auto;
131
- }
132
-
133
- /* title */
134
- .juice-toast .jt-title {
135
- font-weight: 700;
136
- font-size: 13px;
137
- line-height: 1.1;
138
- }
139
-
140
- /* message */
141
- .juice-toast .jt-message {
142
- font-size: 13px;
143
- line-height: 1.3;
144
- opacity: 0.95;
145
- }
146
-
147
- /* ================= ICON POSITION ================= */
148
-
149
- .jt-icon-top {
150
- flex-direction: column;
151
- align-items: flex-start;
152
- }
153
-
154
- .jt-icon-top .icon {
155
- align-self: center;
156
- margin-bottom: 6px;
157
- }
158
-
159
- /* ================= CLOSE ================= */
160
-
161
- .juice-toast-close {
162
- position: absolute;
163
- top: 6px;
164
- right: 8px;
165
- cursor: pointer;
166
- font-size: 16px;
167
- opacity: 0.75;
168
- padding: 4px;
169
- border-radius: 4px;
170
- }
171
-
172
- .juice-toast-close:hover {
173
- opacity: 1;
174
- background: rgba(255,255,255,0.06);
175
- }
176
-
177
- /* ================= ACTIONS ================= */
178
-
179
- .jt-actions {
180
- display: flex;
181
- gap: 8px;
182
- margin-top: 10px;
183
- }
184
-
185
- .jt-action {
186
- background: transparent;
187
- border: 1px solid currentColor;
188
- padding: 4px 10px;
189
- border-radius: 6px;
190
- cursor: pointer;
191
- font-size: 12px;
192
- }
193
-
194
- /* ================= COMPACT ================= */
195
-
196
- .jt-compact {
197
- padding: 8px 10px;
198
- gap: 8px;
199
- font-size: 0.9em;
200
- }
201
-
202
- /* ================= GLASS UI ================= */
203
-
204
- .jt-glass {
205
- --g: calc(var(--jt-glass, 60) / 100);
206
-
207
- background: rgba(30, 30, 30, calc(0.2 + var(--g)));
208
- backdrop-filter: blur(calc(6px + (14px * var(--g))))
209
- saturate(calc(1 + (0.4 * var(--g))));
210
- -webkit-backdrop-filter: blur(calc(6px + (14px * var(--g))))
211
- saturate(calc(1 + (0.4 * var(--g))));
212
- }
213
-
214
- /* light theme support */
215
- [data-theme="light"] .jt-glass {
216
- background:
217
- linear-gradient(
218
- rgba(255,255,255, calc(0.6 * var(--g))),
219
- rgba(255,255,255, calc(0.35 * var(--g)))
220
- ),
221
- rgba(255,255,255, calc(0.55 - (0.25 * var(--g))));
222
-
223
- color: #111;
224
-
225
- border:
226
- 1px solid rgba(0,0,0, calc(0.05 + 0.12 * var(--g)));
227
-
228
- box-shadow:
229
- 0 10px 30px rgba(0,0,0, calc(0.08 + 0.18 * var(--g))),
230
- inset 0 1px 0 rgba(255,255,255, calc(0.4 * var(--g)));
231
- }
232
-
233
- /* ================= PROGRESS BAR ================= */
234
- .jt-progress {
235
- position: absolute;
236
- left: 0;
237
- bottom: 0;
238
-
239
- height: 3px;
240
- width: 100%;
241
-
242
- background: rgba(255,255,255,.7);
243
- transform-origin: left;
244
- transform: scaleX(1);
245
- opacity: .85;
246
- }
247
-
248
- /* ================= ANIMATIONS ================= */
249
-
250
- @keyframes jt-spin {
251
- to { transform: rotate(360deg); }
252
- }
253
-
254
- @keyframes jt-pulse {
255
- 50% { transform: scale(1.15); }
256
- }
257
-
258
- @keyframes jt-shake {
259
- 25% { transform: translateX(-3px); }
260
- 50% { transform: translateX(3px); }
261
- 75% { transform: translateX(-3px); }
262
- }
263
-
264
- @keyframes jt-bounce {
265
- 0% { transform: scale(1); }
266
- 30% { transform: scale(1.25); }
267
- 60% { transform: scale(.95); }
268
- 100% { transform: scale(1); }
269
- }
270
-
271
- @keyframes jt-wiggle {
272
- 0% { transform: rotate(0); }
273
- 25% { transform: rotate(-10deg); }
274
- 50% { transform: rotate(10deg); }
275
- 75% { transform: rotate(-6deg); }
276
- 100% { transform: rotate(0); }
277
- }
278
-
279
- @keyframes jt-pop {
280
- 0% { transform: scale(.7); opacity: 0; }
281
- 70% { transform: scale(1.05); opacity: 1; }
282
- 100% { transform: scale(1); }
283
- }
284
-
285
- /* ================= CLASSES ================= */
286
-
287
- .spin { animation: jt-spin .6s linear; }
288
- .pulse { animation: jt-pulse .4s ease; }
289
- .shake { animation: jt-shake .4s ease; }
290
- .bounce { animation: jt-bounce .45s ease; }
291
- .wiggle { animation: jt-wiggle .5s ease; }
292
- .pop { animation: jt-pop .35s ease-out; }
293
-
294
- .icon-clickable {
295
- cursor: pointer;
296
- transition: transform .15s ease, opacity .15s ease;
297
- }
298
-
299
- .icon-clickable:hover {
300
- transform: scale(1.1);
301
- opacity: .85;
302
- }
303
-
304
- /* ================= ACCESSIBILITY ================= */
305
-
306
- @media (prefers-reduced-motion: reduce) {
307
- .spin,
308
- .pulse,
309
- .shake,
310
- .bounce,
311
- .wiggle,
312
- .pop {
313
- animation: none !important;
314
- }
315
- }
316
- `;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},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","polite"),n.tabIndex=0,i.size&&sizePreset[i.size]){let l=sizePreset[i.size];l.width&&(n.style.width=l.width),l.padding&&(n.style.padding=l.padding)}let c=null,d=i.duration??this._defaults.duration;i.progress&&d>0&&((c=document.createElement("div")).className="jt-progress",i.progressColor&&(c.style.background=i.progressColor||"rgba(255,255,255,.7)"),n.appendChild(c));let p=this._normalizeGlass(i.glassUI??this._defaults.glassUI);p>0&&(n.classList.add("jt-glass"),n.style.setProperty("--jt-glass",p)),p||(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.glassUI??this._defaults.glassUI)&&n.classList.add("jt-glass"),i.width&&(n.style.width=i.width),i.height&&(n.style.height=i.height);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,f=0,$=!1,g=e=>{let t=e.touches?e.touches[0]:e;h=t.clientX,f=0,$=!0,n.__paused=!0},x=e=>{if(!$)return;let t=e.touches?e.touches[0]:e;f=t.clientX-h,n.style.transform=`translate3d(${f}px, 0, 0)`},y=()=>{$&&($=!1,Math.abs(f)>(this._defaults.swipeThreshold||60)?(n.style.transition="transform .25s ease, opacity .2s ease",n.style.transform=`translate3d(${f>0?1e3:-1e3}px, 0, 0)`,setTimeout(()=>{n.remove(),this._next()},220)):(n.style.transition="transform .2s ease",n.style.transform=""),setTimeout(()=>{n.__paused=!1},60),h=f=0)};isTouch?(n.addEventListener("touchstart",g,{passive:!0}),n.addEventListener("touchmove",x,{passive:!0}),n.addEventListener("touchend",y),n.addEventListener("touchcancel",y)):n.addEventListener("mousedown",e=>{h=e.clientX,f=0,$=!0,n.__paused=!0;let t=e=>{f=e.clientX-h,n.style.transform=`translate3d(${f}px, 0, 0)`},s=()=>{document.removeEventListener("mousemove",t),document.removeEventListener("mouseup",s),y()};document.addEventListener("mousemove",t),document.addEventListener("mouseup",s)});let b=document.createElement("div");b.className="jt-content";let v=i.enterAnimation??"pop";if(v&&!reduceMotion&&n.classList.add(v),i.title){let _=document.createElement("div");_.className="jt-title",_.textContent=i.title,b.appendChild(_)}let j=document.createElement("div");if(j.className="jt-message",j.textContent=i.message||"",b.appendChild(j),u&&"top"===i.iconPosition?(n.classList.add("jt-icon-top"),n.appendChild(u),n.appendChild(b)):u&&"right"===i.iconPosition?(n.appendChild(b),n.appendChild(u)):(u&&n.appendChild(u),n.appendChild(b)),Array.isArray(i.actions)&&i.actions.length){let w=document.createElement("div");w.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())},w.appendChild(t)}),b.appendChild(w)}if(i.closable){let k=document.createElement("span");k.className="juice-toast-close",k.innerHTML="\xd7",k.onclick=()=>{n.remove(),this._next()},n.appendChild(k)}isIOSStandalone&&(n.style.borderRadius=n.style.borderRadius||"14px");let S=this._getRoot(i.position),E=this._defaults.maxVisible;if(E&&S.children.length>=E&&S.firstChild.remove(),S.appendChild(n),this._runPlugins({toast:n,cfg:i,type:e,root:S}),requestAnimationFrame(()=>{n.classList.add("show")}),0===d)return;let C=Date.now(),L=d,I,T=()=>{if(n.__paused)C=Date.now();else{let e=Date.now();L-=e-C,C=e}if(L<=0?(n.classList.remove("show"),setTimeout(()=>{n.remove(),this._next()},300)):I=requestAnimationFrame(T),c){let t=Math.max(0,Math.min(1,L/d));c.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(),I=requestAnimationFrame(T),(i.playSound||this._defaults.playSound)&&this._playSound(i.playSound)}};export default juiceToast;export{juiceToast};
6
+ const 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,n="en-US",t=1){if(!("speechSynthesis"in window))return;const s=new SpeechSynthesisUtterance(e);s.lang=n,s.rate=t;const o=()=>{window.speechSynthesis.speak(s),document.body.removeEventListener("touchstart",o),document.body.removeEventListener("click",o)};/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream&&!1===window.speechSynthesis.speaking?(document.body.addEventListener("touchstart",o,{once:!0}),document.body.addEventListener("click",o,{once:!0})):o()}const raf=window.requestAnimationFrame||window.webkitRequestAnimationFrame||(e=>setTimeout(e,16)),TYPE_ANIMATION={success:"bounce",error:"shake",warning:"wiggle",info:"pulse",loading:"spin"};let __cssInjected=!1;const BASE_CSS='\n:root {\n --jt-safe-top: env(safe-area-inset-top, 0px);\n --jt-safe-bottom: env(safe-area-inset-bottom, 0px);\n}\n\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 padding-top: var(--jt-safe-top);\n padding-bottom: var(--jt-safe-bottom);\n}\n\n\n/* ================= TOAST ================= */\n\n.juice-toast {\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 scroll-behavior: contains;\n -webkit-overflow-scrolling: touch;\n\n will-change: transform, opacity;\n backface-visibility: hidden;\n -webkit-backface-visibility: hidden;\n\n touch-action: pan-y;\n\n}\n\n/* visible */\n.juice-toast.show {\n opacity: 1;\n --jt-y: 0px;\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: 8px 10px;\n gap: 8px;\n font-size: 0.9em;\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.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-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(e){if(!isBrowser||__cssInjected)return;const n=document.createElement("style");n.id="juice-toast-style",n.textContent=e,document.head.appendChild(n),__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(e={}){this._config=e,this._defaults={...this._defaults,...e},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,n={}){this._config[e]=n,this._registerTypes()},defineTheme(e,n={}){themes[e]={...themes[e]||{},...n}},setTheme(e){if(this._theme=e,!isBrowser)return;const n=document.querySelector('[id^="juice-toast-root-"]');n&&(n.dataset.theme=e)},clear(){this._queue.length=0},destroy(){if(this.clear(),!isBrowser)return;document.querySelectorAll('[id^="juice-toast-root-"]').forEach((e=>e.remove()))},_registerTypes(){Object.keys(this._config).forEach((e=>{if("function"==typeof this[e]&&!this[e].__auto)return;const n=n=>this._enqueue(e,n);n.__auto=!0,this[e]=n}))},_enqueue(e,n){this._queue.push({type:e,payload:n}),this._showing||this._next()},_next(){if(!this._queue.length)return void(this._showing=!1);this._showing=!0;const e=this._queue.shift();this._showToast(e.type,e.payload)},_runPlugins(e){this._plugins.forEach((n=>{try{n(e)}catch(e){this._warn("Plugin error: "+(e&&e.message?e.message:String(e)))}}))},_normalizeGlass(e){if(!0===e)return 60;if(!1===e||null==e)return 0;const n=Number(e);return Number.isFinite(n)?Math.max(0,Math.min(100,n)):0},_getRoot(e="bottom-right"){if(!isBrowser)return null;let n=document.getElementById(`juice-toast-root-${e}`);if(!n){switch(n=document.createElement("div"),n.id=`juice-toast-root-${e}`,n.dataset.position=e,n.dataset.theme=this._theme,n.style.position="fixed",n.style.zIndex=9999,n.style.display="flex",n.style.flexDirection="column",n.style.gap="8px",n.style.pointerEvents="none",e){case"top-left":n.style.top="calc(20px + env(safe-area-inset-top))",n.style.left="20px",n.style.alignItems="flex-start";break;case"top-right":n.style.top="calc(20px + env(safe-area-inset-top))",n.style.right="20px",n.style.alignItems="flex-end";break;case"bottom-left":n.style.bottom="calc(20px + env(safe-area-inset-bottom))",n.style.left="20px",n.style.alignItems="flex-start";break;case"bottom-right":n.style.bottom="calc(20px + env(safe-area-inset-bottom))",n.style.right="20px",n.style.alignItems="flex-end";break;case"top-center":n.style.top="calc(20px + env(safe-area-inset-top))",n.style.left="50%",n.style.transform="translateX(-50%)",n.style.alignItems="center";break;case"bottom-center":n.style.bottom="calc(20px + env(safe-area-inset-bottom))",n.style.left="50%",n.style.transform="translateX(-50%)",n.style.alignItems="center";break;default:n.style.bottom="calc(20px + env(safe-area-inset-bottom))",n.style.right="20px"}document.body.appendChild(n)}return n},_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;const n="string"==typeof e&&e?e:this._defaults.playSound;if(n)try{const e=new Audio(n);e.volume=.6;const t=()=>{e.play().catch((()=>{})),window.removeEventListener("touchstart",t),window.removeEventListener("click",t)};e.play().catch((()=>{window.addEventListener("touchstart",t,{once:!0}),window.addEventListener("click",t,{once:!0})}))}catch(e){}},_showToast(e,n){if(!isBrowser)return;!1!==this._defaults.injectCSS&&injectCSS(this._defaults.css||BASE_CSS);const t={...this._config[e]||{},..."object"==typeof n?n:{message:String(n)}};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"===e?"assertive":"polite"),o.setAttribute("aria-atomic","true"),o.tabIndex=0,t.closable&&(close.tabIndex=0,close.addEventListener("keydown",(e=>{"Enter"!==e.key&&" "!==e.key||(o.remove(),this._next())}))),t.size&&sizePreset[t.size]){const e=sizePreset[t.size];e.width&&(o.style.width=e.width),e.padding&&(o.style.padding=e.padding)}let a=null;const r=t.duration??this._defaults.duration;t.progress&&r>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&&t.message&&speakTTS(t.message,t.ttsLang??"en-US",t.ttsRate??1);const c=this._normalizeGlass(t.glassUI??this._defaults.glassUI);c>0&&(o.style.setProperty("--jt-glass",t.glassUI??50),o.classList.add("jt-glass")),c||(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 l=null;if(t.icon){l=document.createElement("i"),l.className=["icon",t.iconPack||"",t.icon].join(" ").trim(),t.iconSize&&(l.style.fontSize=t.iconSize),(t.iconLink||t.iconAnimate)&&(l.classList.add("icon-clickable"),l.onclick=e=>{e.stopPropagation(),t.iconAnimate&&(l.classList.remove(t.iconAnimate),l.offsetWidth,l.classList.add(t.iconAnimate)),t.iconLink&&window.open(t.iconLink,"_blank","noopener")});const n=t.iconAnimate??TYPE_ANIMATION[e];n&&(l.classList.add(n),l.addEventListener("click",(()=>{l.classList.remove(n),l.offsetWidth,l.classList.add(n)})))}reduceMotion&&(o.classList.remove("pop","bounce","shake","wiggle","pulse","spin"),l?.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 d=0,p=0,u=!1;const m=e=>{const n=e.touches?e.touches[0]:e;d=n.clientX,p=0,u=!0,o.__paused=!0},f=e=>{if(!u)return;const n=e.touches?e.touches[0]:e;p=n.clientX-d,o.style.transform=`translate3d(${p}px, 0, 0)`},h=()=>{u&&(u=!1,Math.abs(p)>(this._defaults.swipeThreshold||60)?(o.style.transition="transform .25s ease, opacity .2s ease",o.style.transform=`translate3d(${p>0?1e3:-1e3}px, 0, 0)`,setTimeout((()=>{o.replaceWith(),o.onclick=null,o.onmousedown=null,o.remove(),this._next()}),220)):(o.style.transition="transform .2s ease",o.style.transform=""),setTimeout((()=>{o.__paused=!1}),60),d=p=0)};isTouch?(o.addEventListener("touchstart",m,{passive:!0}),o.addEventListener("touchmove",f,{passive:!0}),o.addEventListener("touchend",h),o.addEventListener("touchcancel",h)):o.addEventListener("mousedown",(e=>{d=e.clientX,p=0,u=!0,o.__paused=!0;const n=e=>{p=e.clientX-d,o.style.transform=`translate3d(${p}px, 0, 0)`},t=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",t),h()};document.addEventListener("mousemove",n),document.addEventListener("mouseup",t)}));const g=document.createElement("div");g.className="jt-content";const b=t.enterAnimation??"pop";if(b&&!reduceMotion&&o.classList.add(b),t.title){const e=document.createElement("div");e.className="jt-title",e.textContent=t.title,g.appendChild(e)}const x=document.createElement("div");if(x.className="jt-message",x.textContent=t.message||"",g.appendChild(x),l&&"top"===t.iconPosition?(o.classList.add("jt-icon-top"),o.appendChild(l),o.appendChild(g)):l&&"right"===t.iconPosition?(o.appendChild(g),o.appendChild(l)):(l&&o.appendChild(l),o.appendChild(g)),Array.isArray(t.actions)&&t.actions.length){const e=document.createElement("div");e.className="jt-actions",t.actions.forEach((n=>{const t=document.createElement("button");t.className="jt-action",t.textContent=n.label,t.onclick=e=>{e.stopPropagation(),n.onClick?.(e),n.closeOnClick&&(o.replaceWith(),o.onclick=null,o.onmousedown=null,o.remove(),this._next())},e.appendChild(t)})),g.appendChild(e)}if(t.closable){const e=document.createElement("span");e.className="juice-toast-close",e.innerHTML="×",e.onclick=()=>{o.replaceWith(),o.onclick=null,o.onmousedown=null,o.remove(),this._next()},o.appendChild(e)}isIOSStandalone&&(o.style.borderRadius=o.style.borderRadius||"14px");const y=this._getRoot(t.position),w=this._defaults.maxVisible;if(w&&y.children.length>=w&&y.firstChild.remove(),y.appendChild(o),this._runPlugins({toast:o,cfg:t,type:e,root:y}),requestAnimationFrame((()=>{o.classList.add("show")})),0===r)return;let v=Date.now(),_=r;const k=()=>{if(o.__paused)v=Date.now();else{const e=Date.now();_-=e-v,v=e}if(_<=0?(o.classList.remove("show"),setTimeout((()=>{o.replaceWith(),o.onclick=null,o.onmousedown=null,o.remove(),this._next()}),300)):raf(k),a){const e=Math.max(0,Math.min(1,_/r));a.style.transform=`scaleX(${e})`}};isTouch||(o.addEventListener("mouseenter",(()=>o.__paused=!0)),o.addEventListener("mouseleave",(()=>o.__paused=!1))),o.addEventListener("touchstart",(()=>{o.__paused=!0}),{passive:!0}),o.addEventListener("touchend",(()=>{o.__paused=!1})),v=Date.now(),raf(k),(t.playSound||this._defaults.playSound)&&this._playSound(t.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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "juice-toast",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Lightweight, dependency-free toast notification library",
5
5
  "keywords": [
6
6
  "toast",
@@ -25,15 +25,18 @@
25
25
  "engines": {
26
26
  "node": ">=18"
27
27
  },
28
+ "scripts": {
29
+ "format": "npx prettier --write src/"
30
+ },
28
31
  "module": "dist/juice-toast.esm.js",
29
32
  "types": "dist/juice-toast.d.ts",
30
33
  "exports": {
31
34
  ".": {
32
35
  "import": "./dist/juice-toast.esm.js",
33
36
  "types": "./dist/juice-toast.d.ts"
34
- },
37
+ },
35
38
  "./ios": {
36
- "import": "./dist/juice-toast.ios.js",
39
+ "import": "./dist/juice-toast.ios.js",
37
40
  "types": "./dist/juice-toast-ios.d.ts"
38
41
  }
39
42
  },
@@ -54,5 +57,8 @@
54
57
  "access": "public"
55
58
  },
56
59
  "unpkg": "dist/juice-toast.esm.js",
57
- "jsdelivr": "dist/juice-toast.esm.js"
60
+ "jsdelivr": "dist/juice-toast.esm.js",
61
+ "devDependencies": {
62
+ "prettier": "^3.8.1"
63
+ }
58
64
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Sholehuddin Khairy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.