/*
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/scheduling","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../ViewAnimation","./unitBezier","./viewpointUtils","../../geometry/Point"],(function(t,i,e,s,n,o,a,r,h,p,c,u,d,l,m){"use strict";let y=function(){function t(t,i,e,s){const n=t.targetGeometry,o=i.targetGeometry;s?"string"==typeof s&&(s=d.parse(s)||d.easingFunctions.ease):s=d.easingFunctions.ease,this.easing=s,this.duration=e,this.sCenterX=n.x,this.sCenterY=n.y,this.sScale=t.scale,this.sRotation=t.rotation,this.tCenterX=o.x,this.tCenterY=o.y,this.tScale=i.scale,this.tRotation=i.rotation,this.dCenterX=this.tCenterX-this.sCenterX,this.dCenterY=this.tCenterY-this.sCenterY,this.dScale=this.tScale-this.sScale,this.dRotation=this.tRotation-this.sRotation,this.dRotation>180?this.dRotation-=360:this.dRotation<-180&&(this.dRotation+=360)}return t.prototype.applyRatio=function(t,i){const e=this.easing(i);let s,n,o,a;i>=1?(s=this.tCenterX,n=this.tCenterY,o=this.tRotation,a=this.tScale):(s=this.sCenterX+e*this.dCenterX,n=this.sCenterY+e*this.dCenterY,o=this.sRotation+e*this.dRotation,a=this.sScale+e*this.dScale),t.targetGeometry.x=s,t.targetGeometry.y=n,t.scale=a,t.rotation=o},t}(),w=function(i){function e(e){var n;return(n=i.call(this,e)||this).duration=200,n.transition=null,n.easing=d.easingFunctions.ease,n.view=null,n.viewpoint=null,n.viewpoint=new s({targetGeometry:new m,scale:0,rotation:0}),n._updateTask=o.addFrameTask({postRender:n._postRender.bind(t._assertThisInitialized(n))}),n._updateTask.pause(),n}t._inheritsLoose(e,i);var n=e.prototype;return n.destroy=function(){this._updateTask.remove(),this._updateTask=null},n.animate=function(t,i,e){this.stop();const s=this.viewpoint;l.copy(s,i),this.transition=new y(this.viewpoint,t.target,e&&e.duration||this.duration,e&&e.easing||this.easing);const n=()=>{this.animation===t&&this._updateTask&&("finished"===t.state&&(this.transition.applyRatio(this.viewpoint,1),this.view.state&&(this.view.state.viewpoint=this.viewpoint.clone())),this.animation=null,this.updateFunction=null)};return t.when(n,n),this._startTime=performance.now(),this._updateTask.resume(),this.animation=t,t},n.animateContinous=function(t,i){this.stop(),this.updateFunction=i,this.viewpoint=t;const e=new u({target:t.clone()}),s=()=>{this.animation===e&&this._updateTask&&(this.animation=null,this.updateFunction=null)};return e.when(s,s),this._startTime=performance.now(),this._updateTask.resume(),this.animation=e,e},n.stop=function(){this.animation&&(this.animation.stop(),this.animation=null,this.updateFunction=null)},n._postRender=function(t){const i=this.animation;if(i&&i.state!==u.State.STOPPED){if(this.updateFunction)this.updateFunction(this.viewpoint,t.deltaTime);else{const t=(performance.now()-this._startTime)/this.transition.duration,i=t>=1;this.transition.applyRatio(this.viewpoint,t),i&&this.animation.finish()}this.view.state&&(this.view.state.viewpoint=this.viewpoint.clone())}else this._updateTask.pause()},e}(n);i.__decorate([a.property()],w.prototype,"animation",void 0),i.__decorate([a.property()],w.prototype,"duration",void 0),i.__decorate([a.property()],w.prototype,"transition",void 0),i.__decorate([a.property()],w.prototype,"easing",void 0),i.__decorate([a.property()],w.prototype,"view",void 0),i.__decorate([a.property()],w.prototype,"viewpoint",void 0),w=i.__decorate([c.subclass("esri.views.2d.AnimationManager")],w);return w}));
