Files
2024-07-15 11:28:08 +02:00

5 lines
18 KiB
JavaScript

/*!
* PEP v0.4.3 | https://github.com/jquery/PEP
* Copyright jQuery Foundation and other contributors | http://jquery.org/license
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.PointerEventsPolyfill=e()}(this,function(){"use strict";function r(t,e){e=e||Object.create(null);var n=document.createEvent("Event");n.initEvent(t,e.bubbles||!1,e.cancelable||!1);for(var i,r=2;r<c.length;r++)n[i=c[r]]=e[i]||l[r];n.buttons=e.buttons||0;var o;return o=e.pressure&&n.buttons?e.pressure:n.buttons?.5:0,n.x=n.clientX,n.y=n.clientY,n.pointerId=e.pointerId||0,n.width=e.width||0,n.height=e.height||0,n.pressure=o,n.tiltX=e.tiltX||0,n.tiltY=e.tiltY||0,n.twist=e.twist||0,n.tangentialPressure=e.tangentialPressure||0,n.pointerType=e.pointerType||"",n.hwTimestamp=e.hwTimestamp||0,n.isPrimary=e.isPrimary||!1,n}function t(){this.array=[],this.size=0}function e(t,e,n,i){this.addCallback=t.bind(i),this.removeCallback=e.bind(i),this.changedCallback=n.bind(i),w&&(this.observer=new w(this.mutationWatcher.bind(this)))}function n(t){return"body /shadow-deep/ "+i(t)}function i(t){return'[touch-action="'+t+'"]'}function o(t){return"{ -ms-touch-action: "+t+"; touch-action: "+t+"; }"}function a(t){if(!m.pointermap.has(t)){var e=new Error("InvalidPointerId");throw e.name="InvalidPointerId",e}}function s(t){for(var e=t.parentNode;e&&e!==t.ownerDocument;)e=e.parentNode;if(!e){var n=new Error("InvalidStateError");throw n.name="InvalidStateError",n}}function u(t){return 0!==m.pointermap.get(t).buttons}var c=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","pageX","pageY"],l=[!1,!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0],h=window.Map&&window.Map.prototype.forEach?Map:t,p=["bubbles","cancelable","view","detail","screenX","screenY","clientX","clientY","ctrlKey","altKey","shiftKey","metaKey","button","relatedTarget","buttons","pointerId","width","height","pressure","tiltX","tiltY","pointerType","hwTimestamp","isPrimary","type","target","currentTarget","which","pageX","pageY","timeStamp"],d=[!(t.prototype={set:function(t,e){return void 0===e?this.delete(t):(this.has(t)||this.size++,void(this.array[t]=e))},has:function(t){return void 0!==this.array[t]},delete:function(t){this.has(t)&&(delete this.array[t],this.size--)},get:function(t){return this.array[t]},clear:function(){this.array.length=0,this.size=0},forEach:function(n,i){return this.array.forEach(function(t,e){n.call(i,t,e,this)},this)}}),!1,null,null,0,0,0,0,!1,!1,!1,!1,0,null,0,0,0,0,0,0,0,"",0,!1,"",null,null,0,0,0,0],v={pointerover:1,pointerout:1,pointerenter:1,pointerleave:1},f="undefined"!=typeof SVGElementInstance,m={pointermap:new h,eventMap:Object.create(null),captureInfo:Object.create(null),eventSources:Object.create(null),eventSourceList:[],registerSource:function(t,e){var n=e,i=n.events;i&&(i.forEach(function(t){n[t]&&(this.eventMap[t]=n[t].bind(n))},this),this.eventSources[t]=n,this.eventSourceList.push(n))},register:function(t){for(var e,n=this.eventSourceList.length,i=0;i<n&&(e=this.eventSourceList[i]);i++)e.register.call(e,t)},unregister:function(t){for(var e,n=this.eventSourceList.length,i=0;i<n&&(e=this.eventSourceList[i]);i++)e.unregister.call(e,t)},contains:function(t,e){try{return t.contains(e)}catch(t){return!1}},down:function(t){t.bubbles=!0,this.fireEvent("pointerdown",t)},move:function(t){t.bubbles=!0,this.fireEvent("pointermove",t)},up:function(t){t.bubbles=!0,this.fireEvent("pointerup",t)},enter:function(t){t.bubbles=!1,this.fireEvent("pointerenter",t)},leave:function(t){t.bubbles=!1,this.fireEvent("pointerleave",t)},over:function(t){t.bubbles=!0,this.fireEvent("pointerover",t)},out:function(t){t.bubbles=!0,this.fireEvent("pointerout",t)},cancel:function(t){t.bubbles=!0,this.fireEvent("pointercancel",t)},leaveOut:function(t){this.out(t),this.propagate(t,this.leave,!1)},enterOver:function(t){this.over(t),this.propagate(t,this.enter,!0)},eventHandler:function(t){if(!t._handledByPE){var e=t.type,n=this.eventMap&&this.eventMap[e];n&&n(t),t._handledByPE=!0}},listen:function(e,t){t.forEach(function(t){this.addEvent(e,t)},this)},unlisten:function(e,t){t.forEach(function(t){this.removeEvent(e,t)},this)},addEvent:function(t,e){t.addEventListener(e,this.boundHandler)},removeEvent:function(t,e){t.removeEventListener(e,this.boundHandler)},makeEvent:function(t,e){this.captureInfo[e.pointerId]&&(e.relatedTarget=null);var n=new r(t,e);return e.preventDefault&&(n.preventDefault=e.preventDefault),n._target=n._target||e.target,n},fireEvent:function(t,e){var n=this.makeEvent(t,e);return this.dispatchEvent(n)},cloneEvent:function(t){for(var e,n=Object.create(null),i=0;i<p.length;i++)n[e=p[i]]=t[e]||d[i],!f||"target"!==e&&"relatedTarget"!==e||n[e]instanceof SVGElementInstance&&(n[e]=n[e].correspondingUseElement);return t.preventDefault&&(n.preventDefault=function(){t.preventDefault()}),n},getTarget:function(t){var e=this.captureInfo[t.pointerId];return e?t._target!==e&&t.type in v?void 0:e:t._target},propagate:function(e,n,t){for(var i=e.target,r=[];i!==document&&!i.contains(e.relatedTarget);)if(r.push(i),!(i=i.parentNode))return;t&&r.reverse(),r.forEach(function(t){e.target=t,n.call(this,e)},this)},setCapture:function(t,e,n){this.captureInfo[t]&&this.releaseCapture(t,n),this.captureInfo[t]=e,this.implicitRelease=this.releaseCapture.bind(this,t,n),document.addEventListener("pointerup",this.implicitRelease),document.addEventListener("pointercancel",this.implicitRelease);var i=new r("gotpointercapture");i.pointerId=t,i._target=e,n||this.asyncDispatchEvent(i)},releaseCapture:function(t,e){var n=this.captureInfo[t];if(n){this.captureInfo[t]=void 0,document.removeEventListener("pointerup",this.implicitRelease),document.removeEventListener("pointercancel",this.implicitRelease);var i=new r("lostpointercapture");i.pointerId=t,i._target=n,e||this.asyncDispatchEvent(i)}},dispatchEvent:function(t){var e=this.getTarget(t);if(e)return e.dispatchEvent(t)},asyncDispatchEvent:function(t){requestAnimationFrame(this.dispatchEvent.bind(this,t))}};m.boundHandler=m.eventHandler.bind(m);var E={shadow:function(t){if(t)return t.shadowRoot||t.webkitShadowRoot},canTarget:function(t){return t&&Boolean(t.elementFromPoint)},targetingShadow:function(t){var e=this.shadow(t);if(this.canTarget(e))return e},olderShadow:function(t){var e=t.olderShadowRoot;if(!e){var n=t.querySelector("shadow");n&&(e=n.olderShadowRoot)}return e},allShadows:function(t){for(var e=[],n=this.shadow(t);n;)e.push(n),n=this.olderShadow(n);return e},searchRoot:function(t,e,n){if(t){var i,r,o=t.elementFromPoint(e,n);for(r=this.targetingShadow(o);r;){if(i=r.elementFromPoint(e,n)){var a=this.targetingShadow(i);return this.searchRoot(a,e,n)||i}r=this.olderShadow(r)}return o}},owner:function(t){for(var e=t;e.parentNode;)e=e.parentNode;return e.nodeType!==Node.DOCUMENT_NODE&&e.nodeType!==Node.DOCUMENT_FRAGMENT_NODE&&(e=document),e},findTarget:function(t){var e=t.clientX,n=t.clientY,i=this.owner(t.target);return i.elementFromPoint(e,n)||(i=document),this.searchRoot(i,e,n)}},b=Array.prototype.forEach.call.bind(Array.prototype.forEach),T=Array.prototype.map.call.bind(Array.prototype.map),y=Array.prototype.slice.call.bind(Array.prototype.slice),g=Array.prototype.filter.call.bind(Array.prototype.filter),w=window.MutationObserver||window.WebKitMutationObserver,P={subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["touch-action"]};e.prototype={watchSubtree:function(t){this.observer&&E.canTarget(t)&&this.observer.observe(t,P)},enableOnSubtree:function(t){this.watchSubtree(t),t===document&&"complete"!==document.readyState?this.installOnLoad():this.installNewSubtree(t)},installNewSubtree:function(t){b(this.findElements(t),this.addElement,this)},findElements:function(t){return t.querySelectorAll?t.querySelectorAll("[touch-action]"):[]},removeElement:function(t){this.removeCallback(t)},addElement:function(t){this.addCallback(t)},elementChanged:function(t,e){this.changedCallback(t,e)},concatLists:function(t,e){return t.concat(y(e))},installOnLoad:function(){document.addEventListener("readystatechange",function(){"complete"===document.readyState&&this.installNewSubtree(document)}.bind(this))},isElement:function(t){return t.nodeType===Node.ELEMENT_NODE},flattenMutationTree:function(t){var e=T(t,this.findElements,this);return e.push(g(t,this.isElement)),e.reduce(this.concatLists,[])},mutationWatcher:function(t){t.forEach(this.mutationHandler,this)},mutationHandler:function(t){"childList"===t.type?(this.flattenMutationTree(t.addedNodes).forEach(this.addElement,this),this.flattenMutationTree(t.removedNodes).forEach(this.removeElement,this)):"attributes"===t.type&&this.elementChanged(t.target,t.oldValue)}};var S=["none","auto","pan-x","pan-y",{rule:"pan-x pan-y",selectors:["pan-x pan-y","pan-y pan-x"]}],O="",I=window.PointerEvent||window.MSPointerEvent,M=!window.ShadowDOMPolyfill&&document.head.createShadowRoot,C=m.pointermap,R=[1,4,2,8,16],Y=!1;try{Y=1===new MouseEvent("test",{buttons:1}).buttons}catch(t){}var N,_={POINTER_ID:1,POINTER_TYPE:"mouse",events:["mousedown","mousemove","mouseup","mouseover","mouseout"],register:function(t){m.listen(t,this.events)},unregister:function(t){m.unlisten(t,this.events)},lastTouches:[],isEventSimulatedFromTouch:function(t){for(var e,n=this.lastTouches,i=t.clientX,r=t.clientY,o=0,a=n.length;o<a&&(e=n[o]);o++){var s=Math.abs(i-e.x),u=Math.abs(r-e.y);if(s<=25&&u<=25)return!0}},prepareEvent:function(t){var e=m.cloneEvent(t),n=e.preventDefault;return e.preventDefault=function(){t.preventDefault(),n()},e.pointerId=this.POINTER_ID,e.isPrimary=!0,e.pointerType=this.POINTER_TYPE,e},prepareButtonsForMove:function(t,e){var n=C.get(this.POINTER_ID);0!==e.which&&n?t.buttons=n.buttons:t.buttons=0,e.buttons=t.buttons},mousedown:function(t){if(!this.isEventSimulatedFromTouch(t)){var e=C.get(this.POINTER_ID),n=this.prepareEvent(t);Y||(n.buttons=R[n.button],e&&(n.buttons|=e.buttons),t.buttons=n.buttons),C.set(this.POINTER_ID,t),e&&0!==e.buttons?m.move(n):m.down(n)}},mousemove:function(t){if(!this.isEventSimulatedFromTouch(t)){var e=this.prepareEvent(t);Y||this.prepareButtonsForMove(e,t),e.button=-1,C.set(this.POINTER_ID,t),m.move(e)}},mouseup:function(t){if(!this.isEventSimulatedFromTouch(t)){var e=C.get(this.POINTER_ID),n=this.prepareEvent(t);if(!Y){var i=R[n.button];n.buttons=e?e.buttons&~i:0,t.buttons=n.buttons}C.set(this.POINTER_ID,t),n.buttons&=~R[n.button],0===n.buttons?m.up(n):m.move(n)}},mouseover:function(t){if(!this.isEventSimulatedFromTouch(t)){var e=this.prepareEvent(t);Y||this.prepareButtonsForMove(e,t),e.button=-1,C.set(this.POINTER_ID,t),m.enterOver(e)}},mouseout:function(t){if(!this.isEventSimulatedFromTouch(t)){var e=this.prepareEvent(t);Y||this.prepareButtonsForMove(e,t),e.button=-1,m.leaveOut(e)}},cancel:function(t){var e=this.prepareEvent(t);m.cancel(e),this.deactivateMouse()},deactivateMouse:function(){C.delete(this.POINTER_ID)}},D=m.captureInfo,L=E.findTarget.bind(E),X=E.allShadows.bind(E),k=m.pointermap,A="touch-action",F={events:["touchstart","touchmove","touchend","touchcancel"],register:function(t){N.enableOnSubtree(t)},unregister:function(){},elementAdded:function(t){var e=t.getAttribute(A),n=this.touchActionToScrollType(e);n&&(t._scrollType=n,m.listen(t,this.events),X(t).forEach(function(t){t._scrollType=n,m.listen(t,this.events)},this))},elementRemoved:function(t){t._scrollType=void 0,m.unlisten(t,this.events),X(t).forEach(function(t){t._scrollType=void 0,m.unlisten(t,this.events)},this)},elementChanged:function(t,e){var n=t.getAttribute(A),i=this.touchActionToScrollType(n),r=this.touchActionToScrollType(e);i&&r?(t._scrollType=i,X(t).forEach(function(t){t._scrollType=i},this)):r?this.elementRemoved(t):i&&this.elementAdded(t)},scrollTypes:{EMITTER:"none",XSCROLLER:"pan-x",YSCROLLER:"pan-y",SCROLLER:/^(?:pan-x pan-y)|(?:pan-y pan-x)|auto$/},touchActionToScrollType:function(t){var e=t,n=this.scrollTypes;return"none"===e?"none":e===n.XSCROLLER?"X":e===n.YSCROLLER?"Y":n.SCROLLER.exec(e)?"XY":void 0},POINTER_TYPE:"touch",firstTouch:null,isPrimaryTouch:function(t){return this.firstTouch===t.identifier},setPrimaryTouch:function(t){(0===k.size||1===k.size&&k.has(1))&&(this.firstTouch=t.identifier,this.firstXY={X:t.clientX,Y:t.clientY},this.scrolling=!1,this.cancelResetClickCount())},removePrimaryPointer:function(t){t.isPrimary&&(this.firstTouch=null,this.firstXY=null,this.resetClickCount())},clickCount:0,resetId:null,resetClickCount:function(){var t=function(){this.clickCount=0,this.resetId=null}.bind(this);this.resetId=setTimeout(t,200)},cancelResetClickCount:function(){this.resetId&&clearTimeout(this.resetId)},typeToButtons:function(t){var e=0;return"touchstart"!==t&&"touchmove"!==t||(e=1),e},touchToPointer:function(t){var e=this.currentTouchEvent,n=m.cloneEvent(t),i=n.pointerId=t.identifier+2;n.target=D[i]||L(n),n.bubbles=!0,n.cancelable=!0,n.detail=this.clickCount,n.button=0,n.buttons=this.typeToButtons(e.type),n.width=2*(t.radiusX||t.webkitRadiusX||0),n.height=2*(t.radiusY||t.webkitRadiusY||0),n.pressure=t.force||t.webkitForce||.5,n.isPrimary=this.isPrimaryTouch(t),n.pointerType=this.POINTER_TYPE,n.altKey=e.altKey,n.ctrlKey=e.ctrlKey,n.metaKey=e.metaKey,n.shiftKey=e.shiftKey;var r=this;return n.preventDefault=function(){r.scrolling=!1,r.firstXY=null,e.preventDefault()},n},processTouches:function(t,e){var n=t.changedTouches;this.currentTouchEvent=t;for(var i,r=0;r<n.length;r++)i=n[r],e.call(this,this.touchToPointer(i))},shouldScroll:function(t){if(this.firstXY){var e,n=t.currentTarget._scrollType;if("none"===n)e=!1;else if("XY"===n)e=!0;else{var i=t.changedTouches[0],r=n,o="Y"===n?"X":"Y",a=Math.abs(i["client"+r]-this.firstXY[r]);e=Math.abs(i["client"+o]-this.firstXY[o])<=a}return this.firstXY=null,e}},findTouch:function(t,e){for(var n,i=0,r=t.length;i<r&&(n=t[i]);i++)if(n.identifier===e)return!0},vacuumTouches:function(t){var i=t.touches;if(k.size>=i.length){var r=[];k.forEach(function(t,e){if(1!==e&&!this.findTouch(i,e-2)){var n=t.out;r.push(n)}},this),r.forEach(this.cancelOut,this)}},touchstart:function(t){this.vacuumTouches(t),this.setPrimaryTouch(t.changedTouches[0]),this.dedupSynthMouse(t),this.scrolling||(this.clickCount++,this.processTouches(t,this.overDown))},overDown:function(t){k.set(t.pointerId,{target:t.target,out:t,outTarget:t.target}),m.enterOver(t),m.down(t)},touchmove:function(t){this.scrolling||(this.shouldScroll(t)?(this.scrolling=!0,this.touchcancel(t)):(t.preventDefault(),this.processTouches(t,this.moveOverOut)))},moveOverOut:function(t){var e=t,n=k.get(e.pointerId);if(n){var i=n.out,r=n.outTarget;m.move(e),i&&r!==e.target&&(i.relatedTarget=e.target,e.relatedTarget=r,i.target=r,e.target?(m.leaveOut(i),m.enterOver(e)):(e.target=r,e.relatedTarget=null,this.cancelOut(e))),n.out=e,n.outTarget=e.target}},touchend:function(t){this.dedupSynthMouse(t),this.processTouches(t,this.upOut)},upOut:function(t){this.scrolling||(m.up(t),m.leaveOut(t)),this.cleanUpPointer(t)},touchcancel:function(t){this.processTouches(t,this.cancelOut)},cancelOut:function(t){m.cancel(t),m.leaveOut(t),this.cleanUpPointer(t)},cleanUpPointer:function(t){k.delete(t.pointerId),this.removePrimaryPointer(t)},dedupSynthMouse:function(t){var e=_.lastTouches,n=t.changedTouches[0];if(this.isPrimaryTouch(n)){var i={x:n.clientX,y:n.clientY};e.push(i);var r=function(t,e){var n=t.indexOf(e);-1<n&&t.splice(n,1)}.bind(null,e,i);setTimeout(r,2500)}}};N=new e(F.elementAdded,F.elementRemoved,F.elementChanged,F);var x,K,j,B=m.pointermap,U=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,z={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(t){m.listen(t,this.events)},unregister:function(t){m.unlisten(t,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(t){var e=t;return U&&((e=m.cloneEvent(t)).pointerType=this.POINTER_TYPES[t.pointerType]),e},cleanup:function(t){B.delete(t)},MSPointerDown:function(t){B.set(t.pointerId,t);var e=this.prepareEvent(t);m.down(e)},MSPointerMove:function(t){var e=this.prepareEvent(t);m.move(e)},MSPointerUp:function(t){var e=this.prepareEvent(t);m.up(e),this.cleanup(t.pointerId)},MSPointerOut:function(t){var e=this.prepareEvent(t);m.leaveOut(e)},MSPointerOver:function(t){var e=this.prepareEvent(t);m.enterOver(e)},MSPointerCancel:function(t){var e=this.prepareEvent(t);m.cancel(e),this.cleanup(t.pointerId)},MSLostPointerCapture:function(t){var e=m.makeEvent("lostpointercapture",t);m.dispatchEvent(e)},MSGotPointerCapture:function(t){var e=m.makeEvent("gotpointercapture",t);m.dispatchEvent(e)}},H=window.navigator;return K=H.msPointerEnabled?(x=function(t){a(t),s(this),u(t)&&(m.setCapture(t,this,!0),this.msSetPointerCapture(t))},function(t){a(t),m.releaseCapture(t,!0),this.msReleasePointerCapture(t)}):(x=function(t){a(t),s(this),u(t)&&m.setCapture(t,this)},function(t){a(t),m.releaseCapture(t)}),j=function(t){return!!m.captureInfo[t]},function(){if(I){S.forEach(function(t){String(t)===t?(O+=i(t)+o(t)+"\n",M&&(O+=n(t)+o(t)+"\n")):(O+=t.selectors.map(i)+o(t.rule)+"\n",M&&(O+=t.selectors.map(n)+o(t.rule)+"\n"))});var t=document.createElement("style");t.textContent=O,document.head.appendChild(t)}}(),function(){if(!window.PointerEvent){if(window.PointerEvent=r,window.navigator.msPointerEnabled){var t=window.navigator.msMaxTouchPoints;Object.defineProperty(window.navigator,"maxTouchPoints",{value:t,enumerable:!0}),m.registerSource("ms",z)}else Object.defineProperty(window.navigator,"maxTouchPoints",{value:0,enumerable:!0}),m.registerSource("mouse",_),void 0!==window.ontouchstart&&m.registerSource("touch",F);m.register(document)}}(),window.Element&&!Element.prototype.setPointerCapture&&Object.defineProperties(Element.prototype,{setPointerCapture:{value:x},releasePointerCapture:{value:K},hasPointerCapture:{value:j}}),{dispatcher:m,Installer:e,PointerEvent:r,PointerMap:h,targetFinding:E}});