StocksNew/public/vendor/flasher/flasher.min.js

2 lines
8.9 KiB
JavaScript
Raw Normal View History

2024-08-27 12:03:06 +00:00
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).flasher=e()}(this,(function(){"use strict";function t(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}var e=function(){function t(t){this.options={timeout:5e3,fps:30,position:"top-right",direction:"top",rtl:!1,style:{},darkMode:"media"},this.viewFactory=t}return t.prototype.success=function(t,e,n){this.flash("success",t,e,n)},t.prototype.info=function(t,e,n){this.flash("info",t,e,n)},t.prototype.warning=function(t,e,n){this.flash("warning",t,e,n)},t.prototype.error=function(t,e,n){this.flash("error",t,e,n)},t.prototype.flash=function(t,e,n,o){var r=this.createNotification(t,e,n,o);this.renderOptions({}),this.render({notification:r})},t.prototype.createNotification=function(t,e,n,o){if("object"==typeof t?(t=(o=t).type,e=o.message,n=o.title):"object"==typeof e?(e=(o=e).message,n=o.title):"object"==typeof n&&(n=(o=n).title),void 0===e)throw new Error("message option is required");return{type:t||"info",message:e,title:n,options:o}},t.prototype.render=function(t){var e=this,n=t.notification.options||{},o=Array.isArray(n)?this.options:Object.assign({},this.options,n),r=function(){var n=e.createContainer(o);e.addToContainer(n,t,o)};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",r):r()},t.prototype.renderOptions=function(t){this.options=Object.assign({},this.options,t),this.applyDarkMode()},t.prototype.createContainer=function(t){var e='.fl-main-container[data-position="'.concat(t.position,'"]'),n=document.querySelector(e);return n?(n.dataset.turboCache="false",n.classList.add("fl-no-cache"),n):((n=document.createElement("div")).classList.add("fl-main-container"),n.dataset.position=t.position,n.dataset.turboCache="false",n.classList.add("fl-no-cache"),Object.keys(t.style).forEach((function(e){null==n||n.style.setProperty(e,t.style[e])})),document.body.append(n),n)},t.prototype.addToContainer=function(t,e,n){var o=this.stringToHTML(e.template||this.viewFactory.render(e));o.classList.add("fl-container"),this.appendNotification(t,o,n),this.renderProgressBar(o,n),this.handleClick(o)},t.prototype.appendNotification=function(t,e,n){"bottom"===n.direction?t.append(e):t.prepend(e),n.rtl&&e.classList.add("fl-rtl"),setTimeout((function(){e.classList.add("fl-show")}),100)},t.prototype.removeNotification=function(t){var e=t.parentElement;t.classList.remove("fl-show"),t.addEventListener("transitionend",(function(){t.remove(),e.hasChildNodes()||e.remove()}))},t.prototype.handleClick=function(t){var e=this;t.addEventListener("click",(function(){return e.removeNotification(t)}))},t.prototype.renderProgressBar=function(t,e){var n=this;if(e.timeout&&!(e.timeout<=0)){var o=document.createElement("span");o.classList.add("fl-progress");var r=t.querySelector(".fl-progress-bar");r&&r.append(o);var i=1e3/e.fps,s=0,a=function(){var r=100*(1-i*((s+=1)/e.timeout));o.style.width="".concat(r,"%"),r<=0&&(clearInterval(c),n.removeNotification(t))},c=window.setInterval(a,i);t.addEventListener("mouseout",(function(){return c=window.setInterval(a,i)})),t.addEventListener("mouseover",(function(){return clearInterval(c)}))}},t.prototype.applyDarkMode=function(){if(!document.body.classList.contains("fl-dark-mode")&&!document.querySelector("style.flasher-js")){var t=[].concat(this.options.darkMode),e=t[0],n=t[1],o=void 0===n?".dark":n,r=".fl-main-container .fl-container.fl-flasher {background-color: rgb(15, 23, 42);color: rgb(255, 255, 255);}";r="media"===e?"@media (prefers-color-scheme: dark) {".concat(r,"}"):"".concat(o," ").concat(r);var i=document.createElement("style");i.type="text/css",i.classList.add("flasher-js"),i.appendChild(document.createTextNode(r)),document.head.appendChild(i),document.body.classList.add("fl-dark-mode")}},t.prototype.stringToHTML=function(t){var e=function(){if(!DOMParser)return!1;var t=n