/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../geometry","../../../../Viewpoint","../../../../core/Accessor","../../../../core/reactiveUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../chunks/vec2","../../../../chunks/vec2f64","../../viewpointUtils","../../../navigation/RotationMomentumEstimator","../../../navigation/ZoomMomentumEstimator","../../../../geometry/Point"],(function(t,o,i,e,n,s,a,m,r,u,h,c,l,_,p,d,M){"use strict";let v=function(o){function i(t){var i;return(i=o.call(this,t)||this)._animationTime=0,i._momentumFinished=!1,i._rotationMomentumEstimator=new p.RotationMomentumEstimator(.6,.15,.95),i._rotationDirection=1,i._zoomDirection=1,i._zoomMomentumEstimator=new d.ZoomMomentumEstimator,i._zoomOnly=null,i.zoomMomentum=null,i.rotateMomentum=null,i.viewpoint=new e({targetGeometry:new M,scale:0,rotation:0}),i.own(s.when((()=>i._momentumFinished),(()=>i.navigation.stop()))),i}t._inheritsLoose(i,o);var n=i.prototype;return n.begin=function(t,o){this.navigation.begin(),this._rotationMomentumEstimator.reset(),this._zoomMomentumEstimator.reset(),this._zoomOnly=null,this._previousAngle=this._startAngle=o.angle,this._previousRadius=this._startRadius=o.radius,this._previousCenter=o.center,this._updateTimestamp=null,t.constraints.rotationEnabled&&this.addToRotateEstimator(0,o.timestamp),this.addToZoomEstimator(o,1)},n.update=function(t,o){null===this._updateTimestamp&&(this._updateTimestamp=o.timestamp);const i=o.angle,e=o.radius,n=o.center,s=Math.abs(180*(i-this._startAngle)/Math.PI),a=Math.abs(e-this._startRadius),m=this._startRadius/e;if(this._previousRadius){const r=e/this._previousRadius;let u=180*(i-this._previousAngle)/Math.PI;this._rotationDirection=u>=0?1:-1,this._zoomDirection=r>=1?1:-1,t.constraints.rotationEnabled?(null===this._zoomOnly&&o.timestamp-this._updateTimestamp>200&&(this._zoomOnly=a-s>0),null===this._zoomOnly||this._zoomOnly?u=0:this.addToRotateEstimator(i-this._startAngle,o.timestamp)):u=0,this.addToZoomEstimator(o,m),this.navigation.setViewpoint([n.x,n.y],1/r,u,[this._previousCenter.x-n.x,n.y-this._previousCenter.y])}this._previousAngle=i,this._previousRadius=e,this._previousCenter=n},n.end=function(t){this.rotateMomentum=this._rotationMomentumEstimator.evaluateMomentum(),this.zoomMomentum=this._zoomMomentumEstimator.evaluateMomentum(),this._animationTime=0,(this.rotateMomentum||this.zoomMomentum)&&this.onAnimationUpdate(t),this.navigation.end()},n.addToRotateEstimator=function(t,o){this._rotationMomentumEstimator.add(t,.001*o)},n.addToZoomEstimator=function(t,o){this._zoomMomentumEstimator.add(o,.001*t.timestamp)},n.canZoomIn=function(t){const o=t.scale,i=t.constraints.effectiveMaxScale;return 0===i||o>i},n.canZoomOut=function(t){const o=t.scale,i=t.constraints.effectiveMinScale;return 0===i||o<i},n.onAnimationUpdate=function(t){this.navigation.animationManager.animateContinous(t.viewpoint,((o,i)=>{const e=!this.canZoomIn(t)&&this._zoomDirection>1||!this.canZoomOut(t)&&this._zoomDirection<1,n=!this.rotateMomentum||this.rotateMomentum.isFinished(this._animationTime),s=e||!this.zoomMomentum||this.zoomMomentum.isFinished(this._animationTime),a=.001*i;if(this._momentumFinished=n&&s,!this._momentumFinished){const i=this.rotateMomentum?Math.abs(this.rotateMomentum.valueDelta(this._animationTime,a))*this._rotationDirection*180/Math.PI:0;let e=this.zoomMomentum?Math.abs(this.zoomMomentum.valueDelta(this._animationTime,a)):1;const n=l.create(),s=l.create();if(this._previousCenter){c.set(n,this._previousCenter.x,this._previousCenter.y),_.getPaddingScreenTranslation(s,t.size,t.padding),c.add(n,n,s);const{constraints:a,scale:m}=t,r=m*e;e<1&&!a.canZoomInTo(r)?(e=m/a.effectiveMaxScale,this.zoomMomentum=null,this.rotateMomentum=null):e>1&&!a.canZoomOutTo(r)&&(e=m/a.effectiveMinScale,this.zoomMomentum=null,this.rotateMomentum=null),_.scaleAndRotateBy(o,t.viewpoint,e,i,n,t.size),t.constraints.constrainByGeometry(o)}}this._animationTime+=a}))},n.stopMomentumNavigation=function(){(this.rotateMomentum||this.zoomMomentum)&&(this.rotateMomentum&&(this._rotationMomentumEstimator.reset(),this.rotateMomentum=null),this.zoomMomentum&&(this._zoomMomentumEstimator.reset(),this.zoomMomentum=null),this.navigation.stop())},i}(n);o.__decorate([a.property()],v.prototype,"_momentumFinished",void 0),o.__decorate([a.property()],v.prototype,"viewpoint",void 0),o.__decorate([a.property()],v.prototype,"navigation",void 0),v=o.__decorate([h.subclass("esri.views.2d.navigation.actions.Pinch")],v);return v}));
