{"version":3,"file":"ngx-notifier.mjs","sources":["../../../projects/ngx-notifier/src/lib/others/notification-helper.ts","../../../projects/ngx-notifier/src/lib/services/ngx-notifier.service.ts","../../../projects/ngx-notifier/src/lib/ngx-notifier.component.ts","../../../projects/ngx-notifier/src/lib/ngx-notifier.component.html","../../../projects/ngx-notifier/src/public-api.ts","../../../projects/ngx-notifier/src/ngx-notifier.ts"],"sourcesContent":["/** Notification Class */\nexport class Notification {\n  /** unique id for each notification */\n  id: string;\n  /** message to be shown */\n  message: string;\n  /** bootstrap background colors */\n  style: string;\n  /** timeout for notification */\n  duration: number | undefined;\n\n  /**\n   * Constructor For Notification\n   *\n   * @param message message to be shown\n   * @param style bootstrap background colors\n   * @param duration timeout for notification\n   */\n  constructor(message: string, style?: string, duration?: number) {\n    this.id = `_${Math.random().toString(36).substring(2, 11)}`; // generate a random number\n    this.message = message;\n    this.style = style || 'info';\n    this.duration = duration;\n  }\n}\n\n/** INotification interface */\nexport interface INotification {\n  /** unique id for each notification */\n  id: string;\n  /** message to be shown */\n  message: string;\n  /** bootstrap background colors */\n  style?: string;\n  /** timeout for notification */\n  duration?: number;\n}\n","import { Injectable } from '@angular/core';\nimport { Subject } from 'rxjs';\n\nimport { Notification } from '../others/notification-helper';\n\n/** Notification Service, recieves notifications from user and interacts with components */\n@Injectable({\n  providedIn: 'root',\n})\nexport class NgxNotifierService {\n  /** notification which can be subscribed on new messages */\n  notification: Subject<Notification> = new Subject<Notification>();\n  /** clear all toast notifications */\n  clearToasts: Subject<void> = new Subject();\n  /** clear last toast notification */\n  clearLastToast: Subject<void> = new Subject();\n\n  /** pushes a new notification */\n  createToast(message: string, style?: string, duration?: number): void {\n    this.notification.next(new Notification(message, style, duration));\n  }\n\n  /** clear all toast notifications */\n  clear(): void {\n    this.clearToasts.next();\n  }\n\n  /** clear last toast notification */\n  clearLast(): void {\n    this.clearLastToast.next();\n  }\n}\n","import { Component, Input, OnDestroy, SecurityContext } from '@angular/core';\nimport { DomSanitizer } from '@angular/platform-browser';\nimport { trigger, style, transition, animate, state } from '@angular/animations';\nimport { Subject } from 'rxjs';\nimport { takeUntil } from 'rxjs/operators';\n\nimport { INotification } from './others/notification-helper';\n\nimport { NgxNotifierService } from './services/ngx-notifier.service';\nimport { CommonModule } from '@angular/common';\n\n/**\n * Notifier compoent, which holds all the notifications can be accessed via `ngx-notifier` selector\n */\n@Component({\n  selector: 'ngx-notifier',\n  standalone: true,\n  imports: [CommonModule],\n  templateUrl: './ngx-notifier.component.html',\n  styleUrls: ['./ngx-notifier.component.scss'],\n  animations: [\n    trigger('animateToasts', [\n      state('void', style({ opacity: 0 })),\n      transition(':enter, :leave', [ // void <=> *\n        animate('0.3s ease'),\n      ]),\n    ]),\n  ],\n})\n\nexport class NgxNotifierComponent implements OnDestroy {\n  private componentDestroyed$: Subject<boolean> = new Subject();\n\n  /** whether to allow duplicate messages or not */\n  @Input() allowDuplicates = true;\n  /** allow HTML in notification */\n  @Input() allowHTML = false;\n  /** custom class to be attached */\n  @Input() className = '';\n  /** default duration for dismissing notifications (60s/1minute) */\n  @Input() duration = 60000;\n  /** weather to enable or disable animations */\n  @Input() disableAnimations = false;\n  /** click to dismiss a notification */\n  @Input() dismissOnClick = false;\n  /** whether to insert on top or at bottom */\n  @Input() insertOnTop = true;\n  /** Maximum number of notifications to keep */\n  @Input() max = 5;\n\n  /** array of notifications */\n  notifications: INotification[] = [];\n\n  /** id of last inserted message */\n  private lastInsertedNotificationId!: string;\n\n  /**\n   * NgxNotifierComponent Constructor\n   *\n   * @param ngxNotifierService subscribe to get values form notifier service\n   */\n  constructor(private ngxNotifierService: NgxNotifierService, private domSanitizer: DomSanitizer) {\n    this.ngxNotifierService.notification.pipe(\n      takeUntil(this.componentDestroyed$),\n    ).subscribe((notification: INotification) => { this.updateNotifications(notification); });\n\n    this.ngxNotifierService.clearToasts.pipe(\n      takeUntil(this.componentDestroyed$),\n    ).subscribe(() => { this.notifications = []; });\n\n    this.ngxNotifierService.clearLastToast.pipe(\n      takeUntil(this.componentDestroyed$),\n    ).subscribe(() => { this.clearLastToast(); });\n  }\n\n  /**\n   * updates notification into the array i.e., Which is the display\n   *\n   * @param notification notification element\n   */\n  private updateNotifications(notification: INotification): void {\n    // checks whether the message is alrady present in notifications\n    const index = this.notifications.map((e) => e.message).indexOf(notification.message);\n\n    if (!this.allowDuplicates) {\n      if (index !== -1) {\n        return;\n      }\n    }\n\n    // save the last inserted Id\n    this.lastInsertedNotificationId = notification.id;\n\n    // sanitize html if enableHTML is set to true\n    let sanitizedMessage: string | null = null;\n    if (notification.message && this.allowHTML) {\n      sanitizedMessage = this.domSanitizer.sanitize(SecurityContext.HTML, notification.message);\n    }\n    // set sanitized output to notification message\n    notification.message = sanitizedMessage || notification.message;\n\n    // insert notification in the first position of the array\n    if (this.insertOnTop) {\n      this.notifications.unshift(notification);\n    } else {\n      this.notifications.push(notification);\n    }\n\n    /**\n     * remove the last inserted element if max has\n     * pop or shift based on `insertOnTop`\n     */\n    if (this.notifications.length > this.max) {\n      if (this.insertOnTop) {\n        this.notifications.pop();\n      } else {\n        this.notifications.shift();\n      }\n    }\n\n    // clear notification in given time\n    setTimeout(() => {\n      this.notifications.splice(index, 1);\n    }, notification.duration || this.duration);\n  }\n\n  /**\n   * remove the element from the array based on index\n   *\n   * @param index position of the element\n   */\n  removeNotification(index: number): void {\n    if (index !== undefined || index !== null) {\n      this.notifications.splice(index, 1);\n    }\n  }\n\n  /**\n   * click event when toast is cleared\n   *\n   * @param index position of the element\n   */\n  onToastClick(index: number): void {\n    if (this.dismissOnClick) {\n      this.removeNotification(index);\n    }\n  }\n\n  // dummy keyup handler\n  onKeyUp():void {\n    // do nothing\n  }\n\n  /** clear last inserted toast notification */\n  private clearLastToast(): void {\n    const index = this.notifications.map((e) => e.id).indexOf(this.lastInsertedNotificationId);\n\n    if (this.notifications.length !== 0 && index !== -1) {\n      this.notifications.splice(index, 1);\n    }\n  }\n\n  /** stop subscription when component is destroyed */\n  ngOnDestroy(): void {\n    this.componentDestroyed$.next(true);\n    this.componentDestroyed$.complete();\n  }\n}\n","<div\n  class=\"ngx-notifier\"\n  *ngIf=\"notifications?.length !== 0\"\n  [ngClass]=\"className\"\n  [@animateToasts]\n  [@.disabled]=\"disableAnimations\"\n>\n  <div [ngClass]=\"{ pointer: dismissOnClick }\">\n    <div\n      class=\"ngx-n-notification alert\"\n      role=\"alert\"\n      *ngFor=\"let notification of notifications; let i = index\"\n      [ngClass]=\"'alert-' + notification.style\"\n      (click)=\"onToastClick(i)\"\n      (keyup)=\"onKeyUp()\"\n      [@animateToasts]\n    >\n      <button type=\"button\" class=\"pointer close\" aria-label=\"Close\" (click)=\"removeNotification(i)\">\n        <svg\n          xmlns=\"http://www.w3.org/2000/svg\"\n          width=\"12\"\n          height=\"12\"\n          fill=\"currentColor\"\n          viewBox=\"0 0 16 16\"\n          aria-hidden=\"true\"\n        >\n          <path\n            d=\"M1.293 1.293a1 1 0 0 1 1.414 0L8 6.586l5.293-5.293a1 1 0 1 1 1.414 1.414L9.414 8l5.293 5.293a1 1 0 0 1-1.414 1.414L8 9.414l-5.293 5.293a1 1 0 0 1-1.414-1.414L6.586 8 1.293 2.707a1 1 0 0 1 0-1.414z\"\n          />\n        </svg>\n      </button>\n      <p *ngIf=\"allowHTML\" [innerHTML]=\"notification.message\"></p>\n      <p *ngIf=\"!allowHTML\">{{ notification.message }}</p>\n    </div>\n  </div>\n</div>\n","/*\n * Public API Surface of ngx-notifier\n */\n\nexport * from './lib/services/ngx-notifier.service';\nexport * from './lib/ngx-notifier.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.NgxNotifierService"],"mappings":";;;;;;;;;AAAA;MACa,YAAY,CAAA;AAUvB;;;;;;AAMG;AACH,IAAA,WAAA,CAAY,OAAe,EAAE,KAAc,EAAE,QAAiB,EAAA;QAC5D,IAAI,CAAC,EAAE,GAAG,CAAA,CAAA,EAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,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