1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
"use strict";define("notify",[],function(){return class{constructor(e){this.queue=new Promise((e,t)=>{e()});let t=document.createElement("div");t.classList.add("notify");let s=document.createElement("div");s.classList.add("notify__messages"),t.appendChild(s),e.appendChild(t),this.container=s}queueMessage(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=t.timeout||1100,i=t.level||null,n=t.sticky||!1,a=this.renderMessage(e,n,i);if(this.container.appendChild(a),n)return void(this.queue=this.queue.then(()=>this.showMessage(a)));this.queue=this.queue.then(()=>this.showMessage(a)).then(()=>new Promise(e=>{setTimeout(()=>{e()},this.calculateTimeout(a,s))})).then(()=>this.hideMessage(a)).then(()=>this.removeMessage(a))}showMessage(e){return new Promise((t,s)=>{"0s"!==window.getComputedStyle(e).getPropertyValue("transition-duration")?e.addEventListener("transitionend",()=>{t()}):t(),e.classList.remove("invisible")})}hideMessage(e){return new Promise((t,s)=>{"0s"!==window.getComputedStyle(e).getPropertyValue("transition-duration")?e.addEventListener("transitionend",()=>{t()}):t(),e.classList.add("invisible")})}removeMessage(e){return new Promise(t=>{e.parentNode.removeChild(e),t()})}renderMessage(e,t,s){let i=document.createElement("div");return i.innerHTML=e,i.classList.add("notify__message"),i.classList.add("invisible"),t?i.classList.add("sticky"):i.addEventListener("click",e=>{e.preventDefault(),this.hideMessage(i),this.removeMessage(i)}),s&&i.classList.add(s),i}calculateTimeout(e,t){let s=e.innerText.length-25/30;return t+Math.max(0,1e3*s)}}}); |