mirror of
https://github.com/php-flasher/php-flasher.git
synced 2026-03-31 15:07:47 +01:00
2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i(require("@flasher/flasher")):"function"==typeof define&&define.amd?define(["@flasher/flasher"],i):(t="undefined"!=typeof globalThis?globalThis:t||self).notyf=i(t.flasher)}(this,(function(t){"use strict";class i{success(t,i,e){this.flash("success",t,i,e)}error(t,i,e){this.flash("error",t,i,e)}info(t,i,e){this.flash("info",t,i,e)}warning(t,i,e){this.flash("warning",t,i,e)}flash(t,i,e,n){if("object"==typeof t?(t=(n=t).type,i=n.message,e=n.title):"object"==typeof i?(i=(n=i).message,e=n.title):"object"==typeof e&&(e=(n=e).title),void 0===i)throw new Error("message option is required");const o={type:t,message:i,title:e||t,options:n||{},metadata:{plugin:""}};this.renderOptions(n||{}),this.renderEnvelopes([o])}}var e,n=function(){return n=Object.assign||function(t){for(var i,e=1,n=arguments.length;e<n;e++)for(var o in i=arguments[e])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t},n.apply(this,arguments)},o=function(){function t(t){this.options=t,this.listeners={}}return t.prototype.on=function(t,i){var e=this.listeners[t]||[];this.listeners[t]=e.concat([i])},t.prototype.triggerEvent=function(t,i){var e=this;(this.listeners[t]||[]).forEach((function(t){return t({target:e,event:i})}))},t}();!function(t){t[t.Add=0]="Add",t[t.Remove=1]="Remove"}(e||(e={}));var s,a=function(){function t(){this.notifications=[]}return t.prototype.push=function(t){this.notifications.push(t),this.updateFn(t,e.Add,this.notifications)},t.prototype.splice=function(t,i){var n=this.notifications.splice(t,i)[0];return this.updateFn(n,e.Remove,this.notifications),n},t.prototype.indexOf=function(t){return this.notifications.indexOf(t)},t.prototype.onUpdate=function(t){this.updateFn=t},t}();!function(t){t.Dismiss="dismiss",t.Click="click"}(s||(s={}));var r={types:[{type:"success",className:"notyf__toast--success",backgroundColor:"#3dc763",icon:{className:"notyf__icon--success",tagName:"i"}},{type:"error",className:"notyf__toast--error",backgroundColor:"#ed3d3d",icon:{className:"notyf__icon--error",tagName:"i"}}],duration:2e3,ripple:!0,position:{x:"right",y:"bottom"},dismissible:!1},c=function(){function t(){this.notifications=[],this.events={},this.X_POSITION_FLEX_MAP={left:"flex-start",center:"center",right:"flex-end"},this.Y_POSITION_FLEX_MAP={top:"flex-start",center:"center",bottom:"flex-end"};var t=document.createDocumentFragment(),i=this._createHTMLElement({tagName:"div",className:"notyf"});t.appendChild(i),document.body.appendChild(t),this.container=i,this.animationEndEventName=this._getAnimationEndEventName(),this._createA11yContainer()}return t.prototype.on=function(t,i){var e;this.events=n(n({},this.events),((e={})[t]=i,e))},t.prototype.update=function(t,i){i===e.Add?this.addNotification(t):i===e.Remove&&this.removeNotification(t)},t.prototype.removeNotification=function(t){var i,e,n=this,o=this._popRenderedNotification(t);o&&((i=o.node).classList.add("notyf__toast--disappear"),i.addEventListener(this.animationEndEventName,e=function(t){t.target===i&&(i.removeEventListener(n.animationEndEventName,e),n.container.removeChild(i))}))},t.prototype.addNotification=function(t){var i=this._renderNotification(t);this.notifications.push({notification:t,node:i}),this._announce(t.options.message||"Notification")},t.prototype._renderNotification=function(t){var i,e=this._buildNotificationCard(t),n=t.options.className;return n&&(i=e.classList).add.apply(i,n.split(" ")),this.container.appendChild(e),e},t.prototype._popRenderedNotification=function(t){for(var i=-1,e=0;e<this.notifications.length&&i<0;e++)this.notifications[e].notification===t&&(i=e);if(-1!==i)return this.notifications.splice(i,1)[0]},t.prototype.getXPosition=function(t){var i;return(null===(i=null==t?void 0:t.position)||void 0===i?void 0:i.x)||"right"},t.prototype.getYPosition=function(t){var i;return(null===(i=null==t?void 0:t.position)||void 0===i?void 0:i.y)||"bottom"},t.prototype.adjustContainerAlignment=function(t){var i=this.X_POSITION_FLEX_MAP[this.getXPosition(t)],e=this.Y_POSITION_FLEX_MAP[this.getYPosition(t)],n=this.container.style;n.setProperty("justify-content",e),n.setProperty("align-items",i)},t.prototype._buildNotificationCard=function(t){var i=this,e=t.options,n=e.icon;this.adjustContainerAlignment(e);var o=this._createHTMLElement({tagName:"div",className:"notyf__toast"}),a=this._createHTMLElement({tagName:"div",className:"notyf__ripple"}),r=this._createHTMLElement({tagName:"div",className:"notyf__wrapper"}),c=this._createHTMLElement({tagName:"div",className:"notyf__message"});c.innerHTML=e.message||"";var p=e.background||e.backgroundColor;if(n){var f=this._createHTMLElement({tagName:"div",className:"notyf__icon"});if(("string"==typeof n||n instanceof String)&&(f.innerHTML=new String(n).valueOf()),"object"==typeof n){var l=n.tagName,d=void 0===l?"i":l,u=n.className,h=n.text,m=n.color,y=void 0===m?p:m,v=this._createHTMLElement({tagName:d,className:u,text:h});y&&(v.style.color=y),f.appendChild(v)}r.appendChild(f)}if(r.appendChild(c),o.appendChild(r),p&&(e.ripple?(a.style.background=p,o.appendChild(a)):o.style.background=p),e.dismissible){var g=this._createHTMLElement({tagName:"div",className:"notyf__dismiss"}),_=this._createHTMLElement({tagName:"button",className:"notyf__dismiss-btn"});g.appendChild(_),r.appendChild(g),o.classList.add("notyf__toast--dismissible"),_.addEventListener("click",(function(e){var n,o;null===(o=(n=i.events)[s.Dismiss])||void 0===o||o.call(n,{target:t,event:e}),e.stopPropagation()}))}o.addEventListener("click",(function(e){var n,o;return null===(o=(n=i.events)[s.Click])||void 0===o?void 0:o.call(n,{target:t,event:e})}));var N="top"===this.getYPosition(e)?"upper":"lower";return o.classList.add("notyf__toast--"+N),o},t.prototype._createHTMLElement=function(t){var i=t.tagName,e=t.className,n=t.text,o=document.createElement(i);return e&&(o.className=e),o.textContent=n||null,o},t.prototype._createA11yContainer=function(){var t=this._createHTMLElement({tagName:"div",className:"notyf-announcer"});t.setAttribute("aria-atomic","true"),t.setAttribute("aria-live","polite"),t.style.border="0",t.style.clip="rect(0 0 0 0)",t.style.height="1px",t.style.margin="-1px",t.style.overflow="hidden",t.style.padding="0",t.style.position="absolute",t.style.width="1px",t.style.outline="0",document.body.appendChild(t),this.a11yContainer=t},t.prototype._announce=function(t){var i=this;this.a11yContainer.textContent="",setTimeout((function(){i.a11yContainer.textContent=t}),100)},t.prototype._getAnimationEndEventName=function(){var t,i=document.createElement("_fake"),e={MozTransition:"animationend",OTransition:"oAnimationEnd",WebkitTransition:"webkitAnimationEnd",transition:"animationend"};for(t in e)if(void 0!==i.style[t])return e[t];return"animationend"},t}(),p=function(){function t(t){var i=this;this.dismiss=this._removeNotification,this.notifications=new a,this.view=new c;var e=this.registerTypes(t);this.options=n(n({},r),t),this.options.types=e,this.notifications.onUpdate((function(t,e){return i.view.update(t,e)})),this.view.on(s.Dismiss,(function(t){var e=t.target,n=t.event;i._removeNotification(e),e.triggerEvent(s.Dismiss,n)})),this.view.on(s.Click,(function(t){var i=t.target,e=t.event;return i.triggerEvent(s.Click,e)}))}return t.prototype.error=function(t){var i=this.normalizeOptions("error",t);return this.open(i)},t.prototype.success=function(t){var i=this.normalizeOptions("success",t);return this.open(i)},t.prototype.open=function(t){var i=this.options.types.find((function(i){return i.type===t.type}))||{},e=n(n({},i),t);this.assignProps(["ripple","position","dismissible"],e);var s=new o(e);return this._pushNotification(s),s},t.prototype.dismissAll=function(){for(;this.notifications.splice(0,1););},t.prototype.assignProps=function(t,i){var e=this;t.forEach((function(t){i[t]=null==i[t]?e.options[t]:i[t]}))},t.prototype._pushNotification=function(t){var i=this;this.notifications.push(t);var e=void 0!==t.options.duration?t.options.duration:this.options.duration;e&&setTimeout((function(){return i._removeNotification(t)}),e)},t.prototype._removeNotification=function(t){var i=this.notifications.indexOf(t);-1!==i&&this.notifications.splice(i,1)},t.prototype.normalizeOptions=function(t,i){var e={type:t};return"string"==typeof i?e.message=i:"object"==typeof i&&(e=n(n({},e),i)),e},t.prototype.registerTypes=function(t){var i=(t&&t.types||[]).slice();return r.types.map((function(t){var e=-1;i.forEach((function(i,n){i.type===t.type&&(e=n)}));var o=-1!==e?i.splice(e,1)[0]:{};return n(n({},t),o)})).concat(i)},t}();const f=new class extends i{renderEnvelopes(t){t.forEach((t=>{var i;const e=Object.assign(Object.assign({},t),t.options);null===(i=this.notyf)||void 0===i||i.open(e)})),this.notyf.view.container.dataset.turboTemporary="",this.notyf.view.a11yContainer.dataset.turboTemporary=""}renderOptions(t){const i=Object.assign({duration:t.duration||5e3},t);i.types=i.types||[],i.types.push({type:"info",className:"notyf__toast--info",background:"#5784E5",icon:{className:"notyf__icon--info",tagName:"i"}}),i.types.push({type:"warning",className:"notyf__toast--warning",background:"#E3A008",icon:{className:"notyf__icon--warning",tagName:"i"}}),this.notyf=this.notyf||new p(i)}};return t.addPlugin("notyf",f),f}));
|