UNPKG

@allincart-ag/dive

Version:

Allincart Spatial Framework

2 lines (1 loc) 2.96 kB
"use strict";var u=Object.defineProperty;var h=(n,e,t)=>e in n?u(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var a=(n,e,t)=>h(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("@tweenjs/tween.js"),c=require("../../chunks/MathUtils-CBW56ZuG.cjs");function _(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const d=_(f);class g{addEventListener(e,t){this._listeners===void 0&&(this._listeners={});const s=this._listeners;s[e]===void 0&&(s[e]=[]),s[e].indexOf(t)===-1&&s[e].push(t)}hasEventListener(e,t){if(this._listeners===void 0)return!1;const s=this._listeners;return s[e]!==void 0&&s[e].indexOf(t)!==-1}removeEventListener(e,t){if(this._listeners===void 0)return;const r=this._listeners[e];if(r!==void 0){const i=r.indexOf(t);i!==-1&&r.splice(i,1)}}dispatchEvent(e){if(this._listeners===void 0)return;const s=this._listeners[e.type];if(s!==void 0){e.target=this;const r=s.slice(0);for(let i=0,l=r.length;i<l;i++)r[i].call(this,e);e.target=null}}}class p extends g{constructor(t,s,r,i){super();a(this,"_uuid",c.MathUtils.generateUUID());a(this,"_playing",!1);a(this,"_stopped",!1);a(this,"_completed",!1);this.object=t,this.to=s,this.duration=r,this.options=i}get uuid(){return this._uuid}get playing(){return this._playing}get stopped(){return this._stopped}get completed(){return this._completed}dispose(){this._playing=!1,this._stopped=!1,this._completed=!1}play(){return this._playing=!0,this._stopped=!1,this.dispatchEvent({type:"play",target:this}),this}stop(){return this._playing=!1,this._stopped=!0,this.dispatchEvent({type:"stop",target:this}),this}}class E{constructor(){a(this,"uuid",c.MathUtils.generateUUID());a(this,"TWEEN",d);a(this,"_callbackMap",new Map);a(this,"_tweens",new Map)}animate(e,t,s,r){var l,o;const i=new p(e,t,s,r);return this._callbackMap.set(i.uuid,{onUpdate:((l=i.options)==null?void 0:l.onUpdate)??(()=>{}),onComplete:((o=i.options)==null?void 0:o.onComplete)??(()=>{})}),this._createTween(i),i}remove(e){if(!this._callbackMap.has(e)){console.warn(`Animator with uuid ${e} not found`);return}this._callbackMap.delete(e),this._tweens.delete(e)}dispose(){this._callbackMap.clear(),this._tweens.clear()}tick(){this.TWEEN.update()}_createTween(e){var s;const t=new this.TWEEN.Tween(e.object).to(e.to,e.duration).easing(((s=e.options)==null?void 0:s.easing)??this.TWEEN.Easing.Quadratic.Out).onUpdate((r,i)=>{var l;(l=this._callbackMap.get(e.uuid))==null||l.onUpdate(r,i)}).onComplete(r=>{var i;(i=this._callbackMap.get(e.uuid))==null||i.onComplete(r)});e.addEventListener("play",()=>{t.start()}),e.addEventListener("stop",()=>{t.stop()}),this._tweens.set(e.uuid,t)}}exports.TWEEN=d;exports.AnimationSystem=E;exports.Animator=p;