text: import"../polymer/polymer-legacy.js";import{dom}from"../polymer/lib/legacy/polymer.dom.js";var _boundScrollHandler,currentLockingElement,lastTouchPosition={pageX:0,pageY:0},lastRootTarget=null,lastScrollableNodes=[],scrollEvents=["wheel","mousewheel","DOMMouseScroll","touchstart","touchmove"];export{currentLockingElement};export function elementIsScrollLocked(element){var scrollLocked,lockingElement=currentLockingElement;return void 0!==lockingElement&&(!!_hasCachedLockedElement(element)||!_hasCachedUnlockedElement(element)&&((scrollLocked=!!lockingElement&&lockingElement!==element&&!_composedTreeContains(lockingElement,element))?_lockedElementCache.push(element):_unlockedElementCache.push(element),scrollLocked))}export function pushScrollLock(element){_lockingElements.indexOf(element)>=0||(0===_lockingElements.length&&_lockScrollInteractions(),_lockingElements.push(element),currentLockingElement=_lockingElements[_lockingElements.length-1],_lockedElementCache=[],_unlockedElementCache=[])}export function removeScrollLock(element){var index=_lockingElements.indexOf(element);-1!==index&&(_lockingElements.splice(index,1),currentLockingElement=_lockingElements[_lockingElements.length-1],_lockedElementCache=[],_unlockedElementCache=[],0===_lockingElements.length&&_unlockScrollInteractions())}export const _lockingElements=[];export let _lockedElementCache=null;export let _unlockedElementCache=null;export function _hasCachedLockedElement(element){return _lockedElementCache.indexOf(element)>-1}export function _hasCachedUnlockedElement(element){return _unlockedElementCache.indexOf(element)>-1}export function _composedTreeContains(element,child){var contentElements,distributedNodes,contentIndex,nodeIndex;if(element.contains(child))return!0;for(contentElements=dom(element).querySelectorAll("content,slot"),contentIndex=0;contentIndex<contentElements.length;++contentIndex)for(distributedNodes=dom(contentElements[contentIndex]).getDistributedNodes(),nodeIndex=0;nodeIndex<distributedNodes.length;++nodeIndex)if(distributedNodes[nodeIndex].nodeType===Node.ELEMENT_NODE&&_composedTreeContains(distributedNodes[nodeIndex],child))return!0;return!1}export function _scrollInteractionHandler(event){if(event.cancelable&&_shouldPreventScrolling(event)&&event.preventDefault(),event.targetTouches){var touch=event.targetTouches[0];lastTouchPosition.pageX=touch.pageX,lastTouchPosition.pageY=touch.pageY}}export{_boundScrollHandler};export function _lockScrollInteractions(){_boundScrollHandler=_boundScrollHandler||_scrollInteractionHandler.bind(void 0);for(var i=0,l=scrollEvents.length;i<l;i++)document.addEventListener(scrollEvents[i],_boundScrollHandler,{capture:!0,passive:!1})}export function _unlockScrollInteractions(){for(var i=0,l=scrollEvents.length;i<l;i++)document.removeEventListener(scrollEvents[i],_boundScrollHandler,{capture:!0,passive:!1})}export function _shouldPreventScrolling(event){var target=dom(event).rootTarget;if("touchmove"!==event.type&&lastRootTarget!==target&&(lastRootTarget=target,lastScrollableNodes=_getScrollableNodes(dom(event).path)),!lastScrollableNodes.length)return!0;if("touchstart"===event.type)return!1;var info=_getScrollInfo(event);return!_getScrollingNode(lastScrollableNodes,info.deltaX,info.deltaY)}export function _getScrollableNodes(nodes){for(var scrollables=[],lockingIndex=nodes.indexOf(currentLockingElement),i=0;i<=lockingIndex;i++)if(nodes[i].nodeType===Node.ELEMENT_NODE){var node=nodes[i],style=node.style;"scroll"!==style.overflow&&"auto"!==style.overflow&&(style=window.getComputedStyle(node)),"scroll"!==style.overflow&&"auto"!==style.overflow||scrollables.push(node)}return scrollables}export function _getScrollingNode(nodes,deltaX,deltaY){if(deltaX||deltaY)for(var verticalScroll=Math.abs(deltaY)>=Math.abs(deltaX),i=0;i<nodes.length;i++){var node=nodes[i];if(verticalScroll?deltaY<0?node.scrollTop>0:node.scrollTop<node.scrollHeight-node.clientHeight:deltaX<0?node.scrollLeft>0:node.scrollLeft<node.scrollWidth-node.clientWidth)return node}}export function _getScrollInfo(event){var info={deltaX:event.deltaX,deltaY:event.deltaY};if("deltaX"in event);else if("wheelDeltaX"in event&&"wheelDeltaY"in event)info.deltaX=-event.wheelDeltaX,info.deltaY=-event.wheelDeltaY;else if("wheelDelta"in event)info.deltaX=0,info.deltaY=-event.wheelDelta;else if("axis"in event)info.deltaX=1===event.axis?event.detail:0,info.deltaY=2===event.axis?event.detail:0;else if(event.targetTouches){var touch=event.targetTouches[0];info.deltaX=lastTouchPosition.pageX-touch.pageX,info.deltaY=lastTouchPosition.pageY-touch.pageY}return info}