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ED,WACEF,OAAOG,iBAAiB,SAAUvB,KAAKwB,SAASxB,KAAKyB,aAAc,KACpE,G,sBAED,SAASC,EAAMC,GACb,IAAIC,EACAC,EACJ,OAAO,WAAmB,kCAANC,EAAM,yBAANA,EAAM,gBACnBD,GAIHE,aAAaH,GACbA,EAAWI,YAAW,WAChBC,KAAKC,MAAQL,GAAWF,IAC1BD,EAAKS,MAAM,EAAML,GACjBD,EAAUI,KAAKC,MAElB,GAAEP,GAASM,KAAKC,MAAQL,MATzBH,EAAKS,MAAMnC,KAAM8B,GACjBD,EAAUI,KAAKC,MAUlB,CACF,G,sBA6CD,SAAShB,GACPA,EAAGkB,UAAUC,IAAI,YAClB,G,wBAED,SAAWnB,GACTA,EAAGkB,UAAUE,OAAO,YACrB,I,mFAlFGrC,G,OAqFNsC,SAASC,iBAAiB,+BAA+BC,SAAQ,SAACvC,GAChE,IAAID,EAAmBC,EACxB,I","sources":["webpack://octopus.public.web/webpack/universalModuleDefinition","webpack://octopus.public.web/./Assets/js/beforeAfterOctopus.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, () => {\nreturn ","class BeforeAfterOctopus {\n constructor(element) {\n this.element = element;\n this.svgBefore = element.querySelector(\"[data-before-octopus]\");\n this.svgAfter = element.querySelector(\"[data-after-octopus]\");\n this.windowHeight = window.innerHeight;\n\n this.addScrollListener();\n }\n\n addScrollListener() {\n window.addEventListener(\"scroll\", this.throttle(this.handleScroll, 100));\n }\n\n throttle(func, limit) {\n let lastFunc;\n let lastRan;\n return function (...args) {\n if (!lastRan) {\n func.apply(this, args);\n lastRan = Date.now();\n } else {\n clearTimeout(lastFunc);\n lastFunc = setTimeout(() => {\n if (Date.now() - lastRan >= limit) {\n func.apply(this, args);\n lastRan = Date.now();\n }\n }, limit - (Date.now() - lastRan));\n }\n };\n }\n\n handleScroll = () => {\n if (!this.isVisible()) {\n this.deactivateAll();\n } else {\n this.updateVisibility();\n }\n };\n\n isVisible = () => {\n const { top, bottom } = this.element.getBoundingClientRect();\n return top <= this.windowHeight && bottom >= 0;\n };\n\n updateVisibility = () => {\n const beforeHalfVisible = this.isHalfVisible(this.svgBefore);\n const afterVisible = this.isFullyVisible(this.svgAfter);\n\n if (beforeHalfVisible) {\n this.activate(this.svgBefore);\n this.deactivate(this.svgAfter);\n } else if (afterVisible) {\n this.deactivate(this.svgBefore);\n this.activate(this.svgAfter);\n } else {\n this.deactivateAll();\n }\n };\n\n isHalfVisible = (el) => {\n const { top, bottom } = el.getBoundingClientRect();\n return top <= this.windowHeight / 3 && bottom > this.windowHeight / 2;\n };\n\n isFullyVisible = (el) => {\n const { top } = el.getBoundingClientRect();\n return top < this.windowHeight / 3;\n };\n\n deactivateAll = () => {\n this.deactivate(this.svgBefore);\n this.deactivate(this.svgAfter);\n };\n\n activate(el) {\n el.classList.add(\"is-active\");\n }\n\n deactivate(el) {\n el.classList.remove(\"is-active\");\n }\n}\n\ndocument.querySelectorAll(\"[data-before-after-octopus]\").forEach((element) => {\n new BeforeAfterOctopus(element);\n});\n"],"names":["root","factory","exports","module","define","amd","a","i","this","BeforeAfterOctopus","element","isVisible","updateVisibility","deactivateAll","getBoundingClientRect","top","bottom","windowHeight","beforeHalfVisible","isHalfVisible","svgBefore","afterVisible","isFullyVisible","svgAfter","activate","deactivate","el","querySelector","window","innerHeight","addScrollListener","addEventListener","throttle","handleScroll","func","limit","lastFunc","lastRan","args","clearTimeout","setTimeout","Date","now","apply","classList","add","remove","document","querySelectorAll","forEach"],"sourceRoot":""}