UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

1 lines 10.5 kB
{"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,EAAE,IAAI,CAAC,IAAI;YACf,UA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