You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
8.8 KiB

10 months ago
  1. var __assign=function(){__assign=Object.assign||function __assign(t){for(var i,e=1,n=arguments.length;e<n;e++){i=arguments[e];for(var o in i)Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o])}return t};return __assign.apply(this,arguments)};var t=function(){function NotyfNotification(t){this.options=t;this.listeners={}}NotyfNotification.prototype.on=function(t,i){var e=this.listeners[t]||[];this.listeners[t]=e.concat([i])};NotyfNotification.prototype.triggerEvent=function(t,i){var e=this;var n=this.listeners[t]||[];n.forEach((function(t){return t({target:e,event:i})}))};return NotyfNotification}();var i;(function(t){t[t.Add=0]="Add";t[t.Remove=1]="Remove"})(i||(i={}));var e=function(){function NotyfArray(){this.notifications=[]}NotyfArray.prototype.push=function(t){this.notifications.push(t);this.updateFn(t,i.Add,this.notifications)};NotyfArray.prototype.splice=function(t,e){var n=this.notifications.splice(t,e)[0];this.updateFn(n,i.Remove,this.notifications);return n};NotyfArray.prototype.indexOf=function(t){return this.notifications.indexOf(t)};NotyfArray.prototype.onUpdate=function(t){this.updateFn=t};return NotyfArray}();var n;(function(t){t.Dismiss="dismiss";t.Click="click"})(n||(n={}));var o={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:true,position:{x:"right",y:"bottom"},dismissible:false};var a=function(){function NotyfView(){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();var i=this._createHTMLElement({tagName:"div",className:"notyf"});t.appendChild(i);document.body.appendChild(t);this.container=i;this.animationEndEventName=this._getAnimationEndEventName();this._createA11yContainer()}NotyfView.prototype.on=function(t,i){var e;this.events=__assign(__assign({},this.events),(e={},e[t]=i,e))};NotyfView.prototype.update=function(t,e){e===i.Add?this.addNotification(t):e===i.Remove&&this.removeNotification(t)};NotyfView.prototype.removeNotification=function(t){var i=this;var e=this._popRenderedNotification(t);var n;if(e){n=e.node;n.classList.add("notyf__toast--disappear");var o;n.addEventListener(this.animationEndEventName,o=function(t){if(t.target===n){n.removeEventListener(i.animationEndEventName,o);i.container.removeChild(n)}})}};NotyfView.prototype.addNotification=function(t){var i=this._renderNotification(t);this.notifications.push({notification:t,node:i});this._announce(t.options.message||"Notification")};NotyfView.prototype._renderNotification=function(t){var i;var e=this._buildNotificationCard(t);var n=t.options.className;n&&(i=e.classList).add.apply(i,n.split(" "));this.container.appendChild(e);return e};NotyfView.prototype._popRenderedNotification=function(t){var i=-1;for(var 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]};NotyfView.prototype.getXPosition=function(t){var i;return(null===(i=null===t||void 0===t?void 0:t.position)||void 0===i?void 0:i.x)||"right"};NotyfView.prototype.getYPosition=function(t){var i;return(null===(i=null===t||void 0===t?void 0:t.position)||void 0===i?void 0:i.y)||"bottom"};NotyfView.prototype.adjustContainerAlignment=function(t){var i=this.X_POSITION_FLEX_MAP[this.getXPosition(t)];var e=this.Y_POSITION_FLEX_MAP[this.getYPosition(t)];var n=this.container.style;n.setProperty("justify-content",e);n.setProperty("align-items",i)};NotyfView.prototype._buildNotificationCard=function(t){var i=this;var e=t.options;var o=e.icon;this.adjustContainerAlignment(e);var a=this._createHTMLElement({tagName:"div",className:"notyf__toast"});var s=this._createHTMLElement({tagName:"div",className:"notyf__ripple"});var r=this._createHTMLElement({tagName:"div",className:"notyf__wrapper"});var c=th
  2. /**
  3. * Assigns properties to a config object based on two rules:
  4. * 1. If the config object already sets that prop, leave it as so
  5. * 2. Otherwise, use the default prop from the global options
  6. *
  7. * It's intended to build the final config object to open a notification. e.g. if
  8. * 'dismissible' is not set, then use the value from the global config.
  9. *
  10. * @param props - properties to be assigned to the config object
  11. * @param config - object whose properties need to be set
  12. */Notyf.prototype.assignProps=function(t,i){var e=this;t.forEach((function(t){i[t]=null==i[t]?e.options[t]:i[t]}))};Notyf.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)};Notyf.prototype._removeNotification=function(t){var i=this.notifications.indexOf(t);-1!==i&&this.notifications.splice(i,1)};Notyf.prototype.normalizeOptions=function(t,i){var e={type:t};"string"===typeof i?e.message=i:"object"===typeof i&&(e=__assign(__assign({},e),i));return e};Notyf.prototype.registerTypes=function(t){var i=(t&&t.types||[]).slice();var e=o.types.map((function(t){var e=-1;i.forEach((function(i,n){i.type===t.type&&(e=n)}));var n=-1!==e?i.splice(e,1)[0]:{};return __assign(__assign({},t),n)}));return e.concat(i)};return Notyf}();export{o as DEFAULT_OPTIONS,s as Notyf,e as NotyfArray,i as NotyfArrayEvent,n as NotyfEvent,t as NotyfNotification,a as NotyfView};