{"version":3,"sources":["webpack:///./modules/sticky/sticky.js","webpack:///./modules/sticky/position_sticky_detect.js","webpack:///./modules/sticky/get_bounds.js"],"names":["eventHandler","stickyPosition","el","top","isAdded","placeholder","width","height","document","createElement","classList","add","style","createPlaceholder","checker","adding","window","scrollY","removing","position","parentNode","insertBefore","removeChild","id","getElementById","mStyle","positionStickySupport","cssText","indexOf","devices","JSON","parse","dataset","sticky","getBoundingClientRect","offsetTop","GetBounds","vpDetect","ViewportDetect","handler","setSticky","device","includes","stickyAvailable","removeEventListener","addEventListener","noSticky","getDevice","addCallback","track"],"mappings":"mIAmCMA,G,MAAe,SAACC,EAAgBC,GACpC,IAtBsBC,EAClBC,EAqBEC,EA/BkB,SAAC,GAAuB,IAArBC,EAAoB,EAApBA,MAAOC,EAAa,EAAbA,OAC5BF,EAAcG,SAASC,cAAc,OAK3C,OAJAJ,EAAYK,UAAUC,IAAI,sBAC1BN,EAAYO,MAAMN,MAAlB,UAA6BA,EAA7B,MACAD,EAAYO,MAAML,OAAlB,UAA8BA,EAA9B,MAEOF,EAyBaQ,CAAkBZ,GAEhCa,GAxBgBX,EAwBOF,EAxBPE,IAClBC,GAAU,EAEP,CACLW,OAAQ,WACN,OAAIC,OAAOC,SAAWd,IAAQC,IAC5BA,GAAU,GACH,IAIXc,SAAU,WACR,SAAIF,OAAOC,QAAUd,GAAOC,KAC1BA,GAAU,GACH,MAWb,OAAO,WACDU,EAAQC,UACVb,EAAGU,MAAMO,SAAW,QACpBjB,EAAGU,MAAMT,IAAM,MAEXD,EAAGkB,YACLlB,EAAGkB,WAAWC,aAAahB,EAAaH,IAEjCY,EAAQI,aACjBhB,EAAGU,MAAMO,SAAW,SACpBjB,EAAGU,MAAMT,IAAM,GAEXD,EAAGkB,YACLlB,EAAGkB,WAAWE,YAAYjB,OA0BnB,mBAAAkB,GACb,IAAMrB,EAAKM,SAASgB,eAAeD,GACnC,IAAKrB,EAAI,OAAO,KAEhB,IC7EMuB,ED6EAC,IC7EAD,EAFKjB,SAASC,cAAc,KAEhBG,OACXe,QAAU,gEAC6B,IAAvCF,EAAON,SAASS,QAAQ,WD4EzBC,EAAUC,KAAKC,MAAM7B,EAAG8B,QAAQC,QAEhChC,EEpFO,SAAAC,GACb,IAAKA,EAAI,MAAO,CAAEC,IAAK,EAAGI,OAAQ,EAAGD,MAAO,GADzB,MAEOJ,EAAGgC,wBAArB3B,EAFW,EAEXA,OAAQD,EAFG,EAEHA,MAChB,MAAO,CAAEH,IAAKD,EAAGiC,UAAW5B,SAAQD,SFiFb8B,CAAUlC,GAC3BmC,EAAWC,MACXC,EAAUvC,EAAaC,EAAgBC,GAEvCsC,EAAYd,EA/BI,SAACxB,EAAI2B,GAAL,OAAiB,SAAAY,GACnCZ,EAAQa,SAASD,IACnBvC,EAAGU,MAAQ,+DACXV,EAAGU,MAAMT,IAAM,MAEfD,EAAGU,MAAMO,SAAW,SACpBjB,EAAGU,MAAMT,IAAM,KAyByBwC,CAAgBzC,EAAI2B,GArB/C,SAAC3B,EAAI2B,EAASU,GAAd,OAA0B,SAAAE,GACzCzB,OAAO4B,oBAAoB,SAAUL,GACjCV,EAAQa,SAASD,GACnBzB,OAAO6B,iBAAiB,SAAUN,IAElCrC,EAAGU,MAAMO,SAAW,SACpBjB,EAAGU,MAAMT,IAAM,KAewD2C,CAAS5C,EAAI2B,EAASU,GAE/FC,EAAUH,EAASU,aAEnBV,EAASW,YAAYR,GAErBH,EAASY","file":"sticky-e80c2597.chunk.js","sourcesContent":["import ViewportDetect from '@djforth/viewport-detection-fp';\nimport GetBounds from './get_bounds';\n\nimport positionStickyDetect from './position_sticky_detect';\n\nconst createPlaceholder = ({ width, height }) => {\n const placeholder = document.createElement('div');\n placeholder.classList.add('sticky-placeholder');\n placeholder.style.width = `${width}px`;\n placeholder.style.height = `${height}px`;\n\n return placeholder;\n};\n\nconst changeSticky = ({ top }) => {\n let isAdded = false;\n\n return {\n adding: () => {\n if (window.scrollY >= top && !isAdded) {\n isAdded = true;\n return true;\n }\n return false;\n },\n removing: () => {\n if (window.scrollY < top && isAdded) {\n isAdded = false;\n return true;\n }\n return false;\n },\n };\n};\n\nconst eventHandler = (stickyPosition, el) => {\n const placeholder = createPlaceholder(stickyPosition);\n\n const checker = changeSticky(stickyPosition);\n return () => {\n if (checker.adding()) {\n el.style.position = 'fixed';\n el.style.top = '0px';\n\n if (el.parentNode) {\n el.parentNode.insertBefore(placeholder, el);\n }\n } else if (checker.removing()) {\n el.style.position = 'static';\n el.style.top = '';\n\n if (el.parentNode) {\n el.parentNode.removeChild(placeholder);\n }\n }\n };\n};\n\nconst stickyAvailable = (el, devices) => device => {\n if (devices.includes(device)) {\n el.style = 'position:sticky;position:-webkit-sticky;position:-ms-sticky;';\n el.style.top = '0';\n } else {\n el.style.position = 'static';\n el.style.top = '';\n }\n};\n\nconst noSticky = (el, devices, handler) => device => {\n window.removeEventListener('scroll', handler);\n if (devices.includes(device)) {\n window.addEventListener('scroll', handler);\n } else {\n el.style.position = 'static';\n el.style.top = '';\n }\n};\n\nexport default id => {\n const el = document.getElementById(id);\n if (!el) return null;\n\n const positionStickySupport = positionStickyDetect();\n const devices = JSON.parse(el.dataset.sticky);\n\n const stickyPosition = GetBounds(el);\n const vpDetect = ViewportDetect();\n const handler = eventHandler(stickyPosition, el);\n\n const setSticky = positionStickySupport ? stickyAvailable(el, devices) : noSticky(el, devices, handler);\n\n setSticky(vpDetect.getDevice());\n\n vpDetect.addCallback(setSticky);\n\n vpDetect.track();\n};\n","// @flow\n\nexport default () => {\n const el = document.createElement('a');\n\n const mStyle = el.style;\n mStyle.cssText = 'position:sticky;position:-webkit-sticky;position:-ms-sticky;';\n return mStyle.position.indexOf('sticky') !== -1;\n};\n","// @flow\nexport default el => {\n if (!el) return { top: 0, height: 0, width: 0 };\n const { height, width } = el.getBoundingClientRect();\n return { top: el.offsetTop, height, width };\n};\n"],"sourceRoot":""}