juice-toast 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sholehuddin Khairy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ # 🍹 JuiceToast
2
+
3
+ **JuiceToast** is a lightweight, flexible, and dependency-free toast notification library.
4
+ It supports **ESM**, **UMD**, **dynamic toast types**, **theme systems**, **queue handling**, and **backward compatibility**.
5
+
6
+ Suitable for small projects up to custom-built frameworks.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ - 🚀 Zero dependencies
13
+ - 📦 Supports **ESM** & **UMD**
14
+ - 🔁 Queue system (toasts are displayed one at a time)
15
+ - 🎨 Theme system (light / dark / custom)
16
+ - 🧩 Dynamic toast types (`success`, `error`, etc.)
17
+ - ⏳ Auto close & sticky toasts
18
+ - ❌ Closable toasts
19
+ - ⭐ Icon support with animation and link
20
+ - 🕰 Backward compatibility with legacy APIs
21
+
22
+ ---
23
+
24
+ ## 📦 Installation
25
+
26
+ ### ESM
27
+ ```js
28
+ import juiceToast from "./juice-toast.esm.js";
29
+ ```
30
+
31
+ ### UMD (Browser)
32
+ ```html
33
+ <script src="juice-toast.umd.js"></script>
34
+ <script>
35
+ juiceToast.success("Hello world!");
36
+ </script>
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 🚀 Quick Start
42
+
43
+ ```js
44
+ juiceToast.setup({
45
+ success: {
46
+ icon: "check",
47
+ theme: "light",
48
+ duration: 2000
49
+ },
50
+ error: {
51
+ icon: "x",
52
+ bg: "#7f1d1d",
53
+ color: "#fff",
54
+ closable: true
55
+ }
56
+ });
57
+
58
+ juiceToast.success("Success!");
59
+ juiceToast.error({ title: "Error", message: "An error has occurred" });
60
+ ```
61
+
62
+ ---
63
+
64
+ ## 🧠 Core Concept
65
+
66
+ ### Toast Types
67
+ Toasts are triggered based on **types** defined via `setup()` or `addType()`.
68
+
69
+ ```js
70
+ juiceToast.info("Hello");
71
+ juiceToast.warning({ message: "Be careful", duration: 4000 });
72
+ ```
73
+
74
+ ---
75
+
76
+ ## ⚙️ API
77
+
78
+ ### `setup(config)`
79
+ Register all toast types.
80
+
81
+ ```js
82
+ juiceToast.setup({
83
+ success: { bg: "green" },
84
+ error: { bg: "red" }
85
+ });
86
+ ```
87
+
88
+ ---
89
+
90
+ ### `addType(name, config)`
91
+ Add a toast type dynamically.
92
+
93
+ ```js
94
+ juiceToast.addType("warning", {
95
+ bg: "#facc15",
96
+ color: "#111"
97
+ });
98
+ ```
99
+
100
+ ---
101
+
102
+ ### `defineTheme(name, styles)`
103
+ Create or override a theme.
104
+
105
+ ```js
106
+ juiceToast.defineTheme("ocean", {
107
+ bg: "#0ea5e9",
108
+ color: "#fff",
109
+ border: "1px solid #0284c7"
110
+ });
111
+ ```
112
+
113
+ ---
114
+
115
+ ### `setTheme(name)`
116
+ Set the global theme.
117
+
118
+ ```js
119
+ juiceToast.setTheme("dark");
120
+ ```
121
+
122
+ ---
123
+
124
+ ### `clear()`
125
+ Clear all toast queues.
126
+
127
+ ```js
128
+ juiceToast.clear();
129
+ ```
130
+
131
+ ---
132
+
133
+ ### `destroy()`
134
+ Remove all queues and the root DOM element.
135
+
136
+ ```js
137
+ juiceToast.destroy();
138
+ ```
139
+
140
+ ---
141
+
142
+ ## 🧾 Toast Payload
143
+
144
+ ```ts
145
+ interface ToastPayload {
146
+ message?: string;
147
+ title?: string;
148
+
149
+ bg?: string;
150
+ color?: string;
151
+ border?: string;
152
+ glow?: string;
153
+ theme?: string;
154
+
155
+ duration?: number; // ms, 0 = sticky
156
+ position?: "top" | "center" | "bottom";
157
+ toast?: "top" | "center" | "bottom"; // backward compatibility
158
+ closable?: boolean;
159
+ closeable?: boolean; // backward compatibility
160
+
161
+ icon?: string;
162
+ iconPack?: string;
163
+ iconLink?: string;
164
+ iconAnimate?: string;
165
+
166
+ [key: string]: any;
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ## 🎯 Full Example
173
+
174
+ ```js
175
+ juiceToast.success({
176
+ title: "Login",
177
+ message: "Successfully logged in!",
178
+ icon: "check-circle",
179
+ iconPack: "fa-solid",
180
+ iconAnimate: "shake",
181
+ iconLink: "https://example.com",
182
+ duration: 3000,
183
+ position: "top",
184
+ closable: true
185
+ });
186
+ ```
187
+
188
+ ---
189
+
190
+ ## 🔄 Backward Compatibility
191
+
192
+ JuiceToast automatically supports legacy APIs:
193
+
194
+ | Legacy | Current |
195
+ |------|---------|
196
+ | `toast` | `position` |
197
+ | `closeable` | `closable` |
198
+ | `icon_left_top` | `icon` |
199
+ | `icon_config` | `iconPack` |
200
+ | `icon_onClick_url` | `iconLink` |
201
+ | `icon_onClick_animate` | `iconAnimate` |
202
+
203
+ ---
204
+
205
+ ## 🎨 Default Themes
206
+
207
+ ```js
208
+ light: {
209
+ bg: "#ffffff",
210
+ color: "#111",
211
+ border: "1px solid #e5e7eb"
212
+ }
213
+
214
+ dark: {
215
+ bg: "#1f2937",
216
+ color: "#fff",
217
+ border: "1px solid rgba(255,255,255,.08)"
218
+ }
219
+ ```
220
+
221
+ ---
222
+
223
+ ## 📌 Notes
224
+
225
+ - Not compatible with SSR (DOM required)
226
+ - Root element is automatically created: `#juice-toast-root`
227
+
228
+ ---
229
+
230
+ ## 📄 License
231
+
232
+ MIT © JuiceToast
@@ -0,0 +1,65 @@
1
+ export type ToastPosition = "top" | "center" | "bottom";
2
+
3
+ export interface ToastTheme {
4
+ bg ? : string;
5
+ color ? : string;
6
+ border ? : string;
7
+ glow ? : string;
8
+ }
9
+
10
+ export interface ToastPayload {
11
+ /* CONTENT */
12
+ message ? : string;
13
+ title ? : string;
14
+
15
+ /* STYLE */
16
+ bg ? : string;
17
+ color ? : string;
18
+ border ? : string;
19
+ glow ? : string;
20
+ theme ? : string;
21
+
22
+ /* BEHAVIOR */
23
+ duration ? : number; // ms, 0 = sticky
24
+ position ? : ToastPosition;
25
+ toast ? : ToastPosition; // backward compat
26
+ closable ? : boolean;
27
+ closeable ? : boolean; // backward compat
28
+
29
+ /* ICON (Fontic / others) */
30
+ icon ? : string;
31
+ icon_left_top ? : string; // backward compat
32
+ icon_config ? : string; // backward compat
33
+ iconPack ? : string;
34
+
35
+ iconLink ? : string;
36
+ iconAnimate ? : string;
37
+
38
+ /* any future extension */
39
+ [key: string]: any;
40
+ }
41
+
42
+ export interface ToastTypeConfig extends ToastPayload {}
43
+
44
+ export interface JuiceToastAPI {
45
+ /* ===== SETUP ===== */
46
+ setup(config: Record < string, ToastTypeConfig > ): void;
47
+ addType(name: string, config ? : ToastTypeConfig): void;
48
+
49
+ /* ===== THEME ===== */
50
+ defineTheme(name: string, styles: ToastTheme): void;
51
+ setTheme(name: string): void;
52
+
53
+ /* ===== QUEUE ===== */
54
+ clear(): void;
55
+ destroy(): void;
56
+
57
+ /* ===== DYNAMIC METHODS ===== */
58
+ [type: string]: ((payload ? : string | number | ToastPayload) => void) | any;
59
+ }
60
+
61
+ /* ===== DEFAULT EXPORT ===== */
62
+ declare const juiceToast: JuiceToastAPI;
63
+
64
+ export default juiceToast;
65
+ export { juiceToast };
@@ -0,0 +1,2 @@
1
+ const c=typeof window!="undefined"&&typeof document!="undefined",l={light:{bg:"#ffffff",color:"#111",border:"1px solid #e5e7eb"},dark:{bg:"#1f2937",color:"#fff",border:"1px solid rgba(255,255,255,.08)"}},k={_config:{},_queue:[],_showing:!1,_theme:"dark",setup(t={}){this._config=t,this._registerTypes()},addType(t,o={}){this._config[t]=o,this._registerTypes()},defineTheme(t,o={}){l[t]={...l[t]||{},...o}},setTheme(t){if(this._theme=t,!c)return;const o=document.getElementById("juice-toast-root");o&&(o.dataset.theme=t)},clear(){this._queue.length=0},destroy(){var t;this.clear(),c&&((t=document.getElementById("juice-toast-root"))==null||t.remove())},_registerTypes(){Object.keys(this._config).forEach(t=>{if(typeof this[t]=="function"&&!this[t].__auto)return;const o=a=>this._enqueue(t,a);o.__auto=!0,this[t]=o})},_enqueue(t,o){this._queue.push({type:t,payload:o}),this._showing||this._next()},_next(){if(!this._queue.length){this._showing=!1;return}this._showing=!0;const t=this._queue.shift();this._showToast(t.type,t.payload)},_getRoot(t){if(!c)return null;let o=document.getElementById("juice-toast-root");return o||(o=document.createElement("div"),o.id="juice-toast-root",document.body.appendChild(o)),o.dataset.position=t||"bottom",o.dataset.theme=this._theme,o},_showToast(t,o){var h,u,f,_,p,g,b;if(!c)return;const a=this._config[t]||{},y=typeof o=="object"?o:{message:String(o)},e={...a,...y};e.icon=(h=e.icon)!=null?h:e.icon_left_top,e.iconPack=(u=e.iconPack)!=null?u:e.icon_config,e.iconLink=(f=e.iconLink)!=null?f:e.icon_onClick_url,e.iconAnimate=(_=e.iconAnimate)!=null?_:e.icon_onClick_animate,e.position=(p=e.position)!=null?p:e.toast,e.closable=(g=e.closable)!=null?g:e.closeable;const r=l[e.theme||this._theme]||{},n=document.createElement("div");if(n.className="juice-toast",n.style.background=e.bg||r.bg,n.style.color=e.color||r.color,n.style.border=e.border||r.border,e.icon){const i=document.createElement("i");i.className=["icon",e.iconPack||"",e.icon].join(" ").trim(),(e.iconLink||e.iconAnimate)&&(i.classList.add("icon-clickable"),i.onclick=j=>{j.stopPropagation(),e.iconAnimate&&(i.classList.remove(e.iconAnimate),i.offsetWidth,i.classList.add(e.iconAnimate)),e.iconLink&&window.open(e.iconLink,"_blank","noopener")}),n.appendChild(i)}const s=document.createElement("div");if(s.className="jt-content",e.title){const i=document.createElement("div");i.className="jt-title",i.textContent=e.title,s.appendChild(i)}const d=document.createElement("div");if(d.className="jt-message",d.textContent=e.message||"",s.appendChild(d),n.appendChild(s),e.closable){const i=document.createElement("span");i.className="juice-toast-close",i.innerHTML="\xD7",i.onclick=()=>{n.remove(),this._next()},n.appendChild(i)}this._getRoot(e.position).appendChild(n),requestAnimationFrame(()=>n.classList.add("show"));const m=(b=e.duration)!=null?b:2500;m!==0&&setTimeout(()=>{n.classList.remove("show"),setTimeout(()=>{n.remove(),this._next()},300)},m)}};var T=k;export{T as default,k as juiceToast};
2
+ //# sourceMappingURL=juice-toast.esm.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/juice-toast.esm.src.js"],
4
+ "sourcesContent": ["const isBrowser =\n typeof window !== \"undefined\" &&\n typeof document !== \"undefined\";\n\n/* ================= THEME REGISTRY ================= */\n\nconst themes = {\n light: {\n bg: \"#ffffff\",\n color: \"#111\",\n border: \"1px solid #e5e7eb\"\n },\n dark: {\n bg: \"#1f2937\",\n color: \"#fff\",\n border: \"1px solid rgba(255,255,255,.08)\"\n }\n};\n\n/* ================= CORE ================= */\n\nconst juiceToast = {\n _config: {},\n _queue: [],\n _showing: false,\n _theme: \"dark\",\n \n /* ===== PUBLIC API ===== */\n \n setup(cfg = {}) {\n this._config = cfg;\n this._registerTypes();\n },\n \n addType(name, cfg = {}) {\n this._config[name] = cfg;\n this._registerTypes();\n },\n \n defineTheme(name, styles = {}) {\n themes[name] = { ...(themes[name] || {}), ...styles };\n },\n \n setTheme(name) {\n this._theme = name;\n if (!isBrowser) return;\n const root = document.getElementById(\"juice-toast-root\");\n if (root) root.dataset.theme = name;\n },\n \n clear() {\n this._queue.length = 0;\n },\n \n destroy() {\n this.clear();\n if (!isBrowser) return;\n document.getElementById(\"juice-toast-root\")?.remove();\n },\n \n /* ===== INTERNAL ===== */\n \n _registerTypes() {\n Object.keys(this._config).forEach(type => {\n if (typeof this[type] === \"function\" && !this[type].__auto) return;\n const fn = payload => this._enqueue(type, payload);\n fn.__auto = true;\n this[type] = fn;\n });\n },\n \n _enqueue(type, payload) {\n this._queue.push({ type, payload });\n if (!this._showing) this._next();\n },\n \n _next() {\n if (!this._queue.length) {\n this._showing = false;\n return;\n }\n this._showing = true;\n const item = this._queue.shift();\n this._showToast(item.type, item.payload);\n },\n \n _getRoot(position) {\n if (!isBrowser) return null;\n let root = document.getElementById(\"juice-toast-root\");\n if (!root) {\n root = document.createElement(\"div\");\n root.id = \"juice-toast-root\";\n document.body.appendChild(root);\n }\n root.dataset.position = position || \"bottom\";\n root.dataset.theme = this._theme;\n return root;\n },\n \n _showToast(type, payload) {\n if (!isBrowser) return;\n \n const base = this._config[type] || {};\n const data =\n typeof payload === \"object\" ?\n payload :\n { message: String(payload) };\n \n const cfg = { ...base, ...data };\n \n /* BACKWARD COMPAT */\n cfg.icon = cfg.icon ?? cfg.icon_left_top;\n cfg.iconPack = cfg.iconPack ?? cfg.icon_config;\n cfg.iconLink = cfg.iconLink ?? cfg.icon_onClick_url;\n cfg.iconAnimate = cfg.iconAnimate ?? cfg.icon_onClick_animate;\n cfg.position = cfg.position ?? cfg.toast;\n cfg.closable = cfg.closable ?? cfg.closeable;\n \n const theme = themes[cfg.theme || this._theme] || {};\n \n const toast = document.createElement(\"div\");\n toast.className = \"juice-toast\";\n toast.style.background = cfg.bg || theme.bg;\n toast.style.color = cfg.color || theme.color;\n toast.style.border = cfg.border || theme.border;\n \n /* ICON */\n if (cfg.icon) {\n const icon = document.createElement(\"i\");\n icon.className = [\n \"icon\",\n cfg.iconPack || \"\",\n cfg.icon\n ].join(\" \").trim();\n \n if (cfg.iconLink || cfg.iconAnimate) {\n icon.classList.add(\"icon-clickable\");\n icon.onclick = e => {\n e.stopPropagation();\n if (cfg.iconAnimate) {\n icon.classList.remove(cfg.iconAnimate);\n void icon.offsetWidth;\n icon.classList.add(cfg.iconAnimate);\n }\n if (cfg.iconLink) {\n window.open(cfg.iconLink, \"_blank\", \"noopener\");\n }\n };\n }\n toast.appendChild(icon);\n }\n \n /* CONTENT */\n const content = document.createElement(\"div\");\n content.className = \"jt-content\";\n \n if (cfg.title) {\n const t = document.createElement(\"div\");\n t.className = \"jt-title\";\n t.textContent = cfg.title;\n content.appendChild(t);\n }\n \n const msg = document.createElement(\"div\");\n msg.className = \"jt-message\";\n msg.textContent = cfg.message || \"\";\n content.appendChild(msg);\n \n toast.appendChild(content);\n \n /* CLOSE */\n if (cfg.closable) {\n const close = document.createElement(\"span\");\n close.className = \"juice-toast-close\";\n close.innerHTML = \"\u00D7\";\n close.onclick = () => {\n toast.remove();\n this._next();\n };\n toast.appendChild(close);\n }\n \n const root = this._getRoot(cfg.position);\n root.appendChild(toast);\n \n requestAnimationFrame(() => toast.classList.add(\"show\"));\n \n const duration = cfg.duration ?? 2500;\n if (duration === 0) return;\n \n setTimeout(() => {\n toast.classList.remove(\"show\");\n setTimeout(() => {\n toast.remove();\n this._next();\n }, 300);\n }, duration);\n }\n};\n\nexport default juiceToast;\nexport { juiceToast };\n"],
5
+ "mappings": "AAAA,MAAMA,EACJ,OAAO,QAAW,aAClB,OAAO,UAAa,YAIhBC,EAAS,CACb,MAAO,CACL,GAAI,UACJ,MAAO,OACP,OAAQ,mBACV,EACA,KAAM,CACJ,GAAI,UACJ,MAAO,OACP,OAAQ,iCACV,CACF,EAIMC,EAAa,CAC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,KAAK,MAAM,CACb,EAAG,GAAG,CACR,EAAGO,CAAQ,CACb,CACF,EAEA,IAAOC,EAAQ5B",
6
+ "names": ["isBrowser", "themes", "juiceToast", "cfg", "name", "styles", "root", "_a", "type", "fn", "payload", "item", "position", "_b", "_c", "_d", "_e", "_f", "_g", "base", "data", "theme", "toast", "icon", "e", "content", "t", "msg", "close", "duration", "juice_toast_esm_src_default"]
7
+ }
@@ -0,0 +1,2 @@
1
+ var juiceToast=(()=>{(function(c,s){typeof define=="function"&&define.amd?define([],s):typeof module=="object"&&module.exports?module.exports=s():c.juiceToast=s()})(void 0,function(){return(function(){const c=typeof window!="undefined"&&typeof document!="undefined",s={light:{bg:"#fff",color:"#111",border:"1px solid #e5e7eb"},dark:{bg:"#1f2937",color:"#fff",border:"1px solid rgba(255,255,255,.08)"}};return{_config:{},_queue:[],_showing:!1,_theme:"dark",setup(t={}){this._config=t,this._registerTypes()},addType(t,o={}){this._config[t]=o,this._registerTypes()},defineTheme(t,o={}){s[t]={...s[t]||{},...o}},setTheme(t){if(this._theme=t,!c)return;const o=document.getElementById("juice-toast-root");o&&(o.dataset.theme=t)},clear(){this._queue.length=0},destroy(){var t;this.clear(),c&&((t=document.getElementById("juice-toast-root"))==null||t.remove())},_registerTypes(){Object.keys(this._config).forEach(t=>{if(typeof this[t]=="function"&&!this[t].__auto)return;const o=r=>this._enqueue(t,r);o.__auto=!0,this[t]=o})},_enqueue(t,o){this._queue.push({type:t,payload:o}),this._showing||this._next()},_next(){if(!this._queue.length){this._showing=!1;return}this._showing=!0;const t=this._queue.shift();this._showToast(t.type,t.payload)},_getRoot(t){if(!c)return null;let o=document.getElementById("juice-toast-root");return o||(o=document.createElement("div"),o.id="juice-toast-root",document.body.appendChild(o)),o.dataset.position=t||"bottom",o.dataset.theme=this._theme,o},_showToast(t,o){var m,h,f,_,p,g,b;if(!c)return;const r=this._config[t]||{},k=typeof o=="object"?o:{message:String(o)},e={...r,...k};e.icon=(m=e.icon)!=null?m:e.icon_left_top,e.iconPack=(h=e.iconPack)!=null?h:e.icon_config,e.iconLink=(f=e.iconLink)!=null?f:e.icon_onClick_url,e.iconAnimate=(_=e.iconAnimate)!=null?_:e.icon_onClick_animate,e.position=(p=e.position)!=null?p:e.toast,e.closable=(g=e.closable)!=null?g:e.closeable;const d=s[e.theme||this._theme]||{},n=document.createElement("div");if(n.className="juice-toast",n.style.background=e.bg||d.bg,n.style.color=e.color||d.color,n.style.border=e.border||d.border,e.icon){const i=document.createElement("i");i.className=["icon",e.iconPack||"",e.icon].join(" ").trim(),(e.iconLink||e.iconAnimate)&&(i.classList.add("icon-clickable"),i.onclick=j=>{j.stopPropagation(),e.iconAnimate&&(i.classList.remove(e.iconAnimate),i.offsetWidth,i.classList.add(e.iconAnimate)),e.iconLink&&window.open(e.iconLink,"_blank","noopener")}),n.appendChild(i)}const a=document.createElement("div");if(a.className="jt-content",e.title){const i=document.createElement("div");i.className="jt-title",i.textContent=e.title,a.appendChild(i)}const l=document.createElement("div");if(l.className="jt-message",l.textContent=e.message||"",a.appendChild(l),n.appendChild(a),e.closable){const i=document.createElement("span");i.className="juice-toast-close",i.innerHTML="\xD7",i.onclick=()=>{n.remove(),this._next()},n.appendChild(i)}this._getRoot(e.position).appendChild(n),requestAnimationFrame(()=>n.classList.add("show"));const u=(b=e.duration)!=null?b:2500;u!==0&&setTimeout(()=>{n.classList.remove("show"),setTimeout(()=>{n.remove(),this._next()},300)},u)}}})()});})();
2
+ //# sourceMappingURL=juice-toast.umd.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/juice-toast.umd.src.js"],
4
+ "sourcesContent": ["(function(root, factory) {\n if (typeof define === \"function\" && define.amd) {\n define([], factory);\n } else if (typeof module === \"object\" && module.exports) {\n module.exports = factory();\n } else {\n root.juiceToast = factory();\n }\n})(this, function() {\n return (function() {\n \n const isBrowser =\n typeof window !== \"undefined\" &&\n typeof document !== \"undefined\";\n \n const themes = {\n light: { bg: \"#fff\", color: \"#111\", border: \"1px solid #e5e7eb\" },\n dark: { bg: \"#1f2937\", color: \"#fff\", border: \"1px solid rgba(255,255,255,.08)\" }\n };\n \n const api = { \n _config: {},\n _queue: [],\n _showing: false,\n _theme: \"dark\",\n \n /* ===== PUBLIC API ===== */\n \n setup(cfg = {}) {\n this._config = cfg;\n this._registerTypes();\n },\n \n addType(name, cfg = {}) {\n this._config[name] = cfg;\n this._registerTypes();\n },\n \n defineTheme(name, styles = {}) {\n themes[name] = { ...(themes[name] || {}), ...styles };\n },\n \n setTheme(name) {\n this._theme = name;\n if (!isBrowser) return;\n const root = document.getElementById(\"juice-toast-root\");\n if (root) root.dataset.theme = name;\n },\n \n clear() {\n this._queue.length = 0;\n },\n \n destroy() {\n this.clear();\n if (!isBrowser) return;\n document.getElementById(\"juice-toast-root\")?.remove();\n },\n \n /* ===== INTERNAL ===== */\n \n _registerTypes() {\n Object.keys(this._config).forEach(type => {\n if (typeof this[type] === \"function\" && !this[type].__auto) return;\n const fn = payload => this._enqueue(type, payload);\n fn.__auto = true;\n this[type] = fn;\n });\n },\n \n _enqueue(type, payload) {\n this._queue.push({ type, payload });\n if (!this._showing) this._next();\n },\n \n _next() {\n if (!this._queue.length) {\n this._showing = false;\n return;\n }\n this._showing = true;\n const item = this._queue.shift();\n this._showToast(item.type, item.payload);\n },\n \n _getRoot(position) {\n if (!isBrowser) return null;\n let root = document.getElementById(\"juice-toast-root\");\n if (!root) {\n root = document.createElement(\"div\");\n root.id = \"juice-toast-root\";\n document.body.appendChild(root);\n }\n root.dataset.position = position || \"bottom\";\n root.dataset.theme = this._theme;\n return root;\n },\n \n _showToast(type, payload) {\n if (!isBrowser) return;\n \n const base = this._config[type] || {};\n const data =\n typeof payload === \"object\" ?\n payload :\n { message: String(payload) };\n \n const cfg = { ...base, ...data };\n \n /* BACKWARD COMPAT */\n cfg.icon = cfg.icon ?? cfg.icon_left_top;\n cfg.iconPack = cfg.iconPack ?? cfg.icon_config;\n cfg.iconLink = cfg.iconLink ?? cfg.icon_onClick_url;\n cfg.iconAnimate = cfg.iconAnimate ?? cfg.icon_onClick_animate;\n cfg.position = cfg.position ?? cfg.toast;\n cfg.closable = cfg.closable ?? cfg.closeable;\n \n const theme = themes[cfg.theme || this._theme] || {};\n \n const toast = document.createElement(\"div\");\n toast.className = \"juice-toast\";\n toast.style.background = cfg.bg || theme.bg;\n toast.style.color = cfg.color || theme.color;\n toast.style.border = cfg.border || theme.border;\n \n /* ICON */\n if (cfg.icon) {\n const icon = document.createElement(\"i\");\n icon.className = [\n \"icon\",\n cfg.iconPack || \"\",\n cfg.icon\n ].join(\" \").trim();\n \n if (cfg.iconLink || cfg.iconAnimate) {\n icon.classList.add(\"icon-clickable\");\n icon.onclick = e => {\n e.stopPropagation();\n if (cfg.iconAnimate) {\n icon.classList.remove(cfg.iconAnimate);\n void icon.offsetWidth;\n icon.classList.add(cfg.iconAnimate);\n }\n if (cfg.iconLink) {\n window.open(cfg.iconLink, \"_blank\", \"noopener\");\n }\n };\n }\n toast.appendChild(icon);\n }\n \n /* CONTENT */\n const content = document.createElement(\"div\");\n content.className = \"jt-content\";\n \n if (cfg.title) {\n const t = document.createElement(\"div\");\n t.className = \"jt-title\";\n t.textContent = cfg.title;\n content.appendChild(t);\n }\n \n const msg = document.createElement(\"div\");\n msg.className = \"jt-message\";\n msg.textContent = cfg.message || \"\";\n content.appendChild(msg);\n \n toast.appendChild(content);\n \n /* CLOSE */\n if (cfg.closable) {\n const close = document.createElement(\"span\");\n close.className = \"juice-toast-close\";\n close.innerHTML = \"\u00D7\";\n close.onclick = () => {\n toast.remove();\n this._next();\n };\n toast.appendChild(close);\n }\n \n const root = this._getRoot(cfg.position);\n root.appendChild(toast);\n \n requestAnimationFrame(() => toast.classList.add(\"show\"));\n \n const duration = cfg.duration ?? 2500;\n if (duration === 0) return;\n \n setTimeout(() => {\n toast.classList.remove(\"show\");\n setTimeout(() => {\n toast.remove();\n this._next();\n }, 300);\n }, duration);\n } \n};\n \n return api;\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,MAAMwB,EAAQ,SAAS,cAAc,MAAM,EAC3CA,EAAM,UAAY,oBAClBA,EAAM,UAAY,OAClBA,EAAM,QAAU,IAAM,CACpBN,EAAM,OAAO,EACb,KAAK,MAAM,CACb,EACAA,EAAM,YAAYM,CAAK,CACzB,CAEa,KAAK,SAASxB,EAAI,QAAQ,EAClC,YAAYkB,CAAK,EAEtB,sBAAsB,IAAMA,EAAM,UAAU,IAAI,MAAM,CAAC,EAEvD,MAAMO,GAAWX,EAAAd,EAAI,WAAJ,KAAAc,EAAgB,KAC7BW,IAAa,GAEjB,WAAW,IAAM,CACfP,EAAM,UAAU,OAAO,MAAM,EAC7B,WAAW,IAAM,CACfA,EAAM,OAAO,EACb,KAAK,MAAM,CACb,EAAG,GAAG,CACR,EAAGO,CAAQ,CACb,CACF,CAGE,GAAG,CACL,CAAC",
6
+ "names": ["root", "factory", "isBrowser", "themes", "cfg", "name", "styles", "_a", "type", "fn", "payload", "item", "position", "_b", "_c", "_d", "_e", "_f", "_g", "base", "data", "theme", "toast", "icon", "e", "content", "t", "msg", "close", "duration"]
7
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "juice-toast",
3
+ "version": "1.0.0",
4
+ "description": "Lightweight, dependency-free toast notification library",
5
+ "keywords": [
6
+ "toast",
7
+ "notification",
8
+ "ui"
9
+ ],
10
+ "license": "MIT",
11
+ "author": "KhairyK",
12
+ "homepage": "https://github.com/KhairyK/juiceToast",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/KhairyK/juiceToast.git"
16
+ },
17
+ "main": "dist/juice-toast.umd.js",
18
+ "module": "dist/juice-toast.esm.js",
19
+ "types": "dist/juice-toast.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "require": "./dist/juice-toast.umd.js",
23
+ "import": "./dist/juice-toast.esm.js",
24
+ "types": "./dist/juice-toast.d.ts"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "sideEffects": false,
31
+ "scripts": {
32
+ "build": "node build.js"
33
+ },
34
+ "devDependencies": {
35
+ "esbuild": "^0.27.2"
36
+ }
37
+ }