{"version":3,"file":"primeng-animateonscroll.mjs","sources":["../../src/animateonscroll/animateonscroll.ts","../../src/animateonscroll/primeng-animateonscroll.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { AfterViewInit, booleanAttribute, Directive, Input, NgModule, numberAttribute, OnInit } from '@angular/core';\nimport { addClass, removeClass } from '@primeuix/utils';\nimport { BaseComponent } from 'primeng/basecomponent';\n\ninterface AnimateOnScrollOptions {\n    root?: HTMLElement;\n    rootMargin?: string;\n    threshold?: number;\n}\n\n/**\n * AnimateOnScroll is used to apply animations to elements when entering or leaving the viewport during scrolling.\n * @group Components\n */\n@Directive({\n    selector: '[pAnimateOnScroll]',\n    standalone: true,\n    host: {\n        '[class.p-animateonscroll]': 'true'\n    }\n})\nexport class AnimateOnScroll extends BaseComponent implements OnInit, AfterViewInit {\n    /**\n     * Selector to define the CSS class for enter animation.\n     * @group Props\n     */\n    @Input() enterClass: string | undefined;\n    /**\n     * Selector to define the CSS class for leave animation.\n     * @group Props\n     */\n    @Input() leaveClass: string | undefined;\n    /**\n     * Specifies the root option of the IntersectionObserver API.\n     * @group Props\n     */\n    @Input() root: HTMLElement | undefined | null;\n    /**\n     * Specifies the rootMargin option of the IntersectionObserver API.\n     * @group Props\n     */\n    @Input() rootMargin: string | undefined;\n    /**\n     * Specifies the threshold option of the IntersectionObserver API\n     * @group Props\n     */\n    @Input({ transform: numberAttribute }) threshold: number | undefined;\n    /**\n     * Whether the scroll event listener should be removed after initial run.\n     * @group Props\n     */\n    @Input({ transform: booleanAttribute }) once: boolean = true;\n\n    observer: IntersectionObserver | undefined;\n\n    resetObserver: any;\n\n    isObserverActive: boolean = false;\n\n    animationState: any;\n\n    animationEndListener: VoidFunction | undefined;\n\n    ngOnInit() {\n        super.ngOnInit();\n        if (isPlatformBrowser(this.platformId)) {\n            this.renderer.setStyle(this.el.nativeElement, 'opacity', this.enterClass ? '0' : '');\n        }\n    }\n\n    ngAfterViewInit() {\n        super.ngAfterViewInit();\n        if (isPlatformBrowser(this.platformId)) {\n            this.bindIntersectionObserver();\n        }\n    }\n\n    get options(): AnimateOnScrollOptions {\n        return {\n            root: this.root,\n            rootMargin: this.rootMargin,\n            threshold: this.threshold\n        };\n    }\n\n    bindIntersectionObserver() {\n        this.observer = new IntersectionObserver(([entry]) => {\n            if (this.isObserverActive) {\n                if (entry.boundingClientRect.top > 0) {\n                    entry.isIntersecting ? this.enter() : this.leave();\n                }\n            } else if (entry.isIntersecting) {\n                this.enter();\n            }\n\n            this.isObserverActive = true;\n        }, this.options);\n\n        setTimeout(() => this.observer.observe(this.el.nativeElement), 0);\n\n        // Reset\n\n        this.resetObserver = new IntersectionObserver(\n            ([entry]) => {\n                if (entry.boundingClientRect.top > 0 && !entry.isIntersecting) {\n                    this.el.nativeElement.style.opacity = this.enterClass ? '0' : '';\n                    removeClass(this.el.nativeElement, [this.enterClass, this.leaveClass]);\n\n                    this.resetObserver.unobserve(this.el.nativeElement);\n                }\n\n                this.animationState = undefined;\n            },\n            { ...this.options, threshold: 0 }\n        );\n    }\n\n    enter() {\n        if (this.animationState !== 'enter' && this.enterClass) {\n            this.el.nativeElement.style.opacity = '';\n            removeClass(this.el.nativeElement, this.leaveClass);\n            addClass(this.el.nativeElement, this.enterClass);\n\n            this.once && this.unbindIntersectionObserver();\n\n            this.bindAnimationEvents();\n            this.animationState = 'enter';\n        }\n    }\n\n    leave() {\n        if (this.animationState !== 'leave' && this.leaveClass) {\n            this.el.nativeElement.style.opacity = this.enterClass ? '0' : '';\n            removeClass(this.el.nativeElement, this.enterClass);\n            addClass(this.el.nativeElement, this.leaveClass);\n\n            this.bindAnimationEvents();\n            this.animationState = 'leave';\n        }\n    }\n\n    bindAnimationEvents() {\n        if (!this.animationEndListener) {\n            this.animationEndListener = this.renderer.listen(this.el.nativeElement, 'animationend', () => {\n                removeClass(this.el.nativeElement, [this.enterClass, this.leaveClass]);\n                !this.once && this.resetObserver.observe(this.el.nativeElement);\n                this.unbindAnimationEvents();\n            });\n        }\n    }\n\n    unbindAnimationEvents() {\n        if (this.animationEndListener) {\n            this.animationEndListener();\n            this.animationEndListener = null;\n        }\n    }\n\n    unbindIntersectionObserver() {\n        this.observer?.unobserve(this.el.nativeElement);\n        this.resetObserver?.unobserve(this.el.nativeElement);\n        this.isObserverActive = false;\n    }\n\n    ngOnDestroy() {\n        this.unbindAnimationEvents();\n        this.unbindIntersectionObserver();\n\n        super.ngOnDestroy();\n    }\n}\n\n@NgModule({\n    imports: [AnimateOnScroll],\n    exports: [AnimateOnScroll]\n})\nexport class AnimateOnScrollModule {}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;AAWA;;;AAGG;AAQG,MAAO,eAAgB,SAAQ,aAAa,CAAA;AAC9C;;;AAGG;AACM,IAAA,UAAU;AACnB;;;AAGG;AACM,IAAA,UAAU;AACnB;;;AAGG;AACM,IAAA,IAAI;AACb;;;AAGG;AACM,IAAA,UAAU;AACnB;;;AAGG;AACoC,IAAA,SAAS;AAChD;;;AAGG;IACqC,IAAI,GAAY,IAAI;AAE5D,IAAA,QAAQ;AAER,IAAA,aAAa;IAEb,gBAAgB,GAAY,KAAK;AAEjC,IAAA,cAAc;AAEd,IAAA,oBAAoB;IAEpB,QAAQ,GAAA;QACJ,KAAK,CAAC,QAAQ,EAAE;AAChB,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACpC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,GAAG,GAAG,GAAG,EAAE,CAAC;;;IAI5F,eAAe,GAAA;QACX,KAAK,CAAC,eAAe,EAAE;AACvB,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACpC,IAAI,CAAC,wBAAwB,EAAE;;;AAIvC,IAAA,IAAI,OAAO,GAAA;QACP,OAAO;YACH,IAAI,E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