101 lines
11 KiB
JavaScript
101 lines
11 KiB
JavaScript
|
import { CommonModule } from '@angular/common';
|
||
|
import { Directive, Input, NgModule } from '@angular/core';
|
||
|
import { DomHandler } from 'primeng/dom';
|
||
|
import * as i0 from "@angular/core";
|
||
|
/**
|
||
|
* Animate manages PrimeFlex CSS classes declaratively to during enter/leave animations on scroll or on page load.
|
||
|
* @group Components
|
||
|
*/
|
||
|
export class Animate {
|
||
|
host;
|
||
|
el;
|
||
|
renderer;
|
||
|
/**
|
||
|
* Selector to define the CSS class for enter animation.
|
||
|
* @group Props
|
||
|
*/
|
||
|
enterClass;
|
||
|
/**
|
||
|
* Selector to define the CSS class for leave animation.
|
||
|
* @group Props
|
||
|
*/
|
||
|
leaveClass;
|
||
|
observer;
|
||
|
timeout;
|
||
|
constructor(host, el, renderer) {
|
||
|
this.host = host;
|
||
|
this.el = el;
|
||
|
this.renderer = renderer;
|
||
|
}
|
||
|
ngOnInit() {
|
||
|
console.log('pAnimate directive is deprecated in 16.7.0 and will be removed in the future. Use pAnimateOnScroll directive instead');
|
||
|
}
|
||
|
ngAfterViewInit() {
|
||
|
this.bindIntersectionObserver();
|
||
|
}
|
||
|
bindIntersectionObserver() {
|
||
|
const options = {
|
||
|
root: null,
|
||
|
rootMargin: '0px',
|
||
|
threshold: 1.0
|
||
|
};
|
||
|
this.observer = new IntersectionObserver((el) => this.isVisible(el), options);
|
||
|
this.observer.observe(this.host.nativeElement);
|
||
|
}
|
||
|
isVisible(element) {
|
||
|
const [intersectionObserverEntry] = element;
|
||
|
intersectionObserverEntry.isIntersecting ? this.enter() : this.leave();
|
||
|
}
|
||
|
enter() {
|
||
|
this.host.nativeElement.style.visibility = 'visible';
|
||
|
DomHandler.addClass(this.host.nativeElement, this.enterClass);
|
||
|
}
|
||
|
leave() {
|
||
|
DomHandler.removeClass(this.host.nativeElement, this.enterClass);
|
||
|
if (this.leaveClass) {
|
||
|
DomHandler.addClass(this.host.nativeElement, this.leaveClass);
|
||
|
}
|
||
|
const animationDuration = this.host.nativeElement.style.animationDuration || 500;
|
||
|
this.timeout = setTimeout(() => {
|
||
|
this.host.nativeElement.style.visibility = 'hidden';
|
||
|
}, animationDuration);
|
||
|
}
|
||
|
unbindIntersectionObserver() {
|
||
|
if (this.observer) {
|
||
|
this.observer.unobserve(this.host.nativeElement);
|
||
|
}
|
||
|
}
|
||
|
ngOnDestroy() {
|
||
|
this.unbindIntersectionObserver();
|
||
|
clearTimeout(this.timeout);
|
||
|
}
|
||
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Animate, deps: [{ token: i0.ElementRef }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
|
||
|
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.7", type: Animate, selector: "[pAnimate]", inputs: { enterClass: "enterClass", leaveClass: "leaveClass" }, host: { properties: { "class.p-animate": "true" } }, ngImport: i0 });
|
||
|
}
|
||
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Animate, decorators: [{
|
||
|
type: Directive,
|
||
|
args: [{
|
||
|
selector: '[pAnimate]',
|
||
|
host: {
|
||
|
'[class.p-animate]': 'true'
|
||
|
}
|
||
|
}]
|
||
|
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.ElementRef }, { type: i0.Renderer2 }], propDecorators: { enterClass: [{
|
||
|
type: Input
|
||
|
}], leaveClass: [{
|
||
|
type: Input
|
||
|
}] } });
|
||
|
export class AnimateModule {
|
||
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AnimateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
||
|
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: AnimateModule, declarations: [Animate], imports: [CommonModule], exports: [Animate] });
|
||
|
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AnimateModule, imports: [CommonModule] });
|
||
|
}
|
||
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: AnimateModule, decorators: [{
|
||
|
type: NgModule,
|
||
|
args: [{
|
||
|
imports: [CommonModule],
|
||
|
exports: [Animate],
|
||
|
declarations: [Animate]
|
||
|
}]
|
||
|
}] });
|
||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5pbWF0ZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcHAvY29tcG9uZW50cy9hbmltYXRlL2FuaW1hdGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLGlCQUFpQixDQUFDO0FBQy9DLE9BQU8sRUFBaUIsU0FBUyxFQUFjLEtBQUssRUFBRSxRQUFRLEVBQXFCLE1BQU0sZUFBZSxDQUFDO0FBQ3pHLE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxhQUFhLENBQUM7O0FBQ3pDOzs7R0FHRztBQU9ILE1BQU0sT0FBTyxPQUFPO0lBZ0JJO0lBQXlCO0lBQXVCO0lBZnBFOzs7T0FHRztJQUNNLFVBQVUsQ0FBcUI7SUFDeEM7OztPQUdHO0lBQ00sVUFBVSxDQUFxQjtJQUV4QyxRQUFRLENBQW1DO0lBRTNDLE9BQU8sQ0FBTTtJQUViLFlBQW9CLElBQWdCLEVBQVMsRUFBYyxFQUFTLFFBQW1CO1FBQW5FLFNBQUksR0FBSixJQUFJLENBQVk7UUFBUyxPQUFFLEdBQUYsRUFBRSxDQUFZO1FBQVMsYUFBUSxHQUFSLFFBQVEsQ0FBVztJQUFHLENBQUM7SUFFM0YsUUFBUTtRQUNKLE9BQU8sQ0FBQyx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