UNPKG

oh-my-live2d

Version:

live2d component for web. 看板娘组件, 支持 model2、model3、model4

1,321 lines 52 kB
import { E as k, u as G, M as C, T as ot, P as nt, C as at, O as lt, a as D } from "./oml2d.app.js"; var w = Math.pow, c = (i, t, e) => new Promise((s, r) => { var o = (l) => { try { a(e.next(l)); } catch (h) { r(h); } }, n = (l) => { try { a(e.throw(l)); } catch (h) { r(h); } }, a = (l) => l.done ? s(l.value) : Promise.resolve(l.value).then(o, n); a((e = e.apply(i, t)).next()); }); const j = 2, V = 2; var S; ((i) => { i.supportMoreMaskDivisions = !0, i.setOpacityFromMotion = !1; })(S || (S = {})); var v; ((i) => { i.LOG_LEVEL_VERBOSE = 0, i.LOG_LEVEL_WARNING = 1, i.LOG_LEVEL_ERROR = 2, i.LOG_LEVEL_NONE = 999, i.logLevel = i.LOG_LEVEL_WARNING, i.sound = !0, i.motionSync = !0, i.motionFadingDuration = 500, i.idleMotionFadingDuration = 2e3, i.expressionFadingDuration = 500, i.preserveExpressionOnMotion = !0, i.cubism4 = S; })(v || (v = {})); const Nt = "0.4.0", d = { log(i, ...t) { v.logLevel <= v.LOG_LEVEL_VERBOSE && console.log(`[${i}]`, ...t); }, warn(i, ...t) { v.logLevel <= v.LOG_LEVEL_WARNING && console.warn(`[${i}]`, ...t); }, error(i, ...t) { v.logLevel <= v.LOG_LEVEL_ERROR && console.error(`[${i}]`, ...t); } }; function O(i, t, e) { return i < t ? t : i > e ? e : i; } function ht(i, t) { return Math.random() * (t - i) + i; } function I(i, t, e, s, r) { const o = t[s]; o !== null && typeof o === i && (e[r] = o); } function b(i, t, e, s, r) { const o = t[s]; Array.isArray(o) && (e[r] = o.filter((n) => n !== null && typeof n === i)); } function dt(i, t) { t.forEach((e) => { Object.getOwnPropertyNames(e.prototype).forEach((s) => { s !== "constructor" && Object.defineProperty(i.prototype, s, Object.getOwnPropertyDescriptor(e.prototype, s)); }); }); } function ut(i) { let t = i.lastIndexOf("/"); return t != -1 && (i = i.slice(0, t)), t = i.lastIndexOf("/"), t !== -1 && (i = i.slice(t + 1)), i; } function ct(i, t) { const e = i.indexOf(t); e !== -1 && i.splice(e, 1); } class Z extends k { constructor(t, e) { super(), this.expressions = [], this.reserveExpressionIndex = -1, this.destroyed = !1, this.settings = t, this.tag = `ExpressionManager(${t.name})`; } init() { this.defaultExpression = this.createExpression({}, void 0), this.currentExpression = this.defaultExpression, this.stopAllExpressions(); } loadExpression(t) { return c(this, null, function* () { if (!this.definitions[t]) { d.warn(this.tag, `Undefined expression at [${t}]`); return; } if (this.expressions[t] === null) { d.warn(this.tag, `Cannot set expression at [${t}] because it's already failed in loading.`); return; } if (this.expressions[t]) return this.expressions[t]; const e = yield this._loadExpression(t); return this.expressions[t] = e, e; }); } _loadExpression(t) { throw new Error("Not implemented."); } setRandomExpression() { return c(this, null, function* () { if (this.definitions.length) { const t = []; for (let e = 0; e < this.definitions.length; e++) this.expressions[e] !== null && this.expressions[e] !== this.currentExpression && e !== this.reserveExpressionIndex && t.push(e); if (t.length) { const e = Math.floor(Math.random() * t.length); return this.setExpression(e); } } return !1; }); } resetExpression() { this._setExpression(this.defaultExpression); } restoreExpression() { this._setExpression(this.currentExpression); } setExpression(t) { return c(this, null, function* () { if (typeof t != "number" && (t = this.getExpressionIndex(t)), !(t > -1 && t < this.definitions.length) || t === this.expressions.indexOf(this.currentExpression)) return !1; this.reserveExpressionIndex = t; const e = yield this.loadExpression(t); return !e || this.reserveExpressionIndex !== t ? !1 : (this.reserveExpressionIndex = -1, this.currentExpression = e, this._setExpression(e), !0); }); } update(t, e) { return this.isFinished() ? !1 : this.updateParameters(t, e); } destroy() { this.destroyed = !0, this.emit("destroy"); const t = this; t.definitions = void 0, t.expressions = void 0; } } const W = 0.01, ft = 40 / 7.5, pt = 1 / (0.15 * 1e3); class mt { constructor() { this.targetX = 0, this.targetY = 0, this.x = 0, this.y = 0, this.vx = 0, this.vy = 0; } focus(t, e, s = !1) { this.targetX = O(t, -1, 1), this.targetY = O(e, -1, 1), s && (this.x = this.targetX, this.y = this.targetY); } update(t) { const e = this.targetX - this.x, s = this.targetY - this.y; if (Math.abs(e) < W && Math.abs(s) < W) return; const r = Math.sqrt(w(e, 2) + w(s, 2)), o = ft / (1e3 / t); let n = o * (e / r) - this.vx, a = o * (s / r) - this.vy; const l = Math.sqrt(w(n, 2) + w(a, 2)), h = o * pt * t; l > h && (n *= h / l, a *= h / l), this.vx += n, this.vy += a; const u = Math.sqrt(w(this.vx, 2) + w(this.vy, 2)), p = 0.5 * (Math.sqrt(w(h, 2) + 8 * h * r) - h); u > p && (this.vx *= p / u, this.vy *= p / u), this.x += this.vx, this.y += this.vy; } } class N { constructor(t) { this.json = t; let e = t.url; if (typeof e != "string") throw new TypeError("The `url` field in settings JSON must be defined as a string."); this.url = e, this.name = ut(this.url); } resolveURL(t) { return G.resolve(this.url, t); } replaceFiles(t) { this.moc = t(this.moc, "moc"), this.pose !== void 0 && (this.pose = t(this.pose, "pose")), this.physics !== void 0 && (this.physics = t(this.physics, "physics")); for (let e = 0; e < this.textures.length; e++) this.textures[e] = t(this.textures[e], `textures[${e}]`); } getDefinedFiles() { const t = []; return this.replaceFiles((e) => (t.push(e), e)), t; } validateFiles(t) { const e = (o, n) => { const a = this.resolveURL(o); if (!t.includes(a)) { if (n) throw new Error(`File "${o}" is defined in settings, but doesn't exist in given files`); return !1; } return !0; }; return [this.moc, ...this.textures].forEach((o) => e(o, !0)), this.getDefinedFiles().filter((o) => e(o, !1)); } } var U = /* @__PURE__ */ ((i) => (i[i.NONE = 0] = "NONE", i[i.IDLE = 1] = "IDLE", i[i.NORMAL = 2] = "NORMAL", i[i.FORCE = 3] = "FORCE", i))(U || {}); class gt { constructor() { this.debug = !1, this.currentPriority = 0, this.reservePriority = 0; } reserve(t, e, s) { if (s <= 0) return d.log(this.tag, "Cannot start a motion with MotionPriority.NONE."), !1; if (t === this.currentGroup && e === this.currentIndex) return d.log(this.tag, "Motion is already playing.", this.dump(t, e)), !1; if (t === this.reservedGroup && e === this.reservedIndex || t === this.reservedIdleGroup && e === this.reservedIdleIndex) return d.log(this.tag, "Motion is already reserved.", this.dump(t, e)), !1; if (s === 1) { if (this.currentPriority !== 0) return d.log(this.tag, "Cannot start idle motion because another motion is playing.", this.dump(t, e)), !1; if (this.reservedIdleGroup !== void 0) return d.log(this.tag, "Cannot start idle motion because another idle motion has reserved.", this.dump(t, e)), !1; this.setReservedIdle(t, e); } else { if (s < 3) { if (s <= this.currentPriority) return d.log(this.tag, "Cannot start motion because another motion is playing as an equivalent or higher priority.", this.dump(t, e)), !1; if (s <= this.reservePriority) return d.log(this.tag, "Cannot start motion because another motion has reserved as an equivalent or higher priority.", this.dump(t, e)), !1; } this.setReserved(t, e, s); } return !0; } start(t, e, s, r) { if (r === 1) { if (this.setReservedIdle(void 0, void 0), this.currentPriority !== 0) return d.log(this.tag, "Cannot start idle motion because another motion is playing.", this.dump(e, s)), !1; } else { if (e !== this.reservedGroup || s !== this.reservedIndex) return d.log(this.tag, "Cannot start motion because another motion has taken the place.", this.dump(e, s)), !1; this.setReserved(void 0, void 0, 0); } return t ? (this.setCurrent(e, s, r), !0) : !1; } complete() { this.setCurrent(void 0, void 0, 0); } setCurrent(t, e, s) { this.currentPriority = s, this.currentGroup = t, this.currentIndex = e; } setReserved(t, e, s) { this.reservePriority = s, this.reservedGroup = t, this.reservedIndex = e; } setReservedIdle(t, e) { this.reservedIdleGroup = t, this.reservedIdleIndex = e; } isActive(t, e) { return t === this.currentGroup && e === this.currentIndex || t === this.reservedGroup && e === this.reservedIndex || t === this.reservedIdleGroup && e === this.reservedIdleIndex; } reset() { this.setCurrent(void 0, void 0, 0), this.setReserved(void 0, void 0, 0), this.setReservedIdle(void 0, void 0); } shouldRequestIdleMotion() { return this.currentGroup === void 0 && this.reservedIdleGroup === void 0; } shouldOverrideExpression() { return !v.preserveExpressionOnMotion && this.currentPriority > 1; } dump(t, e) { if (this.debug) { const s = [ "currentPriority", "reservePriority", "currentGroup", "currentIndex", "reservedGroup", "reservedIndex", "reservedIdleGroup", "reservedIdleIndex" ]; return ` <Requested> group = "${t}", index = ${e} ` + s.map((r) => "[" + r + "] " + this[r]).join(` `); } return ""; } } const vt = "SoundManager", yt = 0.5; class _ { static get volume() { return this._volume; } static set volume(t) { this._volume = (t > 1 ? 1 : t < 0 ? 0 : t) || 0, this.audios.forEach((e) => e.volume = this._volume); } static add(t, e, s) { const r = new Audio(t); return r.volume = this._volume, r.preload = "auto", r.addEventListener("ended", () => { this.dispose(r), e == null || e(); }), r.addEventListener("error", (o) => { this.dispose(r), d.warn(vt, `Error occurred on "${t}"`, o.error), s == null || s(o.error); }), this.audios.push(r), r; } static play(t) { return new Promise((e, s) => { var r; (r = t.play()) == null || r.catch((o) => { t.dispatchEvent(new ErrorEvent("error", { error: o })), s(o); }), t.readyState === t.HAVE_ENOUGH_DATA ? e() : t.addEventListener("canplaythrough", e); }); } static dispose(t) { t.pause(), t.removeAttribute("src"), ct(this.audios, t); } static destroy() { for (let t = this.audios.length - 1; t >= 0; t--) this.dispose(this.audios[t]); } } _.audios = []; _._volume = yt; var Mt = /* @__PURE__ */ ((i) => (i.ALL = "ALL", i.IDLE = "IDLE", i.NONE = "NONE", i))(Mt || {}); class H extends k { constructor(t, e) { super(), this.motionGroups = {}, this.state = new gt(), this.playing = !1, this.destroyed = !1, this.settings = t, this.tag = `MotionManager(${t.name})`, this.state.tag = this.tag; } init(t) { t != null && t.idleMotionGroup && (this.groups.idle = t.idleMotionGroup), this.setupMotions(t), this.stopAllMotions(); } setupMotions(t) { for (const s of Object.keys(this.definitions)) this.motionGroups[s] = []; let e; switch (t == null ? void 0 : t.motionPreload) { case "NONE": return; case "ALL": e = Object.keys(this.definitions); break; case "IDLE": default: e = [this.groups.idle]; break; } for (const s of e) if (this.definitions[s]) for (let r = 0; r < this.definitions[s].length; r++) this.loadMotion(s, r).then(); } loadMotion(t, e) { return c(this, null, function* () { var s; if (!((s = this.definitions[t]) != null && s[e])) { d.warn(this.tag, `Undefined motion at "${t}"[${e}]`); return; } if (this.motionGroups[t][e] === null) { d.warn(this.tag, `Cannot start motion at "${t}"[${e}] because it's already failed in loading.`); return; } if (this.motionGroups[t][e]) return this.motionGroups[t][e]; const r = yield this._loadMotion(t, e); if (!this.destroyed) return this.motionGroups[t][e] = r != null ? r : null, r; }); } _loadMotion(t, e) { throw new Error("Not implemented."); } startMotion(t, e) { return c(this, arguments, function* (s, r, o = U.NORMAL) { var n; if (!this.state.reserve(s, r, o)) return !1; const a = (n = this.definitions[s]) == null ? void 0 : n[r]; if (!a) return !1; this.currentAudio && _.dispose(this.currentAudio); let l; if (v.sound) { const u = this.getSoundFile(a); if (u) try { l = _.add(this.settings.resolveURL(u), () => this.currentAudio = void 0, () => this.currentAudio = void 0), this.currentAudio = l; } catch (p) { d.warn(this.tag, "Failed to create audio", u, p); } } const h = yield this.loadMotion(s, r); if (l) { const u = _.play(l).catch((p) => d.warn(this.tag, "Failed to play audio", l.src, p)); v.motionSync && (yield u); } return this.state.start(h, s, r, o) ? (d.log(this.tag, "Start motion:", this.getMotionName(a)), this.emit("motionStart", s, r, l), this.state.shouldOverrideExpression() && this.expressionManager && this.expressionManager.resetExpression(), this.playing = !0, this._startMotion(h), !0) : (l && (_.dispose(l), this.currentAudio = void 0), !1); }); } startRandomMotion(t, e) { return c(this, null, function* () { const s = this.definitions[t]; if (s != null && s.length) { const r = []; for (let o = 0; o < s.length; o++) this.motionGroups[t][o] !== null && !this.state.isActive(t, o) && r.push(o); if (r.length) { const o = Math.floor(Math.random() * r.length); return this.startMotion(t, r[o], e); } } return !1; }); } stopAllMotions() { this._stopAllMotions(), this.state.reset(), this.currentAudio && (_.dispose(this.currentAudio), this.currentAudio = void 0); } update(t, e) { var s; return this.isFinished() && (this.playing && (this.playing = !1, this.emit("motionFinish")), this.state.shouldOverrideExpression() && ((s = this.expressionManager) == null || s.restoreExpression()), this.state.complete(), this.state.shouldRequestIdleMotion() && this.startRandomMotion(this.groups.idle, U.IDLE)), this.updateParameters(t, e); } destroy() { var t; this.destroyed = !0, this.emit("destroy"), this.stopAllMotions(), (t = this.expressionManager) == null || t.destroy(); const e = this; e.definitions = void 0, e.motionGroups = void 0; } } const Et = { x: 0, y: 0, width: 0, height: 0 }; class xt extends k { constructor() { super(...arguments), this.focusController = new mt(), this.originalWidth = 0, this.originalHeight = 0, this.width = 0, this.height = 0, this.localTransform = new C(), this.drawingMatrix = new C(), this.hitAreas = {}, this.textureFlipY = !1, this.viewport = [0, 0, 0, 0], this.destroyed = !1; } init() { this.setupLayout(), this.setupHitAreas(); } setupLayout() { const t = this, e = this.getSize(); t.originalWidth = e[0], t.originalHeight = e[1]; const s = Object.assign({ width: j, height: V }, this.getLayout()); this.localTransform.scale(s.width / j, s.height / V), t.width = this.originalWidth * this.localTransform.a, t.height = this.originalHeight * this.localTransform.d; const r = s.x !== void 0 && s.x - s.width / 2 || s.centerX !== void 0 && s.centerX || s.left !== void 0 && s.left - s.width / 2 || s.right !== void 0 && s.right + s.width / 2 || 0, o = s.y !== void 0 && s.y - s.height / 2 || s.centerY !== void 0 && s.centerY || s.top !== void 0 && s.top - s.height / 2 || s.bottom !== void 0 && s.bottom + s.height / 2 || 0; this.localTransform.translate(this.width * r, -this.height * o); } setupHitAreas() { const t = this.getHitAreaDefs().filter((e) => e.index >= 0); for (const e of t) this.hitAreas[e.name] = e; } hitTest(t, e) { return Object.keys(this.hitAreas).filter((s) => this.isHit(s, t, e)); } isHit(t, e, s) { if (!this.hitAreas[t]) return !1; const r = this.hitAreas[t].index, o = this.getDrawableBounds(r, Et); return o.x <= e && e <= o.x + o.width && o.y <= s && s <= o.y + o.height; } getDrawableBounds(t, e) { const s = this.getDrawableVertices(t); let r = s[0], o = s[0], n = s[1], a = s[1]; for (let l = 0; l < s.length; l += 2) { const h = s[l], u = s[l + 1]; r = Math.min(h, r), o = Math.max(h, o), n = Math.min(u, n), a = Math.max(u, a); } return e != null || (e = {}), e.x = r, e.y = n, e.width = o - r, e.height = a - n, e; } updateTransform(t) { this.drawingMatrix.copyFrom(t).append(this.localTransform); } update(t, e) { this.focusController.update(t); } destroy() { this.destroyed = !0, this.emit("destroy"), this.motionManager.destroy(), this.motionManager = void 0; } } const Pt = "XHRLoader"; class B extends Error { constructor(t, e, s, r = !1) { super(t), this.url = e, this.status = s, this.aborted = r; } } const g = class { static createXHR(i, t, e, s, r) { const o = new XMLHttpRequest(); if (g.allXhrSet.add(o), i) { let n = g.xhrMap.get(i); n ? n.add(o) : (n = /* @__PURE__ */ new Set([o]), g.xhrMap.set(i, n)), i.listeners("destroy").includes(g.cancelXHRs) || i.once("destroy", g.cancelXHRs); } return o.open("GET", t), o.responseType = e, o.onload = () => { (o.status === 200 || o.status === 0) && o.response ? s(o.response) : o.onerror(); }, o.onerror = () => { d.warn(Pt, `Failed to load resource as ${o.responseType} (Status ${o.status}): ${t}`), r(new B("Network error.", t, o.status)); }, o.onabort = () => r(new B("Aborted.", t, o.status, !0)), o.onloadend = () => { var n; g.allXhrSet.delete(o), i && ((n = g.xhrMap.get(i)) == null || n.delete(o)); }, o; } static cancelXHRs() { var i; (i = g.xhrMap.get(this)) == null || i.forEach((t) => { t.abort(), g.allXhrSet.delete(t); }), g.xhrMap.delete(this); } static release() { g.allXhrSet.forEach((i) => i.abort()), g.allXhrSet.clear(), g.xhrMap = /* @__PURE__ */ new WeakMap(); } }; let R = g; R.xhrMap = /* @__PURE__ */ new WeakMap(); R.allXhrSet = /* @__PURE__ */ new Set(); R.loader = (i, t) => new Promise((e, s) => { g.createXHR(i.target, i.settings ? i.settings.resolveURL(i.url) : i.url, i.type, (o) => { i.result = o, e(); }, s).send(); }); function Q(i, t) { let e = -1; return s(0); function s(r, o) { if (o) return Promise.reject(o); if (r <= e) return Promise.reject(new Error("next() called multiple times")); e = r; const n = i[r]; if (!n) return Promise.resolve(); try { return Promise.resolve(n(t, s.bind(null, r + 1))); } catch (a) { return Promise.reject(a); } } } class P { static load(t) { return Q(this.middlewares, t).then(() => t.result); } } P.middlewares = [R.loader]; function wt(i, t = {}) { var e; const s = { resourceOptions: { crossorigin: t.crossOrigin } }; if (D.fromURL) return D.fromURL(i, s).catch((n) => { if (n instanceof Error) throw n; const a = new Error("Texture loading error"); throw a.event = n, a; }); s.resourceOptions.autoLoad = !1; const r = D.from(i, s); if (r.baseTexture.valid) return Promise.resolve(r); const o = r.baseTexture.resource; return (e = o._live2d_load) != null || (o._live2d_load = new Promise((n, a) => { const l = (h) => { o.source.removeEventListener("error", l); const u = new Error("Texture loading error"); u.event = h, a(u); }; o.source.addEventListener("error", l), o.load().then(() => n(r)).catch(l); })), o._live2d_load; } const Y = "Live2DFactory", K = (i, t) => c(void 0, null, function* () { if (typeof i.source == "string") { const e = yield P.load({ url: i.source, type: "json", target: i.live2dModel }); e.url = i.source, i.source = e, i.live2dModel.emit("settingsJSONLoaded", e); } return t(); }), tt = (i, t) => c(void 0, null, function* () { if (i.source instanceof N) return i.settings = i.source, t(); if (typeof i.source == "object") { const e = f.findRuntime(i.source); if (e) { const s = e.createModelSettings(i.source); return i.settings = s, i.live2dModel.emit("settingsLoaded", s), t(); } } throw new TypeError("Unknown settings format."); }), et = (i, t) => { if (i.settings) { const e = f.findRuntime(i.settings); if (e) return e.ready().then(t); } return t(); }, st = (i, t) => c(void 0, null, function* () { yield t(); const e = i.internalModel; if (e) { const s = i.settings, r = f.findRuntime(s); if (r) { const o = []; s.pose && o.push(P.load({ settings: s, url: s.pose, type: "json", target: e }).then((n) => { e.pose = r.createPose(e.coreModel, n), i.live2dModel.emit("poseLoaded", e.pose); }).catch((n) => { i.live2dModel.emit("poseLoadError", n), d.warn(Y, "Failed to load pose.", n); })), s.physics && o.push(P.load({ settings: s, url: s.physics, type: "json", target: e }).then((n) => { e.physics = r.createPhysics(e.coreModel, n), i.live2dModel.emit("physicsLoaded", e.physics); }).catch((n) => { i.live2dModel.emit("physicsLoadError", n), d.warn(Y, "Failed to load physics.", n); })), o.length && (yield Promise.all(o)); } } }), it = (i, t) => c(void 0, null, function* () { if (i.settings) { const e = i.live2dModel, s = i.settings.textures.map((r) => { const o = i.settings.resolveURL(r); return wt(o, { crossOrigin: i.options.crossOrigin }); }); if (yield t(), i.internalModel) e.internalModel = i.internalModel, e.emit("modelLoaded", i.internalModel); else throw new TypeError("Missing internal model."); e.textures = yield Promise.all(s), e.emit("textureLoaded", e.textures); } else throw new TypeError("Missing settings."); }), rt = (i, t) => c(void 0, null, function* () { const e = i.settings; if (e instanceof N) { const s = f.findRuntime(e); if (!s) throw new TypeError("Unknown model settings."); const r = yield P.load({ settings: e, url: e.moc, type: "arraybuffer", target: i.live2dModel }); if (!s.isValidMoc(r)) throw new Error("Invalid moc data"); const o = s.createCoreModel(r); return i.internalModel = s.createInternalModel(o, e, i.options), t(); } throw new TypeError("Missing settings."); }), m = class { static registerRuntime(i) { m.runtimes.push(i), m.runtimes.sort((t, e) => e.version - t.version); } static findRuntime(i) { for (const t of m.runtimes) if (t.test(i)) return t; } static setupLive2DModel(i, t, e) { return c(this, null, function* () { const s = new Promise((n) => i.once("textureLoaded", n)), r = new Promise((n) => i.once("modelLoaded", n)), o = Promise.all([s, r]).then(() => i.emit("ready")); yield Q(m.live2DModelMiddlewares, { live2dModel: i, source: t, options: e || {} }), yield o, i.emit("load"); }); } static loadMotion(i, t, e) { var s, r; const o = (n) => i.emit("motionLoadError", t, e, n); try { const n = (s = i.definitions[t]) == null ? void 0 : s[e]; if (!n) return Promise.resolve(void 0); i.listeners("destroy").includes(m.releaseTasks) || i.once("destroy", m.releaseTasks); let a = m.motionTasksMap.get(i); a || (a = {}, m.motionTasksMap.set(i, a)); let l = a[t]; l || (l = [], a[t] = l); const h = i.getMotionFile(n); return (r = l[e]) != null || (l[e] = P.load({ url: h, settings: i.settings, type: i.motionDataType, target: i }).then((u) => { var p; const A = (p = m.motionTasksMap.get(i)) == null ? void 0 : p[t]; A && delete A[e]; const $ = i.createMotion(u, t, n); return i.emit("motionLoaded", t, e, $), $; }).catch((u) => { d.warn(i.tag, `Failed to load motion: ${h} `, u), o(u); })), l[e]; } catch (n) { d.warn(i.tag, `Failed to load motion at "${t}"[${e}] `, n), o(n); } return Promise.resolve(void 0); } static loadExpression(i, t) { var e; const s = (r) => i.emit("expressionLoadError", t, r); try { const r = i.definitions[t]; if (!r) return Promise.resolve(void 0); i.listeners("destroy").includes(m.releaseTasks) || i.once("destroy", m.releaseTasks); let o = m.expressionTasksMap.get(i); o || (o = [], m.expressionTasksMap.set(i, o)); const n = i.getExpressionFile(r); return (e = o[t]) != null || (o[t] = P.load({ url: n, settings: i.settings, type: "json", target: i }).then((a) => { const l = m.expressionTasksMap.get(i); l && delete l[t]; const h = i.createExpression(a, r); return i.emit("expressionLoaded", t, h), h; }).catch((a) => { d.warn(i.tag, `Failed to load expression: ${n} `, a), s(a); })), o[t]; } catch (r) { d.warn(i.tag, `Failed to load expression at [${t}] `, r), s(r); } return Promise.resolve(void 0); } static releaseTasks() { this instanceof H ? m.motionTasksMap.delete(this) : m.expressionTasksMap.delete(this); } }; let f = m; f.runtimes = []; f.urlToJSON = K; f.jsonToSettings = tt; f.waitUntilReady = et; f.setupOptionals = st; f.setupEssentials = it; f.createInternalModel = rt; f.live2DModelMiddlewares = [ K, tt, et, st, it, rt ]; f.motionTasksMap = /* @__PURE__ */ new WeakMap(); f.expressionTasksMap = /* @__PURE__ */ new WeakMap(); H.prototype._loadMotion = function(i, t) { return f.loadMotion(this, i, t); }; Z.prototype._loadExpression = function(i) { return f.loadExpression(this, i); }; class Lt { constructor() { this._autoInteract = !1; } get autoInteract() { return this._autoInteract; } set autoInteract(t) { t !== this._autoInteract && (t ? this.on("pointertap", q, this) : this.off("pointertap", q, this), this._autoInteract = t); } registerInteraction(t) { t !== this.interactionManager && (this.unregisterInteraction(), this._autoInteract && t && (this.interactionManager = t, t.on("pointermove", z, this))); } unregisterInteraction() { var t; this.interactionManager && ((t = this.interactionManager) == null || t.off("pointermove", z, this), this.interactionManager = void 0); } } function q(i) { this.tap(i.data.global.x, i.data.global.y); } function z(i) { this.focus(i.data.global.x, i.data.global.y); } class _t extends ot { } const M = new nt(), It = new C(); let x; class bt extends at { constructor(t) { super(), this.tag = "Live2DModel(uninitialized)", this.textures = [], this.transform = new _t(), this.anchor = new lt(this.onAnchorChange, this, 0, 0), this.glContextID = -1, this.elapsedTime = performance.now(), this.deltaTime = 0, this._autoUpdate = !1, this.once("modelLoaded", () => this.init(t)); } static from(t, e) { const s = new this(e); return f.setupLive2DModel(s, t, e).then(() => s); } static fromSync(t, e) { const s = new this(e); return f.setupLive2DModel(s, t, e).then(e == null ? void 0 : e.onLoad).catch(e == null ? void 0 : e.onError), s; } static registerTicker(t) { x = t; } get autoUpdate() { return this._autoUpdate; } set autoUpdate(t) { var e; x || (x = (e = window.PIXI) == null ? void 0 : e.Ticker), t ? this._destroyed || (x ? (x.shared.add(this.onTickerUpdate, this), this._autoUpdate = !0) : d.warn(this.tag, "No Ticker registered, please call Live2DModel.registerTicker(Ticker).")) : (x == null || x.shared.remove(this.onTickerUpdate, this), this._autoUpdate = !1); } init(t) { this.tag = `Live2DModel(${this.internalModel.settings.name})`; const e = Object.assign({ autoUpdate: !0, autoInteract: !0 }, t); e.autoInteract && (this.interactive = !0), this.autoInteract = e.autoInteract, this.autoUpdate = e.autoUpdate; } onAnchorChange() { this.pivot.set(this.anchor.x * this.internalModel.width, this.anchor.y * this.internalModel.height); } motion(t, e, s) { return e === void 0 ? this.internalModel.motionManager.startRandomMotion(t, s) : this.internalModel.motionManager.startMotion(t, e, s); } expression(t) { return this.internalModel.motionManager.expressionManager ? t === void 0 ? this.internalModel.motionManager.expressionManager.setRandomExpression() : this.internalModel.motionManager.expressionManager.setExpression(t) : Promise.resolve(!1); } focus(t, e, s = !1) { M.x = t, M.y = e, this.toModelPosition(M, M, !0); let r = M.x / this.internalModel.originalWidth * 2 - 1, o = M.y / this.internalModel.originalHeight * 2 - 1, n = Math.atan2(o, r); this.internalModel.focusController.focus(Math.cos(n), -Math.sin(n), s); } tap(t, e) { const s = this.hitTest(t, e); s.length && (d.log(this.tag, "Hit", s), this.emit("hit", s)); } hitTest(t, e) { return M.x = t, M.y = e, this.toModelPosition(M, M), this.internalModel.hitTest(M.x, M.y); } toModelPosition(t, e = t.clone(), s) { return s || (this._recursivePostUpdateTransform(), this.parent ? this.displayObjectUpdateTransform() : (this.parent = this._tempDisplayObjectParent, this.displayObjectUpdateTransform(), this.parent = null)), this.transform.worldTransform.applyInverse(t, e), this.internalModel.localTransform.applyInverse(e, e), e; } containsPoint(t) { return this.getBounds(!0).contains(t.x, t.y); } _calculateBounds() { this._bounds.addFrame(this.transform, 0, 0, this.internalModel.width, this.internalModel.height); } onTickerUpdate() { this.update(x.shared.deltaMS); } update(t) { this.deltaTime += t, this.elapsedTime += t; } _render(t) { this.registerInteraction(t.plugins.interaction), t.batch.reset(), t.geometry.reset(), t.shader.reset(), t.state.reset(); let e = !1; this.glContextID !== t.CONTEXT_UID && (this.glContextID = t.CONTEXT_UID, this.internalModel.updateWebGLContext(t.gl, this.glContextID), e = !0); for (let o = 0; o < this.textures.length; o++) { const n = this.textures[o]; n.valid && ((e || !n.baseTexture._glTextures[this.glContextID]) && (t.gl.pixelStorei(WebGLRenderingContext.UNPACK_FLIP_Y_WEBGL, this.internalModel.textureFlipY), t.texture.bind(n.baseTexture, 0)), this.internalModel.bindTexture(o, n.baseTexture._glTextures[this.glContextID].texture), n.baseTexture.touched = t.textureGC.count); } const s = t.framebuffer.viewport; this.internalModel.viewport = [s.x, s.y, s.width, s.height], this.deltaTime && (this.internalModel.update(this.deltaTime, this.elapsedTime), this.deltaTime = 0); const r = It.copyFrom(t.globalUniforms.uniforms.projectionMatrix).append(this.worldTransform); this.internalModel.updateTransform(r), this.internalModel.draw(t.gl), t.state.reset(), t.texture.reset(); } destroy(t) { this.emit("destroy"), this.autoUpdate = !1, this.unregisterInteraction(), t != null && t.texture && this.textures.forEach((e) => e.destroy(t.baseTexture)), this.internalModel.destroy(), super.destroy(t); } } dt(bt, [Lt]); const E = class { static resolveURL(i, t) { var e; const s = (e = E.filesMap[i]) == null ? void 0 : e[t]; if (s === void 0) throw new Error("Cannot find this file from uploaded files: " + t); return s; } static upload(i, t) { return c(this, null, function* () { const e = {}; for (const s of t.getDefinedFiles()) { const r = decodeURI(G.resolve(t.url, s)), o = i.find((n) => n.webkitRelativePath === r); o && (e[s] = URL.createObjectURL(o)); } E.filesMap[t._objectURL] = e; }); } static createSettings(i) { return c(this, null, function* () { const t = i.find((n) => n.name.endsWith("model.json") || n.name.endsWith("model3.json")); if (!t) throw new TypeError("Settings file not found"); const e = yield E.readText(t), s = JSON.parse(e); s.url = t.webkitRelativePath; const r = f.findRuntime(s); if (!r) throw new Error("Unknown settings JSON"); const o = r.createModelSettings(s); return o._objectURL = URL.createObjectURL(t), o; }); } static readText(i) { return c(this, null, function* () { return new Promise((t, e) => { const s = new FileReader(); s.onload = () => t(s.result), s.onerror = e, s.readAsText(i, "utf8"); }); }); } }; let X = E; X.filesMap = {}; X.factory = (i, t) => c(void 0, null, function* () { if (Array.isArray(i.source) && i.source[0] instanceof File) { const e = i.source; let s = e.settings; if (!s) s = yield E.createSettings(e); else if (!s._objectURL) throw new Error('"_objectURL" must be specified in ModelSettings'); s.validateFiles(e.map((r) => encodeURI(r.webkitRelativePath))), yield E.upload(e, s), s.resolveURL = function(r) { return E.resolveURL(this._objectURL, r); }, i.source = s, i.live2dModel.once("modelLoaded", (r) => { r.once("destroy", function() { const o = this.settings._objectURL; if (URL.revokeObjectURL(o), E.filesMap[o]) for (const n of Object.values(E.filesMap[o])) URL.revokeObjectURL(n); delete E.filesMap[o]; }); }); } return t(); }); f.live2DModelMiddlewares.unshift(X.factory); const y = class { static unzip(i, t) { return c(this, null, function* () { const e = yield y.getFilePaths(i), s = []; for (const o of t.getDefinedFiles()) { const n = decodeURI(G.resolve(t.url, o)); e.includes(n) && s.push(n); } const r = yield y.getFiles(i, s); for (let o = 0; o < r.length; o++) { const n = s[o], a = r[o]; Object.defineProperty(a, "webkitRelativePath", { value: n }); } return r; }); } static createSettings(i) { return c(this, null, function* () { const e = (yield y.getFilePaths(i)).find((n) => n.endsWith("model.json") || n.endsWith("model3.json")); if (!e) throw new Error("Settings file not found"); const s = yield y.readText(i, e); if (!s) throw new Error("Empty settings file: " + e); const r = JSON.parse(s); r.url = e; const o = f.findRuntime(r); if (!o) throw new Error("Unknown settings JSON"); return o.createModelSettings(r); }); } static zipReader(i, t) { return c(this, null, function* () { throw new Error("Not implemented"); }); } static getFilePaths(i) { return c(this, null, function* () { throw new Error("Not implemented"); }); } static getFiles(i, t) { return c(this, null, function* () { throw new Error("Not implemented"); }); } static readText(i, t) { return c(this, null, function* () { throw new Error("Not implemented"); }); } static releaseReader(i) { } }; let F = y; F.ZIP_PROTOCOL = "zip://"; F.uid = 0; F.factory = (i, t) => c(void 0, null, function* () { const e = i.source; let s, r, o; if (typeof e == "string" && (e.endsWith(".zip") || e.startsWith(y.ZIP_PROTOCOL)) ? (e.startsWith(y.ZIP_PROTOCOL) ? s = e.slice(y.ZIP_PROTOCOL.length) : s = e, r = yield P.load({ url: s, type: "blob", target: i.live2dModel })) : Array.isArray(e) && e.length === 1 && e[0] instanceof File && e[0].name.endsWith(".zip") && (r = e[0], s = URL.createObjectURL(r), o = e.settings), r) { if (!r.size) throw new Error("Empty zip file"); const n = yield y.zipReader(r, s); o || (o = yield y.createSettings(n)), o._objectURL = y.ZIP_PROTOCOL + y.uid + "/" + o.url; const a = yield y.unzip(n, o); a.settings = o, i.source = a, s.startsWith("blob:") && i.live2dModel.once("modelLoaded", (l) => { l.once("destroy", function() { URL.revokeObjectURL(s); }); }), y.releaseReader(n); } return t(); }); f.live2DModelMiddlewares.unshift(F.factory); if (!window.Live2D) throw new Error("Could not find Cubism 2 runtime. This plugin requires live2d.min.js to be loaded."); const Tt = Live2DMotion.prototype.updateParam; Live2DMotion.prototype.updateParam = function(i, t) { Tt.call(this, i, t), t.isFinished() && this.onFinishHandler && (this.onFinishHandler(this), delete this.onFinishHandler); }; class Ot extends AMotion { constructor(t) { super(), this.params = [], this.setFadeIn(t.fade_in > 0 ? t.fade_in : v.expressionFadingDuration), this.setFadeOut(t.fade_out > 0 ? t.fade_out : v.expressionFadingDuration), Array.isArray(t.params) && t.params.forEach((e) => { const s = e.calc || "add"; if (s === "add") { const r = e.def || 0; e.val -= r; } else if (s === "mult") { const r = e.def || 1; e.val /= r; } this.params.push({ calc: s, val: e.val, id: e.id }); }); } updateParamExe(t, e, s, r) { this.params.forEach((o) => { t.setParamFloat(o.id, o.val * s); }); } } class Rt extends Z { constructor(t, e) { var s; super(t, e), this.queueManager = new MotionQueueManager(), this.definitions = (s = this.settings.expressions) != null ? s : [], this.init(); } isFinished() { return this.queueManager.isFinished(); } getExpressionIndex(t) { return this.definitions.findIndex((e) => e.name === t); } getExpressionFile(t) { return t.file; } createExpression(t, e) { return new Ot(t); } _setExpression(t) { return this.queueManager.startMotion(t); } stopAllExpressions() { this.queueManager.stopAllMotions(); } updateParameters(t, e) { return this.queueManager.updateParam(t); } } class Ft extends H { constructor(t, e) { super(t, e), this.groups = { idle: "idle" }, this.motionDataType = "arraybuffer", this.queueManager = new MotionQueueManager(), this.definitions = this.settings.motions, this.init(e); } init(t) { super.init(t), this.settings.expressions && (this.expressionManager = new Rt(this.settings, t)); } isFinished() { return this.queueManager.isFinished(); } createMotion(t, e, s) { const r = Live2DMotion.loadMotion(t), o = e === this.groups.idle ? v.idleMotionFadingDuration : v.motionFadingDuration; return r.setFadeIn(s.fade_in > 0 ? s.fade_in : o), r.setFadeOut(s.fade_out > 0 ? s.fade_out : o), r; } getMotionFile(t) { return t.file; } getMotionName(t) { return t.file; } getSoundFile(t) { return t.sound; } _startMotion(t, e) { return t.onFinishHandler = e, this.queueManager.stopAllMotions(), this.queueManager.startMotion(t); } _stopAllMotions() { this.queueManager.stopAllMotions(); } updateParameters(t, e) { return this.queueManager.updateParam(t); } destroy() { super.destroy(), this.queueManager = void 0; } } class At { constructor(t) { this.coreModel = t, this.blinkInterval = 4e3, this.closingDuration = 100, this.closedDuration = 50, this.openingDuration = 150, this.eyeState = 0, this.eyeParamValue = 1, this.closedTimer = 0, this.nextBlinkTimeLeft = this.blinkInterval, this.leftParam = t.getParamIndex("PARAM_EYE_L_OPEN"), this.rightParam = t.getParamIndex("PARAM_EYE_R_OPEN"); } setEyeParams(t) { this.eyeParamValue = O(t, 0, 1), this.coreModel.setParamFloat(this.leftParam, this.eyeParamValue), this.coreModel.setParamFloat(this.rightParam, this.eyeParamValue); } update(t) { switch (this.eyeState) { case 0: this.nextBlinkTimeLeft -= t, this.nextBlinkTimeLeft < 0 && (this.eyeState = 1, this.nextBlinkTimeLeft = this.blinkInterval + this.closingDuration + this.closedDuration + this.openingDuration + ht(0, 2e3)); break; case 1: this.setEyeParams(this.eyeParamValue + t / this.closingDuration), this.eyeParamValue <= 0 && (this.eyeState = 2, this.closedTimer = 0); break; case 2: this.closedTimer += t, this.closedTimer >= this.closedDuration && (this.eyeState = 3); break; case 3: this.setEyeParams(this.eyeParamValue + t / this.openingDuration), this.eyeParamValue >= 1 && (this.eyeState = 0); } } } const L = new Float32Array([ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]); class Dt extends xt { constructor(t, e, s) { super(), this.textureFlipY = !0, this.drawDataCount = 0, this.disableCulling = !1, this.coreModel = t, this.settings = e, this.motionManager = new Ft(e, s), this.eyeBlink = new At(t), this.eyeballXParamIndex = t.getParamIndex("PARAM_EYE_BALL_X"), this.eyeballYParamIndex = t.getParamIndex("PARAM_EYE_BALL_Y"), this.angleXParamIndex = t.getParamIndex("PARAM_ANGLE_X"), this.angleYParamIndex = t.getParamIndex("PARAM_ANGLE_Y"), this.angleZParamIndex = t.getParamIndex("PARAM_ANGLE_Z"), this.bodyAngleXParamIndex = t.getParamIndex("PARAM_BODY_ANGLE_X"), this.breathParamIndex = t.getParamIndex("PARAM_BREATH"), this.init(); } init() { super.init(), this.settings.initParams && this.settings.initParams.forEach(({ id: o, value: n }) => this.coreModel.setParamFloat(o, n)), this.settings.initOpacities && this.settings.initOpacities.forEach(({ id: o, value: n }) => this.coreModel.setPartsOpacity(o, n)), this.coreModel.saveParam(); const t = this.coreModel.getModelContext()._$aS; t != null && t.length && (this.drawDataCount = t.length); let e = this.coreModel.drawParamWebGL.culling; Object.defineProperty(this.coreModel.drawParamWebGL, "culling", { set: (o) => e = o, get: () => this.disableCulling ? !1 : e }); const s = this.coreModel.getModelContext().clipManager, r = s.setupClip; s.setupClip = (o, n) => { r.call(s, o, n), n.gl.viewport(...this.viewport); }; } getSize() { return [this.coreModel.getCanvasWidth(), this.coreModel.getCanvasHeight()]; } getLayout() { const t = {}; if (this.settings.layout) for (const e of Object.keys(this.settings.layout)) { let s = e; e === "center_x" ? s = "centerX" : e === "center_y" && (s = "centerY"), t[s] = this.settings.layout[e]; } return t; } updateWebGLContext(t, e) { const s = this.coreModel.drawParamWebGL; s.firstDraw = !0, s.setGL(t), s.glno = e; for (const n in s) s.hasOwnProperty(n) && s[n] instanceof WebGLBuffer && (s[n] = null); const r = this.coreModel.getModelContext().clipManager; r.curFrameNo = e; const o = t.getParameter(t.FRAMEBUFFER_BINDING); r.getMaskRenderTexture(), t.bindFramebuffer(t.FRAMEBUFFER, o); } bindTexture(t, e) { this.coreModel.setTexture(t, e); } getHitAreaDefs() { var t; return ((t = this.settings.hitAreas) == null ? void 0 : t.map((e) => ({ id: e.id, name: e.name, index: this.coreModel.getDrawDataIndex(e.id) }))) || []; } getDrawableIDs() { const t = this.coreModel.getModelContext(), e = []; for (let s = 0; s < this.drawDataCount; s++) { const r = t.getDrawData(s); r && e.push(r.getDrawDataID().id); } return e; } getDrawableIndex(t) { return this.coreModel.getDrawDataIndex(t); } getDrawableVertices(t) { if (typeof t == "string" && (t = this.coreModel.getDrawDataIndex(t), t === -1)) throw new TypeError("Unable to find drawable ID: " + t); return this.coreModel.getTransformedPoints(t).slice(); } update(t, e) { var s, r, o, n; super.update(t, e); const a = this.coreModel; this.emit("beforeMotionUpdate"); const l = this.motionManager.update(this.coreModel, e); this.emit("afterMotionUpdate"), a.saveParam(), (s = this.motionManager.expressionManager) == null || s.update(a, e), l || (r = this.eyeBlink) == null || r.update(t), this.updateFocus(), this.updateNaturalMovements(t, e), (o = this.physics) == null || o.update(e), (n = this.pose) == null || n.update(t), this.emit("beforeModelUpdate"), a.update(), a.loadParam(); } updateFocus() { this.coreModel.addToParamFloat(this.eyeballXParamIndex, this.focusController.x), this.coreModel.addToParamFloat(this.eyeballYParamIndex, this.focusController.y), this.coreModel.addToParamFloat(this.angleXParamIndex, this.focusController.x * 30), this.coreModel.addToParamFloat(this.angleYParamIndex, this.focusController.y * 30), this.coreModel.addToParamFloat(this.angleZParamIndex, this.focusController.x * this.focusController.y * -30), this.coreModel.addToParamFloat(this.bodyAngleXParamIndex, this.focusController.x * 10); } updateNaturalMovements(t, e) { const s = e / 1e3 * 2 * Math.PI; this.coreModel.addToParamFloat(this.angleXParamIndex, 15 * Math.sin(s / 6.5345) * 0.5), this.coreModel.addToParamFloat(this.angleYParamIndex, 8 * Math.sin(s / 3.5345) * 0.5), this.coreModel.addToParamFloat(this.angleZParamIndex, 10 * Math.sin(s / 5.5345) * 0.5), this.coreModel.addToParamFloat(this.bodyAngleXParamIndex, 4 * Math.sin(s / 15.5345) * 0.5), this.coreModel.setParamFloat(this.breathParamIndex, 0.5 + 0.5 * Math.sin(s / 3.2345)); } draw(t) { const e = this.disableCulling; t.getParameter(t.FRAMEBUFFER_BINDING) && (this.disableCulling = !0); const s = this.drawingMatrix; L[0] = s.a, L[1] = s.b, L[4] = s.c, L[5] = s.d, L[12] = s.tx, L[13] = s.ty, this.coreModel.setMatrix(L), this.coreModel.draw(), this.disableCulling = e; } destroy() { super.destroy(), this.coreModel = void 0; } } class T extends N { constructor(t) { if (super(t), this.motions = {}, !T.isValidJSON(t)) throw new TypeError("Invalid JSON."); this.moc = t.model, b("string", t, this, "textures", "textures"), this.copy(t); } static isValidJSON(t) { var e; return !!t && typeof t.model == "string" && ((e = t.textures) == null ? void 0 : e.length) > 0 && t.textures.every((s) => typeof s == "string"); } copy(t) { I("string", t, this, "name", "name"), I("string", t, this, "pose", "pose"), I("string", t, this, "physics", "physics"), I("object", t, this, "layout", "layout"), I("object", t, this, "motions", "motions"), b("object", t, this, "hit_areas", "hitAreas"), b("object", t, this, "expressions", "expressions"), b("object", t, this, "init_params", "initParams"), b("object", t, this, "init_opacities", "initOpacities"); } replaceFiles(t) { super.replaceFiles(t); for (const [e, s] of Object.entries(this.motions)) for (let r = 0; r < s.length; r++) s[r].file = t(s[r].file, `motions.${e}[${r}].file`), s[r].sound !== void 0 && (s[r].sound = t(s[r].sound, `motions.${e}[${r}].sound`)); if (this.expressions) for (let e = 0; e < this.expressions.length; e++) this.expressions[e].file = t(this.expressions[e].file, `expressions[${e}].file`); } } const Ct = { x: PhysicsHair.Src.SRC_TO_X, y: PhysicsHair.Src.SRC_TO_Y, angle: PhysicsHair.Src.SRC_TO_G_ANGLE }, St = { x: PhysicsHair.Src.SRC_TO_X, y: PhysicsHair.Src.SRC_TO_Y, angle: PhysicsHair.Src.SRC_TO_G_ANGLE }; class Ut { constructor(t, e) { this.coreModel = t, this.physicsHairs = [], e.physics_hair && (this.physicsHairs = e.physics_hair.map((s) => { const r = new PhysicsHair(); return r.setup(s.setup.length, s.setup.regist, s.setup.mass), s.src.forEach(({ id: o, ptype: n, scale: a, weight: l }) => { const h = Ct[n]; h && r.addSrcParam(h, o, a, l); }), s.targets.forEach(({ id: o, ptype: n, scale: a, weight: l }) => { const h = St[n]; h && r.addTargetParam(h, o, a, l); }), r; })); } update(t) { this.physicsHairs.forEach((e) => e.update(this.coreModel, t)); } } class J { constructor(t) { this.id = t, this.paramIndex = -1, this.partsIndex = -1, this.link = []; } initIndex(t) { this.paramIndex = t.getParamIndex("VISIBLE:" + this.id), this.partsIndex = t.getPartsDataIndex(PartsDataID.getID(this.id)), t.setParamFloat(this.paramIndex, 1); } } class kt { constructor(t, e) { this.coreModel = t, this.opacityAnimDuration = 500, this.partsGroups = [], e.parts_visible && (this.partsGroups = e.parts_visible.map(({ group: s }) => s.map(({ id: r, link: o }) => { const n = new J(r); return o && (n.link = o.map((a) => new J(a))), n; })), this.init()); } init() { this.partsGroups.forEach((t) => { t.forEach((e) => { if (e.initIndex(this.coreModel), e.paramIndex >= 0) { const s = this.coreModel.getParamFloat(e.paramIndex) !== 0; this.coreModel.setPartsOpacity(e.partsIndex, s ? 1 : 0), this.coreModel.setParamFloat(e.paramIndex, s ? 1 : 0), e.link.length > 0 && e.link.forEach((r) => r.initIndex(this.coreModel)); } }); }); } normalizePartsOpacityGroup(t, e) { const s = this.coreModel, r = 0.5, o = 0.15; let n = 1, a = t.findIndex(({ paramIndex: l, partsIndex: h }) => h >= 0 && s.getParamFloat(l) !== 0); if (a >= 0) { const l = s.getPartsOpacity(t[a].partsIndex); n = O(l + e / this.opacityAnimDuration, 0, 1); } else a = 0, n = 1; t.forEach(({ partsIndex: l }, h) => { if (l >= 0) if (a == h) s.setPartsOpacity(l, n); else { let u = s.getPartsOpacity(l), p; n < r ? p = n * (r - 1) / r + 1 : p = (