@shopware-ag/dive
Version:
Shopware Spatial Framework
80 lines (79 loc) • 3 kB
JavaScript
var c = Object.defineProperty;
var d = (n, o, t) => o in n ? c(n, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[o] = t;
var s = (n, o, t) => d(n, typeof o != "symbol" ? o + "" : o, t);
import { Group as l, Tween as g, Easing as f } from "@tweenjs/tween.js";
import { A as y } from "./Animator-DHnpWRt_.mjs";
class v extends y {
constructor(t, i, h) {
super();
s(this, "_group", new l());
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 = h;
const _ = Array.isArray(t) ? t : [t];
for (const r of _) {
const p = {};
for (const e of Object.keys(r.to))
p[e] = r.object[e];
this._snapshots.push({ object: r.object, values: p });
const u = new g(r.object, this._group).to(r.to, i).easing((h == null ? void 0 : h.easing) ?? f.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(u);
}
}
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 h of Object.keys(i))
t[h] = i[h];
}
dispose() {
this._tweens.forEach((t) => t.stop()), this._tweens = [], this._group.removeAll(), this._state = "idle";
}
}
export {
v as TargetAnimator
};