customizable-toast-notification 3.2.0 β†’ 3.3.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/README.md CHANGED
@@ -193,3 +193,9 @@ Contributions are welcome! Please read the [CONTRIBUTING.md]() for details on ou
193
193
  ## License
194
194
 
195
195
  This project is licensed under the Apache-2.0 License - see the [LICENSE.md](LICENSE) file for details.
196
+
197
+ ## πŸ‘¨β€πŸ’» Author
198
+
199
+ Made with ❀️ by [Priyanshu Patel](https://github.com/sammy-cool/customizable-toast-notification)
200
+
201
+ Feel free to ⭐ this repository if you found it helpful!
@@ -2,17 +2,19 @@
2
2
  * @fileoverview A simple toast notification library for any JavaScript framework.
3
3
  * @name Customizable Toast Notifications
4
4
  * @author Priyanshu Patel
5
- * @version 1.0.0
5
+ * @version "3.2.0"
6
+ * @build Production
6
7
  * @license Apache-2.0
7
8
  * @depends None
8
- * @description This library provides a simple way to create toast notifications.
9
+ * @description A lightweight and fully customizable toast notification library
10
+ * designed for seamless integration with any JavaScript or framework-based UI.
11
+ * Supports flexible positioning, theming, icons, animations, and timing options
12
+ * out of the box β€” with zero dependencies.
9
13
  * Author: Priyanshu Patel
10
14
  * Email: priyanshu.alt191@gmail.com
11
15
  * Created: July 31, 2024
12
- * Description: A simple toast notification library for any JavaScript framework.
13
- * Version: 1.0.0
14
16
  * License: Apache-2.0
15
17
  * Dependencies: None
16
18
  */
17
- let t={info:"blue",success:"green",error:"red",warning:"darkorange"},e={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},n=!1;function o(t,e,o,i,s,r){const a=document.createElement("div");return a.textContent=t,a.style.background=e,a.style.color=o,a.style.padding="10px 20px",a.style.marginTop="10px",a.style.borderRadius="5px",a.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",a.style.opacity="0",a.style.transition=`opacity ${i} ${s}`,r&&function(t,e){const o=document.createElement("button");o.textContent="Γ—",o.style.marginLeft="10px",o.style.background="transparent",o.style.border="none",o.style.color=e,o.style.cursor="pointer",o.onclick=()=>{t.style.opacity="0",t.addEventListener("transitionend",()=>{t.remove(),n=!1})},t.appendChild(o)}(a,o),a}function i({message:i,duration:s,position:r,type:a,backgroundColor:l,textColor:c,showCloseButton:d,animationDuration:u,animationEasing:p}){if(n)return;n=!0;const y=i||e[a]||"This is a default message.",m=l||t[a]||"gray",g=c||("white"===m?"black":"white"),f=function(t){let e=document.getElementById(`toast-container-${t}`);return e||(e=document.createElement("div"),e.id=`toast-container-${t}`,e.style.position="fixed",e.style.zIndex="9999",function(t,e){e.includes("bottom")?t.style.bottom="10px":e.includes("top")&&(t.style.top="10px"),e.includes("right")?t.style.right="10px":e.includes("left")?t.style.left="10px":e.includes("center")&&(t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)")}(e,t),document.body.appendChild(e)),e}(r),b=o(y,m,g,u||"0.5s",p||"ease",d);f.appendChild(b),requestAnimationFrame(()=>{b.style.opacity="1"}),setTimeout(()=>{b.parentNode&&(b.style.opacity="0",b.addEventListener("transitionend",()=>{b.remove(),n=!1}))},s||3e3)}function s(t){if("object"!=typeof t)return;const{message:e,duration:n,position:o="bottom-right",type:s="info",backgroundColor:r,textColor:a,showCloseButton:l=!1,animationDuration:c,animationEasing:d}=t;i({message:e,duration:n||3e3,position:o,type:s,backgroundColor:r,textColor:a,showCloseButton:l,animationDuration:c,animationEasing:d})}function r(e){"object"==typeof e&&Object.assign(t,e)}function a(t){"object"==typeof t&&Object.assign(e,t)}export{s as createToast,r as setDefaultColors,a as setDefaultMessages};
19
+ let t={info:"blue",success:"green",error:"red",warning:"darkorange"},e={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},o=!1;function n(t,e,n,s,i,r,a,l,c,d,p){const u=document.createElement("div");if(u.textContent=t,u.style.background=e,u.style.color=n,u.style.padding="10px 20px",u.style.marginTop="10px",u.style.borderRadius="5px",u.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",u.style.opacity="0",u.style.transition=`opacity ${s} ${i}`,u.style.position="relative",u.style.overflow="hidden",r&&function(t,e){const n=document.createElement("button");n.textContent="Γ—",n.style.marginLeft="10px",n.style.background="transparent",n.style.border="none",n.style.color=e,n.style.cursor="pointer",n.onclick=()=>{t.style.opacity="0",t.addEventListener("transitionend",()=>{t.remove(),o=!1})},t.appendChild(n)}(u,n),a){const t=document.createElement("div");t.style.position="absolute",t.style["top"===d?"top":"bottom"]="0",t.style.left="0",t.style.height=c||"4px",t.style.backgroundColor=l||n,t.style.width="100%",t.style.transition=`width ${p}ms linear`,requestAnimationFrame(()=>{t.style.width="0%"}),u.appendChild(t)}return u}function s({message:s,duration:i,position:r,type:a,backgroundColor:l,textColor:c,showCloseButton:d,animationDuration:p,animationEasing:u,showProgressBar:y,progressColor:g,progressHeight:m,progressPosition:f}){if(o)return;o=!0;const h=s||e[a]||"This is a default message.",b=l||t[a]||"gray",x=c||("white"===b?"black":"white"),C=function(t){let e=document.getElementById(`toast-container-${t}`);return e||(e=document.createElement("div"),e.id=`toast-container-${t}`,e.style.position="fixed",e.style.zIndex="9999",function(t,e){e.includes("bottom")?t.style.bottom="10px":e.includes("top")&&(t.style.top="10px"),e.includes("right")?t.style.right="10px":e.includes("left")?t.style.left="10px":e.includes("center")&&(t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)")}(e,t),document.body.appendChild(e)),e}(r),w=n(h,b,x,p||"0.5s",u||"ease",d,y,g,m,f,i||3e3);C.appendChild(w),requestAnimationFrame(()=>{w.style.opacity="1"}),setTimeout(()=>{w.parentNode&&(w.style.opacity="0",w.addEventListener("transitionend",()=>{w.remove(),o=!1}))},i||3e3)}function i(t){if("object"!=typeof t)return;const{message:e,duration:o,position:n="bottom-right",type:i="info",backgroundColor:r,textColor:a,showCloseButton:l=!1,animationDuration:c,animationEasing:d,showProgressBar:p=!1,progressColor:u,progressHeight:y="4px",progressPosition:g="bottom"}=t;s({message:e,duration:o||3e3,position:n,type:i,backgroundColor:r,textColor:a,showCloseButton:l,animationDuration:c,animationEasing:d,showProgressBar:p,progressColor:u,progressHeight:y,progressPosition:g})}function r(e){"object"==typeof e&&Object.assign(t,e)}function a(t){"object"==typeof t&&Object.assign(e,t)}export{i as createToast,r as setDefaultColors,a as setDefaultMessages};
18
20
  //# sourceMappingURL=index.esm.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.mjs","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n}) {\r\n if (isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\"; // Fade in effect\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\"; // Fade out effect\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n // Validate options\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n } = options;\r\n\r\n // Validate duration\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","showToast","message","duration","position","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","left","transform","setPosition","body","createToastContainer","requestAnimationFrame","setTimeout","parentNode","createToast","options","setDefaultColors","newColors","Object","assign","setDefaultMessages","newMessages"],"mappings":";;;;;;;;;;;;;;;;AAuCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAerC,OAdAF,EAAMG,YAAcT,EACpBM,EAAMI,MAAMC,WAAaV,EACzBK,EAAMI,MAAME,MAAQV,EACpBI,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,aAAe,MAC3BT,EAAMI,MAAMM,UAAY,8BACxBV,EAAMI,MAAMO,QAAU,IACtBX,EAAMI,MAAMQ,WAAa,WAAWf,KAAqBC,IAErDC,GAON,SAAwBC,EAAOJ,GAC7B,MAAMiB,EAAcZ,SAASC,cAAc,UAC3CW,EAAYV,YAAc,IAC1BU,EAAYT,MAAMU,WAAa,OAC/BD,EAAYT,MAAMC,WAAa,cAC/BQ,EAAYT,MAAMW,OAAS,OAC3BF,EAAYT,MAAME,MAAQV,EAC1BiB,EAAYT,MAAMY,OAAS,UAE3BH,EAAYI,QAAU,KACpBjB,EAAMI,MAAMO,QAAU,IACtBX,EAAMkB,iBAAiB,gBAAiB,KACtClB,EAAMmB,SACN3B,GAAiB,KAIrBQ,EAAMoB,YAAYP,EACpB,CAxBIQ,CAAerB,EAAOJ,GAGjBI,CACT,CAsBA,S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B,EAAYC,GAEnB,GAAuB,iBAAZA,EAET,OAGF,MAAMxB,QACJA,EAAOC,SACPA,EAAQC,SACRA,EAAW,eAAcC,KACzBA,EAAO,OAAM/B,gBACbA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,GACEiD,EAOJzB,EAAU,CACRC,UACAC,SAAUA,GAAY,IACtBC,WACAC,OACA/B,kBACAC,YACAG,kBACAF,oBACAC,mBAEJ,CAQA,SAASkD,EAAiBC,GAEC,iBAAdA,GAKXC,OAAOC,OAAOjE,EAAe+D,EAC/B,CAQA,SAASG,EAAmBC,GAEC,iBAAhBA,GAKXH,OAAOC,OAAO5D,EAAiB8D,EACjC"}
