UNPKG

@taiga-ui/kit

Version:
104 lines (98 loc) 4.26 kB
import { __extends, __read, __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 { of, Subject, Observable } from 'rxjs'; import { switchMap, filter, mapTo, catchError, take, takeUntil } from 'rxjs/operators'; var TuiLazyLoadingService = /** @class */ (function (_super) { __extends(TuiLazyLoadingService, _super); function TuiLazyLoadingService(changeDetectorRef, destroy$, intersections$) { var _this = _super.call(this, function (subscriber) { return _this.src$ .pipe(switchMap(function (src) { return intersections$.pipe(filter(function (_a) { var _b = __read(_a, 1), isIntersecting = _b[0].isIntersecting; return isIntersecting; }), mapTo(src), catchError(function () { return of(src); }), watch(changeDetectorRef), take(1)); }), takeUntil(destroy$)) .subscribe(subscriber); }) || this; _this.src$ = new Subject(); return _this; } TuiLazyLoadingService.prototype.next = function (src) { this.src$.next(src); }; TuiLazyLoadingService.ctorParameters = function () { return [ { 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); return TuiLazyLoadingService; }(Observable)); var TuiLazyLoadingDirective = /** @class */ (function () { function TuiLazyLoadingDirective(src$, elementRef) { var _this = this; this.src$ = src$; this.elementRef = elementRef; this.src = null; this.supported = 'loading' in this.elementRef.nativeElement; if (!this.supported) { this.src$.subscribe(function (src) { _this.src = src; }); } } Object.defineProperty(TuiLazyLoadingDirective.prototype, "srcSetter", { set: function (src) { this.src = this.supported ? src : null; this.src$.next(src); }, enumerable: true, configurable: true }); TuiLazyLoadingDirective.ctorParameters = function () { return [ { 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); return TuiLazyLoadingDirective; }()); var TuiLazyLoadingModule = /** @class */ (function () { function TuiLazyLoadingModule() { } TuiLazyLoadingModule = __decorate([ NgModule({ declarations: [TuiLazyLoadingDirective], exports: [TuiLazyLoadingDirective], }) ], TuiLazyLoadingModule); return TuiLazyLoadingModule; }()); /** * Generated bundle index. Do not edit. */ export { TuiLazyLoadingDirective, TuiLazyLoadingModule, TuiLazyLoadingService as ɵa }; //# sourceMappingURL=taiga-ui-kit-directives-lazy-loading.js.map