{"version":3,"file":"primeng-animateonscroll.mjs","sources":["../../src/animateonscroll/animateonscroll.ts","../../src/animateonscroll/primeng-animateonscroll.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { booleanAttribute, Directive, Input, NgModule, numberAttribute } from '@angular/core';\nimport { addClass, removeClass } from '@primeuix/utils';\nimport { BaseComponent } from 'primeng/basecomponent';\n\ninterface AnimateOnScrollOptions {\n    root?: HTMLElement | null;\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 {\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 = 0.5;\n    /**\n     * Whether the scroll event listener should be removed after initial run.\n     * @group Props\n     */\n    @Input({ transform: booleanAttribute }) once: boolean = false;\n\n    observer: IntersectionObserver | undefined;\n\n    resetObserver: any;\n\n    isObserverActive: boolean = false;\n\n    animationState: any;\n\n    animationEndListener: VoidFunction | null | undefined;\n\n    onInit() {\n        if (isPlatformBrowser(this.platformId)) {\n            this.renderer.setStyle(this.el.nativeElement, 'opacity', this.enterClass ? '0' : '');\n        }\n    }\n\n    onAfterViewInit() {\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 || 0.5\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    onDestroy() {\n        this.unbindAnimationEvents();\n        this.unbindIntersectionObserver();\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;IACoC,SAAS,GAAuB,GAAG;AAC1E;;;AAGG;IACqC,IAAI,GAAY,KAAK;AAE7D,IAAA,QAAQ;AAER,IAAA,aAAa;IAEb,gBAAgB,GAAY,KAAK;AAEjC,IAAA,cAAc;AAEd,IAAA,oBAAoB;IAEpB,MAAM,GAAA;AACF,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;QACxF;IACJ;IAEA,eAAe,GAAA;AACX,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YACpC,IAAI,CAAC,wBAAwB,EAAE;QACnC;IACJ;AAEA,IAAA,IAAI,OAAO,GAAA;QACP,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,UAAU,EAAE,IAAI,CAAC,UAAU;AAC3B,YAAA,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI;SAChC;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