1
+ {"version":3,"file":"index.esm.mjs","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β€” with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n toast.style.position = \"relative\";\r\n toast.style.overflow = \"hidden\";\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n if (showProgressBar) {\r\n const progressBar = document.createElement(\"div\");\r\n progressBar.style.position = \"absolute\";\r\n progressBar.style[progressPosition === \"top\" ? \"top\" : \"bottom\"] = \"0\";\r\n progressBar.style.left = \"0\";\r\n progressBar.style.height = progressHeight || \"4px\";\r\n progressBar.style.backgroundColor = progressColor || textColor;\r\n progressBar.style.width = \"100%\";\r\n progressBar.style.transition = `width ${duration}ms linear`;\r\n\r\n // Trigger animation\r\n requestAnimationFrame(() => {\r\n progressBar.style.width = \"0%\";\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n}) {\r\n if (isToastShowing) return;\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration || 3000\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @param {boolean} [options.showProgressBar=false] - Show a visual progress bar.\r\n * @param {string} [options.progressColor] - Color of the progress bar.\r\n * @param {string} [options.progressHeight='4px'] - Height of the progress bar.\r\n * @param {string} [options.progressPosition='bottom'] - 'top' or 'bottom' placement of the progress bar.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar = false,\r\n progressColor,\r\n progressHeight = \"4px\",\r\n progressPosition = \"bottom\",\r\n } = options;\r\n\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","showProgressBar","progressColor","progressHeight","progressPosition","duration","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","position","overflow","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","progressBar","left","height","width","requestAnimationFrame","showToast","message","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","transform","setPosition","body","createToastContainer","setTimeout","parentNode","createToast","options","setDefaultColors","newColors","Object","assign","setDefaultMessages","newMessages"],"mappings":";;;;;;;;;;;;;;;;;;AAyCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAiBrC,GAhBAF,EAAMG,YAAcd,EACpBW,EAAMI,MAAMC,WAAaf,EACzBU,EAAMI,MAAME,MAAQf,EACpBS,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,aAAe,MAC3BT,EAAMI,MAAMM,UAAY,8BACxBV,EAAMI,MAAMO,QAAU,IACtBX,EAAMI,MAAMQ,WAAa,WAAWpB,KAAqBC,IACzDO,EAAMI,MAAMS,SAAW,WACvBb,EAAMI,MAAMU,SAAW,SAEnBpB,GAyBN,SAAwBM,EAAOT,GAC7B,MAAMwB,EAAcd,SAASC,cAAc,UAC3Ca,EAAYZ,YAAc,IAC1BY,EAAYX,MAAMY,WAAa,OAC/BD,EAAYX,MAAMC,WAAa,cAC/BU,EAAYX,MAAMa,OAAS,OAC3BF,EAAYX,MAAME,MAAQf,EAC1BwB,EAAYX,MAAMc,OAAS,UAE3BH,EAAYI,QAAU,KACpBnB,EAAMI,MAAMO,QAAU,IACtBX,EAAMoB,iBAAiB,gBAAiB,KACtCpB,EAAMqB,SACNlC,GAAiB,KAIrBa,EAAMsB,YAAYP,EACpB,CA1CIQ,CAAevB,EAAOT,GAGpBI,EAAiB,CACnB,MAAM6B,EAAcvB,SAASC,cAAc,OAC3CsB,EAAY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C,MAAMqB,KAAO,MACvBa,EAAUlC,MAAMuC,UAAY,wBAEhC,CAtBIC,CAAYV,EAAgBrB,GAC5BZ,SAAS4C,KAAKvB,YAAYY,IAErBA,CACT,CAmHyBY,CAAqBjC,GACtCb,EAAQZ,EACZC,EACA2C,EACAC,EACAzC,GAAqB,OACrBC,GAAmB,OACnBC,EACAC,EACAC,EACAC,EACAC,EACAC,GAAY,KAGdmC,EAAeZ,YAAYtB,GAC3B4B,sBAAsB,KACpB5B,EAAMI,MAAMO,QAAU,MAGxBoC,WAAW,KACL/C,EAAMgD,aACRhD,EAAMI,MAAMO,QAAU,IACtBX,EAAMoB,iBAAiB,gBAAiB,KACtCpB,EAAMqB,SACNlC,GAAiB,MAGpBY,GAAY,IACjB,CAqBA,SAASkD,EAAYC,GACnB,GAAuB,iBAAZA,EAET,OAGF,MAAMpB,QACJA,EAAO/B,SACPA,EAAQc,SACRA,EAAW,eAAckB,KACzBA,EAAO,OAAMzC,gBACbA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,EAAeE,gBACfA,GAAkB,EAAKC,cACvBA,EAAaC,eACbA,EAAiB,MAAKC,iBACtBA,EAAmB,UACjBoD,EAMJrB,EAAU,CACRC,UACA/B,SAAUA,GAAY,IACtBc,WACAkB,OACAzC,kBACAC,YACAG,kBACAF,oBACAC,kBACAE,kBACAC,gBACAC,iBACAC,oBAEJ,CAQA,SAASqD,EAAiBC,GAEC,iBAAdA,GAKXC,OAAOC,OAAOzE,EAAeuE,EAC/B,CAQA,SAASG,EAAmBC,GAEC,iBAAhBA,GAKXH,OAAOC,OAAOpE,EAAiBsE,EACjC"}
package/dist/index.umd.js CHANGED
@@ -3,16 +3,18 @@
3
3
  * @fileoverview A simple toast notification library for any JavaScript framework.
