{ "version": 3, "sources": ["src/app/shared/intersection-observer/intersection-observer.directive.ts"], "sourcesContent": ["import { isPlatformBrowser } from '@angular/common';\nimport {\n Directive,\n ElementRef,\n EventEmitter,\n Inject,\n Input,\n OnDestroy,\n OnInit,\n Output,\n PLATFORM_ID,\n} from '@angular/core';\nimport { Observable, Subject } from 'rxjs';\nimport {\n debounceTime,\n distinctUntilChanged,\n map,\n takeUntil,\n} from 'rxjs/operators';\n\n@Directive({\n selector: '[appIntersectionObserver]',\n standalone: true,\n})\nexport class IntersectionObserverDirective implements OnInit, OnDestroy {\n @Input() intersectionDebounce = 50;\n @Input() intersectionRootMargin = '0px';\n @Input() intersectionRoot: HTMLElement;\n @Input() intersectionThreshold: number;\n\n @Output() visibilityChange = new EventEmitter();\n\n private destroy$ = new Subject();\n\n constructor(\n private element: ElementRef,\n @Inject(PLATFORM_ID) private platformId: Object\n ) {}\n\n ngOnInit() {\n if (isPlatformBrowser(this.platformId)) {\n const element = this.element.nativeElement;\n\n const config = {\n root: this.intersectionRoot,\n rootMargin: this.intersectionRootMargin,\n threshold: +this.intersectionThreshold,\n };\n\n this.fromIntersectionObserver(element, config)\n .pipe(\n debounceTime(this.intersectionDebounce),\n map(\n entry =>\n entry.isIntersecting &&\n entry.intersectionRatio >=\n this.intersectionThreshold\n ),\n distinctUntilChanged(),\n takeUntil(this.destroy$)\n )\n .subscribe(status => {\n this.visibilityChange.emit(status);\n });\n }\n }\n\n fromIntersectionObserver(\n element: HTMLElement,\n config: IntersectionObserverInit\n ) {\n return new Observable(subscriber => {\n const intersectionObserver = new IntersectionObserver(\n (entries: IntersectionObserverEntry[] = []) => {\n subscriber.next(entries[0] || null);\n },\n config\n );\n intersectionObserver.observe(element);\n return () => {\n intersectionObserver.disconnect();\n };\n });\n }\n\n ngOnDestroy() {\n this.destroy$.next(null);\n }\n}\n"], "mappings": "4HAwBA,IAAaA,GAA6B,IAAA,CAApC,MAAOA,CAA6B,CAUtCC,YACYC,EACqBC,EAAkB,CADv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CAA6B,GAAA", "names": ["IntersectionObserverDirective", "constructor", "element", "platformId", "intersectionDebounce", "intersectionRootMargin", "visibilityChange", "EventEmitter", "destroy$", "Subject", "ngOnInit", "isPlatformBrowser", "nativeElement", "config", "root", "intersectionRoot", "rootMargin", "threshold", "intersectionThreshold", "fromIntersectionObserver", "pipe", "debounceTime", "map", "entry", "isIntersecting", "intersectionRatio", "distinctUntilChanged", "takeUntil", "subscribe", "status", "emit", "Observable", "subscriber", "intersectionObserver", "IntersectionObserver", "entries", "next", "observe", "disconnect", "ngOnDestroy", "\u0275\u0275directiveInject", "ElementRef", "PLATFORM_ID", "selectors", "inputs", "outputs", "standalone"] }