import{FALSE}from"../functions.js";import PointerInteraction,{centroid as centroidFromPointers}from"./Pointer.js";class PinchZoom extends PointerInteraction{constructor(t){t=t||{};const e=t;e.stopDown||(e.stopDown=FALSE),super(e),this.anchor_=null,this.duration_=void 0!==t.duration?t.duration:400,this.lastDistance_=void 0,this.lastScaleDelta_=1}handleDragEvent(t){let e=1;var n=this.targetPointers[0],i=this.targetPointers[1],o=n.clientX-i.clientX,n=n.clientY-i.clientY,i=Math.sqrt(o*o+n*n);void 0!==this.lastDistance_&&(e=this.lastDistance_/i),this.lastDistance_=i;const s=t.map,r=s.getView();1!=e&&(this.lastScaleDelta_=e);o=s.getViewport().getBoundingClientRect();const a=centroidFromPointers(this.targetPointers);a[0]-=o.left,a[1]-=o.top,this.anchor_=s.getCoordinateFromPixel(a),s.render(),r.adjustResolution(e,this.anchor_)}handleUpEvent(t){if(this.targetPointers.length<2){const e=t.map,n=e.getView();t=1<this.lastScaleDelta_?1:-1;return n.endInteraction(this.duration_,t),!1}return!0}handleDownEvent(t){if(2<=this.targetPointers.length){const e=t.map;return this.anchor_=null,this.lastDistance_=void 0,this.lastScaleDelta_=1,this.handlingDownUpSequence||e.getView().beginInteraction(),!0}return!1}}export default PinchZoom;