juice-toast 1.3.2 → 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/API.md +2 -2
- package/CHANGELOG.md +18 -3
- package/EoL.md +4 -1
- package/dist/juice-toast.esm.js +22 -2
- package/dist/juice-toast.ios.js +363 -2
- package/dist/juice-toast.umd.js +16 -0
- package/package.json +2 -2
- package/dist/juice-toast-ios.d.ts +0 -160
- package/dist/juice-toast.d.ts +0 -120
package/API.md
CHANGED
|
@@ -251,10 +251,10 @@ juiceToast.custom("Hello World");
|
|
|
251
251
|
## Background image
|
|
252
252
|
```js
|
|
253
253
|
juiceToast.setup({
|
|
254
|
-
|
|
254
|
+
image: { bgImage: "https://cdn.kyrt.my.id/image/ts-logo-128.svg" }
|
|
255
255
|
});
|
|
256
256
|
|
|
257
|
-
juiceToast.
|
|
257
|
+
juiceToast.image("Hi");
|
|
258
258
|
```
|
|
259
259
|
|
|
260
260
|
---
|
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +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
|
|
13
|
+
- Bug Fixes on Closeable Toast & Logic
|
|
14
|
+
|
|
15
|
+
v1.3.2
|
|
2
16
|
- Improved A11Y
|
|
3
|
-
- Adding
|
|
17
|
+
- Adding Background Image
|
|
4
18
|
- Adding more Theme
|
|
5
|
-
- Adding default toast (juiceToast.success|error|info|warning
|
|
19
|
+
- Adding default toast (juiceToast.success|error|info|warning)
|
|
6
20
|
|
|
7
21
|
v1.3.1
|
|
8
22
|
- Improved iOS / Safari (WebKit) compatibility
|
|
@@ -36,6 +50,7 @@ NEXT 120/2026
|
|
|
36
50
|
- Add Promise-based Toast API
|
|
37
51
|
- Add Stack Grouping
|
|
38
52
|
- Improve TypeScript Definitions
|
|
53
|
+
- !Remove UMD due to maintance reason!
|
|
39
54
|
|
|
40
55
|
v1.1.0
|
|
41
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,6 +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
|
-
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};
|
|
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,6 +1,367 @@
|
|
|
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
|
-
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};
|
|
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
|
+
:root {
|
|
8
|
+
--jt-safe-top: env(safe-area-inset-top, 0px);
|
|
9
|
+
--jt-safe-bottom: env(safe-area-inset-bottom, 0px);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
#juice-toast-root {
|
|
13
|
+
position: fixed;
|
|
14
|
+
z-index: 9999;
|
|
15
|
+
display: flex;
|
|
16
|
+
gap: 10px;
|
|
17
|
+
pointer-events: none;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* top */
|
|
21
|
+
#juice-toast-root[data-position="top"] {
|
|
22
|
+
top: 20px;
|
|
23
|
+
left: 50%;
|
|
24
|
+
transform: translateX(-50%);
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
align-items: center;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* center */
|
|
30
|
+
#juice-toast-root[data-position="center"] {
|
|
31
|
+
top: 50%;
|
|
32
|
+
left: 50%;
|
|
33
|
+
transform: translate(-50%, -50%);
|
|
34
|
+
flex-direction: column;
|
|
35
|
+
align-items: center;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
[id^="juice-toast-root-"] {
|
|
39
|
+
position: fixed;
|
|
40
|
+
z-index: 9999;
|
|
41
|
+
display: flex;
|
|
42
|
+
gap: 10px;
|
|
43
|
+
pointer-events: none;
|
|
44
|
+
padding-top: var(--jt-safe-top);
|
|
45
|
+
padding-bottom: var(--jt-safe-bottom);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
/* ================= TOAST ================= */
|
|
50
|
+
|
|
51
|
+
.juice-toast {
|
|
52
|
+
--jt-x: 0px;
|
|
53
|
+
--jt-y: 12px;
|
|
54
|
+
|
|
55
|
+
pointer-events: auto;
|
|
56
|
+
display: flex;
|
|
57
|
+
gap: 12px;
|
|
58
|
+
align-items: flex-start;
|
|
59
|
+
|
|
60
|
+
min-width: 220px;
|
|
61
|
+
max-width: 420px;
|
|
62
|
+
padding: 12px 16px;
|
|
63
|
+
margin: 6px 0;
|
|
64
|
+
|
|
65
|
+
border-radius: 8px;
|
|
66
|
+
background: #333;
|
|
67
|
+
color: #fff;
|
|
68
|
+
|
|
69
|
+
font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial;
|
|
70
|
+
font-size: 14px;
|
|
71
|
+
|
|
72
|
+
opacity: 0;
|
|
73
|
+
transform: translate(var(--jt-x), var(--jt-y));
|
|
74
|
+
transition:
|
|
75
|
+
opacity .25s ease,
|
|
76
|
+
transform .25s ease,
|
|
77
|
+
background .25s ease,
|
|
78
|
+
color .25s ease,
|
|
79
|
+
box-shadow .25s ease;
|
|
80
|
+
|
|
81
|
+
position: relative;
|
|
82
|
+
box-sizing: border-box;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
|
|
85
|
+
scroll-behavior: contains;
|
|
86
|
+
-webkit-overflow-scrolling: touch;
|
|
87
|
+
|
|
88
|
+
will-change: transform, opacity;
|
|
89
|
+
backface-visibility: hidden;
|
|
90
|
+
-webkit-backface-visibility: hidden;
|
|
91
|
+
|
|
92
|
+
touch-action: pan-y;
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* visible */
|
|
97
|
+
.juice-toast.show {
|
|
98
|
+
opacity: 1;
|
|
99
|
+
--jt-y: 0px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ================= ICON ================= */
|
|
103
|
+
|
|
104
|
+
.juice-toast .icon {
|
|
105
|
+
width: 28px;
|
|
106
|
+
height: 28px;
|
|
107
|
+
display: inline-flex;
|
|
108
|
+
align-items: center;
|
|
109
|
+
justify-content: center;
|
|
110
|
+
font-size: 16px;
|
|
111
|
+
line-height: 1;
|
|
112
|
+
flex: 0 0 28px;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* clickable icon */
|
|
116
|
+
.icon-clickable {
|
|
117
|
+
opacity: 0.85;
|
|
118
|
+
cursor: pointer;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.icon-clickable:hover {
|
|
122
|
+
opacity: 1;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.jt-message code {
|
|
126
|
+
background: rgba(255,255,255,0.1);
|
|
127
|
+
color: #facc15; /* kuning */
|
|
128
|
+
padding: 2px 4px;
|
|
129
|
+
border-radius: 4px;
|
|
130
|
+
font-family: monospace;
|
|
131
|
+
font-size: 0.9em;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* ================= CONTENT ================= */
|
|
135
|
+
|
|
136
|
+
.juice-toast .jt-content {
|
|
137
|
+
display: flex;
|
|
138
|
+
flex-direction: column;
|
|
139
|
+
gap: 4px;
|
|
140
|
+
flex: 1 1 auto;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* title */
|
|
144
|
+
.juice-toast .jt-title {
|
|
145
|
+
font-weight: 700;
|
|
146
|
+
font-size: 13px;
|
|
147
|
+
line-height: 1.1;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* message */
|
|
151
|
+
.juice-toast .jt-message {
|
|
152
|
+
font-size: 13px;
|
|
153
|
+
line-height: 1.3;
|
|
154
|
+
opacity: 0.95;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* ================= ICON POSITION ================= */
|
|
158
|
+
|
|
159
|
+
.jt-icon-top {
|
|
160
|
+
flex-direction: column;
|
|
161
|
+
align-items: flex-start;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.jt-icon-top .icon {
|
|
165
|
+
align-self: center;
|
|
166
|
+
margin-bottom: 6px;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* ================= CLOSE ================= */
|
|
170
|
+
|
|
171
|
+
.juice-toast-close {
|
|
172
|
+
position: absolute;
|
|
173
|
+
top: 6px;
|
|
174
|
+
right: 8px;
|
|
175
|
+
cursor: pointer;
|
|
176
|
+
font-size: 16px;
|
|
177
|
+
opacity: 0.75;
|
|
178
|
+
padding: 4px;
|
|
179
|
+
border-radius: 4px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.juice-toast-close:hover {
|
|
183
|
+
opacity: 1;
|
|
184
|
+
background: rgba(255,255,255,0.06);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* ================= ACTIONS ================= */
|
|
188
|
+
|
|
189
|
+
.jt-actions {
|
|
190
|
+
display: flex;
|
|
191
|
+
gap: 8px;
|
|
192
|
+
margin-top: 10px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.jt-action {
|
|
196
|
+
background: transparent;
|
|
197
|
+
border: 1px solid currentColor;
|
|
198
|
+
padding: 4px 10px;
|
|
199
|
+
border-radius: 6px;
|
|
200
|
+
cursor: pointer;
|
|
201
|
+
font-size: 12px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/* ================= COMPACT ================= */
|
|
205
|
+
|
|
206
|
+
.jt-compact {
|
|
207
|
+
padding: 8px 10px;
|
|
208
|
+
gap: 8px;
|
|
209
|
+
font-size: 0.9em;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* ================= GLASS UI ================= */
|
|
213
|
+
|
|
214
|
+
.jt-glass {
|
|
215
|
+
--g: calc(var(--jt-glass, 60) / 100);
|
|
216
|
+
|
|
217
|
+
background: rgba(30, 30, 30, calc(0.2 + var(--g)));
|
|
218
|
+
backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
219
|
+
saturate(calc(1 + (0.4 * var(--g))));
|
|
220
|
+
-webkit-backdrop-filter: blur(calc(6px + (14px * var(--g))))
|
|
221
|
+
saturate(calc(1 + (0.4 * var(--g))));
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* light theme support */
|
|
225
|
+
[data-theme="light"] .jt-glass {
|
|
226
|
+
background:
|
|
227
|
+
linear-gradient(
|
|
228
|
+
rgba(255,255,255, calc(0.6 * var(--g))),
|
|
229
|
+
rgba(255,255,255, calc(0.35 * var(--g)))
|
|
230
|
+
),
|
|
231
|
+
rgba(255,255,255, calc(0.55 - (0.25 * var(--g))));
|
|
232
|
+
|
|
233
|
+
color: #111;
|
|
234
|
+
|
|
235
|
+
border:
|
|
236
|
+
1px solid rgba(0,0,0, calc(0.05 + 0.12 * var(--g)));
|
|
237
|
+
|
|
238
|
+
box-shadow:
|
|
239
|
+
0 10px 30px rgba(0,0,0, calc(0.08 + 0.18 * var(--g))),
|
|
240
|
+
inset 0 1px 0 rgba(255,255,255, calc(0.4 * var(--g)));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/* ================= PROGRESS BAR ================= */
|
|
244
|
+
.jt-progress {
|
|
245
|
+
position: absolute;
|
|
246
|
+
left: 0;
|
|
247
|
+
bottom: 0;
|
|
248
|
+
|
|
249
|
+
height: 3px;
|
|
250
|
+
width: 100%;
|
|
251
|
+
|
|
252
|
+
background: linear-gradient(to right, #FFFFFF, #FAFAFA);
|
|
253
|
+
height: 4px;
|
|
254
|
+
transform-origin: left;
|
|
255
|
+
transition: transform linear;
|
|
256
|
+
border-radius: 2px;
|
|
257
|
+
transform: scaleX(1);
|
|
258
|
+
opacity: .85;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.juice-toast.bg-image {
|
|
262
|
+
background-size: cover;
|
|
263
|
+
background-position: center;
|
|
264
|
+
background-repeat: no-repeat;
|
|
265
|
+
color: #fff;
|
|
266
|
+
text-shadow: 0 1px 2px rgba(0,0,0,0.6);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/* ================= ANIMATIONS ================= */
|
|
270
|
+
|
|
271
|
+
@keyframes jt-spin {
|
|
272
|
+
to { transform: rotate(360deg); }
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
@keyframes jt-pulse {
|
|
276
|
+
50% { transform: scale(1.15); }
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
@keyframes jt-shake {
|
|
280
|
+
25% { transform: translateX(-3px); }
|
|
281
|
+
50% { transform: translateX(3px); }
|
|
282
|
+
75% { transform: translateX(-3px); }
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
@keyframes jt-bounce {
|
|
286
|
+
0% { transform: scale(1); }
|
|
287
|
+
30% { transform: scale(1.25); }
|
|
288
|
+
60% { transform: scale(.95); }
|
|
289
|
+
100% { transform: scale(1); }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@keyframes jt-wiggle {
|
|
293
|
+
0% { transform: rotate(0); }
|
|
294
|
+
25% { transform: rotate(-10deg); }
|
|
295
|
+
50% { transform: rotate(10deg); }
|
|
296
|
+
75% { transform: rotate(-6deg); }
|
|
297
|
+
100% { transform: rotate(0); }
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@keyframes jt-pop {
|
|
301
|
+
0% { transform: scale(.7); opacity: 0; }
|
|
302
|
+
70% { transform: scale(1.05); opacity: 1; }
|
|
303
|
+
100% { transform: scale(1); }
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@keyframes jt-spin {
|
|
307
|
+
from {
|
|
308
|
+
transform: rotate(0deg);
|
|
309
|
+
}
|
|
310
|
+
to {
|
|
311
|
+
transform: rotate(360deg);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/* ================= CLASSES ================= */
|
|
316
|
+
|
|
317
|
+
.spin { animation: jt-spin .6s linear; }
|
|
318
|
+
.pulse { animation: jt-pulse .4s ease; }
|
|
319
|
+
.shake { animation: jt-shake .4s ease; }
|
|
320
|
+
.bounce { animation: jt-bounce .45s ease; }
|
|
321
|
+
.wiggle { animation: jt-wiggle .5s ease; }
|
|
322
|
+
.pop { animation: jt-pop .35s ease-out; }
|
|
323
|
+
.spin {
|
|
324
|
+
animation: jt - spin 1 s linear infinite;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.icon-clickable {
|
|
328
|
+
cursor: pointer;
|
|
329
|
+
transition: transform .15s ease, opacity .15s ease;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
.icon-clickable:hover {
|
|
333
|
+
transform: scale(1.1);
|
|
334
|
+
opacity: .85;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/* ================= ACCESSIBILITY ================= */
|
|
338
|
+
|
|
339
|
+
@media (prefers-reduced-motion: reduce) {
|
|
340
|
+
.spin,
|
|
341
|
+
.pulse,
|
|
342
|
+
.shake,
|
|
343
|
+
.bounce,
|
|
344
|
+
.wiggle,
|
|
345
|
+
.pop {
|
|
346
|
+
animation: none !important;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "juice-toast",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4-alpha.1",
|
|
4
4
|
"description": "Lightweight, dependency-free toast notification library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"toast",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"funding": "https://patreon.com/Khairy47",
|
|
25
25
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
26
|
+
"node": ">=19"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"format": "npx prettier --write src/"
|
|
@@ -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 };
|