/**
@license
Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
part of the polymer project is also subject to an additional IP rights grant
found at http://polymer.github.io/PATENTS.txt
*/
import"../polymer/polymer-legacy.js";import{dom as e}from"../polymer/lib/legacy/polymer.dom.js";var l,t,o={pageX:0,pageY:0},n=null,r=[],c=["wheel","mousewheel","DOMMouseScroll","touchstart","touchmove"];export{t as currentLockingElement};export function elementIsScrollLocked(e){var l,o=t;return void 0!==o&&(!!_hasCachedLockedElement(e)||!_hasCachedUnlockedElement(e)&&((l=!!o&&o!==e&&!_composedTreeContains(o,e))?_lockedElementCache.push(e):_unlockedElementCache.push(e),l))}export function pushScrollLock(e){_lockingElements.indexOf(e)>=0||(0===_lockingElements.length&&_lockScrollInteractions(),_lockingElements.push(e),t=_lockingElements[_lockingElements.length-1],_lockedElementCache=[],_unlockedElementCache=[])}export function removeScrollLock(e){var l=_lockingElements.indexOf(e);-1!==l&&(_lockingElements.splice(l,1),t=_lockingElements[_lockingElements.length-1],_lockedElementCache=[],_unlockedElementCache=[],0===_lockingElements.length&&_unlockScrollInteractions())}export const _lockingElements=[];export let _lockedElementCache=null;export let _unlockedElementCache=null;export function _hasCachedLockedElement(e){return _lockedElementCache.indexOf(e)>-1}export function _hasCachedUnlockedElement(e){return _unlockedElementCache.indexOf(e)>-1}export function _composedTreeContains(l,t){var o,n,r,c;if(l.contains(t))return!0;for(o=e(l).querySelectorAll("content,slot"),r=0;r<o.length;++r)for(n=e(o[r]).getDistributedNodes(),c=0;c<n.length;++c)if(n[c].nodeType===Node.ELEMENT_NODE&&_composedTreeContains(n[c],t))return!0;return!1}export function _scrollInteractionHandler(e){if(e.cancelable&&_shouldPreventScrolling(e)&&e.preventDefault(),e.targetTouches){var l=e.targetTouches[0];o.pageX=l.pageX,o.pageY=l.pageY}}export{l as _boundScrollHandler};export function _lockScrollInteractions(){l=l||_scrollInteractionHandler.bind(void 0);for(var e=0,t=c.length;e<t;e++)document.addEventListener(c[e],l,{capture:!0,passive:!1})}export function _unlockScrollInteractions(){for(var e=0,t=c.length;e<t;e++)document.removeEventListener(c[e],l,{capture:!0,passive:!1})}export function _shouldPreventScrolling(l){var t=e(l).rootTarget;if("touchmove"!==l.type&&n!==t&&(n=t,r=_getScrollableNodes(e(l).path)),!r.length)return!0;if("touchstart"===l.type)return!1;var o=_getScrollInfo(l);return!_getScrollingNode(r,o.deltaX,o.deltaY)}export function _getScrollableNodes(e){for(var l=[],o=e.indexOf(t),n=0;n<=o;n++)if(e[n].nodeType===Node.ELEMENT_NODE){var r=e[n],c=r.style;"scroll"!==c.overflow&&"auto"!==c.overflow&&(c=window.getComputedStyle(r)),"scroll"!==c.overflow&&"auto"!==c.overflow||l.push(r)}return l}export function _getScrollingNode(e,l,t){if(l||t)for(var o=Math.abs(t)>=Math.abs(l),n=0;n<e.length;n++){var r=e[n];if(o?t<0?r.scrollTop>0:r.scrollTop<r.scrollHeight-r.clientHeight:l<0?r.scrollLeft>0:r.scrollLeft<r.scrollWidth-r.clientWidth)return r}}export function _getScrollInfo(e){var l={deltaX:e.deltaX,deltaY:e.deltaY};if("deltaX"in e);else if("wheelDeltaX"in e&&"wheelDeltaY"in e)l.deltaX=-e.wheelDeltaX,l.deltaY=-e.wheelDeltaY;else if("wheelDelta"in e)l.deltaX=0,l.deltaY=-e.wheelDelta;else if("axis"in e)l.deltaX=1===e.axis?e.detail:0,l.deltaY=2===e.axis?e.detail:0;else if(e.targetTouches){var t=e.targetTouches[0];l.deltaX=o.pageX-t.pageX,l.deltaY=o.pageY-t.pageY}return l}