Icard/angular-clarity-master(work.../node_modules/ngx-toastr/esm2022/toastr/toast.component.mjs

273 lines
31 KiB
JavaScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Component, HostBinding, HostListener, } from '@angular/core';
import { NgIf } from '@angular/common';
import * as i0 from "@angular/core";
import * as i1 from "./toastr.service";
import * as i2 from "./toastr-config";
class Toast {
toastrService;
toastPackage;
ngZone;
message;
title;
options;
duplicatesCount;
originalTimeout;
/** width of progress bar */
width = -1;
/** a combination of toast type and options.toastClass */
toastClasses = '';
/** controls animation */
state;
/** hides component when waiting to be displayed */
get displayStyle() {
if (this.state.value === 'inactive') {
return 'none';
}
return;
}
timeout;
intervalId;
hideTime;
sub;
sub1;
sub2;
sub3;
constructor(toastrService, toastPackage, ngZone) {
this.toastrService = toastrService;
this.toastPackage = toastPackage;
this.ngZone = ngZone;
this.message = toastPackage.message;
this.title = toastPackage.title;
this.options = toastPackage.config;
this.originalTimeout = toastPackage.config.timeOut;
this.toastClasses = `${toastPackage.toastType} ${toastPackage.config.toastClass}`;
this.sub = toastPackage.toastRef.afterActivate().subscribe(() => {
this.activateToast();
});
this.sub1 = toastPackage.toastRef.manualClosed().subscribe(() => {
this.remove();
});
this.sub2 = toastPackage.toastRef.timeoutReset().subscribe(() => {
this.resetTimeout();
});
this.sub3 = toastPackage.toastRef.countDuplicate().subscribe(count => {
this.duplicatesCount = count;
});
this.state = {
value: 'inactive',
params: {
easeTime: this.toastPackage.config.easeTime,
easing: 'ease-in',
},
};
}
ngOnDestroy() {
this.sub.unsubscribe();
this.sub1.unsubscribe();
this.sub2.unsubscribe();
this.sub3.unsubscribe();
clearInterval(this.intervalId);
clearTimeout(this.timeout);
}
/**
* activates toast and sets timeout
*/
activateToast() {
this.state = { ...this.state, value: 'active' };
if (!(this.options.disableTimeOut === true || this.options.disableTimeOut === 'timeOut') &&
this.options.timeOut) {
this.outsideTimeout(() => this.remove(), this.options.timeOut);
this.hideTime = new Date().getTime() + this.options.timeOut;
if (this.options.progressBar) {
this.outsideInterval(() => this.updateProgress(), 10);
}
}
}
/**
* updates progress bar width
*/
updateProgress() {
if (this.width === 0 || this.width === 100 || !this.options.timeOut) {
return;
}
const now = new Date().getTime();
const remaining = this.hideTime - now;
this.width = (remaining / this.options.timeOut) * 100;
if (this.options.progressAnimation === 'increasing') {
this.width = 100 - this.width;
}
if (this.width <= 0) {
this.width = 0;
}
if (this.width >= 100) {
this.width = 100;
}
}
resetTimeout() {
clearTimeout(this.timeout);
clearInterval(this.intervalId);
this.state = { ...this.state, value: 'active' };
this.outsideTimeout(() => this.remove(), this.originalTimeout);
this.options.timeOut = this.originalTimeout;
this.hideTime = new Date().getTime() + (this.options.timeOut || 0);
this.width = -1;
if (this.options.progressBar) {
this.outsideInterval(() => this.updateProgress(), 10);
}
}
/**
* tells toastrService to remove this toast after animation time
*/
remove() {
if (this.state.value === 'removed') {
return;
}
clearTimeout(this.timeout);
this.state = { ...this.state, value: 'removed' };
this.outsideTimeout(() => this.toastrService.remove(this.toastPackage.toastId), +this.toastPackage.config.easeTime);
}
tapToast() {
if (this.state.value === 'removed') {
return;
}
this.toastPackage.triggerTap();
if (this.options.tapToDismiss) {
this.remove();
}
}
stickAround() {
if (this.state.value === 'removed') {
return;
}
if (this.options.disableTimeOut !== 'extendedTimeOut') {
clearTimeout(this.timeout);
this.options.timeOut = 0;
this.hideTime = 0;
// disable progressBar
clearInterval(this.intervalId);
this.width = 0;
}
}
delayedHideToast() {
if ((this.options.disableTimeOut === true || this.options.disableTimeOut === 'extendedTimeOut') ||
this.options.extendedTimeOut === 0 ||
this.state.value === 'removed') {
return;
}
this.outsideTimeout(() => this.remove(), this.options.extendedTimeOut);
this.options.timeOut = this.options.extendedTimeOut;
this.hideTime = new Date().getTime() + (this.options.timeOut || 0);
this.width = -1;
if (this.options.progressBar) {
this.outsideInterval(() => this.updateProgress(), 10);
}
}
outsideTimeout(func, timeout) {
if (this.ngZone) {
this.ngZone.runOutsideAngular(() => (this.timeout = setTimeout(() => this.runInsideAngular(func), timeout)));
}
else {
this.timeout = setTimeout(() => func(), timeout);
}
}
outsideInterval(func, timeout) {
if (this.ngZone) {
this.ngZone.runOutsideAngular(() => (this.intervalId = setInterval(() => this.runInsideAngular(func), timeout)));
}
else {
this.intervalId = setInterval(() => func(), timeout);
}
}
runInsideAngular(func) {
if (this.ngZone) {
this.ngZone.run(() => func());
}
else {
func();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: Toast, deps: [{ token: i1.ToastrService }, { token: i2.ToastPackage }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.0.1", type: Toast, isStandalone: true, selector: "[toast-component]", host: { listeners: { "click": "tapToast()", "mouseenter": "stickAround()", "mouseleave": "delayedHideToast()" }, properties: { "class": "this.toastClasses", "@flyInOut": "this.state", "style.display": "this.displayStyle" } }, ngImport: i0, template: `
<button *ngIf="options.closeButton" (click)="remove()" type="button" class="toast-close-button" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
</div>
<div *ngIf="message && options.enableHtml" role="alert"
[class]="options.messageClass" [innerHTML]="message">
</div>
<div *ngIf="message && !options.enableHtml" role="alert"
[class]="options.messageClass" [attr.aria-label]="message">
{{ message }}
</div>
<div *ngIf="options.progressBar">
<div class="toast-progress" [style.width]="width + '%'"></div>
</div>
`, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], animations: [
trigger('flyInOut', [
state('inactive', style({ opacity: 0 })),
state('active', style({ opacity: 1 })),
state('removed', style({ opacity: 0 })),
transition('inactive => active', animate('{{ easeTime }}ms {{ easing }}')),
transition('active => removed', animate('{{ easeTime }}ms {{ easing }}')),
]),
] });
}
export { Toast };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: Toast, decorators: [{
type: Component,
args: [{
selector: '[toast-component]',
template: `
<button *ngIf="options.closeButton" (click)="remove()" type="button" class="toast-close-button" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
{{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
</div>
<div *ngIf="message && options.enableHtml" role="alert"
[class]="options.messageClass" [innerHTML]="message">
</div>
<div *ngIf="message && !options.enableHtml" role="alert"
[class]="options.messageClass" [attr.aria-label]="message">
{{ message }}
</div>
<div *ngIf="options.progressBar">
<div class="toast-progress" [style.width]="width + '%'"></div>
</div>
`,
animations: [
trigger('flyInOut', [
state('inactive', style({ opacity: 0 })),
state('active', style({ opacity: 1 })),
state('removed', style({ opacity: 0 })),
transition('inactive => active', animate('{{ easeTime }}ms {{ easing }}')),
transition('active => removed', animate('{{ easeTime }}ms {{ easing }}')),
]),
],
preserveWhitespaces: false,
standalone: true,
imports: [NgIf],
}]
}], ctorParameters: function () { return [{ type: i1.ToastrService }, { type: i2.ToastPackage }, { type: i0.NgZone }]; }, propDecorators: { toastClasses: [{
type: HostBinding,
args: ['class']
}], state: [{
type: HostBinding,
args: ['@flyInOut']
}], displayStyle: [{
type: HostBinding,
args: ['style.display']
}], tapToast: [{
type: HostListener,
args: ['click']
}], stickAround: [{
type: HostListener,
args: ['mouseenter']
}], delayedHideToast: [{
type: HostListener,
args: ['mouseleave']
}] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9hc3QuY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi90b2FzdHIvdG9hc3QuY29tcG9uZW50LnRzIl0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