{"version":3,"file":"vi5hnuu-ngx-noti.mjs","sources":["../../../projects/ngx-noti/src/lib/utils/util-functions.ts","../../../projects/ngx-noti/src/lib/services/ngx-noti/ngx-noti.service.ts","../../../projects/ngx-noti/src/lib/models/notification.interface.ts","../../../projects/ngx-noti/src/lib/utils/anims.ts","../../../projects/ngx-noti/src/lib/components/notifications-panel/notifications-panel.component.ts","../../../projects/ngx-noti/src/lib/components/notifications-panel/notifications-panel.component.html","../../../projects/ngx-noti/src/public-api.ts","../../../projects/ngx-noti/src/vi5hnuu-ngx-noti.ts"],"sourcesContent":["export const generateId=({length=32,prefix=''}:{length?:number, prefix?:string})=> {\r\n  const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+[]{}|;:,.<>?/~`';\r\n  const charactersLength = characters.length;\r\n\r\n  if (length <= prefix.length) {\r\n    throw new Error('Length must be greater than the prefix length.');\r\n  }\r\n\r\n  const idLength = length - prefix.length;\r\n  let result = '';\r\n  for (let i = 0; i < idLength; i++) {\r\n    const randomIndex = Math.floor(Math.random() * charactersLength);\r\n    result += characters[randomIndex];\r\n  }\r\n\r\n  return prefix + result;\r\n}\r\n","import {Injectable, TemplateRef} from \"@angular/core\";\r\nimport {Notification, NotificationType} from '../../models/notification.interface';\r\nimport {generateId} from '../../utils/util-functions';\r\n\r\n@Injectable()\r\nexport class NgxNotiService {\r\n  private notificationsInfo:{notifications:Notification[],intervals:{[key:string]:any}}={notifications:[],intervals:{}};\r\n\r\n  constructor() {}\r\n\r\n  public get _notifications():Readonly<Notification[]>{//prop to be used only internally\r\n    return this.notificationsInfo.notifications;\r\n  }\r\n\r\n  addNotification(\r\n    {title,type,description,visibilityTimeMs,iconSrc,templateRef}:{\r\n      title: string,\r\n      type:NotificationType,\r\n      description?:string,\r\n      visibilityTimeMs?:number,\r\n      iconSrc?:string,\r\n      templateRef?:TemplateRef<any>,\r\n    }\r\n  ){\r\n    const notification={\r\n      id:generateId({prefix:'NOT'}),\r\n      title,\r\n      type,\r\n      description,\r\n      visibilityTimeMs:visibilityTimeMs!==undefined ? Math.max(visibilityTimeMs,1000):visibilityTimeMs,\r\n      visibilityTimeMsLeft:visibilityTimeMs!==undefined ? Math.max(visibilityTimeMs,1000):visibilityTimeMs,\r\n      iconSrc,\r\n      templateRef\r\n    } as Notification;\r\n    this.notificationsInfo.notifications.push(notification);\r\n    if(notification.visibilityTimeMs!==undefined) this.notificationsInfo.intervals[notification.id]=setInterval(()=>{\r\n      notification.visibilityTimeMsLeft!-=100;\r\n      if(notification.visibilityTimeMsLeft!<=0) this.clearNotification(notification.id);\r\n    },100);\r\n  }\r\n\r\n  clearNotification(notificationId:string){\r\n    clearInterval(this.notificationsInfo.intervals[notificationId]);\r\n    delete this.notificationsInfo.intervals[notificationId];\r\n    this.notificationsInfo.notifications=this.notificationsInfo.notifications.filter(n=>n.id!==notificationId);\r\n  }\r\n\r\n  clearAllNotifications(){\r\n    this.notificationsInfo.notifications=[];\r\n    Object.values(this.notificationsInfo.intervals).forEach(interval=>clearInterval(interval));\r\n  }\r\n}\r\n","import {TemplateRef} from '@angular/core';\r\n\r\nexport interface Notification{\r\n  id:string,\r\n  title: string,\r\n  type:NotificationType,\r\n  description?:string,\r\n  visibilityTimeMs?:number,\r\n  visibilityTimeMsLeft?:number,\r\n  iconSrc?:string,\r\n  templateRef?:TemplateRef<any>,\r\n}\r\n\r\nexport enum NotificationType {\r\n  ERROR,\r\n  SUCCESS,\r\n  WARNING,\r\n  INFO\r\n}\r\n\r\nexport enum NotificationPosition {\r\n  TOP_LEFT,\r\n  TOP_RIGHT,\r\n  BOTTOM_RIGHT,\r\n  BOTTOM_LEFT,\r\n  TOP_CENTER,\r\n  BOTTOM_CENTER\r\n}\r\n","import {animate, style, transition, trigger} from '@angular/animations';\r\n\r\nexport const slideInOut = trigger('slideInOut', [\r\n  transition(':enter', [\r\n    style({ transform: 'translateX(-100%)', opacity: 0 }),\r\n    animate('{{enterDurationMs}}ms ease-out', style({ transform: 'translateX(0)', opacity: 1 }))\r\n  ],{params:{enterDurationMs:300}}),\r\n  transition(':leave', [\r\n    animate('{{exitDurationMs}}ms ease-in', style({ transform: 'translateX(-100%)', opacity: 0 }))\r\n  ],{params:{exitDurationMs:300}}),\r\n]);\r\n","import {\r\n  Component,\r\n  EventEmitter,\r\n  Input,\r\n  Output,\r\n  ViewEncapsulation\r\n} from '@angular/core';\r\nimport {NgClass, NgForOf, NgIf, NgTemplateOutlet} from \"@angular/common\";\r\nimport {NotificationPosition, NotificationType} from '../../models/notification.interface';\r\nimport {slideInOut} from '../../utils/anims';\r\nimport {NgxNotiService} from '../../services/ngx-noti/ngx-noti.service';\r\n\r\n@Component({\r\n  selector: 'lib-notifications-panel',\r\n  imports: [\r\n    NgForOf,\r\n    NgClass,\r\n    NgIf,\r\n    NgTemplateOutlet\r\n  ],\r\n  templateUrl: './notifications-panel.component.html',\r\n  styleUrl: './notifications-panel.component.scss',\r\n  animations:[slideInOut],\r\n  encapsulation: ViewEncapsulation.ShadowDom\r\n})\r\nexport class NotificationsPanelComponent{\r\n  @Input() notificationsPosition:NotificationPosition=NotificationPosition.BOTTOM_RIGHT;\r\n  @Output() dismiss=new EventEmitter<string>();\r\n  @Output() dismissAll=new EventEmitter<void>();\r\n\r\n  constructor(private ngxNotiService:NgxNotiService) {\r\n  }\r\n\r\n  get notifications(){\r\n    return this.ngxNotiService._notifications;\r\n  }\r\n\r\n  protected readonly NotificationType = NotificationType;\r\n  protected readonly NotificationPosition = NotificationPosition;\r\n\r\n  get isTopLevelNotification(){\r\n    return [NotificationPosition.TOP_LEFT, NotificationPosition.TOP_CENTER, NotificationPosition.TOP_RIGHT].includes(this.notificationsPosition);\r\n  }\r\n}\r\n","<div\r\n  [ngClass]=\"{\r\n    'top-left':notificationsPosition===NotificationPosition.TOP_LEFT,\r\n    'top-center':notificationsPosition===NotificationPosition.TOP_CENTER,\r\n    'top-right':notificationsPosition===NotificationPosition.TOP_RIGHT,\r\n    'bottom-right':notificationsPosition===NotificationPosition.BOTTOM_RIGHT,\r\n    'bottom-center':notificationsPosition===NotificationPosition.BOTTOM_CENTER,\r\n    'bottom-left':notificationsPosition===NotificationPosition.BOTTOM_LEFT,\r\n  }\"\r\n  class=\"fixed hide-scrollbar transition-all max-w-[95%] sm:max-w-[25rem] z-50 p-4 overflow-auto max-h-[90dvh]\">\r\n  <div @slideInOut class=\"relative rounded-md overflow-hidden h-auto mb-2 hover:!z-[99999999] notification-shadow group hover:scale-[1.03] transition-all\"\r\n       [style.margin-top]=\"-15+'px'\"\r\n       [style.z-index]=\"(isTopLevelNotification ? 1 : -1)*index\"\r\n       [ngClass]=\"{'warn':notification.type===NotificationType.WARNING,\r\n       'error':notification.type===NotificationType.ERROR,\r\n       'success':notification.type===NotificationType.SUCCESS,\r\n       'info':notification.type===NotificationType.INFO}\"\r\n       *ngFor=\"let notification of (isTopLevelNotification ? notifications : notifications.slice().reverse());let index=index\">\r\n    <div  class=\"flex gap-2 items-start px-4 py-2\">\r\n      <div class=\"max-w-8 max-h-8 my-auto flex items-center justify-center aspect-square rounded-full overflow-hidden\">\r\n        <img alt=\"notification-icon\" *ngIf=\"notification.iconSrc\" [src]=\"notification.iconSrc\" class=\"size-6\"/>\r\n        <ng-container *ngIf=\"!notification.iconSrc\">\r\n          <ng-container *ngIf=\"notification.templateRef;else defaultIcon\">\r\n            <ng-container *ngTemplateOutlet=\"notification.templateRef\"></ng-container>\r\n          </ng-container>\r\n          <ng-template #defaultIcon>\r\n            <span class=\"material-symbols-outlined\">{{(notification.type===NotificationType.ERROR ? 'error':(notification.type===NotificationType.WARNING ? 'warning':(notification.type===NotificationType.SUCCESS ? 'celebration':'lightbulb')))}}</span>\r\n          </ng-template>\r\n        </ng-container>\r\n      </div>\r\n      <div class=\"flex flex-col mr-4\">\r\n        <p class=\"font-semibold\">{{notification.title}}</p>\r\n        <p class=\"text-sm text-wrap\">{{notification.description}}</p>\r\n      </div>\r\n      <div role=\"button\" (click)=\"dismiss.next(notification.id)\">\r\n        <span class=\"material-symbols-outlined scale-75 text-black hover:text-red-400 hover:scale-[0.9] hover:rotate-90 transition-all\">close</span>\r\n      </div>\r\n    </div>\r\n    <div class=\"progress h-1 w-full bg-primary transition-all\"\r\n         [style.width.%]=\"(notification?.visibilityTimeMsLeft && notification.visibilityTimeMs) ? (notification.visibilityTimeMsLeft!*100/notification.visibilityTimeMs!):0\"\r\n    ></div>\r\n  </div>\r\n</div>\r\n","/*\r\n * Public API Surface of ngx-noti\r\n */\r\n\r\nexport * from './lib/services/ngx-noti/ngx-noti.service';\r\nexport * from './lib/components/notifications-panel/notifications-panel.component';\r\nexport * from './lib/models/notification.interface';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.NgxNotiService"],"mappings":";;;;;AAAO,MAAM,UAAU,GAAC,CAAC,EAAC,MAAM,GAAC,EAAE,EAAC,MAAM,GAAC,EAAE,EAAkC,KAAG;IAChF,MAAM,UAAU,GAAG,6FAA6F;AAChH,IAAA,MAAM,gBAAgB,GAAG,UAAU,CAAC,MAAM;AAE1C,IAAA,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE;AAC3B,QAAA,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC;;AAGnE,IAAA,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM;IACvC,IAAI,MAAM,GAAG,EAAE;AACf,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,CAAC,EAAE,EAAE;AACjC,QAAA,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,gBAAgB,CAAC;AAChE,QAAA,MAAM,IAAI,UAAU,CAAC,WAAW,CAAC;;IAGnC,OAAO,MAAM,GAAG,MAAM;AACxB,CAAC;;MCXY,cAAc,CAAA;IACjB,iBAAiB,GAA6D,EAAC,aAAa,EAAC,EA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