UNPKG

@taiga-ui/cdk

Version:

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

55 lines (50 loc) 3.25 kB
import * as i0 from '@angular/core'; import { inject, Injectable, input, Directive } from '@angular/core'; import { toObservable, outputFromObservable } from '@angular/core/rxjs-interop'; import { TuiActiveZone } from '@taiga-ui/cdk/directives/active-zone'; import { tuiZonefreeScheduler, tuiZoneOptimized, tuiIfMap } from '@taiga-ui/cdk/observables'; import { Observable, throttleTime, map, startWith, distinctUntilChanged } 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: "19.2.25", ngImport: i0, type: TuiObscuredService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiObscuredService }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiObscuredService, decorators: [{ type: Injectable }], ctorParameters: () => [] }); /** * Directive that monitors element visibility */ class TuiObscured { constructor() { this.activeZone = inject(TuiActiveZone, { optional: true }); this.obscured$ = inject(TuiObscuredService, { self: true }).pipe(map((by) => !!by?.every((el) => !this.activeZone?.contains(el)))); this.tuiObscuredEnabled = input(); this.tuiObscured$ = toObservable(this.tuiObscuredEnabled).pipe(tuiIfMap(() => this.obscured$)); this.tuiObscured = outputFromObservable(this.tuiObscured$); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiObscured, deps: [], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "19.2.25", type: TuiObscured, isStandalone: true, selector: "[tuiObscured]", inputs: { tuiObscuredEnabled: { classPropertyName: "tuiObscuredEnabled", publicName: "tuiObscuredEnabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { tuiObscured: "tuiObscured" }, providers: [TuiObscuredService], ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: TuiObscured, decorators: [{ type: Directive, args: [{ selector: '[tuiObscured]', providers: [TuiObscuredService], }] }] }); /** * Generated bundle index. Do not edit. */ export { TuiObscured, TuiObscuredService }; //# sourceMappingURL=taiga-ui-cdk-directives-obscured.mjs.map