{"version":3,"sources":["webpack:///./node_modules/gvue/src/assets/js/directives/vue-parallax-js.js"],"names":["Parallax","constructor","minWidth","this","items","itemsInVp","active","getActive","iom","IntersectionObserverManager","isLandscape","rootMargin","isPortrait","scrollEvent","move","resizeEvent","debounce","reset","window","innerWidth","add","el","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","length","unobserveItems","disableEvent","observeItems","enableEvent","removeEventListener","addEventListener","passive","centerX","prop","install","Vue","p","prototype","$parallaxjs","directive","inserted","binding"],"mappings":";+GAAA,mCAGA,MAAMA,EACFC,YAAaC,EAAW,KACpBC,KAAKC,MAAQ,GACbD,KAAKE,UAAY,GACjBF,KAAKD,SAAWA,EAChBC,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,KAAKD,UAAYgB,OAAOC,WAGnCC,IAAKC,GAAI,UAAEC,EAAF,MAAaC,IAElB,IAAKpB,KAAKI,aAAyB,IAAVgB,EACrB,OAEJF,EAAGG,MAAMC,WAAa,OACtBJ,EAAGG,MAAME,WAAa,YACtB,MAAMF,EAAQH,EAAGM,cAAgBT,OAAOU,iBAAiBP,GACnDQ,EAASP,EAAUQ,KAAOZ,OAAOa,YAAcV,EAAGW,cAAgBX,EAAGY,cAAgBZ,EAAGa,aACxFC,EAAkBd,EAAGe,aAAef,EAAGe,aAAaC,UAAY,EAGtEl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,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,IAInEX,aAAcZ,EAAM1B,GACZ0B,EAAK3B,UAAUmD,UACflD,GAAS,qBAGb,MAAMF,EAAK4B,EAAK5B,GACVqD,EAAO,YACbrD,EAAGG,MAAO,SAAQkD,KAAUnD,EAC5BF,EAAGG,MAAO,MAAKkD,KAAUnD,EACzBF,EAAGG,MAAO,KAAIkD,KAAUnD,GAIjB,cACXoD,QAAS,CAACC,GAAO1E,eACb,MAAM2E,EAAI,IAAI7E,EAASE,GAEvB0E,EAAIE,UAAUC,YAAcF,EAC5BD,EAAII,UAAU,WAAY,CACtBC,SAAU5D,EAAI6D,GACVL,EAAEzD,IAAIC,EAAI6D,GACVL,EAAE/D,OACF+D,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":""}