UNPKG

notify-zh

Version:

Es una pequeña libreria de notificaciones para el FrontEnd. Esta libreria tiene un peso de 1.4 Kb.

1 lines 4.26 kB
'use strict';var v=n=>{throw TypeError(n)};var g=(n,t,e)=>t.has(n)||v("Cannot "+e);var c=(n,t,e)=>(g(n,t,"read from private field"),e?e.call(n):t.get(n)),f=(n,t,e)=>t.has(n)?v("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(n):t.set(n,e),b=(n,t,e,s)=>(g(n,t,"write to private field"),t.set(n,e),e),l=(n,t,e)=>(g(n,t,"access private method"),e);var A=(n,t,e,s)=>({set _(i){b(n,t,i);},get _(){return c(n,t,s)}});var R="notifyContainer",w="divNotification",_="notifyCustom",C="animateInOpacity",z="animateOutOpacity",h,x,a,o,F,M,k,D,H,B,y,N=class{constructor(){f(this,o);f(this,h,false);f(this,x,1);f(this,a,{defaultTime:3e3,position:"center-top",disableDefaultStyles:false,classNames:{},backgrounds:{warning:"#F09200",error:"#DE350B",success:"#13BF5F",info:"#4261fb"}});}config(t){var e;b(this,a,{...c(this,a),...t,classNames:{...c(this,a).classNames,...(e=t.classNames)!=null?e:{}}});}success(t){l(this,o,y).call(this,{...t,type:"success"});}warning(t){l(this,o,y).call(this,{...t,type:"warning"});}error(t){l(this,o,y).call(this,{...t,type:"error"});}info(t){l(this,o,y).call(this,{...t,type:"info"});}};h=new WeakMap,x=new WeakMap,a=new WeakMap,o=new WeakSet,F=function(t){let e="position:fixed;z-index:2000;pointer-events:none;",s={"top-left":"top:20px;left:20px","top-right":"top:20px;right:20px","bottom-left":"bottom:20px;left:20px","bottom-right":"bottom:20px;right:20px","center-bottom":"bottom:20px;left:50%;transform:translateX(-50%)","center-top":"top:20px;left:50%;transform:translateX(-50%)",center:"top:50%;left:50%;transform:translate(-50%,-50%)"};return e+(s[t]||s["center-top"])},M=function(){if(document.getElementById("notify-zh-styles"))return;let t=document.createElement("style");t.id="notify-zh-styles",t.textContent=`.${_}{z-index:9999;border-radius:5px;box-sizing:border-box;color:#fff;font-size:1rem;background:#000;text-align:center;padding:12px 40px;opacity:0;display:inline;margin-bottom:10px;box-shadow:0 2px 1px -1px rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 1px 3px 0 rgba(0,0,0,.12)}.${C}{animation:showOpacity 1s}.${z}{animation:hideOpacity 1s}@keyframes showOpacity{from{opacity:0}to{opacity:1}}@keyframes hideOpacity{from{opacity:1}to{opacity:0}}`,document.head.appendChild(t);},k=function(t){let e=`${R}-${t}`,s=document.getElementById(e);if(!s){s=document.createElement("div"),s.id=e;let i=l(this,o,F).call(this,t);s.style.cssText=i;let r=document.createElement("div");r.id=`${w}-${t}`,r.style.display="flex",r.style.flexDirection=t.includes("bottom")?"column":"column-reverse",r.style.alignItems="center",s.appendChild(r),document.body.appendChild(s);}return s},D=function(t){var I,E,P,T,S,L;let{type:e,message:s,icon:i}=t,r=A(this,x)._++,d=(E=(I=c(this,a).backgrounds)==null?void 0:I[e])!=null?E:"#000",m=(T=(P=c(this,a).classNames)==null?void 0:P.base)!=null?T:_,u=(L=(S=c(this,a).classNames)==null?void 0:S[e])!=null?L:`notify-${e}`,p=document.createElement("div");p.className=`${m} ${u}`,p.id=`notify-${r}`;let O=document.createElement("span");if(O.textContent=s,i!=null&&i.el){let $=document.createElement("span");$.innerHTML=i==null?void 0:i.el,p.appendChild($);}return p.appendChild(O),p.style.display="flex",p.style.alignItems="center",p.style.background=d,p},H=function(t){var i,r,d,m;let e=(r=(i=c(this,a).classNames)==null?void 0:i.animateOut)!=null?r:z,s=(m=(d=c(this,a).classNames)==null?void 0:d.animateIn)!=null?m:C;t.addEventListener("animationend",()=>{t.remove();},{once:true}),t.classList.remove(s),t.classList.add(e);},B=function(t){var s,i;let e=(i=(s=c(this,a).classNames)==null?void 0:s.animateIn)!=null?i:C;t.style.opacity="0",requestAnimationFrame(()=>{t.addEventListener("animationend",()=>{},{once:true}),t.classList.add(e),t.style.opacity="1";});},y=function(t){var m,u,p;!c(this,h)&&!c(this,a).disableDefaultStyles&&(l(this,o,M).call(this),b(this,h,true));let e=(u=(m=t.position)!=null?m:c(this,a).position)!=null?u:"center-top",i=l(this,o,k).call(this,e).querySelector(`#${w}-${e}`);if(!i){console.error("Notify zh: Notification wrapper not available.");return}let r=l(this,o,D).call(this,t),d=(p=t.time)!=null?p:c(this,a).defaultTime;i.appendChild(r),l(this,o,B).call(this,r),setTimeout(()=>{l(this,o,H).call(this,r);},d);};var q=new N,Y=q;module.exports=Y;