UNPKG

bro-toastify

Version:

A framework-agnostic toast notification library

3 lines (2 loc) 8.07 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const n={default:{type:"fade",duration:300,easing:"ease"},success:{type:"fade",duration:300,easing:"ease"},error:{type:"fade",duration:300,easing:"ease"},info:{type:"fade",duration:300,easing:"ease"},warning:{type:"fade",duration:500,easing:"ease"},loading:{type:"fade",duration:300,easing:"ease"},show:{type:"fade",duration:300,easing:"ease"},promises:{type:"fade",duration:300,easing:"ease"},fade:{type:"fade",duration:300,easing:"ease"},"top-slide":{type:"top-slide",duration:300,easing:"ease"},"right-slide":{type:"right-slide",duration:300,easing:"ease"},"bottom-slide":{type:"bottom-slide",duration:300,easing:"ease"},"left-slide":{type:"left-slide",duration:300,easing:"ease"},zoom:{type:"zoom",duration:300,easing:"ease"},flip:{type:"flip",duration:300,easing:"ease"},bounce:{type:"bounce",duration:300,easing:"ease"},none:{type:"none",duration:0,easing:"ease"}};const e={type:"default",duration:3e3,position:"top-right",dismissible:!0,pauseOnHover:!0,customIcon:void 0,customClass:void 0},t=new Map,o=new Map,i=()=>Date.now().toString(36)+Math.random().toString(36).substring(2,5);function s(o){if(!o.message)return void console.error("BroToastify: message is required");const s=o.type||"default",a=o.containerOptions||{},f=a.animation?{...n[a.animation]}:n.fade,l={...e,...o,duration:"loading"===o.type?0:o.duration??e.duration,animation:{...n[s],...f,...o.animation}},c=o.id||i(),m={...l,id:c,createdAt:Date.now()};return t.set(c,m),d("create",m),l.duration&&l.duration>0&&"undefined"!=typeof window&&setTimeout((()=>{r(c)}),l.duration),m}function r(n){let e,o;"string"==typeof n?(e=n,o=Array.from(t.values()).find((n=>n.id===e))):(e=n.id,o=n),o&&(t.delete(e),d("dismiss",o),o.onClose&&o.onClose())}function a(n,e){return"undefined"==typeof window?{off:()=>{}}:(o.has(n)||o.set(n,[]),o.get(n).push(e),{off:()=>{const t=o.get(n);if(t){const n=t.indexOf(e);-1!==n&&t.splice(n,1)}}})}function d(n,e){if("undefined"!=typeof window){const t=o.get(n);t&&t.forEach((n=>n(e)))}}const f={show:(n,e)=>s({message:n,type:"show",...e}),default:(n,e)=>s({message:n,type:"default",...e}),success:(n,e)=>s({message:n,type:"success",...e}),error:(n,e)=>s({message:n,type:"error",...e}),info:(n,e)=>s({message:n,type:"info",...e}),warning:(n,e)=>s({message:n,type:"warning",...e}),loading:(n,e)=>{const t=i();return s({id:t,message:n,type:"loading",...e}),{id:t}},promises:(n,e,t)=>{const o=i();return s({id:o,message:e.loading,type:"loading",...t}),n.then((n=>(r(o),s({message:e.success,type:"success",...t}),n))).catch((n=>{throw r(o),s({message:e.error,type:"error",...t}),n})),{id:o}},isToastActive:n=>!!Array.from(t.values()).find((e=>e.id===n)),dismiss:n=>r(n),dismissible:n=>r(n),clearAll:function(){Array.from(t.values()).forEach((n=>{r(n.id)}))}};let l=!1;const c=f;exports.ToastContainerComponent=class{position="top-right";newestOnTop=!0;toasts=[];createUnsubscribe=null;dismissUnsubscribe=null;ngOnInit(){const n=a("create",(n=>{n.position===this.position&&(this.newestOnTop?this.toasts=[n,...this.toasts]:this.toasts=[...this.toasts,n])}));this.createUnsubscribe=n.off;const e=a("dismiss",(n=>{this.toasts=this.toasts.filter((e=>e.id!==n.id))}));this.dismissUnsubscribe=e.off}ngOnDestroy(){this.createUnsubscribe&&this.createUnsubscribe(),this.dismissUnsubscribe&&this.dismissUnsubscribe()}handleDismiss(n){f.dismissible(n)}},exports.ToastService=class{constructor(){"undefined"!=typeof window&&function(){if("undefined"==typeof window||l)return;const n="broToastify-styles";if(document.getElementById(n))l=!0;else try{const e=document.createElement("style");e.id=n,e.innerHTML="\n .broToastify-container {\n position: fixed;\n z-index: 9999;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n max-width: 100%;\n max-height: 100vh;\n overflow-y: auto;\n padding: 1rem;\n }\n \n .broToastify-notification {\n position: relative;\n min-width: 300px;\n max-width: 500px;\n padding: 1rem;\n border-radius: 0.375rem;\n box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);\n overflow: hidden;\n display: flex;\n flex-direction: column;\n opacity: 1 !important;\n visibility: visible !important;\n }\n\n .broToastify-default {\n background-color: rgb(240, 241, 240);\n color: #333;\n }\n \n .broToastify-success {\n background-color: #10B981;\n color: white;\n }\n \n .broToastify-error {\n background-color: #EF4444;\n color: white;\n }\n \n .broToastify-info {\n background-color: #3B82F6;\n color: white;\n }\n \n .broToastify-warning {\n background-color: #F59E0B;\n color: white;\n }\n\n .broToastify-loading {\n background-color: #F3F4F6;\n color: #333;\n }\n\n .broToastify-loader-container {\n display: flex;\n align-items: center;\n gap: 0.5rem;\n } \n\n .broToastify-loader {\n border: 4px solid #f3f3f3;\n border-top: 4px solid #3498db;\n border-radius: 50%;\n width: 20px;\n height: 20px;\n animation: spin 1s linear infinite;\n }\n\n .broToastify-loader-message {\n font-size: 0.875rem;\n color: #333;\n animation: fadeIn 0.3s ease-in-out;\n }\n\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n\n @keyframes fadeIn {\n 0% { opacity: 0; transform: translateY(-10px); }\n 100% { opacity: 1; transform: translateY(0); }\n }\n \n .broToastify-title {\n font-weight: bold;\n margin-bottom: 0.25rem;\n font-size: 1rem;\n }\n \n .broToastify-message {\n font-size: 0.875rem;\n }\n \n .broToastify-close {\n position: absolute;\n top: 0.5rem;\n right: 0.5rem;\n background: transparent;\n border: none;\n color: currentColor;\n font-size: 1.25rem;\n cursor: pointer;\n opacity: 0.7;\n transition: opacity 0.2s;\n }\n \n .broToastify-close:hover {\n opacity: 1;\n }\n \n .broToastify-top-right {\n top: 1rem;\n right: 1rem;\n align-items: flex-end;\n }\n \n .broToastify-top-left {\n top: 1rem;\n left: 1rem;\n align-items: flex-start;\n }\n \n .broToastify-bottom-right {\n bottom: 1rem;\n right: 1rem;\n align-items: flex-end;\n }\n \n .broToastify-bottom-left {\n bottom: 1rem;\n left: 1rem;\n align-items: flex-start;\n }\n \n .broToastify-top-center {\n top: 1rem;\n left: 50%;\n transform: translateX(-50%);\n align-items: center;\n }\n \n .broToastify-bottom-center {\n bottom: 1rem;\n left: 50%;\n transform: translateX(-50%);\n align-items: center;\n }\n \n undefined\n undefined\n undefined\n undefined\n undefined\n undefined\n undefined\n undefined\n \n @media (max-width: 576px) {\n .broToastify-container {\n width: 100%;\n padding: 0 1rem;\n }\n \n .broToastify-notification {\n min-width: 100%;\n max-width: 100%;\n }\n \n .broToastify-top-center,\n .broToastify-top-right,\n .broToastify-top-left {\n top: 0;\n right: 0;\n left: 0;\n transform: none;\n }\n \n .broToastify-bottom-center,\n .broToastify-bottom-right,\n .broToastify-bottom-left {\n bottom: 0;\n right: 0;\n left: 0;\n transform: none;\n }\n }\n ",document.head.appendChild(e),l=!0}catch(n){console.error("Failed to inject bro-toastify styles:",n)}}()}show(n,e){return f.show(n,e)}success(n,e){return f.success(n,e)}error(n,e){return f.error(n,e)}info(n,e){return f.info(n,e)}warning(n,e){return f.warning(n,e)}dismiss(n){f.dismissible(n)}clearAll(){f.clearAll()}},exports.angularToast=c; //# sourceMappingURL=angular.cjs.js.map