4
4
  * @name Customizable Toast Notifications
5
5
  * @author Priyanshu Patel
6
- * @version 1.0.0
6
+ * @version "3.2.0"
7
+ * @build Production
7
8
  * @license Apache-2.0
8
9
  * @depends None
9
- * @description This library provides a simple way to create toast notifications.
10
+ * @description A lightweight and fully customizable toast notification library
11
+ * designed for seamless integration with any JavaScript or framework-based UI.
12
+ * Supports flexible positioning, theming, icons, animations, and timing options
13
+ * out of the box β€” with zero dependencies.
10
14
  * Author: Priyanshu Patel
11
15
  * Email: priyanshu.alt191@gmail.com
12
16
  * Created: July 31, 2024
13
- * Description: A simple toast notification library for any JavaScript framework.
14
- * Version: 1.0.0
15
17
  * License: Apache-2.0
16
18
  * Dependencies: None
17
- */let t={info:"blue",success:"green",error:"red",warning:"darkorange"},o={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},n=!1;function s(e,t,o,s,i,a){const r=document.createElement("div");return r.textContent=e,r.style.background=t,r.style.color=o,r.style.padding="10px 20px",r.style.marginTop="10px",r.style.borderRadius="5px",r.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",r.style.opacity="0",r.style.transition=`opacity ${s} ${i}`,a&&function(e,t){const o=document.createElement("button");o.textContent="Γ—",o.style.marginLeft="10px",o.style.background="transparent",o.style.border="none",o.style.color=t,o.style.cursor="pointer",o.onclick=()=>{e.style.opacity="0",e.addEventListener("transitionend",()=>{e.remove(),n=!1})},e.appendChild(o)}(r,o),r}function i({message:e,duration:i,position:a,type:r,backgroundColor:l,textColor:c,showCloseButton:d,animationDuration:u,animationEasing:p}){if(n)return;n=!0;const y=e||o[r]||"This is a default message.",f=l||t[r]||"gray",m=c||("white"===f?"black":"white"),g=function(e){let t=document.getElementById(`toast-container-${e}`);return t||(t=document.createElement("div"),t.id=`toast-container-${e}`,t.style.position="fixed",t.style.zIndex="9999",function(e,t){t.includes("bottom")?e.style.bottom="10px":t.includes("top")&&(e.style.top="10px"),t.includes("right")?e.style.right="10px":t.includes("left")?e.style.left="10px":t.includes("center")&&(e.style.top="50%",e.style.left="50%",e.style.transform="translate(-50%, -50%)")}(t,e),document.body.appendChild(t)),t}(a),b=s(y,f,m,u||"0.5s",p||"ease",d);g.appendChild(b),requestAnimationFrame(()=>{b.style.opacity="1"}),setTimeout(()=>{b.parentNode&&(b.style.opacity="0",b.addEventListener("transitionend",()=>{b.remove(),n=!1}))},i||3e3)}e.createToast=function(e){if("object"!=typeof e)return;const{message:t,duration:o,position:n="bottom-right",type:s="info",backgroundColor:a,textColor:r,showCloseButton:l=!1,animationDuration:c,animationEasing:d}=e;i({message:t,duration:o||3e3,position:n,type:s,backgroundColor:a,textColor:r,showCloseButton:l,animationDuration:c,animationEasing:d})},e.setDefaultColors=function(e){"object"==typeof e&&Object.assign(t,e)},e.setDefaultMessages=function(e){"object"==typeof e&&Object.assign(o,e)},Object.defineProperty(e,"__esModule",{value:!0})});
19
+ */let t={info:"blue",success:"green",error:"red",warning:"darkorange"},o={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},s=!1;function n(e,t,o,n,i,r,a,l,c,d,p){const u=document.createElement("div");if(u.textContent=e,u.style.background=t,u.style.color=o,u.style.padding="10px 20px",u.style.marginTop="10px",u.style.borderRadius="5px",u.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",u.style.opacity="0",u.style.transition=`opacity ${n} ${i}`,u.style.position="relative",u.style.overflow="hidden",r&&function(e,t){const o=document.createElement("button");o.textContent="Γ—",o.style.marginLeft="10px",o.style.background="transparent",o.style.border="none",o.style.color=t,o.style.cursor="pointer",o.onclick=()=>{e.style.opacity="0",e.addEventListener("transitionend",()=>{e.remove(),s=!1})},e.appendChild(o)}(u,o),a){const e=document.createElement("div");e.style.position="absolute",e.style["top"===d?"top":"bottom"]="0",e.style.left="0",e.style.height=c||"4px",e.style.backgroundColor=l||o,e.style.width="100%",e.style.transition=`width ${p}ms linear`,requestAnimationFrame(()=>{e.style.width="0%"}),u.appendChild(e)}return u}function i({message:e,duration:i,position:r,type:a,backgroundColor:l,textColor:c,showCloseButton:d,animationDuration:p,animationEasing:u,showProgressBar:y,progressColor:g,progressHeight:f,progressPosition:m}){if(s)return;s=!0;const h=e||o[a]||"This is a default message.",b=l||t[a]||"gray",x=c||("white"===b?"black":"white"),C=function(e){let t=document.getElementById(`toast-container-${e}`);return t||(t=document.createElement("div"),t.id=`toast-container-${e}`,t.style.position="fixed",t.style.zIndex="9999",function(e,t){t.includes("bottom")?e.style.bottom="10px":t.includes("top")&&(e.style.top="10px"),t.includes("right")?e.style.right="10px":t.includes("left")?e.style.left="10px":t.includes("center")&&(e.style.top="50%",e.style.left="50%",e.style.transform="translate(-50%, -50%)")}(t,e),document.body.appendChild(t)),t}(r),w=n(h,b,x,p||"0.5s",u||"ease",d,y,g,f,m,i||3e3);C.appendChild(w),requestAnimationFrame(()=>{w.style.opacity="1"}),setTimeout(()=>{w.parentNode&&(w.style.opacity="0",w.addEventListener("transitionend",()=>{w.remove(),s=!1}))},i||3e3)}e.createToast=function(e){if("object"!=typeof e)return;const{message:t,duration:o,position:s="bottom-right",type:n="info",backgroundColor:r,textColor:a,showCloseButton:l=!1,animationDuration:c,animationEasing:d,showProgressBar:p=!1,progressColor:u,progressHeight:y="4px",progressPosition:g="bottom"}=e;i({message:t,duration:o||3e3,position:s,type:n,backgroundColor:r,textColor:a,showCloseButton:l,animationDuration:c,animationEasing:d,showProgressBar:p,progressColor:u,progressHeight:y,progressPosition:g})},e.setDefaultColors=function(e){"object"==typeof e&&Object.assign(t,e)},e.setDefaultMessages=function(e){"object"==typeof e&&Object.assign(o,e)},Object.defineProperty(e,"__esModule",{value:!0})});
18
20
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n}) {\r\n if (isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\"; // Fade in effect\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\"; // Fade out effect\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n // Validate options\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n } = options;\r\n\r\n // Validate duration\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","showToast","message","duration","position","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","left","transform","setPosition","body","createToastContainer","requestAnimationFrame","setTimeout","parentNode","options","newColors","Object","assign","newMessages"],"mappings":";;;;;;;;;;;;;;;;KAuCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAerC,OAdAF,EAAM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U7B,MAAM+B,OAAS,OAChBV,EAASS,SAAS,SAC3BD,EAAU7B,MAAMgC,IAAM,QAGpBX,EAASS,SAAS,SACpBD,EAAU7B,MAAMiC,MAAQ,OACfZ,EAASS,SAAS,QAC3BD,EAAU7B,MAAMkC,KAAO,OACdb,EAASS,SAAS,YAC3BD,EAAU7B,MAAMgC,IAAM,MACtBH,EAAU7B,MAAMkC,KAAO,MACvBL,EAAU7B,MAAMmC,UAAY,wBAEhC,CAtBIC,CAAYX,EAAgBJ,GAC5BxB,SAASwC,KAAKrB,YAAYS,IAErBA,CACT,CAuFyBa,CAAqBjB,GACtCzB,EAAQP,EACZC,EACAiC,EACAC,EACA/B,GAAqB,OACrBC,GAAmB,OACnBC,GAGF8B,EAAeT,YAAYpB,GAC3B2C,sBAAsB,KACpB3C,EAAMI,MAAMO,QAAU,MAGxBiC,WAAW,KACL5C,EAAM6C,aACR7C,EAAMI,MAAMO,QAAU,IACtBX,EAAMkB,iBAAiB,gBAAiB,KACtClB,EAAMmB,SACN3B,GAAiB,MAGpBgC,GAAY,IACjB,eAiBA,SAAqBsB,GAEnB,GAAuB,iBAAZA,EAET,OAGF,MAAMvB,QACJA,EAAOC,SACPA,EAAQC,SACRA,EAAW,eAAcC,KACzBA,EAAO,OAAM/B,gBACbA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,GACEgD,EAOJxB,EAAU,CACRC,UACAC,SAAUA,GAAY,IACtBC,WACAC,OACA/B,kBACAC,YACAG,kBACAF,oBACAC,mBAEJ,qBAQA,SAA0BiD,GAEC,iBAAdA,GAKXC,OAAOC,OAAO/D,EAAe6D,EAC/B,uBAQA,SAA4BG,GAEC,iBAAhBA,GAKXF,OAAOC,OAAO1D,EAAiB2D,EACjC"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version __VERSION__\r\n * @build Production\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description A lightweight and fully customizable toast notification library\r\n * designed for seamless integration with any JavaScript or framework-based UI.\r\n * Supports flexible positioning, theming, icons, animations, and timing options\r\n * out of the box β€” with zero dependencies.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n toast.style.position = \"relative\";\r\n toast.style.overflow = \"hidden\";\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n if (showProgressBar) {\r\n const progressBar = document.createElement(\"div\");\r\n progressBar.style.position = \"absolute\";\r\n progressBar.style[progressPosition === \"top\" ? \"top\" : \"bottom\"] = \"0\";\r\n progressBar.style.left = \"0\";\r\n progressBar.style.height = progressHeight || \"4px\";\r\n progressBar.style.backgroundColor = progressColor || textColor;\r\n progressBar.style.width = \"100%\";\r\n progressBar.style.transition = `width ${duration}ms linear`;\r\n\r\n // Trigger animation\r\n requestAnimationFrame(() => {\r\n progressBar.style.width = \"0%\";\r\n });\r\n\r\n toast.appendChild(progressBar);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n}) {\r\n if (isToastShowing) return;\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n duration || 3000\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\";\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\";\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false;\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @param {boolean} [options.showProgressBar=false] - Show a visual progress bar.\r\n * @param {string} [options.progressColor] - Color of the progress bar.\r\n * @param {string} [options.progressHeight='4px'] - Height of the progress bar.\r\n * @param {string} [options.progressPosition='bottom'] - 'top' or 'bottom' placement of the progress bar.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar = false,\r\n progressColor,\r\n progressHeight = \"4px\",\r\n progressPosition = \"bottom\",\r\n } = options;\r\n\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n showProgressBar,\r\n progressColor,\r\n progressHeight,\r\n progressPosition,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","showProgressBar","progressColor","progressHeight","progressPosition","duration","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","position","overflow","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","progressBar","left","height","width","requestAnimationFrame","showToast","message","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","transform","setPosition","body","createToastContainer","setTimeout","parentNode","options","newColors","Object","assign","newMessages"],"mappings":";;;;;;;;;;;;;;;;;;KAyCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAiBrC,GAhBAF,EAAMG,YAAcd,EACpBW,EAAMI,MAAMC,WAAaf,EACzBU,EAAMI,MAAME,MAAQf,EACpBS,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,a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bA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,EAAeE,gBACfA,GAAkB,EAAKC,cACvBA,EAAaC,eACbA,EAAiB,MAAKC,iBACtBA,EAAmB,UACjBmD,EAMJpB,EAAU,CACRC,UACA/B,SAAUA,GAAY,IACtBc,WACAkB,OACAzC,kBACAC,YACAG,kBACAF,oBACAC,kBACAE,kBACAC,gBACAC,iBACAC,oBAEJ,qBAQA,SAA0BoD,GAEC,iBAAdA,GAKXC,OAAOC,OAAOvE,EAAeqE,EAC/B,uBAQA,SAA4BG,GAEC,iBAAhBA,GAKXF,OAAOC,OAAOlE,EAAiBmE,EACjC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customizable-toast-notification",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "A lightweight and highly customizable toast notification library or component for modern web applications.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
package/postinstall.js CHANGED
@@ -1,136 +1,65 @@
1
- import fs from "fs";
2
- import os from "os";
3
- import path from "path";
4
- import cp from "child_process";
5
-
6
- if (
7
- process.env.CI ||
8
- process.env.npm_config_global ||
9
- process.env.NODE_ENV === "production"
10
- ) {
11
- process.exit(0);
12
- }
13
-
14
- const appName = "customizable-toast";
15
-
16
- let configDir;
17
- switch (process.platform) {
18
- case "win32":
19
- configDir = path.join(
20
- process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming"),
21
- appName
22
- );
23
- break;
24
- case "darwin":
25
- configDir = path.join(
26
- os.homedir(),
27
- "Library",
28
- "Application Support",
29
- appName
30
- );
31
- break;
32
- default:
33
- configDir = path.join(
34
- process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"),
35
- appName
36
- );
37
- }
38
-
39
- const storeFile = path.join(configDir, "install-count.json");
40
-
41
- // Ensure config dir
42
- fs.mkdirSync(configDir, { recursive: true });
43
-
44
- // Read + increment count
45
- let count = 0;
46
1
  try {
47
- if (fs.existsSync(storeFile)) {
48
- if (process.platform === "win32") {
49
- try {
50
- cp.execSync(`attrib -h "${storeFile}"`);
51
- } catch (err) {
52
- process.exit(0);
53
- }
54
- }
55
- const data = JSON.parse(fs.readFileSync(storeFile, "utf8"));
56
- count = data.count || 0;
2
+ if (
3
+ process.env.CI ||
4
+ process.env.NODE_ENV === "prod" ||
5
+ process.env.NODE_ENV === "production"
6
+ ) {
7
+ process.exit(0);
8
+ } else {
9
+ showMessage(5);
57
10
  }
58
- } catch {
59
- count = 0;
60
- }
61
11
 
62
- count++;
63
-
64
- // Save count back
65
- try {
66
- fs.writeFileSync(storeFile, JSON.stringify({ count }), "utf8");
67
- if (process.platform === "win32" && count === 1) {
68
- try {
69
- cp.execSync(`attrib +h "${storeFile}"`);
70
- } catch (err) {
71
- process.exit(0);
72
- }
73
- }
74
- } catch (err) {
75
- process.exit(0);
76
- }
77
-
78
- // --- Message Logic ---
79
- if (count === 1 || count === 2 || count === 5) {
80
- showMessage(count);
81
- } else {
82
- process.exit(0); // Silent for other installs
83
- }
84
-
85
- // --- Spinner + Delayed Message Box ---
86
- function showMessage(count) {
87
- const width = process.stdout.columns || 80;
88
- const boxWidth = 60;
89
-
90
- const spinnerFrames = ["|", "/", "-", "\\"];
91
- let i = 0;
92
-
93
- const stripAnsi = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
94
- const pad = (text) =>
95
- " ".repeat(Math.max(boxWidth - stripAnsi(text).length, 0));
96
- const center = (text) =>
97
- " ".repeat(Math.max(Math.floor((width - stripAnsi(text).length) / 2), 0)) +
98
- text;
99
-
100
- const lines = [
101
- count === 5
102
- ? "🎯Thanks for sticking with it!\nThis is the final message. πŸš€"
103
- : `πŸ“¦Thanks for using this package!`,
104
- "",
105
- "πŸ“˜ For help: Check the README.md",
106
- "🀝 Open to collaboration & teamwork.",
107
- "πŸ’Ό Looking for exciting dev opportunities.",
108
- "πŸ”— Contact: priyanshu.alt191@gmail.com",
109
- "πŸš€ Built different. Stay creative.",
110
- ];
111
-
112
- const spinner = setInterval(() => {
113
- process.stdout.write(
114
- `\r⏳ Finalizing install ${spinnerFrames[i++ % spinnerFrames.length]} `
115
- );
116
- }, 100);
117
-
118
- setTimeout(() => {
119
- clearInterval(spinner);
120
- process.stdout.write("\r".padEnd(40, " ") + "\r"); // Clear spinner line
121
-
122
- console.log(
123
- "\n" + center(`\x1b[36m\x1b[1mβ•”${"═".repeat(boxWidth)}β•—\x1b[0m`)
124
- );
125
- lines.forEach((line) => {
126
- line.split("\n").forEach((sub) => {
127
- console.log(
128
- center(`\x1b[36mβ•‘ \x1b[0m${sub}${pad(sub)}\x1b[36m β•‘\x1b[0m`)
129
- );
12
+ function showMessage(count) {
13
+ const width = process.stdout.columns || 80;
14
+ const boxWidth = 60;
15
+
16
+ const spinnerFrames = ["|", "/", "-", "\\"];
17
+ let i = 0;
18
+
19
+ const stripAnsi = (text) => text.replace(/\x1b\[[0-9;]*m/g, "");
20
+ const pad = (text) =>
21
+ " ".repeat(Math.max(boxWidth - stripAnsi(text).length, 0));
22
+ const center = (text) =>
23
+ " ".repeat(
24
+ Math.max(Math.floor((width - stripAnsi(text).length) / 2), 0)
25
+ ) + text;
26
+
27
+ const lines = [
28
+ count === 5
29
+ ? "🎯Thanks for sticking with it!\nThis is the final message. πŸš€"
30
+ : `πŸ“¦Thanks for using this package!`,
31
+ "πŸ“˜ For help: Check the README.md",
32
+ "🀝 Open to collaboration & teamwork.",
33
+ "πŸ’Ό Looking for exciting dev opportunities.",
34
+ "πŸ”— Contact: priyanshu.alt191@gmail.com",
35
+ "πŸš€ Built different. Stay creative.",
36
+ ];
37
+
38
+ const spinner = setInterval(() => {
39
+ process.stdout.write(
40
+ `\r⏳ Finalizing install ${spinnerFrames[i++ % spinnerFrames.length]} `
41
+ );
42
+ }, 100);
43
+
44
+ setTimeout(() => {
45
+ clearInterval(spinner);
46
+ process.stdout.write("\r".padEnd(40, " ") + "\r"); // Clear spinner line
47
+
48
+ console.log(
49
+ "\n" + center(`\x1b[36m\x1b[1mβ•”${"═".repeat(boxWidth)}β•—\x1b[0m`)
50
+ );
51
+ lines.forEach((line) => {
52
+ line.split("\n").forEach((sub) => {
53
+ console.log(
54
+ center(`\x1b[36mβ•‘ \x1b[0m${sub}${pad(sub)}\x1b[36m β•‘\x1b[0m`)
55
+ );
56
+ });
130
57
  });
131
- });
132
- console.log(center(`\x1b[36mβ•š${"═".repeat(boxWidth)}╝\x1b[0m`) + "\n");
58
+ console.log(center(`\x1b[36mβ•š${"═".repeat(boxWidth)}╝\x1b[0m`) + "\n");
133
59
 
134
- process.exit(0); // βœ… Exit only after message shown
135
- }, 1200);
60
+ process.exit(0); // βœ… Exit only after message shown
61
+ }, 1200);
62
+ }
63
+ } catch (error) {
64
+ process.exit(0); // Exit silently
136
65
  }
Binary file
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});let t={info:"blue",success:"green",error:"red",warning:"darkorange"},e={info:"This is an info message.",success:"Action completed successfully!",error:"An error occurred!",warning:"This is a warning message!"},o=!1;function n(t,e,n,s,i,r){const a=document.createElement("div");return a.textContent=t,a.style.background=e,a.style.color=n,a.style.padding="10px 20px",a.style.marginTop="10px",a.style.borderRadius="5px",a.style.boxShadow="0 0 10px rgba(0, 0, 0, 0.1)",a.style.opacity="0",a.style.transition=`opacity ${s} ${i}`,r&&function(t,e){const n=document.createElement("button");n.textContent="Γ—",n.style.marginLeft="10px",n.style.background="transparent",n.style.border="none",n.style.color=e,n.style.cursor="pointer",n.onclick=()=>{t.style.opacity="0",t.addEventListener("transitionend",()=>{t.remove(),o=!1})},t.appendChild(n)}(a,n),a}function s({message:s,duration:i,position:r,type:a,backgroundColor:l,textColor:c,showCloseButton:u,animationDuration:d,animationEasing:p}){if(o)return;o=!0;const y=s||e[a]||"This is a default message.",m=l||t[a]||"gray",g=c||("white"===m?"black":"white"),f=function(t){let e=document.getElementById(`toast-container-${t}`);return e||(e=document.createElement("div"),e.id=`toast-container-${t}`,e.style.position="fixed",e.style.zIndex="9999",function(t,e){e.includes("bottom")?t.style.bottom="10px":e.includes("top")&&(t.style.top="10px"),e.includes("right")?t.style.right="10px":e.includes("left")?t.style.left="10px":e.includes("center")&&(t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)")}(e,t),document.body.appendChild(e)),e}(r),b=n(y,m,g,d||"0.5s",p||"ease",u);f.appendChild(b),requestAnimationFrame(()=>{b.style.opacity="1"}),setTimeout(()=>{b.parentNode&&(b.style.opacity="0",b.addEventListener("transitionend",()=>{b.remove(),o=!1}))},i||3e3)}exports.createToast=function(t){if("object"!=typeof t)return;const{message:e,duration:o,position:n="bottom-right",type:i="info",backgroundColor:r,textColor:a,showCloseButton:l=!1,animationDuration:c,animationEasing:u}=t;s({message:e,duration:o||3e3,position:n,type:i,backgroundColor:r,textColor:a,showCloseButton:l,animationDuration:c,animationEasing:u})},exports.setDefaultColors=function(e){"object"==typeof e&&Object.assign(t,e)},exports.setDefaultMessages=function(t){"object"==typeof t&&Object.assign(e,t)};
2
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n}) {\r\n if (isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\"; // Fade in effect\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\"; // Fade out effect\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n // Validate options\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n } = options;\r\n\r\n // Validate duration\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","showToast","message","duration","position","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","left","transform","setPosition","body","createToastContainer","requestAnimationFrame","setTimeout","parentNode","options","newColors","Object","assign","newMessages"],"mappings":"oEAuCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAerC,OAdAF,EAAMG,YAAcT,EACpBM,EAAMI,MAAMC,WAAaV,EACzBK,EAAMI,MAAME,MAAQV,EACpBI,EAAMI,MAAMG,QAAU,YACtBP,EAAMI,MAAMI,UAAY,OACxBR,EAAMI,MAAMK,aAAe,MAC3BT,EAAMI,MAAMM,UAAY,8BACxBV,EAAMI,MAAMO,QAAU,IACtBX,EAAMI,MAAMQ,WAAa,WAAWf,KAAqBC,IAEr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BL,EAAU7B,MAAMmC,UAAY,wBAEhC,CAtBIC,CAAYX,EAAgBJ,GAC5BxB,SAASwC,KAAKrB,YAAYS,IAErBA,CACT,CAuFyBa,CAAqBjB,GACtCzB,EAAQP,EACZC,EACAiC,EACAC,EACA/B,GAAqB,OACrBC,GAAmB,OACnBC,GAGF8B,EAAeT,YAAYpB,GAC3B2C,sBAAsB,KACpB3C,EAAMI,MAAMO,QAAU,MAGxBiC,WAAW,KACL5C,EAAM6C,aACR7C,EAAMI,MAAMO,QAAU,IACtBX,EAAMkB,iBAAiB,gBAAiB,KACtClB,EAAMmB,SACN3B,GAAiB,MAGpBgC,GAAY,IACjB,qBAiBA,SAAqBsB,GAEnB,GAAuB,iBAAZA,EAET,OAGF,MAAMvB,QACJA,EAAOC,SACPA,EAAQC,SACRA,EAAW,eAAcC,KACzBA,EAAO,OAAM/B,gBACbA,EAAeC,UACfA,EAASG,gBACTA,GAAkB,EAAKF,kBACvBA,EAAiBC,gBACjBA,GACEgD,EAOJxB,EAAU,CACRC,UACAC,SAAUA,GAAY,IACtBC,WACAC,OACA/B,kBACAC,YACAG,kBACAF,oBACAC,mBAEJ,2BAQA,SAA0BiD,GAEC,iBAAdA,GAKXC,OAAOC,OAAO/D,EAAe6D,EAC/B,6BAQA,SAA4BG,GAEC,iBAAhBA,GAKXF,OAAOC,OAAO1D,EAAiB2D,EACjC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\n/**\r\n * @fileoverview A simple toast notification library for any JavaScript framework.\r\n * @name Customizable Toast Notifications\r\n * @author Priyanshu Patel\r\n * @version 1.0.0\r\n * @license Apache-2.0\r\n * @depends None\r\n * @description This library provides a simple way to create toast notifications.\r\n * Author: Priyanshu Patel\r\n * Email: priyanshu.alt191@gmail.com\r\n * Created: July 31, 2024\r\n * Description: A simple toast notification library for any JavaScript framework.\r\n * Version: 1.0.0\r\n * License: Apache-2.0\r\n * Dependencies: None\r\n */\r\n\r\n/**\r\n * Creates a toast notification.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast. Defaults based on type if not provided.\r\n * @param {number} [options.duration=3000] - The duration the toast should be displayed, in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast on the screen.\r\n * @param {string} [options.type='info'] - The type of the toast ('info', 'success', 'error', 'warning').\r\n * @param {string} [options.backgroundColor] - Custom background color for the toast notification.\r\n * @param {string} [options.textColor='white'] - Custom text color for the toast notification.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of the fade-in and fade-out animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for the animations.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @return {void}\r\n */\r\n\r\n/** ########################################### Defaults ############################################ */\r\n\r\nconsole.log(\"Before toast creation\");\r\n\r\nlet defaultColors = {\r\n info: \"blue\",\r\n success: \"green\",\r\n error: \"red\",\r\n warning: \"darkorange\",\r\n};\r\n\r\nlet defaultMessages = {\r\n info: \"This is an info message.\",\r\n success: \"Action completed successfully!\",\r\n error: \"An error occurred!\",\r\n warning: \"This is a warning message!\",\r\n};\r\n\r\n// Flag to manage if a toast is currently being shown\r\nlet isToastShowing = false;\r\n\r\nfunction createToastContainer(position) {\r\n let toastContainer = document.getElementById(`toast-container-${position}`);\r\n if (!toastContainer) {\r\n toastContainer = document.createElement(\"div\");\r\n toastContainer.id = `toast-container-${position}`;\r\n toastContainer.style.position = \"fixed\";\r\n toastContainer.style.zIndex = \"9999\";\r\n setPosition(toastContainer, position);\r\n document.body.appendChild(toastContainer);\r\n }\r\n return toastContainer;\r\n}\r\n\r\nfunction setPosition(container, position) {\r\n if (position.includes(\"bottom\")) {\r\n container.style.bottom = \"10px\";\r\n } else if (position.includes(\"top\")) {\r\n container.style.top = \"10px\";\r\n }\r\n\r\n if (position.includes(\"right\")) {\r\n container.style.right = \"10px\";\r\n } else if (position.includes(\"left\")) {\r\n container.style.left = \"10px\";\r\n } else if (position.includes(\"center\")) {\r\n container.style.top = \"50%\";\r\n container.style.left = \"50%\";\r\n container.style.transform = \"translate(-50%, -50%)\";\r\n }\r\n}\r\n\r\nfunction createToastElement(\r\n finalMessage,\r\n backgroundColor,\r\n textColor,\r\n animationDuration,\r\n animationEasing,\r\n showCloseButton\r\n) {\r\n const toast = document.createElement(\"div\");\r\n toast.textContent = finalMessage;\r\n toast.style.background = backgroundColor;\r\n toast.style.color = textColor;\r\n toast.style.padding = \"10px 20px\";\r\n toast.style.marginTop = \"10px\";\r\n toast.style.borderRadius = \"5px\";\r\n toast.style.boxShadow = \"0 0 10px rgba(0, 0, 0, 0.1)\";\r\n toast.style.opacity = \"0\";\r\n toast.style.transition = `opacity ${animationDuration} ${animationEasing}`;\r\n\r\n if (showCloseButton) {\r\n addCloseButton(toast, textColor);\r\n }\r\n\r\n return toast;\r\n}\r\n\r\nfunction addCloseButton(toast, textColor) {\r\n const closeButton = document.createElement(\"button\");\r\n closeButton.textContent = \"Γ—\";\r\n closeButton.style.marginLeft = \"10px\";\r\n closeButton.style.background = \"transparent\";\r\n closeButton.style.border = \"none\";\r\n closeButton.style.color = textColor;\r\n closeButton.style.cursor = \"pointer\";\r\n\r\n closeButton.onclick = () => {\r\n toast.style.opacity = \"0\"; // Start fade out\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n };\r\n\r\n toast.appendChild(closeButton);\r\n}\r\n\r\nfunction showToast({\r\n message,\r\n duration,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n}) {\r\n if (isToastShowing) return;\r\n\r\n isToastShowing = true;\r\n\r\n const finalMessage =\r\n message || defaultMessages[type] || \"This is a default message.\";\r\n const toastBackgroundColor = backgroundColor || defaultColors[type] || \"gray\";\r\n const toastTextColor =\r\n textColor || (toastBackgroundColor === \"white\" ? \"black\" : \"white\");\r\n\r\n const toastContainer = createToastContainer(position);\r\n const toast = createToastElement(\r\n finalMessage,\r\n toastBackgroundColor,\r\n toastTextColor,\r\n animationDuration || \"0.5s\",\r\n animationEasing || \"ease\",\r\n showCloseButton\r\n );\r\n\r\n toastContainer.appendChild(toast);\r\n requestAnimationFrame(() => {\r\n toast.style.opacity = \"1\"; // Fade in effect\r\n });\r\n\r\n setTimeout(() => {\r\n if (toast.parentNode) {\r\n toast.style.opacity = \"0\"; // Fade out effect\r\n toast.addEventListener(\"transitionend\", () => {\r\n toast.remove();\r\n isToastShowing = false; // Reset the flag when the toast is removed\r\n });\r\n }\r\n }, duration || 3000);\r\n}\r\n\r\n/**\r\n * Create a toast notification with the provided options.\r\n *\r\n * @param {Object} options - Options for the toast notification.\r\n * @param {string} [options.message] - The message to display in the toast.\r\n * @param {number} [options.duration=3000] - The duration of the toast in milliseconds.\r\n * @param {string} [options.position='bottom-right'] - The position of the toast.\r\n * @param {string} [options.type='info'] - The type of the toast.\r\n * @param {string} [options.backgroundColor] - The custom background color.\r\n * @param {string} [options.textColor='white'] - The custom text color.\r\n * @param {boolean} [options.showCloseButton=false] - Whether to show a close button.\r\n * @param {string} [options.animationDuration='0.5s'] - Duration of animations.\r\n * @param {string} [options.animationEasing='ease'] - Easing function for animations.\r\n * @return {void}\r\n */\r\nfunction createToast(options) {\r\n // Validate options\r\n if (typeof options !== \"object\") {\r\n console.error(\"Options should be an object.\");\r\n return;\r\n }\r\n\r\n const {\r\n message,\r\n duration,\r\n position = \"bottom-right\",\r\n type = \"info\",\r\n backgroundColor,\r\n textColor,\r\n showCloseButton = false,\r\n animationDuration,\r\n animationEasing,\r\n } = options;\r\n\r\n // Validate duration\r\n if (duration && typeof duration !== \"number\") {\r\n console.warn(\"Duration should be a number. Falling back to default value.\");\r\n }\r\n\r\n showToast({\r\n message,\r\n duration: duration || 3000,\r\n position,\r\n type,\r\n backgroundColor,\r\n textColor,\r\n showCloseButton,\r\n animationDuration,\r\n animationEasing,\r\n });\r\n}\r\n\r\n/**\r\n * Set default colors for toast types.\r\n *\r\n * @param {Object} newColors - New colors to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultColors(newColors) {\r\n // Validate newColors\r\n if (typeof newColors !== \"object\") {\r\n console.error(\"New colors should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultColors, newColors);\r\n}\r\n\r\n/**\r\n * Set default messages for toast types.\r\n *\r\n * @param {Object} newMessages - New messages to set for toast types.\r\n * @return {void}\r\n */\r\nfunction setDefaultMessages(newMessages) {\r\n // Validate newMessages\r\n if (typeof newMessages !== \"object\") {\r\n console.error(\"New messages should be an object.\");\r\n return;\r\n }\r\n\r\n Object.assign(defaultMessages, newMessages);\r\n}\r\n\r\nexport { createToast, setDefaultColors, setDefaultMessages };\r\n\r\nconsole.log(\"After toast creation\");\r\n"],"names":["defaultColors","info","success","error","warning","defaultMessages","isToastShowing","createToastElement","finalMessage","backgroundColor","textColor","animationDuration","animationEasing","showCloseButton","toast","document","createElement","textContent","style","background","color","padding","marginTop","borderRadius","boxShadow","opacity","transition","closeButton","marginLeft","border","cursor","onclick","addEventListener","remove","appendChild","addCloseButton","showToast","message","duration","position","type","toastBackgroundColor","toastTextColor","toastContainer","getElementById","id","zIndex","container","includes","bottom","top","right","left","transform","setPosition","body","createToastContainer","requestAnimationFrame","setTimeout","parentNode","options","newColors","Object","assign","newMessages"],"mappings":"oEAuCA,IAAIA,EAAgB,CAClBC,KAAM,OACNC,QAAS,QACTC,MAAO,MACPC,QAAS,cAGPC,EAAkB,CACpBJ,KAAM,2BACNC,QAAS,iCACTC,MAAO,qBACPC,QAAS,8BAIPE,GAAiB,EAiCrB,SAASC,EACPC,EACAC,EACAC,EACAC,EACAC,EACAC,GAEA,MAAMC,EAAQC,SAASC,cAAc,OAerC,OAdAF,EAAMG,YAAcT,EACpBM,EAAMI,MAAMC,WAAaV,EACzBK,EAAMI,MAAME,MAAQV,EACpBI,EAAMI,MAAMG,QAAU,YAC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