pinch-zoom-element/dist/pinch-zoom-min.js

2 lines
8.6 KiB
JavaScript
Raw Normal View History

2023-01-02 14:47:21 +00:00
!function(){"use strict";!function(){class t{constructor(t){this.id=-1,this.nativePointer=t,this.pageX=t.pageX,this.pageY=t.pageY,this.clientX=t.clientX,this.clientY=t.clientY,self.Touch&&t instanceof Touch?this.id=t.identifier:e(t)&&(this.id=t.pointerId)}getCoalesced(){return"getCoalescedEvents"in this.nativePointer?this.nativePointer.getCoalescedEvents().map(e=>new t(e)):[this]}}const e=t=>self.PointerEvent&&t instanceof PointerEvent,i=()=>{};class n{constructor(t,e){this._element=t,this.startPointers=[],this.currentPointers=[];const{start:n=(()=>!0),move:s=i,end:r=i}=e;this._startCallback=n,this._moveCallback=s,this._endCallback=r,this._pointerStart=this._pointerStart.bind(this),this._touchStart=this._touchStart.bind(this),this._move=this._move.bind(this),this._triggerPointerEnd=this._triggerPointerEnd.bind(this),this._pointerEnd=this._pointerEnd.bind(this),this._touchEnd=this._touchEnd.bind(this),self.PointerEvent?this._element.addEventListener("pointerdown",this._pointerStart):(this._element.addEventListener("mousedown",this._pointerStart),this._element.addEventListener("touchstart",this._touchStart),this._element.addEventListener("touchmove",this._move),this._element.addEventListener("touchend",this._touchEnd))}_triggerPointerStart(t,e){return!!this._startCallback(t,e)&&(this.currentPointers.push(t),this.startPointers.push(t),!0)}_pointerStart(i){0===i.button&&this._triggerPointerStart(new t(i),i)&&(e(i)?(this._element.setPointerCapture(i.pointerId),this._element.addEventListener("pointermove",this._move),this._element.addEventListener("pointerup",this._pointerEnd)):(window.addEventListener("mousemove",this._move),window.addEventListener("mouseup",this._pointerEnd)))}_touchStart(e){for(const i of Array.from(e.changedTouches))this._triggerPointerStart(new t(i),e)}_move(e){const i=this.currentPointers.slice(),n="changedTouches"in e?Array.from(e.changedTouches).map(e=>new t(e)):[new t(e)],s=[];for(const t of n){const e=this.currentPointers.findIndex(e=>e.id===t.id);-1!==e&&(s.push(t),this.currentPointers[e]=t)}0!==s.length&&this._moveCallback(i,s,e)}_triggerPointerEnd(t,e){const i=this.currentPointers.findIndex(e=>e.id===t.id);return-1!==i&&(this.currentPointers.splice(i,1),this.startPointers.splice(i,1),this._endCallback(t,e),!0)}_pointerEnd(i){if(this._triggerPointerEnd(new t(i),i))if(e(i)){if(this.currentPointers.length)return;this._element.removeEventListener("pointermove",this._move),this._element.removeEventListener("pointerup",this._pointerEnd)}else window.removeEventListener("mousemove",this._move),window.removeEventListener("mouseup",this._pointerEnd)}_touchEnd(e){for(const i of Array.from(e.changedTouches))this._triggerPointerEnd(new t(i),e)}}const s="min-scale",r="allow-pan-min-scale",o="reset-to-min-scale-limit",a="reach-min-scale-strategy",h="stop-propagate-handled",l="none";function c(t,e){return e?Math.sqrt((e.clientX-t.clientX)**2+(e.clientY-t.clientY)**2):0}function g(t,e){return e?{clientX:(t.clientX+e.clientX)/2,clientY:(t.clientY+e.clientY)/2}:t}function d(t,e){return"number"==typeof t?t:t.trimRight().endsWith("%")?e*parseFloat(t)/100:parseFloat(t)}let u;function p(){return u||(u=document.createElementNS("http://www.w3.org/2000/svg","svg"))}function m(){return p().createSVGMatrix()}function _(){return p().createSVGPoint()}const f=.01,E=-1,v=-1,P=0,w=(t,e)=>Math.round(100*t)-Math.round(100*e);class b extends HTMLElement{constructor(){super(),this._transform=m(),new MutationObserver(()=>this._stageElChange()).observe(this,{childList:!0});const t=new n(this,{start:(e,i)=>{if(2===t.currentPointers.length||!this._positioningEl)return!1;const n=t.currentPointers.length+1===1;return!(n&&!this._allowPan())&&(this._maybeStopPropagate(i),n||this._maybeEmitCancel([e,...t.currentPointers])),i.preventDefault(),!0},move:(e,i,n)=>{this._onPointerMove(e,t.currentPointers,n)},end:(e,i)=>{this._onPointerEnd(e,t.currentPointers,i)}});this.addEventListener("wheel",t=>this._onWheel(t)),this.addEventListener("click",e=>this._onClick(e,t))}static get observedAttributes(){return[s]}attributeChangedCallback(t,e,i){t===s&&