UNPKG

@taiga-ui/kit

Version:
85 lines (79 loc) 3.29 kB
import { __decorate, __param } from 'tslib'; import { ChangeDetectorRef, Inject, Injectable, ElementRef, Input, HostBinding, Directive, NgModule } from '@angular/core'; import { IntersectionObserverService } from '@ng-web-apis/intersection-observer'; import { watch, TuiDestroyService } from '@taiga-ui/cdk'; import { Observable, of, Subject } from 'rxjs'; import { switchMap, filter, mapTo, catchError, take, takeUntil } from 'rxjs/operators'; let TuiLazyLoadingService = class TuiLazyLoadingService extends Observable { constructor(changeDetectorRef, destroy$, intersections$) { super(subscriber => this.src$ .pipe(switchMap(src => intersections$.pipe(filter(([{ isIntersecting }]) => isIntersecting), mapTo(src), catchError(() => of(src)), watch(changeDetectorRef), take(1))), takeUntil(destroy$)) .subscribe(subscriber)); this.src$ = new Subject(); } next(src) { this.src$.next(src); } }; TuiLazyLoadingService.ctorParameters = () => [ { type: ChangeDetectorRef, decorators: [{ type: Inject, args: [ChangeDetectorRef,] }] }, { type: Observable, decorators: [{ type: Inject, args: [TuiDestroyService,] }] }, { type: Observable, decorators: [{ type: Inject, args: [IntersectionObserverService,] }] } ]; TuiLazyLoadingService = __decorate([ Injectable(), __param(0, Inject(ChangeDetectorRef)), __param(1, Inject(TuiDestroyService)), __param(2, Inject(IntersectionObserverService)) ], TuiLazyLoadingService); let TuiLazyLoadingDirective = class TuiLazyLoadingDirective { constructor(src$, elementRef) { this.src$ = src$; this.elementRef = elementRef; this.src = null; this.supported = 'loading' in this.elementRef.nativeElement; if (!this.supported) { this.src$.subscribe(src => { this.src = src; }); } } set srcSetter(src) { this.src = this.supported ? src : null; this.src$.next(src); } }; TuiLazyLoadingDirective.ctorParameters = () => [ { type: TuiLazyLoadingService, decorators: [{ type: Inject, args: [TuiLazyLoadingService,] }] }, { type: ElementRef, decorators: [{ type: Inject, args: [ElementRef,] }] } ]; __decorate([ Input('src') ], TuiLazyLoadingDirective.prototype, "srcSetter", null); __decorate([ HostBinding('attr.src') ], TuiLazyLoadingDirective.prototype, "src", void 0); TuiLazyLoadingDirective = __decorate([ Directive({ selector: 'img[loading="lazy"]', providers: [TuiLazyLoadingService, IntersectionObserverService, TuiDestroyService], host: { '[style.animation]': '"tuiSkeletonBackgroundVibe ease-in-out 1s infinite alternate"', }, }), __param(0, Inject(TuiLazyLoadingService)), __param(1, Inject(ElementRef)) ], TuiLazyLoadingDirective); let TuiLazyLoadingModule = class TuiLazyLoadingModule { }; TuiLazyLoadingModule = __decorate([ NgModule({ declarations: [TuiLazyLoadingDirective], exports: [TuiLazyLoadingDirective], }) ], TuiLazyLoadingModule); /** * Generated bundle index. Do not edit. */ export { TuiLazyLoadingDirective, TuiLazyLoadingModule, TuiLazyLoadingService as ɵa }; //# sourceMappingURL=taiga-ui-kit-directives-lazy-loading.js.map