{"version":3,"file":"primeng-animateonscroll.mjs","sources":["../../src/animateonscroll/animateonscroll.ts","../../src/animateonscroll/primeng-animateonscroll.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { booleanAttribute, computed, 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    enterClass = input<string>();\n\n    /**\n     * Selector to define the CSS class for leave animation.\n     * @group Props\n     */\n    leaveClass = input<string>();\n\n    /**\n     * Specifies the root option of the IntersectionObserver API.\n     * @group Props\n     */\n    root = input<HTMLElement | null>();\n\n    /**\n     * Specifies the rootMargin option of the IntersectionObserver API.\n     * @group Props\n     */\n    rootMargin = input<string>();\n\n    /**\n     * Specifies the threshold option of the IntersectionObserver API\n     * @group Props\n     */\n    threshold = input(0.5, { transform: numberAttribute });\n\n    /**\n     * Whether the scroll event listener should be removed after initial run.\n     * @group Props\n     */\n    once = input(false, { transform: booleanAttribute });\n\n    observer: IntersectionObserver | undefined;\n\n    resetObserver: IntersectionObserver | undefined;\n\n    isObserverActive: boolean = false;\n\n    animationState: 'enter' | 'leave' | undefined;\n\n    animationEndListener: VoidFunction | null | undefined;\n\n    options = computed<AnimateOnScrollOptions>(() => ({\n        root: this.root(),\n        rootMargin: this.rootMargin(),\n        threshold: this.threshold() || 0.5\n    }));\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    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        const enterClass = this.enterClass();\n        if (this.animationState !== 'enter' && enterClass) {\n            this.el.nativeElement.style.opacity = '';\n            removeClass(this.el.nativeElement, this.leaveClass());\n            addClass(this.el.nativeElement, enterClass);\n\n            this.once() && this.unbindIntersectionObserver();\n\n            this.bindAnimationEvents();\n            this.animationState = 'enter';\n        }\n    }\n\n    leave() {\n        const leaveClass = this.leaveClass();\n        if (this.animationState !== 'leave' && leaveClass) {\n            this.el.nativeElement.style.opacity = this.enterClass() ? '0' : '';\n            removeClass(this.el.nativeElement, this.enterClass());\n            addClass(this.el.nativeElement, 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;AACH,IAAA,UAAU,GAAG,KAAK;8FAAU;AAE5B;;;AAGG;AACH,IAAA,UAAU,GAAG,KAAK;8FAAU;AAE5B;;;AAGG;AACH,IAAA,IAAI,GAAG,KAAK;wFAAsB;AAElC;;;AAGG;AACH,IAAA,UAAU,GAAG,KAAK;8FAAU;AAE5B;;;AAGG;IACH,SAAS,GAAG,KAAK,CAAC,GAAG,iFAAI,SAAS,EAAE,eAAe,EAAA,CAAG;AAEtD;;;AAGG;IACH,IAAI,GAAG,KAAK,CAAC,KAAK,4EAAI,SAAS,EAAE,gBAAgB,EAAA,CAAG;AAEpD,IAAA,QAAQ;AAER,IAAA,aAAa;IAEb,gBAAgB,GAAY,KAAK;AAEjC,IAAA,cAAc;AAEd,IAAA,oBAAoB;AAEpB,IAAA,OAAO,GAAG,QAAQ,CAAyB,OAAO;AAC9C,QAAA,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;AACjB,QAAA,UAAU,EAAE,IAAI,CAAC,UAAU,EAAE;AAC7B,QAAA,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI;KAClC,CAAC;gFAAC;IAEH,MAAM,GAAA;AACF,QAAA,IAAI,iBAAiB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE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