{"version":3,"sources":["scripts/vendor/parallax.js"],"names":["initializeParallax","clip","parallax","querySelectorAll","parallaxDetails","sticky","getComputedStyle","document","body","transform","style","fixedPos","createElement","position","top","width","height","zIndex","insertBefore","firstChild","i","length","elem","container","parentNode","overflow","warn","perspectiveElement","error","webkitOverflowScrolling","transformStyle","perspectiveOrigin","perspective","transformOrigin","previousCover","previousElementSibling","hasAttribute","nextCover","nextElementSibling","push","offsetTop","addEventListener","node","parallaxStart","offsetHeight","parallaxEnd","clientHeight","scrollTop","display","onResize","bind","details","rate","getAttribute","scrollbarWidth","offsetWidth","clientWidth","depth","scale","dx","dy","scrollHeight","window"],"mappings":";AAiBA,SAASA,EAAmBC,GACtBC,IAAAA,EAAWD,EAAKE,iBAAiB,eACjCC,EAAkB,GAClBC,GAAS,EAKoC,QAA7CC,iBAAiBC,SAASC,MAAMC,YAClCF,SAASC,KAAKE,MAAMD,UAAY,iBAC9BE,IAAAA,EAAWJ,SAASK,cAAc,OAC7BF,EAAAA,MAAMG,SAAW,QACjBH,EAAAA,MAAMI,IAAM,IACZJ,EAAAA,MAAMK,MAAQ,MACdL,EAAAA,MAAMM,OAAS,MACfN,EAAAA,MAAMO,OAAS,EACfT,SAAAA,KAAKU,aAAaP,EAAUJ,SAASC,KAAKW,YAE9C,IAAA,IAAIC,EAAI,EAAGA,EAAIlB,EAASmB,OAAQD,IAAK,CACpCE,IAAAA,EAAOpB,EAASkB,GAChBG,EAAYD,EAAKE,WACjBlB,GAAwC,WAAxCA,iBAAiBiB,GAAWE,SAA5BnB,CAIAL,GAAQsB,EAAUC,YAAcvB,GAC1ByB,QAAAA,KACN,0FACAJ,GAGArB,IAKA0B,EALA1B,EAAOsB,EAAUC,WACkB,WAAnClB,iBAAiBL,GAAMwB,UACjBG,QAAAA,MAAM,0DAA2DN,EAAMrB,GAI7EI,GAAUC,iBAAiBL,GAAM4B,yBAC1B,GAAA,EACYN,EAAAA,IAEAtB,EAAAA,EACXS,EAAAA,MAAMoB,eAAiB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GAAGI,WAAWL,YAI5E,SAAS8B,EAASE,GACX,IAAA,IAAI/B,EAAI,EAAGA,EAAI+B,EAAQ9B,OAAQD,IAAK,CACnCG,IAAAA,EAAY4B,EAAQ/B,GAAGsB,KAAKlB,WAE5BvB,EAAOsB,EAAUC,WACjBU,EAAgBiB,EAAQ/B,GAAGc,cAC3BG,EAAYc,EAAQ/B,GAAGiB,UACvBe,EAAOD,EAAQ/B,GAAGsB,KAAKW,aAAa,YAEpCV,EAAgBT,EAAgBA,EAAcM,UAAYN,EAAcU,aAAe,EACvFU,EAAiBH,EAAQ/B,GAAGf,OAAS,EAAIJ,EAAKsD,YAActD,EAAKuD,YAEjExC,GADemC,EAAQ/B,GAAGf,OACjB8C,EAAQ/B,GAAGsB,KAAKE,cACzBa,EAAQ,EACRL,GAAAA,EACM,EAAA,EAAI,EAAIA,OAGR,GAACpC,GADSqB,EAAYA,EAAUG,UAAYjB,EAAUqB,cAC9BD,IAAkB3B,EAASf,EAAK6C,cAE9DK,EAAQ/B,GAAGf,SAAQoD,EAAQ,EAAMA,GAEjCC,IAAAA,EAAQ,GAAO,EAAMD,GAGrBE,EAAKL,GAAkBI,EAAQ,GAE/BE,EAAKT,EAAQ/B,GAAGf,SACdJ,EAAK4D,aAAelB,EAAgB3B,IAAW,EAAI0C,IACpDf,EAAgBc,GAASzC,EAASf,EAAK6C,eAAiBY,EAErDtC,EAAAA,GAAGsB,KAAKhC,MAAMD,UACpB,UAAY,EAAIgD,GAAS,iBAAmBE,EAAK,OAASC,EAAK,OAASH,EAAQ,OAItFK,OAAO9D,mBAAqBA","file":"parallax.c8e88645.map","sourceRoot":"../promo","sourcesContent":["/**\n * Copyright 2016 Google Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nfunction initializeParallax(clip) {\n  var parallax = clip.querySelectorAll('*[parallax]')\n  var parallaxDetails = []\n  var sticky = false\n\n  // Edge requires a transform on the document body and a fixed position element\n  // in order for it to properly render the parallax effect as you scroll.\n  // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/5084491/\n  if (getComputedStyle(document.body).transform == 'none')\n    document.body.style.transform = 'translateZ(0)'\n  var fixedPos = document.createElement('div')\n  fixedPos.style.position = 'fixed'\n  fixedPos.style.top = '0'\n  fixedPos.style.width = '1px'\n  fixedPos.style.height = '1px'\n  fixedPos.style.zIndex = 1\n  document.body.insertBefore(fixedPos, document.body.firstChild)\n\n  for (var i = 0; i < parallax.length; i++) {\n    var elem = parallax[i]\n    var container = elem.parentNode\n    if (getComputedStyle(container).overflow != 'visible') {\n      console.error('Need non-scrollable container to apply perspective for', elem)\n      continue\n    }\n    if (clip && container.parentNode != clip) {\n      console.warn(\n        'Currently we only track a single overflow clip, but elements from multiple clips found.',\n        elem\n      )\n    }\n    var clip = container.parentNode\n    if (getComputedStyle(clip).overflow == 'visible') {\n      console.error('Parent of sticky container should be scrollable element', elem, clip)\n    }\n    // TODO(flackr): optimize to not redo this for the same clip/container.\n    var perspectiveElement\n    if (sticky || getComputedStyle(clip).webkitOverflowScrolling) {\n      sticky = true\n      perspectiveElement = container\n    } else {\n      perspectiveElement = clip\n      container.style.transformStyle = 'preserve-3d'\n    }\n    perspectiveElement.style.perspectiveOrigin = 'bottom right'\n    perspectiveElement.style.perspective = '1px'\n    if (sticky) elem.style.position = '-webkit-sticky'\n    if (sticky) elem.style.top = '0'\n    elem.style.transformOrigin = 'bottom right'\n\n    // Find the previous and next elements to parallax between.\n    var previousCover = parallax[i].previousElementSibling\n    while (previousCover && previousCover.hasAttribute('parallax'))\n      previousCover = previousCover.previousElementSibling\n    var nextCover = parallax[i].nextElementSibling\n    while (nextCover && !nextCover.hasAttribute('parallax-cover'))\n      nextCover = nextCover.nextElementSibling\n\n    parallaxDetails.push({\n      node: parallax[i],\n      top: parallax[i].offsetTop,\n      sticky: !!sticky,\n      nextCover: nextCover,\n      previousCover: previousCover\n    })\n  }\n\n  // Add a scroll listener to hide perspective elements when they should no\n  // longer be visible.\n  clip.addEventListener('scroll', function() {\n    for (var i = 0; i < parallaxDetails.length; i++) {\n      var container = parallaxDetails[i].node.parentNode\n      var previousCover = parallaxDetails[i].previousCover\n      var nextCover = parallaxDetails[i].nextCover\n      var parallaxStart = previousCover ? previousCover.offsetTop + previousCover.offsetHeight : 0\n      var parallaxEnd = nextCover ? nextCover.offsetTop : container.offsetHeight\n      var threshold = 200\n      var visible =\n        parallaxStart - threshold - clip.clientHeight < clip.scrollTop &&\n        parallaxEnd + threshold > clip.scrollTop\n      // FIXME: Repainting the images while scrolling can cause jank.\n      // For now, keep them all.\n      // var display = visible ? 'block' : 'none'\n      var display = 'block'\n      if (parallaxDetails[i].node.style.display != display)\n        parallaxDetails[i].node.style.display = display\n    }\n  })\n  window.addEventListener('load', onResize.bind(null, parallaxDetails))\n  window.addEventListener('resize', onResize.bind(null, parallaxDetails))\n  onResize(parallaxDetails)\n  for (var i = 0; i < parallax.length; i++) {\n    parallax[i].parentNode.insertBefore(parallax[i], parallax[i].parentNode.firstChild)\n  }\n}\n\nfunction onResize(details) {\n  for (var i = 0; i < details.length; i++) {\n    var container = details[i].node.parentNode\n\n    var clip = container.parentNode\n    var previousCover = details[i].previousCover\n    var nextCover = details[i].nextCover\n    var rate = details[i].node.getAttribute('parallax')\n\n    var parallaxStart = previousCover ? previousCover.offsetTop + previousCover.offsetHeight : 0\n    var scrollbarWidth = details[i].sticky ? 0 : clip.offsetWidth - clip.clientWidth\n    var parallaxElem = details[i].sticky ? container : clip\n    var height = details[i].node.offsetHeight\n    var depth = 0\n    if (rate) {\n      depth = 1 - 1 / rate\n    } else {\n      var parallaxEnd = nextCover ? nextCover.offsetTop : container.offsetHeight\n      depth = (height - parallaxEnd + parallaxStart) / (height - clip.clientHeight)\n    }\n    if (details[i].sticky) depth = 1.0 / depth\n\n    var scale = 1.0 / (1.0 - depth)\n\n    // The scrollbar is included in the 'bottom right' perspective origin.\n    var dx = scrollbarWidth * (scale - 1)\n    // Offset for the position within the container.\n    var dy = details[i].sticky\n      ? -(clip.scrollHeight - parallaxStart - height) * (1 - scale)\n      : (parallaxStart - depth * (height - clip.clientHeight)) * scale\n\n    details[i].node.style.transform =\n      'scale(' + (1 - depth) + ') translate3d(' + dx + 'px, ' + dy + 'px, ' + depth + 'px)'\n  }\n}\n\nwindow.initializeParallax = initializeParallax\n"]}