/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import{isSome as e}from"../../core/maybe.js";import{watch as t}from"../../core/reactiveUtils.js";import{addFrameTask as a}from"../../core/scheduling.js";class s{constructor(t){this.view=t,this._frameTaskHandle=null,this._updateRequested=!1,this.stationary=!0,this.animationInProgress=!1,this.prepare=()=>{this._updateParameters.state=this.view.state,this._updateParameters.stationary=this.view.stationary,this._updateParameters.pixelRatio=window.devicePixelRatio,this._updateParameters.renderingOptions=this.view.renderingOptions},this.update=()=>{this._updateRequested=!1;const{basemapView:t,graphicsView:a,labelManager:s,layerViews:i,state:{id:r}}=this.view;t.baseLayerViews.forEach(this._updateLayerView,this),i.forEach(this._updateLayerView,this),t.referenceLayerViews.forEach(this._updateLayerView,this),e(s)&&(s.lastUpdateId!==r&&(s.viewChange(),s.lastUpdateId=r),s.updateRequested&&s.processUpdate(this._updateParameters)),e(a)&&(a.lastUpdateId!==r&&(a.viewChange(),a.lastUpdateId=r),a.updateRequested&&a.processUpdate(this._updateParameters)),this.view.graphicsTileStore.setViewState(this._updateParameters.state),this.animationInProgress||this._updateRequested||this._frameTaskHandle.pause()}}destroy(){this.stop()}start(){if(this._frameTaskHandle)return;const e=this.view;this.stationary=e.stationary,this._updateParameters={state:e.state,pixelRatio:window.devicePixelRatio,stationary:this.stationary,renderingOptions:e.renderingOptions},this._stationaryHandle=t((()=>e.stationary),(e=>{this.stationary=e,this.requestFrame()})),this._frameTaskHandle=a(this),this.requestUpdate()}stop(){this._frameTaskHandle&&(this._updateRequested=!1,this._stationaryHandle.remove(),this._frameTaskHandle.remove(),this._updateParameters=this._stationaryHandle=this._frameTaskHandle=null,this.stationary=!0,this.animationInProgress=!1)}requestUpdate(){this._updateRequested||(this._updateRequested=!0,this.requestFrame())}requestFrame(){this._frameTaskHandle&&this._frameTaskHandle.resume()}_updateLayerView(e){const t=this.view.state,a=e.lastUpdateId;null!=a&&(this.stationary||e.moving)||(e.moving=!0,e.moveStart()),a!==t.id&&e.viewChange(),this.stationary&&e.moving&&(e.moving=!1,e.moveEnd()),e.lastUpdateId=t.id,e.updateRequested&&e.processUpdate(this._updateParameters),"layerViews"in e&&e.layerViews.forEach(this._updateLayerView,this)}}export{s as default};