!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";var t=function(t){return function(t){return!!t&&"object"==typeof t}(t)&&!function(t){var n=Object.prototype.toString.call(t);return"[object RegExp]"===n||"[object Date]"===n||function(t){return t.$$typeof===e}(t)}(t)};var e="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function n(t,e){return!1!==e.clone&&e.isMergeableObject(t)?a((n=t,Array.isArray(n)?[]:{}),t,e):t;var n}function r(t,e,r){return t.concat(e).map((function(t){return n(t,r)}))}function o(t){return Object.keys(t).concat(function(t){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t).filter((function(e){return t.propertyIsEnumerable(e)})):[]}(t))}function i(t,e){try{return e in t}catch(t){return!1}}function s(t,e,r){var s={};return r.isMergeableObject(t)&&o(t).forEach((function(e){s[e]=n(t[e],r)})),o(e).forEach((function(o){(function(t,e){return i(t,e)&&!(Object.hasOwnProperty.call(t,e)&&Object.propertyIsEnumerable.call(t,e))})(t,o)||(i(t,o)&&r.isMergeableObject(e[o])?s[o]=function(t,e){if(!e.customMerge)return a;var n=e.customMerge(t);return"function"==typeof n?n:a}(o,r)(t[o],e[o],r):s[o]=n(e[o],r))})),s}function a(e,o,i){(i=i||{}).arrayMerge=i.arrayMerge||r,i.isMergeableObject=i.isMergeableObject||t,i.cloneUnlessOtherwiseSpecified=n;var a=Array.isArray(o);return a===Array.isArray(e)?a?i.arrayMerge(e,o,i):s(e,o,i):n(o,i)}a.all=function(t,e){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce((function(t,n){return a(t,n,e)}),{})};var c=a,u=function(){function t(){this.options={timeout:5e3,fps:30,position:"top-right",direction:"top",style:{position:"fixed",maxWidth:"304px",width:"100%",zIndex:999999,transition:"0.8s"}}}return t.prototype.render=function(e){var n=e.notification,r=t.stringToHTML(e.template||"");if(r){var o=JSON.parse(JSON.stringify(this.options));Array.isArray(n.options)||(o=c(o,n.options)),r.style.transition=o.style.transition,void 0!==n.options&&void 0!==n.options.position&&(o.position=n.options.position);var i=document.getElementById("flasher-container-"+o.position);if(null===i){switch((i=document.createElement("div")).id="flasher-container-"+o.position,Object.keys(o.style).forEach((function(t){i.style.setProperty(t,o.style[t])})),i.style.maxWidth=o.style.maxWidth,o.position){case"top-left":i.style.top=o.style.top||"0",i.style.left=o.style.left||"0.5em";break;case"top-right":i.style.top=o.style.top||"0",i.style.right=o.style.right||"0.5em";break;case"bottom-left":i.style.bottom=o.style.bottom||"0",i.style.left=o.style.left||"0.5em";break;case"bottom-right":default:i.style.bottom=o.style.bottom||"0",i.style.right=o.style.right||"0.5em"}document.getElementsByTagName("body")[0].appendChild(i)}switch(o.direction){case"top":i.insertBefore(r,i.firstChild);break;case"bottom":default:i.appendChild(r)}r.addEventListener("click",(function(){r.style.transform="scale(1.05)",setTimeout((function(){r.remove()}),200)}));var s=r.querySelector(".flasher-progress");if(s instanceof HTMLElement&&o.timeout>0){var a,u=0,l=1e3/o.fps,f=function(){var t=100*(1-l*((u+=1)/o.timeout));s.style.width=t+"%",t<=0&&(r.style.opacity="0",clearInterval(a),setTimeout((function(){r.remove()}),900))};a=setInterval(f,l),r.addEventListener("mouseover",(function(){clearInterval(a)})),r.addEventListener("mouseout",(function(){a=setInterval(f,l)}))}}},t.prototype.renderOptions=function(t){this.options=c(this.options,t)},t.stringToHTML=function(t){if(function(){if(!DOMParser)return!1;var t=new DOMParser;try{t.parseFromString("x","text/html")}catch(t){return!1}return!0}())return(new DOMParser).parseFromString(t,"text/html").body.firstChild;var e=document.createElement("div");return e.innerHTML=t,e.firstElementChild},t}(),l=function(){function t(){this.factories=new Map}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.render=function(t){var e=this;this.addStyles(t.styles,(function(){e.addScripts(t.scripts,(function(){e.renderOptions(t.options),e.renderEnvelopes(t.envelopes,t.context)}))}))},t.prototype.addStyles=function(t,e){var n=this;if(0!==t.length)if(null===document.querySelector('link[href="'+t[0]+'"]')){var r=document.createElement("link");r.setAttribute("href",t[0]),r.setAttribute("type","text/css"),r.setAttribute("rel","stylesheet"),r.onload=function(){return n.addStyles(t.slice(1),e)},document.head.appendChild(r)}else this.addStyles(t.slice(1),e);else"function"==typeof e&&e()},t.prototype.addScripts=function(t,e){var n=this;if(0!==t.length)if(null===document.querySelector('script[src="'+t[0]+'"]')){var r=document.createElement("script");r.setAttribute("src",t[0]),r.setAttribute("type","text/javascript"),r.onload=function(){return n.addScripts(t.slice(1),e)},document.body.appendChild(r)}else this.addScripts(t.slice(1),e);else"function"==typeof e&&e()},t.prototype.renderOptions=function(t){var e=this;Object.entries(t).forEach((function(t){var n=t[0],r=t[1],o=e.create(n);void 0!==o&&o.renderOptions(r)}))},t.prototype.renderEnvelopes=function(e,n){var r=this,o=new Map;e.forEach((function(e){e.context=n;var i=r.create(e.handler);void 0!==i&&(t.isQueueable(i)?(o.get(e.handler)||i.resetQueue(),i.addEnvelope(e),o.set(e.handler,i)):i.render(e))})),o.forEach((function(t){t.renderQueue()}))},t.prototype.create=function(t){return 0!==t.indexOf("template.")||this.factories.has(t)||this.addFactory(t,new u),this.factories.get(t)},t.prototype.addFactory=function(t,e){this.factories.set(t,e)},t.isQueueable=function(t){return"function"==typeof t.addEnvelope&&"function"==typeof t.renderQueue},t}();return l.getInstance().addFactory("template",new u),l}));