UNPKG

primevue

Version:

PrimeVue is an open source UI library for Vue 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 PrimeBloc

1 lines 9.66 kB
{"version":3,"file":"index.mjs","sources":["../../src/animateonscroll/BaseAnimateOnScroll.js","../../src/animateonscroll/AnimateOnScroll.js"],"sourcesContent":["import BaseDirective from '@primevue/core/basedirective';\nimport AnimateOnScrollStyle from 'primevue/animateonscroll/style';\n\nconst BaseAnimateOnScroll = BaseDirective.extend({\n style: AnimateOnScrollStyle\n});\n\nexport default BaseAnimateOnScroll;\n","import { addClass, removeClass } from '@primeuix/utils/dom';\nimport BaseAnimateOnScroll from './BaseAnimateOnScroll';\n\nconst AnimateOnScroll = BaseAnimateOnScroll.extend('animateonscroll', {\n created() {\n this.$value = this.$value || {};\n this.$el.style.opacity = this.$value.enterClass ? '0' : '';\n },\n mounted() {\n this.$el.setAttribute('data-pd-animateonscroll', true);\n\n this.bindIntersectionObserver();\n },\n unmounted() {\n this.unbindAnimationEvents();\n this.unbindIntersectionObserver();\n },\n observer: undefined,\n resetObserver: undefined,\n isObserverActive: false,\n animationState: undefined,\n animationEndListener: undefined,\n methods: {\n bindAnimationEvents() {\n if (!this.animationEndListener) {\n this.animationEndListener = () => {\n removeClass(this.$el, [this.$value.enterClass, this.$value.leaveClass]);\n !this.$modifiers.once && this.resetObserver.observe(this.$el);\n this.unbindAnimationEvents();\n };\n\n this.$el.addEventListener('animationend', this.animationEndListener);\n }\n },\n bindIntersectionObserver() {\n const { root, rootMargin, threshold = 0.5 } = this.$value;\n const options = { root, rootMargin, threshold };\n\n // States\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 }, options);\n\n setTimeout(() => this.observer.observe(this.$el), 0);\n\n // Reset\n this.resetObserver = new IntersectionObserver(\n ([entry]) => {\n if (entry.boundingClientRect.top > 0 && !entry.isIntersecting) {\n this.$el.style.opacity = this.$value.enterClass ? '0' : '';\n removeClass(this.$el, [this.$value.enterClass, this.$value.leaveClass]);\n\n this.resetObserver.unobserve(this.$el);\n }\n\n this.animationState = undefined;\n },\n { ...options, threshold: 0 }\n );\n },\n enter() {\n if (this.animationState !== 'enter' && this.$value.enterClass) {\n this.$el.style.opacity = '';\n removeClass(this.$el, this.$value.leaveClass);\n addClass(this.$el, this.$value.enterClass);\n\n this.$modifiers.once && this.unbindIntersectionObserver(this.$el);\n\n this.bindAnimationEvents();\n this.animationState = 'enter';\n }\n },\n leave() {\n if (this.animationState !== 'leave' && this.$value.leaveClass) {\n this.$el.style.opacity = this.$value.enterClass ? '0' : '';\n removeClass(this.$el, this.$value.enterClass);\n addClass(this.$el, this.$value.leaveClass);\n\n this.bindAnimationEvents();\n this.animationState = 'leave';\n }\n },\n unbindAnimationEvents() {\n if (this.animationEndListener) {\n this.$el.removeEventListener('animationend', this.animationEndListener);\n this.animationEndListener = undefined;\n }\n },\n unbindIntersectionObserver() {\n this.observer?.unobserve(this.$el);\n this.resetObserver?.unobserve(this.$el);\n this.isObserverActive = false;\n }\n }\n});\n\nexport default AnimateOnScroll;\n"],"names":["BaseAnimateOnScroll","BaseDirective","extend","style","AnimateOnScrollStyle","AnimateOnScroll","created","$value","$el","opacity","enterClass","mounted","setAttribute","bindIntersectionObserver","unmounted","unbindAnimationEvents","unbindIntersectionObserver","observer","undefined","resetObserver","isObserverActive","animationState","animationEndListener","methods","bindAnimationEvents","_this","removeClass","leaveClass","$modifiers","once","observe","addEventListener","_this2","_this$$value","root","rootMargin","_this$$value$threshol","threshold","options","IntersectionObserver","_ref","_ref2","_slicedToArray","entry","boundingClientRect","top","isIntersecting","enter","leave","setTimeout","_ref3","_ref4","unobserve","_objectSpread","addClass","removeEventListener","_this$observer","_this$resetObserver"],"mappings":";;;;AAGA,IAAMA,mBAAmB,GA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