"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports.SimilarAnimation=exports.BaseAnimation=exports.AnimationEventType=void 0,exports.createAnimationFromSimilarAnimation=createAnimationFromSimilarAnimation,exports.createAnimationFromTween=createAnimationFromTween,exports.createAnimationFromTweenGroup=createAnimationFromTweenGroup;var _eventEmitter=_interopRequireDefault(require("../common/event-emitter")),_util=require("../common/util"),_executer=require("./executer");let AnimationEventType=exports.AnimationEventType=function(a){return a.complete="complete",a.start="start",a.update="update",a.resume="resume",a.stop="stop",a.pause="pause",a}({});class BaseAnimation extends _eventEmitter.default{constructor(){super(),this.uuid=void 0,this.type="animation",this.poor=!1,this.uuid=(0,_util.createUUid)();let a=a=>this.update(a),b=()=>{(0,_executer.removeRender)(a)};this.addEventListener(AnimationEventType.stop,b),this.addEventListener(AnimationEventType.complete,b),this.addEventListener(AnimationEventType.pause,b),this.addEventListener(AnimationEventType.start,()=>{(0,_executer.onRender)(a)})}}exports.BaseAnimation=BaseAnimation;class SimilarAnimation extends BaseAnimation{constructor(a){super(),this.handler=void 0,this.poor=!0,this.handler=a}pause(){return this.handler.pause&&this.handler.pause.call(this),this.emit(AnimationEventType.pause),this}resume(){return this.handler.resume&&this.handler.resume.call(this),this.emit(AnimationEventType.resume),this}start(){const a=this.handler.start.call(this);return this.emit(AnimationEventType.start),a&&this.emit(AnimationEventType.complete),this}stop(){return this.handler.stop&&this.handler.stop.call(this),this.emit(AnimationEventType.stop),this}update(a){return this.handler.update&&this.handler.update.call(this,a),this.emit(AnimationEventType.update),this}}exports.SimilarAnimation=SimilarAnimation;function createAnimationFromSimilarAnimation(a){return new SimilarAnimation(a)}class TweenAnimation extends BaseAnimation{constructor(a){super(),this.tween=void 0,this.tween=a,this.tween.onStop(()=>{this.emit(AnimationEventType.stop)}).onComplete(()=>{this.emit(AnimationEventType.complete)})}pause(a){return this.tween.pause(a),this.emit(AnimationEventType.pause),this}resume(a){return this.tween.resume(a),this.emit(AnimationEventType.resume),this}start(){return this.tween.start(),this.emit(AnimationEventType.start),this}stop(){return this.tween.stop(),this}update(a){return this.tween.update(a),this.emit(AnimationEventType.update),this}}function createAnimationFromTween(a){return new TweenAnimation(a)}class TweenGroupAnimation extends BaseAnimation{constructor(a){super(),this.group=void 0,this.groupedTweens=void 0,this.groupLength=void 0,this.completeSum=void 0,this.startSum=void 0,this.stopSum=void 0,this.group=a,this.groupedTweens=this.group.getAll(),this.groupLength=this.group.getAll().length,this.completeSum=0,this.startSum=0,this.stopSum=0,this.onCallbacks()}onCallbacks(){this.groupedTweens.forEach(a=>{a.onComplete(()=>{this.completeSum+=1,this.completeSum===this.groupLength&&(this.emit(AnimationEventType.complete),this.completeSum=0)}).onStop(()=>{this.stopSum+=1,this.stopSum===this.groupLength&&(this.emit(AnimationEventType.stop),this.stopSum=0)})})}pause(){return this.groupedTweens.forEach(a=>{a.pause()}),this.emit(AnimationEventType.pause),this}resume(a){return this.groupedTweens.forEach(b=>{b.resume(a)}),this.emit(AnimationEventType.resume),this}start(){return this.groupedTweens.forEach(a=>a.start()),this.emit(AnimationEventType.start),this}stop(){return this.groupedTweens.forEach(a=>a.stop()),this}update(a){return this.group.update(a),this.emit(AnimationEventType.update),this}}function createAnimationFromTweenGroup(a){return new TweenGroupAnimation(a)}