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