{"version":3,"sources":["webpack:///./node_modules/gvue/src/assets/js/directives/vue-parallax-js.js"],"names":["Parallax","constructor","minWidth","arguments","length","undefined","this","items","itemsInVp","active","getActive","iom","IntersectionObserverManager","isLandscape","rootMargin","isPortrait","scrollEvent","move","resizeEvent","debounce","reset","window","innerWidth","add","el","_ref","modifiers","value","style","transition","willChange","currentStyle","getComputedStyle","height","absY","innerHeight","clientHeight","offsetHeight","scrollHeight","offsetTopParent","offsetParent","offsetTop","push","initialOffsetTop","parseInt","marginTop","addItem","element","onViewportEnter","parallaxItem","onViewportOut","unparallaxItem","find","item","filter","requestAnimationFrame","windowHeight","windowSize","scrollY","pageYOffset","map","elH","offset","pos","toFixed","setTransform","enableParallax","disableParallax","enable","unobserveItems","disableEvent","observeItems","enableEvent","removeEventListener","addEventListener","passive","centerX","prop","install","Vue","_ref2","p","prototype","$parallaxjs","directive","inserted","binding"],"mappings":";+GAAA,mCAGA,MAAMA,EACFC,cAA6B,IAAhBC,EAAQC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,IACpBG,KAAKC,MAAQ,GACbD,KAAKE,UAAY,GACjBF,KAAKJ,SAAWA,EAChBI,KAAKG,OAASH,KAAKI,YACnBJ,KAAKK,IAAM,IAAIC,OAA4B,CACvCC,YAAa,CACTC,WAAY,YAEhBC,WAAY,CACRD,WAAY,cAIpBR,KAAKU,YAAc,KACfV,KAAKW,QAETX,KAAKY,YAAcC,eAAS,KACxBb,KAAKc,QACLd,KAAKW,QACN,KAGPP,YACI,OAAOJ,KAAKJ,UAAYmB,OAAOC,WAGnCC,IAAKC,EAAEC,GAAwB,IAApBC,EAASD,EAATC,UAAWC,EAAKF,EAALE,MAElB,IAAKrB,KAAKI,aAAyB,IAAViB,EACrB,OAEJH,EAAGI,MAAMC,WAAa,OACtBL,EAAGI,MAAME,WAAa,YACtB,MAAMF,EAAQJ,EAAGO,cAAgBV,OAAOW,iBAAiBR,GACnDS,EAASP,EAAUQ,KAAOb,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ACI7D,KAAKE,UAAY,GACjBF,KAAKK,IAAI0D,iBACT/D,KAAKgE,eAGTJ,iBACI5D,KAAKK,IAAI4D,eACTjE,KAAKkE,cAGTF,eACIjD,OAAOoD,oBAAoB,SAAUnE,KAAKU,aAC1CK,OAAOoD,oBAAoB,SAAUnE,KAAKY,aAG9CsD,cACInD,OAAOqD,iBAAiB,SAAUpE,KAAKU,YAAa,CAAE2D,SAAS,IAC/DtD,OAAOqD,iBAAiB,SAAUpE,KAAKY,YAAa,CAAEyD,SAAS,IAInEV,aAAcZ,EAAM1B,GACZ0B,EAAK3B,UAAUkD,UACfjD,GAAS,qBAGb,MAAMH,EAAK6B,EAAK7B,GACVqD,EAAO,YACbrD,EAAGI,MAAO,SAAQiD,GAAUlD,EAC5BH,EAAGI,MAAO,MAAKiD,GAAUlD,EACzBH,EAAGI,MAAO,KAAIiD,GAAUlD,GAIjB,cACXmD,QAASA,CAACC,EAAGC,KAAmB,IAAf9E,EAAQ8E,EAAR9E,SACb,MAAM+E,EAAI,IAAIjF,EAASE,GAEvB6E,EAAIG,UAAUC,YAAcF,EAC5BF,EAAIK,UAAU,WAAY,CACtBC,SAAU7D,EAAI8D,GACVL,EAAE1D,IAAIC,EAAI8D,GACVL,EAAEhE,OACFgE,EAAEb","file":"js/VueParallaxJs.js","sourcesContent":["import IntersectionObserverManager from 'nespresso-library/src/utils/IntersectionObserverManager'\nimport debounce from 'nespresso-library/src/utils/debounce'\n\nclass Parallax {\n    constructor (minWidth = 767) {\n        this.items = [] // Items to apply parallax\n        this.itemsInVp = [] // Items in viewport to parallax\n        this.minWidth = minWidth // Screen width to activate the parallax\n        this.active = this.getActive() // Enable/Disable parallax\n        this.iom = new IntersectionObserverManager({\n            isLandscape: {\n                rootMargin: '200% 0px'\n            },\n            isPortrait: {\n                rootMargin: '200% 0px'\n            }\n        })\n\n        this.scrollEvent = () => {\n            this.move()\n        }\n        this.resizeEvent = debounce(() => {\n            this.reset()\n            this.move()\n        }, 500)\n    }\n\n    getActive () {\n        return this.minWidth <= window.innerWidth\n    }\n\n    add (el, { modifiers, value }) {\n        // Exclude element with no speed\n        if (!this.getActive() || value === 0) {\n            return\n        }\n        el.style.transition = 'none'\n        el.style.willChange = 'transform'\n        const style = el.currentStyle || window.getComputedStyle(el)\n        const height = modifiers.absY ? window.innerHeight : el.clientHeight || el.offsetHeight || el.scrollHeight\n        const offsetTopParent = el.offsetParent ? el.offsetParent.offsetTop : 0\n\n        // Add element in general array with all calcul\n        this.items.push({\n            el: el,\n            initialOffsetTop: el.offsetTop + offsetTopParent - parseInt(style.marginTop, 10),\n            style: style,\n            modifiers: modifiers,\n            value: value,\n            clientHeight: height\n        })\n\n        // Observe element\n        this.iom.addItem({\n            element: el,\n            onViewportEnter: () => {\n                this.parallaxItem(el)\n            },\n            onViewportOut: () => {\n                this.unparallaxItem(el)\n            }\n        })\n    }\n\n    parallaxItem (el) {\n        this.itemsInVp.push(this.items.find(item => item.el === el))\n    }\n\n    unparallaxItem (el) {\n        this.itemsInVp = this.itemsInVp.filter(item => item.el !== el)\n    }\n\n    move () {\n        requestAnimationFrame(() => {\n            const windowHeight = window.innerHeight\n            const windowSize = (window.scrollY || window.pageYOffset) + windowHeight\n\n            this.itemsInVp.map((item) => {\n                const elH = item.clientHeight\n                let offset = item.initialOffsetTop\n                let pos = windowSize\n                pos = pos - elH / 2\n                pos = pos - windowHeight / 2\n                pos = pos * item.value\n\n                offset = item.initialOffsetTop\n                offset = offset * -1\n                offset = offset * item.value\n                pos = pos + offset\n\n                pos = pos.toFixed(2)\n\n                this.setTransform(item, `translateY(${pos}px)`)\n            })\n        })\n    }\n\n    // Remove all transformations\n    reset () {\n        this.active = this.getActive()\n        if (!this.active) {\n            this.disableParallax()\n        } else {\n            this.enableParallax()\n        }\n        requestAnimationFrame(() => {\n            this.items.map(item => {\n                item.el.style = item.style\n            })\n        })\n    }\n\n    enable () {\n        if (this.items.length === 0) {\n            return\n        }\n\n        this.enableParallax()\n    }\n\n    disableParallax () {\n        this.itemsInVp = []\n        this.iom.unobserveItems()\n        this.disableEvent()\n    }\n\n    enableParallax () {\n        this.iom.observeItems()\n        this.enableEvent()\n    }\n\n    disableEvent () {\n        window.removeEventListener('scroll', this.scrollEvent)\n        window.removeEventListener('resize', this.resizeEvent)\n    }\n\n    enableEvent () {\n        window.addEventListener('scroll', this.scrollEvent, { passive: true })\n        window.addEventListener('resize', this.resizeEvent, { passive: true })\n    }\n\n    // Apply style on item\n    setTransform (item, value) {\n        if (item.modifiers.centerX) {\n            value += ' translateX(-50%)'\n        }\n\n        const el = item.el\n        const prop = 'Transform'\n        el.style[`webkit${prop}`] = value\n        el.style[`moz${prop}`] = value\n        el.style[`ms${prop}`] = value\n    }\n}\n\nexport default {\n    install: (Vue, { minWidth }) => {\n        const p = new Parallax(minWidth)\n\n        Vue.prototype.$parallaxjs = p\n        Vue.directive('parallax', {\n            inserted (el, binding) {\n                p.add(el, binding)\n                p.move()\n                p.enable()\n            }\n        })\n    }\n}\n"],"sourceRoot":""}