UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.18 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{makeHandle as t}from"../../../../../core/handleUtils.js";import{Milliseconds as e}from"../../../../../core/time.js";import{AnimatedSymbolRepeatType as r}from"../../../../../symbols/cim/enums.js";import{getRandomValue as i}from"../grouping.js";function a(t){return e(t.frameDurations.reduce(((t,e)=>t+e),0))}function n(t){const{width:e,height:r}=t,i=t.frameDurations.reverse(),a=e=>{const r=t.frameDurations.length-1-e;return t.getFrame(r)};return{frameCount:t.frameCount,duration:t.duration,frameDurations:i,getFrame:a,width:e,height:r}}function o(t,r){const{width:i,height:a,getFrame:n}=t,o=r/t.duration,s=t.frameDurations.map((t=>e(t*o)));return{frameCount:t.frameCount,duration:t.duration,frameDurations:s,getFrame:n,width:i,height:a}}function s(t,r){const{width:i,height:a,getFrame:n}=t,o=t.frameDurations.slice(),s=o.shift();return o.unshift(e(s+r)),{frameCount:t.frameCount,duration:t.duration+r,frameDurations:o,getFrame:n,width:i,height:a}}function m(t,r){const{width:i,height:a,getFrame:n}=t,o=t.frameDurations.slice(),s=o.pop();return o.push(e(s+r)),{frameCount:t.frameCount,duration:t.duration+r,frameDurations:o,getFrame:n,width:i,height:a}}class u{constructor(t,e,r,i){this._animation=t,this._repeatType=r,this._onFrameData=i,this._direction=1,this._currentFrame=0,this.timeToFrame=this._animation.frameDurations[this._currentFrame];let a=0;for(;e>a;)a+=this.timeToFrame,this.nextFrame();const n=this._animation.getFrame(this._currentFrame);this._onFrameData(n)}nextFrame(){if(this._currentFrame+=this._direction,this._direction>0){if(this._currentFrame===this._animation.frameDurations.length)switch(this._repeatType){case r.None:this._currentFrame-=this._direction;break;case r.Loop:this._currentFrame=0;break;case r.Oscillate:this._currentFrame-=this._direction,this._direction=-1}}else if(-1===this._currentFrame)switch(this._repeatType){case r.None:this._currentFrame-=this._direction;break;case r.Loop:this._currentFrame=this._animation.frameDurations.length-1;break;case r.Oscillate:this._currentFrame-=this._direction,this._direction=1}this.timeToFrame=this._animation.frameDurations[this._currentFrame];const t=this._animation.getFrame(this._currentFrame);this._onFrameData(t)}}function h(t,h,c,f){let l,{repeatType:d}=h;if(null==d&&(d=r.Loop),!0===h.reverseAnimation&&(t=n(t)),null!=h.duration&&(t=o(t,e(1e3*h.duration))),null!=h.repeatDelay){const i=1e3*h.repeatDelay;d===r.Loop?t=m(t,e(i)):d===r.Oscillate&&(t=s(m(t,e(i/2)),e(i/2)))}if(null!=h.startTimeOffset)l=e(1e3*h.startTimeOffset);else if(null!=h.randomizeStartTime){const r=82749913,n=null!=h.randomizeStartSeed?h.randomizeStartSeed:r,o=i(c,n);l=e(o*a(t))}else l=e(0);return new u(t,l,d,f)}function c(e,r,i,a){const n=null==r.playAnimation||r.playAnimation,o=h(e,r,i,a);let s,m=o.timeToFrame;function u(){s=n?setTimeout((()=>{o.nextFrame(),m=o.timeToFrame,u()}),m):void 0}return u(),t((()=>n&&clearTimeout(s)))}export{u as Player,o as adjustDuration,m as appendDelay,h as createPlayer,a as getDuration,c as play,s as prependDelay,n as reverse};