@knighttower/toast
Version:
A dead simple toast library
1 lines • 10.4 kB
JavaScript
var t,e;t=this,e=()=>(()=>{"use strict";var t={51:t=>{t.exports=function(t){var e=document.createElement("style");return t.setAttributes(e,t.attributes),t.insert(e,t.options),e}},128:t=>{var e={};t.exports=function(t,n){var o=function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement){try{n=n.contentDocument.head}catch(t){n=null}}e[t]=n}return e[t]}(t);if(!o){throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.")}o.appendChild(n)}},591:t=>{var e=[];function n(t){for(var n=-1,o=0;o<e.length;o++){if(e[o].identifier===t){n=o;break}}return n}function o(t,o){for(var i={},s=[],a=0;a<t.length;a++){var c=t[a],l=o.base?c[0]+o.base:c[0],d=i[l]||0,u="".concat(l," ").concat(d);i[l]=d+1;var p=n(u),f={css:c[1],media:c[2],sourceMap:c[3],supports:c[4],layer:c[5]};if(-1!==p){e[p].references++,e[p].updater(f)}else{var h=r(f,o);o.byIndex=a,e.splice(a,0,{identifier:u,updater:h,references:1})}s.push(u)}return s}function r(t,e){var n=e.domAPI(e);return n.update(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap&&e.supports===t.supports&&e.layer===t.layer){return}n.update(t=e)}else{n.remove()}}}t.exports=function(t,r){var i=o(t=t||[],r=r||{});return function(t){t=t||[];for(var s=0;s<i.length;s++){var a=n(i[s]);e[a].references--}for(var c=o(t,r),l=0;l<i.length;l++){var d=n(i[l]);0===e[d].references&&(e[d].updater(),e.splice(d,1))}i=c}}},656:t=>{t.exports=function(t,e){if(e.styleSheet){e.styleSheet.cssText=t}else{for(;e.firstChild;){e.removeChild(e.firstChild)}e.appendChild(document.createTextNode(t))}}},666:(t,e,n)=>{n.d(e,{A:()=>i});var o=n(935),r=n.n(o)()((function(t){return t[1]}));r.push([t.id,'.x-toast__container{line-height:normal;max-width:600px;pointer-events:none;position:fixed;transition:all 1s ease-in-out;width:100%;z-index:999999}.x-toast__wrapper{padding:10px 20px;position:relative}.x-toast__container.--top-center{transform:translate(calc(50vw - 50%))}.x-toast__container.--top-left{left:0;top:0}.x-toast__container.--top-right{right:0;top:0}.x-toast__container.--bottom-left{bottom:0;left:0}.x-toast__container.--bottom-right{bottom:0;right:0}.x-toast__container.--bottom-center{bottom:0;transform:translate(calc(50vw - 50%))}.x-toast__container.--bottom-right .x-toast,.x-toast__container.--top-right .x-toast{margin-right:0!important;padding-right:30px}.x-toast{border:1px solid;border-left:6px solid transparent;border-radius:2px;box-shadow:0 0 9px rgba(0,0,0,.25);display:table;margin:.5rem auto;padding:16px;pointer-events:none;position:relative;text-wrap:normal;transform:translateZ(0);transition:all .32s ease-in-out;width:auto}.x-toast--info{background-color:#eaf2fa;border-color:#91c5f2;color:#31708f}.x-toast--success{background-color:#e9ffd9;border-color:#a6ca8a;color:#3c763d}.x-toast--warning{background-color:#fff8c4;border-color:#f2c779;color:#8a6d3b}.x-toast--error{background-color:#ffecec;border-color:#f5aca6;color:#a94442}.x-toast.close-on-click{cursor:pointer;padding-right:45px;pointer-events:auto}.x-toast.close-on-click:before{content:"\xd7";cursor:pointer;font-size:2rem;padding:7px;position:absolute;right:0;top:0}.x-toast__progress{background-color:#4a4c70;bottom:0;height:2px;left:3px;opacity:.4;position:absolute;transition:width 0s ease;width:0}.x-toast[class*="--hide"],.x-toast[class*="--init"]{opacity:0}.x-toast[class*="--show"]{opacity:1}.x-toast.slide-left-right--init{right:-100%}.x-toast.slide-left-right--show{right:0}.x-toast.slide-left-right--hide{right:-100%}.x-toast.slide-right-left--init{left:-100%}.x-toast.slide-right-left--show{left:0}.x-toast.slide-right-left--hide{left:-100%}.x-toast.slide-up-down--init{top:-100%}.x-toast.slide-up-down--show{top:0}.x-toast.slide-up-down--hide{top:-100%}.x-toast.slide-down-up--init{bottom:-100%}.x-toast.slide-down-up--show{bottom:0}.x-toast.slide-down-up--hide{bottom:-100%}',""]);const i=r},740:t=>{t.exports=function(t){if("undefined"==typeof document){return{update:function(){},remove:function(){}}}var e=t.insertStyleElement(t);return{update:function(n){!function(t,e,n){var o="";n.supports&&(o+="@supports (".concat(n.supports,") {")),n.media&&(o+="@media ".concat(n.media," {"));var r=void 0!==n.layer;r&&(o+="@layer".concat(n.layer.length>0?" ".concat(n.layer):""," {")),o+=n.css,r&&(o+="}"),n.media&&(o+="}"),n.supports&&(o+="}");var i=n.sourceMap;i&&"undefined"!=typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(i))))," */")),e.styleTagTransform(o,t,e.options)}(e,t,n)},remove:function(){!function(t){if(null===t.parentNode){return!1}t.parentNode.removeChild(t)}(e)}}}},855:(t,e,n)=>{t.exports=function(t){var e=n.nc;e&&t.setAttribute("nonce",e)}},935:t=>{t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=t(e);return e[2]?"@media ".concat(e[2]," {").concat(n,"}"):n})).join("")},e.i=function(t,n,o){"string"==typeof t&&(t=[[null,t,""]]);var r={};if(o){for(var i=0;i<this.length;i++){var s=this[i][0];null!=s&&(r[s]=!0)}}for(var a=0;a<t.length;a++){var c=[].concat(t[a]);o&&r[c[0]]||(n&&(c[2]?c[2]="".concat(n," and ").concat(c[2]):c[2]=n),e.push(c))}},e}}},e={};function n(o){var r=e[o];if(void 0!==r){return r.exports}var i=e[o]={id:o,exports:{}};return t[o](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var o in e){n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})}},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.nc=void 0;var o={};return(()=>{const t=t=>t&&"object"==typeof t&&t.constructor===Object,e=function(n){for(var o=arguments.length,r=new Array(o>1?o-1:0),i=1;i<o;i++){r[i-1]=arguments[i]}return r.reduce(((n,o)=>(t(o)?Object.entries(o).forEach((o=>{let[r,i]=o;n[r]=t(i)&&t(n[r])?e(n[r],i):i})):Object.assign(n,o),n)),{...n})};!function(t,n){const o="x-toast",r={classname:"x",transition:"slide-left-right",insertBefore:!0,duration:3e3,autoClose:!0,progressBar:!0,onShow:function(t){},onHide:function(t){},position:"top-right"},i={container:"{:class-name}__container",mainwrap:"{:class-name}__wrapper",toasts:{info:"{:class-name}--info",success:"{:class-name}--success",warning:"{:class-name}--warning",error:"{:class-name}--error"},animate:{init:"{:transition}--init",show:"{:transition}--show",hide:"{:transition}--hide"},progress:"{:class-name}__progress",position:"--{:position}"};function s(t){return n.createElement(t||"div")}function a(t){return t.parentElement||t.parentNode}function c(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),o=1;o<e;o++){n[o-1]=arguments[o]}return n.forEach((e=>{(function(t,e){return t.classList.contains(e)})(t,e)||t.classList.add(e)})),t}function l(t,e,n){let o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return t.addEventListener(e,n,o),t}function d(t,e,n){let o=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return t.removeEventListener(e,n,o),t}let u=null;function p(){if(u){return u}const t=document.createElement("div"),e={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(let n in e){if(n in t.style){u=e[n];break}}return u}function f(t,e){for(const n in t){if(!0===t.hasOwnProperty(n)){switch(typeof t[n]){case"object":f(t[n],e);break;case"string":for(const o in e){!0===e.hasOwnProperty(o)&&(t[n]=t[n].replace(o,e[o]))}}}}return t}const h=function(t,e,n,o,r){const i=()=>{const t=a(e);e.remove(),t.childNodes.length<1&&a(t).remove()},s=e=>{d(e.target,e.type,s,!1),i(),"function"==typeof r&&r(t)};setTimeout((()=>{const n=p();void 0!==n?l(e,n,s,!1):(i(),"function"==typeof r&&r(t)),c(e,o.hide)}),n)},m=function(t,e){return"string"==typeof e&&(t.classmap[e]=f({...i},{"{:class-name}":o,"{:transition}":e,"{:position}":t.settings.position})),e};t.$toast=t.$toast||new class{constructor(t){this.settings={},this.classmap={},this.config(t||r),this.transition(this.settings.transition)}config(t){return this.settings=e(r,this.settings,t||{}),this}transition(t){return this.settings.transition=m(this,t),this}toast(t,r,i){const u=this.classmap;let f=this.settings;"number"==typeof i?f.duration=i:f=e(this.settings,i||{}),!1===u.hasOwnProperty(f.transition)&&m(this,f.transition);const g=u[f.transition];let v=n.querySelector("."+g.container);const x=!!v;if(x){v=v.querySelector("."+g.mainwrap)}else{v=c(s("div"),g.container,g.container,g.position);const t=c(s("div"),g.mainwrap);v.appendChild(v=t)}const b=c(s("div"),o,f.classname,g.toasts[t],g.animate.init);return b.textContent=r,x||n.body.append(a(v)),function(t,e,n,o,r,i,s){const a=e=>{d(e.target,e.type,a,!1),"function"==typeof s&&s(t)};let u=n.childNodes;u=u[!0===i?0:u.length],n.insertBefore(e,u),setTimeout((()=>{const n=p();void 0!==n?l(e,n,a,!1):"function"==typeof s&&s(t),c(e,o.show)}),100)}(t,b,v,g.animate,f.duration,f.insertBefore,f.onShow),f.autoClose?h(t,b,f.duration,g.animate,f.onHide):function(t,e,n,o,r){c(e,r),l(e,"click",(function(r){r.stopPropagation(),h(t,e,0,n,o)}))}(t,b,g.animate,f.onHide,"close-on-click"),f.progressBar&&f.autoClose&&function(t,e,n,o){setTimeout((()=>{const r=c(s("div"),o.progress,o.progress+"--"+t);e.appendChild(r);let i=0,a=0;const l=setInterval((()=>{i++,a=Math.round(1500*i/n),a>100?clearInterval(l):r.style.width=a+"%"}),10)}),100)}(t,b,f.duration,g),this}info(t,e){this.toast("info",t,e)}success(t,e){this.toast("success",t,e)}warning(t,e){this.toast("warning",t,e)}error(t,e){this.toast("error",t,e)}}}("undefined"!=typeof window?window:{},"undefined"!=typeof document?document:{})})(),(()=>{n.r(o),n.d(o,{default:()=>g});var t=n(591),e=n.n(t),r=n(740),i=n.n(r),s=n(128),a=n.n(s),c=n(855),l=n.n(c),d=n(51),u=n.n(d),p=n(656),f=n.n(p),h=n(666),m={};m.styleTagTransform=f(),m.setAttributes=l(),m.insert=a().bind(null,"head"),m.domAPI=i(),m.insertStyleElement=u(),e()(h.A,m);const g=h.A&&h.A.locals?h.A.locals:void 0})(),o})(),"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("bundle",[],e):"object"==typeof exports?exports.bundle=e():t.bundle=e();