UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

61 lines (56 loc) 3.27 kB
import * as i0 from '@angular/core'; import { inject, Injectable, Directive, Output, Input } from '@angular/core'; import { TuiActiveZone } from '@taiga-ui/cdk/directives/active-zone'; import { tuiZonefreeScheduler, tuiZoneOptimized, tuiIfMap } from '@taiga-ui/cdk/observables'; import { Observable, throttleTime, map, startWith, distinctUntilChanged, BehaviorSubject } from 'rxjs'; import { WA_ANIMATION_FRAME } from '@ng-web-apis/common'; import { tuiInjectElement, tuiGetElementObscures } from '@taiga-ui/cdk/utils/dom'; /** * Service that monitors element visibility by polling and returning * either null or an array of elements that overlap given element edges */ class TuiObscuredService extends Observable { constructor() { super((subscriber) => this.obscured$.subscribe(subscriber)); this.el = tuiInjectElement(); this.obscured$ = inject(WA_ANIMATION_FRAME).pipe(throttleTime(100, tuiZonefreeScheduler()), map(() => tuiGetElementObscures(this.el)), startWith(null), distinctUntilChanged(), tuiZoneOptimized()); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObscuredService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObscuredService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObscuredService, decorators: [{ type: Injectable }], ctorParameters: function () { return []; } }); /** * Directive that monitors element visibility */ class TuiObscured { constructor() { this.activeZone = inject(TuiActiveZone, { optional: true }); this.enabled$ = new BehaviorSubject(false); this.obscured$ = inject(TuiObscuredService, { self: true }).pipe(map((by) => !!by?.every((el) => !this.activeZone?.contains(el)))); this.tuiObscured = this.enabled$.pipe(tuiIfMap(() => this.obscured$)); } set tuiObscuredEnabled(enabled) { this.enabled$.next(enabled); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObscured, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: TuiObscured, isStandalone: true, selector: "[tuiObscured]", inputs: { tuiObscuredEnabled: "tuiObscuredEnabled" }, outputs: { tuiObscured: "tuiObscured" }, providers: [TuiObscuredService], ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TuiObscured, decorators: [{ type: Directive, args: [{ standalone: true, selector: '[tuiObscured]', providers: [TuiObscuredService], }] }], propDecorators: { tuiObscured: [{ type: Output }], tuiObscuredEnabled: [{ type: Input }] } }); /** * Generated bundle index. Do not edit. */ export { TuiObscured, TuiObscuredService }; //# sourceMappingURL=taiga-ui-cdk-directives-obscured.mjs.map