UNPKG

@shopware-ag/dive

Version:

Shopware Spatial Framework

2 lines (1 loc) 2.42 kB
"use strict";var l=Object.defineProperty;var d=(r,o,t)=>o in r?l(r,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[o]=t;var s=(r,o,t)=>d(r,typeof o!="symbol"?o+"":o,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("@tweenjs/tween.js"),g=require("./Animator-YDE8aFEd.cjs");class y extends g.Animator{constructor(t,i,n){super();s(this,"_group",new p.Group);s(this,"_tweens",[]);s(this,"_snapshots",[]);s(this,"_state","idle");s(this,"_duration");s(this,"_loop","once");s(this,"_options");s(this,"_completedCount",0);this._duration=i,this._options=n;const u=Array.isArray(t)?t:[t];for(const h of u){const _={};for(const e of Object.keys(h.to))_[e]=h.object[e];this._snapshots.push({object:h.object,values:_});const c=new p.Tween(h.object,this._group).to(h.to,i).easing((n==null?void 0:n.easing)??p.Easing.Quadratic.Out).onUpdate(()=>{var e,a;(a=(e=this._options)==null?void 0:e.onUpdate)==null||a.call(e),this.dispatchEvent({type:"update",target:this})}).onComplete(()=>{var e,a;this._completedCount++,this._completedCount>=this._tweens.length&&(this._state="idle",(a=(e=this._options)==null?void 0:e.onComplete)==null||a.call(e),this.dispatchEvent({type:"complete",target:this}))});this._tweens.push(c)}}get state(){return this._state}get duration(){return this._duration}get loop(){return this._loop}set loop(t){this._loop=t,this._tweens.forEach(i=>{i.repeat(t==="once"?0:1/0),i.yoyo(t==="pingpong")})}get time(){return this._tweens.length>0?this._tweens[0].getDuration():0}set time(t){}play(){return this._tweens.forEach(t=>t.stop()),this._state="playing",this._completedCount=0,this._restoreSnapshots(),this._tweens.forEach(t=>t.start()),this.dispatchEvent({type:"play",target:this}),this}pause(){return this._state="paused",this._tweens.forEach(t=>t.pause()),this.dispatchEvent({type:"pause",target:this}),this}resume(){return this._state="playing",this._tweens.forEach(t=>t.resume()),this.dispatchEvent({type:"resume",target:this}),this}stop(){return this._state="idle",this._tweens.forEach(t=>t.stop()),this._restoreSnapshots(),this.dispatchEvent({type:"stop",target:this}),this}update(){this._state!=="idle"&&this._group.update()}_restoreSnapshots(){for(const{object:t,values:i}of this._snapshots)for(const n of Object.keys(i))t[n]=i[n]}dispose(){this._tweens.forEach(t=>t.stop()),this._tweens=[],this._group.removeAll(),this._state="idle"}}exports.TargetAnimator=y;