{"version":3,"file":"fundamental-ngx-core-scroll-spy.mjs","sources":["../../../../libs/core/scroll-spy/scroll-spy.directive.ts","../../../../libs/core/scroll-spy/scroll-spy.module.ts","../../../../libs/core/scroll-spy/fundamental-ngx-core-scroll-spy.ts"],"sourcesContent":["import { DestroyRef, Directive, ElementRef, OnInit, inject, input, output } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\nimport { resizeObservable } from '@fundamental-ngx/cdk/utils';\nimport { debounceTime } from 'rxjs';\n\n/**\n * A directive designed to help navigation elements determine the element currently in view of the user.\n */\n@Directive({\n    selector: '[fdScrollSpy]',\n    host: {\n        '(scroll)': 'onScroll($event)'\n    },\n    exportAs: 'fdScrollSpy'\n})\nexport class ScrollSpyDirective implements OnInit {\n    /**\n     * An array of tags to track.\n     */\n    readonly trackedTags = input<string[]>([]);\n\n    /**\n     * Whether events are still fired if there is no tag present on the user's screen.\n     */\n    readonly fireEmpty = input(false);\n\n    /**\n     * A number that represent at what location in the container the event is fired.\n     * 0.5 would fire the events in the middle of the container,\n     * 0 for the top and 1 for the bottom.\n     */\n    readonly targetPercent = input(0);\n\n    /**\n     * Number that represents the offset in pixels for fired target. `100` value means that the event will be fired for\n     * target that is 100 pixels below the spy container.\n     */\n    readonly targetOffset = input(0);\n\n    /**\n     * Whether to disable scroll spy\n     */\n    readonly scrollSpyDisabled = input(false);\n\n    /**\n     * Event fired on the scroll element when a new item becomes activated by the scrollspy .\n     * The returned value is the HTMLElement itself, or undefined when no element is active.\n     */\n    readonly spyChange = output<HTMLElement | undefined>();\n\n    /** @hidden */\n    private _currentActive: HTMLElement | undefined;\n\n    /** @hidden */\n    private readonly _elRef = inject(ElementRef);\n\n    /** @hidden */\n    private readonly _destroyRef = inject(DestroyRef);\n\n    /** @hidden */\n    onScroll(event?: Event, forced = false): void {\n        if (this.scrollSpyDisabled()) {\n            return;\n        }\n\n        let spiedTag: HTMLElement | undefined;\n        const target = (event?.target || this._elRef.nativeElement) as HTMLElement;\n        const children: HTMLElement[] = this._elRef.nativeElement.children;\n        const [firstChild] = children;\n        const childrenLength = children.length;\n        const targetScrollTop = target.scrollTop;\n        const targetOffsetTop = firstChild.offsetTop + this.targetOffset();\n\n        for (let i = 0; i < childrenLength; i++) {\n            const element = children[i];\n            if (this.trackedTags().some((tag) => tag.toLocaleUpperCase() === element.tagName.toLocaleUpperCase())) {\n                if (\n                    element.offsetTop - targetOffsetTop <=\n                    targetScrollTop + target.offsetHeight * this.targetPercent()\n                ) {\n                    spiedTag = element;\n                }\n            }\n        }\n\n        if (forced || ((spiedTag || this.fireEmpty()) && spiedTag !== this._currentActive)) {\n            this._currentActive = spiedTag;\n            this.spyChange.emit(this._currentActive);\n        }\n    }\n\n    /** @hidden */\n    ngOnInit(): void {\n        // When the spy container being resized, re-evaluate scroll position.\n        resizeObservable(this._elRef.nativeElement)\n            .pipe(debounceTime(30), takeUntilDestroyed(this._destroyRef))\n            .subscribe(() => {\n                this.onScroll(undefined, true);\n            });\n    }\n}\n","import { NgModule } from '@angular/core';\n\nimport { ScrollSpyDirective } from './scroll-spy.directive';\n\n/**\n * @deprecated\n * Use direct `ScrollSpyDirective` import.\n */\n@NgModule({\n    imports: [ScrollSpyDirective],\n    exports: [ScrollSpyDirective]\n})\nexport class ScrollSpyModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKA;;AAEG;MAQU,kBAAkB,CAAA;AAP/B,IAAA,WAAA,GAAA;AAQI;;AAEG;AACM,QAAA,IAAA,CAAA,WAAW,GAAG,KAAK,CAAW,EAAE,uDAAC;AAE1C;;AAEG;AACM,QAAA,IAAA,CAAA,SAAS,GAAG,KAAK,CAAC,KAAK,qDAAC;AAEjC;;;;AAIG;AACM,QAAA,IAAA,CAAA,aAAa,GAAG,KAAK,CAAC,CAAC,yDAAC;AAEjC;;;AAGG;AACM,QAAA,IAAA,CAAA,YAAY,GAAG,KAAK,CAAC,CAAC,wDAAC;AAEh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