mesh-avatar 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -21,55 +21,55 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  SOFTWARE.
23
23
  */
24
- const ee = (n, e, t) => {
24
+ const ne = (n, e, t) => {
25
25
  (typeof n != "number" || !Number.isFinite(n)) && t.push(`${e}: expected a finite number`);
26
- }, _e = (n, e, t) => {
27
- ee(n, e, t), typeof n == "number" && n <= 0 && t.push(`${e}: must be positive`);
28
- }, Ae = (n, e, t) => {
29
- _e(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
30
- }, Ue = (n, e, t) => {
31
- ee(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
32
- }, Bt = (n, e, t) => {
26
+ }, Le = (n, e, t) => {
27
+ ne(n, e, t), typeof n == "number" && n <= 0 && t.push(`${e}: must be positive`);
28
+ }, we = (n, e, t) => {
29
+ Le(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
30
+ }, Ie = (n, e, t) => {
31
+ ne(n, e, t), typeof n == "number" && !Number.isInteger(n) && t.push(`${e}: expected an integer`);
32
+ }, jt = (n, e, t) => {
33
33
  (typeof n != "string" || !n.trim()) && t.push(`${e}: expected a non-empty string`);
34
- }, ge = (n, e = 0, t = 1 / 0) => (r, a, o) => {
34
+ }, ge = (n, e = 0, t = 1 / 0) => (r, a, s) => {
35
35
  if (!Array.isArray(r)) {
36
- o.push(`${a}: expected an array`);
36
+ s.push(`${a}: expected an array`);
37
37
  return;
38
38
  }
39
- (r.length < e || r.length > t) && o.push(`${a}: expected ${e}..${t} items`), r.forEach((i, f) => n(i, `${a}[${f}]`, o));
40
- }, ye = ge(ee, 2, 2), he = (n, e, t) => {
39
+ (r.length < e || r.length > t) && s.push(`${a}: expected ${e}..${t} items`), r.forEach((l, f) => n(l, `${a}[${f}]`, s));
40
+ }, ye = ge(ne, 2, 2), ue = (n, e, t) => {
41
41
  ye(n, e, t), Array.isArray(n) && n.length === 2 && n[0] >= n[1] && t.push(`${e}: start must be less than end`);
42
42
  }, oe = (n, e = []) => (t, r, a) => {
43
43
  if (!t || typeof t != "object" || Array.isArray(t)) {
44
44
  a.push(`${r}: expected an object`);
45
45
  return;
46
46
  }
47
- const o = t;
48
- for (const [i, f] of Object.entries(n))
49
- o[i] === void 0 && e.includes(i) || f(o[i], `${r}.${i}`, a);
50
- }, $e = { cx: ee, cy: ee, rx: _e, ry: _e }, ve = oe($e), Ze = ge(ye, 3), Ut = ge(ye, 2), et = (n, e, t) => {
51
- ee(n, e, t), typeof n == "number" && (n < 0 || n > 1) && t.push(`${e}: must be between 0 and 1`);
52
- }, vn = (n) => oe({
47
+ const s = t;
48
+ for (const [l, f] of Object.entries(n))
49
+ s[l] === void 0 && e.includes(l) || f(s[l], `${r}.${l}`, a);
50
+ }, Ce = { cx: ne, cy: ne, rx: Le, ry: Le }, ve = oe(Ce), We = ge(ye, 3), It = ge(ye, 2), nt = (n, e, t) => {
51
+ ne(n, e, t), typeof n == "number" && (n < 0 || n > 1) && t.push(`${e}: must be between 0 and 1`);
52
+ }, bn = (n) => oe({
53
53
  version: (e, t, r) => {
54
54
  e !== 1 && r.push(`${t}: only version 1 is supported`);
55
55
  },
56
- image: oe({ width: Ae, height: Ae }),
56
+ image: oe({ width: we, height: we }),
57
57
  head: oe({
58
- ...$e,
59
- shiftX: ee,
60
- shiftY: ee,
61
- pivotX: ee,
62
- pivotY: ee,
63
- maxRoll: ee,
64
- weightBand: he,
65
- turnBand: he
58
+ ...Ce,
59
+ shiftX: ne,
60
+ shiftY: ne,
61
+ pivotX: ne,
62
+ pivotY: ne,
63
+ maxRoll: ne,
64
+ weightBand: ue,
65
+ turnBand: ue
66
66
  }),
67
67
  body: oe({
68
- pivotX: ee,
69
- pivotY: ee,
70
- maxRoll: ee,
71
- breathBand: he,
72
- rollBand: he,
68
+ pivotX: ne,
69
+ pivotY: ne,
70
+ maxRoll: ne,
71
+ breathBand: ue,
72
+ rollBand: ue,
73
73
  chest: ve,
74
74
  shoulders: ge(ve)
75
75
  }),
@@ -80,98 +80,98 @@ const ee = (n, e, t) => {
80
80
  eyeB: ve,
81
81
  earL: ve,
82
82
  earR: ve,
83
- brow: oe({ ...$e, band: he }),
84
- jaw: oe({ ...$e, band: he })
83
+ brow: oe({ ...Ce, band: ue }),
84
+ jaw: oe({ ...Ce, band: ue })
85
85
  }),
86
86
  buns: oe({ bunL: ve, bunR: ve }, ["bunL", "bunR"]),
87
87
  eyes: ge(oe({
88
- opening: Ze,
89
- roi: Ze,
90
- x0: ee,
91
- x1: ee,
92
- top: ge(ee, 24, 24),
93
- bot: ge(ee, 24, 24)
88
+ opening: We,
89
+ roi: We,
90
+ x0: ne,
91
+ x1: ne,
92
+ top: ge(ne, 24, 24),
93
+ bot: ge(ne, 24, 24)
94
94
  }, n ? ["x0", "x1", "top", "bot"] : []), 2, 2),
95
95
  mouth: oe({
96
- cx: ee,
97
- cy: ee,
98
- angle: ee,
99
- halfLen: _e,
100
- bow: ee,
101
- area: oe({ ...$e, angle: ee })
96
+ cx: ne,
97
+ cy: ne,
98
+ angle: ne,
99
+ halfLen: Le,
100
+ bow: ne,
101
+ area: oe({ ...Ce, angle: ne })
102
102
  }),
103
103
  cheeks: ge(ye, 2, 2),
104
- strands: ge(oe({ name: Bt, nodes: Ut, sigma: _e, k: _e, max: _e })),
104
+ strands: ge(oe({ name: jt, nodes: It, sigma: Le, k: Le, max: Le })),
105
105
  accessories: ge(oe({
106
- name: Bt,
106
+ name: jt,
107
107
  pivot: ye,
108
108
  tip: ye,
109
- split: et,
110
- box: ge(Ue, 4, 4),
111
- color: oe({ redness: et, minRed: ee })
109
+ split: nt,
110
+ box: ge(Ie, 4, 4),
111
+ color: oe({ redness: nt, minRed: ne })
112
112
  })),
113
113
  hand: oe({
114
- outline: Ze,
115
- jaw: Ut,
116
- jawRange: he,
117
- background: Ze,
114
+ outline: We,
115
+ jaw: It,
116
+ jawRange: ue,
117
+ background: We,
118
118
  elbow: ye,
119
119
  wrist: ye,
120
120
  knuckle: ye,
121
121
  contact: ye,
122
- forearmShare: et,
123
- armBand: he,
124
- wristBand: he,
125
- handBand: he,
126
- fingerXBand: he,
127
- fingerYBand: he,
128
- pinBand: he
122
+ forearmShare: nt,
123
+ armBand: ue,
124
+ wristBand: ue,
125
+ handBand: ue,
126
+ fingerXBand: ue,
127
+ fingerYBand: ue,
128
+ pinBand: ue
129
129
  }),
130
130
  mesh: oe({
131
- baseCell: Ae,
131
+ baseCell: we,
132
132
  fine: oe({
133
- x0: Ue,
134
- x1: Ue,
135
- y0: Ue,
136
- y1: Ue,
137
- cell: Ae
133
+ x0: Ie,
134
+ x1: Ie,
135
+ y0: Ie,
136
+ y1: Ie,
137
+ cell: we
138
138
  }),
139
- handCell: Ae,
140
- tasselCell: Ae,
141
- eyeBallCell: Ae,
142
- eyeCell: Ae,
143
- spriteCell: Ae
139
+ handCell: we,
140
+ tasselCell: we,
141
+ eyeBallCell: we,
142
+ eyeCell: we,
143
+ spriteCell: we
144
144
  }),
145
- view: oe({ padTop: ee, padSide: ee, gazeCenter: ye }, ["gazeCenter"])
145
+ view: oe({ padTop: ne, padSide: ne, gazeCenter: ye }, ["gazeCenter"])
146
146
  }, ["buns", "strands", "accessories", "hand"]);
147
- function Qt(n, e = {}) {
147
+ function en(n, e = {}) {
148
148
  const t = [];
149
- if (vn(e.draft ?? !1)(n, "rig", t), t.length) return t;
149
+ if (bn(e.draft ?? !1)(n, "rig", t), t.length) return t;
150
150
  const r = n;
151
- r.eyes.forEach((a, o) => {
152
- const i = ["x0", "x1", "top", "bot"];
153
- if (!(e.draft && i.every((f) => a[f] === void 0))) {
154
- if (i.some((f) => a[f] === void 0)) {
155
- t.push(`rig.eyes[${o}]: supply all x0/x1/top/bot fields or omit all in a draft`);
151
+ r.eyes.forEach((a, s) => {
152
+ const l = ["x0", "x1", "top", "bot"];
153
+ if (!(e.draft && l.every((f) => a[f] === void 0))) {
154
+ if (l.some((f) => a[f] === void 0)) {
155
+ t.push(`rig.eyes[${s}]: supply all x0/x1/top/bot fields or omit all in a draft`);
156
156
  return;
157
157
  }
158
- a.x0 >= a.x1 && t.push(`rig.eyes[${o}].x1: must exceed x0`), a.top.some((f, m) => f > a.bot[m]) && t.push(`rig.eyes[${o}].top: must not exceed bottom curve`);
158
+ a.x0 >= a.x1 && t.push(`rig.eyes[${s}].x1: must exceed x0`), a.top.some((f, y) => f > a.bot[y]) && t.push(`rig.eyes[${s}].top: must not exceed bottom curve`);
159
159
  }
160
160
  }), (r.mesh.fine.x0 >= r.mesh.fine.x1 || r.mesh.fine.y0 >= r.mesh.fine.y1) && t.push("rig.mesh.fine: rectangle must have positive area"), (r.view.padTop <= -1 || r.view.padTop >= 1 || r.view.padSide <= -0.5) && t.push("rig.view: margins must leave a positive viewport");
161
- for (const [a, o] of (r.strands ?? []).entries())
162
- o.nodes.some((i, f) => f > 0 && i[0] === o.nodes[f - 1][0] && i[1] === o.nodes[f - 1][1]) && t.push(`rig.strands[${a}].nodes: consecutive nodes must differ`);
163
- for (const [a, o] of (r.accessories ?? []).entries())
164
- (o.box[0] < 0 || o.box[1] < 0 || o.box[2] > r.image.width || o.box[3] > r.image.height) && t.push(`rig.accessories[${a}].box: rectangle must stay inside the image`), (o.split <= 0 || o.split >= 1) && t.push(`rig.accessories[${a}].split: must be strictly between 0 and 1`), o.pivot.every((i, f) => i === o.tip[f]) && t.push(`rig.accessories[${a}].tip: must differ from pivot`), (o.box[0] >= o.box[2] || o.box[1] >= o.box[3]) && t.push(`rig.accessories[${a}].box: rectangle must have positive area`);
161
+ for (const [a, s] of (r.strands ?? []).entries())
162
+ s.nodes.some((l, f) => f > 0 && l[0] === s.nodes[f - 1][0] && l[1] === s.nodes[f - 1][1]) && t.push(`rig.strands[${a}].nodes: consecutive nodes must differ`);
163
+ for (const [a, s] of (r.accessories ?? []).entries())
164
+ (s.box[0] < 0 || s.box[1] < 0 || s.box[2] > r.image.width || s.box[3] > r.image.height) && t.push(`rig.accessories[${a}].box: rectangle must stay inside the image`), (s.split <= 0 || s.split >= 1) && t.push(`rig.accessories[${a}].split: must be strictly between 0 and 1`), s.pivot.every((l, f) => l === s.tip[f]) && t.push(`rig.accessories[${a}].tip: must differ from pivot`), (s.box[0] >= s.box[2] || s.box[1] >= s.box[3]) && t.push(`rig.accessories[${a}].box: rectangle must have positive area`);
165
165
  return t;
166
166
  }
167
- function wt(n) {
168
- const e = Qt(n);
167
+ function Et(n) {
168
+ const e = en(n);
169
169
  if (e.length) throw new Error(`Invalid rig:
170
170
  ${e.join(`
171
171
  `)}`);
172
172
  return structuredClone(n);
173
173
  }
174
- const We = [
174
+ const Ge = [
175
175
  { id: "angleX", label: "Face angle X", min: -30, max: 30, def: 0, group: "Head and body" },
176
176
  { id: "angleY", label: "Face angle Y", min: -30, max: 30, def: 0, group: "Head and body" },
177
177
  { id: "angleZ", label: "Face roll", min: -30, max: 30, def: 0, group: "Head and body" },
@@ -192,253 +192,253 @@ const We = [
192
192
  { id: "handAngle", label: "Wrist angle", min: -10, max: 10, def: 0, group: "Hand" },
193
193
  { id: "fingerTap", label: "Finger tap", min: 0, max: 1, def: 0, group: "Hand" }
194
194
  ];
195
- function bn(n) {
196
- const e = { w: n.image.width, h: n.image.height }, t = (b, M, S) => S ? Math.exp(-(((b - S.cx) / S.rx) ** 2 + ((M - S.cy) / S.ry) ** 2)) : 0, r = 24, a = n.eyes;
197
- function o(b, M) {
198
- const S = Math.min(1, Math.max(0, M)) * (r - 1), L = Math.min(Math.floor(S), r - 2), U = S - L;
199
- return b[L] + (b[L + 1] - b[L]) * U;
195
+ function xn(n) {
196
+ const e = { w: n.image.width, h: n.image.height }, t = (x, M, T) => T ? Math.exp(-(((x - T.cx) / T.rx) ** 2 + ((M - T.cy) / T.ry) ** 2)) : 0, r = 24, a = n.eyes;
197
+ function s(x, M) {
198
+ const T = Math.min(1, Math.max(0, M)) * (r - 1), _ = Math.min(Math.floor(T), r - 2), Y = T - _;
199
+ return x[_] + (x[_ + 1] - x[_]) * Y;
200
200
  }
201
- function i(b, M, S, L) {
201
+ function l(x, M, T, _) {
202
202
  M = Math.min(1, Math.max(0, M));
203
- const U = o(b.top, M), X = o(b.bot, M), k = 1 - S, P = 4 * M * (1 - M), A = o(b.bot, 0.5) - o(b.top, 0.5), R = b.top[0] + (b.top[r - 1] - b.top[0]) * M - 0.3 * A * P, C = Math.max(U, X + 1 + (R - X - 1) * L);
204
- return [(C - U) * Math.max(k, -0.07), k > 0 ? (C - X) * k * L : 0];
205
- }
206
- const f = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]], m = 5;
207
- function g(b, M, S, L) {
208
- let U = 0, X = 0;
209
- for (const [R, C] of f) {
210
- const [Q, te] = i(b, (M + R * m - b.x0) / (b.x1 - b.x0), S, L);
211
- U += Q * C / 9, X += te * C / 9;
212
- }
213
- const k = Math.min(1, Math.max(0, (M - b.x0) / (b.x1 - b.x0))), P = o(b.top, k), A = o(b.bot, k);
214
- return { top: P, bot: A, b: 1 - S, lid: P + U, bc: A + X };
215
- }
216
- function p(b, M, S, L, U, X) {
217
- const k = g(b, S, U, X);
218
- return M === "lash" ? k.lid - (k.top - L) * (1 - 0.3 * Math.min(1, Math.max(0, k.b))) : M === "low" ? L + (k.bc - k.bot) : M === "crease" ? L + (k.lid - k.top) * 0.22 : L;
219
- }
220
- function l(b, M, S) {
221
- const L = Math.min(1, Math.max(0, 1 - M));
222
- return b === "low" ? 1 - Math.min(1, L * S * 1.2) : b === "crease" ? 1 - 0.45 * L : 1;
223
- }
224
- const h = n.mouth, E = n.cheeks, y = n.head, u = n.body, v = (b, M, S) => {
225
- const L = Math.min(1, Math.max(0, (S - b) / (M - b)));
226
- return L * L * (3 - 2 * L);
203
+ const Y = s(x.top, M), X = s(x.bot, M), F = 1 - T, C = 4 * M * (1 - M), Z = s(x.bot, 0.5) - s(x.top, 0.5), E = x.top[0] + (x.top[r - 1] - x.top[0]) * M - 0.3 * Z * C, R = Math.max(Y, X + 1 + (E - X - 1) * _);
204
+ return [(R - Y) * Math.max(F, -0.07), F > 0 ? (R - X) * F * _ : 0];
205
+ }
206
+ const f = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]], y = 5;
207
+ function d(x, M, T, _) {
208
+ let Y = 0, X = 0;
209
+ for (const [E, R] of f) {
210
+ const [J, te] = l(x, (M + E * y - x.x0) / (x.x1 - x.x0), T, _);
211
+ Y += J * R / 9, X += te * R / 9;
212
+ }
213
+ const F = Math.min(1, Math.max(0, (M - x.x0) / (x.x1 - x.x0))), C = s(x.top, F), Z = s(x.bot, F);
214
+ return { top: C, bot: Z, b: 1 - T, lid: C + Y, bc: Z + X };
215
+ }
216
+ function m(x, M, T, _, Y, X) {
217
+ const F = d(x, T, Y, X);
218
+ return M === "lash" ? F.lid - (F.top - _) * (1 - 0.3 * Math.min(1, Math.max(0, F.b))) : M === "low" ? _ + (F.bc - F.bot) : M === "crease" ? _ + (F.lid - F.top) * 0.22 : _;
219
+ }
220
+ function c(x, M, T) {
221
+ const _ = Math.min(1, Math.max(0, 1 - M));
222
+ return x === "low" ? 1 - Math.min(1, _ * T * 1.2) : x === "crease" ? 1 - 0.45 * _ : 1;
223
+ }
224
+ const p = n.mouth, b = n.cheeks, v = n.head, h = n.body, u = (x, M, T) => {
225
+ const _ = Math.min(1, Math.max(0, (T - x) / (M - x)));
226
+ return _ * _ * (3 - 2 * _);
227
227
  };
228
- function x(b, M) {
229
- return 1 - v(...y.weightBand, M);
230
- }
231
- function s(b, M) {
232
- return 1 - v(...y.turnBand, M);
233
- }
234
- const c = n.strands ?? [];
235
- function T(b, M, S) {
236
- let L = 1 / 0, U = 0;
237
- const X = S.length - 1;
238
- for (let k = 0; k < X; k++) {
239
- const [P, A] = S[k], [R, C] = S[k + 1], Q = R - P, te = C - A, ne = Math.min(1, Math.max(0, ((b - P) * Q + (M - A) * te) / (Q * Q + te * te))), ie = Math.hypot(b - P - Q * ne, M - A - te * ne);
240
- ie < L && (L = ie, U = (k + ne) / X);
241
- }
242
- return [L, U];
243
- }
244
- function d(b, M, S) {
245
- if (S < 0.02) return [];
246
- const L = [];
247
- let U = 0;
248
- c.forEach((k, P) => {
249
- const [A, R] = T(b, M, k.nodes), C = Math.exp(-((A / k.sigma) ** 2));
250
- C < 0.02 || (L.push([P, C, R]), U += C);
228
+ function w(x, M) {
229
+ return 1 - u(...v.weightBand, M);
230
+ }
231
+ function o(x, M) {
232
+ return 1 - u(...v.turnBand, M);
233
+ }
234
+ const i = n.strands ?? [];
235
+ function S(x, M, T) {
236
+ let _ = 1 / 0, Y = 0;
237
+ const X = T.length - 1;
238
+ for (let F = 0; F < X; F++) {
239
+ const [C, Z] = T[F], [E, R] = T[F + 1], J = E - C, te = R - Z, ee = Math.min(1, Math.max(0, ((x - C) * J + (M - Z) * te) / (J * J + te * te))), se = Math.hypot(x - C - J * ee, M - Z - te * ee);
240
+ se < _ && (_ = se, Y = (F + ee) / X);
241
+ }
242
+ return [_, Y];
243
+ }
244
+ function g(x, M, T) {
245
+ if (T < 0.02) return [];
246
+ const _ = [];
247
+ let Y = 0;
248
+ i.forEach((F, C) => {
249
+ const [Z, E] = S(x, M, F.nodes), R = Math.exp(-((Z / F.sigma) ** 2));
250
+ R < 0.02 || (_.push([C, R, E]), Y += R);
251
251
  });
252
- const X = Math.max(1, U);
253
- return L.map(([k, P, A]) => [k, S * P / X * v(0.04, 0.55, A), A]);
252
+ const X = Math.max(1, Y);
253
+ return _.map(([F, C, Z]) => [F, T * C / X * u(0.04, 0.55, Z), Z]);
254
254
  }
255
- function w(b, M, S = 1) {
255
+ function A(x, M, T = 1) {
256
256
  return {
257
- head: x(b, M),
258
- turn: s(b, M),
259
- strands: d(b, M, S),
260
- bunL: t(b, M, n.buns?.bunL),
261
- bunR: t(b, M, n.buns?.bunR),
262
- brow: t(b, M, n.face.brow) * (1 - v(...n.face.brow.band, M)),
257
+ head: w(x, M),
258
+ turn: o(x, M),
259
+ strands: g(x, M, T),
260
+ bunL: t(x, M, n.buns?.bunL),
261
+ bunR: t(x, M, n.buns?.bunR),
262
+ brow: t(x, M, n.face.brow) * (1 - u(...n.face.brow.band, M)),
263
263
  // chin below the mouth line drops a little when the mouth opens
264
- jaw: t(b, M, n.face.jaw) * v(...n.face.jaw.band, M),
264
+ jaw: t(x, M, n.face.jaw) * u(...n.face.jaw.band, M),
265
265
  // per-feature depth for head turns (nose sticks out most, ears sit at the back)
266
- nose: t(b, M, n.face.nose),
267
- mouth: t(b, M, n.face.mouth),
268
- eyeA: t(b, M, n.face.eyeA),
269
- eyeB: t(b, M, n.face.eyeB),
270
- earR: t(b, M, n.face.earR),
271
- earL: t(b, M, n.face.earL),
272
- chest: t(b, M, u.chest),
273
- breath: 1 - v(...u.breathBand, M),
274
- shoulder: u.shoulders.reduce((L, U) => L + t(b, M, U), 0)
266
+ nose: t(x, M, n.face.nose),
267
+ mouth: t(x, M, n.face.mouth),
268
+ eyeA: t(x, M, n.face.eyeA),
269
+ eyeB: t(x, M, n.face.eyeB),
270
+ earR: t(x, M, n.face.earR),
271
+ earL: t(x, M, n.face.earL),
272
+ chest: t(x, M, h.chest),
273
+ breath: 1 - u(...h.breathBand, M),
274
+ shoulder: h.shoulders.reduce((_, Y) => _ + t(x, M, Y), 0)
275
275
  };
276
276
  }
277
- function F(b, M, S, L) {
278
- const U = (b - y.cx) / y.rx, X = (M - y.cy) / y.ry, k = 1 - U * U - X * X;
279
- if (k <= 0) return [0, 0];
280
- const P = v(0, 0.84, k);
281
- return [S * y.shiftX * P, -L * y.shiftY * P];
282
- }
283
- function Y(b, M, S, L) {
284
- const U = Math.cos(L), X = Math.sin(L), k = b[0] - M, P = b[1] - S;
285
- b[0] = M + k * U - P * X, b[1] = S + k * X + P * U;
286
- }
287
- function I(b, M, S, L = M) {
288
- const U = F(b[0], b[1], S.angleX / 30, S.angleY / 30);
289
- b[0] += U[0] * L, b[1] += U[1] * L, !(M <= 0) && Y(b, y.pivotX, y.pivotY, -S.angleZ / 30 * y.maxRoll * M);
290
- }
291
- function _(b, M, S, L = 0, U = 1, X = 0) {
292
- const k = S.breath;
293
- b[1] -= k * (5 * U + 4 * X), b[0] += (b[0] - u.chest.cx) * 0.012 * k * L, b[0] += S.bodyAngleX / 10 * (7 + 9 * L), Y(b, u.pivotX, u.pivotY, -S.bodyAngleZ / 10 * u.maxRoll * (1 - v(...u.rollBand, M)));
294
- }
295
- function B(b, M, S, L, U, X) {
296
- const k = X;
297
- k[0] = b, k[1] = M;
298
- const P = U.gain;
299
- for (const [C, Q, te] of S.strands) {
300
- const ne = U.strands?.[C];
301
- if (!ne) continue;
302
- const ie = te * 3, se = Math.min(2, Math.floor(ie)), me = ie - se;
303
- k[0] += (ne[se][0] + (ne[se + 1][0] - ne[se][0]) * me) * Q * P, k[1] += (ne[se][1] + (ne[se + 1][1] - ne[se][1]) * me) * Q * P;
304
- }
305
- if (k[0] += (U.bunL[0] * S.bunL + U.bunR[0] * S.bunR) * P, k[1] += (U.bunL[1] * S.bunL + U.bunR[1] * S.bunR) * P, k[1] -= L.browY * 7 * S.brow, S.brow > 0.01) {
306
- const C = L.browAngle * 0.12 * S.brow;
307
- k[1] += (b - n.face.brow.cx) * Math.sin(C);
308
- }
309
- k[1] += L.mouthOpen * 3.5 * S.jaw;
310
- const A = L.angleX / 30, R = L.angleY / 30;
311
- return k[0] += A * (8 * S.nose + 5 * S.mouth) + (b - n.face.eyeA.cx) * 0.12 * A * S.eyeA - (b - n.face.eyeB.cx) * 0.12 * A * S.eyeB - A * 9 * S.earR + A * 4 * S.earL - A * 10 * (S.bunL + S.bunR), k[1] -= R * (6 * S.nose + 3 * S.mouth), k[1] += (M - n.face.eyeA.cy) * -0.06 * Math.abs(R) * S.eyeA + (M - n.face.eyeB.cy) * -0.06 * Math.abs(R) * S.eyeB, I(k, S.head, L, S.turn), _(k, M, L, S.chest, S.breath, S.shoulder), k;
312
- }
313
- const O = n.hand, z = O?.elbow ?? [0, 0], D = O?.wrist ?? [0, 0], J = O?.knuckle ?? [0, 0], j = O?.contact ?? [0, 0], H = O?.forearmShare ?? 0;
314
- function Z(b, M) {
277
+ function L(x, M, T, _) {
278
+ const Y = (x - v.cx) / v.rx, X = (M - v.cy) / v.ry, F = 1 - Y * Y - X * X;
279
+ if (F <= 0) return [0, 0];
280
+ const C = u(0, 0.84, F);
281
+ return [T * v.shiftX * C, -_ * v.shiftY * C];
282
+ }
283
+ function B(x, M, T, _) {
284
+ const Y = Math.cos(_), X = Math.sin(_), F = x[0] - M, C = x[1] - T;
285
+ x[0] = M + F * Y - C * X, x[1] = T + F * X + C * Y;
286
+ }
287
+ function j(x, M, T, _ = M) {
288
+ const Y = L(x[0], x[1], T.angleX / 30, T.angleY / 30);
289
+ x[0] += Y[0] * _, x[1] += Y[1] * _, !(M <= 0) && B(x, v.pivotX, v.pivotY, -T.angleZ / 30 * v.maxRoll * M);
290
+ }
291
+ function k(x, M, T, _ = 0, Y = 1, X = 0) {
292
+ const F = T.breath;
293
+ x[1] -= F * (5 * Y + 4 * X), x[0] += (x[0] - h.chest.cx) * 0.012 * F * _, x[0] += T.bodyAngleX / 10 * (7 + 9 * _), B(x, h.pivotX, h.pivotY, -T.bodyAngleZ / 10 * h.maxRoll * (1 - u(...h.rollBand, M)));
294
+ }
295
+ function U(x, M, T, _, Y, X) {
296
+ const F = X;
297
+ F[0] = x, F[1] = M;
298
+ const C = Y.gain;
299
+ for (const [R, J, te] of T.strands) {
300
+ const ee = Y.strands?.[R];
301
+ if (!ee) continue;
302
+ const se = te * 3, le = Math.min(2, Math.floor(se)), ce = se - le;
303
+ F[0] += (ee[le][0] + (ee[le + 1][0] - ee[le][0]) * ce) * J * C, F[1] += (ee[le][1] + (ee[le + 1][1] - ee[le][1]) * ce) * J * C;
304
+ }
305
+ if (F[0] += (Y.bunL[0] * T.bunL + Y.bunR[0] * T.bunR) * C, F[1] += (Y.bunL[1] * T.bunL + Y.bunR[1] * T.bunR) * C, F[1] -= _.browY * 7 * T.brow, T.brow > 0.01) {
306
+ const R = _.browAngle * 0.12 * T.brow;
307
+ F[1] += (x - n.face.brow.cx) * Math.sin(R);
308
+ }
309
+ F[1] += _.mouthOpen * 3.5 * T.jaw;
310
+ const Z = _.angleX / 30, E = _.angleY / 30;
311
+ return F[0] += Z * (8 * T.nose + 5 * T.mouth) + (x - n.face.eyeA.cx) * 0.12 * Z * T.eyeA - (x - n.face.eyeB.cx) * 0.12 * Z * T.eyeB - Z * 9 * T.earR + Z * 4 * T.earL - Z * 10 * (T.bunL + T.bunR), F[1] -= E * (6 * T.nose + 3 * T.mouth), F[1] += (M - n.face.eyeA.cy) * -0.06 * Math.abs(E) * T.eyeA + (M - n.face.eyeB.cy) * -0.06 * Math.abs(E) * T.eyeB, j(F, T.head, _, T.turn), k(F, M, _, T.chest, T.breath, T.shoulder), F;
312
+ }
313
+ const O = n.hand, $ = O?.elbow ?? [0, 0], D = O?.wrist ?? [0, 0], q = O?.knuckle ?? [0, 0], N = O?.contact ?? [0, 0], P = O?.forearmShare ?? 0;
314
+ function H(x, M) {
315
315
  return O ? {
316
- arm: 1 - v(...O.armBand, M),
317
- wrist: 1 - v(...O.wristBand, M),
318
- hand: 1 - v(...O.handBand, M),
319
- finger: v(...O.fingerXBand, b) * (1 - v(...O.fingerYBand, M)),
320
- pinBottom: v(...O.pinBand, M)
316
+ arm: 1 - u(...O.armBand, M),
317
+ wrist: 1 - u(...O.wristBand, M),
318
+ hand: 1 - u(...O.handBand, M),
319
+ finger: u(...O.fingerXBand, x) * (1 - u(...O.fingerYBand, M)),
320
+ pinBottom: u(...O.pinBand, M)
321
321
  } : { arm: 0, wrist: 0, hand: 0, finger: 0, pinBottom: 0 };
322
322
  }
323
- const $ = (b, M, S, L) => {
324
- const U = b[0] - M[0], X = b[1] - M[1];
325
- return [M[0] + U * S - X * L, M[1] + U * L + X * S];
326
- }, q = (b) => Math.atan2(b[1], b[0]);
327
- function W(b) {
328
- const M = [...j];
329
- I(M, x(...j), b, s(...j)), _(M, j[1], b, 0, 1, 0);
330
- const S = [...z];
331
- _(S, z[1], b, 0, 0, 0);
332
- const U = (q([M[0] - S[0], M[1] - S[1]]) - q([j[0] - z[0], j[1] - z[1]])) * H, X = Math.cos(U), k = Math.sin(U), P = (te) => {
333
- const ne = $(te, z, X, k);
334
- return [ne[0] + S[0] - z[0], ne[1] + S[1] - z[1]];
335
- }, A = P(D), R = P(j), C = q([M[0] - A[0], M[1] - A[1]]) - q([R[0] - A[0], R[1] - A[1]]), Q = Math.min(1.03, Math.max(0.97, Math.hypot(M[0] - A[0], M[1] - A[1]) / Math.hypot(R[0] - A[0], R[1] - A[1])));
336
- return { tr: P, w: A, b: C, k: Q };
337
- }
338
- function N(b, M, S, L, U, X) {
339
- let k = [b, M];
340
- k = $(k, J, Math.cos(L.fingerTap * 0.07 * S.finger), Math.sin(L.fingerTap * 0.07 * S.finger));
341
- const P = -L.handAngle / 10 * 0.045 * S.wrist, A = -L.armAngle / 10 * 0.015 * S.arm;
342
- k = $(k, D, Math.cos(P), Math.sin(P)), k = $(k, z, Math.cos(A), Math.sin(A)), k = U.tr(k);
343
- const R = U.b * S.hand, C = 1 + (U.k - 1) * S.hand;
344
- return k = $(k, U.w, Math.cos(R) * C, Math.sin(R) * C), k[1] += (M - k[1]) * S.pinBottom, X[0] = k[0], X[1] = k[1], X;
345
- }
346
- const G = n.accessories ?? [];
347
- function V(b, M, S, L) {
348
- const U = w(b.pivot[0], b.pivot[1]);
349
- return B(b.pivot[0], b.pivot[1], U, M, S, L);
350
- }
351
- return { IMG: e, EYES: a, MOUTH: h, CHEEKS: E, STRANDS: c, TASSELS: G, headWeight: x, turnWeight: s, baseWeights: w, deformBase: B, applyHead: I, applyBody: _, handWeights: Z, handFrame: W, deformHand: N, eyePartY: p, eyePartAlpha: l, tasselAnchor: V };
323
+ const G = (x, M, T, _) => {
324
+ const Y = x[0] - M[0], X = x[1] - M[1];
325
+ return [M[0] + Y * T - X * _, M[1] + Y * _ + X * T];
326
+ }, z = (x) => Math.atan2(x[1], x[0]);
327
+ function W(x) {
328
+ const M = [...N];
329
+ j(M, w(...N), x, o(...N)), k(M, N[1], x, 0, 1, 0);
330
+ const T = [...$];
331
+ k(T, $[1], x, 0, 0, 0);
332
+ const Y = (z([M[0] - T[0], M[1] - T[1]]) - z([N[0] - $[0], N[1] - $[1]])) * P, X = Math.cos(Y), F = Math.sin(Y), C = (te) => {
333
+ const ee = G(te, $, X, F);
334
+ return [ee[0] + T[0] - $[0], ee[1] + T[1] - $[1]];
335
+ }, Z = C(D), E = C(N), R = z([M[0] - Z[0], M[1] - Z[1]]) - z([E[0] - Z[0], E[1] - Z[1]]), J = Math.min(1.03, Math.max(0.97, Math.hypot(M[0] - Z[0], M[1] - Z[1]) / Math.hypot(E[0] - Z[0], E[1] - Z[1])));
336
+ return { tr: C, w: Z, b: R, k: J };
337
+ }
338
+ function I(x, M, T, _, Y, X) {
339
+ let F = [x, M];
340
+ F = G(F, q, Math.cos(_.fingerTap * 0.07 * T.finger), Math.sin(_.fingerTap * 0.07 * T.finger));
341
+ const C = -_.handAngle / 10 * 0.045 * T.wrist, Z = -_.armAngle / 10 * 0.015 * T.arm;
342
+ F = G(F, D, Math.cos(C), Math.sin(C)), F = G(F, $, Math.cos(Z), Math.sin(Z)), F = Y.tr(F);
343
+ const E = Y.b * T.hand, R = 1 + (Y.k - 1) * T.hand;
344
+ return F = G(F, Y.w, Math.cos(E) * R, Math.sin(E) * R), F[1] += (M - F[1]) * T.pinBottom, X[0] = F[0], X[1] = F[1], X;
345
+ }
346
+ const V = n.accessories ?? [];
347
+ function K(x, M, T, _) {
348
+ const Y = A(x.pivot[0], x.pivot[1]);
349
+ return U(x.pivot[0], x.pivot[1], Y, M, T, _);
350
+ }
351
+ return { IMG: e, EYES: a, MOUTH: p, CHEEKS: b, STRANDS: i, TASSELS: V, headWeight: w, turnWeight: o, baseWeights: A, deformBase: U, applyHead: j, applyBody: k, handWeights: H, handFrame: W, deformHand: I, eyePartY: m, eyePartAlpha: c, tasselAnchor: K };
352
352
  }
353
- function xn(n, e, t, r = !1) {
354
- const a = r ? Math.max(e, t) * 2 : 1, o = new Float32Array(n.length), i = Math.SQRT2;
355
- for (let f = 0; f < t; f++) for (let m = 0; m < e; m++) {
356
- const g = f * e + m;
357
- n[g] <= 3 || (o[g] = Math.min(
358
- m ? o[g - 1] + 1 : a,
359
- f ? o[g - e] + 1 : a,
360
- m && f ? o[g - e - 1] + i : a,
361
- f && m + 1 < e ? o[g - e + 1] + i : a
353
+ function wn(n, e, t, r = !1) {
354
+ const a = r ? Math.max(e, t) * 2 : 1, s = new Float32Array(n.length), l = Math.SQRT2;
355
+ for (let f = 0; f < t; f++) for (let y = 0; y < e; y++) {
356
+ const d = f * e + y;
357
+ n[d] <= 3 || (s[d] = Math.min(
358
+ y ? s[d - 1] + 1 : a,
359
+ f ? s[d - e] + 1 : a,
360
+ y && f ? s[d - e - 1] + l : a,
361
+ f && y + 1 < e ? s[d - e + 1] + l : a
362
362
  ));
363
363
  }
364
- for (let f = t - 1; f >= 0; f--) for (let m = e - 1; m >= 0; m--) {
365
- const g = f * e + m;
366
- !n[g] || n[g] <= 3 || (o[g] = Math.min(
367
- o[g],
368
- m + 1 < e ? o[g + 1] + 1 : a,
369
- f + 1 < t ? o[g + e] + 1 : a,
370
- m && f + 1 < t ? o[g + e - 1] + i : a,
371
- m + 1 < e && f + 1 < t ? o[g + e + 1] + i : a
364
+ for (let f = t - 1; f >= 0; f--) for (let y = e - 1; y >= 0; y--) {
365
+ const d = f * e + y;
366
+ !n[d] || n[d] <= 3 || (s[d] = Math.min(
367
+ s[d],
368
+ y + 1 < e ? s[d + 1] + 1 : a,
369
+ f + 1 < t ? s[d + e] + 1 : a,
370
+ y && f + 1 < t ? s[d + e - 1] + l : a,
371
+ y + 1 < e && f + 1 < t ? s[d + e + 1] + l : a
372
372
  ));
373
373
  }
374
- return o;
374
+ return s;
375
375
  }
376
- function tt(n, e, t) {
376
+ function rt(n, e, t) {
377
377
  return Math.exp(-(((n - t.cx) / t.rx) ** 2 + ((e - t.cy) / t.ry) ** 2));
378
378
  }
379
- function wn(n, e, t) {
379
+ function An(n, e, t) {
380
380
  const r = ((n - t.head.cx) / t.head.rx) ** 2 + ((e - t.head.cy) / t.head.ry) ** 2;
381
- let a = t.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + t.body.chest.rx * 0.23 * tt(n, e, t.body.chest);
382
- a += t.face.nose.rx * 0.2 * tt(n, e, t.face.nose);
383
- for (const [o, i] of t.cheeks) a += t.head.rx * 0.012 * tt(n, e, { cx: o, cy: i, rx: t.head.rx * 0.3, ry: t.head.ry * 0.16 });
381
+ let a = t.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + t.body.chest.rx * 0.23 * rt(n, e, t.body.chest);
382
+ a += t.face.nose.rx * 0.2 * rt(n, e, t.face.nose);
383
+ for (const [s, l] of t.cheeks) a += t.head.rx * 0.012 * rt(n, e, { cx: s, cy: l, rx: t.head.rx * 0.3, ry: t.head.ry * 0.16 });
384
384
  return a;
385
385
  }
386
- function qe(n, e, t, r) {
387
- const a = new Float32Array(n.length), o = new Float32Array(n.length), i = (f, m, g, p, l, h) => {
388
- for (let E = 0; E < p; E++) {
389
- const y = E * h;
390
- let u = 0, v = 0;
391
- for (let x = 0; x < Math.min(r, g - 1) + 1; x++)
392
- u += f[y + x * l], v++;
393
- for (let x = 0; x < g; x++) {
394
- m[y + x * l] = u / v;
395
- const s = x + r + 1, c = x - r;
396
- s < g && (u += f[y + s * l], v++), c >= 0 && (u -= f[y + c * l], v--);
386
+ function Ke(n, e, t, r) {
387
+ const a = new Float32Array(n.length), s = new Float32Array(n.length), l = (f, y, d, m, c, p) => {
388
+ for (let b = 0; b < m; b++) {
389
+ const v = b * p;
390
+ let h = 0, u = 0;
391
+ for (let w = 0; w < Math.min(r, d - 1) + 1; w++)
392
+ h += f[v + w * c], u++;
393
+ for (let w = 0; w < d; w++) {
394
+ y[v + w * c] = h / u;
395
+ const o = w + r + 1, i = w - r;
396
+ o < d && (h += f[v + o * c], u++), i >= 0 && (h -= f[v + i * c], u--);
397
397
  }
398
398
  }
399
399
  };
400
- return i(n, a, e, t, 1, e), i(a, o, t, e, e, 1), o;
400
+ return l(n, a, e, t, 1, e), l(a, s, t, e, e, 1), s;
401
401
  }
402
- function An(n, e, t, r) {
403
- const a = qe(n, t, r, 1), o = qe(n, t, r, 6), i = new Float32Array(n.length);
404
- for (let g = 0; g < i.length; g++) i[g] = e[g] > 128 ? a[g] - o[g] : 0;
405
- const f = new Float32Array(n.length * 2), m = (g, p) => i[Math.max(0, Math.min(r - 1, p)) * t + Math.max(0, Math.min(t - 1, g))];
406
- for (let g = 0; g < r; g++) for (let p = 0; p < t; p++) {
407
- const l = g * t + p;
408
- e[l] <= 128 || (f[2 * l] = Math.max(-1, Math.min(1, -(m(p + 1, g) - m(p - 1, g)) * 4)), f[2 * l + 1] = Math.max(-1, Math.min(1, -(m(p, g + 1) - m(p, g - 1)) * 4)));
402
+ function Mn(n, e, t, r) {
403
+ const a = Ke(n, t, r, 1), s = Ke(n, t, r, 6), l = new Float32Array(n.length);
404
+ for (let d = 0; d < l.length; d++) l[d] = e[d] > 128 ? a[d] - s[d] : 0;
405
+ const f = new Float32Array(n.length * 2), y = (d, m) => l[Math.max(0, Math.min(r - 1, m)) * t + Math.max(0, Math.min(t - 1, d))];
406
+ for (let d = 0; d < r; d++) for (let m = 0; m < t; m++) {
407
+ const c = d * t + m;
408
+ e[c] <= 128 || (f[2 * c] = Math.max(-1, Math.min(1, -(y(m + 1, d) - y(m - 1, d)) * 4)), f[2 * c + 1] = Math.max(-1, Math.min(1, -(y(m, d + 1) - y(m, d - 1)) * 4)));
409
409
  }
410
410
  return f;
411
411
  }
412
- function Mn(n, e, t, r, a, o = !0, i) {
413
- const f = !!a && r[0] === 0 && r[1] === 0 && r[2] === a.image.width && r[3] === a.image.height, m = xn(n, e, t, f), g = new Float32Array(n.length), p = r[2] / e, l = r[3] / t, h = Math.min(p, l), E = Math.min(r[2], r[3]) * 0.08;
414
- for (let s = 0; s < t; s++) for (let c = 0; c < e; c++) {
415
- const T = s * e + c;
416
- g[T] = (o ? Math.sqrt(m[T] * h * E) * 0.55 : 0) + (a ? wn(r[0] + (c + 0.5) * p, r[1] + (s + 0.5) * l, a) : 0);
417
- }
418
- const y = Math.max(1, Math.round(Math.min(e, t) * 0.02));
419
- g.set(qe(qe(g, e, t, y), e, t, y));
420
- const u = i ? An(i, n, e, t) : null, v = new Uint8Array(e * t * 4), x = (s, c) => g[Math.max(0, Math.min(t - 1, c)) * e + Math.max(0, Math.min(e - 1, s))];
421
- for (let s = 0; s < t; s++) for (let c = 0; c < e; c++) {
422
- const T = -(x(c + 2, s) - x(c - 2, s)) / (4 * p), d = -(x(c, s + 2) - x(c, s - 2)) / (4 * l), w = Math.hypot(T, d, 1), F = (s * e + c) * 4, Y = s * e + c;
423
- v[F] = Math.round((T / w * 0.5 + 0.5) * 255), v[F + 1] = Math.round((d / w * 0.5 + 0.5) * 255), v[F + 2] = Math.round(((u?.[2 * Y] ?? 0) * 0.5 + 0.5) * 255), v[F + 3] = Math.round(((u?.[2 * Y + 1] ?? 0) * 0.5 + 0.5) * 255);
424
- }
425
- return v;
412
+ function En(n, e, t, r, a, s = !0, l) {
413
+ const f = !!a && r[0] === 0 && r[1] === 0 && r[2] === a.image.width && r[3] === a.image.height, y = wn(n, e, t, f), d = new Float32Array(n.length), m = r[2] / e, c = r[3] / t, p = Math.min(m, c), b = Math.min(r[2], r[3]) * 0.08;
414
+ for (let o = 0; o < t; o++) for (let i = 0; i < e; i++) {
415
+ const S = o * e + i;
416
+ d[S] = (s ? Math.sqrt(y[S] * p * b) * 0.55 : 0) + (a ? An(r[0] + (i + 0.5) * m, r[1] + (o + 0.5) * c, a) : 0);
417
+ }
418
+ const v = Math.max(1, Math.round(Math.min(e, t) * 0.02));
419
+ d.set(Ke(Ke(d, e, t, v), e, t, v));
420
+ const h = l ? Mn(l, n, e, t) : null, u = new Uint8Array(e * t * 4), w = (o, i) => d[Math.max(0, Math.min(t - 1, i)) * e + Math.max(0, Math.min(e - 1, o))];
421
+ for (let o = 0; o < t; o++) for (let i = 0; i < e; i++) {
422
+ const S = -(w(i + 2, o) - w(i - 2, o)) / (4 * m), g = -(w(i, o + 2) - w(i, o - 2)) / (4 * c), A = Math.hypot(S, g, 1), L = (o * e + i) * 4, B = o * e + i;
423
+ u[L] = Math.round((S / A * 0.5 + 0.5) * 255), u[L + 1] = Math.round((g / A * 0.5 + 0.5) * 255), u[L + 2] = Math.round(((h?.[2 * B] ?? 0) * 0.5 + 0.5) * 255), u[L + 3] = Math.round(((h?.[2 * B + 1] ?? 0) * 0.5 + 0.5) * 255);
424
+ }
425
+ return u;
426
426
  }
427
- const Yt = /* @__PURE__ */ new WeakMap();
428
- function En(n, e, t, r) {
429
- const a = JSON.stringify([e, t.head, t.body.chest, t.face.nose, t.cheeks, r]), o = Yt.get(n);
430
- if (o?.key === a) return { ...o, computed: !1, ms: 0 };
431
- const i = performance.now(), f = Math.min(1, 512 / Math.max(n.width, n.height)), m = Math.max(1, Math.round(n.width * f)), g = Math.max(1, Math.round(n.height * f)), p = document.createElement("canvas");
432
- p.width = m, p.height = g;
433
- const l = p.getContext("2d", { willReadFrequently: !0 });
434
- l.drawImage(n, 0, 0, m, g);
435
- const h = l.getImageData(0, 0, m, g).data, E = new Uint8Array(m * g), y = new Float32Array(m * g);
436
- for (let v = 0; v < E.length; v++)
437
- E[v] = h[4 * v + 3], y[v] = (0.2126 * h[4 * v] + 0.7152 * h[4 * v + 1] + 0.0722 * h[4 * v + 2]) / 255;
438
- const u = { key: a, data: Mn(E, m, g, e, t, r, r ? y : void 0), width: m, height: g };
439
- return Yt.set(n, u), { ...u, computed: !0, ms: performance.now() - i };
427
+ const Nt = /* @__PURE__ */ new WeakMap();
428
+ function Sn(n, e, t, r) {
429
+ const a = JSON.stringify([e, t.head, t.body.chest, t.face.nose, t.cheeks, r]), s = Nt.get(n);
430
+ if (s?.key === a) return { ...s, computed: !1, ms: 0 };
431
+ const l = performance.now(), f = Math.min(1, 512 / Math.max(n.width, n.height)), y = Math.max(1, Math.round(n.width * f)), d = Math.max(1, Math.round(n.height * f)), m = document.createElement("canvas");
432
+ m.width = y, m.height = d;
433
+ const c = m.getContext("2d", { willReadFrequently: !0 });
434
+ c.drawImage(n, 0, 0, y, d);
435
+ const p = c.getImageData(0, 0, y, d).data, b = new Uint8Array(y * d), v = new Float32Array(y * d);
436
+ for (let u = 0; u < b.length; u++)
437
+ b[u] = p[4 * u + 3], v[u] = (0.2126 * p[4 * u] + 0.7152 * p[4 * u + 1] + 0.0722 * p[4 * u + 2]) / 255;
438
+ const h = { key: a, data: En(b, y, d, e, t, r, r ? v : void 0), width: y, height: d };
439
+ return Nt.set(n, h), { ...h, computed: !0, ms: performance.now() - l };
440
440
  }
441
- const Fe = Object.freeze({
441
+ const Ue = Object.freeze({
442
442
  enabled: !1,
443
443
  x: 0.2,
444
444
  y: 0.2,
@@ -455,7 +455,7 @@ const Fe = Object.freeze({
455
455
  specular: 0.12,
456
456
  rim: 0.3,
457
457
  detail: 0.4
458
- }), It = {
458
+ }), Xt = {
459
459
  x: [0, 1],
460
460
  y: [0, 1],
461
461
  z: [0.1, 2],
@@ -469,41 +469,41 @@ const Fe = Object.freeze({
469
469
  specular: [0, 1],
470
470
  rim: [0, 1],
471
471
  detail: [0, 1]
472
- }, Sn = /* @__PURE__ */ new Set(["color", "ambientColor"]);
473
- function Tn(n) {
472
+ }, Tn = /* @__PURE__ */ new Set(["color", "ambientColor"]);
473
+ function On(n) {
474
474
  if (!n || typeof n != "object" || Array.isArray(n)) return null;
475
475
  const e = n;
476
- if (Object.keys(e).length !== Object.keys(Fe).length || Object.keys(e).some((r) => !(r in Fe)) || ![!0, !1].includes(e.enabled) || ![!0, !1].includes(e.shadow) || !["soft", "cel"].includes(e.mode)) return null;
477
- const t = { ...Fe, enabled: e.enabled, shadow: e.shadow, mode: e.mode };
478
- for (const r of Object.keys(It)) {
479
- const a = e[r], [o, i] = It[r];
480
- if (typeof a != "number" || !Number.isFinite(a) || Sn.has(r) && !Number.isInteger(a)) return null;
481
- t[r] = Math.max(o, Math.min(i, a));
476
+ if (Object.keys(e).length !== Object.keys(Ue).length || Object.keys(e).some((r) => !(r in Ue)) || ![!0, !1].includes(e.enabled) || ![!0, !1].includes(e.shadow) || !["soft", "cel"].includes(e.mode)) return null;
477
+ const t = { ...Ue, enabled: e.enabled, shadow: e.shadow, mode: e.mode };
478
+ for (const r of Object.keys(Xt)) {
479
+ const a = e[r], [s, l] = Xt[r];
480
+ if (typeof a != "number" || !Number.isFinite(a) || Tn.has(r) && !Number.isInteger(a)) return null;
481
+ t[r] = Math.max(s, Math.min(l, a));
482
482
  }
483
483
  return t;
484
484
  }
485
- function _r(n) {
485
+ function Ur(n) {
486
486
  return `#${n.toString(16).padStart(6, "0")}`;
487
487
  }
488
- const Ge = -0.1, On = 0.9, Rn = 1, Ln = 1.06;
489
- function _n(n, e) {
488
+ const Ve = -0.1, Rn = 0.9, Ln = 1, _n = 1.06;
489
+ function kn(n, e) {
490
490
  return [(0.5 - n) * 0.12, (0.5 - e) * 0.12];
491
491
  }
492
- function kn(n, e, t, r) {
493
- const a = n * Math.PI / 180, o = e * Math.PI / 180, i = -t / 30 * r, f = Math.cos(a), m = Math.sin(a), g = Math.cos(o), p = Math.sin(o), l = Math.cos(i), h = Math.sin(i);
492
+ function Fn(n, e, t, r) {
493
+ const a = n * Math.PI / 180, s = e * Math.PI / 180, l = -t / 30 * r, f = Math.cos(a), y = Math.sin(a), d = Math.cos(s), m = Math.sin(s), c = Math.cos(l), p = Math.sin(l);
494
494
  return [
495
- l * f,
496
- h * f,
497
- -m,
498
- l * m * p - h * g,
499
- h * m * p + l * g,
500
- f * p,
501
- l * m * g + h * p,
502
- h * m * g - l * p,
503
- f * g
495
+ c * f,
496
+ p * f,
497
+ -y,
498
+ c * y * m - p * d,
499
+ p * y * m + c * d,
500
+ f * m,
501
+ c * y * d + p * m,
502
+ p * y * d - c * m,
503
+ f * d
504
504
  ];
505
505
  }
506
- class Fn {
506
+ class Bn {
507
507
  constructor(e, t) {
508
508
  this.gl = e, this.program = t(e, `#version 300 es
509
509
  out vec2 vUv;
@@ -521,19 +521,19 @@ class Fn {
521
521
  }`), this.vao = e.createVertexArray(), this.targets = [];
522
522
  }
523
523
  target(e, t) {
524
- const r = this.gl, a = r.createTexture(), o = r.createFramebuffer();
525
- if (r.bindTexture(r.TEXTURE_2D, a), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e, t, 0, r.RGBA, r.UNSIGNED_BYTE, null), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.bindFramebuffer(r.FRAMEBUFFER, o), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, a, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
526
- return { texture: a, framebuffer: o };
524
+ const r = this.gl, a = r.createTexture(), s = r.createFramebuffer();
525
+ if (r.bindTexture(r.TEXTURE_2D, a), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e, t, 0, r.RGBA, r.UNSIGNED_BYTE, null), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.bindFramebuffer(r.FRAMEBUFFER, s), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, a, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
526
+ return { texture: a, framebuffer: s };
527
527
  }
528
528
  begin(e, t) {
529
529
  const r = this.gl;
530
530
  (this.width !== e || this.height !== t) && (this.clearTargets(), this.width = e, this.height = t, this.targets = [this.target(e, t), this.target(Math.ceil(e / 2), Math.ceil(t / 2))]), r.bindFramebuffer(r.FRAMEBUFFER, this.targets[0].framebuffer), r.viewport(0, 0, e, t), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT);
531
531
  }
532
532
  composite(e) {
533
- const t = this.gl, { prog: r, u: a } = this.program, o = this.width, i = this.height;
534
- t.useProgram(r), t.bindVertexArray(this.vao), t.activeTexture(t.TEXTURE0), t.uniform1i(a.uTex, 0), t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, this.targets[1].framebuffer), t.viewport(0, 0, Math.ceil(o / 2), Math.ceil(i / 2)), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 0), t.uniform2f(a.uShift, 0, 0), t.uniform2f(a.uStep, 3 / o, 0), t.drawArrays(t.TRIANGLES, 0, 3), t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, o, i), t.clearColor(0, 0, 0, 0), t.clear(t.COLOR_BUFFER_BIT), t.enable(t.BLEND), t.bindTexture(t.TEXTURE_2D, this.targets[1].texture);
535
- const f = _n(e.x, e.y);
536
- t.uniform1i(a.uPass, 1), t.uniform2f(a.uShift, f[0], -f[1]), t.uniform2f(a.uStep, 0, 3 / i), t.drawArrays(t.TRIANGLES, 0, 3), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 2), t.drawArrays(t.TRIANGLES, 0, 3), t.bindVertexArray(null);
533
+ const t = this.gl, { prog: r, u: a } = this.program, s = this.width, l = this.height;
534
+ t.useProgram(r), t.bindVertexArray(this.vao), t.activeTexture(t.TEXTURE0), t.uniform1i(a.uTex, 0), t.disable(t.BLEND), t.bindFramebuffer(t.FRAMEBUFFER, this.targets[1].framebuffer), t.viewport(0, 0, Math.ceil(s / 2), Math.ceil(l / 2)), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 0), t.uniform2f(a.uShift, 0, 0), t.uniform2f(a.uStep, 3 / s, 0), t.drawArrays(t.TRIANGLES, 0, 3), t.bindFramebuffer(t.FRAMEBUFFER, null), t.viewport(0, 0, s, l), t.clearColor(0, 0, 0, 0), t.clear(t.COLOR_BUFFER_BIT), t.enable(t.BLEND), t.bindTexture(t.TEXTURE_2D, this.targets[1].texture);
535
+ const f = kn(e.x, e.y);
536
+ t.uniform1i(a.uPass, 1), t.uniform2f(a.uShift, f[0], -f[1]), t.uniform2f(a.uStep, 0, 3 / l), t.drawArrays(t.TRIANGLES, 0, 3), t.bindTexture(t.TEXTURE_2D, this.targets[0].texture), t.uniform1i(a.uPass, 2), t.drawArrays(t.TRIANGLES, 0, 3), t.bindVertexArray(null);
537
537
  }
538
538
  clearTargets() {
539
539
  for (const e of this.targets)
@@ -544,8 +544,8 @@ class Fn {
544
544
  this.clearTargets(), this.gl.deleteProgram(this.program.prog), this.gl.deleteVertexArray(this.vao);
545
545
  }
546
546
  }
547
- function Bn(n, e) {
548
- const { IMG: t, EYES: r, MOUTH: a, CHEEKS: o } = n, i = `#version 300 es
547
+ function Un(n, e) {
548
+ const { IMG: t, EYES: r, MOUTH: a, CHEEKS: s } = n, l = `#version 300 es
549
549
  in vec2 aPos; in vec2 aUv;
550
550
  uniform vec2 uScale; uniform vec2 uOffset;
551
551
  out vec2 vUv;
@@ -657,7 +657,7 @@ function Bn(n, e) {
657
657
  c = texAt(p);
658
658
  }
659
659
  outColor = c * uAlpha;
660
- }`, m = i.replace("out vec2 vUv;", "in float aHeadWeight; out float vHeadWeight; out vec2 vScreen; out vec2 vUv;").replace("vUv = aUv;", "vHeadWeight = aHeadWeight; vScreen = vec2((aPos.x * uScale.x + uOffset.x + 1.0) * 0.5, (1.0 - aPos.y * uScale.y - uOffset.y) * 0.5); vUv = aUv;"), g = f.replace("uniform sampler2D uTex;", `uniform sampler2D uTex;
660
+ }`, y = l.replace("out vec2 vUv;", "in float aHeadWeight; out float vHeadWeight; out vec2 vScreen; out vec2 vUv;").replace("vUv = aUv;", "vHeadWeight = aHeadWeight; vScreen = vec2((aPos.x * uScale.x + uOffset.x + 1.0) * 0.5, (1.0 - aPos.y * uScale.y - uOffset.y) * 0.5); vUv = aUv;"), d = f.replace("uniform sampler2D uTex;", `uniform sampler2D uTex;
661
661
  uniform sampler2D uNormal; in float vHeadWeight; in vec2 vScreen;
662
662
  uniform mat3 uHeadRotation; uniform vec3 uLight; uniform vec3 uLightColor; uniform vec3 uAmbientColor;
663
663
  uniform vec4 uLighting; uniform vec4 uSurface; uniform float uAspect; uniform int uCel;`).replace("outColor = c * uAlpha;", `
@@ -665,7 +665,7 @@ function Bn(n, e) {
665
665
  vec4 encoded = texture(uNormal, vUv);
666
666
  vec2 base = encoded.rg * 2.0 - 1.0;
667
667
  vec3 n = vec3(base, sqrt(max(0.0, 1.0 - dot(base, base))));
668
- n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${On.toFixed(3)}, 0.0));
668
+ n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${Rn.toFixed(3)}, 0.0));
669
669
  n = normalize(mix(n, uHeadRotation * n, vHeadWeight));
670
670
  vec2 toLight = (uLight.xy - vScreen) * vec2(uAspect, 1.0);
671
671
  vec3 light = normalize(vec3(toLight, uLight.z));
@@ -673,21 +673,21 @@ function Bn(n, e) {
673
673
  float diffuse;
674
674
  if (uCel == 1) {
675
675
  float w = 0.01 + uSurface.x * 0.08;
676
- diffuse = 0.2 + 0.45 * smoothstep(${Ge.toFixed(3)} - w, ${Ge.toFixed(3)} + w, ndl) + 0.35 * smoothstep(0.55 - w, 0.55 + w, ndl);
676
+ diffuse = 0.2 + 0.45 * smoothstep(${Ve.toFixed(3)} - w, ${Ve.toFixed(3)} + w, ndl) + 0.35 * smoothstep(0.55 - w, 0.55 + w, ndl);
677
677
  } else {
678
678
  float s = 0.05 + uSurface.x * 0.5;
679
- diffuse = smoothstep(${Ge.toFixed(3)} - s, ${Ge.toFixed(3)} + s, ndl) * (0.35 + 0.65 * max(0.0, ndl));
679
+ diffuse = smoothstep(${Ve.toFixed(3)} - s, ${Ve.toFixed(3)} + s, ndl) * (0.35 + 0.65 * max(0.0, ndl));
680
680
  }
681
681
  float reach = dot(toLight, toLight) / (uLighting.w * uLighting.w);
682
682
  float attenuation = 1.0 / (1.0 + reach);
683
683
  vec3 radiance = uLightColor * uLighting.y * attenuation;
684
684
  // A light close to the surface may brighten a little, but must not bleach painted colours.
685
- vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${Ln.toFixed(3)}));
685
+ vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${_n.toFixed(3)}));
686
686
  // Painted shadows are deeper versions of the base colour, not grey: multiply by the colour
687
687
  // itself as the surface turns away from the light.
688
688
  vec3 albedo = c.rgb / max(c.a, 1e-4);
689
689
  float dark = 1.0 - clamp(dot(irradiance, vec3(0.3333)), 0.0, 1.0);
690
- vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${Rn.toFixed(3)}) * irradiance;
690
+ vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${Ln.toFixed(3)}) * irradiance;
691
691
  float specular = pow(max(dot(n, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0), 60.0) * uSurface.y;
692
692
  if (uCel == 1) specular = smoothstep(0.3, 0.35, specular) * uSurface.y;
693
693
  vec2 side = length(n.xy) > 0.001 ? normalize(n.xy) : vec2(0.0);
@@ -695,308 +695,308 @@ function Bn(n, e) {
695
695
  shaded += radiance * (specular * max(0.0, ndl) + rim) * c.a;
696
696
  // Strength blends between the original painting and the relit result; alpha is unchanged.
697
697
  c.rgb = clamp(mix(c.rgb, shaded, uLighting.x), vec3(0.0), vec3(c.a));
698
- outColor = c * uAlpha;`), p = `#version 300 es
698
+ outColor = c * uAlpha;`), m = `#version 300 es
699
699
  in vec2 aPos; uniform vec2 uScale; uniform vec2 uOffset;
700
- void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`, l = `#version 300 es
700
+ void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`, c = `#version 300 es
701
701
  precision mediump float; uniform vec4 uColor; out vec4 o; void main() { o = uColor; }`;
702
- function h(v, x, s) {
703
- const c = v.createProgram();
704
- for (const [w, F] of [[v.VERTEX_SHADER, x], [v.FRAGMENT_SHADER, s]]) {
705
- const Y = v.createShader(w);
706
- if (v.shaderSource(Y, F), v.compileShader(Y), !v.getShaderParameter(Y, v.COMPILE_STATUS)) throw new Error(v.getShaderInfoLog(Y));
707
- v.attachShader(c, Y), v.deleteShader(Y);
708
- }
709
- if (v.bindAttribLocation(c, 0, "aPos"), v.bindAttribLocation(c, 1, "aUv"), v.bindAttribLocation(c, 2, "aHeadWeight"), v.linkProgram(c), !v.getProgramParameter(c, v.LINK_STATUS)) throw new Error(v.getProgramInfoLog(c));
710
- const T = {}, d = v.getProgramParameter(c, v.ACTIVE_UNIFORMS);
711
- for (let w = 0; w < d; w++) {
712
- const F = v.getActiveUniform(c, w).name.replace("[0]", "");
713
- T[F] = v.getUniformLocation(c, F);
714
- }
715
- return { prog: c, u: T };
716
- }
717
- function E(v, x, s, c) {
718
- const T = [v];
719
- let d = v;
720
- for (; d < v + x - 0.5; ) {
721
- const w = c && d >= c.from && d < c.to ? c.cell : s;
722
- d = Math.min(v + x, d + w), T.push(d);
723
- }
724
- return T;
725
- }
726
- function y(v, x, s, c, T = null) {
727
- const [d, w, F, Y] = v, I = E(d, F, x, T && { from: T.x0, to: T.x1, cell: T.cell }), _ = E(w, Y, x, T && { from: T.y0, to: T.y1, cell: T.cell }), B = I.length - 1, O = _.length - 1, z = (B + 1) * (O + 1), D = new Float32Array(z * 2), J = new Float32Array(z * 2);
728
- for (let q = 0; q <= O; q++) for (let W = 0; W <= B; W++) {
729
- const N = q * (B + 1) + W;
730
- D[N * 2] = I[W], D[N * 2 + 1] = _[q], J[N * 2] = (I[W] - d) / F, J[N * 2 + 1] = (_[q] - w) / Y;
731
- }
732
- const j = [], H = [], Z = s.length / c, $ = c === 1 ? 0 : 1;
733
- for (let q = 0; q < O; q++) for (let W = 0; W < B; W++) {
734
- const N = Math.floor(I[W] - d) * $ - 2, G = Math.ceil(I[W + 1] - d) * $ + 2, V = Math.floor(_[q] - w) * $ - 2, b = Math.ceil(_[q + 1] - w) * $ + 2;
702
+ function p(u, w, o) {
703
+ const i = u.createProgram();
704
+ for (const [A, L] of [[u.VERTEX_SHADER, w], [u.FRAGMENT_SHADER, o]]) {
705
+ const B = u.createShader(A);
706
+ if (u.shaderSource(B, L), u.compileShader(B), !u.getShaderParameter(B, u.COMPILE_STATUS)) throw new Error(u.getShaderInfoLog(B));
707
+ u.attachShader(i, B), u.deleteShader(B);
708
+ }
709
+ if (u.bindAttribLocation(i, 0, "aPos"), u.bindAttribLocation(i, 1, "aUv"), u.bindAttribLocation(i, 2, "aHeadWeight"), u.linkProgram(i), !u.getProgramParameter(i, u.LINK_STATUS)) throw new Error(u.getProgramInfoLog(i));
710
+ const S = {}, g = u.getProgramParameter(i, u.ACTIVE_UNIFORMS);
711
+ for (let A = 0; A < g; A++) {
712
+ const L = u.getActiveUniform(i, A).name.replace("[0]", "");
713
+ S[L] = u.getUniformLocation(i, L);
714
+ }
715
+ return { prog: i, u: S };
716
+ }
717
+ function b(u, w, o, i) {
718
+ const S = [u];
719
+ let g = u;
720
+ for (; g < u + w - 0.5; ) {
721
+ const A = i && g >= i.from && g < i.to ? i.cell : o;
722
+ g = Math.min(u + w, g + A), S.push(g);
723
+ }
724
+ return S;
725
+ }
726
+ function v(u, w, o, i, S = null) {
727
+ const [g, A, L, B] = u, j = b(g, L, w, S && { from: S.x0, to: S.x1, cell: S.cell }), k = b(A, B, w, S && { from: S.y0, to: S.y1, cell: S.cell }), U = j.length - 1, O = k.length - 1, $ = (U + 1) * (O + 1), D = new Float32Array($ * 2), q = new Float32Array($ * 2);
728
+ for (let z = 0; z <= O; z++) for (let W = 0; W <= U; W++) {
729
+ const I = z * (U + 1) + W;
730
+ D[I * 2] = j[W], D[I * 2 + 1] = k[z], q[I * 2] = (j[W] - g) / L, q[I * 2 + 1] = (k[z] - A) / B;
731
+ }
732
+ const N = [], P = [], H = o.length / i, G = i === 1 ? 0 : 1;
733
+ for (let z = 0; z < O; z++) for (let W = 0; W < U; W++) {
734
+ const I = Math.floor(j[W] - g) * G - 2, V = Math.ceil(j[W + 1] - g) * G + 2, K = Math.floor(k[z] - A) * G - 2, x = Math.ceil(k[z + 1] - A) * G + 2;
735
735
  let M = !1;
736
- for (let k = Math.max(0, V); k < Math.min(Z, b) && !M; k += 1)
737
- for (let P = Math.max(0, N); P < Math.min(c, G); P += 1)
738
- if (s[k * c + P] > 3) {
736
+ for (let F = Math.max(0, K); F < Math.min(H, x) && !M; F += 1)
737
+ for (let C = Math.max(0, I); C < Math.min(i, V); C += 1)
738
+ if (o[F * i + C] > 3) {
739
739
  M = !0;
740
740
  break;
741
741
  }
742
742
  if (!M) continue;
743
- const S = q * (B + 1) + W, L = S + 1, U = S + B + 1, X = U + 1;
744
- j.push(S, L, U, L, X, U), H.push(S, L, S, U, L, U), W === B - 1 && H.push(L, X), q === O - 1 && H.push(U, X);
743
+ const T = z * (U + 1) + W, _ = T + 1, Y = T + U + 1, X = Y + 1;
744
+ N.push(T, _, Y, _, X, Y), P.push(T, _, T, Y, _, Y), W === U - 1 && P.push(_, X), z === O - 1 && P.push(Y, X);
745
745
  }
746
- return { rect: v, cols: B, rows: O, rest: D, uv: J, pos: new Float32Array(D), tris: new Uint32Array(j), lines: new Uint32Array(H) };
746
+ return { rect: u, cols: U, rows: O, rest: D, uv: q, pos: new Float32Array(D), tris: new Uint32Array(N), lines: new Uint32Array(P) };
747
747
  }
748
- class u {
748
+ class h {
749
749
  // padTop / padSide: margin around the image, as a share of its height / width. A negative
750
750
  // padTop pushes the top of the image above the canvas (hides a cut-off top edge).
751
- constructor(x, { padTop: s = 0, padSide: c = 0, fit: T = "contain" } = {}) {
752
- this.pad = { top: s, side: c }, this.fit = T;
753
- const d = x.getContext("webgl2", { premultipliedAlpha: !0, antialias: !0, alpha: !0, preserveDrawingBuffer: !0 });
754
- if (!d) throw new Error("WebGL2 is not available");
755
- this.gl = d, this.canvas = x, this.main = h(d, i, f), this.line = h(d, p, l), this.layers = [], this.lighting = Fe, this.lightingStats = { normalMs: 0, computedLayers: 0, cachedLayers: 0 }, d.enable(d.BLEND), d.blendFunc(d.ONE, d.ONE_MINUS_SRC_ALPHA);
756
- }
757
- texture(x) {
758
- const s = this.gl, c = s.createTexture();
759
- return s.bindTexture(s.TEXTURE_2D, c), s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, s.RGBA, s.UNSIGNED_BYTE, x), s.generateMipmap(s.TEXTURE_2D), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, s.LINEAR_MIPMAP_LINEAR), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, s.LINEAR), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, s.CLAMP_TO_EDGE), c;
760
- }
761
- addLayer(x, s, c, T = {}) {
762
- const d = this.gl, w = d.createVertexArray();
763
- d.bindVertexArray(w);
764
- const F = d.createBuffer();
765
- d.bindBuffer(d.ARRAY_BUFFER, F), d.bufferData(d.ARRAY_BUFFER, c.pos, d.DYNAMIC_DRAW);
766
- for (const z of [this.main, this.line]) {
767
- const D = d.getAttribLocation(z.prog, "aPos");
768
- d.enableVertexAttribArray(D), d.vertexAttribPointer(D, 2, d.FLOAT, !1, 0, 0);
751
+ constructor(w, { padTop: o = 0, padSide: i = 0, fit: S = "contain" } = {}) {
752
+ this.pad = { top: o, side: i }, this.fit = S;
753
+ const g = w.getContext("webgl2", { premultipliedAlpha: !0, antialias: !0, alpha: !0, preserveDrawingBuffer: !0 });
754
+ if (!g) throw new Error("WebGL2 is not available");
755
+ this.gl = g, this.canvas = w, this.main = p(g, l, f), this.line = p(g, m, c), this.layers = [], this.lighting = Ue, this.lightingStats = { normalMs: 0, computedLayers: 0, cachedLayers: 0 }, g.enable(g.BLEND), g.blendFunc(g.ONE, g.ONE_MINUS_SRC_ALPHA);
756
+ }
757
+ texture(w) {
758
+ const o = this.gl, i = o.createTexture();
759
+ return o.bindTexture(o.TEXTURE_2D, i), o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, w), o.generateMipmap(o.TEXTURE_2D), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), i;
760
+ }
761
+ addLayer(w, o, i, S = {}) {
762
+ const g = this.gl, A = g.createVertexArray();
763
+ g.bindVertexArray(A);
764
+ const L = g.createBuffer();
765
+ g.bindBuffer(g.ARRAY_BUFFER, L), g.bufferData(g.ARRAY_BUFFER, i.pos, g.DYNAMIC_DRAW);
766
+ for (const $ of [this.main, this.line]) {
767
+ const D = g.getAttribLocation($.prog, "aPos");
768
+ g.enableVertexAttribArray(D), g.vertexAttribPointer(D, 2, g.FLOAT, !1, 0, 0);
769
769
  }
770
- const Y = d.createBuffer();
771
- d.bindBuffer(d.ARRAY_BUFFER, Y), d.bufferData(d.ARRAY_BUFFER, c.uv, d.STATIC_DRAW);
772
- const I = d.getAttribLocation(this.main.prog, "aUv");
773
- d.enableVertexAttribArray(I), d.vertexAttribPointer(I, 2, d.FLOAT, !1, 0, 0);
774
- const _ = d.createBuffer();
775
- d.bindBuffer(d.ELEMENT_ARRAY_BUFFER, _), d.bufferData(d.ELEMENT_ARRAY_BUFFER, c.tris, d.STATIC_DRAW), d.bindVertexArray(null);
776
- const B = d.createBuffer();
777
- d.bindBuffer(d.ELEMENT_ARRAY_BUFFER, B), d.bufferData(d.ELEMENT_ARRAY_BUFFER, c.lines, d.STATIC_DRAW);
778
- const O = { name: x, image: s, mesh: c, tex: this.texture(s), vao: w, posBuf: F, uvBuf: Y, triBuf: _, lineBuf: B, visible: !0, face: !!T.face, eyeBall: T.eyeBall, color: T.color || [1, 1, 1, 1] };
770
+ const B = g.createBuffer();
771
+ g.bindBuffer(g.ARRAY_BUFFER, B), g.bufferData(g.ARRAY_BUFFER, i.uv, g.STATIC_DRAW);
772
+ const j = g.getAttribLocation(this.main.prog, "aUv");
773
+ g.enableVertexAttribArray(j), g.vertexAttribPointer(j, 2, g.FLOAT, !1, 0, 0);
774
+ const k = g.createBuffer();
775
+ g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, k), g.bufferData(g.ELEMENT_ARRAY_BUFFER, i.tris, g.STATIC_DRAW), g.bindVertexArray(null);
776
+ const U = g.createBuffer();
777
+ g.bindBuffer(g.ELEMENT_ARRAY_BUFFER, U), g.bufferData(g.ELEMENT_ARRAY_BUFFER, i.lines, g.STATIC_DRAW);
778
+ const O = { name: w, image: o, mesh: i, tex: this.texture(o), vao: A, posBuf: L, uvBuf: B, triBuf: k, lineBuf: U, visible: !0, face: !!S.face, eyeBall: S.eyeBall, color: S.color || [1, 1, 1, 1] };
779
779
  return this.layers.push(O), O;
780
780
  }
781
781
  destroy() {
782
- const x = this.gl;
783
- for (const s of this.layers) {
784
- x.deleteTexture(s.tex), s.normal && x.deleteTexture(s.normal), s.headBuf && x.deleteBuffer(s.headBuf), x.deleteVertexArray(s.vao);
785
- for (const c of [s.posBuf, s.uvBuf, s.triBuf, s.lineBuf]) x.deleteBuffer(c);
782
+ const w = this.gl;
783
+ for (const o of this.layers) {
784
+ w.deleteTexture(o.tex), o.normal && w.deleteTexture(o.normal), o.headBuf && w.deleteBuffer(o.headBuf), w.deleteVertexArray(o.vao);
785
+ for (const i of [o.posBuf, o.uvBuf, o.triBuf, o.lineBuf]) w.deleteBuffer(i);
786
786
  }
787
- x.deleteProgram(this.main.prog), x.deleteProgram(this.line.prog), this.lit && x.deleteProgram(this.lit.prog), this.shadow?.destroy(), this.layers.length = 0;
788
- }
789
- setLighting(x) {
790
- if (this.lighting = Tn({ ...Fe, ...x }) ?? Fe, !this.lighting.enabled) return;
791
- const s = this.gl;
792
- this.lit || (this.lit = h(s, m, g));
793
- for (const c of this.layers) {
794
- if (c.normal || c.overlay) continue;
795
- const T = En(c.image, c.mesh.rect, e, !/^(eye|mouth)/.test(c.name));
796
- this.lightingStats.normalMs += T.ms, this.lightingStats[T.computed ? "computedLayers" : "cachedLayers"]++, c.normal = s.createTexture(), s.activeTexture(s.TEXTURE0), s.bindTexture(s.TEXTURE_2D, c.normal), s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, T.width, T.height, 0, s.RGBA, s.UNSIGNED_BYTE, T.data), s.generateMipmap(s.TEXTURE_2D), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, s.LINEAR_MIPMAP_LINEAR), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, s.LINEAR), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, s.CLAMP_TO_EDGE);
797
- const d = new Float32Array(c.mesh.rest.length / 2);
798
- for (let w = 0; w < d.length; w++) d[w] = n.headWeight(c.mesh.rest[w * 2], c.mesh.rest[w * 2 + 1]);
799
- c.headBuf = s.createBuffer(), s.bindVertexArray(c.vao), s.bindBuffer(s.ARRAY_BUFFER, c.headBuf), s.bufferData(s.ARRAY_BUFFER, d, s.STATIC_DRAW), s.enableVertexAttribArray(2), s.vertexAttribPointer(2, 1, s.FLOAT, !1, 0, 0);
787
+ w.deleteProgram(this.main.prog), w.deleteProgram(this.line.prog), this.lit && w.deleteProgram(this.lit.prog), this.shadow?.destroy(), this.layers.length = 0;
788
+ }
789
+ setLighting(w) {
790
+ if (this.lighting = On({ ...Ue, ...w }) ?? Ue, !this.lighting.enabled) return;
791
+ const o = this.gl;
792
+ this.lit || (this.lit = p(o, y, d));
793
+ for (const i of this.layers) {
794
+ if (i.normal || i.overlay) continue;
795
+ const S = Sn(i.image, i.mesh.rect, e, !/^(eye|mouth)/.test(i.name));
796
+ this.lightingStats.normalMs += S.ms, this.lightingStats[S.computed ? "computedLayers" : "cachedLayers"]++, i.normal = o.createTexture(), o.activeTexture(o.TEXTURE0), o.bindTexture(o.TEXTURE_2D, i.normal), o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, S.width, S.height, 0, o.RGBA, o.UNSIGNED_BYTE, S.data), o.generateMipmap(o.TEXTURE_2D), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE);
797
+ const g = new Float32Array(i.mesh.rest.length / 2);
798
+ for (let A = 0; A < g.length; A++) g[A] = n.headWeight(i.mesh.rest[A * 2], i.mesh.rest[A * 2 + 1]);
799
+ i.headBuf = o.createBuffer(), o.bindVertexArray(i.vao), o.bindBuffer(o.ARRAY_BUFFER, i.headBuf), o.bufferData(o.ARRAY_BUFFER, g, o.STATIC_DRAW), o.enableVertexAttribArray(2), o.vertexAttribPointer(2, 1, o.FLOAT, !1, 0, 0);
800
800
  }
801
- s.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new Fn(s, h));
801
+ o.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new Bn(o, p));
802
802
  }
803
803
  resize() {
804
- const x = this.canvas, s = Math.min(window.devicePixelRatio || 1, 2), c = Math.round(x.clientWidth * s), T = Math.round(x.clientHeight * s);
805
- (x.width !== c || x.height !== T) && (x.width = c, x.height = T);
806
- const d = (this.fit === "cover" ? Math.max : Math.min)(c / (t.w * (1 + 2 * this.pad.side)), T / (t.h * (1 + this.pad.top))), w = (c - t.w * d) / 2, F = (T - t.h * d) / (this.fit === "cover" ? 2 : 1);
807
- this.scale = [2 * d / c, -2 * d / T], this.offset = [-1 + 2 * w / c, 1 - 2 * F / T], this.pxScale = d, this.pxOff = [w, F];
808
- }
809
- draw(x) {
810
- const s = this.gl;
811
- this.resize(), s.viewport(0, 0, this.canvas.width, this.canvas.height), s.clearColor(0, 0, 0, 0), s.clear(s.COLOR_BUFFER_BIT);
812
- const c = this.lighting.enabled, T = c && this.lighting.shadow;
813
- T && this.shadow.begin(this.canvas.width, this.canvas.height);
814
- const d = c ? this.lit : this.main;
815
- if (this.current = d, s.useProgram(d.prog), c) {
816
- const w = this.lighting;
817
- s.uniform1i(d.u.uNormal, 1), s.uniform3f(d.u.uLight, w.x, w.y, w.z), s.uniform3f(d.u.uLightColor, (w.color >> 16 & 255) / 255, (w.color >> 8 & 255) / 255, (w.color & 255) / 255), s.uniform3f(d.u.uAmbientColor, (w.ambientColor >> 16 & 255) / 255, (w.ambientColor >> 8 & 255) / 255, (w.ambientColor & 255) / 255), s.uniform4f(d.u.uLighting, w.strength, w.intensity, w.ambient, w.reach), s.uniform4f(d.u.uSurface, w.softness, w.specular, w.rim, w.detail), s.uniform1f(d.u.uAspect, this.canvas.width / this.canvas.height), s.uniform1i(d.u.uCel, w.mode === "cel" ? 1 : 0), s.uniformMatrix3fv(d.u.uHeadRotation, !1, kn(x.angleX ?? 0, x.angleY ?? 0, x.angleZ ?? 0, e.head.maxRoll));
804
+ const w = this.canvas, o = Math.min(window.devicePixelRatio || 1, 2), i = Math.round(w.clientWidth * o), S = Math.round(w.clientHeight * o);
805
+ (w.width !== i || w.height !== S) && (w.width = i, w.height = S);
806
+ const g = (this.fit === "cover" ? Math.max : Math.min)(i / (t.w * (1 + 2 * this.pad.side)), S / (t.h * (1 + this.pad.top))), A = (i - t.w * g) / 2, L = (S - t.h * g) / (this.fit === "cover" ? 2 : 1);
807
+ this.scale = [2 * g / i, -2 * g / S], this.offset = [-1 + 2 * A / i, 1 - 2 * L / S], this.pxScale = g, this.pxOff = [A, L];
808
+ }
809
+ draw(w) {
810
+ const o = this.gl;
811
+ this.resize(), o.viewport(0, 0, this.canvas.width, this.canvas.height), o.clearColor(0, 0, 0, 0), o.clear(o.COLOR_BUFFER_BIT);
812
+ const i = this.lighting.enabled, S = i && this.lighting.shadow;
813
+ S && this.shadow.begin(this.canvas.width, this.canvas.height);
814
+ const g = i ? this.lit : this.main;
815
+ if (this.current = g, o.useProgram(g.prog), i) {
816
+ const A = this.lighting;
817
+ o.uniform1i(g.u.uNormal, 1), o.uniform3f(g.u.uLight, A.x, A.y, A.z), o.uniform3f(g.u.uLightColor, (A.color >> 16 & 255) / 255, (A.color >> 8 & 255) / 255, (A.color & 255) / 255), o.uniform3f(g.u.uAmbientColor, (A.ambientColor >> 16 & 255) / 255, (A.ambientColor >> 8 & 255) / 255, (A.ambientColor & 255) / 255), o.uniform4f(g.u.uLighting, A.strength, A.intensity, A.ambient, A.reach), o.uniform4f(g.u.uSurface, A.softness, A.specular, A.rim, A.detail), o.uniform1f(g.u.uAspect, this.canvas.width / this.canvas.height), o.uniform1i(g.u.uCel, A.mode === "cel" ? 1 : 0), o.uniformMatrix3fv(g.u.uHeadRotation, !1, Fn(w.angleX ?? 0, w.angleY ?? 0, w.angleZ ?? 0, e.head.maxRoll));
818
818
  }
819
- s.uniform2fv(d.u.uScale, this.scale), s.uniform2fv(d.u.uOffset, this.offset), s.uniform1i(d.u.uTex, 0), s.uniform4fv(d.u.uEyeBox, r.flatMap((w) => [w.x0, w.x1, 0, 0])), s.uniform1fv(d.u.uEyeTop, r.flatMap((w) => w.top)), s.uniform1fv(d.u.uEyeBot, r.flatMap((w) => w.bot)), s.uniform4fv(d.u.uEyeState, x.eyes), s.uniform4f(d.u.uMouth, a.cx, a.cy, a.angle, a.halfLen), s.uniform4f(d.u.uMouthState, x.mouthOpen, x.mouthForm, a.bow, 0), s.uniform4f(d.u.uCheeks, o[0][0], o[0][1], o[1][0], o[1][1]), s.uniform1f(d.u.uCheek, x.cheek), s.activeTexture(s.TEXTURE0);
820
- for (const w of this.layers)
821
- !w.visible || w.overlay || this.drawLayer(w, w.alpha ?? 1);
822
- if (this.original && x.originalAlpha > 0 && this.drawLayer(this.original, x.originalAlpha), T && this.shadow.composite(this.lighting), x.showMesh) {
823
- const w = this.line;
824
- s.useProgram(w.prog), s.uniform2fv(w.u.uScale, this.scale), s.uniform2fv(w.u.uOffset, this.offset);
825
- for (const F of this.layers)
826
- !F.visible || F.overlay || (s.bindVertexArray(F.vao), s.bindBuffer(s.ELEMENT_ARRAY_BUFFER, F.lineBuf), s.uniform4fv(w.u.uColor, F.color), s.drawElements(s.LINES, F.mesh.lines.length, s.UNSIGNED_INT, 0), s.bindBuffer(s.ELEMENT_ARRAY_BUFFER, F.triBuf));
827
- x.joints?.length && this.drawPoints(x.joints), s.bindVertexArray(null);
819
+ o.uniform2fv(g.u.uScale, this.scale), o.uniform2fv(g.u.uOffset, this.offset), o.uniform1i(g.u.uTex, 0), o.uniform4fv(g.u.uEyeBox, r.flatMap((A) => [A.x0, A.x1, 0, 0])), o.uniform1fv(g.u.uEyeTop, r.flatMap((A) => A.top)), o.uniform1fv(g.u.uEyeBot, r.flatMap((A) => A.bot)), o.uniform4fv(g.u.uEyeState, w.eyes), o.uniform4f(g.u.uMouth, a.cx, a.cy, a.angle, a.halfLen), o.uniform4f(g.u.uMouthState, w.mouthOpen, w.mouthForm, a.bow, 0), o.uniform4f(g.u.uCheeks, s[0][0], s[0][1], s[1][0], s[1][1]), o.uniform1f(g.u.uCheek, w.cheek), o.activeTexture(o.TEXTURE0);
820
+ for (const A of this.layers)
821
+ !A.visible || A.overlay || this.drawLayer(A, A.alpha ?? 1);
822
+ if (this.original && w.originalAlpha > 0 && this.drawLayer(this.original, w.originalAlpha), S && this.shadow.composite(this.lighting), w.showMesh) {
823
+ const A = this.line;
824
+ o.useProgram(A.prog), o.uniform2fv(A.u.uScale, this.scale), o.uniform2fv(A.u.uOffset, this.offset);
825
+ for (const L of this.layers)
826
+ !L.visible || L.overlay || (o.bindVertexArray(L.vao), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, L.lineBuf), o.uniform4fv(A.u.uColor, L.color), o.drawElements(o.LINES, L.mesh.lines.length, o.UNSIGNED_INT, 0), o.bindBuffer(o.ELEMENT_ARRAY_BUFFER, L.triBuf));
827
+ w.joints?.length && this.drawPoints(w.joints), o.bindVertexArray(null);
828
828
  }
829
829
  }
830
- drawLayer(x, s) {
831
- const c = this.gl, T = this.current;
832
- c.useProgram(T.prog), c.bindVertexArray(x.vao), c.bindBuffer(c.ARRAY_BUFFER, x.posBuf), c.bufferSubData(c.ARRAY_BUFFER, 0, x.mesh.pos), this.lighting.enabled && (c.activeTexture(c.TEXTURE1), c.bindTexture(c.TEXTURE_2D, x.normal), c.activeTexture(c.TEXTURE0)), c.bindTexture(c.TEXTURE_2D, x.tex), c.uniform4fv(T.u.uRect, x.mesh.rect), c.uniform1i(T.u.uFace, x.eyeBall !== void 0 ? 2 + x.eyeBall : x.face ? 1 : 0), c.uniform1f(T.u.uAlpha, s), c.drawElements(c.TRIANGLES, x.mesh.tris.length, c.UNSIGNED_INT, 0);
830
+ drawLayer(w, o) {
831
+ const i = this.gl, S = this.current;
832
+ i.useProgram(S.prog), i.bindVertexArray(w.vao), i.bindBuffer(i.ARRAY_BUFFER, w.posBuf), i.bufferSubData(i.ARRAY_BUFFER, 0, w.mesh.pos), this.lighting.enabled && (i.activeTexture(i.TEXTURE1), i.bindTexture(i.TEXTURE_2D, w.normal), i.activeTexture(i.TEXTURE0)), i.bindTexture(i.TEXTURE_2D, w.tex), i.uniform4fv(S.u.uRect, w.mesh.rect), i.uniform1i(S.u.uFace, w.eyeBall !== void 0 ? 2 + w.eyeBall : w.face ? 1 : 0), i.uniform1f(S.u.uAlpha, o), i.drawElements(i.TRIANGLES, w.mesh.tris.length, i.UNSIGNED_INT, 0);
833
833
  }
834
- drawPoints(x) {
835
- const s = this.gl, c = this.line;
834
+ drawPoints(w) {
835
+ const o = this.gl, i = this.line;
836
836
  if (!this.pointBuf) {
837
- this.pointBuf = s.createBuffer(), this.pointVao = s.createVertexArray(), s.bindVertexArray(this.pointVao), s.bindBuffer(s.ARRAY_BUFFER, this.pointBuf);
838
- const T = s.getAttribLocation(c.prog, "aPos");
839
- s.enableVertexAttribArray(T), s.vertexAttribPointer(T, 2, s.FLOAT, !1, 0, 0);
837
+ this.pointBuf = o.createBuffer(), this.pointVao = o.createVertexArray(), o.bindVertexArray(this.pointVao), o.bindBuffer(o.ARRAY_BUFFER, this.pointBuf);
838
+ const S = o.getAttribLocation(i.prog, "aPos");
839
+ o.enableVertexAttribArray(S), o.vertexAttribPointer(S, 2, o.FLOAT, !1, 0, 0);
840
840
  }
841
- s.bindVertexArray(this.pointVao), s.bindBuffer(s.ARRAY_BUFFER, this.pointBuf), s.bufferData(s.ARRAY_BUFFER, new Float32Array(x.flat()), s.DYNAMIC_DRAW), s.uniform4f(c.u.uColor, 1, 0.85, 0.2, 1), s.drawArrays(s.POINTS, 0, x.length);
841
+ o.bindVertexArray(this.pointVao), o.bindBuffer(o.ARRAY_BUFFER, this.pointBuf), o.bufferData(o.ARRAY_BUFFER, new Float32Array(w.flat()), o.DYNAMIC_DRAW), o.uniform4f(i.u.uColor, 1, 0.85, 0.2, 1), o.drawArrays(o.POINTS, 0, w.length);
842
842
  }
843
843
  // canvas CSS px -> source image px
844
- toImage(x, s) {
844
+ toImage(w, o) {
845
845
  if (!this.pxOff) return null;
846
- const c = this.canvas.width / this.canvas.clientWidth;
847
- return [(x * c - this.pxOff[0]) / this.pxScale, (s * c - this.pxOff[1]) / this.pxScale];
846
+ const i = this.canvas.width / this.canvas.clientWidth;
847
+ return [(w * i - this.pxOff[0]) / this.pxScale, (o * i - this.pxOff[1]) / this.pxScale];
848
848
  }
849
849
  }
850
- return { Renderer: u, buildGrid: y };
850
+ return { Renderer: h, buildGrid: v };
851
851
  }
852
- function Un(n, e) {
853
- const { applyHead: t, applyBody: r, TASSELS: a, tasselAnchor: o } = n, i = (e.strands ?? []).map((s) => {
854
- if (s.nodes.length === 4) return s;
855
- const c = Array.from({ length: 4 }, (T, d) => {
856
- const w = d / 3 * (s.nodes.length - 1), F = Math.min(s.nodes.length - 2, Math.floor(w)), Y = w - F;
857
- return [0, 1].map((I) => s.nodes[F][I] + (s.nodes[F + 1][I] - s.nodes[F][I]) * Y);
852
+ function Yn(n, e) {
853
+ const { applyHead: t, applyBody: r, TASSELS: a, tasselAnchor: s } = n, l = (e.strands ?? []).map((o) => {
854
+ if (o.nodes.length === 4) return o;
855
+ const i = Array.from({ length: 4 }, (S, g) => {
856
+ const A = g / 3 * (o.nodes.length - 1), L = Math.min(o.nodes.length - 2, Math.floor(A)), B = A - L;
857
+ return [0, 1].map((j) => o.nodes[L][j] + (o.nodes[L + 1][j] - o.nodes[L][j]) * B);
858
858
  });
859
- return { ...s, nodes: c };
860
- }), f = [0, 300, 200, 140], m = 0.9, g = 7, p = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, l = Math.min(6, i.filter((s) => s.name.startsWith("bang")).length), h = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, E = (s, c) => [s[0] * Math.cos(c) - s[1] * Math.sin(c), s[0] * Math.sin(c) + s[1] * Math.cos(c)], y = (s, c) => {
861
- const T = Math.hypot(s[0], s[1]);
862
- if (T < 1e-6) return s;
863
- const d = c * Math.tanh(T / c) / T;
864
- return [s[0] * d, s[1] * d];
865
- }, u = Object.fromEntries(Object.entries(e.buns ?? {}).map(([s, c]) => [s, { at: [c.cx, c.cy], k: 260, c: 11, hang: 3, max: 4 }])), v = (s, c) => {
866
- const T = Math.hypot(s[0], s[1]);
867
- T > c && (s[0] *= c / T, s[1] *= c / T);
859
+ return { ...o, nodes: i };
860
+ }), f = [0, 300, 200, 140], y = 0.9, d = 7, m = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, c = Math.min(6, l.filter((o) => o.name.startsWith("bang")).length), p = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, b = (o, i) => [o[0] * Math.cos(i) - o[1] * Math.sin(i), o[0] * Math.sin(i) + o[1] * Math.cos(i)], v = (o, i) => {
861
+ const S = Math.hypot(o[0], o[1]);
862
+ if (S < 1e-6) return o;
863
+ const g = i * Math.tanh(S / i) / S;
864
+ return [o[0] * g, o[1] * g];
865
+ }, h = Object.fromEntries(Object.entries(e.buns ?? {}).map(([o, i]) => [o, { at: [i.cx, i.cy], k: 260, c: 11, hang: 3, max: 4 }])), u = (o, i) => {
866
+ const S = Math.hypot(o[0], o[1]);
867
+ S > i && (o[0] *= i / S, o[1] *= i / S);
868
868
  };
869
- class x {
869
+ class w {
870
870
  constructor() {
871
871
  this.gain = 1, this.out = { gain: 1, bunL: [0, 0], bunR: [0, 0] }, this.hair = {};
872
- for (const c of Object.keys(u))
873
- this.hair[c] = { p: null, v: [0, 0] }, this.out[c] = [0, 0];
874
- this.strands = i.map(() => ({ p: null, v: [[0, 0], [0, 0], [0, 0], [0, 0]] })), this.out.strands = i.map(() => [[0, 0], [0, 0], [0, 0], [0, 0]]), this.chains = a.map((c) => {
875
- const T = c.tip[0] - c.pivot[0], d = c.tip[1] - c.pivot[1], w = Math.hypot(T, d), F = [T / w, d / w];
876
- return { t: c, dir: F, L1: w * c.split, L2: w * (1 - c.split), pts: null, prev: null, phi: [0, 0], anchor: [0, 0] };
872
+ for (const i of Object.keys(h))
873
+ this.hair[i] = { p: null, v: [0, 0] }, this.out[i] = [0, 0];
874
+ this.strands = l.map(() => ({ p: null, v: [[0, 0], [0, 0], [0, 0], [0, 0]] })), this.out.strands = l.map(() => [[0, 0], [0, 0], [0, 0], [0, 0]]), this.chains = a.map((i) => {
875
+ const S = i.tip[0] - i.pivot[0], g = i.tip[1] - i.pivot[1], A = Math.hypot(S, g), L = [S / A, g / A];
876
+ return { t: i, dir: L, L1: A * i.split, L2: A * (1 - i.split), pts: null, prev: null, phi: [0, 0], anchor: [0, 0] };
877
877
  }), this.time = 0;
878
878
  }
879
- hairAnchor(c, T) {
880
- const d = [c[0], c[1]];
881
- return t(d, 1, T), r(d, c[1], T), d;
882
- }
883
- step(c, T) {
884
- const d = Math.max(1, Math.ceil(T / 0.004166666666666667)), w = Math.min(T, 0.05) / d, F = -c.angleZ / 30 * e.head.maxRoll - c.bodyAngleZ / 10 * e.body.maxRoll, Y = this.gain;
885
- i.forEach((_, B) => {
886
- const O = this.strands[B], z = this.out.strands[B], D = _.nodes.map((j) => this.hairAnchor(j, c));
887
- O.p || (O.p = D.map((j) => [...j]));
888
- const J = B * 1.7;
889
- for (let j = 0; j < d; j++) {
890
- const H = this.time + j * w;
891
- for (let Z = 1; Z < 4; Z++) {
892
- const $ = Math.hypot(_.nodes[Z][0] - _.nodes[0][0], _.nodes[Z][1] - _.nodes[0][1]), q = (Math.sin(H * 1.3) * 0.5 + Math.sin(H * 3.1) * 0.3 + Math.sin(H * 4.7 + J) * 0.2) * _.max * 0.1 * Z / 3, W = [O.p[Z - 1][0] - D[Z - 1][0], O.p[Z - 1][1] - D[Z - 1][1]], N = D[Z][0] + W[0] * m * p.couple - Math.sin(F) * $ * 0.12 + q, G = D[Z][1] + W[1] * m * p.couple, V = f[Z] * _.k * p.stiff / Math.max(0.35, Y), b = g * p.damp * Math.sqrt(p.stiff) / Math.max(0.5, Math.sqrt(Y)), M = O.v[Z], S = O.p[Z];
893
- M[0] += (V * (N - S[0]) - b * M[0]) * w, M[1] += (V * (G - S[1]) - b * M[1]) * w, S[0] += M[0] * w, S[1] += M[1] * w;
879
+ hairAnchor(i, S) {
880
+ const g = [i[0], i[1]];
881
+ return t(g, 1, S), r(g, i[1], S), g;
882
+ }
883
+ step(i, S) {
884
+ const g = Math.max(1, Math.ceil(S / 0.004166666666666667)), A = Math.min(S, 0.05) / g, L = -i.angleZ / 30 * e.head.maxRoll - i.bodyAngleZ / 10 * e.body.maxRoll, B = this.gain;
885
+ l.forEach((k, U) => {
886
+ const O = this.strands[U], $ = this.out.strands[U], D = k.nodes.map((N) => this.hairAnchor(N, i));
887
+ O.p || (O.p = D.map((N) => [...N]));
888
+ const q = U * 1.7;
889
+ for (let N = 0; N < g; N++) {
890
+ const P = this.time + N * A;
891
+ for (let H = 1; H < 4; H++) {
892
+ const G = Math.hypot(k.nodes[H][0] - k.nodes[0][0], k.nodes[H][1] - k.nodes[0][1]), z = (Math.sin(P * 1.3) * 0.5 + Math.sin(P * 3.1) * 0.3 + Math.sin(P * 4.7 + q) * 0.2) * k.max * 0.1 * H / 3, W = [O.p[H - 1][0] - D[H - 1][0], O.p[H - 1][1] - D[H - 1][1]], I = D[H][0] + W[0] * y * m.couple - Math.sin(L) * G * 0.12 + z, V = D[H][1] + W[1] * y * m.couple, K = f[H] * k.k * m.stiff / Math.max(0.35, B), x = d * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(B)), M = O.v[H], T = O.p[H];
893
+ M[0] += (K * (I - T[0]) - x * M[0]) * A, M[1] += (K * (V - T[1]) - x * M[1]) * A, T[0] += M[0] * A, T[1] += M[1] * A;
894
894
  }
895
895
  O.p[0] = [...D[0]];
896
896
  }
897
- for (let j = 0; j < 4; j++) {
898
- const H = [O.p[j][0] - D[j][0], O.p[j][1] - D[j][1]];
899
- z[j] = y(H, Math.max(0.5, _.max * p.reach * Math.max(1, Y) * j / 3));
897
+ for (let N = 0; N < 4; N++) {
898
+ const P = [O.p[N][0] - D[N][0], O.p[N][1] - D[N][1]];
899
+ $[N] = v(P, Math.max(0.5, k.max * m.reach * Math.max(1, B) * N / 3));
900
900
  }
901
901
  });
902
- for (const [_, B] of Object.entries(u)) {
903
- const O = this.hair[_], z = this.hairAnchor(B.at, c), D = Math.sin(this.time * 1.3 + B.at[0] * 0.01) * 0.6 + Math.sin(this.time * 2.9 + B.at[1] * 0.02) * 0.4, J = z[0] - Math.sin(F) * B.hang + D * B.max * 0.12, j = z[1];
904
- O.p || (O.p = [J, j]);
905
- const H = B.k / Math.max(0.35, Y), Z = B.c / Math.max(0.5, Math.sqrt(Y));
906
- for (let q = 0; q < d; q++)
907
- O.v[0] += (H * (J - O.p[0]) - Z * O.v[0]) * w, O.v[1] += (H * (j - O.p[1]) - Z * O.v[1]) * w, O.p[0] += O.v[0] * w, O.p[1] += O.v[1] * w;
908
- const $ = [O.p[0] - z[0], O.p[1] - z[1]];
909
- v($, B.max * Math.max(1, Y)), this.out[_] = $;
902
+ for (const [k, U] of Object.entries(h)) {
903
+ const O = this.hair[k], $ = this.hairAnchor(U.at, i), D = Math.sin(this.time * 1.3 + U.at[0] * 0.01) * 0.6 + Math.sin(this.time * 2.9 + U.at[1] * 0.02) * 0.4, q = $[0] - Math.sin(L) * U.hang + D * U.max * 0.12, N = $[1];
904
+ O.p || (O.p = [q, N]);
905
+ const P = U.k / Math.max(0.35, B), H = U.c / Math.max(0.5, Math.sqrt(B));
906
+ for (let z = 0; z < g; z++)
907
+ O.v[0] += (P * (q - O.p[0]) - H * O.v[0]) * A, O.v[1] += (P * (N - O.p[1]) - H * O.v[1]) * A, O.p[0] += O.v[0] * A, O.p[1] += O.v[1] * A;
908
+ const G = [O.p[0] - $[0], O.p[1] - $[1]];
909
+ u(G, U.max * Math.max(1, B)), this.out[k] = G;
910
910
  }
911
911
  this.out.gain = 1;
912
- const I = this.out.strands;
913
- for (let _ = 0; _ < p.bind; _++) for (let B = 1; B < 4; B++) {
914
- const O = I.slice(0, l).map((z) => [...z[B]]);
915
- for (let z = 0; z < l; z++) {
916
- const D = O[Math.max(0, z - 1)], J = O[Math.min(l - 1, z + 1)];
917
- for (const j of [0, 1]) I[z][B][j] = O[z][j] * 0.5 + (D[j] + J[j]) * 0.25;
912
+ const j = this.out.strands;
913
+ for (let k = 0; k < m.bind; k++) for (let U = 1; U < 4; U++) {
914
+ const O = j.slice(0, c).map(($) => [...$[U]]);
915
+ for (let $ = 0; $ < c; $++) {
916
+ const D = O[Math.max(0, $ - 1)], q = O[Math.min(c - 1, $ + 1)];
917
+ for (const N of [0, 1]) j[$][U][N] = O[$][N] * 0.5 + (D[N] + q[N]) * 0.25;
918
918
  }
919
919
  }
920
- for (const _ of this.chains) {
921
- const B = o(_.t, c, this.out, [0, 0]);
922
- _.st || (_.st = { th: [0, 0], w: [0, 0], pos: [...B], vel: [0, 0], acc: [0, 0] });
923
- const O = _.st, z = h, D = [(B[0] - O.pos[0]) / Math.max(T, 1e-3), (B[1] - O.pos[1]) / Math.max(T, 1e-3)], J = 1 - Math.exp(-T * z.smooth), j = [(D[0] - O.vel[0]) / Math.max(T, 1e-3), (D[1] - O.vel[1]) / Math.max(T, 1e-3)];
924
- O.acc = [O.acc[0] + (j[0] - O.acc[0]) * J, O.acc[1] + (j[1] - O.acc[1]) * J], O.vel = [O.vel[0] + (D[0] - O.vel[0]) * J, O.vel[1] + (D[1] - O.vel[1]) * J], O.pos = [...B];
925
- const H = [-_.dir[1], _.dir[0]], Z = -(O.acc[0] * H[0] + O.acc[1] * H[1]) / (_.L1 + _.L2) * z.inertia, $ = (Math.sin(this.time * 0.9 + _.t.pivot[0]) * 0.6 + Math.sin(this.time * 0.37 + _.t.pivot[1]) * 0.4) * z.wind, q = -F * z.hang + $, W = 2 * Math.PI * z.freq / Math.sqrt(Math.max(0.4, Y)), N = W * 1.35;
926
- for (let M = 0; M < d; M++) {
927
- const S = -W * W * (O.th[0] - q) - 2 * z.zeta * W * O.w[0] + Z;
928
- O.w[0] += S * w, O.th[0] += O.w[0] * w;
929
- const L = -N * N * (O.th[1] - O.th[0]) - 2 * z.zeta * N * O.w[1] + Z * 0.4 + S * 0.5;
930
- O.w[1] += L * w, O.th[1] += O.w[1] * w;
920
+ for (const k of this.chains) {
921
+ const U = s(k.t, i, this.out, [0, 0]);
922
+ k.st || (k.st = { th: [0, 0], w: [0, 0], pos: [...U], vel: [0, 0], acc: [0, 0] });
923
+ const O = k.st, $ = p, D = [(U[0] - O.pos[0]) / Math.max(S, 1e-3), (U[1] - O.pos[1]) / Math.max(S, 1e-3)], q = 1 - Math.exp(-S * $.smooth), N = [(D[0] - O.vel[0]) / Math.max(S, 1e-3), (D[1] - O.vel[1]) / Math.max(S, 1e-3)];
924
+ O.acc = [O.acc[0] + (N[0] - O.acc[0]) * q, O.acc[1] + (N[1] - O.acc[1]) * q], O.vel = [O.vel[0] + (D[0] - O.vel[0]) * q, O.vel[1] + (D[1] - O.vel[1]) * q], O.pos = [...U];
925
+ const P = [-k.dir[1], k.dir[0]], H = -(O.acc[0] * P[0] + O.acc[1] * P[1]) / (k.L1 + k.L2) * $.inertia, G = (Math.sin(this.time * 0.9 + k.t.pivot[0]) * 0.6 + Math.sin(this.time * 0.37 + k.t.pivot[1]) * 0.4) * $.wind, z = -L * $.hang + G, W = 2 * Math.PI * $.freq / Math.sqrt(Math.max(0.4, B)), I = W * 1.35;
926
+ for (let M = 0; M < g; M++) {
927
+ const T = -W * W * (O.th[0] - z) - 2 * $.zeta * W * O.w[0] + H;
928
+ O.w[0] += T * A, O.th[0] += O.w[0] * A;
929
+ const _ = -I * I * (O.th[1] - O.th[0]) - 2 * $.zeta * I * O.w[1] + H * 0.4 + T * 0.5;
930
+ O.w[1] += _ * A, O.th[1] += O.w[1] * A;
931
931
  }
932
- O.th[0] = Math.max(-0.55, Math.min(z.max, O.th[0])), O.th[1] = Math.max(-0.55 * 1.4, Math.min(z.max * 1.4, O.th[1])), _.phi = [O.th[0], O.th[1]];
933
- const G = E(_.dir, O.th[0]), V = E(_.dir, O.th[1]), b = [B[0] + G[0] * _.L1, B[1] + G[1] * _.L1];
934
- _.pts = [[...B], b, [b[0] + V[0] * _.L2, b[1] + V[1] * _.L2]], _.anchor = B;
932
+ O.th[0] = Math.max(-0.55, Math.min($.max, O.th[0])), O.th[1] = Math.max(-0.55 * 1.4, Math.min($.max * 1.4, O.th[1])), k.phi = [O.th[0], O.th[1]];
933
+ const V = b(k.dir, O.th[0]), K = b(k.dir, O.th[1]), x = [U[0] + V[0] * k.L1, U[1] + V[1] * k.L1];
934
+ k.pts = [[...U], x, [x[0] + K[0] * k.L2, x[1] + K[1] * k.L2]], k.anchor = U;
935
935
  }
936
- return this.time += T, this.out;
936
+ return this.time += S, this.out;
937
937
  }
938
938
  }
939
- return { Physics: x };
939
+ return { Physics: w };
940
940
  }
941
- function Yn(n, e) {
942
- const { baseWeights: t, deformBase: r, MOUTH: a } = n, o = (d, w, F) => {
943
- const Y = Math.min(1, Math.max(0, (F - d) / (w - d)));
944
- return Y * Y * (3 - 2 * Y);
945
- }, i = e.mouth.area, f = {
941
+ function jn(n, e) {
942
+ const { baseWeights: t, deformBase: r, MOUTH: a } = n, s = (g, A, L) => {
943
+ const B = Math.min(1, Math.max(0, (L - g) / (A - g)));
944
+ return B * B * (3 - 2 * B);
945
+ }, l = e.mouth.area, f = {
946
946
  a: { sprite: "mouth_a", ref: 0.9, width: 1 },
947
947
  aHalf: { sprite: "mouth_a_half", ref: 0.55, width: 1 },
948
948
  i: { sprite: "mouth_i", ref: 0.55, width: 1 },
949
949
  e: { sprite: "mouth_a_half", ref: 0.65, width: 1.06 },
950
950
  o: { sprite: "mouth_o", ref: 0.75, width: 1 },
951
951
  u: { sprite: "mouth_o", ref: 0.75, width: 0.78 }
952
- }, m = 0.16, g = ["angry", "sad"];
953
- function p(d, w) {
954
- const Y = (B, O, z) => B >= O - (w ? 0.07 : 0) && B < z + (w ? 0.07 : 0), I = [["i", -9, -0.55], ["e", -0.55, -0.2], ["a", -0.2, 0.35], ["o", 0.35, 0.75], ["u", 0.75, 9]], _ = w && I.find((B) => B[0] === w || w === "aHalf" && B[0] === "a");
955
- return _ && Y(d, _[1], _[2]) ? _[0] : I.find((B) => d >= B[1] && d < B[2])[0];
956
- }
957
- const l = 0.75, h = 0.3, E = 0.06, y = ["sad", "surprise"];
958
- function u(d, w, F = null) {
959
- return F && d >= h ? F : d >= l ? null : d < h ? w >= 0.5 ? "eyes_smile" : "eyes_closed" : "eyes_half";
960
- }
961
- function v(d, w, F = null) {
962
- if (d < m) return null;
963
- const Y = p(w, F);
964
- return Y === "a" ? d >= 0.6 ? "a" : "aHalf" : Y;
965
- }
966
- function x(d) {
967
- return a.cy + (d - a.cx) * Math.tan(a.angle);
968
- }
969
- function s() {
970
- return i.cx;
971
- }
972
- function c(d, w) {
973
- const F = Math.cos(-i.angle), Y = Math.sin(-i.angle), I = d - i.cx, _ = w - i.cy, B = (I * F - _ * Y) / i.rx, O = (I * Y + _ * F) / i.ry;
974
- return 1 - o(0.55, 0.95, Math.hypot(B, O));
975
- }
976
- function T(d, w, F, Y, I) {
977
- const _ = {}, B = (N) => N.startsWith("eyes_closed") || N.startsWith("eyes_smile"), O = (N) => g.some((G) => N === `mouth_${G}`), z = (N) => B(N) ? 1 : N.startsWith("eyes_") ? 0 : O(N) ? 2 : 3, D = Object.entries(w.layers).sort((N, G) => z(N[0]) - z(G[0]));
978
- for (const [N, G] of D) {
979
- const V = Y(G, e.mesh.spriteCell, I(F[N]), F[N].width), b = [], M = [];
980
- for (let L = 0; L < V.rest.length / 2; L++) {
981
- const U = V.rest[L * 2], X = V.rest[L * 2 + 1];
982
- b.push(t(U, X, 0)), M.push(N.startsWith("mouth") ? c(U, X) : 0);
952
+ }, y = 0.16, d = ["angry", "sad"];
953
+ function m(g, A) {
954
+ const B = (U, O, $) => U >= O - (A ? 0.07 : 0) && U < $ + (A ? 0.07 : 0), j = [["i", -9, -0.55], ["e", -0.55, -0.2], ["a", -0.2, 0.35], ["o", 0.35, 0.75], ["u", 0.75, 9]], k = A && j.find((U) => U[0] === A || A === "aHalf" && U[0] === "a");
955
+ return k && B(g, k[1], k[2]) ? k[0] : j.find((U) => g >= U[1] && g < U[2])[0];
956
+ }
957
+ const c = 0.75, p = 0.3, b = 0.06, v = ["sad", "surprise"];
958
+ function h(g, A, L = null) {
959
+ return L && g >= p ? L : g >= c ? null : g < p ? A >= 0.5 ? "eyes_smile" : "eyes_closed" : "eyes_half";
960
+ }
961
+ function u(g, A, L = null) {
962
+ if (g < y) return null;
963
+ const B = m(A, L);
964
+ return B === "a" ? g >= 0.6 ? "a" : "aHalf" : B;
965
+ }
966
+ function w(g) {
967
+ return a.cy + (g - a.cx) * Math.tan(a.angle);
968
+ }
969
+ function o() {
970
+ return l.cx;
971
+ }
972
+ function i(g, A) {
973
+ const L = Math.cos(-l.angle), B = Math.sin(-l.angle), j = g - l.cx, k = A - l.cy, U = (j * L - k * B) / l.rx, O = (j * B + k * L) / l.ry;
974
+ return 1 - s(0.55, 0.95, Math.hypot(U, O));
975
+ }
976
+ function S(g, A, L, B, j) {
977
+ const k = {}, U = (I) => I.startsWith("eyes_closed") || I.startsWith("eyes_smile"), O = (I) => d.some((V) => I === `mouth_${V}`), $ = (I) => U(I) ? 1 : I.startsWith("eyes_") ? 0 : O(I) ? 2 : 3, D = Object.entries(A.layers).sort((I, V) => $(I[0]) - $(V[0]));
978
+ for (const [I, V] of D) {
979
+ const K = B(V, e.mesh.spriteCell, j(L[I]), L[I].width), x = [], M = [];
980
+ for (let _ = 0; _ < K.rest.length / 2; _++) {
981
+ const Y = K.rest[_ * 2], X = K.rest[_ * 2 + 1];
982
+ x.push(t(Y, X, 0)), M.push(I.startsWith("mouth") ? i(Y, X) : 0);
983
983
  }
984
- const S = d.addLayer(N, F[N], V, { color: [0.4, 1, 0.8, 0.6] });
985
- S.visible = !1, _[N] = { mesh: V, W: b, inner: M, layer: S };
986
- }
987
- const J = [0, 1].map((N) => !!(_[`eyes_closed_${N}`] && _[`eyes_half_${N}`])), j = Object.values(f).some((N) => _[N.sprite]), H = (N, G) => (N === "eyes_smile" && !_[`eyes_smile_${G}`] && (N = "eyes_closed"), N === "open" || _[`${N}_${G}`] ? N : "open"), Z = [0, 0];
988
- let $ = null;
989
- const q = [0, 1].map(() => ({ cur: "open", prev: "open", t: 1 }));
990
- function W(N, G, V, b, M = 1) {
991
- const S = N.mesh.rest, L = N.mesh.pos;
992
- for (let U = 0; U < N.W.length; U++) {
993
- let X = S[U * 2], k = S[U * 2 + 1];
994
- const P = N.inner[U];
995
- if (P > 0) {
996
- const A = x(X);
997
- k = A + (k - A) * (1 + (b - 1) * P), X = s() + (X - s()) * (1 + (M - 1) * P);
984
+ const T = g.addLayer(I, L[I], K, { color: [0.4, 1, 0.8, 0.6] });
985
+ T.visible = !1, k[I] = { mesh: K, W: x, inner: M, layer: T };
986
+ }
987
+ const q = [0, 1].map((I) => !!(k[`eyes_closed_${I}`] && k[`eyes_half_${I}`])), N = Object.values(f).some((I) => k[I.sprite]), P = (I, V) => (I === "eyes_smile" && !k[`eyes_smile_${V}`] && (I = "eyes_closed"), I === "open" || k[`${I}_${V}`] ? I : "open"), H = [0, 0];
988
+ let G = null;
989
+ const z = [0, 1].map(() => ({ cur: "open", prev: "open", t: 1 }));
990
+ function W(I, V, K, x, M = 1) {
991
+ const T = I.mesh.rest, _ = I.mesh.pos;
992
+ for (let Y = 0; Y < I.W.length; Y++) {
993
+ let X = T[Y * 2], F = T[Y * 2 + 1];
994
+ const C = I.inner[Y];
995
+ if (C > 0) {
996
+ const Z = w(X);
997
+ F = Z + (F - Z) * (1 + (x - 1) * C), X = o() + (X - o()) * (1 + (M - 1) * C);
998
998
  }
999
- r(X, k, N.W[U], G, V, Z), L[U * 2] = Z[0], L[U * 2 + 1] = Z[1];
999
+ r(X, F, I.W[Y], V, K, H), _[Y * 2] = H[0], _[Y * 2 + 1] = H[1];
1000
1000
  }
1001
1001
  }
1002
1002
  return {
@@ -1007,43 +1007,86 @@ function Yn(n, e) {
1007
1007
  * `mood` (angry / sad / surprise) picks drawn expression eyes (sad, surprise) and closed
1008
1008
  * mouths (angry, sad) when the avatar has them.
1009
1009
  */
1010
- update(N, G, V = 1 / 60, b = null) {
1011
- for (const P of Object.values(_)) P.layer.visible = !1;
1010
+ update(I, V, K = 1 / 60, x = null) {
1011
+ for (const C of Object.values(k)) C.layer.visible = !1;
1012
1012
  const M = [!1, !1];
1013
1013
  [
1014
- [N.eyeROpen, N.eyeSmile],
1015
- [N.eyeLOpen, N.eyeSmileL ?? N.eyeSmile]
1016
- ].forEach(([P, A], R) => {
1017
- const C = q[R], Q = y.includes(b) && _[`eyes_${b}_${R}`] ? `eyes_${b}` : null, te = H(u(P, A, Q) ?? "open", R);
1018
- te !== C.cur && (C.prev = C.cur, C.cur = te, C.t = 0), C.t = V > 0 ? Math.min(1, C.t + V / E) : 1;
1019
- const ne = o(0, 1, C.t), ie = (me, He) => {
1020
- if (me === "open" || He <= 1e-3) return;
1021
- const we = _[`${me}_${R}`];
1022
- we && (we.layer.visible = !0, we.layer.alpha = He, W(we, N, G, 1));
1023
- }, se = (me) => me === "open" ? -1 : B(me) ? 1 : 0;
1024
- C.t >= 1 ? ie(C.cur, 1) : se(C.cur) > se(C.prev) ? (ie(C.prev, 1), ie(C.cur, ne)) : (ie(C.cur, 1), ie(C.prev, 1 - ne)), M[R] = C.cur !== "open" && ne >= 0.999;
1014
+ [I.eyeROpen, I.eyeSmile],
1015
+ [I.eyeLOpen, I.eyeSmileL ?? I.eyeSmile]
1016
+ ].forEach(([C, Z], E) => {
1017
+ const R = z[E], J = v.includes(x) && k[`eyes_${x}_${E}`] ? `eyes_${x}` : null, te = P(h(C, Z, J) ?? "open", E);
1018
+ te !== R.cur && (R.prev = R.cur, R.cur = te, R.t = 0), R.t = K > 0 ? Math.min(1, R.t + K / b) : 1;
1019
+ const ee = s(0, 1, R.t), se = (ce, je) => {
1020
+ if (ce === "open" || je <= 1e-3) return;
1021
+ const _e = k[`${ce}_${E}`];
1022
+ _e && (_e.layer.visible = !0, _e.layer.alpha = je, W(_e, I, V, 1));
1023
+ }, le = (ce) => ce === "open" ? -1 : U(ce) ? 1 : 0;
1024
+ R.t >= 1 ? se(R.cur, 1) : le(R.cur) > le(R.prev) ? (se(R.prev, 1), se(R.cur, ee)) : (se(R.cur, 1), se(R.prev, 1 - ee)), M[E] = R.cur !== "open" && ee >= 0.999;
1025
1025
  });
1026
- const L = v(N.mouthOpen, N.mouthForm, $);
1027
- $ = L;
1028
- const U = L && f[L], X = U && _[U.sprite], k = g.includes(b) && _[`mouth_${b}`];
1029
- if (k && (!X || N.mouthOpen < m + 0.04) && (k.layer.visible = !0, k.layer.alpha = 1, W(k, N, G, 1)), X) {
1030
- X.layer.visible = !0, X.layer.alpha = o(m, m + 0.04, N.mouthOpen);
1031
- const P = Math.min(1.1, Math.max(0.5, N.mouthOpen / U.ref));
1032
- W(X, N, G, P, U.width);
1026
+ const _ = u(I.mouthOpen, I.mouthForm, G);
1027
+ G = _;
1028
+ const Y = _ && f[_], X = Y && k[Y.sprite], F = d.includes(x) && k[`mouth_${x}`];
1029
+ if (F && (!X || I.mouthOpen < y + 0.04) && (F.layer.visible = !0, F.layer.alpha = 1, W(F, I, V, 1)), X) {
1030
+ X.layer.visible = !0, X.layer.alpha = s(y, y + 0.04, I.mouthOpen);
1031
+ const C = Math.min(1.1, Math.max(0.5, I.mouthOpen / Y.ref));
1032
+ W(X, I, V, C, Y.width);
1033
1033
  }
1034
- return { eyes: M, mouth: L, mouthDrawn: j && (!U || !!X) };
1034
+ return { eyes: M, mouth: _, mouthDrawn: N && (!Y || !!X) };
1035
1035
  },
1036
1036
  /** Whether each eye has the closed and half-closed drawings, so the layered eye stays open. */
1037
- eyesDrawn: J
1037
+ eyesDrawn: q
1038
1038
  };
1039
1039
  }
1040
- return { createSprites: T, mouthShape: v, eyeSprite: u };
1040
+ return { createSprites: S, mouthShape: u, eyeSprite: h };
1041
1041
  }
1042
- const Nt = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
1042
+ const $t = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
1043
1043
  function In(n, e) {
1044
- return n && n !== "neutral" ? Nt[n] ?? null : (e && Nt[e]) ?? null;
1044
+ return n && n !== "neutral" ? $t[n] ?? null : (e && $t[e]) ?? null;
1045
+ }
1046
+ function Nn(n, e, t, r = 6) {
1047
+ let a = e, s = t, l = -1, f = -1;
1048
+ for (let m = 0; m < t; m++) {
1049
+ const c = m * e;
1050
+ for (let p = 0; p < e; p++)
1051
+ n[c + p] > 3 && (p < a && (a = p), p > l && (l = p), m < s && (s = m), m > f && (f = m));
1052
+ }
1053
+ if (l < 0) return null;
1054
+ const y = Math.max(0, a - r), d = Math.max(0, s - r);
1055
+ return [y, d, Math.min(e, l + 1 + r) - y, Math.min(t, f + 1 + r) - d];
1056
+ }
1057
+ function Xn(n, e, t, r, a, s, l = 16, f, y, d) {
1058
+ const m = /* @__PURE__ */ new Map();
1059
+ for (const c of e.overlays) {
1060
+ const p = t[c.name];
1061
+ if (f !== void 0 && p.width !== f || y !== void 0 && p.height !== y)
1062
+ throw new Error(`overlay ${c.name}: image size does not match base.png`);
1063
+ const b = a(p), v = Nn(b, p.width, p.height);
1064
+ if (!v) continue;
1065
+ const [h, u, w, o] = v, i = new Uint8Array(w * o);
1066
+ for (let L = 0; L < o; L++) i.set(b.subarray((u + L) * p.width + h, (u + L) * p.width + h + w), L * w);
1067
+ const S = r(v, l, i, w), g = [];
1068
+ for (let L = 0; L < S.rest.length; L += 2) {
1069
+ const B = s(S.rest[L], S.rest[L + 1], 0);
1070
+ g.push({ ...B, brow: 0, jaw: 0 });
1071
+ }
1072
+ const A = n.addLayer(`overlay_${c.name}`, d(p, v), S);
1073
+ A.visible = !1, m.set(c.name, { mesh: S, weights: g, layer: A });
1074
+ }
1075
+ return {
1076
+ /** Shows the named overlays and hides the rest. Unknown names are ignored. */
1077
+ set(c) {
1078
+ const p = new Set(c);
1079
+ for (const [b, v] of m) v.layer.visible = p.has(b);
1080
+ },
1081
+ update(c, p, b, v) {
1082
+ for (const { mesh: h, weights: u, layer: w } of m.values())
1083
+ if (w.visible)
1084
+ for (let o = 0; o < u.length; o++)
1085
+ b(h.rest[o * 2], h.rest[o * 2 + 1], u[o], c, p, v), h.pos[o * 2] = v[0], h.pos[o * 2 + 1] = v[1];
1086
+ }
1087
+ };
1045
1088
  }
1046
- function At(n) {
1089
+ function St(n) {
1047
1090
  if (!n || typeof n != "object" || Array.isArray(n)) throw new TypeError("lipSync: expected an object");
1048
1091
  const e = n, t = {};
1049
1092
  for (const r of ["granularity", "openness", "closeSpeed"]) {
@@ -1061,32 +1104,32 @@ function At(n) {
1061
1104
  }
1062
1105
  return t;
1063
1106
  }
1064
- function jt(n = {}, e = {
1107
+ function zt(n = {}, e = {
1065
1108
  granularity: 0.5,
1066
1109
  openness: 0.5,
1067
1110
  closeSpeed: 0.5
1068
1111
  }) {
1069
- const t = At(n);
1112
+ const t = St(n);
1070
1113
  return {
1071
1114
  granularity: t.granularity ?? e.granularity,
1072
1115
  openness: t.openness ?? e.openness,
1073
1116
  closeSpeed: t.closeSpeed ?? e.closeSpeed
1074
1117
  };
1075
1118
  }
1076
- const Se = (n, e, t, r) => n === 0.5 ? t : n < 0.5 ? e + (t - e) * n * 2 : t + (r - t) * (n - 0.5) * 2;
1077
- function Xt(n) {
1119
+ const Ee = (n, e, t, r) => n === 0.5 ? t : n < 0.5 ? e + (t - e) * n * 2 : t + (r - t) * (n - 0.5) * 2;
1120
+ function Ct(n) {
1078
1121
  return {
1079
- arm: Se(n.granularity, 0.2, 0.6, 0.9),
1080
- trigger: Se(n.granularity, 0.65, 0.8, 0.95),
1081
- relax: Se(n.granularity, 1.5, 5, 12),
1082
- range: Se(n.granularity, 0.7, 0.3, 0.05),
1083
- risePower: Se(n.granularity, 0.05, 0.3, 0.8),
1084
- openness: Se(n.openness, 0.55, 1, 1.25),
1085
- audioRelease: Se(n.closeSpeed, 6, 32, 45),
1086
- kanaRelease: Se(n.closeSpeed, 6, 22, 45)
1122
+ arm: Ee(n.granularity, 0.2, 0.6, 0.9),
1123
+ trigger: Ee(n.granularity, 0.65, 0.8, 0.95),
1124
+ relax: Ee(n.granularity, 1.5, 5, 12),
1125
+ range: Ee(n.granularity, 0.7, 0.3, 0.05),
1126
+ risePower: Ee(n.granularity, 0.05, 0.3, 0.8),
1127
+ openness: Ee(n.openness, 0.55, 1, 1.25),
1128
+ audioRelease: Ee(n.closeSpeed, 6, 32, 45),
1129
+ kanaRelease: Ee(n.closeSpeed, 6, 22, 45)
1087
1130
  };
1088
1131
  }
1089
- const Nn = /* @__PURE__ */ new Set([
1132
+ const $n = /* @__PURE__ */ new Set([
1090
1133
  "angleX",
1091
1134
  "angleY",
1092
1135
  "angleZ",
@@ -1096,7 +1139,7 @@ const Nn = /* @__PURE__ */ new Set([
1096
1139
  "handAngle",
1097
1140
  "gazeX",
1098
1141
  "gazeY"
1099
- ]), Mt = {
1142
+ ]), Tt = {
1100
1143
  nod: {
1101
1144
  label: "Nod",
1102
1145
  dur: 1.7,
@@ -1244,7 +1287,7 @@ const Nn = /* @__PURE__ */ new Set([
1244
1287
  blush: [[0, 0], [1.6, 0.3], [2.6, 0]]
1245
1288
  }
1246
1289
  }
1247
- }, Et = {
1290
+ }, Ot = {
1248
1291
  lookAround: {
1249
1292
  label: "Look around",
1250
1293
  dur: 5.2,
@@ -1484,16 +1527,16 @@ const Nn = /* @__PURE__ */ new Set([
1484
1527
  }
1485
1528
  }
1486
1529
  };
1487
- function jn(n, e) {
1530
+ function zn(n, e) {
1488
1531
  if (e <= n[0][0]) return n[0][1];
1489
1532
  const t = n.length - 1;
1490
1533
  if (e >= n[t][0]) return n[t][1];
1491
1534
  let r = 0;
1492
1535
  for (; e > n[r + 1][0]; ) r++;
1493
- const [a, o] = n[r], [i, f] = n[r + 1], m = (u) => u <= 0 || u >= t ? 0 : (n[u + 1][1] - n[u - 1][1]) / (n[u + 1][0] - n[u - 1][0]), g = i - a, p = (e - a) / g, l = m(r) * g, h = m(r + 1) * g, E = p * p, y = E * p;
1494
- return (2 * y - 3 * E + 1) * o + (y - 2 * E + p) * l + (-2 * y + 3 * E) * f + (y - E) * h;
1536
+ const [a, s] = n[r], [l, f] = n[r + 1], y = (h) => h <= 0 || h >= t ? 0 : (n[h + 1][1] - n[h - 1][1]) / (n[h + 1][0] - n[h - 1][0]), d = l - a, m = (e - a) / d, c = y(r) * d, p = y(r + 1) * d, b = m * m, v = b * m;
1537
+ return (2 * v - 3 * b + 1) * s + (v - 2 * b + m) * c + (-2 * v + 3 * b) * f + (v - b) * p;
1495
1538
  }
1496
- const ze = {
1539
+ const Pe = {
1497
1540
  a: { open: 0.9, form: 0, label: "あ" },
1498
1541
  i: { open: 0.5, form: -0.85, label: "い" },
1499
1542
  u: { open: 0.4, form: 0.9, label: "う" },
@@ -1501,21 +1544,21 @@ const ze = {
1501
1544
  o: { open: 0.75, form: 0.6, label: "お" },
1502
1545
  n: { open: 0, form: null, label: "ん" }
1503
1546
  // closes with the previous shape
1504
- }, Xn = {
1547
+ }, Cn = {
1505
1548
  a: "あかさたなはまやらわがざだばぱぁ",
1506
1549
  i: "いきしちにひみりぎじぢびぴぃ",
1507
1550
  u: "うくすつぬふむゆるぐずづぶぷぅゔ",
1508
1551
  e: "えけせてねへめれげぜでべぺぇ",
1509
1552
  o: "おこそとのほもよろをごぞどぼぽぉ"
1510
- }, en = {};
1511
- for (const [n, e] of Object.entries(Xn)) for (const t of e) en[t] = n;
1512
- const $n = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), Cn = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), $t = { ゃ: "a", ゅ: "u", ょ: "o" }, zn = /* @__PURE__ */ new Set([..."、。,.,.!?!?  …"]), Pn = (n) => n.replace(/[ァ-ヶ]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 96));
1513
- function Dn(n, e = 0.14) {
1553
+ }, tn = {};
1554
+ for (const [n, e] of Object.entries(Cn)) for (const t of e) tn[t] = n;
1555
+ const Pn = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), Dn = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), Pt = { ゃ: "a", ゅ: "u", ょ: "o" }, Hn = /* @__PURE__ */ new Set([..."、。,.,.!?!?  …"]), Zn = (n) => n.replace(/[ァ-ヶ]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 96));
1556
+ function Wn(n, e = 0.14) {
1514
1557
  const t = [];
1515
- for (const r of Pn(n)) {
1558
+ for (const r of Zn(n)) {
1516
1559
  const a = t[t.length - 1];
1517
- if ($t[r] && a) {
1518
- a.vowel = $t[r];
1560
+ if (Pt[r] && a) {
1561
+ a.vowel = Pt[r];
1519
1562
  continue;
1520
1563
  }
1521
1564
  if (r === "ー" && a) {
@@ -1530,41 +1573,41 @@ function Dn(n, e = 0.14) {
1530
1573
  t.push({ vowel: "n", dur: e, onset: null });
1531
1574
  continue;
1532
1575
  }
1533
- if (zn.has(r)) {
1576
+ if (Hn.has(r)) {
1534
1577
  t.push({ vowel: "n", dur: e * 2.2, onset: null });
1535
1578
  continue;
1536
1579
  }
1537
- const o = en[r];
1538
- o && t.push({ vowel: o, dur: e, onset: $n.has(r) ? "lips" : Cn.has(r) ? null : "consonant" });
1580
+ const s = tn[r];
1581
+ s && t.push({ vowel: s, dur: e, onset: Pn.has(r) ? "lips" : Dn.has(r) ? null : "consonant" });
1539
1582
  }
1540
1583
  return t;
1541
1584
  }
1542
- function Hn(n, e, t = 0.5) {
1543
- if (t !== 0.5) return Zn(n, e, t);
1585
+ function Gn(n, e, t = 0.5) {
1586
+ if (t !== 0.5) return Vn(n, e, t);
1544
1587
  let r = 0;
1545
1588
  for (const a of n) {
1546
1589
  if (e < r + a.dur) {
1547
- const o = (e - r) / a.dur, i = ze[a.vowel], f = a.onset === "lips" ? 0.05 : a.onset === "consonant" ? 0.45 : 1, m = o < 0.35 ? f + (1 - f) * (o / 0.35) : 1;
1548
- return { open: i.open * m, form: i.form, vowel: a.vowel };
1590
+ const s = (e - r) / a.dur, l = Pe[a.vowel], f = a.onset === "lips" ? 0.05 : a.onset === "consonant" ? 0.45 : 1, y = s < 0.35 ? f + (1 - f) * (s / 0.35) : 1;
1591
+ return { open: l.open * y, form: l.form, vowel: a.vowel };
1549
1592
  }
1550
1593
  r += a.dur;
1551
1594
  }
1552
1595
  return null;
1553
1596
  }
1554
- function Zn(n, e, t) {
1597
+ function Vn(n, e, t) {
1555
1598
  const r = t < 0.5 ? (0.5 - t) * 0.72 : 0;
1556
- let a = 0, o = 0, i = null;
1599
+ let a = 0, s = 0, l = null;
1557
1600
  for (const f of n) {
1558
- let m = f.vowel;
1559
- if (f.vowel === "n" ? r && f.dur <= 0.2 && i ? m = i : (o = 0, i = null) : ((!i || o >= r) && (i = f.vowel, o = 0), o += f.dur, r && (m = i)), e < a + f.dur) {
1560
- const g = ze[m], p = f.onset === "lips" ? 0.05 : f.onset === "consonant" ? 0.45 : 1, l = t < 0.5 ? 1 - (1 - p) * t * 2 : p * (2 - t * 2), h = Math.min(f.dur * 0.35, 0.05), E = (e - a) / h;
1561
- return { open: g.open * (E < 1 ? l + (1 - l) * E : 1), form: g.form, vowel: m };
1601
+ let y = f.vowel;
1602
+ if (f.vowel === "n" ? r && f.dur <= 0.2 && l ? y = l : (s = 0, l = null) : ((!l || s >= r) && (l = f.vowel, s = 0), s += f.dur, r && (y = l)), e < a + f.dur) {
1603
+ const d = Pe[y], m = f.onset === "lips" ? 0.05 : f.onset === "consonant" ? 0.45 : 1, c = t < 0.5 ? 1 - (1 - m) * t * 2 : m * (2 - t * 2), p = Math.min(f.dur * 0.35, 0.05), b = (e - a) / p;
1604
+ return { open: d.open * (b < 1 ? c + (1 - c) * b : 1), form: d.form, vowel: y };
1562
1605
  }
1563
1606
  a += f.dur;
1564
1607
  }
1565
1608
  return null;
1566
1609
  }
1567
- const nt = { ...Mt, ...Et }, Ct = { amp: 1, stiff: 1.8 }, Wn = /^(angle|bodyAngle|armAngle|handAngle)/, Gn = /* @__PURE__ */ new Set([
1610
+ const at = { ...Tt, ...Ot }, Dt = { amp: 1, stiff: 1.8 }, qn = /^(angle|bodyAngle|armAngle|handAngle)/, Jn = /* @__PURE__ */ new Set([
1568
1611
  "eyeOpen",
1569
1612
  "eyeOpenL",
1570
1613
  "eyeSmileL",
@@ -1574,18 +1617,18 @@ const nt = { ...Mt, ...Et }, Ct = { amp: 1, stiff: 1.8 }, Wn = /^(angle|bodyAngl
1574
1617
  "blush",
1575
1618
  "browY",
1576
1619
  "browAngle"
1577
- ]), Ve = (n, e, t) => {
1620
+ ]), qe = (n, e, t) => {
1578
1621
  const r = Math.min(1, Math.max(0, (t - n) / (e - n)));
1579
1622
  return r * r * (3 - 2 * r);
1580
1623
  };
1581
- function zt(n, e) {
1582
- const t = Math.floor(n), r = n - t, a = (i) => {
1583
- const f = Math.sin((i + e * 57.3) * 127.1) * 43758.5453;
1624
+ function Ht(n, e) {
1625
+ const t = Math.floor(n), r = n - t, a = (l) => {
1626
+ const f = Math.sin((l + e * 57.3) * 127.1) * 43758.5453;
1584
1627
  return f - Math.floor(f);
1585
- }, o = r * r * (3 - 2 * r);
1586
- return (a(t) * (1 - o) + a(t + 1) * o) * 2 - 1;
1628
+ }, s = r * r * (3 - 2 * r);
1629
+ return (a(t) * (1 - s) + a(t + 1) * s) * 2 - 1;
1587
1630
  }
1588
- const Me = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, pe = (n, e, t) => Math.max(e, Math.min(t, n)), tn = {
1631
+ const Ae = (n, e) => Ht(n, e) * 0.7 + Ht(n * 2.3, e + 9) * 0.3, pe = (n, e, t) => Math.max(e, Math.min(t, n)), nn = {
1589
1632
  normal: { label: "Neutral", p: {} },
1590
1633
  smile: { label: "Smile", p: { eyeOpen: 0, eyeSmile: 1, blush: 0.35, browY: 0.2 } },
1591
1634
  shy: { label: "Blush", p: { eyeOpen: 0.78, eyeSmile: 0.5, blush: 1, browAngle: -0.5, browY: -0.1, glance: [0.7, 0.35] } },
@@ -1599,14 +1642,14 @@ const Me = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, pe = (n, e, t) =
1599
1642
  angryTalk: { label: "angry", p: { eyeOpen: 0.72, browAngle: 0.85, browY: -0.55, mouthForm: 0.2 } },
1600
1643
  surprisedTalk: { label: "surprised", p: { eyeOpen: 1.18, browY: 0.9, mouthForm: 0.9 } },
1601
1644
  relaxedTalk: { label: "relaxed", p: { eyeOpen: 0.82, eyeSmile: 0.35, blush: 0.15, browY: 0.1 } }
1602
- }, Pt = {
1645
+ }, Zt = {
1603
1646
  happy: ["happyTalk", "nod"],
1604
1647
  sad: ["sadTalk", "sigh"],
1605
1648
  angry: ["angryTalk", "no"],
1606
1649
  surprised: ["surprisedTalk", "surprise"],
1607
1650
  relaxed: ["relaxedTalk", "sway"],
1608
1651
  neutral: ["normal", null]
1609
- }, Vn = {
1652
+ }, Kn = {
1610
1653
  gazeX: [260, 0.9],
1611
1654
  gazeY: [260, 0.9],
1612
1655
  angleX: [55, 0.72],
@@ -1617,41 +1660,41 @@ const Me = (n, e) => zt(n, e) * 0.7 + zt(n * 2.3, e + 9) * 0.3, pe = (n, e, t) =
1617
1660
  armAngle: [20, 0.85],
1618
1661
  handAngle: [30, 0.8]
1619
1662
  };
1620
- class qn {
1663
+ class Qn {
1621
1664
  /** @param {number[]} gazeCenter */
1622
1665
  constructor(e) {
1623
- this.mode = "auto", this.P = Object.fromEntries(We.map((t) => [t.id, t.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(We.map((t) => [t.id, 0])), this.expr = "normal", this.exprMix = {}, this.t = 0, this.blink = { t: 0, start: 1.5, double: !1 }, this.gaze = { x: 0, y: 0, next: 0 }, this.tap = { next: 4, until: -1 }, this.pointer = null, this.faceCenter = [...e], this.lipOpen = null, this.lipForm = 0, this.speaking = !1, this.voice = 0, this.mouth = 0, this.vowel = "a", this.vowelForm = 0, this.lipSync = jt(), this.lipMotion = Xt(this.lipSync), this.syllableArmed = !0, this.voicePeak = 0, this.voiceTrough = 0, this.kana = null, this.lipHold = null, this.emotionUntil = 0, this.talkGain = 1, this.play = null, this.autoMotion = !0, this.nextAuto = 14, this.autoIdle = !0, this.nextIdle = 3, this.lastAuto = null, this.onMotion = null;
1666
+ this.mode = "auto", this.P = Object.fromEntries(Ge.map((t) => [t.id, t.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(Ge.map((t) => [t.id, 0])), this.expr = "normal", this.exprMix = {}, this.t = 0, this.blink = { t: 0, start: 1.5, double: !1 }, this.gaze = { x: 0, y: 0, next: 0 }, this.tap = { next: 4, until: -1 }, this.pointer = null, this.faceCenter = [...e], this.lipOpen = null, this.lipForm = 0, this.speaking = !1, this.voice = 0, this.mouth = 0, this.vowel = "a", this.vowelForm = 0, this.lipSync = zt(), this.lipMotion = Ct(this.lipSync), this.syllableArmed = !0, this.voicePeak = 0, this.voiceTrough = 0, this.kana = null, this.lipHold = null, this.emotionUntil = 0, this.talkGain = 1, this.play = null, this.autoMotion = !0, this.nextAuto = 14, this.autoIdle = !0, this.nextIdle = 3, this.lastAuto = null, this.onMotion = null;
1624
1667
  }
1625
1668
  setExpression(e) {
1626
1669
  this.expr = e;
1627
1670
  }
1628
1671
  hasMotion(e) {
1629
- return e in nt;
1672
+ return e in at;
1630
1673
  }
1631
1674
  // ---- speech (driven from outside, e.g. by the TTS audio analyser) ----
1632
1675
  setVoiceLevel(e) {
1633
1676
  this.voice = Math.min(1, Math.max(0, Number(e) || 0));
1634
1677
  }
1635
1678
  setLipSync(e) {
1636
- this.lipSync = jt(e, this.lipSync), this.lipMotion = Xt(this.lipSync);
1679
+ this.lipSync = zt(e, this.lipSync), this.lipMotion = Ct(this.lipSync);
1637
1680
  }
1638
1681
  setSpeaking(e) {
1639
1682
  e !== this.speaking && (this.speaking = !!e, e || (this.emotionUntil = this.t + 1.2, this.voice = 0));
1640
1683
  }
1641
1684
  /** `playMotion: false` changes only the face (a caller that picks motions itself). */
1642
1685
  setEmotion(e, { playMotion: t = !0 } = {}) {
1643
- const r = Pt[e] ?? Pt.neutral;
1686
+ const r = Zt[e] ?? Zt.neutral;
1644
1687
  this.expr = r[0], this.emotionUntil = 1 / 0, r[1] && t && this.playMotion(r[1]);
1645
1688
  }
1646
1689
  /** Mouth shapes from kana text, without audio (preview / tuning). */
1647
1690
  /** @param {string} text @param {{ speed?: number, loop?: boolean }} [options] */
1648
1691
  speakKana(e, { speed: t, loop: r = !1 } = {}) {
1649
1692
  this.lipHold = null;
1650
- const a = Dn(e, t === void 0 ? 0.14 : 1 / pe(Number(t) || 7, 4, 12));
1651
- this.kana = a.length ? { moras: a, t: 0, loop: r, duration: a.reduce((o, i) => o + i.dur, 0) } : null;
1693
+ const a = Wn(e, t === void 0 ? 0.14 : 1 / pe(Number(t) || 7, 4, 12));
1694
+ this.kana = a.length ? { moras: a, t: 0, loop: r, duration: a.reduce((s, l) => s + l.dur, 0) } : null;
1652
1695
  }
1653
1696
  holdMouth(e) {
1654
- this.kana = null, this.lipHold = Object.hasOwn(ze, e) ? e : null;
1697
+ this.kana = null, this.lipHold = Object.hasOwn(Pe, e) ? e : null;
1655
1698
  }
1656
1699
  stopLipSync() {
1657
1700
  this.kana = null, this.lipHold = null, this.lipOpen = null, this.mouth = 0;
@@ -1667,11 +1710,11 @@ class qn {
1667
1710
  // the dip before each mora even when a loud voice never gets quiet.
1668
1711
  speechMouth(e) {
1669
1712
  if (this.kana || this.lipHold) {
1670
- let h;
1671
- if (this.lipHold ? h = ze[this.lipHold] : (this.kana.t += e, this.kana.loop && (this.kana.t %= this.kana.duration), h = Hn(this.kana.moras, this.kana.t, this.lipSync.granularity)), !h)
1713
+ let p;
1714
+ if (this.lipHold ? p = Pe[this.lipHold] : (this.kana.t += e, this.kana.loop && (this.kana.t %= this.kana.duration), p = Gn(this.kana.moras, this.kana.t, this.lipSync.granularity)), !p)
1672
1715
  return this.kana = null, this.mouth > 0.01 ? [this.mouth *= this.lipSync.closeSpeed === 0.5 ? 0.6 : Math.exp(-e * this.lipMotion.kanaRelease), this.vowelForm] : null;
1673
- const E = this.lipMotion.openness === 1 ? h.open : Math.min(1, h.open * this.lipMotion.openness), y = E > this.mouth ? 1 - Math.exp(-e * 30) : 1 - Math.exp(-e * this.lipMotion.kanaRelease);
1674
- return this.mouth += (E - this.mouth) * y, h.form !== null && (this.vowelForm = h.form), [this.mouth, this.vowelForm];
1716
+ const b = this.lipMotion.openness === 1 ? p.open : Math.min(1, p.open * this.lipMotion.openness), v = b > this.mouth ? 1 - Math.exp(-e * 30) : 1 - Math.exp(-e * this.lipMotion.kanaRelease);
1717
+ return this.mouth += (b - this.mouth) * v, p.form !== null && (this.vowelForm = p.form), [this.mouth, this.vowelForm];
1675
1718
  }
1676
1719
  const t = this.speaking ? this.voice : 0, r = 1 - Math.exp(-e * this.lipMotion.relax);
1677
1720
  this.voicePeak = t > this.voicePeak ? t : this.voicePeak + (t - this.voicePeak) * r, this.voiceTrough = t < this.voiceTrough ? t : this.voiceTrough + (t - this.voiceTrough) * r;
@@ -1679,18 +1722,18 @@ class qn {
1679
1722
  if (t < a * this.lipMotion.arm) this.syllableArmed = !0;
1680
1723
  else if (this.syllableArmed && t > a * this.lipMotion.trigger && t > 0.1) {
1681
1724
  this.syllableArmed = !1;
1682
- const h = Math.random();
1683
- this.vowel = h < 0.4 ? "a" : h < 0.58 ? "o" : h < 0.74 ? "e" : h < 0.88 ? "i" : "u";
1725
+ const p = Math.random();
1726
+ this.vowel = p < 0.4 ? "a" : p < 0.58 ? "o" : p < 0.74 ? "e" : p < 0.88 ? "i" : "u";
1684
1727
  }
1685
- const o = this.voicePeak - this.voiceTrough, i = o < a * this.lipMotion.range ? 1 : Math.max(0, (t - this.voiceTrough) / o), f = ze[this.vowel ?? "a"], m = Math.min(1, Math.pow(t, 0.7) * 1.15) * Math.pow(i, this.lipMotion.risePower), g = this.speaking ? Math.min(0.95, m) * (0.45 + 0.55 * f.open / 0.9) : 0, p = this.lipMotion.openness === 1 ? g : Math.min(1, g * this.lipMotion.openness), l = p > this.mouth ? 1 - Math.exp(-e * 40) : 1 - Math.exp(-e * this.lipMotion.audioRelease);
1686
- return this.mouth += (p - this.mouth) * l, this.speaking && (this.vowelForm = f.form), this.speaking || this.mouth > 0.01 ? [this.mouth, this.vowelForm] : null;
1728
+ const s = this.voicePeak - this.voiceTrough, l = s < a * this.lipMotion.range ? 1 : Math.max(0, (t - this.voiceTrough) / s), f = Pe[this.vowel ?? "a"], y = Math.min(1, Math.pow(t, 0.7) * 1.15) * Math.pow(l, this.lipMotion.risePower), d = this.speaking ? Math.min(0.95, y) * (0.45 + 0.55 * f.open / 0.9) : 0, m = this.lipMotion.openness === 1 ? d : Math.min(1, d * this.lipMotion.openness), c = m > this.mouth ? 1 - Math.exp(-e * 40) : 1 - Math.exp(-e * this.lipMotion.audioRelease);
1729
+ return this.mouth += (m - this.mouth) * c, this.speaking && (this.vowelForm = f.form), this.speaking || this.mouth > 0.01 ? [this.mouth, this.vowelForm] : null;
1687
1730
  }
1688
1731
  // Breathing: inhale ~40% of the cycle, a slower exhale, a short pause at the bottom,
1689
1732
  // and a period that drifts between ~3.2 and 4.6 s so it never looks metronomic.
1690
1733
  breathValue(e) {
1691
1734
  this.breathPhase = (this.breathPhase ?? 0) + e / (this.breathPeriod ?? 3.8), this.breathPhase >= 1 && (this.breathPhase -= 1, this.breathPeriod = 3.2 + Math.random() * 1.4);
1692
1735
  const t = this.breathPhase;
1693
- return t < 0.4 ? Ve(0, 0.4, t) : t < 0.88 ? 1 - Ve(0.4, 0.88, t) : 0;
1736
+ return t < 0.4 ? qe(0, 0.4, t) : t < 0.88 ? 1 - qe(0.4, 0.88, t) : 0;
1694
1737
  }
1695
1738
  // pick one at random, never the one that just played
1696
1739
  playRandom(e) {
@@ -1709,81 +1752,81 @@ class qn {
1709
1752
  update(e) {
1710
1753
  this.t += e;
1711
1754
  const t = this.t, r = {};
1712
- for (const y of We) r[y.id] = y.def;
1755
+ for (const v of Ge) r[v.id] = v.def;
1713
1756
  if (this.mode === "manual")
1714
1757
  Object.assign(r, this.manual);
1715
1758
  else if (this.mode === "auto") {
1716
- if (r.angleX = Me(t * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = Me(t * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = Me(t * 0.12, 3) * 10, r.bodyAngleX = Me(t * 0.1, 4) * 5, r.bodyAngleZ = Me(t * 0.09, 5) * 4, r.armAngle = Me(t * 0.14, 6) * 5, r.handAngle = Me(t * 0.21, 7) * 5, t > this.gaze.next) {
1717
- const y = Math.random();
1718
- this.gaze.x = y < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.8, this.gaze.y = y < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.5, this.gaze.next = t + 0.8 + Math.random() * 2.5;
1759
+ if (r.angleX = Ae(t * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = Ae(t * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = Ae(t * 0.12, 3) * 10, r.bodyAngleX = Ae(t * 0.1, 4) * 5, r.bodyAngleZ = Ae(t * 0.09, 5) * 4, r.armAngle = Ae(t * 0.14, 6) * 5, r.handAngle = Ae(t * 0.21, 7) * 5, t > this.gaze.next) {
1760
+ const v = Math.random();
1761
+ this.gaze.x = v < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.8, this.gaze.y = v < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.5, this.gaze.next = t + 0.8 + Math.random() * 2.5;
1719
1762
  }
1720
1763
  if (r.gazeX = this.gaze.x + r.angleX / 60, r.gazeY = this.gaze.y + r.angleY / 60, t > this.tap.next && (this.tap.until = t + 1.1, this.tap.next = t + 5 + Math.random() * 6), this.speaking) {
1721
1764
  this.nextIdle = Math.max(this.nextIdle, t + 2.5), this.nextAuto = Math.max(this.nextAuto, t + 6);
1722
- const y = this.talkGain;
1723
- this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * y - (this.talkNod ?? 0)) * Math.min(1, e * 6), r.angleY -= this.talkNod, r.angleX += Me(t * 0.6, 11) * 5 * y, r.angleZ += Me(t * 0.5, 12) * 4 * y;
1765
+ const v = this.talkGain;
1766
+ this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * v - (this.talkNod ?? 0)) * Math.min(1, e * 6), r.angleY -= this.talkNod, r.angleX += Ae(t * 0.6, 11) * 5 * v, r.angleZ += Ae(t * 0.5, 12) * 4 * v;
1724
1767
  }
1725
- !this.speaking && t > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && t > this.nextAuto ? (this.playRandom(Object.keys(Mt).filter((y) => y !== "surprise")), this.nextAuto = t + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, t + 5)) : !this.play && this.autoIdle && t > this.nextIdle && (this.playRandom(Object.keys(Et)), this.nextIdle = t + 5 + Math.random() * 5));
1768
+ !this.speaking && t > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && t > this.nextAuto ? (this.playRandom(Object.keys(Tt).filter((v) => v !== "surprise")), this.nextAuto = t + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, t + 5)) : !this.play && this.autoIdle && t > this.nextIdle && (this.playRandom(Object.keys(Ot)), this.nextIdle = t + 5 + Math.random() * 5));
1726
1769
  } else if (this.mode === "mouse" && this.pointer) {
1727
- const y = (this.pointer[0] - this.faceCenter[0]) / 500, u = (this.pointer[1] - this.faceCenter[1]) / 500;
1728
- r.angleX = pe(y * 30, -30, 30), r.angleY = pe(-u * 30, -30, 30), r.angleZ = pe(-y * u * 25, -12, 12), r.bodyAngleX = pe(y * 10, -10, 10) * 0.6, r.gazeX = pe(y * 1.4, -1, 1), r.gazeY = pe(-u * 1.4, -1, 1), r.handAngle = pe(y * 4, -5, 5);
1770
+ const v = (this.pointer[0] - this.faceCenter[0]) / 500, h = (this.pointer[1] - this.faceCenter[1]) / 500;
1771
+ r.angleX = pe(v * 30, -30, 30), r.angleY = pe(-h * 30, -30, 30), r.angleZ = pe(-v * h * 25, -12, 12), r.bodyAngleX = pe(v * 10, -10, 10) * 0.6, r.gazeX = pe(v * 1.4, -1, 1), r.gazeY = pe(-h * 1.4, -1, 1), r.handAngle = pe(v * 4, -5, 5);
1729
1772
  }
1730
1773
  this.mode !== "manual" && (r.breath = this.breathValue(e), t < this.tap.until && (r.fingerTap = Math.max(0, Math.sin((this.tap.until - t) * Math.PI * 3.6)) ** 2));
1731
- let a = null, o = 0;
1774
+ let a = null, s = 0;
1732
1775
  if (this.play) {
1733
- const y = nt[this.play.id];
1734
- if (this.play.t += e, this.play.t >= y.dur)
1776
+ const v = at[this.play.id];
1777
+ if (this.play.t += e, this.play.t >= v.dur)
1735
1778
  this.play = null, this.onMotion?.(null);
1736
1779
  else {
1737
1780
  a = {};
1738
- for (const [u, v] of Object.entries(y.tracks))
1739
- a[u] = jn(v, this.play.t) * (y.idle && Wn.test(u) ? Ct.amp : 1);
1740
- o = Ve(0, 0.15, this.play.t) * (1 - Ve(y.dur - 0.25, y.dur, this.play.t));
1741
- for (const [u, v] of Object.entries(a))
1742
- Nn.has(u) ? r[u] += v : u === "breath" ? r[u] += (v - r[u]) * o : Gn.has(u) || (r[u] = Math.max(r[u], Math.max(0, v)));
1781
+ for (const [h, u] of Object.entries(v.tracks))
1782
+ a[h] = zn(u, this.play.t) * (v.idle && qn.test(h) ? Dt.amp : 1);
1783
+ s = qe(0, 0.15, this.play.t) * (1 - qe(v.dur - 0.25, v.dur, this.play.t));
1784
+ for (const [h, u] of Object.entries(a))
1785
+ $n.has(h) ? r[h] += u : h === "breath" ? r[h] += (u - r[h]) * s : Jn.has(h) || (r[h] = Math.max(r[h], Math.max(0, u)));
1743
1786
  }
1744
1787
  }
1745
1788
  this.mode !== "manual" && (r.angleY += r.breath * 1.6);
1746
- const i = tn[this.expr].p, f = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], m = {
1747
- eyeOpen: i.eyeOpen ?? 1,
1748
- eyeOpenL: i.eyeOpenL ?? i.eyeOpen ?? 1,
1749
- eyeSmileL: i.eyeSmileL ?? i.eyeSmile ?? 0,
1750
- eyeSmile: i.eyeSmile ?? 0,
1751
- mouthOpen: i.mouthOpen ?? 0,
1752
- mouthForm: i.mouthForm ?? 0,
1753
- blush: i.blush ?? 0,
1754
- browY: i.browY ?? 0,
1755
- browAngle: i.browAngle ?? 0,
1756
- gx: i.glance?.[0] ?? 0,
1757
- gy: i.glance?.[1] ?? 0
1758
- }, g = 1 - Math.exp(-e * 9);
1759
- for (const y of f)
1760
- this.exprMix[y] === void 0 && (this.exprMix[y] = m[y]), this.exprMix[y] += (m[y] - this.exprMix[y]) * g;
1761
- const p = this.exprMix, l = {};
1762
- for (const y of We) {
1763
- const u = y.id;
1789
+ const l = nn[this.expr].p, f = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], y = {
1790
+ eyeOpen: l.eyeOpen ?? 1,
1791
+ eyeOpenL: l.eyeOpenL ?? l.eyeOpen ?? 1,
1792
+ eyeSmileL: l.eyeSmileL ?? l.eyeSmile ?? 0,
1793
+ eyeSmile: l.eyeSmile ?? 0,
1794
+ mouthOpen: l.mouthOpen ?? 0,
1795
+ mouthForm: l.mouthForm ?? 0,
1796
+ blush: l.blush ?? 0,
1797
+ browY: l.browY ?? 0,
1798
+ browAngle: l.browAngle ?? 0,
1799
+ gx: l.glance?.[0] ?? 0,
1800
+ gy: l.glance?.[1] ?? 0
1801
+ }, d = 1 - Math.exp(-e * 9);
1802
+ for (const v of f)
1803
+ this.exprMix[v] === void 0 && (this.exprMix[v] = y[v]), this.exprMix[v] += (y[v] - this.exprMix[v]) * d;
1804
+ const m = this.exprMix, c = {};
1805
+ for (const v of Ge) {
1806
+ const h = v.id;
1764
1807
  if (this.mode === "manual" && !a) {
1765
- l[u] = r[u], this.cur[u] = r[u], this.vel[u] = 0;
1808
+ c[h] = r[h], this.cur[h] = r[h], this.vel[h] = 0;
1766
1809
  continue;
1767
1810
  }
1768
- let [v, x] = Vn[u] ?? [120, 0.95];
1769
- a && /^angle|^body/.test(u) && (nt[this.play?.id ?? ""]?.idle ? (v *= Ct.stiff, x = 0.8) : /^angle/.test(u) && (v *= 4.5, x = 0.75));
1770
- const s = 2 * Math.sqrt(v) * x;
1771
- this.vel[u] += (v * (r[u] - this.cur[u]) - s * this.vel[u]) * e, this.cur[u] += this.vel[u] * e, l[u] = this.cur[u];
1772
- }
1773
- let h = 1;
1774
- if (this.mode !== "manual" ? (h = this.blinkValue(e), l.eyeROpen = p.eyeOpen * h, l.eyeLOpen = p.eyeOpenL * h, l.eyeSmile = p.eyeSmile, l.eyeSmileL = p.eyeSmileL, l.mouthOpen = p.mouthOpen, l.mouthForm = p.mouthForm, l.blush = p.blush, l.browY = p.browY + (l.angleY > 0 ? l.angleY / 60 : 0) - (1 - h) * 0.18, l.browAngle = p.browAngle, l.gazeX = pe(l.gazeX + p.gx, -1, 1), l.gazeY = pe(l.gazeY + p.gy, -1, 1)) : l.eyeSmileL = l.eyeSmile, a) {
1775
- const y = (v, x) => {
1776
- l[v] += (x - l[v]) * o;
1777
- }, u = (v) => Math.min(1.3, Math.max(0, v));
1778
- "eyeOpen" in a && (y("eyeROpen", u(a.eyeOpen) * h), "eyeOpenL" in a || y("eyeLOpen", u(a.eyeOpen) * h)), "eyeOpenL" in a && y("eyeLOpen", u(a.eyeOpenL) * h), "eyeSmile" in a && (y("eyeSmile", a.eyeSmile), "eyeSmileL" in a || y("eyeSmileL", a.eyeSmile)), "eyeSmileL" in a && y("eyeSmileL", a.eyeSmileL);
1779
- for (const v of ["mouthOpen", "mouthForm", "blush", "browY", "browAngle"])
1780
- v in a && y(v, v === "mouthOpen" || v === "blush" ? Math.max(0, a[v]) : a[v]);
1781
- }
1782
- const E = this.speechMouth(e);
1783
- return E ? (this.lipOpen = E[0], this.lipForm = E[1]) : this.lipOpen !== null && !this.speaking && !this.kana && (this.lipOpen = null), this.lipOpen !== null && (l.mouthOpen = Math.max(l.mouthOpen * 0.3, this.lipOpen), l.mouthForm = pe(this.lipForm, -1, 1)), this.P = l, l;
1811
+ let [u, w] = Kn[h] ?? [120, 0.95];
1812
+ a && /^angle|^body/.test(h) && (at[this.play?.id ?? ""]?.idle ? (u *= Dt.stiff, w = 0.8) : /^angle/.test(h) && (u *= 4.5, w = 0.75));
1813
+ const o = 2 * Math.sqrt(u) * w;
1814
+ this.vel[h] += (u * (r[h] - this.cur[h]) - o * this.vel[h]) * e, this.cur[h] += this.vel[h] * e, c[h] = this.cur[h];
1815
+ }
1816
+ let p = 1;
1817
+ if (this.mode !== "manual" ? (p = this.blinkValue(e), c.eyeROpen = m.eyeOpen * p, c.eyeLOpen = m.eyeOpenL * p, c.eyeSmile = m.eyeSmile, c.eyeSmileL = m.eyeSmileL, c.mouthOpen = m.mouthOpen, c.mouthForm = m.mouthForm, c.blush = m.blush, c.browY = m.browY + (c.angleY > 0 ? c.angleY / 60 : 0) - (1 - p) * 0.18, c.browAngle = m.browAngle, c.gazeX = pe(c.gazeX + m.gx, -1, 1), c.gazeY = pe(c.gazeY + m.gy, -1, 1)) : c.eyeSmileL = c.eyeSmile, a) {
1818
+ const v = (u, w) => {
1819
+ c[u] += (w - c[u]) * s;
1820
+ }, h = (u) => Math.min(1.3, Math.max(0, u));
1821
+ "eyeOpen" in a && (v("eyeROpen", h(a.eyeOpen) * p), "eyeOpenL" in a || v("eyeLOpen", h(a.eyeOpen) * p)), "eyeOpenL" in a && v("eyeLOpen", h(a.eyeOpenL) * p), "eyeSmile" in a && (v("eyeSmile", a.eyeSmile), "eyeSmileL" in a || v("eyeSmileL", a.eyeSmile)), "eyeSmileL" in a && v("eyeSmileL", a.eyeSmileL);
1822
+ for (const u of ["mouthOpen", "mouthForm", "blush", "browY", "browAngle"])
1823
+ u in a && v(u, u === "mouthOpen" || u === "blush" ? Math.max(0, a[u]) : a[u]);
1824
+ }
1825
+ const b = this.speechMouth(e);
1826
+ return b ? (this.lipOpen = b[0], this.lipForm = b[1]) : this.lipOpen !== null && !this.speaking && !this.kana && (this.lipOpen = null), this.lipOpen !== null && (c.mouthOpen = Math.max(c.mouthOpen * 0.3, this.lipOpen), c.mouthForm = pe(this.lipForm, -1, 1)), this.P = c, c;
1784
1827
  }
1785
1828
  }
1786
- const St = {
1829
+ const Rt = {
1787
1830
  neutral: "normal",
1788
1831
  smile: "smile",
1789
1832
  shy: "shy",
@@ -1792,9 +1835,9 @@ const St = {
1792
1835
  angry: "angryTalk",
1793
1836
  sad: "sadTalk",
1794
1837
  wink: "wink"
1795
- }, Jn = { sad: { pitch: -6, gy: -0.45 } }, Ye = (n, e, t) => Math.max(e, Math.min(t, n)), Ie = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, gx: 0, gy: 0, pitch: 0 });
1796
- function Kn(n) {
1797
- const e = tn[St[n]]?.p ?? {}, t = Jn[n] ?? {};
1838
+ }, er = { sad: { pitch: -6, gy: -0.45 } }, Ne = (n, e, t) => Math.max(e, Math.min(t, n)), Xe = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, gx: 0, gy: 0, pitch: 0 });
1839
+ function tr(n) {
1840
+ const e = nn[Rt[n]]?.p ?? {}, t = er[n] ?? {};
1798
1841
  return {
1799
1842
  eyeOpen: e.eyeOpen ?? 1,
1800
1843
  eyeOpenL: e.eyeOpenL ?? e.eyeOpen ?? 1,
@@ -1809,170 +1852,182 @@ function Kn(n) {
1809
1852
  pitch: t.pitch ?? 0
1810
1853
  };
1811
1854
  }
1812
- function Qn(n, e) {
1855
+ function nr(n, e) {
1813
1856
  const t = { ...n };
1814
- return t.eyeROpen = (n.eyeROpen ?? 1) * e.eyeOpen, t.eyeLOpen = (n.eyeLOpen ?? 1) * e.eyeOpenL, t.eyeSmile = Math.max(n.eyeSmile ?? 0, e.eyeSmile), t.eyeSmileL = Math.max(n.eyeSmileL ?? n.eyeSmile ?? 0, e.eyeSmileL), t.blush = Math.max(n.blush ?? 0, e.blush), t.browY = Ye((n.browY ?? 0) + e.browY, -1, 1), t.browAngle = Ye((n.browAngle ?? 0) + e.browAngle, -1, 1), t.mouthOpen = Math.max(n.mouthOpen ?? 0, e.mouthOpen), t.gazeX = Ye((n.gazeX ?? 0) + e.gx, -1, 1), t.gazeY = Ye((n.gazeY ?? 0) + e.gy, -1, 1), t.angleY = Ye((n.angleY ?? 0) + e.pitch, -30, 30), t;
1857
+ return t.eyeROpen = (n.eyeROpen ?? 1) * e.eyeOpen, t.eyeLOpen = (n.eyeLOpen ?? 1) * e.eyeOpenL, t.eyeSmile = Math.max(n.eyeSmile ?? 0, e.eyeSmile), t.eyeSmileL = Math.max(n.eyeSmileL ?? n.eyeSmile ?? 0, e.eyeSmileL), t.blush = Math.max(n.blush ?? 0, e.blush), t.browY = Ne((n.browY ?? 0) + e.browY, -1, 1), t.browAngle = Ne((n.browAngle ?? 0) + e.browAngle, -1, 1), t.mouthOpen = Math.max(n.mouthOpen ?? 0, e.mouthOpen), t.gazeX = Ne((n.gazeX ?? 0) + e.gx, -1, 1), t.gazeY = Ne((n.gazeY ?? 0) + e.gy, -1, 1), t.angleY = Ne((n.angleY ?? 0) + e.pitch, -30, 30), t;
1815
1858
  }
1816
- class er {
1859
+ class rr {
1817
1860
  /** @type {keyof typeof OVERLAY_EXPRESSIONS} */
1818
1861
  name = "neutral";
1819
- mix = { ...Ie };
1862
+ mix = { ...Xe };
1820
1863
  /** @param {string} name */
1821
1864
  set(e) {
1822
- this.name = Object.hasOwn(St, e) ? (
1865
+ this.name = Object.hasOwn(Rt, e) ? (
1823
1866
  /** @type {keyof typeof OVERLAY_EXPRESSIONS} */
1824
1867
  e
1825
1868
  ) : "neutral";
1826
1869
  }
1827
1870
  /** True while an expression is shown or still fading out. */
1828
1871
  get active() {
1829
- return this.name !== "neutral" || Object.keys(Ie).some((e) => Math.abs(this.mix[e] - Ie[e]) > 1e-3);
1872
+ return this.name !== "neutral" || Object.keys(Xe).some((e) => Math.abs(this.mix[e] - Xe[e]) > 1e-3);
1830
1873
  }
1831
1874
  apply(e, t) {
1832
1875
  if (!this.active)
1833
- return this.mix = { ...Ie }, e;
1834
- const r = Kn(this.name), a = 1 - Math.exp(-Math.max(0, t) * 12);
1835
- for (const o of Object.keys(Ie)) this.mix[o] += (r[o] - this.mix[o]) * a;
1836
- return Qn(e, this.mix);
1876
+ return this.mix = { ...Xe }, e;
1877
+ const r = tr(this.name), a = 1 - Math.exp(-Math.max(0, t) * 12);
1878
+ for (const s of Object.keys(Xe)) this.mix[s] += (r[s] - this.mix[s]) * a;
1879
+ return nr(e, this.mix);
1837
1880
  }
1838
1881
  }
1839
- const Dt = ["ball", "low", "crease", "lash"], rt = /* @__PURE__ */ new Map(), at = /* @__PURE__ */ new Map();
1840
- async function Ht(n) {
1841
- return at.has(n) || at.set(n, fetch(n).then((e) => {
1882
+ const Wt = ["ball", "low", "crease", "lash"], ot = /* @__PURE__ */ new Map(), st = /* @__PURE__ */ new Map();
1883
+ async function it(n) {
1884
+ return st.has(n) || st.set(n, fetch(n).then((e) => {
1842
1885
  if (!e.ok) throw new Error(`failed to load ${n}`);
1843
1886
  return e.json();
1844
- })), at.get(n);
1887
+ })), st.get(n);
1845
1888
  }
1846
- function Zt(n) {
1847
- if (rt.has(n)) return rt.get(n);
1889
+ function lt(n) {
1890
+ if (ot.has(n)) return ot.get(n);
1848
1891
  const e = new Promise((t, r) => {
1849
1892
  const a = new Image();
1850
1893
  a.onload = () => t(a), a.onerror = () => r(new Error(`failed to load ${n}`)), a.src = n;
1851
1894
  });
1852
- return rt.set(n, e), e;
1895
+ return ot.set(n, e), e;
1853
1896
  }
1854
- function nn(n, e) {
1897
+ function rn(n, e) {
1855
1898
  const t = document.createElement("canvas");
1856
1899
  t.width = n.width, t.height = n.height;
1857
1900
  const r = t.getContext("2d");
1858
1901
  r.drawImage(n, 0, 0);
1859
- const a = r.getImageData(0, 0, t.width, t.height).data, o = new Uint8Array(t.width * t.height);
1860
- for (let i = 0; i < o.length; i++) o[i] = a[i * 4 + e];
1861
- return o;
1902
+ const a = r.getImageData(0, 0, t.width, t.height).data, s = new Uint8Array(t.width * t.height);
1903
+ for (let l = 0; l < s.length; l++) s[l] = a[l * 4 + e];
1904
+ return s;
1905
+ }
1906
+ const Fe = (n) => rn(n, 3);
1907
+ function ar(n, [e, t, r, a]) {
1908
+ const s = document.createElement("canvas");
1909
+ return s.width = r, s.height = a, s.getContext("2d").drawImage(n, e, t, r, a, 0, 0, r, a), s;
1862
1910
  }
1863
- const Ne = (n) => nn(n, 3);
1864
- function tr(n, e) {
1865
- const [t, r] = n.t.pivot, a = n.dir, o = n.pts, i = (E, y, u) => {
1866
- const v = Math.min(1, Math.max(0, (u - E) / (y - E)));
1867
- return v * v * (3 - 2 * v);
1868
- }, f = Math.cos(n.phi[0]), m = Math.sin(n.phi[0]), g = Math.cos(n.phi[1]), p = Math.sin(n.phi[1]), l = e.rest, h = e.pos;
1869
- for (let E = 0; E < l.length; E += 2) {
1870
- const y = l[E] - t, u = l[E + 1] - r, v = y * a[0] + u * a[1], x = o[0][0] + y * f - u * m, s = o[0][1] + y * m + u * f, c = y - a[0] * n.L1, T = u - a[1] * n.L1, d = o[1][0] + c * g - T * p, w = o[1][1] + c * p + T * g, F = i(n.L1 * 0.55, n.L1 * 1.35, v);
1871
- h[E] = x + (d - x) * F, h[E + 1] = s + (w - s) * F;
1911
+ function or(n, e) {
1912
+ const [t, r] = n.t.pivot, a = n.dir, s = n.pts, l = (b, v, h) => {
1913
+ const u = Math.min(1, Math.max(0, (h - b) / (v - b)));
1914
+ return u * u * (3 - 2 * u);
1915
+ }, f = Math.cos(n.phi[0]), y = Math.sin(n.phi[0]), d = Math.cos(n.phi[1]), m = Math.sin(n.phi[1]), c = e.rest, p = e.pos;
1916
+ for (let b = 0; b < c.length; b += 2) {
1917
+ const v = c[b] - t, h = c[b + 1] - r, u = v * a[0] + h * a[1], w = s[0][0] + v * f - h * y, o = s[0][1] + v * y + h * f, i = v - a[0] * n.L1, S = h - a[1] * n.L1, g = s[1][0] + i * d - S * m, A = s[1][1] + i * m + S * d, L = l(n.L1 * 0.55, n.L1 * 1.35, u);
1918
+ p[b] = w + (g - w) * L, p[b + 1] = o + (A - o) * L;
1872
1919
  }
1873
1920
  }
1874
- async function nr(n, e) {
1921
+ async function sr(n, e) {
1875
1922
  if (!e.assets && e.assetsBase === void 0)
1876
1923
  throw new Error("createMeshAvatar requires assets or assetsBase.");
1877
- const t = e.rig, r = bn(t), {
1924
+ const t = e.rig, r = xn(t), {
1878
1925
  IMG: a,
1879
- EYES: o,
1880
- baseWeights: i,
1926
+ EYES: s,
1927
+ baseWeights: l,
1881
1928
  deformBase: f,
1882
- eyePartY: m,
1883
- eyePartAlpha: g,
1884
- handWeights: p,
1885
- handFrame: l,
1886
- deformHand: h,
1887
- TASSELS: E
1888
- } = r, { Renderer: y, buildGrid: u } = Bn(r, t), { Physics: v } = Un(r, t), { createSprites: x } = Yn(r, t), s = (e.assetsBase ?? "").replace(/\/?$/, "/"), c = (A, R) => {
1929
+ eyePartY: y,
1930
+ eyePartAlpha: d,
1931
+ handWeights: m,
1932
+ handFrame: c,
1933
+ deformHand: p,
1934
+ TASSELS: b
1935
+ } = r, { Renderer: v, buildGrid: h } = Un(r, t), { Physics: u } = Yn(r, t), { createSprites: w } = jn(r, t), o = (e.assetsBase ?? "").replace(/\/?$/, "/"), i = (E, R) => {
1889
1936
  if (e.assets) {
1890
- if (!e.assets[A]) throw new Error(`Missing project asset: ${A}`);
1891
- return e.assets[A];
1892
- }
1893
- return `${s}${A}${R === void 0 ? "" : `?b=${R}`}`;
1894
- }, T = await Ht(c("layers.json")), d = ["base", ...t.hand ? ["hand"] : [], ...E.map((A) => A.name), ...[0, 1].flatMap((A) => Dt.map((R) => `eye${A}_${R}`)), "hairmask"], w = Object.fromEntries(await Promise.all(d.map(async (A) => [A, await Zt(c(`${A}.png`, T.build))]))), F = nn(w.hairmask, 0), Y = (A, R) => F[Math.min(a.h - 1, Math.max(0, Math.round(R))) * a.w + Math.min(a.w - 1, Math.max(0, Math.round(A)))] / 255, I = new y(n, { padTop: e.padTop ?? t.view.padTop, padSide: e.padSide ?? t.view.padSide, fit: e.fit }), _ = { base: [0, 0, a.w, a.h], ...T.layers }, B = u(_.base, t.mesh.baseCell, Ne(w.base), w.base.width, t.mesh.fine), O = [];
1895
- for (let A = 0; A < B.rest.length / 2; A++) {
1896
- const R = B.rest[A * 2], C = B.rest[A * 2 + 1];
1897
- O.push(i(R, C, Y(R, C)));
1898
- }
1899
- I.addLayer("base", w.base, B, { face: !0 });
1900
- const z = [];
1901
- o.forEach((A, R) => {
1902
- for (const C of Dt) {
1903
- const Q = `eye${R}_${C}`, te = u(_[Q], C === "ball" ? t.mesh.eyeBallCell : t.mesh.eyeCell, Ne(w[Q]), w[Q].width), ne = [];
1904
- for (let se = 0; se < te.rest.length / 2; se++) ne.push(i(te.rest[se * 2], te.rest[se * 2 + 1], 0));
1905
- const ie = I.addLayer(Q, w[Q], te, { eyeBall: C === "ball" ? R : void 0 });
1906
- z.push({ e: A, eye: R, part: C, mesh: te, W: ne, layer: ie });
1937
+ if (!e.assets[E]) throw new Error(`Missing project asset: ${E}`);
1938
+ return e.assets[E];
1939
+ }
1940
+ return `${o}${E}${R === void 0 ? "" : `?b=${R}`}`;
1941
+ }, S = await it(i("layers.json")), g = ["base", ...t.hand ? ["hand"] : [], ...b.map((E) => E.name), ...[0, 1].flatMap((E) => Wt.map((R) => `eye${E}_${R}`)), "hairmask"], A = Object.fromEntries(await Promise.all(g.map(async (E) => [E, await lt(i(`${E}.png`, S.build))]))), L = rn(A.hairmask, 0), B = (E, R) => L[Math.min(a.h - 1, Math.max(0, Math.round(R))) * a.w + Math.min(a.w - 1, Math.max(0, Math.round(E)))] / 255, j = new v(n, { padTop: e.padTop ?? t.view.padTop, padSide: e.padSide ?? t.view.padSide, fit: e.fit }), k = { base: [0, 0, a.w, a.h], ...S.layers }, U = h(k.base, t.mesh.baseCell, Fe(A.base), A.base.width, t.mesh.fine), O = [];
1942
+ for (let E = 0; E < U.rest.length / 2; E++) {
1943
+ const R = U.rest[E * 2], J = U.rest[E * 2 + 1];
1944
+ O.push(l(R, J, B(R, J)));
1945
+ }
1946
+ j.addLayer("base", A.base, U, { face: !0 });
1947
+ const $ = [];
1948
+ s.forEach((E, R) => {
1949
+ for (const J of Wt) {
1950
+ const te = `eye${R}_${J}`, ee = h(k[te], J === "ball" ? t.mesh.eyeBallCell : t.mesh.eyeCell, Fe(A[te]), A[te].width), se = [];
1951
+ for (let ce = 0; ce < ee.rest.length / 2; ce++) se.push(l(ee.rest[ce * 2], ee.rest[ce * 2 + 1], 0));
1952
+ const le = j.addLayer(te, A[te], ee, { eyeBall: J === "ball" ? R : void 0 });
1953
+ $.push({ e: E, eye: R, part: J, mesh: ee, W: se, layer: le });
1907
1954
  }
1908
1955
  });
1909
1956
  let D = null;
1910
1957
  try {
1911
1958
  {
1912
- const A = await Ht(c("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(A.layers).map(async (C) => [C, await Zt(c(`sprites/${C}.png`, A.build))])));
1913
- D = x(I, A, R, u, Ne);
1914
- }
1915
- } catch (A) {
1916
- console.warn("eye / mouth sprites not loaded:", A);
1917
- }
1918
- const J = E.map((A) => {
1919
- const R = u(_[A.name], t.mesh.tasselCell, Ne(w[A.name]), w[A.name].width);
1920
- return I.addLayer(A.name, w[A.name], R);
1921
- }), j = t.hand ? u(_.hand, t.mesh.handCell, Ne(w.hand), w.hand.width) : { rest: [], pos: [] }, H = [];
1922
- for (let A = 0; A < j.rest.length / 2; A++) H.push(p(j.rest[A * 2], j.rest[A * 2 + 1]));
1923
- t.hand && I.addLayer("hand", w.hand, j);
1924
- const Z = new v(), $ = new qn(t.view.gazeCenter ?? [t.head.cx, t.head.cy]);
1925
- e.lipSync !== void 0 && $.setLipSync(e.lipSync);
1926
- const q = /* @__PURE__ */ new Set();
1927
- $.onMotion = (A) => {
1928
- for (const R of q) R(A);
1959
+ const E = await it(i("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(E.layers).map(async (J) => [J, await lt(i(`sprites/${J}.png`, E.build))])));
1960
+ D = w(j, E, R, h, Fe);
1961
+ }
1962
+ } catch (E) {
1963
+ console.warn("eye / mouth sprites not loaded:", E);
1964
+ }
1965
+ let q = null;
1966
+ try {
1967
+ const E = await it(i("overlays/overlays.json")), R = Object.fromEntries(await Promise.all(E.overlays.map(async (J) => [J.name, await lt(i(`overlays/${J.file}`))])));
1968
+ q = Xn(j, E, R, h, Fe, l, t.mesh.spriteCell, a.w, a.h, ar);
1969
+ } catch (E) {
1970
+ e.assets?.["overlays/overlays.json"] && console.warn("overlay layers not loaded:", E);
1971
+ }
1972
+ const N = b.map((E) => {
1973
+ const R = h(k[E.name], t.mesh.tasselCell, Fe(A[E.name]), A[E.name].width);
1974
+ return j.addLayer(E.name, A[E.name], R);
1975
+ }), P = t.hand ? h(k.hand, t.mesh.handCell, Fe(A.hand), A.hand.width) : { rest: [], pos: [] }, H = [];
1976
+ for (let E = 0; E < P.rest.length / 2; E++) H.push(m(P.rest[E * 2], P.rest[E * 2 + 1]));
1977
+ t.hand && j.addLayer("hand", A.hand, P);
1978
+ const G = new u(), z = new Qn(t.view.gazeCenter ?? [t.head.cx, t.head.cy]);
1979
+ e.lipSync !== void 0 && z.setLipSync(e.lipSync);
1980
+ const W = /* @__PURE__ */ new Set();
1981
+ z.onMotion = (E) => {
1982
+ for (const R of W) R(E);
1929
1983
  };
1930
- let W = {}, N = 1, G = {};
1931
- const V = new er(), b = [0, 0];
1932
- function M(A) {
1933
- const R = { ...$.update(A) };
1934
- for (const [Q, te] of Object.entries(W)) R[Q] = N === 1 ? te : (R[Q] ?? 0) + (te - (R[Q] ?? 0)) * N;
1935
- $.lipOpen !== null && (R.mouthOpen = $.P.mouthOpen, (!e.preserveMouthForm || W.mouthForm === void 0) && (R.mouthForm = $.P.mouthForm));
1936
- const C = V.apply(R, A);
1937
- return G = C, C;
1938
- }
1939
- function S(A) {
1940
- const R = M(A), C = Z.step(R, A), Q = B.pos, te = B.rest;
1941
- for (let K = 0; K < O.length; K++)
1942
- f(te[K * 2], te[K * 2 + 1], O[K], R, C, b), Q[K * 2] = b[0], Q[K * 2 + 1] = b[1];
1943
- const ne = (K, ke) => D?.eyesDrawn[ke] ? 1 : K;
1944
- for (const K of z) {
1945
- const ke = ne(K.eye === 0 ? R.eyeROpen : R.eyeLOpen, K.eye), Lt = K.eye === 0 ? R.eyeSmile : R.eyeSmileL ?? R.eyeSmile;
1946
- K.layer.alpha = g(K.part, ke, Lt);
1947
- const _t = K.mesh.rest, kt = K.mesh.pos;
1948
- for (let Re = 0; Re < K.W.length; Re++) {
1949
- const Ft = _t[Re * 2], yn = _t[Re * 2 + 1];
1950
- f(Ft, m(K.e, K.part, Ft, yn, ke, Lt), K.W[Re], R, C, b), kt[Re * 2] = b[0], kt[Re * 2 + 1] = b[1];
1984
+ let I = {}, V = 1, K = {};
1985
+ const x = new rr(), M = [0, 0];
1986
+ function T(E) {
1987
+ const R = { ...z.update(E) };
1988
+ for (const [te, ee] of Object.entries(I)) R[te] = V === 1 ? ee : (R[te] ?? 0) + (ee - (R[te] ?? 0)) * V;
1989
+ z.lipOpen !== null && (R.mouthOpen = z.P.mouthOpen, (!e.preserveMouthForm || I.mouthForm === void 0) && (R.mouthForm = z.P.mouthForm));
1990
+ const J = x.apply(R, E);
1991
+ return K = J, J;
1992
+ }
1993
+ function _(E) {
1994
+ const R = T(E), J = G.step(R, E), te = U.pos, ee = U.rest;
1995
+ for (let Q = 0; Q < O.length; Q++)
1996
+ f(ee[Q * 2], ee[Q * 2 + 1], O[Q], R, J, M), te[Q * 2] = M[0], te[Q * 2 + 1] = M[1];
1997
+ const se = (Q, ke) => D?.eyesDrawn[ke] ? 1 : Q;
1998
+ for (const Q of $) {
1999
+ const ke = se(Q.eye === 0 ? R.eyeROpen : R.eyeLOpen, Q.eye), Ft = Q.eye === 0 ? R.eyeSmile : R.eyeSmileL ?? R.eyeSmile;
2000
+ Q.layer.alpha = d(Q.part, ke, Ft);
2001
+ const Bt = Q.mesh.rest, Ut = Q.mesh.pos;
2002
+ for (let Oe = 0; Oe < Q.W.length; Oe++) {
2003
+ const Yt = Bt[Oe * 2], vn = Bt[Oe * 2 + 1];
2004
+ f(Yt, y(Q.e, Q.part, Yt, vn, ke, Ft), Q.W[Oe], R, J, M), Ut[Oe * 2] = M[0], Ut[Oe * 2 + 1] = M[1];
1951
2005
  }
1952
2006
  }
1953
- const ie = D?.update(R, C, A, In(V.name, $.mode === "manual" ? null : $.expr));
1954
- if (ie) for (const K of z) ie.eyes[K.eye] && (K.layer.alpha = 0);
1955
- const se = j.pos, me = j.rest, He = l(R);
1956
- for (let K = 0; K < H.length; K++)
1957
- h(me[K * 2], me[K * 2 + 1], H[K], R, He, b), se[K * 2] = b[0], se[K * 2 + 1] = b[1];
1958
- Z.chains.forEach((K, ke) => tr(K, J[ke].mesh));
1959
- const we = 7;
1960
- I.draw({
2007
+ const le = D?.update(R, J, E, In(x.name, z.mode === "manual" ? null : z.expr));
2008
+ if (le) for (const Q of $) le.eyes[Q.eye] && (Q.layer.alpha = 0);
2009
+ q?.update(R, J, f, M);
2010
+ const ce = P.pos, je = P.rest, _e = c(R);
2011
+ for (let Q = 0; Q < H.length; Q++)
2012
+ p(je[Q * 2], je[Q * 2 + 1], H[Q], R, _e, M), ce[Q * 2] = M[0], ce[Q * 2 + 1] = M[1];
2013
+ G.chains.forEach((Q, ke) => or(Q, N[ke].mesh));
2014
+ const Ze = 7;
2015
+ j.draw({
1961
2016
  angleX: R.angleX,
1962
2017
  angleY: R.angleY,
1963
2018
  angleZ: R.angleZ,
1964
2019
  eyes: [
1965
- ne(R.eyeROpen, 0),
2020
+ se(R.eyeROpen, 0),
1966
2021
  R.eyeSmile,
1967
- R.gazeX * we,
1968
- -R.gazeY * we * 0.6,
1969
- ne(R.eyeLOpen, 1),
2022
+ R.gazeX * Ze,
2023
+ -R.gazeY * Ze * 0.6,
2024
+ se(R.eyeLOpen, 1),
1970
2025
  R.eyeSmileL ?? R.eyeSmile,
1971
- R.gazeX * we * 0.85,
1972
- -R.gazeY * we * 0.6
2026
+ R.gazeX * Ze * 0.85,
2027
+ -R.gazeY * Ze * 0.6
1973
2028
  ],
1974
2029
  // with sprites the drawn mouths replace the shader-painted one
1975
- mouthOpen: ie?.mouthDrawn ? 0 : R.mouthOpen,
2030
+ mouthOpen: le?.mouthDrawn ? 0 : R.mouthOpen,
1976
2031
  mouthForm: R.mouthForm,
1977
2032
  cheek: R.blush,
1978
2033
  showMesh: !1,
@@ -1980,106 +2035,110 @@ async function nr(n, e) {
1980
2035
  joints: []
1981
2036
  });
1982
2037
  }
1983
- let L = 0, U = performance.now(), X = !1;
1984
- const k = (A) => {
1985
- const R = Math.min(0.05, (A - U) / 1e3);
1986
- U = A, S(R), L = requestAnimationFrame(k);
2038
+ let Y = 0, X = performance.now(), F = !1;
2039
+ const C = (E) => {
2040
+ const R = Math.min(0.05, (E - X) / 1e3);
2041
+ X = E, _(R), Y = requestAnimationFrame(C);
1987
2042
  };
1988
- return e.manual || (L = requestAnimationFrame(k)), {
2043
+ return e.manual || (Y = requestAnimationFrame(C)), {
1989
2044
  motions: [
1990
- ...Object.entries(Mt).map(([A, R]) => ({ id: A, label: R.label, idle: !1 })),
1991
- ...Object.entries(Et).map(([A, R]) => ({ id: A, label: R.label, idle: !0 }))
2045
+ ...Object.entries(Tt).map(([E, R]) => ({ id: E, label: R.label, idle: !1 })),
2046
+ ...Object.entries(Ot).map(([E, R]) => ({ id: E, label: R.label, idle: !0 }))
1992
2047
  ],
1993
- setParameters(A, R = 1) {
1994
- W = { ...A }, N = Math.min(1, Math.max(0, Number(R) || 0));
2048
+ setParameters(E, R = 1) {
2049
+ I = { ...E }, V = Math.min(1, Math.max(0, Number(R) || 0));
1995
2050
  },
1996
2051
  getParameters() {
1997
- return { ...G };
2052
+ return { ...K };
1998
2053
  },
1999
2054
  /** 0..1 loudness of the voice being played (e.g. normalised RMS). */
2000
- setVoiceLevel(A) {
2001
- $.setVoiceLevel(A);
2055
+ setVoiceLevel(E) {
2056
+ z.setVoiceLevel(E);
2002
2057
  },
2003
2058
  /** Partial mouth-movement settings; omitted fields retain their current values. */
2004
- setLipSync(A) {
2005
- $.setLipSync(A);
2059
+ setLipSync(E) {
2060
+ z.setLipSync(E);
2006
2061
  },
2007
2062
  /** true while TTS audio is playing: idle motions pause and the head nods along. */
2008
- setSpeaking(A) {
2009
- $.setSpeaking(A);
2063
+ setSpeaking(E) {
2064
+ z.setSpeaking(E);
2010
2065
  },
2011
2066
  /** AITuber OnAir emotion tag: happy / sad / angry / surprised / relaxed / neutral (or null). */
2012
- setEmotion(A, R) {
2013
- $.setEmotion(A, R);
2067
+ setEmotion(E, R) {
2068
+ z.setEmotion(E, R);
2014
2069
  },
2015
2070
  /** Live expression layered over tracking (see OVERLAY_EXPRESSIONS); 'neutral' clears it. */
2016
- setExpression(A) {
2017
- V.set(A);
2071
+ setExpression(E) {
2072
+ x.set(E);
2073
+ },
2074
+ /** Show the named overlay layers (built/overlays/overlays.json) and hide the others. */
2075
+ setOverlays(E) {
2076
+ q?.set(E);
2018
2077
  },
2019
2078
  getExpression() {
2020
- return { name: V.name, active: V.active };
2079
+ return { name: x.name, active: x.active };
2021
2080
  },
2022
2081
  /** How much the head moves with the voice while speaking (1 = default, calmer below). */
2023
- setTalkGain(A) {
2024
- $.talkGain = Math.max(0, Number(A) || 0);
2082
+ setTalkGain(E) {
2083
+ z.talkGain = Math.max(0, Number(E) || 0);
2025
2084
  },
2026
2085
  /** Play a motion or idle motion by id (see `motions`). */
2027
- play(A) {
2028
- $.hasMotion(A) && $.playMotion(A);
2086
+ play(E) {
2087
+ z.hasMotion(E) && z.playMotion(E);
2029
2088
  },
2030
2089
  /** Move the mouth through the vowels of kana text (no audio; for previews). */
2031
- speakKana(A, R) {
2032
- $.speakKana(String(A ?? ""), R);
2090
+ speakKana(E, R) {
2091
+ z.speakKana(String(E ?? ""), R);
2033
2092
  },
2034
- holdMouth(A) {
2035
- $.holdMouth(A);
2093
+ holdMouth(E) {
2094
+ z.holdMouth(E);
2036
2095
  },
2037
2096
  stopLipSync() {
2038
- $.stopLipSync();
2097
+ z.stopLipSync();
2039
2098
  },
2040
2099
  getLipSyncState() {
2041
- return $.getLipSyncState();
2100
+ return z.getLipSyncState();
2042
2101
  },
2043
- setAutoIdle(A) {
2044
- $.autoIdle = !!A;
2102
+ setAutoIdle(E) {
2103
+ z.autoIdle = !!E;
2045
2104
  },
2046
- setLighting(A) {
2047
- I.setLighting(A);
2105
+ setLighting(E) {
2106
+ j.setLighting(E);
2048
2107
  },
2049
2108
  getLightingStats() {
2050
- return { ...I.lightingStats };
2109
+ return { ...j.lightingStats };
2051
2110
  },
2052
- setAutoMotion(A) {
2053
- $.autoMotion = !!A;
2111
+ setAutoMotion(E) {
2112
+ z.autoMotion = !!E;
2054
2113
  },
2055
2114
  /** Hair / tassel sway multiplier (1 = default). */
2056
- setSwayGain(A) {
2057
- Z.gain = A;
2115
+ setSwayGain(E) {
2116
+ G.gain = E;
2058
2117
  },
2059
2118
  /** Called with the motion id when a motion starts and with null when it ends. */
2060
- onMotion(A) {
2061
- return q.add(A), () => q.delete(A);
2119
+ onMotion(E) {
2120
+ return W.add(E), () => W.delete(E);
2062
2121
  },
2063
2122
  /** Advance the simulation by `sec` and draw (for tests / hidden tabs). */
2064
- advance(A, R = 60) {
2065
- if (!X)
2066
- if (A === 0) S(0);
2067
- else for (let C = 0; C < Math.round(A * R); C++) S(1 / R);
2123
+ advance(E, R = 60) {
2124
+ if (!F)
2125
+ if (E === 0) _(0);
2126
+ else for (let J = 0; J < Math.round(E * R); J++) _(1 / R);
2068
2127
  },
2069
2128
  /** Update motion and lip sync without drawing a hidden preview. */
2070
- advanceParameters(A) {
2071
- X || M(A);
2129
+ advanceParameters(E) {
2130
+ F || T(E);
2072
2131
  },
2073
2132
  destroy() {
2074
- X || (X = !0, cancelAnimationFrame(L), q.clear(), I.destroy());
2133
+ F || (F = !0, cancelAnimationFrame(Y), W.clear(), j.destroy());
2075
2134
  }
2076
2135
  };
2077
2136
  }
2078
- const kr = Object.keys(St);
2079
- async function rr(n, e) {
2080
- return nr(n, { ...e, rig: wt(e.rig) });
2137
+ const Yr = Object.keys(Rt);
2138
+ async function ir(n, e) {
2139
+ return sr(n, { ...e, rig: Et(e.rig) });
2081
2140
  }
2082
- function Be(n) {
2141
+ function Ye(n) {
2083
2142
  if (!n || typeof n != "object" || Array.isArray(n))
2084
2143
  throw new Error("avatar.json: expected an object");
2085
2144
  const e = n, t = [];
@@ -2093,7 +2152,7 @@ function Be(n) {
2093
2152
  }
2094
2153
  if (e.lipSync !== void 0)
2095
2154
  try {
2096
- r.lipSync = At(e.lipSync);
2155
+ r.lipSync = St(e.lipSync);
2097
2156
  } catch (a) {
2098
2157
  t.push(`avatar.json.lipSync: ${a instanceof Error ? a.message : String(a)}`);
2099
2158
  }
@@ -2101,111 +2160,126 @@ function Be(n) {
2101
2160
  `));
2102
2161
  return r;
2103
2162
  }
2104
- function rn(n) {
2105
- return Be({ format: "mesh-avatar", version: 1, name: n });
2106
- }
2107
- const ot = (n) => !!n && typeof n == "object" && !Array.isArray(n), Le = (n, e) => Array.isArray(n) && n.length === e && n.every((t) => typeof t == "number" && Number.isFinite(t)), st = (n, e) => Object.hasOwn(n, e);
2108
2163
  function an(n) {
2164
+ return Ye({ format: "mesh-avatar", version: 1, name: n });
2165
+ }
2166
+ const Je = (n) => !!n && typeof n == "object" && !Array.isArray(n), Re = (n, e) => Array.isArray(n) && n.length === e && n.every((t) => typeof t == "number" && Number.isFinite(t)), ct = (n, e) => Object.hasOwn(n, e);
2167
+ function on(n) {
2109
2168
  const e = [];
2110
- function t(h, E = !0) {
2111
- if (!st(n, h)) {
2112
- E && e.push(`${h}: missing file`);
2169
+ function t(b, v = !0) {
2170
+ if (!ct(n, b)) {
2171
+ v && e.push(`${b}: missing file`);
2113
2172
  return;
2114
2173
  }
2115
- const y = n[h];
2116
- if (!(y instanceof Uint8Array)) {
2117
- e.push(`${h}: JSON bytes are required`);
2174
+ const h = n[b];
2175
+ if (!(h instanceof Uint8Array)) {
2176
+ e.push(`${b}: JSON bytes are required`);
2118
2177
  return;
2119
2178
  }
2120
2179
  let u;
2121
2180
  try {
2122
- u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(y));
2181
+ u = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(h));
2123
2182
  } catch {
2124
- e.push(`${h}: invalid UTF-8 JSON`);
2183
+ e.push(`${b}: invalid UTF-8 JSON`);
2125
2184
  return;
2126
2185
  }
2127
- if (!ot(u)) {
2128
- e.push(`${h}: expected an object`);
2186
+ if (!Je(u)) {
2187
+ e.push(`${b}: expected an object`);
2129
2188
  return;
2130
2189
  }
2131
2190
  return u;
2132
2191
  }
2133
- function r(h, E, y = !0) {
2134
- return h.version === 1 || y && h.version === void 0 ? !0 : (e.push(`${E}.version: unsupported version ${JSON.stringify(h.version) ?? "missing"} (expected 1)`), !1);
2192
+ function r(b, v, h = !0) {
2193
+ return b.version === 1 || h && b.version === void 0 ? !0 : (e.push(`${v}.version: unsupported version ${JSON.stringify(b.version) ?? "missing"} (expected 1)`), !1);
2135
2194
  }
2136
- function a(h) {
2137
- if (!st(n, h)) {
2138
- e.push(`${h}: missing file`);
2195
+ function a(b) {
2196
+ if (!ct(n, b)) {
2197
+ e.push(`${b}: missing file`);
2139
2198
  return;
2140
2199
  }
2141
- const E = n[h], y = E instanceof Uint8Array ? E.byteLength : E?.size;
2142
- (!Number.isSafeInteger(y) || y <= 0) && e.push(`${h}: expected a non-empty file`);
2200
+ const v = n[b], h = v instanceof Uint8Array ? v.byteLength : v?.size;
2201
+ (!Number.isSafeInteger(h) || h <= 0) && e.push(`${b}: expected a non-empty file`);
2143
2202
  }
2144
- function o(h, E, y, u) {
2145
- if (!ot(h)) {
2146
- e.push(`${E}.layers: expected a layer rectangle map`);
2203
+ function s(b, v, h, u) {
2204
+ if (!Je(b)) {
2205
+ e.push(`${v}.layers: expected a layer rectangle map`);
2147
2206
  return;
2148
2207
  }
2149
- for (const [v, x] of Object.entries(h)) {
2150
- const s = `${E}.layers.${v}`;
2151
- if (!/^[A-Za-z0-9_-]+$/.test(v)) {
2152
- e.push(`${s}: expected a safe layer name (letters, digits, hyphens or underscores)`);
2208
+ for (const [w, o] of Object.entries(b)) {
2209
+ const i = `${v}.layers.${w}`;
2210
+ if (!/^[A-Za-z0-9_-]+$/.test(w)) {
2211
+ e.push(`${i}: expected a safe layer name (letters, digits, hyphens or underscores)`);
2153
2212
  continue;
2154
2213
  }
2155
- !Le(x, 4) || !x.every(Number.isInteger) || x[0] < 0 || x[1] < 0 || x[2] <= 0 || x[3] <= 0 ? e.push(`${s}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : u && (x[0] + x[2] > u[0] || x[1] + x[3] > u[1]) && e.push(`${s}: rectangle must stay inside the image`), a(`${y}/${v}.png`);
2214
+ !Re(o, 4) || !o.every(Number.isInteger) || o[0] < 0 || o[1] < 0 || o[2] <= 0 || o[3] <= 0 ? e.push(`${i}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : u && (o[0] + o[2] > u[0] || o[1] + o[3] > u[1]) && e.push(`${i}: rectangle must stay inside the image`), a(`${h}/${w}.png`);
2156
2215
  }
2157
- return h;
2216
+ return b;
2158
2217
  }
2159
- function i(h, E) {
2160
- (typeof h.build != "string" || !h.build.trim()) && e.push(`${E}.build: expected a non-empty string`);
2218
+ function l(b, v) {
2219
+ (typeof b.build != "string" || !b.build.trim()) && e.push(`${v}.build: expected a non-empty string`);
2161
2220
  }
2162
2221
  const f = t("avatar.json", !1);
2163
2222
  if (f)
2164
2223
  try {
2165
- Be(f);
2166
- } catch (h) {
2167
- e.push(h.message);
2224
+ Ye(f);
2225
+ } catch (b) {
2226
+ e.push(b.message);
2168
2227
  }
2169
- const m = t("rig.json");
2170
- let g;
2171
- if (m && r(m, "rig.json", !1)) {
2172
- const h = Qt(m);
2173
- e.push(...h.map((E) => `rig.json: ${E}`)), h.length || (g = m);
2228
+ const y = t("rig.json");
2229
+ let d;
2230
+ if (y && r(y, "rig.json", !1)) {
2231
+ const b = en(y);
2232
+ e.push(...b.map((v) => `rig.json: ${v}`)), b.length || (d = y);
2174
2233
  }
2175
2234
  a("built/base.png"), a("built/hairmask.png");
2176
- const p = t("built/layers.json");
2177
- if (p && r(p, "built/layers.json")) {
2178
- i(p, "built/layers.json");
2179
- let h;
2180
- !Le(p.size, 2) || !p.size.every((y) => Number.isInteger(y) && y > 0) ? e.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (h = p.size, g && (h[0] !== g.image.width || h[1] !== g.image.height) && e.push("built/layers.json.size: must match rig.json.image"));
2181
- const E = o(p.layers, "built/layers.json", "built", h);
2182
- if (g && E) {
2183
- const y = [
2184
- ...g.eyes.flatMap((u, v) => ["ball", "low", "crease", "lash"].map((x) => `eye${v}_${x}`)),
2185
- ...g.hand ? ["hand"] : [],
2186
- ...(g.accessories ?? []).map((u) => u.name)
2235
+ const m = t("built/layers.json");
2236
+ if (m && r(m, "built/layers.json")) {
2237
+ l(m, "built/layers.json");
2238
+ let b;
2239
+ !Re(m.size, 2) || !m.size.every((h) => Number.isInteger(h) && h > 0) ? e.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (b = m.size, d && (b[0] !== d.image.width || b[1] !== d.image.height) && e.push("built/layers.json.size: must match rig.json.image"));
2240
+ const v = s(m.layers, "built/layers.json", "built", b);
2241
+ if (d && v) {
2242
+ const h = [
2243
+ ...d.eyes.flatMap((u, w) => ["ball", "low", "crease", "lash"].map((o) => `eye${w}_${o}`)),
2244
+ ...d.hand ? ["hand"] : [],
2245
+ ...(d.accessories ?? []).map((u) => u.name)
2187
2246
  ];
2188
- for (const u of y) st(E, u) || e.push(`built/layers.json.layers.${u}: missing required layer`);
2247
+ for (const u of h) ct(v, u) || e.push(`built/layers.json.layers.${u}: missing required layer`);
2189
2248
  }
2190
- !Array.isArray(p.eyes) || p.eyes.length !== 2 ? e.push("built/layers.json.eyes: expected two eye curves") : p.eyes.forEach((y, u) => {
2191
- const v = `built/layers.json.eyes[${u}]`;
2192
- if (!ot(y)) {
2193
- e.push(`${v}: expected an object`);
2249
+ !Array.isArray(m.eyes) || m.eyes.length !== 2 ? e.push("built/layers.json.eyes: expected two eye curves") : m.eyes.forEach((h, u) => {
2250
+ const w = `built/layers.json.eyes[${u}]`;
2251
+ if (!Je(h)) {
2252
+ e.push(`${w}: expected an object`);
2194
2253
  return;
2195
2254
  }
2196
- Le([y.x0, y.x1], 2) && y.x0 < y.x1 || e.push(`${v}: expected finite x0 < x1`);
2197
- for (const s of ["top", "bot"])
2198
- Le(y[s], 24) || e.push(`${v}.${s}: expected 24 finite numbers`);
2199
- if (Le(y.top, 24) && Le(y.bot, 24) && y.top.some((s, c) => s > y.bot[c]) && e.push(`${v}.top: must not exceed bottom curve`), g) for (const s of ["x0", "x1", "top", "bot"]) {
2200
- const c = y[s], T = g.eyes[u][s];
2201
- (Array.isArray(T) ? Le(c, T.length) && c.every((w, F) => w === T[F]) : c === T) || e.push(`${v}.${s}: must match rig.json.eyes[${u}].${s}`);
2255
+ Re([h.x0, h.x1], 2) && h.x0 < h.x1 || e.push(`${w}: expected finite x0 < x1`);
2256
+ for (const i of ["top", "bot"])
2257
+ Re(h[i], 24) || e.push(`${w}.${i}: expected 24 finite numbers`);
2258
+ if (Re(h.top, 24) && Re(h.bot, 24) && h.top.some((i, S) => i > h.bot[S]) && e.push(`${w}.top: must not exceed bottom curve`), d) for (const i of ["x0", "x1", "top", "bot"]) {
2259
+ const S = h[i], g = d.eyes[u][i];
2260
+ (Array.isArray(g) ? Re(S, g.length) && S.every((L, B) => L === g[B]) : S === g) || e.push(`${w}.${i}: must match rig.json.eyes[${u}].${i}`);
2202
2261
  }
2203
2262
  });
2204
2263
  }
2205
- const l = t("built/sprites/sprites.json", !1);
2206
- return l && r(l, "built/sprites/sprites.json") && (i(l, "built/sprites/sprites.json"), o(l.layers, "built/sprites/sprites.json", "built/sprites", g ? [g.image.width, g.image.height] : void 0)), e;
2264
+ const c = t("built/sprites/sprites.json", !1);
2265
+ c && r(c, "built/sprites/sprites.json") && (l(c, "built/sprites/sprites.json"), s(c.layers, "built/sprites/sprites.json", "built/sprites", d ? [d.image.width, d.image.height] : void 0));
2266
+ const p = t("built/overlays/overlays.json", !1);
2267
+ if (p && r(p, "built/overlays/overlays.json"))
2268
+ if (!Array.isArray(p.overlays)) e.push("built/overlays/overlays.json.overlays: expected an array");
2269
+ else {
2270
+ const b = /* @__PURE__ */ new Set();
2271
+ for (const [v, h] of p.overlays.entries()) {
2272
+ const u = `built/overlays/overlays.json.overlays[${v}]`;
2273
+ if (!Je(h) || typeof h.name != "string" || !/^[A-Za-z0-9_-]+$/.test(h.name) || typeof h.file != "string" || !/^[A-Za-z0-9_-]+\.png$/.test(h.file)) {
2274
+ e.push(`${u}: expected { name, file } with safe names`);
2275
+ continue;
2276
+ }
2277
+ b.has(h.name) && e.push(`${u}.name: duplicate overlay name`), b.add(h.name), a(`built/overlays/${h.file}`);
2278
+ }
2279
+ }
2280
+ return e;
2207
2281
  }
2208
- var ae = Uint8Array, ue = Uint16Array, Tt = Int32Array, Ke = new ae([
2282
+ var ae = Uint8Array, fe = Uint16Array, Lt = Int32Array, et = new ae([
2209
2283
  0,
2210
2284
  0,
2211
2285
  0,
@@ -2240,7 +2314,7 @@ var ae = Uint8Array, ue = Uint16Array, Tt = Int32Array, Ke = new ae([
2240
2314
  0,
2241
2315
  /* impossible */
2242
2316
  0
2243
- ]), Qe = new ae([
2317
+ ]), tt = new ae([
2244
2318
  0,
2245
2319
  0,
2246
2320
  0,
@@ -2274,65 +2348,65 @@ var ae = Uint8Array, ue = Uint16Array, Tt = Int32Array, Ke = new ae([
2274
2348
  /* unused */
2275
2349
  0,
2276
2350
  0
2277
- ]), ft = new ae([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), on = function(n, e) {
2278
- for (var t = new ue(31), r = 0; r < 31; ++r)
2351
+ ]), dt = new ae([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), sn = function(n, e) {
2352
+ for (var t = new fe(31), r = 0; r < 31; ++r)
2279
2353
  t[r] = e += 1 << n[r - 1];
2280
- for (var a = new Tt(t[30]), r = 1; r < 30; ++r)
2281
- for (var o = t[r]; o < t[r + 1]; ++o)
2282
- a[o] = o - t[r] << 5 | r;
2354
+ for (var a = new Lt(t[30]), r = 1; r < 30; ++r)
2355
+ for (var s = t[r]; s < t[r + 1]; ++s)
2356
+ a[s] = s - t[r] << 5 | r;
2283
2357
  return { b: t, r: a };
2284
- }, sn = on(Ke, 2), ln = sn.b, mt = sn.r;
2285
- ln[28] = 258, mt[258] = 28;
2286
- var cn = on(Qe, 0), ar = cn.b, Wt = cn.r, pt = new ue(32768);
2358
+ }, ln = sn(et, 2), cn = ln.b, gt = ln.r;
2359
+ cn[28] = 258, gt[258] = 28;
2360
+ var hn = sn(tt, 0), lr = hn.b, Gt = hn.r, yt = new fe(32768);
2287
2361
  for (var re = 0; re < 32768; ++re) {
2288
- var Te = (re & 43690) >> 1 | (re & 21845) << 1;
2289
- Te = (Te & 52428) >> 2 | (Te & 13107) << 2, Te = (Te & 61680) >> 4 | (Te & 3855) << 4, pt[re] = ((Te & 65280) >> 8 | (Te & 255) << 8) >> 1;
2362
+ var Se = (re & 43690) >> 1 | (re & 21845) << 1;
2363
+ Se = (Se & 52428) >> 2 | (Se & 13107) << 2, Se = (Se & 61680) >> 4 | (Se & 3855) << 4, yt[re] = ((Se & 65280) >> 8 | (Se & 255) << 8) >> 1;
2290
2364
  }
2291
2365
  var xe = (function(n, e, t) {
2292
- for (var r = n.length, a = 0, o = new ue(e); a < r; ++a)
2293
- n[a] && ++o[n[a] - 1];
2294
- var i = new ue(e);
2366
+ for (var r = n.length, a = 0, s = new fe(e); a < r; ++a)
2367
+ n[a] && ++s[n[a] - 1];
2368
+ var l = new fe(e);
2295
2369
  for (a = 1; a < e; ++a)
2296
- i[a] = i[a - 1] + o[a - 1] << 1;
2370
+ l[a] = l[a - 1] + s[a - 1] << 1;
2297
2371
  var f;
2298
2372
  if (t) {
2299
- f = new ue(1 << e);
2300
- var m = 15 - e;
2373
+ f = new fe(1 << e);
2374
+ var y = 15 - e;
2301
2375
  for (a = 0; a < r; ++a)
2302
2376
  if (n[a])
2303
- for (var g = a << 4 | n[a], p = e - n[a], l = i[n[a] - 1]++ << p, h = l | (1 << p) - 1; l <= h; ++l)
2304
- f[pt[l] >> m] = g;
2377
+ for (var d = a << 4 | n[a], m = e - n[a], c = l[n[a] - 1]++ << m, p = c | (1 << m) - 1; c <= p; ++c)
2378
+ f[yt[c] >> y] = d;
2305
2379
  } else
2306
- for (f = new ue(r), a = 0; a < r; ++a)
2307
- n[a] && (f[a] = pt[i[n[a] - 1]++] >> 15 - n[a]);
2380
+ for (f = new fe(r), a = 0; a < r; ++a)
2381
+ n[a] && (f[a] = yt[l[n[a] - 1]++] >> 15 - n[a]);
2308
2382
  return f;
2309
- }), Oe = new ae(288);
2383
+ }), Te = new ae(288);
2310
2384
  for (var re = 0; re < 144; ++re)
2311
- Oe[re] = 8;
2385
+ Te[re] = 8;
2312
2386
  for (var re = 144; re < 256; ++re)
2313
- Oe[re] = 9;
2387
+ Te[re] = 9;
2314
2388
  for (var re = 256; re < 280; ++re)
2315
- Oe[re] = 7;
2389
+ Te[re] = 7;
2316
2390
  for (var re = 280; re < 288; ++re)
2317
- Oe[re] = 8;
2318
- var Pe = new ae(32);
2391
+ Te[re] = 8;
2392
+ var De = new ae(32);
2319
2393
  for (var re = 0; re < 32; ++re)
2320
- Pe[re] = 5;
2321
- var or = /* @__PURE__ */ xe(Oe, 9, 0), sr = /* @__PURE__ */ xe(Oe, 9, 1), ir = /* @__PURE__ */ xe(Pe, 5, 0), lr = /* @__PURE__ */ xe(Pe, 5, 1), it = function(n) {
2394
+ De[re] = 5;
2395
+ var cr = /* @__PURE__ */ xe(Te, 9, 0), hr = /* @__PURE__ */ xe(Te, 9, 1), ur = /* @__PURE__ */ xe(De, 5, 0), fr = /* @__PURE__ */ xe(De, 5, 1), ht = function(n) {
2322
2396
  for (var e = n[0], t = 1; t < n.length; ++t)
2323
2397
  n[t] > e && (e = n[t]);
2324
2398
  return e;
2325
2399
  }, de = function(n, e, t) {
2326
2400
  var r = e / 8 | 0;
2327
2401
  return (n[r] | n[r + 1] << 8) >> (e & 7) & t;
2328
- }, lt = function(n, e) {
2402
+ }, ut = function(n, e) {
2329
2403
  var t = e / 8 | 0;
2330
2404
  return (n[t] | n[t + 1] << 8 | n[t + 2] << 16) >> (e & 7);
2331
- }, Ot = function(n) {
2405
+ }, _t = function(n) {
2332
2406
  return (n + 7) / 8 | 0;
2333
- }, De = function(n, e, t) {
2407
+ }, He = function(n, e, t) {
2334
2408
  return (e == null || e < 0) && (e = 0), (t == null || t > n.length) && (t = n.length), new ae(n.subarray(e, t));
2335
- }, cr = [
2409
+ }, mr = [
2336
2410
  "unexpected EOF",
2337
2411
  "invalid block type",
2338
2412
  "invalid length/literal",
@@ -2349,310 +2423,310 @@ var or = /* @__PURE__ */ xe(Oe, 9, 0), sr = /* @__PURE__ */ xe(Oe, 9, 1), ir = /
2349
2423
  "stream finishing",
2350
2424
  "invalid zip data"
2351
2425
  // determined by unknown compression method
2352
- ], ce = function(n, e, t) {
2353
- var r = new Error(e || cr[n]);
2354
- if (r.code = n, Error.captureStackTrace && Error.captureStackTrace(r, ce), !t)
2426
+ ], he = function(n, e, t) {
2427
+ var r = new Error(e || mr[n]);
2428
+ if (r.code = n, Error.captureStackTrace && Error.captureStackTrace(r, he), !t)
2355
2429
  throw r;
2356
2430
  return r;
2357
- }, hr = function(n, e, t, r) {
2358
- var a = n.length, o = r ? r.length : 0;
2431
+ }, pr = function(n, e, t, r) {
2432
+ var a = n.length, s = r ? r.length : 0;
2359
2433
  if (!a || e.f && !e.l)
2360
2434
  return t || new ae(0);
2361
- var i = !t, f = i || e.i != 2, m = e.i;
2362
- i && (t = new ae(a * 3));
2363
- var g = function(k) {
2364
- var P = t.length;
2365
- if (k > P) {
2366
- var A = new ae(Math.max(P * 2, k));
2367
- A.set(t), t = A;
2368
- }
2369
- }, p = e.f || 0, l = e.p || 0, h = e.b || 0, E = e.l, y = e.d, u = e.m, v = e.n, x = a * 8;
2435
+ var l = !t, f = l || e.i != 2, y = e.i;
2436
+ l && (t = new ae(a * 3));
2437
+ var d = function(F) {
2438
+ var C = t.length;
2439
+ if (F > C) {
2440
+ var Z = new ae(Math.max(C * 2, F));
2441
+ Z.set(t), t = Z;
2442
+ }
2443
+ }, m = e.f || 0, c = e.p || 0, p = e.b || 0, b = e.l, v = e.d, h = e.m, u = e.n, w = a * 8;
2370
2444
  do {
2371
- if (!E) {
2372
- p = de(n, l, 1);
2373
- var s = de(n, l + 1, 3);
2374
- if (l += 3, s)
2375
- if (s == 1)
2376
- E = sr, y = lr, u = 9, v = 5;
2377
- else if (s == 2) {
2378
- var w = de(n, l, 31) + 257, F = de(n, l + 10, 15) + 4, Y = w + de(n, l + 5, 31) + 1;
2379
- l += 14;
2380
- for (var I = new ae(Y), _ = new ae(19), B = 0; B < F; ++B)
2381
- _[ft[B]] = de(n, l + B * 3, 7);
2382
- l += F * 3;
2383
- for (var O = it(_), z = (1 << O) - 1, D = xe(_, O, 1), B = 0; B < Y; ) {
2384
- var J = D[de(n, l, z)];
2385
- l += J & 15;
2386
- var c = J >> 4;
2387
- if (c < 16)
2388
- I[B++] = c;
2445
+ if (!b) {
2446
+ m = de(n, c, 1);
2447
+ var o = de(n, c + 1, 3);
2448
+ if (c += 3, o)
2449
+ if (o == 1)
2450
+ b = hr, v = fr, h = 9, u = 5;
2451
+ else if (o == 2) {
2452
+ var A = de(n, c, 31) + 257, L = de(n, c + 10, 15) + 4, B = A + de(n, c + 5, 31) + 1;
2453
+ c += 14;
2454
+ for (var j = new ae(B), k = new ae(19), U = 0; U < L; ++U)
2455
+ k[dt[U]] = de(n, c + U * 3, 7);
2456
+ c += L * 3;
2457
+ for (var O = ht(k), $ = (1 << O) - 1, D = xe(k, O, 1), U = 0; U < B; ) {
2458
+ var q = D[de(n, c, $)];
2459
+ c += q & 15;
2460
+ var i = q >> 4;
2461
+ if (i < 16)
2462
+ j[U++] = i;
2389
2463
  else {
2390
- var j = 0, H = 0;
2391
- for (c == 16 ? (H = 3 + de(n, l, 3), l += 2, j = I[B - 1]) : c == 17 ? (H = 3 + de(n, l, 7), l += 3) : c == 18 && (H = 11 + de(n, l, 127), l += 7); H--; )
2392
- I[B++] = j;
2464
+ var N = 0, P = 0;
2465
+ for (i == 16 ? (P = 3 + de(n, c, 3), c += 2, N = j[U - 1]) : i == 17 ? (P = 3 + de(n, c, 7), c += 3) : i == 18 && (P = 11 + de(n, c, 127), c += 7); P--; )
2466
+ j[U++] = N;
2393
2467
  }
2394
2468
  }
2395
- var Z = I.subarray(0, w), $ = I.subarray(w);
2396
- u = it(Z), v = it($), E = xe(Z, u, 1), y = xe($, v, 1);
2469
+ var H = j.subarray(0, A), G = j.subarray(A);
2470
+ h = ht(H), u = ht(G), b = xe(H, h, 1), v = xe(G, u, 1);
2397
2471
  } else
2398
- ce(1);
2472
+ he(1);
2399
2473
  else {
2400
- var c = Ot(l) + 4, T = n[c - 4] | n[c - 3] << 8, d = c + T;
2401
- if (d > a) {
2402
- m && ce(0);
2474
+ var i = _t(c) + 4, S = n[i - 4] | n[i - 3] << 8, g = i + S;
2475
+ if (g > a) {
2476
+ y && he(0);
2403
2477
  break;
2404
2478
  }
2405
- f && g(h + T), t.set(n.subarray(c, d), h), e.b = h += T, e.p = l = d * 8, e.f = p;
2479
+ f && d(p + S), t.set(n.subarray(i, g), p), e.b = p += S, e.p = c = g * 8, e.f = m;
2406
2480
  continue;
2407
2481
  }
2408
- if (l > x) {
2409
- m && ce(0);
2482
+ if (c > w) {
2483
+ y && he(0);
2410
2484
  break;
2411
2485
  }
2412
2486
  }
2413
- f && g(h + 131072);
2414
- for (var q = (1 << u) - 1, W = (1 << v) - 1, N = l; ; N = l) {
2415
- var j = E[lt(n, l) & q], G = j >> 4;
2416
- if (l += j & 15, l > x) {
2417
- m && ce(0);
2487
+ f && d(p + 131072);
2488
+ for (var z = (1 << h) - 1, W = (1 << u) - 1, I = c; ; I = c) {
2489
+ var N = b[ut(n, c) & z], V = N >> 4;
2490
+ if (c += N & 15, c > w) {
2491
+ y && he(0);
2418
2492
  break;
2419
2493
  }
2420
- if (j || ce(2), G < 256)
2421
- t[h++] = G;
2422
- else if (G == 256) {
2423
- N = l, E = null;
2494
+ if (N || he(2), V < 256)
2495
+ t[p++] = V;
2496
+ else if (V == 256) {
2497
+ I = c, b = null;
2424
2498
  break;
2425
2499
  } else {
2426
- var V = G - 254;
2427
- if (G > 264) {
2428
- var B = G - 257, b = Ke[B];
2429
- V = de(n, l, (1 << b) - 1) + ln[B], l += b;
2500
+ var K = V - 254;
2501
+ if (V > 264) {
2502
+ var U = V - 257, x = et[U];
2503
+ K = de(n, c, (1 << x) - 1) + cn[U], c += x;
2430
2504
  }
2431
- var M = y[lt(n, l) & W], S = M >> 4;
2432
- M || ce(3), l += M & 15;
2433
- var $ = ar[S];
2434
- if (S > 3) {
2435
- var b = Qe[S];
2436
- $ += lt(n, l) & (1 << b) - 1, l += b;
2505
+ var M = v[ut(n, c) & W], T = M >> 4;
2506
+ M || he(3), c += M & 15;
2507
+ var G = lr[T];
2508
+ if (T > 3) {
2509
+ var x = tt[T];
2510
+ G += ut(n, c) & (1 << x) - 1, c += x;
2437
2511
  }
2438
- if (l > x) {
2439
- m && ce(0);
2512
+ if (c > w) {
2513
+ y && he(0);
2440
2514
  break;
2441
2515
  }
2442
- f && g(h + 131072);
2443
- var L = h + V;
2444
- if (h < $) {
2445
- var U = o - $, X = Math.min($, L);
2446
- for (U + h < 0 && ce(3); h < X; ++h)
2447
- t[h] = r[U + h];
2516
+ f && d(p + 131072);
2517
+ var _ = p + K;
2518
+ if (p < G) {
2519
+ var Y = s - G, X = Math.min(G, _);
2520
+ for (Y + p < 0 && he(3); p < X; ++p)
2521
+ t[p] = r[Y + p];
2448
2522
  }
2449
- for (; h < L; ++h)
2450
- t[h] = t[h - $];
2523
+ for (; p < _; ++p)
2524
+ t[p] = t[p - G];
2451
2525
  }
2452
2526
  }
2453
- e.l = E, e.p = N, e.b = h, e.f = p, E && (p = 1, e.m = u, e.d = y, e.n = v);
2454
- } while (!p);
2455
- return h != t.length && i ? De(t, 0, h) : t.subarray(0, h);
2456
- }, Ee = function(n, e, t) {
2527
+ e.l = b, e.p = I, e.b = p, e.f = m, b && (m = 1, e.m = h, e.d = v, e.n = u);
2528
+ } while (!m);
2529
+ return p != t.length && l ? He(t, 0, p) : t.subarray(0, p);
2530
+ }, Me = function(n, e, t) {
2457
2531
  t <<= e & 7;
2458
2532
  var r = e / 8 | 0;
2459
2533
  n[r] |= t, n[r + 1] |= t >> 8;
2460
- }, je = function(n, e, t) {
2534
+ }, $e = function(n, e, t) {
2461
2535
  t <<= e & 7;
2462
2536
  var r = e / 8 | 0;
2463
2537
  n[r] |= t, n[r + 1] |= t >> 8, n[r + 2] |= t >> 16;
2464
- }, ct = function(n, e) {
2538
+ }, ft = function(n, e) {
2465
2539
  for (var t = [], r = 0; r < n.length; ++r)
2466
2540
  n[r] && t.push({ s: r, f: n[r] });
2467
- var a = t.length, o = t.slice();
2541
+ var a = t.length, s = t.slice();
2468
2542
  if (!a)
2469
- return { t: un, l: 0 };
2543
+ return { t: fn, l: 0 };
2470
2544
  if (a == 1) {
2471
- var i = new ae(t[0].s + 1);
2472
- return i[t[0].s] = 1, { t: i, l: 1 };
2545
+ var l = new ae(t[0].s + 1);
2546
+ return l[t[0].s] = 1, { t: l, l: 1 };
2473
2547
  }
2474
- t.sort(function(d, w) {
2475
- return d.f - w.f;
2548
+ t.sort(function(g, A) {
2549
+ return g.f - A.f;
2476
2550
  }), t.push({ s: -1, f: 25001 });
2477
- var f = t[0], m = t[1], g = 0, p = 1, l = 2;
2478
- for (t[0] = { s: -1, f: f.f + m.f, l: f, r: m }; p != a - 1; )
2479
- f = t[t[g].f < t[l].f ? g++ : l++], m = t[g != p && t[g].f < t[l].f ? g++ : l++], t[p++] = { s: -1, f: f.f + m.f, l: f, r: m };
2480
- for (var h = o[0].s, r = 1; r < a; ++r)
2481
- o[r].s > h && (h = o[r].s);
2482
- var E = new ue(h + 1), y = dt(t[p - 1], E, 0);
2483
- if (y > e) {
2484
- var r = 0, u = 0, v = y - e, x = 1 << v;
2485
- for (o.sort(function(w, F) {
2486
- return E[F.s] - E[w.s] || w.f - F.f;
2551
+ var f = t[0], y = t[1], d = 0, m = 1, c = 2;
2552
+ for (t[0] = { s: -1, f: f.f + y.f, l: f, r: y }; m != a - 1; )
2553
+ f = t[t[d].f < t[c].f ? d++ : c++], y = t[d != m && t[d].f < t[c].f ? d++ : c++], t[m++] = { s: -1, f: f.f + y.f, l: f, r: y };
2554
+ for (var p = s[0].s, r = 1; r < a; ++r)
2555
+ s[r].s > p && (p = s[r].s);
2556
+ var b = new fe(p + 1), v = vt(t[m - 1], b, 0);
2557
+ if (v > e) {
2558
+ var r = 0, h = 0, u = v - e, w = 1 << u;
2559
+ for (s.sort(function(A, L) {
2560
+ return b[L.s] - b[A.s] || A.f - L.f;
2487
2561
  }); r < a; ++r) {
2488
- var s = o[r].s;
2489
- if (E[s] > e)
2490
- u += x - (1 << y - E[s]), E[s] = e;
2562
+ var o = s[r].s;
2563
+ if (b[o] > e)
2564
+ h += w - (1 << v - b[o]), b[o] = e;
2491
2565
  else
2492
2566
  break;
2493
2567
  }
2494
- for (u >>= v; u > 0; ) {
2495
- var c = o[r].s;
2496
- E[c] < e ? u -= 1 << e - E[c]++ - 1 : ++r;
2568
+ for (h >>= u; h > 0; ) {
2569
+ var i = s[r].s;
2570
+ b[i] < e ? h -= 1 << e - b[i]++ - 1 : ++r;
2497
2571
  }
2498
- for (; r >= 0 && u; --r) {
2499
- var T = o[r].s;
2500
- E[T] == e && (--E[T], ++u);
2572
+ for (; r >= 0 && h; --r) {
2573
+ var S = s[r].s;
2574
+ b[S] == e && (--b[S], ++h);
2501
2575
  }
2502
- y = e;
2576
+ v = e;
2503
2577
  }
2504
- return { t: new ae(E), l: y };
2505
- }, dt = function(n, e, t) {
2506
- return n.s == -1 ? Math.max(dt(n.l, e, t + 1), dt(n.r, e, t + 1)) : e[n.s] = t;
2507
- }, Gt = function(n) {
2578
+ return { t: new ae(b), l: v };
2579
+ }, vt = function(n, e, t) {
2580
+ return n.s == -1 ? Math.max(vt(n.l, e, t + 1), vt(n.r, e, t + 1)) : e[n.s] = t;
2581
+ }, Vt = function(n) {
2508
2582
  for (var e = n.length; e && !n[--e]; )
2509
2583
  ;
2510
- for (var t = new ue(++e), r = 0, a = n[0], o = 1, i = function(m) {
2511
- t[r++] = m;
2584
+ for (var t = new fe(++e), r = 0, a = n[0], s = 1, l = function(y) {
2585
+ t[r++] = y;
2512
2586
  }, f = 1; f <= e; ++f)
2513
2587
  if (n[f] == a && f != e)
2514
- ++o;
2588
+ ++s;
2515
2589
  else {
2516
- if (!a && o > 2) {
2517
- for (; o > 138; o -= 138)
2518
- i(32754);
2519
- o > 2 && (i(o > 10 ? o - 11 << 5 | 28690 : o - 3 << 5 | 12305), o = 0);
2520
- } else if (o > 3) {
2521
- for (i(a), --o; o > 6; o -= 6)
2522
- i(8304);
2523
- o > 2 && (i(o - 3 << 5 | 8208), o = 0);
2590
+ if (!a && s > 2) {
2591
+ for (; s > 138; s -= 138)
2592
+ l(32754);
2593
+ s > 2 && (l(s > 10 ? s - 11 << 5 | 28690 : s - 3 << 5 | 12305), s = 0);
2594
+ } else if (s > 3) {
2595
+ for (l(a), --s; s > 6; s -= 6)
2596
+ l(8304);
2597
+ s > 2 && (l(s - 3 << 5 | 8208), s = 0);
2524
2598
  }
2525
- for (; o--; )
2526
- i(a);
2527
- o = 1, a = n[f];
2599
+ for (; s--; )
2600
+ l(a);
2601
+ s = 1, a = n[f];
2528
2602
  }
2529
2603
  return { c: t.subarray(0, r), n: e };
2530
- }, Xe = function(n, e) {
2604
+ }, ze = function(n, e) {
2531
2605
  for (var t = 0, r = 0; r < e.length; ++r)
2532
2606
  t += n[r] * e[r];
2533
2607
  return t;
2534
- }, hn = function(n, e, t) {
2535
- var r = t.length, a = Ot(e + 2);
2608
+ }, un = function(n, e, t) {
2609
+ var r = t.length, a = _t(e + 2);
2536
2610
  n[a] = r & 255, n[a + 1] = r >> 8, n[a + 2] = n[a] ^ 255, n[a + 3] = n[a + 1] ^ 255;
2537
- for (var o = 0; o < r; ++o)
2538
- n[a + o + 4] = t[o];
2611
+ for (var s = 0; s < r; ++s)
2612
+ n[a + s + 4] = t[s];
2539
2613
  return (a + 4 + r) * 8;
2540
- }, Vt = function(n, e, t, r, a, o, i, f, m, g, p) {
2541
- Ee(e, p++, t), ++a[256];
2542
- for (var l = ct(a, 15), h = l.t, E = l.l, y = ct(o, 15), u = y.t, v = y.l, x = Gt(h), s = x.c, c = x.n, T = Gt(u), d = T.c, w = T.n, F = new ue(19), Y = 0; Y < s.length; ++Y)
2543
- ++F[s[Y] & 31];
2544
- for (var Y = 0; Y < d.length; ++Y)
2545
- ++F[d[Y] & 31];
2546
- for (var I = ct(F, 7), _ = I.t, B = I.l, O = 19; O > 4 && !_[ft[O - 1]]; --O)
2614
+ }, qt = function(n, e, t, r, a, s, l, f, y, d, m) {
2615
+ Me(e, m++, t), ++a[256];
2616
+ for (var c = ft(a, 15), p = c.t, b = c.l, v = ft(s, 15), h = v.t, u = v.l, w = Vt(p), o = w.c, i = w.n, S = Vt(h), g = S.c, A = S.n, L = new fe(19), B = 0; B < o.length; ++B)
2617
+ ++L[o[B] & 31];
2618
+ for (var B = 0; B < g.length; ++B)
2619
+ ++L[g[B] & 31];
2620
+ for (var j = ft(L, 7), k = j.t, U = j.l, O = 19; O > 4 && !k[dt[O - 1]]; --O)
2547
2621
  ;
2548
- var z = g + 5 << 3, D = Xe(a, Oe) + Xe(o, Pe) + i, J = Xe(a, h) + Xe(o, u) + i + 14 + 3 * O + Xe(F, _) + 2 * F[16] + 3 * F[17] + 7 * F[18];
2549
- if (m >= 0 && z <= D && z <= J)
2550
- return hn(e, p, n.subarray(m, m + g));
2551
- var j, H, Z, $;
2552
- if (Ee(e, p, 1 + (J < D)), p += 2, J < D) {
2553
- j = xe(h, E, 0), H = h, Z = xe(u, v, 0), $ = u;
2554
- var q = xe(_, B, 0);
2555
- Ee(e, p, c - 257), Ee(e, p + 5, w - 1), Ee(e, p + 10, O - 4), p += 14;
2556
- for (var Y = 0; Y < O; ++Y)
2557
- Ee(e, p + 3 * Y, _[ft[Y]]);
2558
- p += 3 * O;
2559
- for (var W = [s, d], N = 0; N < 2; ++N)
2560
- for (var G = W[N], Y = 0; Y < G.length; ++Y) {
2561
- var V = G[Y] & 31;
2562
- Ee(e, p, q[V]), p += _[V], V > 15 && (Ee(e, p, G[Y] >> 5 & 127), p += G[Y] >> 12);
2622
+ var $ = d + 5 << 3, D = ze(a, Te) + ze(s, De) + l, q = ze(a, p) + ze(s, h) + l + 14 + 3 * O + ze(L, k) + 2 * L[16] + 3 * L[17] + 7 * L[18];
2623
+ if (y >= 0 && $ <= D && $ <= q)
2624
+ return un(e, m, n.subarray(y, y + d));
2625
+ var N, P, H, G;
2626
+ if (Me(e, m, 1 + (q < D)), m += 2, q < D) {
2627
+ N = xe(p, b, 0), P = p, H = xe(h, u, 0), G = h;
2628
+ var z = xe(k, U, 0);
2629
+ Me(e, m, i - 257), Me(e, m + 5, A - 1), Me(e, m + 10, O - 4), m += 14;
2630
+ for (var B = 0; B < O; ++B)
2631
+ Me(e, m + 3 * B, k[dt[B]]);
2632
+ m += 3 * O;
2633
+ for (var W = [o, g], I = 0; I < 2; ++I)
2634
+ for (var V = W[I], B = 0; B < V.length; ++B) {
2635
+ var K = V[B] & 31;
2636
+ Me(e, m, z[K]), m += k[K], K > 15 && (Me(e, m, V[B] >> 5 & 127), m += V[B] >> 12);
2563
2637
  }
2564
2638
  } else
2565
- j = or, H = Oe, Z = ir, $ = Pe;
2566
- for (var Y = 0; Y < f; ++Y) {
2567
- var b = r[Y];
2568
- if (b > 255) {
2569
- var V = b >> 18 & 31;
2570
- je(e, p, j[V + 257]), p += H[V + 257], V > 7 && (Ee(e, p, b >> 23 & 31), p += Ke[V]);
2571
- var M = b & 31;
2572
- je(e, p, Z[M]), p += $[M], M > 3 && (je(e, p, b >> 5 & 8191), p += Qe[M]);
2639
+ N = cr, P = Te, H = ur, G = De;
2640
+ for (var B = 0; B < f; ++B) {
2641
+ var x = r[B];
2642
+ if (x > 255) {
2643
+ var K = x >> 18 & 31;
2644
+ $e(e, m, N[K + 257]), m += P[K + 257], K > 7 && (Me(e, m, x >> 23 & 31), m += et[K]);
2645
+ var M = x & 31;
2646
+ $e(e, m, H[M]), m += G[M], M > 3 && ($e(e, m, x >> 5 & 8191), m += tt[M]);
2573
2647
  } else
2574
- je(e, p, j[b]), p += H[b];
2648
+ $e(e, m, N[x]), m += P[x];
2575
2649
  }
2576
- return je(e, p, j[256]), p + H[256];
2577
- }, ur = /* @__PURE__ */ new Tt([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), un = /* @__PURE__ */ new ae(0), fr = function(n, e, t, r, a, o) {
2578
- var i = o.z || n.length, f = new ae(r + i + 5 * (1 + Math.ceil(i / 7e3)) + a), m = f.subarray(r, f.length - a), g = o.l, p = (o.r || 0) & 7;
2650
+ return $e(e, m, N[256]), m + P[256];
2651
+ }, dr = /* @__PURE__ */ new Lt([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), fn = /* @__PURE__ */ new ae(0), gr = function(n, e, t, r, a, s) {
2652
+ var l = s.z || n.length, f = new ae(r + l + 5 * (1 + Math.ceil(l / 7e3)) + a), y = f.subarray(r, f.length - a), d = s.l, m = (s.r || 0) & 7;
2579
2653
  if (e) {
2580
- p && (m[0] = o.r >> 3);
2581
- for (var l = ur[e - 1], h = l >> 13, E = l & 8191, y = (1 << t) - 1, u = o.p || new ue(32768), v = o.h || new ue(y + 1), x = Math.ceil(t / 3), s = 2 * x, c = function(R) {
2582
- return (n[R] ^ n[R + 1] << x ^ n[R + 2] << s) & y;
2583
- }, T = new Tt(25e3), d = new ue(288), w = new ue(32), F = 0, Y = 0, I = o.i || 0, _ = 0, B = o.w || 0, O = 0; I + 2 < i; ++I) {
2584
- var z = c(I), D = I & 32767, J = v[z];
2585
- if (u[D] = J, v[z] = D, B <= I) {
2586
- var j = i - I;
2587
- if ((F > 7e3 || _ > 24576) && (j > 423 || !g)) {
2588
- p = Vt(n, m, 0, T, d, w, Y, _, O, I - O, p), _ = F = Y = 0, O = I;
2589
- for (var H = 0; H < 286; ++H)
2590
- d[H] = 0;
2591
- for (var H = 0; H < 30; ++H)
2592
- w[H] = 0;
2654
+ m && (y[0] = s.r >> 3);
2655
+ for (var c = dr[e - 1], p = c >> 13, b = c & 8191, v = (1 << t) - 1, h = s.p || new fe(32768), u = s.h || new fe(v + 1), w = Math.ceil(t / 3), o = 2 * w, i = function(E) {
2656
+ return (n[E] ^ n[E + 1] << w ^ n[E + 2] << o) & v;
2657
+ }, S = new Lt(25e3), g = new fe(288), A = new fe(32), L = 0, B = 0, j = s.i || 0, k = 0, U = s.w || 0, O = 0; j + 2 < l; ++j) {
2658
+ var $ = i(j), D = j & 32767, q = u[$];
2659
+ if (h[D] = q, u[$] = D, U <= j) {
2660
+ var N = l - j;
2661
+ if ((L > 7e3 || k > 24576) && (N > 423 || !d)) {
2662
+ m = qt(n, y, 0, S, g, A, B, k, O, j - O, m), k = L = B = 0, O = j;
2663
+ for (var P = 0; P < 286; ++P)
2664
+ g[P] = 0;
2665
+ for (var P = 0; P < 30; ++P)
2666
+ A[P] = 0;
2593
2667
  }
2594
- var Z = 2, $ = 0, q = E, W = D - J & 32767;
2595
- if (j > 2 && z == c(I - W))
2596
- for (var N = Math.min(h, j) - 1, G = Math.min(32767, I), V = Math.min(258, j); W <= G && --q && D != J; ) {
2597
- if (n[I + Z] == n[I + Z - W]) {
2598
- for (var b = 0; b < V && n[I + b] == n[I + b - W]; ++b)
2668
+ var H = 2, G = 0, z = b, W = D - q & 32767;
2669
+ if (N > 2 && $ == i(j - W))
2670
+ for (var I = Math.min(p, N) - 1, V = Math.min(32767, j), K = Math.min(258, N); W <= V && --z && D != q; ) {
2671
+ if (n[j + H] == n[j + H - W]) {
2672
+ for (var x = 0; x < K && n[j + x] == n[j + x - W]; ++x)
2599
2673
  ;
2600
- if (b > Z) {
2601
- if (Z = b, $ = W, b > N)
2674
+ if (x > H) {
2675
+ if (H = x, G = W, x > I)
2602
2676
  break;
2603
- for (var M = Math.min(W, b - 2), S = 0, H = 0; H < M; ++H) {
2604
- var L = I - W + H & 32767, U = u[L], X = L - U & 32767;
2605
- X > S && (S = X, J = L);
2677
+ for (var M = Math.min(W, x - 2), T = 0, P = 0; P < M; ++P) {
2678
+ var _ = j - W + P & 32767, Y = h[_], X = _ - Y & 32767;
2679
+ X > T && (T = X, q = _);
2606
2680
  }
2607
2681
  }
2608
2682
  }
2609
- D = J, J = u[D], W += D - J & 32767;
2683
+ D = q, q = h[D], W += D - q & 32767;
2610
2684
  }
2611
- if ($) {
2612
- T[_++] = 268435456 | mt[Z] << 18 | Wt[$];
2613
- var k = mt[Z] & 31, P = Wt[$] & 31;
2614
- Y += Ke[k] + Qe[P], ++d[257 + k], ++w[P], B = I + Z, ++F;
2685
+ if (G) {
2686
+ S[k++] = 268435456 | gt[H] << 18 | Gt[G];
2687
+ var F = gt[H] & 31, C = Gt[G] & 31;
2688
+ B += et[F] + tt[C], ++g[257 + F], ++A[C], U = j + H, ++L;
2615
2689
  } else
2616
- T[_++] = n[I], ++d[n[I]];
2690
+ S[k++] = n[j], ++g[n[j]];
2617
2691
  }
2618
2692
  }
2619
- for (I = Math.max(I, B); I < i; ++I)
2620
- T[_++] = n[I], ++d[n[I]];
2621
- p = Vt(n, m, g, T, d, w, Y, _, O, I - O, p), g || (o.r = p & 7 | m[p / 8 | 0] << 3, p -= 7, o.h = v, o.p = u, o.i = I, o.w = B);
2693
+ for (j = Math.max(j, U); j < l; ++j)
2694
+ S[k++] = n[j], ++g[n[j]];
2695
+ m = qt(n, y, d, S, g, A, B, k, O, j - O, m), d || (s.r = m & 7 | y[m / 8 | 0] << 3, m -= 7, s.h = u, s.p = h, s.i = j, s.w = U);
2622
2696
  } else {
2623
- for (var I = o.w || 0; I < i + g; I += 65535) {
2624
- var A = I + 65535;
2625
- A >= i && (m[p / 8 | 0] = g, A = i), p = hn(m, p + 1, n.subarray(I, A));
2697
+ for (var j = s.w || 0; j < l + d; j += 65535) {
2698
+ var Z = j + 65535;
2699
+ Z >= l && (y[m / 8 | 0] = d, Z = l), m = un(y, m + 1, n.subarray(j, Z));
2626
2700
  }
2627
- o.i = i;
2701
+ s.i = l;
2628
2702
  }
2629
- return De(f, 0, r + Ot(p) + a);
2630
- }, mr = /* @__PURE__ */ (function() {
2703
+ return He(f, 0, r + _t(m) + a);
2704
+ }, yr = /* @__PURE__ */ (function() {
2631
2705
  for (var n = new Int32Array(256), e = 0; e < 256; ++e) {
2632
2706
  for (var t = e, r = 9; --r; )
2633
2707
  t = (t & 1 && -306674912) ^ t >>> 1;
2634
2708
  n[e] = t;
2635
2709
  }
2636
2710
  return n;
2637
- })(), pr = function() {
2711
+ })(), vr = function() {
2638
2712
  var n = -1;
2639
2713
  return {
2640
2714
  p: function(e) {
2641
2715
  for (var t = n, r = 0; r < e.length; ++r)
2642
- t = mr[t & 255 ^ e[r]] ^ t >>> 8;
2716
+ t = yr[t & 255 ^ e[r]] ^ t >>> 8;
2643
2717
  n = t;
2644
2718
  },
2645
2719
  d: function() {
2646
2720
  return ~n;
2647
2721
  }
2648
2722
  };
2649
- }, dr = function(n, e, t, r, a) {
2723
+ }, br = function(n, e, t, r, a) {
2650
2724
  if (!a && (a = { l: 1 }, e.dictionary)) {
2651
- var o = e.dictionary.subarray(-32768), i = new ae(o.length + n.length);
2652
- i.set(o), i.set(n, o.length), n = i, a.w = o.length;
2725
+ var s = e.dictionary.subarray(-32768), l = new ae(s.length + n.length);
2726
+ l.set(s), l.set(n, s.length), n = l, a.w = s.length;
2653
2727
  }
2654
- return fr(n, e.level == null ? 6 : e.level, e.mem == null ? a.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(n.length))) * 1.5) : 20 : 12 + e.mem, t, r, a);
2655
- }, fn = function(n, e) {
2728
+ return gr(n, e.level == null ? 6 : e.level, e.mem == null ? a.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(n.length))) * 1.5) : 20 : 12 + e.mem, t, r, a);
2729
+ }, mn = function(n, e) {
2656
2730
  var t = {};
2657
2731
  for (var r in n)
2658
2732
  t[r] = n[r];
@@ -2661,337 +2735,341 @@ var or = /* @__PURE__ */ xe(Oe, 9, 0), sr = /* @__PURE__ */ xe(Oe, 9, 1), ir = /
2661
2735
  return t;
2662
2736
  }, be = function(n, e) {
2663
2737
  return n[e] | n[e + 1] << 8;
2664
- }, fe = function(n, e) {
2738
+ }, me = function(n, e) {
2665
2739
  return (n[e] | n[e + 1] << 8 | n[e + 2] << 16 | n[e + 3] << 24) >>> 0;
2666
- }, ht = function(n, e) {
2667
- return fe(n, e) + fe(n, e + 4) * 4294967296;
2668
- }, le = function(n, e, t) {
2740
+ }, mt = function(n, e) {
2741
+ return me(n, e) + me(n, e + 4) * 4294967296;
2742
+ }, ie = function(n, e, t) {
2669
2743
  for (; t; ++e)
2670
2744
  n[e] = t, t >>>= 8;
2671
2745
  };
2672
- function gr(n, e) {
2673
- return dr(n, e || {}, 0, 0);
2746
+ function xr(n, e) {
2747
+ return br(n, e || {}, 0, 0);
2674
2748
  }
2675
- function yr(n, e) {
2676
- return hr(n, { i: 2 }, e && e.out, e && e.dictionary);
2749
+ function wr(n, e) {
2750
+ return pr(n, { i: 2 }, e && e.out, e && e.dictionary);
2677
2751
  }
2678
- var mn = function(n, e, t, r) {
2752
+ var pn = function(n, e, t, r) {
2679
2753
  for (var a in n) {
2680
- var o = n[a], i = e + a, f = r;
2681
- Array.isArray(o) && (f = fn(r, o[1]), o = o[0]), ArrayBuffer.isView(o) ? t[i] = [o, f] : (t[i += "/"] = [new ae(0), f], mn(o, i, t, r));
2754
+ var s = n[a], l = e + a, f = r;
2755
+ Array.isArray(s) && (f = mn(r, s[1]), s = s[0]), ArrayBuffer.isView(s) ? t[l] = [s, f] : (t[l += "/"] = [new ae(0), f], pn(s, l, t, r));
2682
2756
  }
2683
- }, qt = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), gt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), vr = 0;
2757
+ }, Jt = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), bt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), Ar = 0;
2684
2758
  try {
2685
- gt.decode(un, { stream: !0 }), vr = 1;
2759
+ bt.decode(fn, { stream: !0 }), Ar = 1;
2686
2760
  } catch {
2687
2761
  }
2688
- var br = function(n) {
2762
+ var Mr = function(n) {
2689
2763
  for (var e = "", t = 0; ; ) {
2690
2764
  var r = n[t++], a = (r > 127) + (r > 223) + (r > 239);
2691
2765
  if (t + a > n.length)
2692
- return { s: e, r: De(n, t - 1) };
2766
+ return { s: e, r: He(n, t - 1) };
2693
2767
  a ? a == 3 ? (r = ((r & 15) << 18 | (n[t++] & 63) << 12 | (n[t++] & 63) << 6 | n[t++] & 63) - 65536, e += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : a & 1 ? e += String.fromCharCode((r & 31) << 6 | n[t++] & 63) : e += String.fromCharCode((r & 15) << 12 | (n[t++] & 63) << 6 | n[t++] & 63) : e += String.fromCharCode(r);
2694
2768
  }
2695
2769
  };
2696
- function Jt(n, e) {
2770
+ function Kt(n, e) {
2697
2771
  var t;
2698
- if (qt)
2699
- return qt.encode(n);
2700
- for (var r = n.length, a = new ae(n.length + (n.length >> 1)), o = 0, i = function(g) {
2701
- a[o++] = g;
2772
+ if (Jt)
2773
+ return Jt.encode(n);
2774
+ for (var r = n.length, a = new ae(n.length + (n.length >> 1)), s = 0, l = function(d) {
2775
+ a[s++] = d;
2702
2776
  }, t = 0; t < r; ++t) {
2703
- if (o + 5 > a.length) {
2704
- var f = new ae(o + 8 + (r - t << 1));
2777
+ if (s + 5 > a.length) {
2778
+ var f = new ae(s + 8 + (r - t << 1));
2705
2779
  f.set(a), a = f;
2706
2780
  }
2707
- var m = n.charCodeAt(t);
2708
- m < 128 || e ? i(m) : m < 2048 ? (i(192 | m >> 6), i(128 | m & 63)) : m > 55295 && m < 57344 ? (m = 65536 + (m & 1047552) | n.charCodeAt(++t) & 1023, i(240 | m >> 18), i(128 | m >> 12 & 63), i(128 | m >> 6 & 63), i(128 | m & 63)) : (i(224 | m >> 12), i(128 | m >> 6 & 63), i(128 | m & 63));
2781
+ var y = n.charCodeAt(t);
2782
+ y < 128 || e ? l(y) : y < 2048 ? (l(192 | y >> 6), l(128 | y & 63)) : y > 55295 && y < 57344 ? (y = 65536 + (y & 1047552) | n.charCodeAt(++t) & 1023, l(240 | y >> 18), l(128 | y >> 12 & 63), l(128 | y >> 6 & 63), l(128 | y & 63)) : (l(224 | y >> 12), l(128 | y >> 6 & 63), l(128 | y & 63));
2709
2783
  }
2710
- return De(a, 0, o);
2784
+ return He(a, 0, s);
2711
2785
  }
2712
- function xr(n, e) {
2786
+ function Er(n, e) {
2713
2787
  if (e) {
2714
2788
  for (var t = "", r = 0; r < n.length; r += 16384)
2715
2789
  t += String.fromCharCode.apply(null, n.subarray(r, r + 16384));
2716
2790
  return t;
2717
2791
  } else {
2718
- if (gt)
2719
- return gt.decode(n);
2720
- var a = br(n), o = a.s, t = a.r;
2721
- return t.length && ce(8), o;
2792
+ if (bt)
2793
+ return bt.decode(n);
2794
+ var a = Mr(n), s = a.s, t = a.r;
2795
+ return t.length && he(8), s;
2722
2796
  }
2723
2797
  }
2724
- var wr = function(n, e) {
2798
+ var Sr = function(n, e) {
2725
2799
  return e + 30 + be(n, e + 26) + be(n, e + 28);
2726
- }, Ar = function(n, e, t) {
2727
- var r = be(n, e + 28), a = be(n, e + 30), o = xr(n.subarray(e + 46, e + 46 + r), !(be(n, e + 8) & 2048)), i = e + 46 + r, f = Mr(n, i, a, t, fe(n, e + 20), fe(n, e + 24), fe(n, e + 42)), m = f[0], g = f[1], p = f[2];
2728
- return [be(n, e + 10), m, g, o, i + a + be(n, e + 32), p];
2729
- }, Mr = function(n, e, t, r, a, o, i) {
2730
- var f = a == 4294967295, m = o == 4294967295, g = i == 4294967295, p = e + t, l = f + m + g;
2731
- if (r && l) {
2732
- for (; e + 4 < p; e += 4 + be(n, e + 2))
2800
+ }, Tr = function(n, e, t) {
2801
+ var r = be(n, e + 28), a = be(n, e + 30), s = Er(n.subarray(e + 46, e + 46 + r), !(be(n, e + 8) & 2048)), l = e + 46 + r, f = Or(n, l, a, t, me(n, e + 20), me(n, e + 24), me(n, e + 42)), y = f[0], d = f[1], m = f[2];
2802
+ return [be(n, e + 10), y, d, s, l + a + be(n, e + 32), m];
2803
+ }, Or = function(n, e, t, r, a, s, l) {
2804
+ var f = a == 4294967295, y = s == 4294967295, d = l == 4294967295, m = e + t, c = f + y + d;
2805
+ if (r && c) {
2806
+ for (; e + 4 < m; e += 4 + be(n, e + 2))
2733
2807
  if (be(n, e) == 1)
2734
2808
  return [
2735
- f ? ht(n, e + 4 + 8 * m) : a,
2736
- m ? ht(n, e + 4) : o,
2737
- g ? ht(n, e + 4 + 8 * (m + f)) : i,
2809
+ f ? mt(n, e + 4 + 8 * y) : a,
2810
+ y ? mt(n, e + 4) : s,
2811
+ d ? mt(n, e + 4 + 8 * (y + f)) : l,
2738
2812
  1
2739
2813
  ];
2740
- r < 2 && ce(13);
2814
+ r < 2 && he(13);
2741
2815
  }
2742
- return [a, o, i, 0];
2743
- }, yt = function(n) {
2816
+ return [a, s, l, 0];
2817
+ }, xt = function(n) {
2744
2818
  var e = 0;
2745
2819
  if (n)
2746
2820
  for (var t in n) {
2747
2821
  var r = n[t].length;
2748
- r > 65535 && ce(9), e += r + 4;
2822
+ r > 65535 && he(9), e += r + 4;
2749
2823
  }
2750
2824
  return e;
2751
- }, Kt = function(n, e, t, r, a, o, i, f) {
2752
- var m = r.length, g = t.extra, p = f && f.length, l = yt(g);
2753
- le(n, e, i != null ? 33639248 : 67324752), e += 4, i != null && (n[e++] = 20, n[e++] = t.os), n[e] = 20, e += 2, n[e++] = t.flag << 1 | (o < 0 && 8), n[e++] = a && 8, n[e++] = t.compression & 255, n[e++] = t.compression >> 8;
2754
- var h = new Date(t.mtime == null ? Date.now() : t.mtime), E = h.getFullYear() - 1980;
2755
- if ((E < 0 || E > 119) && ce(10), le(n, e, E << 25 | h.getMonth() + 1 << 21 | h.getDate() << 16 | h.getHours() << 11 | h.getMinutes() << 5 | h.getSeconds() >> 1), e += 4, o != -1 && (le(n, e, t.crc), le(n, e + 4, o < 0 ? -o - 2 : o), le(n, e + 8, t.size)), le(n, e + 12, m), le(n, e + 14, l), e += 16, i != null && (le(n, e, p), le(n, e + 6, t.attrs), le(n, e + 10, i), e += 14), n.set(r, e), e += m, l)
2756
- for (var y in g) {
2757
- var u = g[y], v = u.length;
2758
- le(n, e, +y), le(n, e + 2, v), n.set(u, e + 4), e += 4 + v;
2759
- }
2760
- return p && (n.set(f, e), e += p), e;
2761
- }, Er = function(n, e, t, r, a) {
2762
- le(n, e, 101010256), le(n, e + 8, t), le(n, e + 10, t), le(n, e + 12, r), le(n, e + 16, a);
2825
+ }, Qt = function(n, e, t, r, a, s, l, f) {
2826
+ var y = r.length, d = t.extra, m = f && f.length, c = xt(d);
2827
+ ie(n, e, l != null ? 33639248 : 67324752), e += 4, l != null && (n[e++] = 20, n[e++] = t.os), n[e] = 20, e += 2, n[e++] = t.flag << 1 | (s < 0 && 8), n[e++] = a && 8, n[e++] = t.compression & 255, n[e++] = t.compression >> 8;
2828
+ var p = new Date(t.mtime == null ? Date.now() : t.mtime), b = p.getFullYear() - 1980;
2829
+ if ((b < 0 || b > 119) && he(10), ie(n, e, b << 25 | p.getMonth() + 1 << 21 | p.getDate() << 16 | p.getHours() << 11 | p.getMinutes() << 5 | p.getSeconds() >> 1), e += 4, s != -1 && (ie(n, e, t.crc), ie(n, e + 4, s < 0 ? -s - 2 : s), ie(n, e + 8, t.size)), ie(n, e + 12, y), ie(n, e + 14, c), e += 16, l != null && (ie(n, e, m), ie(n, e + 6, t.attrs), ie(n, e + 10, l), e += 14), n.set(r, e), e += y, c)
2830
+ for (var v in d) {
2831
+ var h = d[v], u = h.length;
2832
+ ie(n, e, +v), ie(n, e + 2, u), n.set(h, e + 4), e += 4 + u;
2833
+ }
2834
+ return m && (n.set(f, e), e += m), e;
2835
+ }, Rr = function(n, e, t, r, a) {
2836
+ ie(n, e, 101010256), ie(n, e + 8, t), ie(n, e + 10, t), ie(n, e + 12, r), ie(n, e + 16, a);
2763
2837
  };
2764
- function Sr(n, e) {
2838
+ function Lr(n, e) {
2765
2839
  e || (e = {});
2766
2840
  var t = {}, r = [];
2767
- mn(n, "", t, e);
2768
- var a = 0, o = 0;
2769
- for (var i in t) {
2770
- var f = t[i], m = f[0], g = f[1], p = g.level == 0 ? 0 : 8, l = Jt(i), h = l.length, E = g.comment, y = E && Jt(E), u = y && y.length, v = yt(g.extra);
2771
- h > 65535 && ce(11);
2772
- var x = p ? gr(m, g) : m, s = x.length, c = pr();
2773
- c.p(m), r.push(fn(g, {
2774
- size: m.length,
2775
- crc: c.d(),
2776
- c: x,
2777
- f: l,
2778
- m: y,
2779
- u: h != i.length || y && E.length != u,
2841
+ pn(n, "", t, e);
2842
+ var a = 0, s = 0;
2843
+ for (var l in t) {
2844
+ var f = t[l], y = f[0], d = f[1], m = d.level == 0 ? 0 : 8, c = Kt(l), p = c.length, b = d.comment, v = b && Kt(b), h = v && v.length, u = xt(d.extra);
2845
+ p > 65535 && he(11);
2846
+ var w = m ? xr(y, d) : y, o = w.length, i = vr();
2847
+ i.p(y), r.push(mn(d, {
2848
+ size: y.length,
2849
+ crc: i.d(),
2850
+ c: w,
2851
+ f: c,
2852
+ m: v,
2853
+ u: p != l.length || v && b.length != h,
2780
2854
  o: a,
2781
- compression: p
2782
- })), a += 30 + h + v + s, o += 76 + 2 * (h + v) + (u || 0) + s;
2855
+ compression: m
2856
+ })), a += 30 + p + u + o, s += 76 + 2 * (p + u) + (h || 0) + o;
2783
2857
  }
2784
- for (var T = new ae(o + 22), d = a, w = o - a, F = 0; F < r.length; ++F) {
2785
- var l = r[F];
2786
- Kt(T, l.o, l, l.f, l.u, l.c.length);
2787
- var Y = 30 + l.f.length + yt(l.extra);
2788
- T.set(l.c, l.o + Y), Kt(T, a, l, l.f, l.u, l.c.length, l.o, l.m), a += 16 + Y + (l.m ? l.m.length : 0);
2858
+ for (var S = new ae(s + 22), g = a, A = s - a, L = 0; L < r.length; ++L) {
2859
+ var c = r[L];
2860
+ Qt(S, c.o, c, c.f, c.u, c.c.length);
2861
+ var B = 30 + c.f.length + xt(c.extra);
2862
+ S.set(c.c, c.o + B), Qt(S, a, c, c.f, c.u, c.c.length, c.o, c.m), a += 16 + B + (c.m ? c.m.length : 0);
2789
2863
  }
2790
- return Er(T, a, r.length, w, d), T;
2864
+ return Rr(S, a, r.length, A, g), S;
2791
2865
  }
2792
- function Tr(n, e) {
2793
- for (var t = {}, r = n.length - 22; fe(n, r) != 101010256; --r)
2794
- (!r || n.length - r > 65558) && ce(13);
2866
+ function _r(n, e) {
2867
+ for (var t = {}, r = n.length - 22; me(n, r) != 101010256; --r)
2868
+ (!r || n.length - r > 65558) && he(13);
2795
2869
  var a = be(n, r + 8);
2796
2870
  if (!a)
2797
2871
  return {};
2798
- var o = fe(n, r + 16), i = fe(n, r - 20) == 117853008;
2799
- if (i) {
2800
- var f = fe(n, r - 12);
2801
- i = fe(n, f) == 101075792, i && (a = fe(n, f + 32), o = fe(n, f + 48));
2802
- }
2803
- for (var m = e && e.filter, g = 0; g < a; ++g) {
2804
- var p = Ar(n, o, i), l = p[0], h = p[1], E = p[2], y = p[3], u = p[4], v = p[5], x = wr(n, v);
2805
- o = u, (!m || m({
2806
- name: y,
2807
- size: h,
2808
- originalSize: E,
2809
- compression: l
2810
- })) && (l ? l == 8 ? t[y] = yr(n.subarray(x, x + h), { out: new ae(E) }) : ce(14, "unknown compression type " + l) : t[y] = De(n, x, x + h));
2872
+ var s = me(n, r + 16), l = me(n, r - 20) == 117853008;
2873
+ if (l) {
2874
+ var f = me(n, r - 12);
2875
+ l = me(n, f) == 101075792, l && (a = me(n, f + 32), s = me(n, f + 48));
2876
+ }
2877
+ for (var y = e && e.filter, d = 0; d < a; ++d) {
2878
+ var m = Tr(n, s, l), c = m[0], p = m[1], b = m[2], v = m[3], h = m[4], u = m[5], w = Sr(n, u);
2879
+ s = h, (!y || y({
2880
+ name: v,
2881
+ size: p,
2882
+ originalSize: b,
2883
+ compression: c
2884
+ })) && (c ? c == 8 ? t[v] = wr(n.subarray(w, w + p), { out: new ae(b) }) : he(14, "unknown compression type " + c) : t[v] = He(n, w, w + p));
2811
2885
  }
2812
2886
  return t;
2813
2887
  }
2814
- const Je = 200, vt = 64 * 1024 * 1024, bt = new TextDecoder("utf-8", { fatal: !0 });
2815
- function Rt(n) {
2888
+ const Qe = 200, wt = 64 * 1024 * 1024, At = new TextDecoder("utf-8", { fatal: !0 });
2889
+ function kt(n) {
2816
2890
  if (!n || n.startsWith("/") || /^[A-Za-z]:/.test(n) || n.includes("\\") || n.includes("\0") || n.split("/").includes(".."))
2817
2891
  throw new Error(`ZIP entry ${JSON.stringify(n)}: path must be relative, without .. or backslashes`);
2818
2892
  }
2819
- function xt(n) {
2820
- const e = new DataView(n.buffer, n.byteOffset, n.byteLength), t = (h = "(archive)") => {
2821
- throw new Error(`ZIP entry ${JSON.stringify(h)}: invalid or truncated ZIP`);
2822
- }, r = (h) => h >= 0 && h + 2 <= n.length ? e.getUint16(h, !0) : t(), a = (h) => h >= 0 && h + 4 <= n.length ? e.getUint32(h, !0) : t();
2823
- let o = n.length - 22;
2824
- for (; o >= Math.max(0, n.length - 65557) && !(a(o) === 101010256 && o + 22 + r(o + 20) === n.length); o--)
2893
+ function Mt(n) {
2894
+ const e = new DataView(n.buffer, n.byteOffset, n.byteLength), t = (p = "(archive)") => {
2895
+ throw new Error(`ZIP entry ${JSON.stringify(p)}: invalid or truncated ZIP`);
2896
+ }, r = (p) => p >= 0 && p + 2 <= n.length ? e.getUint16(p, !0) : t(), a = (p) => p >= 0 && p + 4 <= n.length ? e.getUint32(p, !0) : t();
2897
+ let s = n.length - 22;
2898
+ for (; s >= Math.max(0, n.length - 65557) && !(a(s) === 101010256 && s + 22 + r(s + 20) === n.length); s--)
2825
2899
  ;
2826
- (o < 0 || o < n.length - 65557) && t(), (r(o + 4) || r(o + 6) || r(o + 8) !== r(o + 10)) && t();
2827
- const i = r(o + 10), f = a(o + 16), m = f + a(o + 12);
2828
- m !== o && t();
2829
- const g = [], p = /* @__PURE__ */ new Set();
2830
- let l = f;
2831
- for (let h = 0; h < i; h++) {
2832
- (l + 46 > m || a(l) !== 33639248) && t();
2833
- const E = r(l + 28), y = l + 46 + E + r(l + 30) + r(l + 32);
2834
- y > m && t();
2835
- let u;
2900
+ (s < 0 || s < n.length - 65557) && t(), (r(s + 4) || r(s + 6) || r(s + 8) !== r(s + 10)) && t();
2901
+ const l = r(s + 10), f = a(s + 16), y = f + a(s + 12);
2902
+ y !== s && t();
2903
+ const d = [], m = /* @__PURE__ */ new Set();
2904
+ let c = f;
2905
+ for (let p = 0; p < l; p++) {
2906
+ (c + 46 > y || a(c) !== 33639248) && t();
2907
+ const b = r(c + 28), v = c + 46 + b + r(c + 30) + r(c + 32);
2908
+ v > y && t();
2909
+ let h;
2836
2910
  try {
2837
- u = bt.decode(n.subarray(l + 46, l + 46 + E));
2911
+ h = At.decode(n.subarray(c + 46, c + 46 + b));
2838
2912
  } catch {
2839
2913
  throw new Error("ZIP entry (invalid UTF-8 name): invalid filename");
2840
2914
  }
2841
- if (Rt(u), h >= Je) throw new Error(`ZIP entry ${JSON.stringify(u)}: more than ${Je} entries`);
2842
- if (p.has(u)) throw new Error(`ZIP entry ${JSON.stringify(u)}: duplicate entry`);
2843
- p.add(u);
2844
- const v = a(l + 24), x = a(l + 20), s = a(l + 42);
2845
- if (v > vt || x > vt) throw new Error(`ZIP entry ${JSON.stringify(u)}: exceeds 64 MB`);
2846
- if (r(l + 10) !== 0) throw new Error(`ZIP entry ${JSON.stringify(u)}: expected stored compression (method 0)`);
2847
- if (r(l + 8) & 1) throw new Error(`ZIP entry ${JSON.stringify(u)}: encrypted entries are not supported`);
2848
- (x !== v || s + 30 > f || a(s) !== 67324752) && t(u);
2849
- const c = s + 30 + r(s + 26) + r(s + 28);
2850
- (c + v > f || r(s + 8) !== 0 || r(s + 6) !== r(l + 8)) && t(u);
2851
- let T;
2915
+ if (kt(h), p >= Qe) throw new Error(`ZIP entry ${JSON.stringify(h)}: more than ${Qe} entries`);
2916
+ if (m.has(h)) throw new Error(`ZIP entry ${JSON.stringify(h)}: duplicate entry`);
2917
+ m.add(h);
2918
+ const u = a(c + 24), w = a(c + 20), o = a(c + 42);
2919
+ if (u > wt || w > wt) throw new Error(`ZIP entry ${JSON.stringify(h)}: exceeds 64 MB`);
2920
+ if (r(c + 10) !== 0) throw new Error(`ZIP entry ${JSON.stringify(h)}: expected stored compression (method 0)`);
2921
+ if (r(c + 8) & 1) throw new Error(`ZIP entry ${JSON.stringify(h)}: encrypted entries are not supported`);
2922
+ (w !== u || o + 30 > f || a(o) !== 67324752) && t(h);
2923
+ const i = o + 30 + r(o + 26) + r(o + 28);
2924
+ (i + u > f || r(o + 8) !== 0 || r(o + 6) !== r(c + 8)) && t(h);
2925
+ let S;
2852
2926
  try {
2853
- T = bt.decode(n.subarray(s + 30, s + 30 + r(s + 26)));
2927
+ S = At.decode(n.subarray(o + 30, o + 30 + r(o + 26)));
2854
2928
  } catch {
2855
- t(u);
2929
+ t(h);
2856
2930
  }
2857
- T !== u && t(u), g.push({ name: u, offset: s, start: c, size: v, central: l }), l = y;
2931
+ S !== h && t(h), d.push({ name: h, offset: o, start: i, size: u, central: c }), c = v;
2858
2932
  }
2859
- return l !== m && t(), { files: g };
2933
+ return c !== y && t(), { files: d };
2860
2934
  }
2861
- function Or(n) {
2862
- const e = n instanceof Uint8Array ? n : new Uint8Array(n), t = xt(e), r = Tr(e, { filter: (o) => o.name !== "__proto__" }), a = /* @__PURE__ */ Object.create(null);
2863
- for (const o of t.files) {
2864
- const i = o.name === "__proto__" ? e.slice(o.start, o.start + o.size) : r[o.name];
2865
- if (!(i instanceof Uint8Array) || i.length !== o.size) throw new Error(`ZIP entry ${JSON.stringify(o.name)}: invalid size`);
2866
- a[o.name] = i;
2935
+ function kr(n) {
2936
+ const e = n instanceof Uint8Array ? n : new Uint8Array(n), t = Mt(e), r = _r(e, { filter: (s) => s.name !== "__proto__" }), a = /* @__PURE__ */ Object.create(null);
2937
+ for (const s of t.files) {
2938
+ const l = s.name === "__proto__" ? e.slice(s.start, s.start + s.size) : r[s.name];
2939
+ if (!(l instanceof Uint8Array) || l.length !== s.size) throw new Error(`ZIP entry ${JSON.stringify(s.name)}: invalid size`);
2940
+ a[s.name] = l;
2867
2941
  }
2868
2942
  return a;
2869
2943
  }
2870
- function Fr(n, e = {}) {
2871
- const t = Object.hasOwn(n, "avatar.json") ? n["avatar.json"] : void 0, r = t ? Be(JSON.parse(bt.decode(t))) : rn("Avatar"), a = t && !e.manifest ? t : new TextEncoder().encode(JSON.stringify(Be({ ...r, ...e.manifest }), null, 2) + `
2872
- `), o = /* @__PURE__ */ Object.create(null);
2873
- o["avatar.json"] = a;
2874
- for (const [h, E] of Object.entries(n)) h !== "avatar.json" && (o[h] = E);
2875
- for (const [h, [E, y]] of Object.entries(o).entries()) {
2876
- if (Rt(E), h >= Je) throw new Error(`ZIP entry ${JSON.stringify(E)}: more than ${Je} entries`);
2877
- if (y.byteLength > vt) throw new Error(`ZIP entry ${JSON.stringify(E)}: exceeds 64 MB`);
2878
- }
2879
- const i = an(o);
2880
- if (i.length) throw new Error(i.join(`
2944
+ function jr(n, e = {}) {
2945
+ const t = Object.hasOwn(n, "avatar.json") ? n["avatar.json"] : void 0, r = t ? Ye(JSON.parse(At.decode(t))) : an("Avatar"), a = t && !e.manifest ? t : new TextEncoder().encode(JSON.stringify(Ye({ ...r, ...e.manifest }), null, 2) + `
2946
+ `), s = /* @__PURE__ */ Object.create(null);
2947
+ s["avatar.json"] = a;
2948
+ for (const [p, b] of Object.entries(n)) p !== "avatar.json" && (s[p] = b);
2949
+ for (const [p, [b, v]] of Object.entries(s).entries()) {
2950
+ if (kt(b), p >= Qe) throw new Error(`ZIP entry ${JSON.stringify(b)}: more than ${Qe} entries`);
2951
+ if (v.byteLength > wt) throw new Error(`ZIP entry ${JSON.stringify(b)}: exceeds 64 MB`);
2952
+ }
2953
+ const l = on(s);
2954
+ if (l.length) throw new Error(l.join(`
2881
2955
  `));
2882
2956
  let f = "proto0000";
2883
- for (let h = 0; Object.hasOwn(o, f); h++) f = `proto${String(h + 1).padStart(4, "0")}`;
2884
- const m = Object.fromEntries(Object.entries(o).map(([h, E]) => [h === "__proto__" ? f : h, E])), g = Sr(m, { level: 0 });
2885
- if (Object.hasOwn(o, "__proto__")) {
2886
- const h = xt(g).files.find((y) => y.name === f), E = new TextEncoder().encode("__proto__");
2887
- g.set(E, h.offset + 30), g.set(E, h.central + 46);
2888
- }
2889
- const p = xt(g), l = p.files.find((h) => h.name === "avatar.json");
2890
- if (l.offset !== 0) {
2891
- const h = l.start + l.size - l.offset, E = new Uint8Array(g.length);
2892
- E.set(g.subarray(l.offset, l.offset + h)), E.set(g.subarray(0, l.offset), h), E.set(g.subarray(l.offset + h), l.offset + h);
2893
- const y = new DataView(E.buffer);
2894
- for (const u of p.files) y.setUint32(u.central + 42, u === l ? 0 : u.offset < l.offset ? u.offset + h : u.offset, !0);
2895
- return E;
2896
- }
2897
- return g;
2957
+ for (let p = 0; Object.hasOwn(s, f); p++) f = `proto${String(p + 1).padStart(4, "0")}`;
2958
+ const y = Object.fromEntries(Object.entries(s).map(([p, b]) => [p === "__proto__" ? f : p, b])), d = Lr(y, { level: 0 });
2959
+ if (Object.hasOwn(s, "__proto__")) {
2960
+ const p = Mt(d).files.find((v) => v.name === f), b = new TextEncoder().encode("__proto__");
2961
+ d.set(b, p.offset + 30), d.set(b, p.central + 46);
2962
+ }
2963
+ const m = Mt(d), c = m.files.find((p) => p.name === "avatar.json");
2964
+ if (c.offset !== 0) {
2965
+ const p = c.start + c.size - c.offset, b = new Uint8Array(d.length);
2966
+ b.set(d.subarray(c.offset, c.offset + p)), b.set(d.subarray(0, c.offset), p), b.set(d.subarray(c.offset + p), c.offset + p);
2967
+ const v = new DataView(b.buffer);
2968
+ for (const h of m.files) v.setUint32(h.central + 42, h === c ? 0 : h.offset < c.offset ? h.offset + p : h.offset, !0);
2969
+ return b;
2970
+ }
2971
+ return d;
2898
2972
  }
2899
- const Rr = (n) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(n));
2900
- function Ce(n, e) {
2973
+ const Fr = (n) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(n));
2974
+ function Be(n, e) {
2901
2975
  try {
2902
- return Rr(n);
2976
+ return Fr(n);
2903
2977
  } catch {
2904
2978
  throw new Error(`${e}: invalid UTF-8 JSON`);
2905
2979
  }
2906
2980
  }
2907
- function pn(n, e) {
2981
+ function dn(n, e, t) {
2908
2982
  return [
2909
2983
  "layers.json",
2910
2984
  "base.png",
2911
2985
  "hairmask.png",
2912
- ...Object.keys(n?.layers ?? {}).map((t) => `${t}.png`),
2913
- ...e ? ["sprites/sprites.json", ...Object.keys(e.layers ?? {}).map((t) => `sprites/${t}.png`)] : []
2986
+ ...Object.keys(n?.layers ?? {}).map((r) => `${r}.png`),
2987
+ ...e ? ["sprites/sprites.json", ...Object.keys(e.layers ?? {}).map((r) => `sprites/${r}.png`)] : [],
2988
+ // malformed entries are left to validateAvatarFiles, which reports them
2989
+ ...t ? ["overlays/overlays.json", ...(Array.isArray(t.overlays) ? t.overlays : []).flatMap((r) => typeof r?.file == "string" ? [`overlays/${r.file}`] : [])] : []
2914
2990
  ];
2915
2991
  }
2916
- function dn(n) {
2917
- const e = an(n);
2992
+ function gn(n) {
2993
+ const e = on(n);
2918
2994
  if (e.length) throw new Error(e.join(`
2919
2995
  `));
2920
2996
  }
2921
- function gn(n) {
2997
+ function yn(n) {
2922
2998
  return !!n && typeof n == "object" && "manifest" in n && "rig" in n && "assets" in n && "release" in n;
2923
2999
  }
2924
- function ut(n) {
2925
- const e = Or(n);
3000
+ function pt(n) {
3001
+ const e = kr(n);
2926
3002
  if (!Object.hasOwn(e, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
2927
- dn(e);
2928
- const t = Be(Ce(e["avatar.json"], "avatar.json")), r = wt(Ce(e["rig.json"], "rig.json")), a = pn(
2929
- Ce(e["built/layers.json"], "built/layers.json"),
2930
- e["built/sprites/sprites.json"] ? Ce(e["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0
2931
- ), o = {}, i = [], f = () => {
2932
- i.splice(0).forEach((m) => URL.revokeObjectURL(m));
3003
+ gn(e);
3004
+ const t = Ye(Be(e["avatar.json"], "avatar.json")), r = Et(Be(e["rig.json"], "rig.json")), a = e["built/overlays/overlays.json"] ? Be(e["built/overlays/overlays.json"], "built/overlays/overlays.json") : void 0, s = dn(
3005
+ Be(e["built/layers.json"], "built/layers.json"),
3006
+ e["built/sprites/sprites.json"] ? Be(e["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0,
3007
+ a
3008
+ ), l = {}, f = [], y = () => {
3009
+ f.splice(0).forEach((d) => URL.revokeObjectURL(d));
2933
3010
  };
2934
3011
  try {
2935
- for (const m of new Set(a)) {
2936
- const g = URL.createObjectURL(new Blob([new Uint8Array(e[`built/${m}`])], { type: m.endsWith(".json") ? "application/json" : "image/png" }));
2937
- i.push(g), o[m] = g;
3012
+ for (const d of new Set(s)) {
3013
+ const m = URL.createObjectURL(new Blob([new Uint8Array(e[`built/${d}`])], { type: d.endsWith(".json") ? "application/json" : "image/png" }));
3014
+ f.push(m), l[d] = m;
2938
3015
  }
2939
- } catch (m) {
2940
- throw f(), m;
3016
+ } catch (d) {
3017
+ throw y(), d;
2941
3018
  }
2942
- return { manifest: t, rig: r, assets: o, release: f };
3019
+ return { manifest: t, rig: r, assets: l, release: y };
2943
3020
  }
2944
- async function Lr(n, e = {}) {
2945
- if (gn(n)) return n;
2946
- if (n instanceof Blob) return ut(await n.arrayBuffer());
2947
- if (n instanceof ArrayBuffer || n instanceof Uint8Array) return ut(n);
3021
+ async function Br(n, e = {}) {
3022
+ if (yn(n)) return n;
3023
+ if (n instanceof Blob) return pt(await n.arrayBuffer());
3024
+ if (n instanceof ArrayBuffer || n instanceof Uint8Array) return pt(n);
2948
3025
  const t = new URL(n, typeof location > "u" ? void 0 : location.href);
2949
3026
  if (/\.mavatar$/i.test(t.pathname)) {
2950
3027
  const u = await fetch(t);
2951
3028
  if (!u.ok) throw new Error(`.mavatar: could not load (${u.status})`);
2952
- return ut(await u.arrayBuffer());
3029
+ return pt(await u.arrayBuffer());
2953
3030
  }
2954
3031
  t.pathname.endsWith("/") || (t.pathname += "/");
2955
3032
  const r = (u) => {
2956
- const v = new URL(t);
2957
- return v.pathname += u.split("/").map(encodeURIComponent).join("/"), e.version !== void 0 && v.searchParams.set("v", String(e.version)), v.href;
3033
+ const w = new URL(t);
3034
+ return w.pathname += u.split("/").map(encodeURIComponent).join("/"), e.version !== void 0 && w.searchParams.set("v", String(e.version)), w.href;
2958
3035
  }, a = {};
2959
- async function o(u, v = !1) {
2960
- const x = await fetch(r(u));
2961
- if (v && (x.status === 404 || x.ok && x.headers.get("content-type")?.includes("text/html"))) return;
2962
- if (!x.ok) throw new Error(`${u}: could not load (${x.status})`);
2963
- const s = new Uint8Array(await x.arrayBuffer());
2964
- return a[u] = s, Ce(s, u);
2965
- }
2966
- const i = e.rigFile ?? "rig.json";
2967
- Rt(i);
2968
- const [f, m, g, p] = await Promise.all([
2969
- o(i),
2970
- o("built/layers.json"),
2971
- o("avatar.json", !0),
2972
- o("built/sprites/sprites.json", !0)
3036
+ async function s(u, w = !1) {
3037
+ const o = await fetch(r(u));
3038
+ if (w && (o.status === 404 || o.ok && o.headers.get("content-type")?.includes("text/html"))) return;
3039
+ if (!o.ok) throw new Error(`${u}: could not load (${o.status})`);
3040
+ const i = new Uint8Array(await o.arrayBuffer());
3041
+ return a[u] = i, Be(i, u);
3042
+ }
3043
+ const l = e.rigFile ?? "rig.json";
3044
+ kt(l);
3045
+ const [f, y, d, m, c] = await Promise.all([
3046
+ s(l),
3047
+ s("built/layers.json"),
3048
+ s("avatar.json", !0),
3049
+ s("built/sprites/sprites.json", !0),
3050
+ s("built/overlays/overlays.json", !0)
2973
3051
  ]);
2974
- Array.isArray(f?.eyes) && Array.isArray(m?.eyes) && (f.eyes = f.eyes.map((u, v) => {
3052
+ Array.isArray(f?.eyes) && Array.isArray(y?.eyes) && (f.eyes = f.eyes.map((u, w) => {
2975
3053
  if (!u || typeof u != "object") return u;
2976
- const x = { ...u };
2977
- for (const s of ["x0", "x1", "top", "bot"]) x[s] === void 0 && (x[s] = m.eyes[v]?.[s]);
2978
- return x;
3054
+ const o = { ...u };
3055
+ for (const i of ["x0", "x1", "top", "bot"]) o[i] === void 0 && (o[i] = y.eyes[w]?.[i]);
3056
+ return o;
2979
3057
  })), a["rig.json"] = new TextEncoder().encode(JSON.stringify(f));
2980
- const l = pn(m, p);
2981
- for (const u of l) u.endsWith(".png") && (a[`built/${u}`] = { size: 1 });
2982
- dn(a);
2983
- const h = wt(f), E = Object.fromEntries(l.map((u) => [u, r(`built/${u}`)])), y = decodeURIComponent(t.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
2984
- return { manifest: g === void 0 ? rn(y) : Be(g), rig: h, assets: E, release() {
3058
+ const p = dn(y, m, c);
3059
+ for (const u of p) u.endsWith(".png") && (a[`built/${u}`] = { size: 1 });
3060
+ gn(a);
3061
+ const b = Et(f), v = Object.fromEntries(p.map((u) => [u, r(`built/${u}`)])), h = decodeURIComponent(t.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
3062
+ return { manifest: d === void 0 ? an(h) : Ye(d), rig: b, assets: v, release() {
2985
3063
  } };
2986
3064
  }
2987
- async function Br(n, e, t = {}) {
2988
- const r = !gn(e), a = await Lr(e);
3065
+ async function Ir(n, e, t = {}) {
3066
+ const r = !yn(e), a = await Br(e);
2989
3067
  try {
2990
- const o = t.lipSync === void 0 ? a.manifest.lipSync : { ...a.manifest.lipSync, ...At(t.lipSync) }, i = await rr(n, { ...t, ...o === void 0 ? {} : { lipSync: o }, rig: a.rig, assets: a.assets }), f = i.destroy.bind(i);
2991
- let m = !1;
2992
- return Object.assign(i, { package: a, destroy() {
2993
- if (!m) {
2994
- m = !0;
3068
+ const s = t.lipSync === void 0 ? a.manifest.lipSync : { ...a.manifest.lipSync, ...St(t.lipSync) }, l = await ir(n, { ...t, ...s === void 0 ? {} : { lipSync: s }, rig: a.rig, assets: a.assets }), f = l.destroy.bind(l);
3069
+ let y = !1;
3070
+ return Object.assign(l, { package: a, destroy() {
3071
+ if (!y) {
3072
+ y = !0;
2995
3073
  try {
2996
3074
  f();
2997
3075
  } finally {
@@ -2999,23 +3077,23 @@ async function Br(n, e, t = {}) {
2999
3077
  }
3000
3078
  }
3001
3079
  } });
3002
- } catch (o) {
3003
- throw r && a.release(), o;
3080
+ } catch (s) {
3081
+ throw r && a.release(), s;
3004
3082
  }
3005
3083
  }
3006
3084
  export {
3007
- Fe as DEFAULT_LIGHTING,
3008
- kr as LIVE_EXPRESSIONS,
3009
- We as PARAMS,
3010
- _r as colorHex,
3011
- rr as createMeshAvatar,
3012
- Br as loadMeshAvatar,
3013
- Lr as openAvatar,
3014
- Fr as packAvatar,
3015
- Tn as parseLighting,
3016
- Be as parseManifest,
3017
- wt as parseRig,
3018
- Or as unpackAvatar,
3019
- an as validateAvatarFiles,
3020
- Qt as validateRig
3085
+ Ue as DEFAULT_LIGHTING,
3086
+ Yr as LIVE_EXPRESSIONS,
3087
+ Ge as PARAMS,
3088
+ Ur as colorHex,
3089
+ ir as createMeshAvatar,
3090
+ Ir as loadMeshAvatar,
3091
+ Br as openAvatar,
3092
+ jr as packAvatar,
3093
+ On as parseLighting,
3094
+ Ye as parseManifest,
3095
+ Et as parseRig,
3096
+ kr as unpackAvatar,
3097
+ on as validateAvatarFiles,
3098
+ en as validateRig
3021
3099
  };