Icard/angular-clarity-master(work.../node_modules/primeng/esm2022/defer/defer.mjs

111 lines
12 KiB
JavaScript

import { CommonModule, DOCUMENT, isPlatformBrowser } from '@angular/common';
import { ContentChild, Directive, EventEmitter, Inject, NgModule, Output, PLATFORM_ID, TemplateRef } from '@angular/core';
import * as i0 from "@angular/core";
/**
* Defer postpones the loading the content that is initially not in the viewport until it becomes visible on scroll.
* @group Components
*/
export class DeferredLoader {
document;
platformId;
el;
renderer;
viewContainer;
cd;
/**
* Callback to invoke when deferred content is loaded.
* @param {Event} event - Browser event.
* @group Emits
*/
onLoad = new EventEmitter();
template;
documentScrollListener;
view;
window;
constructor(document, platformId, el, renderer, viewContainer, cd) {
this.document = document;
this.platformId = platformId;
this.el = el;
this.renderer = renderer;
this.viewContainer = viewContainer;
this.cd = cd;
this.window = this.document.defaultView;
}
ngAfterViewInit() {
if (isPlatformBrowser(this.platformId)) {
if (this.shouldLoad()) {
this.load();
}
if (!this.isLoaded()) {
this.documentScrollListener = this.renderer.listen(this.window, 'scroll', () => {
if (this.shouldLoad()) {
this.load();
this.documentScrollListener && this.documentScrollListener();
this.documentScrollListener = null;
}
});
}
}
}
shouldLoad() {
if (this.isLoaded()) {
return false;
}
else {
let rect = this.el.nativeElement.getBoundingClientRect();
let docElement = this.document.documentElement;
let winHeight = docElement.clientHeight;
return winHeight >= rect.top;
}
}
load() {
this.view = this.viewContainer.createEmbeddedView(this.template);
this.onLoad.emit();
this.cd.detectChanges();
}
isLoaded() {
return this.view != null && isPlatformBrowser(this.platformId);
}
ngOnDestroy() {
this.view = null;
if (this.documentScrollListener) {
this.documentScrollListener();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DeferredLoader, deps: [{ token: DOCUMENT }, { token: PLATFORM_ID }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.7", type: DeferredLoader, selector: "[pDefer]", outputs: { onLoad: "onLoad" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "template", first: true, predicate: TemplateRef, descendants: true }], ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DeferredLoader, decorators: [{
type: Directive,
args: [{
selector: '[pDefer]',
host: {
class: 'p-element'
}
}]
}], ctorParameters: () => [{ type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }, { type: undefined, decorators: [{
type: Inject,
args: [PLATFORM_ID]
}] }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }], propDecorators: { onLoad: [{
type: Output
}], template: [{
type: ContentChild,
args: [TemplateRef]
}] } });
export class DeferModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DeferModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: DeferModule, declarations: [DeferredLoader], imports: [CommonModule], exports: [DeferredLoader] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DeferModule, imports: [CommonModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DeferModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule],
exports: [DeferredLoader],
declarations: [DeferredLoader]
}]
}] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvYXBwL2NvbXBvbmVudHMvZGVmZXIvZGVmZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5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nJlbmRlcmVyLmxpc3Rlbih0aGlzLndpbmRvdywgJ3Njcm9sbCcsICgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHRoaXMuc2hvdWxkTG9hZCgpKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICB0aGlzLmxvYWQoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZG9jdW1lbnRTY3JvbGxMaXN0ZW5lciAmJiB0aGlzLmRvY3VtZW50U2Nyb2xsTGlzdGVuZXIoKTtcbiAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuZG9jdW1lbnRTY3JvbGxMaXN0ZW5lciA9IG51bGw7XG4gICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfVxuICAgIH1cblxuICAgIHNob3VsZExvYWQoKTogYm9vbGVhbiB7XG4gICAgICAgIGlmICh0aGlzLmlzTG9hZGVkKCkpIHtcbiAgICAgICAgICAgIHJldHVybiBmYWxzZTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGxldCByZWN0ID0gdGhpcy5lbC5uYXRpdmVFbGVtZW50LmdldEJvdW5kaW5nQ2xpZW50UmVjdCgpO1xuICAgICAgICAgICAgbGV0IGRvY0VsZW1lbnQgPSB0aGlzLmRvY3VtZW50LmRvY3VtZW50RWxlbWVudDtcbiAgICAgICAgICAgIGxldCB3aW5IZWlnaHQgPSBkb2NFbGVtZW50LmNsaWVudEhlaWdodDtcblxuICAgICAgICAgICAgcmV0dXJuIHdpbkhlaWdodCA+PSByZWN0LnRvcDtcbiAgICAgICAgfVxuICAgIH1cblxuICAgIGxvYWQoKTogdm9pZCB7XG4gICAgICAgIHRoaXMudmlldyA9IHRoaXMudmlld0NvbnRhaW5lci5jcmVhdGVFbWJlZGRlZFZpZXcodGhpcy50ZW1wbGF0ZSBhcyBUZW1wbGF0ZVJlZjxhbnk+KTtcbiAgICAgICAgdGhpcy5vbkx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