customizable-toast-notification 3.9.3 → 3.9.5
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 +32 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.mjs +4 -4
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +4 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +10 -7
- package/dist/index.cjs +0 -16
- package/dist/index.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# 🍞 Customizable Toast Notifications
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+

|
|
4
5
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
5
|
-
[](https://www.npmjs.com/package/customizable-toast-notification)
|
|
6
6
|
[](https://bundlephobia.com/package/customizable-toast-notification)
|
|
7
7
|
|
|
8
8
|
A **lightweight**, **zero-dependency** toast notification library for modern JavaScript applications. Built with production-grade reliability and comprehensive secret mechanisms.
|
|
@@ -55,14 +55,36 @@ duration: 3000
|
|
|
55
55
|
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
-
### CDN/Browser (UMD Build)
|
|
58
|
+
### CDN/Browser (UMD Build) / Quick Try with jsDelivr
|
|
59
59
|
|
|
60
60
|
```bash
|
|
61
61
|
Global Variable Name: customizableToast
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
<!-- Always latest version -->
|
|
64
|
+
<script src="https://cdn.jsdelivr.net/npm/customizable-toast-notification/dist/index.umd.js"></script>
|
|
65
|
+
|
|
66
|
+
<!-- OR pin to a specific version (recommended for stability) -->
|
|
67
|
+
<script src="https://cdn.jsdelivr.net/npm/customizable-toast-notification@3.9.5/dist/index.umd.js"></script>
|
|
68
|
+
|
|
69
|
+
<script>
|
|
70
|
+
// Access the global UMD export
|
|
71
|
+
customizableToast.createToast({
|
|
72
|
+
message: "Hello from jsDelivr! 🚀",
|
|
73
|
+
backgroundColor: "black",
|
|
74
|
+
textColor: "snow",
|
|
75
|
+
position: "top-center",
|
|
76
|
+
animationDuration: "3s",
|
|
77
|
+
animationEasing: "ease",
|
|
78
|
+
progressPosition: "top",
|
|
79
|
+
cta: {
|
|
80
|
+
autoClose: false,
|
|
81
|
+
label: "Check Pkg!",
|
|
82
|
+
href: "https://www.npmjs.com/package/customizable-toast-notification",
|
|
83
|
+
variant: "link",
|
|
84
|
+
target: "_blank"
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
</script>
|
|
66
88
|
|
|
67
89
|
```
|
|
68
90
|
|
|
@@ -322,6 +344,10 @@ npm run build
|
|
|
322
344
|
|
|
323
345
|
```
|
|
324
346
|
|
|
347
|
+
[](https://www.npmjs.com/package/customizable-toast-notification)
|
|
348
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
349
|
+
[](https://www.npmjs.com/package/customizable-toast-notification)
|
|
350
|
+
|
|
325
351
|
## 📄 License
|
|
326
352
|
|
|
327
353
|
This project is licensed under the [Apache-2.0 License](LICENSE).
|
package/dist/index.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ declare function setDefaultMessages(messages: any): void;
|
|
|
16
16
|
* Otherwise, removes only the first matching toast.
|
|
17
17
|
* @returns {Promise<void>} Resolves when removal is attempted.
|
|
18
18
|
*/
|
|
19
|
-
declare function noop(
|
|
19
|
+
declare function noop(): Promise<void>;
|
|
20
20
|
|
|
21
21
|
export { createToast, noop, setDefaultColors, setDefaultMessages };
|
package/dist/index.esm.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* Customizable Toast Notifications 3.9.
|
|
3
|
-
* Build: 2025-09-
|
|
4
|
-
* Cache-Buster:
|
|
2
|
+
* Customizable Toast Notifications 3.9.5
|
|
3
|
+
* Build: 2025-09-24 12:27:13
|
|
4
|
+
* Cache-Buster: 1758716833182
|
|
5
5
|
* Author: Priyanshu Patel
|
|
6
6
|
* Email: [priyanshu.alt191@gmail.com](mailto:priyanshu.alt191@gmail.com)
|
|
7
7
|
* License: Apache-2.0
|
|
@@ -12,5 +12,5 @@
|
|
|
12
12
|
* Supports flexible positioning, theming, icons, animations, and timing options
|
|
13
13
|
* out of the box — with CTA support and zero dependencies.
|
|
14
14
|
*/
|
|
15
|
-
async function t(t){return`${t}-${Date.now()}-${Math.floor(1e5*Math.random())}`}async function e(t,e){if(!t)return"snow";try{if("transparent"===t)return"snow";let i=await async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.threshold||4.5,r=o(t,e.resolveVarElement);if(!r)return{color:"#000000",contrast:21,meetsAA:!0,blackContrast:21,whiteContrast:1,used:"black"};let l;if(void 0!==r.a&&r.a<1){let t=e.underlyingColor;if(t){const n="string"==typeof t?o(t,e.resolveVarElement):t;t=n?{r:n.r,g:n.g,b:n.b}:{r:255,g:255,b:255}}else t={r:255,g:255,b:255};l=function(t,e){if(void 0===t.a||t.a>=1)return{r:t.r,g:t.g,b:t.b};e||(e={r:255,g:255,b:255});const n=t.a;return{r:Math.round(t.r*n+e.r*(1-n)),g:Math.round(t.g*n+e.g*(1-n)),b:Math.round(t.b*n+e.b*(1-n))}}(r,t)}else l={r:r.r,g:r.g,b:r.b};const c=a(l),u=s(c,1),d=s(c,0);if(u>=i||d>=i)return u>=d?{color:"#ffffff",contrast:u,meetsAA:u>=i,blackContrast:d,whiteContrast:u,used:"white"}:{color:"#000000",contrast:d,meetsAA:d>=i,blackContrast:d,whiteContrast:u,used:"black"};let f;f=u>d?i*(c+.05)-.05:(c+.05)/i-.05;f=Math.min(1,Math.max(0,f));const m=function(t){const e=function(t){return t<=.0031308?Math.round(12.92*t*255):Math.round(255*(1.055*Math.pow(t,1/2.4)-.055))}(t=Math.min(1,Math.max(0,t)));return o=e,i=e,r=e,"#"+n(o)+n(i)+n(r);var o,i,r}(f),p=a({r:parseInt(m.slice(1,3),16),g:parseInt(m.slice(3,5),16),b:parseInt(m.slice(5,7),16)}),h=s(c,p);return{color:m,contrast:h,meetsAA:h>=i,blackContrast:d,whiteContrast:u,used:"generated"}}(t,{underlyingColor:t||"#ffffff",threshold:e||4.5});return i}catch(t){return"snow"}}function n(t){return("0"+t.toString(16)).slice(-2)}function o(t){var e;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null===(e=document)||void 0===e?void 0:e.documentElement;if("string"!=typeof t||!t.trim())return null;const r=t.trim();if(r.startsWith("var(")&&"undefined"!=typeof window&&n){const t=r.slice(4,-1).trim(),e=getComputedStyle(n).getPropertyValue(t).trim();return e?o(e,n):null}if("undefined"!=typeof document)try{const t=document.createElement("canvas").getContext("2d");t.fillStyle="#000",t.fillStyle=r;const e=t.fillStyle,n=e.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)$/i);if(n)return{r:+n[1],g:+n[2],b:+n[3],a:void 0!==n[4]?+n[4]:1};if(e.startsWith("#"))return i(e)}catch(t){}if(/^#[0-9a-fA-F]{3,8}$/.test(r))return i(r);return{black:{r:0,g:0,b:0,a:1},white:{r:255,g:255,b:255,a:1},transparent:{r:0,g:0,b:0,a:0}}[r.toLowerCase()]||null}function i(t){let e=t.replace(/^#/,"");return 3!==e.length&&4!==e.length||(e=e.split("").map(t=>t+t).join("")),6===e.length?{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:1}:8===e.length?{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:parseInt(e.slice(6,8),16)/255}:null}function r(t){return(t/=255)<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}function a(t){return.2126*r(t.r)+.7152*r(t.g)+.0722*r(t.b)}function s(t,e){return(Math.max(t,e)+.05)/(Math.min(t,e)+.05)}async function l(t,e,n){const o=await async function(t){try{if("number"==typeof t&&t>0)return t;if("string"==typeof t){if(t.endsWith("s")&&!t.endsWith("ms")){const e=1e3*parseFloat(t);return e>0?e:500}const e=parseFloat(t);return e>0?e:500}}catch(t){}return 500}(e.animationDuration);Object.assign(t.style,{background:e.backgroundColor,padding:"12px 20px",marginBottom:"10px",borderRadius:e.borderRadius,overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",minWidth:"250px",maxWidth:e.maxWidth,opacity:"0",position:"relative",transition:`opacity ${e.animationDuration} ${e.animationEasing}, transform ${e.animationDuration} ${e.animationEasing}`,transform:"translateY(20px)",zIndex:"9999"}),t._animationDuration=o;const i=document.createElement("span");i.style.position=e.fontPosition,i.style.display="inline-block",i.style.flex="1",i.style.padding=e.fontPadding,i.style.borderRadius=e.fontBorderRadius,i.style.background=e.fontBackgroundColor,i.style.fontFamily=e.fontFamily,i.style.fontSize=e.fontSize,i.style.fontWeight=e.fontWeight,i.style.lineHeight=e.fontLineHeight,i.style.color=e.textColor,i.style.userSelect="text",i.style.wordBreak="break-word",i.style.direction=e.fontDirection,i.style.webkitLineClamp="3",i.style.webkitBoxOrient="vertical",i.style.whiteSpace=e.wrapText?"normal":"nowrap",i.style.display="block",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.lineClamp="3",i.style.boxOrient="vertical",i.style.display="-webkit-box",i.textContent=e.message,i.setAttribute("aria-label","Toast Notification Center"),i.setAttribute("title",e.message),t.appendChild(i),await async function(t,e,n){const o=null==e?void 0:e.cta;if(!o||!o.label)return;const i=!!o.href&&"link"===o.variant,r=document.createElement(i?"a":"button");i?(r.href=o.href,o.target&&(r.target=o.target),r.rel=o.rel||("_blank"===o.target?"noopener noreferrer":"")):r.type="button";r.setAttribute("aria-label",o.ariaLabel||o.label),Object.assign(r.style,{marginLeft:"10px",padding:"6px 10px",borderRadius:"6px",fontSize:"12px",fontWeight:"600",lineHeight:"1",border:"1px solid rgba(255,255,255,0.35)",color:e.textColor||"#fff",background:"rgba(255,255,255,0.15)",cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),r.textContent=o.label,r.addEventListener("click",async e=>{try{if("function"==typeof o.onClick){const t=o.onClick(e);null!=t&&t.then&&await t}}finally{!1!==o.autoClose&&n(t)}}),t.appendChild(r)}(t,e,n),e.showCloseButton&&await async function(t,e,n){const o=document.createElement("button");o.setAttribute("aria-label","Close notification"),o.setAttribute("title","Close"),o.textContent="×",Object.assign(o.style,{background:"none",border:"none",color:e.textColor,fontSize:"18px",marginLeft:"10px",cursor:"pointer"}),o.onclick=()=>n(t),t.appendChild(o),t._cleanupCloseButton=()=>{o.onclick=null}}(t,e,n),e.showProgressBar&&await async function(t,e){const n=document.createElement("div");Object.assign(n.style,{position:"absolute",left:"0",height:e.progressHeight||"4px",background:e.progressColor||"rgba(255, 255, 255, 0.3)",width:"100%",transition:`width ${e.duration||1800}ms linear`,["top"===e.progressPosition?"top":"bottom"]:"0"}),t.appendChild(n),setTimeout(()=>{!function(t){try{return(null==t?void 0:t.offsetWidth)||0}catch(t){return 0}}(n),n.style.width="0%"},100)}(t,e),await async function(t){setTimeout(()=>{requestAnimationFrame(()=>{t.style.opacity="1",t.style.transform="translateY(0)"})},50)}(t)}async function c(t,e){try{const n=document.createElement("div");return n.id=`emergency-${Date.now()}`,n.innerHTML=`\n <div style="\n background: #333 !important;\n color: white !important;\n padding: 10px 15px !important;\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n z-index: 99999 !important;\n border-radius: 3px !important;\n max-width: 250px !important;\n word-wrap: break-word !important;\n font-family: Arial, sans-serif !important;\n font-size: 14px !important;\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\n cursor: pointer !important;\n " onclick="this.parentNode.removeChild(this)">\n ${t.message||"Emergency Toast Creation Showing!"}\n <span style="float: right; margin-left: 10px; font-weight: bold;">×</span>\n </div>\n `,n._animationDuration=500,n._isEmergencyToast=!0,setTimeout(()=>{try{n.parentNode&&n.parentNode.removeChild(n),e(n)}catch(t){}},t.duration||1800),n}catch(n){return setTimeout(()=>{try{alert(t.message||"Toast Creation Failed!"),e(null)}catch(t){e(null)}},100),null}}async function u(e,n){let o;if(!document.querySelector('[id^="toast-container-"]'))return null;try{return o=await async function(e,n){try{const o=document.createElement(e);return o.id=await t(n),o}catch(e){try{const e="div",n="fallback",o=document.createElement(e);return o.id=await t(n),o.setAttribute("data-original-tag",e),o}catch(t){}}}("div","toast"),await l(o,e,n),o}catch(t){return await c(e,n),o}}const d=new Map,f=new Map;function m(){return`toast-container-${function(){return String(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"bottom-right").toLowerCase().trim().replace(/\bbelow\b/g,"bottom").replace(/\s+/g,"-").replace(/[^a-z0-9\-]/g,"-").replace(/\-+/g,"-")}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"bottom-right")}`}async function p(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;const n=m(t.position);if(f.has(n))return f.get(n);const o=(async()=>{const o=d.get(n);if(o&&o.isConnected)return o;let i=document.getElementById(n);i&&!i.isConnected&&document.body.appendChild(i),i?(i.style.position=i.style.position||"fixed",i.style.zIndex=i.style.zIndex||"9999","function"==typeof e&&await e(i,t)):(i=document.createElement("div"),i.id=n,i.setAttribute("role","status"),i.setAttribute("aria-atomic","true"),i.style.position="fixed",i.style.zIndex="9999",i.style.inset="auto 10px 10px auto",i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.flexDirection="column",i.style.overflow="hidden","function"==typeof e&&await e(i,t),document.body.appendChild(i));const r=document.querySelectorAll(`#${n}`);if(r.length>1)for(let t=1;t<r.length;t++)try{r[t].remove()}catch(t){}return d.set(n,i),i})();f.set(n,o);try{return await o}finally{f.delete(m(t.position))}}async function h(t,e){if(!t||!e.position)throw new Error("Invalid container or position!");!function(t){t.style.top="auto",t.style.bottom="auto",t.style.left="auto",t.style.right="auto",t.style.transform="none"}(t);const n=function(t){const e=t.toLowerCase().trim();return{hasTop:e.includes("top"),hasBottom:e.includes("bottom")||e.includes("below"),hasLeft:e.includes("left"),hasRight:e.includes("right"),hasCenter:e.includes("center"),hasFullWidth:e.includes("top-full-width")||e.includes("bottom-full-width")||e.includes("fullwidth")}}(e.position);(function(t,e,n){if(!n.hasFullWidth)return!1;if(e.maxWidth="100vw",n.hasTop)return t.style.top="10px",t.style.left="10px",t.style.right="10px",!0;if(n.hasBottom)return t.style.bottom="10px",t.style.left="10px",t.style.right="10px",!0;return!1})(t,e,n)||function(t,e){if(!e.hasCenter)return!1;if(e.hasTop&&!e.hasLeft&&!e.hasRight)return t.style.top="10px",t.style.left="50%",t.style.transform="translateX(-50%)",!0;if(e.hasBottom&&!e.hasLeft&&!e.hasRight)return t.style.bottom="10px",t.style.left="50%",t.style.transform="translateX(-50%)",!0;if(e.hasLeft&&!e.hasTop&&!e.hasBottom)return t.style.left="10px",t.style.top="50%",t.style.transform="translateY(-50%)",!0;if(e.hasRight&&!e.hasTop&&!e.hasBottom)return t.style.right="10px",t.style.top="50%",t.style.transform="translateY(-50%)",!0;if(!(e.hasLeft||e.hasRight||e.hasTop||e.hasBottom))return t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",!0;return!1}(t,n)||function(t,e){e.hasBottom?t.style.bottom="10px":e.hasTop&&(t.style.top="10px");e.hasRight?t.style.right="10px":e.hasLeft?t.style.left="10px":(t.style.bottom="10px",t.style.left="50%",t.style.transform="translateX(-50%)")}(t,n)}class y{constructor(t,e){this.callback=t,this.delay=e,this.remaining=e,this.startTime=null,this.timeoutId=null,this.isPaused=!1,this.isCompleted=!1}start(){return this.isCompleted||this.timeoutId||(this.startTime=Date.now(),this.timeoutId=setTimeout(()=>{this.isCompleted=!0,this.timeoutId=null,this.callback()},this.remaining)),this}pause(){return this.isPaused||!this.timeoutId||this.isCompleted||(clearTimeout(this.timeoutId),this.timeoutId=null,this.remaining-=Date.now()-this.startTime,this.remaining=Math.max(0,this.remaining),this.isPaused=!0),this}resume(){return!this.isPaused||this.isCompleted||(this.isPaused=!1,this.start()),this}clear(){return this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null),this.isCompleted=!0,this}getRemainingTime(){return this.isCompleted?0:this.isPaused?this.remaining:this.timeoutId?Math.max(0,this.remaining-(Date.now()-this.startTime)):this.delay}}const g=new Map,b=new Map,w=[];let v=0;function x(t){let e=5381;for(let n=0;n<t.length;n++)e=(e<<5)+e+t.charCodeAt(n);return e>>>0}function C(t){let{type:e=options.type,message:n=options.message||"",position:o=options.position}=t;return[String(e).trim().toLowerCase(),x(String(n)).toString(16),String(o).trim().toLowerCase()].join("|")}async function k(t,e,n){try{if(!t||"object"!=typeof t)throw new TypeError("options must be an object");v++;const o=await p(t,h);if(!o)throw new Error("Failed to create toast container");const i=await u(t,S);if(!i)throw new Error("Toast element creation failed");const r=document.createElement("div");Object.assign(r.style,{position:"relative",display:"inline-block",overflow:"visible",marginBottom:"10px",zIndex:"0",width:"100%"});const a=document.createElement("div");Object.assign(a.style,{position:"relative",overflow:"hidden",borderRadius:t.borderRadius||"8px",zIndex:"1"}),a.appendChild(i),r.appendChild(a),o.id.includes("toast-container-")&&o.appendChild(r);const s=!1!==t.pauseOnHover&&(!0===t.pauseOnHover||!!t.cta),l={outer:r,toast:i,count:Math.max(1,0|n),timeout:null,pauseOnHover:s};g.set(e,l),i._key=e,l.count>1&&await L(l),l.timer=E(i,t),await T(l)}catch(e){v=Math.max(0,v-1);(document.querySelector('[id^="toast-container-"]')||document.body).appendChild(await c(t,S))}}function E(t,e){const n=(e.duration||1800)+10,o=new y(async()=>await S(t),n);return o.start(),o}async function T(t){if(!t.pauseOnHover||!t.outer||!t.timer)return;const{outer:e,timer:n}=t,o=()=>{n.pause()},i=()=>{n.resume()},r=t=>{t.target.matches("button, a, [tabindex]")&&n.pause()},a=t=>{e.contains(t.relatedTarget)||n.resume()};e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",i),e.addEventListener("focusin",r),e.addEventListener("focusout",a),e._pauseCleanup=()=>{e.removeEventListener("mouseenter",o),e.removeEventListener("mouseleave",i),e.removeEventListener("focusin",r),e.removeEventListener("focusout",a)}}async function S(t){try{var e,n,o;if(null==t||!t._key)return;const i=g.get(t._key);if(!i)return;null===(e=i.timer)||void 0===e||e.clear(),null===(n=i.outer)||void 0===n||null===(o=n._pauseCleanup)||void 0===o||o.call(n),g.delete(t._key),v=Math.max(0,v-1);const r=i.outer.querySelector(".toast-count-badge");r&&r.remove(),await async function(t){return t?new Promise(e=>{let n=!1;const o=()=>{n||(n=!0,async function(t){if(!t)return!0;try{var e;if(null!=t&&null!==(e=t.parentNode)&&void 0!==e&&e.id.includes("toast-container-"))return t.parentNode.removeChild(t),!0}catch(e){try{if(t.remove)return t.remove(),!0}catch(e){try{return t.style.display="none",t.style.opacity="0",t.style.pointerEvents="none",t.style.position="absolute",t.style.left="-9999px",!0}catch(t){return!1}}}}(t),e())},i=t.firstElementChild||t;if(!i)return Promise.resolve();const r=t=>{try{if(t.target!==i)return;i.removeEventListener("transitionend",r,!0),o()}catch(t){}};try{i.addEventListener("transitionend",r,!0)}catch(t){}setTimeout(()=>{try{i.removeEventListener("transitionend",r,!0),o()}catch(t){}},700)}):Promise.resolve()}(i.outer),await I()}catch(t){}}async function I(){for(;v<3&&w.length;){const t=w.shift();if(g.has(t.key)){const e=g.get(t.key);e.count+=t.count,await L(e);continue}k(t.options,t.key,t.count)}}async function L(t){let{outer:e,count:n}=t;if(!e||!e instanceof HTMLElement)throw new Error("updateBadge: outer must be a valid HTMLElement");if(n<2){const t=e.querySelector(".toast-count-badge");return void(t&&t.remove())}let o=e.querySelector(".toast-count-badge");o||(o=document.createElement("span"),o.className="toast-count-badge",o.setAttribute("aria-label",`${n} identical notifications`),Object.assign(o.style,{position:"absolute",top:"6px",right:"6px",backgroundColor:"#f44336",color:"#fff",borderRadius:"50%",minWidth:"20px",height:"20px",fontSize:"12px",fontWeight:"600",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid #fff",boxShadow:"0 2px 6px rgba(0,0,0,0.3)",zIndex:"2",pointerEvents:"none",transition:"transform 150ms ease"}),e.appendChild(o)),o.textContent=n>99?"99+":String(n);try{o.style.transform="scale(1.2)",setTimeout(()=>o.style.transform="scale(1)",150)}catch(t){}}let A={success:"#28a745",error:"#dc3545",warning:"#ffc107",info:"#17a2b8"},M={success:"Operation completed successfully!",error:"Something went wrong!",warning:"Warning message!",info:"Information message!"};const B=[];let P=!1;async function j(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{const n=await async function(t){var n,o;const i=null==t||null===(n=t.position)||void 0===n||null===(n=n.toLowerCase())||void 0===n?void 0:n.trim(),r=null!=i&&i.includes("top-full-width")||null!=i&&i.includes("bottom-full-width")?"100vw":"400px",a={pauseOnHover:void 0,duration:1800,position:"bottom-right",type:"info",borderRadius:"50px",backgroundColor:void 0,textColor:void 0,showCloseButton:!0,animationDuration:"0.4s",animationType:"fade",animationEasing:"ease",showProgressBar:!0,progressColor:void 0,progressHeight:"4px",progressPosition:"bottom",fontPosition:"relative",fontPadding:void 0,fontBorderRadius:void 0,fontBackgroundColor:void 0,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',fontSize:"14px",fontWeight:"400",fontLineHeight:"1.4",fontDirection:"auto",wrapText:"normal",maxWidth:r,..."object"!=typeof t||Array.isArray(t)?{}:t};a.message=null!==(o=null==t?void 0:t.message)&&void 0!==o?o:a.message;try{var s,l,c;if(!a.backgroundColor)a.backgroundColor=null!==(l=null===(c=A)||void 0===c?void 0:c[a.type])&&void 0!==l?l:window.matchMedia("(prefers-color-scheme: dark)").matches?"#f5f5f5":"#111111";if(a.message=a.message||(null===(s=M)||void 0===s?void 0:s[a.type])||"No Message Provided!",!a.textColor&&a.backgroundColor){const t=await e(a.backgroundColor);a.textColor=null==t?void 0:t.color}if(!a.progressColor&&a.backgroundColor)if(a.textColor)a.progressColor=a.textColor;else{const t=await e(a.backgroundColor);a.progressColor=null==t?void 0:t.color}}catch(t){}"string"!=typeof a.message&&(a.message="No Message Provided!");return a}(t);await async function(t){try{return await p(t,h)}catch(t){return document.body}}(n),await async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{const e=C(t);if(g.has(e)){const n=g.get(e);if(!n)throw new Error(`Active toast with key ${e} not found`);return n.count++,n.timer.clear(),n.timer=E(n.toast,t),await T(n),void await L(n)}if(b.has(e)){const t=b.get(e);if(!t)throw new Error(`Pending toast with key ${e} not found`);return void t.count++}const n={options:t,count:1,rafId:0};b.set(e,n),n.rafId=requestAnimationFrame(async()=>{const t=b.get(e);if(t){if(b.delete(e),v>=3)return w.push({options:t.options,key:e,count:t.count}),void await I();try{await k(t.options,e,t.count)}catch(t){}}})}catch(t){}}(n)}catch(e){var n;const o="string"==typeof(null==t?void 0:t.message)&&null!==(null==t?void 0:t.message)?`${null==t||null===(n=t.message)||void 0===n?void 0:n.substring(0,200)} toast creation failed!`:"Toast creation failed!";alert(o)}}let W=!1;async function R(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"undefined"!=typeof window&&"undefined"!=typeof document&&(await async function(){P||"undefined"!=typeof window&&"undefined"!=typeof document&&("complete"===document.readyState||"interactive"===document.readyState?(P=!0,B.forEach(t=>setTimeout(()=>j(t),2e3)),B.length=0):document.addEventListener("DOMContentLoaded",()=>{P=!0,B.forEach(t=>setTimeout(()=>j(t),2e3)),B.length=0},{once:!0}))}(),P?W?await j(t):(W=!0,setTimeout(await j(t),2e3)):B.push(t))}function $(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(A={...A,...t})}catch(t){}}function z(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(M={...M,...t})}catch(t){}}const D=async function(t){try{const e="all"===t?'[id^="toast-container-"][role="status"]':'[id^="toast-"]:not([id*="container"])';("all"===t?document.querySelectorAll(e):[document.querySelector(e)].filter(Boolean)).forEach(t=>{if("function"==typeof(null==t?void 0:t.remove))t.remove();else if(t)throw new TypeError("Element exists but remove() is not a function")})}catch(t){}};try{"undefined"!=typeof window&&(window.customizableToast={createToast:R,setDefaultColors:$,setDefaultMessages:z,noop:D})}catch(t){}export{R as createToast,D as noop,$ as setDefaultColors,z as setDefaultMessages};
|
|
15
|
+
async function t(t){return`${t}-${Date.now()}-${Math.floor(1e5*Math.random())}`}async function e(t,e){if(!t)return"snow";try{if("transparent"===t)return"snow";let i=await async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=e.threshold||4.5,r=o(t,e.resolveVarElement);if(!r)return{color:"#000000",contrast:21,meetsAA:!0,blackContrast:21,whiteContrast:1,used:"black"};let l;if(void 0!==r.a&&r.a<1){let t=e.underlyingColor;if(t){const n="string"==typeof t?o(t,e.resolveVarElement):t;t=n?{r:n.r,g:n.g,b:n.b}:{r:255,g:255,b:255}}else t={r:255,g:255,b:255};l=function(t,e){if(void 0===t.a||t.a>=1)return{r:t.r,g:t.g,b:t.b};e||(e={r:255,g:255,b:255});const n=t.a;return{r:Math.round(t.r*n+e.r*(1-n)),g:Math.round(t.g*n+e.g*(1-n)),b:Math.round(t.b*n+e.b*(1-n))}}(r,t)}else l={r:r.r,g:r.g,b:r.b};const c=a(l),u=s(c,1),d=s(c,0);if(u>=i||d>=i)return u>=d?{color:"#ffffff",contrast:u,meetsAA:u>=i,blackContrast:d,whiteContrast:u,used:"white"}:{color:"#000000",contrast:d,meetsAA:d>=i,blackContrast:d,whiteContrast:u,used:"black"};let f;f=u>d?i*(c+.05)-.05:(c+.05)/i-.05;f=Math.min(1,Math.max(0,f));const m=function(t){const e=function(t){return t<=.0031308?Math.round(12.92*t*255):Math.round(255*(1.055*Math.pow(t,1/2.4)-.055))}(t=Math.min(1,Math.max(0,t)));return o=e,i=e,r=e,"#"+n(o)+n(i)+n(r);var o,i,r}(f),p=a({r:parseInt(m.slice(1,3),16),g:parseInt(m.slice(3,5),16),b:parseInt(m.slice(5,7),16)}),h=s(c,p);return{color:m,contrast:h,meetsAA:h>=i,blackContrast:d,whiteContrast:u,used:"generated"}}(t,{underlyingColor:t||"#ffffff",threshold:e||4.5});return i}catch(t){return"snow"}}function n(t){return("0"+t.toString(16)).slice(-2)}function o(t){var e;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null===(e=document)||void 0===e?void 0:e.documentElement;if("string"!=typeof t||!t.trim())return null;const r=t.trim();if(r.startsWith("var(")&&"undefined"!=typeof window&&n){const t=r.slice(4,-1).trim(),e=getComputedStyle(n).getPropertyValue(t).trim();return e?o(e,n):null}if("undefined"!=typeof document)try{const t=document.createElement("canvas").getContext("2d");t.fillStyle="#000",t.fillStyle=r;const e=t.fillStyle,n=e.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([0-9.]+))?\)$/i);if(n)return{r:+n[1],g:+n[2],b:+n[3],a:void 0!==n[4]?+n[4]:1};if(e.startsWith("#"))return i(e)}catch(t){}if(/^#[0-9a-fA-F]{3,8}$/.test(r))return i(r);return{black:{r:0,g:0,b:0,a:1},white:{r:255,g:255,b:255,a:1},transparent:{r:0,g:0,b:0,a:0}}[r.toLowerCase()]||null}function i(t){let e=t.replace(/^#/,"");return 3!==e.length&&4!==e.length||(e=e.split("").map(t=>t+t).join("")),6===e.length?{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:1}:8===e.length?{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:parseInt(e.slice(6,8),16)/255}:null}function r(t){return(t/=255)<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}function a(t){return.2126*r(t.r)+.7152*r(t.g)+.0722*r(t.b)}function s(t,e){return(Math.max(t,e)+.05)/(Math.min(t,e)+.05)}async function l(t,e,n){const o=await async function(t){try{if("number"==typeof t&&t>0)return t;if("string"==typeof t){if(t.endsWith("s")&&!t.endsWith("ms")){const e=1e3*parseFloat(t);return e>0?e:500}const e=parseFloat(t);return e>0?e:500}}catch(t){}return 500}(e.animationDuration);Object.assign(t.style,{background:e.backgroundColor,padding:"12px 20px",marginBottom:"10px",borderRadius:e.borderRadius,overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"space-between",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",minWidth:"250px",maxWidth:e.maxWidth,opacity:"0",position:"relative",transition:`opacity ${e.animationDuration} ${e.animationEasing}, transform ${e.animationDuration} ${e.animationEasing}`,transform:"translateY(20px)",zIndex:"9999"}),t._animationDuration=o;const i=document.createElement("span");i.style.position=e.fontPosition,i.style.display="inline-block",i.style.flex="1",i.style.padding=e.fontPadding,i.style.borderRadius=e.fontBorderRadius,i.style.background=e.fontBackgroundColor,i.style.fontFamily=e.fontFamily,i.style.fontSize=e.fontSize,i.style.fontWeight=e.fontWeight,i.style.lineHeight=e.fontLineHeight,i.style.color=e.textColor,i.style.userSelect="text",i.style.wordBreak="break-word",i.style.direction=e.fontDirection,i.style.webkitLineClamp="3",i.style.webkitBoxOrient="vertical",i.style.whiteSpace=e.wrapText?"normal":"nowrap",i.style.display="block",i.style.overflow="hidden",i.style.textOverflow="ellipsis",i.style.lineClamp="3",i.style.boxOrient="vertical",i.style.display="-webkit-box",i.textContent=e.message,i.setAttribute("aria-label","Toast Notification Center"),i.setAttribute("title",e.message),t.appendChild(i),await async function(t,e,n){const o=null==e?void 0:e.cta;if(!o||!o.label)return;const i=!!o.href&&"link"===o.variant,r=document.createElement(i?"a":"button");i?(r.href=o.href,o.target&&(r.target=o.target),r.rel=o.rel||("_blank"===o.target?"noopener noreferrer":"")):r.type="button";r.setAttribute("aria-label",o.ariaLabel||o.label),Object.assign(r.style,{marginLeft:"10px",padding:"6px 10px",borderRadius:"6px",fontSize:"12px",fontWeight:"600",lineHeight:"1",border:"1px solid rgba(255,255,255,0.35)",color:e.textColor||"#fff",background:"rgba(255,255,255,0.15)",cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),r.textContent=o.label,r.addEventListener("click",async e=>{try{if("function"==typeof o.onClick){const t=o.onClick(e);null!=t&&t.then&&await t}}finally{!1!==o.autoClose&&n(t)}}),t.appendChild(r)}(t,e,n),e.showCloseButton&&await async function(t,e,n){const o=document.createElement("button");o.setAttribute("aria-label","Close notification"),o.setAttribute("title","Close"),o.textContent="×",Object.assign(o.style,{background:"none",border:"none",color:e.textColor,fontSize:"18px",marginLeft:"10px",cursor:"pointer"}),o.onclick=()=>n(t),t.appendChild(o),t._cleanupCloseButton=()=>{o.onclick=null}}(t,e,n),e.showProgressBar&&await async function(t,e){const n=document.createElement("div");Object.assign(n.style,{position:"absolute",left:"0",height:e.progressHeight||"4px",background:e.progressColor||"rgba(255, 255, 255, 0.3)",width:"100%",transition:`width ${e.duration||1800}ms linear`,["top"===e.progressPosition?"top":"bottom"]:"0"}),t.appendChild(n),setTimeout(()=>{!function(t){try{return(null==t?void 0:t.offsetWidth)||0}catch(t){return 0}}(n),n.style.width="0%"},100)}(t,e),await async function(t){setTimeout(()=>{requestAnimationFrame(()=>{t.style.opacity="1",t.style.transform="translateY(0)"})},50)}(t)}async function c(t,e){try{const n=document.createElement("div");return n.id=`emergency-${Date.now()}`,n.innerHTML=`\n <div style="\n background: #333 !important;\n color: white !important;\n padding: 10px 15px !important;\n position: fixed !important;\n top: 20px !important;\n right: 20px !important;\n z-index: 99999 !important;\n border-radius: 3px !important;\n max-width: 250px !important;\n word-wrap: break-word !important;\n font-family: Arial, sans-serif !important;\n font-size: 14px !important;\n box-shadow: 0 2px 10px rgba(0,0,0,0.3) !important;\n cursor: pointer !important;\n " onclick="this.parentNode.removeChild(this)">\n ${t.message||"Emergency Toast Creation Showing!"}\n <span style="float: right; margin-left: 10px; font-weight: bold;">×</span>\n </div>\n `,n._animationDuration=500,n._isEmergencyToast=!0,setTimeout(()=>{try{n.parentNode&&n.parentNode.removeChild(n),e(n)}catch(t){}},t.duration||1800),n}catch(n){return setTimeout(()=>{try{alert(t.message||"Toast Creation Failed!"),e(null)}catch(t){e(null)}},100),null}}async function u(e,n){let o;if(!document.querySelector('[id^="toast-container-"]'))return null;try{return o=await async function(e,n){try{const o=document.createElement(e);return o.id=await t(n),o}catch(e){try{const e="div",n="fallback",o=document.createElement(e);return o.id=await t(n),o.setAttribute("data-original-tag",e),o}catch(t){}}}("div","toast"),await l(o,e,n),o}catch(t){return await c(e,n),o}}const d=new Map,f=new Map;function m(){return`toast-container-${function(){return String(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"bottom-right").toLowerCase().trim().replace(/\bbelow\b/g,"bottom").replace(/\s+/g,"-").replace(/[^a-z0-9\-]/g,"-").replace(/\-+/g,"-")}(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"bottom-right")}`}async function p(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;const n=m(t.position);if(f.has(n))return f.get(n);const o=(async()=>{const o=d.get(n);if(o&&o.isConnected)return o;let i=document.getElementById(n);i&&!i.isConnected&&document.body.appendChild(i),i?(i.style.position=i.style.position||"fixed",i.style.zIndex=i.style.zIndex||"9999","function"==typeof e&&await e(i,t)):(i=document.createElement("div"),i.id=n,i.setAttribute("role","status"),i.setAttribute("aria-atomic","true"),i.style.position="fixed",i.style.zIndex="9999",i.style.inset="auto 10px 10px auto",i.style.display="flex",i.style.justifyContent="space-between",i.style.alignItems="center",i.style.flexDirection="column",i.style.overflow="hidden","function"==typeof e&&await e(i,t),document.body.appendChild(i));const r=document.querySelectorAll(`#${n}`);if(r.length>1)for(let t=1;t<r.length;t++)try{r[t].remove()}catch(t){}return d.set(n,i),i})();f.set(n,o);try{return await o}finally{f.delete(m(t.position))}}async function h(t,e){if(!t||!e.position)throw new Error("Invalid container or position!");!function(t){t.style.top="auto",t.style.bottom="auto",t.style.left="auto",t.style.right="auto",t.style.transform="none"}(t);const n=function(t){const e=t.toLowerCase().trim();return{hasTop:e.includes("top"),hasBottom:e.includes("bottom")||e.includes("below"),hasLeft:e.includes("left"),hasRight:e.includes("right"),hasCenter:e.includes("center"),hasFullWidth:e.includes("top-full-width")||e.includes("bottom-full-width")||e.includes("fullwidth")}}(e.position);(function(t,e,n){if(!n.hasFullWidth)return!1;if(e.maxWidth="100vw",n.hasTop)return t.style.top="10px",t.style.left="10px",t.style.right="10px",!0;if(n.hasBottom)return t.style.bottom="10px",t.style.left="10px",t.style.right="10px",!0;return!1})(t,e,n)||function(t,e){if(!e.hasCenter)return!1;if(e.hasTop&&!e.hasLeft&&!e.hasRight)return t.style.top="10px",t.style.left="50%",t.style.transform="translateX(-50%)",!0;if(e.hasBottom&&!e.hasLeft&&!e.hasRight)return t.style.bottom="10px",t.style.left="50%",t.style.transform="translateX(-50%)",!0;if(e.hasLeft&&!e.hasTop&&!e.hasBottom)return t.style.left="10px",t.style.top="50%",t.style.transform="translateY(-50%)",!0;if(e.hasRight&&!e.hasTop&&!e.hasBottom)return t.style.right="10px",t.style.top="50%",t.style.transform="translateY(-50%)",!0;if(!(e.hasLeft||e.hasRight||e.hasTop||e.hasBottom))return t.style.top="50%",t.style.left="50%",t.style.transform="translate(-50%, -50%)",!0;return!1}(t,n)||function(t,e){e.hasBottom?t.style.bottom="10px":e.hasTop&&(t.style.top="10px");e.hasRight?t.style.right="10px":e.hasLeft?t.style.left="10px":(t.style.bottom="10px",t.style.left="50%",t.style.transform="translateX(-50%)")}(t,n)}class y{constructor(t,e){this.callback=t,this.delay=e,this.remaining=e,this.startTime=null,this.timeoutId=null,this.isPaused=!1,this.isCompleted=!1}start(){return this.isCompleted||this.timeoutId||(this.startTime=Date.now(),this.timeoutId=setTimeout(()=>{this.isCompleted=!0,this.timeoutId=null,this.callback()},this.remaining)),this}pause(){return this.isPaused||!this.timeoutId||this.isCompleted||(clearTimeout(this.timeoutId),this.timeoutId=null,this.remaining-=Date.now()-this.startTime,this.remaining=Math.max(0,this.remaining),this.isPaused=!0),this}resume(){return!this.isPaused||this.isCompleted||(this.isPaused=!1,this.start()),this}clear(){return this.timeoutId&&(clearTimeout(this.timeoutId),this.timeoutId=null),this.isCompleted=!0,this}getRemainingTime(){return this.isCompleted?0:this.isPaused?this.remaining:this.timeoutId?Math.max(0,this.remaining-(Date.now()-this.startTime)):this.delay}}const g=new Map,b=new Map,w=[];let v=0;function x(t){let e=5381;for(let n=0;n<t.length;n++)e=(e<<5)+e+t.charCodeAt(n);return e>>>0}async function C(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{const e=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const e=String(t.type||"info").trim().toLowerCase(),n=t.message||"",o=String(t.position||"bottom-right").trim().toLowerCase();return[e,x(String(n)).toString(16),o].join("|")}(t);if(g.has(e)){const n=g.get(e);if(!n)throw new Error(`Active toast with key ${e} not found`);return n.count++,n.timer.clear(),n.timer=E(n.toast,t),await T(n),void await L(n)}if(b.has(e)){const t=b.get(e);if(!t)throw new Error(`Pending toast with key ${e} not found`);return void t.count++}const n={options:t,count:1,rafId:0};b.set(e,n),n.rafId=requestAnimationFrame(async()=>{const t=b.get(e);if(t){if(b.delete(e),v>=3)return w.push({options:t.options,key:e,count:t.count}),void await S();try{await k(t.options,e,t.count)}catch(t){}}})}catch(t){}}async function k(t,e,n){try{if(!t||"object"!=typeof t)throw new TypeError("options must be an object");v++;const o=await p(t,h);if(!o)throw new Error("Failed to create toast container");const i=await u(t,I);if(!i)throw new Error("Toast element creation failed");const r=document.createElement("div");Object.assign(r.style,{position:"relative",display:"inline-block",overflow:"visible",marginBottom:"10px",zIndex:"0",width:"100%"});const a=document.createElement("div");Object.assign(a.style,{position:"relative",overflow:"hidden",borderRadius:t.borderRadius||"8px",zIndex:"1"}),a.appendChild(i),r.appendChild(a),o.id.includes("toast-container-")&&o.appendChild(r);const s=!1!==t.pauseOnHover&&(!0===t.pauseOnHover||!!t.cta),l={outer:r,toast:i,count:Math.max(1,0|n),timeout:null,pauseOnHover:s};g.set(e,l),i._key=e,l.count>1&&await L(l),l.timer=E(i,t),await T(l)}catch(e){v=Math.max(0,v-1);(document.querySelector('[id^="toast-container-"]')||document.body).appendChild(await c(t,I))}}function E(t,e){const n=(e.duration||1800)+10,o=new y(async()=>await I(t),n);return o.start(),o}async function T(t){if(!t.pauseOnHover||!t.outer||!t.timer)return;const{outer:e,timer:n}=t,o=()=>{n.pause()},i=()=>{n.resume()},r=t=>{t.target.matches("button, a, [tabindex]")&&n.pause()},a=t=>{e.contains(t.relatedTarget)||n.resume()};e.addEventListener("mouseenter",o),e.addEventListener("mouseleave",i),e.addEventListener("focusin",r),e.addEventListener("focusout",a),e._pauseCleanup=()=>{e.removeEventListener("mouseenter",o),e.removeEventListener("mouseleave",i),e.removeEventListener("focusin",r),e.removeEventListener("focusout",a)}}async function I(t){try{var e,n,o;if(null==t||!t._key)return;const i=g.get(t._key);if(!i)return;null===(e=i.timer)||void 0===e||e.clear(),null===(n=i.outer)||void 0===n||null===(o=n._pauseCleanup)||void 0===o||o.call(n),g.delete(t._key),v=Math.max(0,v-1);const r=i.outer.querySelector(".toast-count-badge");r&&r.remove(),await async function(t){return t?new Promise(e=>{let n=!1;const o=()=>{n||(n=!0,async function(t){if(!t)return!0;try{var e;if(null!=t&&null!==(e=t.parentNode)&&void 0!==e&&e.id.includes("toast-container-"))return t.parentNode.removeChild(t),!0}catch(e){try{if(t.remove)return t.remove(),!0}catch(e){try{return t.style.display="none",t.style.opacity="0",t.style.pointerEvents="none",t.style.position="absolute",t.style.left="-9999px",!0}catch(t){return!1}}}}(t),e())},i=t.firstElementChild||t;if(!i)return Promise.resolve();const r=t=>{try{if(t.target!==i)return;i.removeEventListener("transitionend",r,!0),o()}catch(t){}};try{i.addEventListener("transitionend",r,!0)}catch(t){}setTimeout(()=>{try{i.removeEventListener("transitionend",r,!0),o()}catch(t){}},700)}):Promise.resolve()}(i.outer),await S()}catch(t){}}async function S(){for(;v<3&&w.length;){const t=w.shift();if(g.has(t.key)){const e=g.get(t.key);e.count+=t.count,await L(e);continue}k(t.options,t.key,t.count)}}async function L(t){let{outer:e,count:n}=t;if(!e||!e instanceof HTMLElement)throw new Error("updateBadge: outer must be a valid HTMLElement");if(n<2){const t=e.querySelector(".toast-count-badge");return void(t&&t.remove())}let o=e.querySelector(".toast-count-badge");o||(o=document.createElement("span"),o.className="toast-count-badge",o.setAttribute("aria-label",`${n} identical notifications`),Object.assign(o.style,{position:"absolute",top:"6px",right:"6px",backgroundColor:"#f44336",color:"#fff",borderRadius:"50%",minWidth:"20px",height:"20px",fontSize:"12px",fontWeight:"600",display:"flex",alignItems:"center",justifyContent:"center",border:"2px solid #fff",boxShadow:"0 2px 6px rgba(0,0,0,0.3)",zIndex:"2",pointerEvents:"none",transition:"transform 150ms ease"}),e.appendChild(o)),o.textContent=n>99?"99+":String(n);try{o.style.transform="scale(1.2)",setTimeout(()=>o.style.transform="scale(1)",150)}catch(t){}}let M={success:"#28a745",error:"#dc3545",warning:"#ffc107",info:"#17a2b8"},A={success:"Operation completed successfully!",error:"Something went wrong!",warning:"Warning message!",info:"Information message!"};const B=[];let P=!1;async function j(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{const n=await async function(t){var n,o;const i=null==t||null===(n=t.position)||void 0===n||null===(n=n.toLowerCase())||void 0===n?void 0:n.trim(),r=null!=i&&i.includes("top-full-width")||null!=i&&i.includes("bottom-full-width")?"100vw":"400px",a={pauseOnHover:void 0,duration:1800,position:"bottom-right",type:"info",borderRadius:"50px",backgroundColor:void 0,textColor:void 0,showCloseButton:!0,animationDuration:"0.4s",animationType:"fade",animationEasing:"ease",showProgressBar:!0,progressColor:void 0,progressHeight:"4px",progressPosition:"bottom",fontPosition:"relative",fontPadding:void 0,fontBorderRadius:void 0,fontBackgroundColor:void 0,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"',fontSize:"14px",fontWeight:"400",fontLineHeight:"1.4",fontDirection:"auto",wrapText:"normal",maxWidth:r,..."object"!=typeof t||Array.isArray(t)?{}:t};a.message=null!==(o=null==t?void 0:t.message)&&void 0!==o?o:a.message;try{var s,l,c;if(!a.backgroundColor)a.backgroundColor=null!==(l=null===(c=M)||void 0===c?void 0:c[a.type])&&void 0!==l?l:window.matchMedia("(prefers-color-scheme: dark)").matches?"#f5f5f5":"#111111";if(a.message=a.message||(null===(s=A)||void 0===s?void 0:s[a.type])||"No Message Provided!",!a.textColor&&a.backgroundColor){const t=await e(a.backgroundColor);a.textColor=null==t?void 0:t.color}if(!a.progressColor&&a.backgroundColor)if(a.textColor)a.progressColor=a.textColor;else{const t=await e(a.backgroundColor);a.progressColor=null==t?void 0:t.color}}catch(t){}"string"!=typeof a.message&&(a.message="No Message Provided!");return a}(t);await async function(t){try{return await p(t,h)}catch(t){return document.body}}(n),await C(n)}catch(e){var n;const o="string"==typeof(null==t?void 0:t.message)&&null!==(null==t?void 0:t.message)?`${null==t||null===(n=t.message)||void 0===n?void 0:n.substring(0,200)} toast creation failed!`:"Toast creation failed!";alert(o)}}let W=!1;async function R(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};"undefined"!=typeof window&&"undefined"!=typeof document&&(await async function(){P||"undefined"!=typeof window&&"undefined"!=typeof document&&("complete"===document.readyState||"interactive"===document.readyState?(P=!0,B.forEach(t=>setTimeout(()=>j(t),2e3)),B.length=0):document.addEventListener("DOMContentLoaded",()=>{P=!0,B.forEach(t=>setTimeout(()=>j(t),2e3)),B.length=0},{once:!0}))}(),P?W?await j(t):(W=!0,setTimeout(()=>{j(t).catch(t=>{})},2e3)):B.push(t))}function $(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(M={...M,...t})}catch(t){}}function z(t){try{t&&"object"==typeof t&&!Array.isArray(t)&&(A={...A,...t})}catch(t){}}const D=async function(){let t=document.querySelector('[id^="toast-"]:not([id*="container"])');await I(t)};try{"undefined"!=typeof window&&(window.customizableToast={createToast:R,setDefaultColors:$,setDefaultMessages:z,noop:D})}catch(t){}export{R as createToast,D as noop,$ as setDefaultColors,z as setDefaultMessages};
|
|
16
16
|
//# sourceMappingURL=index.esm.mjs.map
|