mesh-avatar 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -21,87 +21,87 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
21
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  SOFTWARE.
23
23
  */
24
- function qe(t, e) {
24
+ function qe(e, t) {
25
25
  const n = [0];
26
- for (let i = 1; i < t.length; i++) n.push(n.at(-1) + Math.hypot(t[i][0] - t[i - 1][0], t[i][1] - t[i - 1][1]));
27
- const r = Math.max(0, Math.min(1, e)) * n.at(-1);
26
+ for (let i = 1; i < e.length; i++) n.push(n.at(-1) + Math.hypot(e[i][0] - e[i - 1][0], e[i][1] - e[i - 1][1]));
27
+ const r = Math.max(0, Math.min(1, t)) * n.at(-1);
28
28
  let o = 1;
29
- for (; o < t.length - 1 && n[o] < r; ) o++;
30
- const a = (r - n[o - 1]) / Math.max(1e-9, n[o] - n[o - 1]);
31
- return t[o - 1].map((i, u) => i + (t[o][u] - i) * a);
29
+ for (; o < e.length - 1 && n[o] < r; ) o++;
30
+ const s = (r - n[o - 1]) / Math.max(1e-9, n[o] - n[o - 1]);
31
+ return e[o - 1].map((i, u) => i + (e[o][u] - i) * s);
32
32
  }
33
- const Dt = (t) => t.slice(1).reduce((e, n, r) => e + Math.hypot(n[0] - t[r][0], n[1] - t[r][1]), 0);
34
- function Wn(t, e) {
33
+ const Pt = (e) => e.slice(1).reduce((t, n, r) => t + Math.hypot(n[0] - e[r][0], n[1] - e[r][1]), 0);
34
+ function qn(e, t) {
35
35
  let n = 0;
36
- const r = Dt(t), o = [];
37
- for (let i = 1; i < t.length; i++) {
38
- const u = t[i - 1], y = t[i], v = y[0] - u[0], m = y[1] - u[1], l = Math.hypot(v, m);
39
- for (let c = 1; c < e.length; c++) {
40
- const f = e[c - 1], h = e[c], p = h[0] - f[0], g = h[1] - f[1], b = v * g - m * p;
36
+ const r = Pt(e), o = [];
37
+ for (let i = 1; i < e.length; i++) {
38
+ const u = e[i - 1], y = e[i], v = y[0] - u[0], m = y[1] - u[1], l = Math.hypot(v, m);
39
+ for (let c = 1; c < t.length; c++) {
40
+ const f = t[c - 1], h = t[c], p = h[0] - f[0], g = h[1] - f[1], b = v * g - m * p;
41
41
  if (Math.abs(b) < 1e-9) continue;
42
- const s = ((f[0] - u[0]) * g - (f[1] - u[1]) * p) / b, d = ((f[0] - u[0]) * m - (f[1] - u[1]) * v) / b;
43
- s >= -1e-8 && s <= 1 + 1e-8 && d >= -1e-8 && d <= 1 + 1e-8 && o.push((n + s * l) / r);
42
+ const a = ((f[0] - u[0]) * g - (f[1] - u[1]) * p) / b, d = ((f[0] - u[0]) * m - (f[1] - u[1]) * v) / b;
43
+ a >= -1e-8 && a <= 1 + 1e-8 && d >= -1e-8 && d <= 1 + 1e-8 && o.push((n + a * l) / r);
44
44
  }
45
45
  n += l;
46
46
  }
47
- const a = o.filter((i, u) => o.findIndex((y) => Math.abs(i - y) < 1e-7) === u);
48
- if (a.length !== 1) throw new RangeError("Each tier must cross every column exactly once");
49
- return a[0];
47
+ const s = o.filter((i, u) => o.findIndex((y) => Math.abs(i - y) < 1e-7) === u);
48
+ if (s.length !== 1) throw new RangeError("Each tier must cross every column exactly once");
49
+ return s[0];
50
50
  }
51
- function Tn(t) {
52
- const e = !!(t.seams?.length || t.tiers?.length), n = t.seams?.length || (t.columns ?? 8), r = t.seams?.length ? t.seams : Array.from({ length: n }, (m, l) => [qe(t.waist, l / (n - 1)), qe(t.hem, l / (n - 1))]);
53
- if (e && r.some((m) => Dt(m) < 1)) throw new RangeError("Columns must have nonzero source length");
54
- const o = r.map((m) => [0, ...t.tiers?.length ? t.tiers.map((l) => Wn(m, l)) : [0.5], 1]);
51
+ function kn(e) {
52
+ const t = !!(e.seams?.length || e.tiers?.length), n = e.seams?.length || (e.columns ?? 8), r = e.seams?.length ? e.seams : Array.from({ length: n }, (m, l) => [qe(e.waist, l / (n - 1)), qe(e.hem, l / (n - 1))]);
53
+ if (t && r.some((m) => Pt(m) < 1)) throw new RangeError("Columns must have nonzero source length");
54
+ const o = r.map((m) => [0, ...e.tiers?.length ? e.tiers.map((l) => qn(m, l)) : [0.5], 1]);
55
55
  for (const m of o) if (m.some((l, c) => c > 0 && l - m[c - 1] < 1e-3)) throw new RangeError("Tier intersections must be ordered from waist to hem, with nonzero links");
56
- const a = o[0].length - 1, i = e ? Math.max(2, Math.ceil(((t.rows ?? 5) - 1) / a)) : 0, u = e ? a * i + 1 : t.rows ?? 5, y = new Float64Array(u * n * 2), v = [];
56
+ const s = o[0].length - 1, i = t ? Math.max(2, Math.ceil(((e.rows ?? 5) - 1) / s)) : 0, u = t ? s * i + 1 : e.rows ?? 5, y = new Float64Array(u * n * 2), v = [];
57
57
  for (let m = 0; m < n; m++) {
58
58
  v[m] = [];
59
59
  for (let l = 0; l < u; l++) {
60
- const c = e ? Math.min(a - 1, Math.floor(l / i)) : 0, f = e ? (l - c * i) / i : l / (u - 1), h = e ? o[m][c] + (o[m][c + 1] - o[m][c]) * f : f;
60
+ const c = t ? Math.min(s - 1, Math.floor(l / i)) : 0, f = t ? (l - c * i) / i : l / (u - 1), h = t ? o[m][c] + (o[m][c + 1] - o[m][c]) * f : f;
61
61
  v[m].push(h), y.set(qe(r[m], h), (l * n + m) * 2);
62
62
  }
63
63
  }
64
- if (e) for (let m = 0; m < u - 1; m++) for (let l = 0; l < n - 1; l++) {
65
- const c = (m * n + l) * 2, f = c + 2, h = c + n * 2, p = h + 2, g = (b, s, d) => (y[s] - y[b]) * (y[d + 1] - y[b + 1]) - (y[s + 1] - y[b + 1]) * (y[d] - y[b]);
64
+ if (t) for (let m = 0; m < u - 1; m++) for (let l = 0; l < n - 1; l++) {
65
+ const c = (m * n + l) * 2, f = c + 2, h = c + n * 2, p = h + 2, g = (b, a, d) => (y[a] - y[b]) * (y[d + 1] - y[b + 1]) - (y[a + 1] - y[b + 1]) * (y[d] - y[b]);
66
66
  if (g(c, f, p) <= 1e-6 || g(c, p, h) <= 1e-6) throw new RangeError("Columns must be ordered left to right without crossing");
67
67
  }
68
- return { custom: e, cols: n, rows: u, rest: y, seams: r, joints: o, fractions: v, lengths: r.map(Dt), top: r.map((m) => m[0]) };
69
- }
70
- const le = (t, e, n) => {
71
- (typeof t != "number" || !Number.isFinite(t)) && n.push(`${e}: expected a finite number`);
72
- }, we = (t, e, n) => {
73
- le(t, e, n), typeof t == "number" && t <= 0 && n.push(`${e}: must be positive`);
74
- }, De = (t, e, n) => {
75
- le(t, e, n), typeof t == "number" && t < 0 && n.push(`${e}: must be nonnegative`);
76
- }, Gn = (t, e, n) => {
77
- De(t, e, n), typeof t == "number" && (!Number.isInteger(t) || t > 8) && n.push(`${e}: expected an integer from 0 to 8`);
78
- }, _e = (t, e, n) => {
79
- we(t, e, n), typeof t == "number" && !Number.isInteger(t) && n.push(`${e}: expected an integer`);
80
- }, ot = (t, e, n) => {
81
- le(t, e, n), typeof t == "number" && !Number.isInteger(t) && n.push(`${e}: expected an integer`);
82
- }, yt = (t, e, n) => {
83
- (typeof t != "string" || !t.trim()) && n.push(`${e}: expected a non-empty string`);
84
- }, Oe = (t, e = 0, n = 1 / 0) => (r, o, a) => {
68
+ return { custom: t, cols: n, rows: u, rest: y, seams: r, joints: o, fractions: v, lengths: r.map(Pt), top: r.map((m) => m[0]) };
69
+ }
70
+ const le = (e, t, n) => {
71
+ (typeof e != "number" || !Number.isFinite(e)) && n.push(`${t}: expected a finite number`);
72
+ }, we = (e, t, n) => {
73
+ le(e, t, n), typeof e == "number" && e <= 0 && n.push(`${t}: must be positive`);
74
+ }, De = (e, t, n) => {
75
+ le(e, t, n), typeof e == "number" && e < 0 && n.push(`${t}: must be nonnegative`);
76
+ }, Jn = (e, t, n) => {
77
+ De(e, t, n), typeof e == "number" && (!Number.isInteger(e) || e > 8) && n.push(`${t}: expected an integer from 0 to 8`);
78
+ }, _e = (e, t, n) => {
79
+ we(e, t, n), typeof e == "number" && !Number.isInteger(e) && n.push(`${t}: expected an integer`);
80
+ }, ot = (e, t, n) => {
81
+ le(e, t, n), typeof e == "number" && !Number.isInteger(e) && n.push(`${t}: expected an integer`);
82
+ }, yt = (e, t, n) => {
83
+ (typeof e != "string" || !e.trim()) && n.push(`${t}: expected a non-empty string`);
84
+ }, Oe = (e, t = 0, n = 1 / 0) => (r, o, s) => {
85
85
  if (!Array.isArray(r)) {
86
- a.push(`${o}: expected an array`);
86
+ s.push(`${o}: expected an array`);
87
87
  return;
88
88
  }
89
- (r.length < e || r.length > n) && a.push(`${o}: expected ${e}..${n} items`), r.forEach((i, u) => t(i, `${o}[${u}]`, a));
90
- }, me = Oe(le, 2, 2), Ae = (t, e, n) => {
91
- me(t, e, n), Array.isArray(t) && t.length === 2 && t[0] >= t[1] && n.push(`${e}: start must be less than end`);
92
- }, he = (t, e = []) => (n, r, o) => {
89
+ (r.length < t || r.length > n) && s.push(`${o}: expected ${t}..${n} items`), r.forEach((i, u) => e(i, `${o}[${u}]`, s));
90
+ }, me = Oe(le, 2, 2), Ae = (e, t, n) => {
91
+ me(e, t, n), Array.isArray(e) && e.length === 2 && e[0] >= e[1] && n.push(`${t}: start must be less than end`);
92
+ }, he = (e, t = []) => (n, r, o) => {
93
93
  if (!n || typeof n != "object" || Array.isArray(n)) {
94
94
  o.push(`${r}: expected an object`);
95
95
  return;
96
96
  }
97
- const a = n;
98
- for (const [i, u] of Object.entries(t))
99
- a[i] === void 0 && e.includes(i) || u(a[i], `${r}.${i}`, o);
100
- }, ft = { cx: le, cy: le, rx: we, ry: we }, Ue = he(ft), at = Oe(me, 3), Xe = Oe(me, 2), Je = (t, e, n) => {
101
- le(t, e, n), typeof t == "number" && (t < 0 || t > 1) && n.push(`${e}: must be between 0 and 1`);
102
- }, qn = (t) => he({
103
- version: (e, n, r) => {
104
- e !== 1 && r.push(`${n}: only version 1 is supported`);
97
+ const s = n;
98
+ for (const [i, u] of Object.entries(e))
99
+ s[i] === void 0 && t.includes(i) || u(s[i], `${r}.${i}`, o);
100
+ }, ft = { cx: le, cy: le, rx: we, ry: we }, Ue = he(ft), st = Oe(me, 3), Xe = Oe(me, 2), Je = (e, t, n) => {
101
+ le(e, t, n), typeof e == "number" && (e < 0 || e > 1) && n.push(`${t}: must be between 0 and 1`);
102
+ }, Kn = (e) => he({
103
+ version: (t, n, r) => {
104
+ t !== 1 && r.push(`${n}: only version 1 is supported`);
105
105
  },
106
106
  image: he({ width: _e, height: _e }),
107
107
  head: he({
@@ -136,13 +136,13 @@ const le = (t, e, n) => {
136
136
  }),
137
137
  buns: he({ bunL: Ue, bunR: Ue }, ["bunL", "bunR"]),
138
138
  eyes: Oe(he({
139
- opening: at,
140
- roi: at,
139
+ opening: st,
140
+ roi: st,
141
141
  x0: le,
142
142
  x1: le,
143
143
  top: Oe(le, 24, 24),
144
144
  bot: Oe(le, 24, 24)
145
- }, t ? ["x0", "x1", "top", "bot"] : []), 2, 2),
145
+ }, e ? ["x0", "x1", "top", "bot"] : []), 2, 2),
146
146
  mouth: he({
147
147
  cx: le,
148
148
  cy: le,
@@ -162,10 +162,10 @@ const le = (t, e, n) => {
162
162
  color: he({ redness: Je, minRed: le })
163
163
  })),
164
164
  hand: he({
165
- outline: at,
165
+ outline: st,
166
166
  jaw: Xe,
167
167
  jawRange: Ae,
168
- background: at,
168
+ background: st,
169
169
  elbow: me,
170
170
  wrist: me,
171
171
  knuckle: me,
@@ -180,7 +180,7 @@ const le = (t, e, n) => {
180
180
  }),
181
181
  cloth: Oe(he({
182
182
  name: yt,
183
- outline: at,
183
+ outline: st,
184
184
  waist: Xe,
185
185
  hem: Xe,
186
186
  columns: _e,
@@ -193,10 +193,10 @@ const le = (t, e, n) => {
193
193
  responseGain: we,
194
194
  swing: we,
195
195
  follow: Je,
196
- cohesion: Gn,
196
+ cohesion: Jn,
197
197
  wind: De,
198
- behind: (e, n, r) => {
199
- typeof e != "boolean" && r.push(`${n}: expected a boolean`);
198
+ behind: (t, n, r) => {
199
+ typeof t != "boolean" && r.push(`${n}: expected a boolean`);
200
200
  },
201
201
  parent: yt,
202
202
  scale: we,
@@ -241,38 +241,38 @@ const le = (t, e, n) => {
241
241
  }, ["clothCell"]),
242
242
  view: he({ padTop: le, padSide: le, gazeCenter: me, irisTravel: we }, ["gazeCenter", "irisTravel"])
243
243
  }, ["buns", "strands", "accessories", "hand", "cloth", "legs", "arms"]);
244
- function Rn(t, e = {}) {
244
+ function Ln(e, t = {}) {
245
245
  const n = [];
246
- if (qn(e.draft ?? !1)(t, "rig", n), n.length) return n;
247
- const r = t;
248
- r.eyes.forEach((a, i) => {
246
+ if (Kn(t.draft ?? !1)(e, "rig", n), n.length) return n;
247
+ const r = e;
248
+ r.eyes.forEach((s, i) => {
249
249
  const u = ["x0", "x1", "top", "bot"];
250
- if (!(e.draft && u.every((y) => a[y] === void 0))) {
251
- if (u.some((y) => a[y] === void 0)) {
250
+ if (!(t.draft && u.every((y) => s[y] === void 0))) {
251
+ if (u.some((y) => s[y] === void 0)) {
252
252
  n.push(`rig.eyes[${i}]: supply all x0/x1/top/bot fields or omit all in a draft`);
253
253
  return;
254
254
  }
255
- a.x0 >= a.x1 && n.push(`rig.eyes[${i}].x1: must exceed x0`), a.top.some((y, v) => y > a.bot[v]) && n.push(`rig.eyes[${i}].top: must not exceed bottom curve`);
255
+ s.x0 >= s.x1 && n.push(`rig.eyes[${i}].x1: must exceed x0`), s.top.some((y, v) => y > s.bot[v]) && n.push(`rig.eyes[${i}].top: must not exceed bottom curve`);
256
256
  }
257
257
  }), (r.mesh.fine.x0 >= r.mesh.fine.x1 || r.mesh.fine.y0 >= r.mesh.fine.y1) && n.push("rig.mesh.fine: rectangle must have positive area"), (r.view.padTop <= -1 || r.view.padTop >= 1 || r.view.padSide <= -0.5) && n.push("rig.view: margins must leave a positive viewport");
258
- for (const [a, i] of (r.strands ?? []).entries())
259
- i.nodes.some((u, y) => y > 0 && u[0] === i.nodes[y - 1][0] && u[1] === i.nodes[y - 1][1]) && n.push(`rig.strands[${a}].nodes: consecutive nodes must differ`);
260
- for (const [a, i] of (r.accessories ?? []).entries())
261
- (i.box[0] < 0 || i.box[1] < 0 || i.box[2] > r.image.width || i.box[3] > r.image.height) && n.push(`rig.accessories[${a}].box: rectangle must stay inside the image`), (i.split <= 0 || i.split >= 1) && n.push(`rig.accessories[${a}].split: must be strictly between 0 and 1`), i.pivot.every((u, y) => u === i.tip[y]) && n.push(`rig.accessories[${a}].tip: must differ from pivot`), (i.box[0] >= i.box[2] || i.box[1] >= i.box[3]) && n.push(`rig.accessories[${a}].box: rectangle must have positive area`);
258
+ for (const [s, i] of (r.strands ?? []).entries())
259
+ i.nodes.some((u, y) => y > 0 && u[0] === i.nodes[y - 1][0] && u[1] === i.nodes[y - 1][1]) && n.push(`rig.strands[${s}].nodes: consecutive nodes must differ`);
260
+ for (const [s, i] of (r.accessories ?? []).entries())
261
+ (i.box[0] < 0 || i.box[1] < 0 || i.box[2] > r.image.width || i.box[3] > r.image.height) && n.push(`rig.accessories[${s}].box: rectangle must stay inside the image`), (i.split <= 0 || i.split >= 1) && n.push(`rig.accessories[${s}].split: must be strictly between 0 and 1`), i.pivot.every((u, y) => u === i.tip[y]) && n.push(`rig.accessories[${s}].tip: must differ from pivot`), (i.box[0] >= i.box[2] || i.box[1] >= i.box[3]) && n.push(`rig.accessories[${s}].box: rectangle must have positive area`);
262
262
  const o = /* @__PURE__ */ new Set();
263
263
  if (r.legs) {
264
264
  (r.legs.twist ?? 0) > 15 && n.push("rig.legs.twist: must be between 0 and 15 degrees");
265
- const a = r.legs;
265
+ const s = r.legs;
266
266
  for (const i of ["left", "right"]) {
267
- const u = a[i];
268
- a.band[0] < u.hip[1] && u.hip[1] < u.knee[1] && u.knee[1] < u.ankle[1] || n.push(`rig.legs.${i}: require band start < hip y < knee y < ankle y`);
267
+ const u = s[i];
268
+ s.band[0] < u.hip[1] && u.hip[1] < u.knee[1] && u.knee[1] < u.ankle[1] || n.push(`rig.legs.${i}: require band start < hip y < knee y < ankle y`);
269
269
  }
270
- a.split.some((i, u) => u > 0 && i[1] <= a.split[u - 1][1]) && n.push("rig.legs.split: y coordinates must increase");
270
+ s.split.some((i, u) => u > 0 && i[1] <= s.split[u - 1][1]) && n.push("rig.legs.split: y coordinates must increase");
271
271
  }
272
272
  if (r.arms) {
273
273
  (r.arms.swing ?? 4) > 10 && n.push("rig.arms.swing: must be between 0 and 10 degrees"), (r.arms.bend ?? 6) > 12 && n.push("rig.arms.bend: must be between 0 and 12 degrees");
274
- for (const a of ["left", "right"]) {
275
- const i = r.arms[a], u = `rig.arms.${a}`;
274
+ for (const s of ["left", "right"]) {
275
+ const i = r.arms[s], u = `rig.arms.${s}`;
276
276
  i.shoulder[1] < i.elbow[1] && i.elbow[1] < i.wrist[1] || n.push(`${u}: require shoulder y < elbow y < wrist y`);
277
277
  for (const [y, v] of Object.entries({ shoulder: [i.shoulder], elbow: [i.elbow], wrist: [i.wrist], split: i.split }))
278
278
  v.some(([m, l]) => m < 0 || l < 0 || m >= r.image.width || l >= r.image.height) && n.push(`${u}.${y}: points must stay inside the image`);
@@ -285,65 +285,65 @@ function Rn(t, e = {}) {
285
285
  const l = i.split[m], c = i.split[m + 1], f = Math.max(0, Math.min(1, (v - l[1]) / (c[1] - l[1])));
286
286
  return l[0] + (c[0] - l[0]) * f;
287
287
  };
288
- [i.elbow, i.wrist].some(([v, m]) => a === "left" ? y(m) <= v : y(m) >= v) && n.push(`${u}.split: must lie on the body side of elbow and wrist`);
288
+ [i.elbow, i.wrist].some(([v, m]) => s === "left" ? y(m) <= v : y(m) >= v) && n.push(`${u}.split: must lie on the body side of elbow and wrist`);
289
289
  }
290
290
  }
291
291
  }
292
- for (const [a, i] of (r.cloth ?? []).entries()) {
293
- if ((!/^[A-Za-z0-9_-]+$/.test(i.name) || o.has(i.name)) && n.push(`rig.cloth[${a}].name: must be a unique layer-safe name`), i.parent !== void 0 && !o.has(i.parent) && n.push(`rig.cloth[${a}].parent: must name an earlier cloth entry`), ((i.columns ?? 2) < 2 || (i.rows ?? 2) < 2) && n.push(`rig.cloth[${a}]: columns and rows must be at least 2`), i.seams?.length === 1 && n.push(`rig.cloth[${a}].seams: at least two columns required`), i.seams?.length || i.tiers?.length) {
294
- i.seams?.some((u) => u.some((y, v) => v > 0 && y[1] <= u[v - 1][1])) && n.push(`rig.cloth[${a}].seams: y must increase from waist to hem`);
292
+ for (const [s, i] of (r.cloth ?? []).entries()) {
293
+ if ((!/^[A-Za-z0-9_-]+$/.test(i.name) || o.has(i.name)) && n.push(`rig.cloth[${s}].name: must be a unique layer-safe name`), i.parent !== void 0 && !o.has(i.parent) && n.push(`rig.cloth[${s}].parent: must name an earlier cloth entry`), ((i.columns ?? 2) < 2 || (i.rows ?? 2) < 2) && n.push(`rig.cloth[${s}]: columns and rows must be at least 2`), i.seams?.length === 1 && n.push(`rig.cloth[${s}].seams: at least two columns required`), i.seams?.length || i.tiers?.length) {
294
+ i.seams?.some((u) => u.some((y, v) => v > 0 && y[1] <= u[v - 1][1])) && n.push(`rig.cloth[${s}].seams: y must increase from waist to hem`);
295
295
  try {
296
- Tn(i);
296
+ kn(i);
297
297
  } catch (u) {
298
- n.push(`rig.cloth[${a}]: ${u instanceof Error ? u.message : String(u)}`);
298
+ n.push(`rig.cloth[${s}]: ${u instanceof Error ? u.message : String(u)}`);
299
299
  }
300
300
  }
301
301
  o.add(i.name);
302
302
  }
303
303
  return n;
304
304
  }
305
- function Qt(t) {
306
- const e = Rn(t);
307
- if (e.length) throw new Error(`Invalid rig:
308
- ${e.join(`
305
+ function en(e) {
306
+ const t = Ln(e);
307
+ if (t.length) throw new Error(`Invalid rig:
308
+ ${t.join(`
309
309
  `)}`);
310
- return structuredClone(t);
310
+ return structuredClone(e);
311
311
  }
312
- const Ke = (t, e, n) => Math.max(e, Math.min(n, t)), Ye = (t, e, n) => {
313
- const r = Ke((n - t) / (e - t), 0, 1);
312
+ const Ke = (e, t, n) => Math.max(t, Math.min(n, e)), Ye = (e, t, n) => {
313
+ const r = Ke((n - e) / (t - e), 0, 1);
314
314
  return r * r * (3 - 2 * r);
315
- }, At = (t, e) => Math.hypot(t[0] - e[0], t[1] - e[1]), vt = (t, e, n) => {
316
- const r = t[0] - e[0], o = t[1] - e[1], a = Math.cos(n), i = Math.sin(n);
317
- return [e[0] + r * a - o * i, e[1] + r * i + o * a];
315
+ }, At = (e, t) => Math.hypot(e[0] - t[0], e[1] - t[1]), vt = (e, t, n) => {
316
+ const r = e[0] - t[0], o = e[1] - t[1], s = Math.cos(n), i = Math.sin(n);
317
+ return [t[0] + r * s - o * i, t[1] + r * i + o * s];
318
318
  };
319
- function ln(t, e, n, r) {
320
- const o = At(t, e), a = At(n, r), i = (e[0] - t[0]) / o, u = (e[1] - t[1]) / o, y = (r[0] - n[0]) / a, v = (r[1] - n[1]) / a, m = a / o, l = [
319
+ function cn(e, t, n, r) {
320
+ const o = At(e, t), s = At(n, r), i = (t[0] - e[0]) / o, u = (t[1] - e[1]) / o, y = (r[0] - n[0]) / s, v = (r[1] - n[1]) / s, m = s / o, l = [
321
321
  y * m * i + v * u,
322
322
  y * m * u - v * i,
323
323
  v * m * i - y * u,
324
324
  v * m * u + y * i
325
325
  ];
326
- return [...l, n[0] - l[0] * t[0] - l[1] * t[1], n[1] - l[2] * t[0] - l[3] * t[1]];
326
+ return [...l, n[0] - l[0] * e[0] - l[1] * e[1], n[1] - l[2] * e[0] - l[3] * e[1]];
327
327
  }
328
- const cn = (t, e) => [e[0] * t[0] + e[1] * t[1] + e[4], e[2] * t[0] + e[3] * t[1] + e[5]], Rt = Object.freeze({ spine: 0.7, bob: 2, twist: 0 });
329
- function Jn(t, e, n = null) {
330
- if (!t) return null;
331
- const r = [t.left, t.right].map((F, j) => {
328
+ const hn = (e, t) => [t[0] * e[0] + t[1] * e[1] + t[4], t[2] * e[0] + t[3] * e[1] + t[5]], kt = Object.freeze({ spine: 0.7, bob: 2, twist: 0 });
329
+ function Qn(e, t, n = null) {
330
+ if (!e) return null;
331
+ const r = [e.left, e.right].map((F, j) => {
332
332
  const C = At(F.hip, F.knee), B = At(F.knee, F.ankle), H = Math.min(C, B) * 0.05, N = Math.hypot(C, H), ne = Math.hypot(B, H), Q = F.ankle[0] - F.hip[0], J = F.ankle[1] - F.hip[1], X = Q * (F.knee[1] - F.hip[1]) - J * (F.knee[0] - F.hip[0]);
333
333
  return { ...F, u: N, v: ne, depth: H, lateral: X / Math.hypot(Q, J), side: Math.sign(X) || (j ? 1 : -1) };
334
- }), o = (t.twist ?? 0) > 0, a = (t.twist ?? 0) * Math.PI / 180, i = Math.max(1, ...r.map((F) => Math.abs(F.hip[0] - t.pelvis[0]) * 1.35)), u = Math.max(e.chest.rx, ...e.shoulders.map((F) => Math.abs(F.cx - e.chest.cx) + F.rx)), y = [0, 0], v = [0, 0];
334
+ }), o = (e.twist ?? 0) > 0, s = (e.twist ?? 0) * Math.PI / 180, i = Math.max(1, ...r.map((F) => Math.abs(F.hip[0] - e.pelvis[0]) * 1.35)), u = Math.max(t.chest.rx, ...t.shoulders.map((F) => Math.abs(F.cx - t.chest.cx) + F.rx)), y = [0, 0], v = [0, 0];
335
335
  let m = 0;
336
336
  const l = (F, j, C, B) => {
337
337
  const H = F - j, N = Math.max(0, 1 - (H / C) ** 2);
338
338
  return H * (Math.cos(B) - 1) + C * 0.75 * N * N * Math.sin(B);
339
339
  }, c = [0, 0, 0], f = [0, 0, 0];
340
- let h = 0, p = 0, g = 0, b = 0, s;
340
+ let h = 0, p = 0, g = 0, b = 0, a;
341
341
  function d(F, j) {
342
- const C = Ke(F.weightShift ?? 0, -1, 1), B = Math.min(Math.max(j, 0), 0.05), H = v[0], N = o ? a * Ke(0.4 * C + (B ? 0.6 * Math.tanh((C - g) / B) : 0), -1, 1) : 0;
342
+ const C = Ke(F.weightShift ?? 0, -1, 1), B = Math.min(Math.max(j, 0), 0.05), H = v[0], N = o ? s * Ke(0.4 * C + (B ? 0.6 * Math.tanh((C - g) / B) : 0), -1, 1) : 0;
343
343
  if (!B)
344
344
  o && (y.fill(N), v.fill(0), m = 0), c.fill(C), f.fill(0), h = 0, p = 0;
345
345
  else {
346
- const ne = (t.bob ?? Rt.bob) * Math.min(1, Math.abs(C - g) / B / 1.5), Q = Math.ceil(B * 240), J = B / Q;
346
+ const ne = (e.bob ?? kt.bob) * Math.min(1, Math.abs(C - g) / B / 1.5), Q = Math.ceil(B * 240), J = B / Q;
347
347
  for (let X = 0; X < Q; X++) {
348
348
  for (let G = 0; G < 3; G++) {
349
349
  const re = G ? c[G - 1] : C;
@@ -362,18 +362,18 @@ function Jn(t, e, n = null) {
362
362
  let w, A, L;
363
363
  function z(F) {
364
364
  const j = Ke(F.weightShift ?? 0, -1, 1), C = Ke(F.bodyAngleX ?? 0, -10, 10);
365
- if (j === w && C === A && b === s) return L;
366
- w = j, A = C, s = b;
367
- const B = -t.tilt * j, H = t.shift * j + C / 10 * (e.hip?.shift ?? t.shift), N = o ? b ? y[0] : a * 0.4 * j : 0, ne = o ? -(1 - (t.spine ?? Rt.spine)) * (b ? y[1] : N) : 0, Q = (V) => {
368
- const M = vt(V, t.pelvis, B);
369
- return o && (M[0] += l(V[0], t.pelvis[0], i, N)), M[0] += H, M;
370
- }, J = r.map((V) => Q(V.hip)), X = r.map((V, M) => V.lateral + V.side * t.bend * Math.max(0, M ? -j : j) ** 2), G = j * j + (C / 10) ** 2, re = t.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * G, W = (V) => (V + Math.hypot(V, re)) / 2;
371
- let te = h + t.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * j * j;
365
+ if (j === w && C === A && b === a) return L;
366
+ w = j, A = C, a = b;
367
+ const B = -e.tilt * j, H = e.shift * j + C / 10 * (t.hip?.shift ?? e.shift), N = o ? b ? y[0] : s * 0.4 * j : 0, ne = o ? -(1 - (e.spine ?? kt.spine)) * (b ? y[1] : N) : 0, Q = (V) => {
368
+ const M = vt(V, e.pelvis, B);
369
+ return o && (M[0] += l(V[0], e.pelvis[0], i, N)), M[0] += H, M;
370
+ }, J = r.map((V) => Q(V.hip)), X = r.map((V, M) => V.lateral + V.side * e.bend * Math.max(0, M ? -j : j) ** 2), G = j * j + (C / 10) ** 2, re = e.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * G, W = (V) => (V + Math.hypot(V, re)) / 2;
371
+ let te = h + e.bend ** 2 / Math.min(...r.map((V) => V.u + V.v)) * j * j;
372
372
  for (let V = 0; V < r.length; V++) {
373
373
  const M = r[V], E = J[V], O = E[0] - M.ankle[0], k = Math.sqrt(Math.max(0, M.u * M.u - X[V] ** 2)) + Math.sqrt(Math.max(0, M.v * M.v - X[V] ** 2)), $ = M.ankle[1] - Math.sqrt(Math.max(0, k * k - O * O)) - E[1];
374
374
  te += W($ - te);
375
375
  }
376
- const se = r.map((V, M) => {
376
+ const ae = r.map((V, M) => {
377
377
  const E = [J[M][0], J[M][1] + te], O = V.ankle;
378
378
  if (!j && !C && !h && !N) return {
379
379
  hip: V.hip,
@@ -396,8 +396,8 @@ function Jn(t, e, n = null) {
396
396
  hip3: [...E, 0],
397
397
  knee3: [...q, ee],
398
398
  ankle3: [...O, 0],
399
- upper: ln(V.hip, V.knee, E, q),
400
- lower: ln(V.knee, V.ankle, q, O)
399
+ upper: cn(V.hip, V.knee, E, q),
400
+ lower: cn(V.knee, V.ankle, q, O)
401
401
  };
402
402
  });
403
403
  return L = {
@@ -406,21 +406,21 @@ function Jn(t, e, n = null) {
406
406
  angle: B,
407
407
  shift: H,
408
408
  drop: te,
409
- bones: se,
409
+ bones: ae,
410
410
  ...o && { twist: { pelvis: N, shoulder: ne, head: 0, acceleration: m } },
411
411
  trunk: { spine: c[0], chest: c[1], head: c[2], bob: h }
412
412
  }, L;
413
413
  }
414
414
  function Y(F) {
415
- const j = t.split;
415
+ const j = e.split;
416
416
  let C = 0;
417
417
  for (; C < j.length - 2 && F > j[C + 1][1]; ) C++;
418
418
  const B = j[C], H = j[C + 1], N = Ke((F - B[1]) / (H[1] - B[1]), 0, 1);
419
419
  return B[0] + (H[0] - B[0]) * N;
420
420
  }
421
421
  function I(F, j) {
422
- const C = j >= t.split[0][1] ? +(F >= Y(j)) : Ye(Y(j) - 4, Y(j) + 4, F), B = r.map((H) => ({
423
- leg: Ye(t.band[0], H.hip[1], j),
422
+ const C = j >= e.split[0][1] ? +(F >= Y(j)) : Ye(Y(j) - 4, Y(j) + 4, F), B = r.map((H) => ({
423
+ leg: Ye(e.band[0], H.hip[1], j),
424
424
  shin: Ye(H.knee[1] - 45, H.knee[1] + 45, j),
425
425
  pin: 1 - Ye(H.ankle[1] - 55, H.ankle[1], j)
426
426
  }));
@@ -429,41 +429,41 @@ function Jn(t, e, n = null) {
429
429
  function U(F, j, C, B, H) {
430
430
  const N = z(H);
431
431
  if (!N.ws && !N.bx && !N.trunk.chest && !N.trunk.head && !h && !N.twist?.pelvis && !N.twist?.shoulder) return;
432
- const ne = [t.pelvis[0] + N.shift, t.pelvis[1] + N.drop], Q = 1 - Ye(Math.min(e.chest.cy, t.pelvis[1] - 1), t.pelvis[1], C), J = 1 - Ye(...t.band, C), X = t.spine ?? Rt.spine, G = t.tilt * (1 - X) * N.trunk.chest, re = t.shift * (1.12 * N.trunk.chest - N.ws) + Math.sin(G) * Math.max(0, t.pelvis[1] - e.chest.cy), W = (M) => {
433
- const E = vt(M, t.pelvis, N.angle);
432
+ const ne = [e.pelvis[0] + N.shift, e.pelvis[1] + N.drop], Q = 1 - Ye(Math.min(t.chest.cy, e.pelvis[1] - 1), e.pelvis[1], C), J = 1 - Ye(...e.band, C), X = e.spine ?? kt.spine, G = e.tilt * (1 - X) * N.trunk.chest, re = e.shift * (1.12 * N.trunk.chest - N.ws) + Math.sin(G) * Math.max(0, e.pelvis[1] - t.chest.cy), W = (M) => {
433
+ const E = vt(M, e.pelvis, N.angle);
434
434
  E[0] += N.shift, E[1] += N.drop;
435
435
  const O = vt(E, ne, (G - N.angle) * J);
436
436
  return O[0] += re * Q, O;
437
437
  }, te = W(F);
438
438
  if (n) {
439
- const M = 1 - Ye(...n.weightBand, C), E = W([n.pivotX, n.pivotY]), O = -t.tilt * (1 - X) * N.trunk.head * M, k = vt(te, E, O);
440
- te[0] = k[0] + t.shift * 1.12 * (N.trunk.head - N.trunk.chest) * M, te[1] = k[1];
439
+ const M = 1 - Ye(...n.weightBand, C), E = W([n.pivotX, n.pivotY]), O = -e.tilt * (1 - X) * N.trunk.head * M, k = vt(te, E, O);
440
+ te[0] = k[0] + e.shift * 1.12 * (N.trunk.head - N.trunk.chest) * M, te[1] = k[1];
441
441
  }
442
442
  if (o) {
443
- const M = e.chest.cy + Math.max(40, (t.pelvis[1] - e.chest.cy) * 0.5), E = Ye(e.chest.cy, M, C), O = N.twist.shoulder + (N.twist.pelvis - N.twist.shoulder) * E, k = e.chest.cx + (t.pelvis[0] - e.chest.cx) * E, $ = u + (i - u) * E, Z = n ? Ye(...n.weightBand, C) : 1;
443
+ const M = t.chest.cy + Math.max(40, (e.pelvis[1] - t.chest.cy) * 0.5), E = Ye(t.chest.cy, M, C), O = N.twist.shoulder + (N.twist.pelvis - N.twist.shoulder) * E, k = t.chest.cx + (e.pelvis[0] - t.chest.cx) * E, $ = u + (i - u) * E, Z = n ? Ye(...n.weightBand, C) : 1;
444
444
  te[0] += l(j, k, $, O) * Z;
445
445
  }
446
- let se = 0, V = 0;
446
+ let ae = 0, V = 0;
447
447
  r.forEach((M, E) => {
448
- const O = N.bones[E], k = B.perBone[E], $ = cn(F, O.upper), Z = cn(F, O.lower), _ = $[0] + (Z[0] - $[0]) * k.shin, D = $[1] + (Z[1] - $[1]) * k.shin, q = E ? B.right : 1 - B.right;
449
- se += ((te[0] - F[0]) * (1 - k.leg) + (_ - F[0]) * k.leg) * k.pin * q, V += ((te[1] - F[1]) * (1 - k.leg) + (D - F[1]) * k.leg) * k.pin * q;
450
- }), F[0] += se, F[1] += V;
448
+ const O = N.bones[E], k = B.perBone[E], $ = hn(F, O.upper), Z = hn(F, O.lower), _ = $[0] + (Z[0] - $[0]) * k.shin, D = $[1] + (Z[1] - $[1]) * k.shin, q = E ? B.right : 1 - B.right;
449
+ ae += ((te[0] - F[0]) * (1 - k.leg) + (_ - F[0]) * k.leg) * k.pin * q, V += ((te[1] - F[1]) * (1 - k.leg) + (D - F[1]) * k.leg) * k.pin * q;
450
+ }), F[0] += ae, F[1] += V;
451
451
  }
452
452
  function T(F) {
453
453
  return 1 - Ye(x - 55, x, F);
454
454
  }
455
455
  return { frame: z, weights: I, apply: U, pin: T, step: d };
456
456
  }
457
- const Ge = (t, e, n) => Math.max(e, Math.min(n, t)), st = (t, e = 0) => Number.isFinite(t) ? t : e, it = (t, e, n) => {
458
- const r = Ge((n - t) / Math.max(1e-6, e - t), 0, 1);
457
+ const Ge = (e, t, n) => Math.max(t, Math.min(n, e)), at = (e, t = 0) => Number.isFinite(e) ? e : t, it = (e, t, n) => {
458
+ const r = Ge((n - e) / Math.max(1e-6, t - e), 0, 1);
459
459
  return r * r * (3 - 2 * r);
460
- }, kt = (t, e, n) => {
461
- const r = t[0] - e[0], o = t[1] - e[1], a = Math.cos(n), i = Math.sin(n);
462
- return [e[0] + r * a - o * i, e[1] + r * i + o * a];
460
+ }, Lt = (e, t, n) => {
461
+ const r = e[0] - t[0], o = e[1] - t[1], s = Math.cos(n), i = Math.sin(n);
462
+ return [t[0] + r * s - o * i, t[1] + r * i + o * s];
463
463
  }, mt = Object.freeze({ swing: 4, bend: 6, inward: 0.4 });
464
- function Kn(t, e, n = null) {
465
- if (!t) return null;
466
- const r = Ge(st(t.swing, mt.swing), 0, 10) * Math.PI / 180, o = Ge(st(t.bend, mt.bend), 0, 12) * Math.PI / 180, a = Ge(st(t.inward, mt.inward), 0, 1), i = [t.left, t.right];
464
+ function er(e, t, n = null) {
465
+ if (!e) return null;
466
+ const r = Ge(at(e.swing, mt.swing), 0, 10) * Math.PI / 180, o = Ge(at(e.bend, mt.bend), 0, 12) * Math.PI / 180, s = Ge(at(e.inward, mt.inward), 0, 1), i = [e.left, e.right];
467
467
  function u(l, c) {
468
468
  let f = 0;
469
469
  for (; f < l.length - 2 && c > l[f + 1][1]; ) f++;
@@ -472,7 +472,7 @@ function Kn(t, e, n = null) {
472
472
  }
473
473
  function y(l, c) {
474
474
  return i.map((f, h) => {
475
- const p = Math.max(1, f.elbow[1] - f.shoulder[1]), g = Math.max(1, f.wrist[1] - f.elbow[1]), b = Math.max(1, Math.min(p, g, e.chest.ry) * 0.2), s = u(f.split, c), d = h ? l - s : s - l, x = +(d >= 0), w = it(-b, b, d), A = it(f.split[0][1] - b, f.split[0][1], c);
475
+ const p = Math.max(1, f.elbow[1] - f.shoulder[1]), g = Math.max(1, f.wrist[1] - f.elbow[1]), b = Math.max(1, Math.min(p, g, t.chest.ry) * 0.2), a = u(f.split, c), d = h ? l - a : a - l, x = +(d >= 0), w = it(-b, b, d), A = it(f.split[0][1] - b, f.split[0][1], c);
476
476
  return {
477
477
  arm: (w + (x - w) * A) * it(f.shoulder[1], f.shoulder[1] + p * 0.55, c) * (1 - it(f.split.at(-1)[1], f.split.at(-1)[1] + b, c)),
478
478
  forearm: it(f.elbow[1] - b, f.elbow[1] + b, c)
@@ -481,21 +481,21 @@ function Kn(t, e, n = null) {
481
481
  }
482
482
  function v(l, c = (f) => [...f]) {
483
483
  return i.map((f, h) => {
484
- const p = h ? "R" : "L", g = h ? -1 : 1, b = Ge(st(l[`armSwing${p}`]), -1, 1);
484
+ const p = h ? "R" : "L", g = h ? -1 : 1, b = Ge(at(l[`armSwing${p}`]), -1, 1);
485
485
  return {
486
486
  shoulder: c(f.shoulder),
487
487
  elbow: c(f.elbow),
488
- swing: g * r * b * (b < 0 ? a : 1),
488
+ swing: g * r * b * (b < 0 ? s : 1),
489
489
  // Flex inward; negative values never hyper-extend the elbow.
490
- bend: -g * o * Ge(st(l[`elbowBend${p}`]), 0, 1)
490
+ bend: -g * o * Ge(at(l[`elbowBend${p}`]), 0, 1)
491
491
  };
492
492
  });
493
493
  }
494
494
  function m(l, c, f, h, p, g = v(p)) {
495
495
  const b = [...l];
496
- g.forEach((s, d) => {
497
- if (!h[d].arm || !s.swing && !s.bend) return;
498
- const x = s.swing ? kt(b, s.shoulder, s.swing) : b, w = s.swing ? kt(s.elbow, s.shoulder, s.swing) : s.elbow, A = s.bend ? kt(x, w, s.bend) : x;
496
+ g.forEach((a, d) => {
497
+ if (!h[d].arm || !a.swing && !a.bend) return;
498
+ const x = a.swing ? Lt(b, a.shoulder, a.swing) : b, w = a.swing ? Lt(a.elbow, a.shoulder, a.swing) : a.elbow, A = a.bend ? Lt(x, w, a.bend) : x;
499
499
  l[0] += (x[0] - b[0] + (A[0] - x[0]) * h[d].forearm) * h[d].arm, l[1] += (x[1] - b[1] + (A[1] - x[1]) * h[d].forearm) * h[d].arm;
500
500
  });
501
501
  }
@@ -522,20 +522,20 @@ const bt = [
522
522
  { id: "handAngle", label: "Wrist angle", min: -10, max: 10, def: 0, group: "Hand" },
523
523
  { id: "fingerTap", label: "Finger tap", min: 0, max: 1, def: 0, group: "Hand" },
524
524
  { id: "weightShift", label: "Weight shift", min: -1, max: 1, def: 0, group: "Legs" },
525
- ...["L", "R"].flatMap((t) => [
526
- { id: `armSwing${t}`, label: `Arm swing ${t}`, min: -1, max: 1, def: 0, group: "Arms" },
527
- { id: `elbowBend${t}`, label: `Elbow bend ${t}`, min: 0, max: 1, def: 0, group: "Arms" }
525
+ ...["L", "R"].flatMap((e) => [
526
+ { id: `armSwing${e}`, label: `Arm swing ${e}`, min: -1, max: 1, def: 0, group: "Arms" },
527
+ { id: `elbowBend${e}`, label: `Elbow bend ${e}`, min: 0, max: 1, def: 0, group: "Arms" }
528
528
  ])
529
529
  ];
530
- function Qn(t) {
531
- const e = { w: t.image.width, h: t.image.height }, n = (M, E, O) => O ? Math.exp(-(((M - O.cx) / O.rx) ** 2 + ((E - O.cy) / O.ry) ** 2)) : 0, r = 24, o = t.eyes;
532
- function a(M, E) {
530
+ function tr(e) {
531
+ const t = { w: e.image.width, h: e.image.height }, n = (M, E, O) => O ? Math.exp(-(((M - O.cx) / O.rx) ** 2 + ((E - O.cy) / O.ry) ** 2)) : 0, r = 24, o = e.eyes;
532
+ function s(M, E) {
533
533
  const O = Math.min(1, Math.max(0, E)) * (r - 1), k = Math.min(Math.floor(O), r - 2), $ = O - k;
534
534
  return M[k] + (M[k + 1] - M[k]) * $;
535
535
  }
536
536
  function i(M, E, O, k) {
537
537
  E = Math.min(1, Math.max(0, E));
538
- const $ = a(M.top, E), Z = a(M.bot, E), _ = 1 - O, D = 4 * E * (1 - E), q = a(M.bot, 0.5) - a(M.top, 0.5), ee = M.top[0] + (M.top[r - 1] - M.top[0]) * E - 0.3 * q * D, oe = Math.max($, Z + 1 + (ee - Z - 1) * k);
538
+ const $ = s(M.top, E), Z = s(M.bot, E), _ = 1 - O, D = 4 * E * (1 - E), q = s(M.bot, 0.5) - s(M.top, 0.5), ee = M.top[0] + (M.top[r - 1] - M.top[0]) * E - 0.3 * q * D, oe = Math.max($, Z + 1 + (ee - Z - 1) * k);
539
539
  return [(oe - $) * Math.max(_, -0.07), _ > 0 ? (oe - Z) * _ * k : 0];
540
540
  }
541
541
  const u = [[-2, 1], [-1, 2], [0, 3], [1, 2], [2, 1]], y = 5;
@@ -545,7 +545,7 @@ function Qn(t) {
545
545
  const [S, R] = i(M, (E + ee * y - M.x0) / (M.x1 - M.x0), O, k);
546
546
  $ += S * oe / 9, Z += R * oe / 9;
547
547
  }
548
- const _ = Math.min(1, Math.max(0, (E - M.x0) / (M.x1 - M.x0))), D = a(M.top, _), q = a(M.bot, _);
548
+ const _ = Math.min(1, Math.max(0, (E - M.x0) / (M.x1 - M.x0))), D = s(M.top, _), q = s(M.bot, _);
549
549
  return { top: D, bot: q, b: 1 - O, lid: D + $, bc: q + Z };
550
550
  }
551
551
  function m(M, E, O, k, $, Z) {
@@ -556,23 +556,23 @@ function Qn(t) {
556
556
  const k = Math.min(1, Math.max(0, 1 - E));
557
557
  return M === "low" ? 1 - Math.min(1, k * O * 1.2) : M === "crease" ? 1 - 0.45 * k : 1;
558
558
  }
559
- const c = t.mouth, f = t.cheeks, h = t.head, p = t.body, g = Jn(t.legs, p, h), b = Kn(t.arms, p, t.legs), s = (M, E, O) => {
559
+ const c = e.mouth, f = e.cheeks, h = e.head, p = e.body, g = Qn(e.legs, p, h), b = er(e.arms, p, e.legs), a = (M, E, O) => {
560
560
  const k = Math.min(1, Math.max(0, (O - M) / (E - M)));
561
561
  return k * k * (3 - 2 * k);
562
562
  };
563
563
  function d(M, E) {
564
- return 1 - s(...h.weightBand, E);
564
+ return 1 - a(...h.weightBand, E);
565
565
  }
566
566
  function x(M, E) {
567
- return 1 - s(...h.turnBand, E);
567
+ return 1 - a(...h.turnBand, E);
568
568
  }
569
- const w = t.strands ?? [];
569
+ const w = e.strands ?? [];
570
570
  function A(M, E, O) {
571
571
  let k = 1 / 0, $ = 0;
572
572
  const Z = O.length - 1;
573
573
  for (let _ = 0; _ < Z; _++) {
574
- const [D, q] = O[_], [ee, oe] = O[_ + 1], S = ee - D, R = oe - q, P = Math.min(1, Math.max(0, ((M - D) * S + (E - q) * R) / (S * S + R * R))), ae = Math.hypot(M - D - S * P, E - q - R * P);
575
- ae < k && (k = ae, $ = (_ + P) / Z);
574
+ const [D, q] = O[_], [ee, oe] = O[_ + 1], S = ee - D, R = oe - q, P = Math.min(1, Math.max(0, ((M - D) * S + (E - q) * R) / (S * S + R * R))), se = Math.hypot(M - D - S * P, E - q - R * P);
575
+ se < k && (k = se, $ = (_ + P) / Z);
576
576
  }
577
577
  return [k, $];
578
578
  }
@@ -585,27 +585,27 @@ function Qn(t) {
585
585
  oe < 0.02 || (k.push([D, oe, ee]), $ += oe);
586
586
  });
587
587
  const Z = Math.max(1, $);
588
- return k.map(([_, D, q]) => [_, O * D / Z * s(0.04, 0.55, q), q]);
588
+ return k.map(([_, D, q]) => [_, O * D / Z * a(0.04, 0.55, q), q]);
589
589
  }
590
590
  function z(M, E, O = 1) {
591
591
  return {
592
592
  head: d(M, E),
593
593
  turn: x(M, E),
594
594
  strands: L(M, E, O),
595
- bunL: n(M, E, t.buns?.bunL),
596
- bunR: n(M, E, t.buns?.bunR),
597
- brow: n(M, E, t.face.brow) * (1 - s(...t.face.brow.band, E)),
595
+ bunL: n(M, E, e.buns?.bunL),
596
+ bunR: n(M, E, e.buns?.bunR),
597
+ brow: n(M, E, e.face.brow) * (1 - a(...e.face.brow.band, E)),
598
598
  // chin below the mouth line drops a little when the mouth opens
599
- jaw: n(M, E, t.face.jaw) * s(...t.face.jaw.band, E),
599
+ jaw: n(M, E, e.face.jaw) * a(...e.face.jaw.band, E),
600
600
  // per-feature depth for head turns (nose sticks out most, ears sit at the back)
601
- nose: n(M, E, t.face.nose),
602
- mouth: n(M, E, t.face.mouth),
603
- eyeA: n(M, E, t.face.eyeA),
604
- eyeB: n(M, E, t.face.eyeB),
605
- earR: n(M, E, t.face.earR),
606
- earL: n(M, E, t.face.earL),
601
+ nose: n(M, E, e.face.nose),
602
+ mouth: n(M, E, e.face.mouth),
603
+ eyeA: n(M, E, e.face.eyeA),
604
+ eyeB: n(M, E, e.face.eyeB),
605
+ earR: n(M, E, e.face.earR),
606
+ earL: n(M, E, e.face.earL),
607
607
  chest: n(M, E, p.chest),
608
- breath: 1 - s(...p.breathBand, E),
608
+ breath: 1 - a(...p.breathBand, E),
609
609
  shoulder: p.shoulders.reduce((k, $) => k + n(M, E, $), 0),
610
610
  ...g && { legs: g.weights(M, E) },
611
611
  ...b && { arms: b.weights(M, E) }
@@ -614,7 +614,7 @@ function Qn(t) {
614
614
  function Y(M, E, O, k) {
615
615
  const $ = (M - h.cx) / h.rx, Z = (E - h.cy) / h.ry, _ = 1 - $ * $ - Z * Z;
616
616
  if (_ <= 0) return [0, 0];
617
- const D = s(0, 0.84, _);
617
+ const D = a(0, 0.84, _);
618
618
  return [O * h.shiftX * D, -k * h.shiftY * D];
619
619
  }
620
620
  function I(M, E, O, k) {
@@ -630,7 +630,7 @@ function Qn(t) {
630
630
  const D = M[0], q = M[1], ee = O.breath;
631
631
  M[1] -= ee * (5 * $ + 4 * Z), M[0] += (M[0] - p.chest.cx) * 0.012 * ee * k;
632
632
  const oe = p.hip;
633
- if (g || (M[0] += O.bodyAngleX / 10 * (oe ? oe.shift * (1 - s(...oe.band, E)) : 7 + 9 * k)), I(M, p.pivotX, p.pivotY, -O.bodyAngleZ / 10 * p.maxRoll * (1 - s(...p.rollBand, E))), g) {
633
+ if (g || (M[0] += O.bodyAngleX / 10 * (oe ? oe.shift * (1 - a(...oe.band, E)) : 7 + 9 * k)), I(M, p.pivotX, p.pivotY, -O.bodyAngleZ / 10 * p.maxRoll * (1 - a(...p.rollBand, E))), g) {
634
634
  const S = g.pin(E);
635
635
  M[0] = D + (M[0] - D) * S, M[1] = q + (M[1] - q) * S;
636
636
  }
@@ -643,16 +643,16 @@ function Qn(t) {
643
643
  for (const [oe, S, R] of O.strands) {
644
644
  const P = $.strands?.[oe];
645
645
  if (!P) continue;
646
- const ae = R * 3, ie = Math.min(2, Math.floor(ae)), pe = ae - ie;
646
+ const se = R * 3, ie = Math.min(2, Math.floor(se)), pe = se - ie;
647
647
  _[0] += (P[ie][0] + (P[ie + 1][0] - P[ie][0]) * pe) * S * D, _[1] += (P[ie][1] + (P[ie + 1][1] - P[ie][1]) * pe) * S * D;
648
648
  }
649
649
  if (_[0] += ($.bunL[0] * O.bunL + $.bunR[0] * O.bunR) * D, _[1] += ($.bunL[1] * O.bunL + $.bunR[1] * O.bunR) * D, _[1] -= k.browY * 7 * O.brow, O.brow > 0.01) {
650
650
  const oe = k.browAngle * 0.12 * O.brow;
651
- _[1] += (M - t.face.brow.cx) * Math.sin(oe);
651
+ _[1] += (M - e.face.brow.cx) * Math.sin(oe);
652
652
  }
653
653
  _[1] += k.mouthOpen * 3.5 * O.jaw;
654
654
  const q = k.angleX / 30, ee = k.angleY / 30;
655
- if (_[0] += q * (8 * O.nose + 5 * O.mouth) + (M - t.face.eyeA.cx) * 0.12 * q * O.eyeA - (M - t.face.eyeB.cx) * 0.12 * q * O.eyeB - q * 9 * O.earR + q * 4 * O.earL - q * 10 * (O.bunL + O.bunR), _[1] -= ee * (6 * O.nose + 3 * O.mouth), _[1] += (E - t.face.eyeA.cy) * -0.06 * Math.abs(ee) * O.eyeA + (E - t.face.eyeB.cy) * -0.06 * Math.abs(ee) * O.eyeB, U(_, O.head, k, O.turn), T(_, E, k, O.chest, O.breath, O.shoulder, O.legs), b && O.arms.some((oe) => oe.arm > 0)) {
655
+ if (_[0] += q * (8 * O.nose + 5 * O.mouth) + (M - e.face.eyeA.cx) * 0.12 * q * O.eyeA - (M - e.face.eyeB.cx) * 0.12 * q * O.eyeB - q * 9 * O.earR + q * 4 * O.earL - q * 10 * (O.bunL + O.bunR), _[1] -= ee * (6 * O.nose + 3 * O.mouth), _[1] += (E - e.face.eyeA.cy) * -0.06 * Math.abs(ee) * O.eyeA + (E - e.face.eyeB.cy) * -0.06 * Math.abs(ee) * O.eyeB, U(_, O.head, k, O.turn), T(_, E, k, O.chest, O.breath, O.shoulder, O.legs), b && O.arms.some((oe) => oe.arm > 0)) {
656
656
  const oe = [
657
657
  k.angleX,
658
658
  k.angleY,
@@ -673,14 +673,14 @@ function Qn(t) {
673
673
  }
674
674
  return _;
675
675
  }
676
- const B = t.hand, H = B?.elbow ?? [0, 0], N = B?.wrist ?? [0, 0], ne = B?.knuckle ?? [0, 0], Q = B?.contact ?? [0, 0], J = B?.forearmShare ?? 0;
676
+ const B = e.hand, H = B?.elbow ?? [0, 0], N = B?.wrist ?? [0, 0], ne = B?.knuckle ?? [0, 0], Q = B?.contact ?? [0, 0], J = B?.forearmShare ?? 0;
677
677
  function X(M, E) {
678
678
  return B ? {
679
- arm: 1 - s(...B.armBand, E),
680
- wrist: 1 - s(...B.wristBand, E),
681
- hand: 1 - s(...B.handBand, E),
682
- finger: s(...B.fingerXBand, M) * (1 - s(...B.fingerYBand, E)),
683
- pinBottom: s(...B.pinBand, E)
679
+ arm: 1 - a(...B.armBand, E),
680
+ wrist: 1 - a(...B.wristBand, E),
681
+ hand: 1 - a(...B.handBand, E),
682
+ finger: a(...B.fingerXBand, M) * (1 - a(...B.fingerYBand, E)),
683
+ pinBottom: a(...B.pinBand, E)
684
684
  } : { arm: 0, wrist: 0, hand: 0, finger: 0, pinBottom: 0 };
685
685
  }
686
686
  const G = (M, E, O, k) => {
@@ -706,48 +706,48 @@ function Qn(t) {
706
706
  const ee = $.b * O.hand, oe = 1 + ($.k - 1) * O.hand;
707
707
  return _ = G(_, $.w, Math.cos(ee) * oe, Math.sin(ee) * oe), _[1] += (E - _[1]) * O.pinBottom, Z[0] = _[0], Z[1] = _[1], Z;
708
708
  }
709
- const se = t.accessories ?? [];
709
+ const ae = e.accessories ?? [];
710
710
  function V(M, E, O, k) {
711
711
  const $ = z(M.pivot[0], M.pivot[1]);
712
712
  return C(M.pivot[0], M.pivot[1], $, E, O, k);
713
713
  }
714
- return { legs: g, stepBody: (M, E) => g?.step(M, E), IMG: e, EYES: o, MOUTH: c, CHEEKS: f, STRANDS: w, TASSELS: se, headWeight: d, turnWeight: x, baseWeights: z, deformBase: C, applyHead: U, applyBody: T, handWeights: X, handFrame: W, deformHand: te, eyePartY: m, eyePartAlpha: l, tasselAnchor: V };
715
- }
716
- function er(t, e, n, r = !1) {
717
- const o = r ? Math.max(e, n) * 2 : 1, a = new Float32Array(t.length), i = Math.SQRT2;
718
- for (let u = 0; u < n; u++) for (let y = 0; y < e; y++) {
719
- const v = u * e + y;
720
- t[v] <= 3 || (a[v] = Math.min(
721
- y ? a[v - 1] + 1 : o,
722
- u ? a[v - e] + 1 : o,
723
- y && u ? a[v - e - 1] + i : o,
724
- u && y + 1 < e ? a[v - e + 1] + i : o
714
+ return { legs: g, stepBody: (M, E) => g?.step(M, E), IMG: t, EYES: o, MOUTH: c, CHEEKS: f, STRANDS: w, TASSELS: ae, headWeight: d, turnWeight: x, baseWeights: z, deformBase: C, applyHead: U, applyBody: T, handWeights: X, handFrame: W, deformHand: te, eyePartY: m, eyePartAlpha: l, tasselAnchor: V };
715
+ }
716
+ function nr(e, t, n, r = !1) {
717
+ const o = r ? Math.max(t, n) * 2 : 1, s = new Float32Array(e.length), i = Math.SQRT2;
718
+ for (let u = 0; u < n; u++) for (let y = 0; y < t; y++) {
719
+ const v = u * t + y;
720
+ e[v] <= 3 || (s[v] = Math.min(
721
+ y ? s[v - 1] + 1 : o,
722
+ u ? s[v - t] + 1 : o,
723
+ y && u ? s[v - t - 1] + i : o,
724
+ u && y + 1 < t ? s[v - t + 1] + i : o
725
725
  ));
726
726
  }
727
- for (let u = n - 1; u >= 0; u--) for (let y = e - 1; y >= 0; y--) {
728
- const v = u * e + y;
729
- !t[v] || t[v] <= 3 || (a[v] = Math.min(
730
- a[v],
731
- y + 1 < e ? a[v + 1] + 1 : o,
732
- u + 1 < n ? a[v + e] + 1 : o,
733
- y && u + 1 < n ? a[v + e - 1] + i : o,
734
- y + 1 < e && u + 1 < n ? a[v + e + 1] + i : o
727
+ for (let u = n - 1; u >= 0; u--) for (let y = t - 1; y >= 0; y--) {
728
+ const v = u * t + y;
729
+ !e[v] || e[v] <= 3 || (s[v] = Math.min(
730
+ s[v],
731
+ y + 1 < t ? s[v + 1] + 1 : o,
732
+ u + 1 < n ? s[v + t] + 1 : o,
733
+ y && u + 1 < n ? s[v + t - 1] + i : o,
734
+ y + 1 < t && u + 1 < n ? s[v + t + 1] + i : o
735
735
  ));
736
736
  }
737
- return a;
737
+ return s;
738
738
  }
739
- function Lt(t, e, n) {
740
- return Math.exp(-(((t - n.cx) / n.rx) ** 2 + ((e - n.cy) / n.ry) ** 2));
739
+ function _t(e, t, n) {
740
+ return Math.exp(-(((e - n.cx) / n.rx) ** 2 + ((t - n.cy) / n.ry) ** 2));
741
741
  }
742
- function tr(t, e, n) {
743
- const r = ((t - n.head.cx) / n.head.rx) ** 2 + ((e - n.head.cy) / n.head.ry) ** 2;
744
- let o = n.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + n.body.chest.rx * 0.23 * Lt(t, e, n.body.chest);
745
- o += n.face.nose.rx * 0.2 * Lt(t, e, n.face.nose);
746
- for (const [a, i] of n.cheeks) o += n.head.rx * 0.012 * Lt(t, e, { cx: a, cy: i, rx: n.head.rx * 0.3, ry: n.head.ry * 0.16 });
742
+ function rr(e, t, n) {
743
+ const r = ((e - n.head.cx) / n.head.rx) ** 2 + ((t - n.head.cy) / n.head.ry) ** 2;
744
+ let o = n.head.rx * 0.8 * Math.sqrt(Math.max(0, 1 - r)) + n.body.chest.rx * 0.23 * _t(e, t, n.body.chest);
745
+ o += n.face.nose.rx * 0.2 * _t(e, t, n.face.nose);
746
+ for (const [s, i] of n.cheeks) o += n.head.rx * 0.012 * _t(e, t, { cx: s, cy: i, rx: n.head.rx * 0.3, ry: n.head.ry * 0.16 });
747
747
  return o;
748
748
  }
749
- function Et(t, e, n, r) {
750
- const o = new Float32Array(t.length), a = new Float32Array(t.length), i = (u, y, v, m, l, c) => {
749
+ function Et(e, t, n, r) {
750
+ const o = new Float32Array(e.length), s = new Float32Array(e.length), i = (u, y, v, m, l, c) => {
751
751
  for (let f = 0; f < m; f++) {
752
752
  const h = f * c;
753
753
  let p = 0, g = 0;
@@ -755,51 +755,51 @@ function Et(t, e, n, r) {
755
755
  p += u[h + b * l], g++;
756
756
  for (let b = 0; b < v; b++) {
757
757
  y[h + b * l] = p / g;
758
- const s = b + r + 1, d = b - r;
759
- s < v && (p += u[h + s * l], g++), d >= 0 && (p -= u[h + d * l], g--);
758
+ const a = b + r + 1, d = b - r;
759
+ a < v && (p += u[h + a * l], g++), d >= 0 && (p -= u[h + d * l], g--);
760
760
  }
761
761
  }
762
762
  };
763
- return i(t, o, e, n, 1, e), i(o, a, n, e, e, 1), a;
763
+ return i(e, o, t, n, 1, t), i(o, s, n, t, t, 1), s;
764
764
  }
765
- function nr(t, e, n, r) {
766
- const o = Et(t, n, r, 1), a = Et(t, n, r, 6), i = new Float32Array(t.length);
767
- for (let v = 0; v < i.length; v++) i[v] = e[v] > 128 ? o[v] - a[v] : 0;
768
- const u = new Float32Array(t.length * 2), y = (v, m) => i[Math.max(0, Math.min(r - 1, m)) * n + Math.max(0, Math.min(n - 1, v))];
765
+ function or(e, t, n, r) {
766
+ const o = Et(e, n, r, 1), s = Et(e, n, r, 6), i = new Float32Array(e.length);
767
+ for (let v = 0; v < i.length; v++) i[v] = t[v] > 128 ? o[v] - s[v] : 0;
768
+ const u = new Float32Array(e.length * 2), y = (v, m) => i[Math.max(0, Math.min(r - 1, m)) * n + Math.max(0, Math.min(n - 1, v))];
769
769
  for (let v = 0; v < r; v++) for (let m = 0; m < n; m++) {
770
770
  const l = v * n + m;
771
- e[l] <= 128 || (u[2 * l] = Math.max(-1, Math.min(1, -(y(m + 1, v) - y(m - 1, v)) * 4)), u[2 * l + 1] = Math.max(-1, Math.min(1, -(y(m, v + 1) - y(m, v - 1)) * 4)));
771
+ t[l] <= 128 || (u[2 * l] = Math.max(-1, Math.min(1, -(y(m + 1, v) - y(m - 1, v)) * 4)), u[2 * l + 1] = Math.max(-1, Math.min(1, -(y(m, v + 1) - y(m, v - 1)) * 4)));
772
772
  }
773
773
  return u;
774
774
  }
775
- function rr(t, e, n, r, o, a = !0, i) {
776
- const u = !!o && r[0] === 0 && r[1] === 0 && r[2] === o.image.width && r[3] === o.image.height, y = er(t, e, n, u), v = new Float32Array(t.length), m = r[2] / e, l = r[3] / n, c = Math.min(m, l), f = Math.min(r[2], r[3]) * 0.08;
777
- for (let s = 0; s < n; s++) for (let d = 0; d < e; d++) {
778
- const x = s * e + d;
779
- v[x] = (a ? Math.sqrt(y[x] * c * f) * 0.55 : 0) + (o ? tr(r[0] + (d + 0.5) * m, r[1] + (s + 0.5) * l, o) : 0);
780
- }
781
- const h = Math.max(1, Math.round(Math.min(e, n) * 0.02));
782
- v.set(Et(Et(v, e, n, h), e, n, h));
783
- const p = i ? nr(i, t, e, n) : null, g = new Uint8Array(e * n * 4), b = (s, d) => v[Math.max(0, Math.min(n - 1, d)) * e + Math.max(0, Math.min(e - 1, s))];
784
- for (let s = 0; s < n; s++) for (let d = 0; d < e; d++) {
785
- const x = -(b(d + 2, s) - b(d - 2, s)) / (4 * m), w = -(b(d, s + 2) - b(d, s - 2)) / (4 * l), A = Math.hypot(x, w, 1), L = (s * e + d) * 4, z = s * e + d;
775
+ function sr(e, t, n, r, o, s = !0, i) {
776
+ const u = !!o && r[0] === 0 && r[1] === 0 && r[2] === o.image.width && r[3] === o.image.height, y = nr(e, t, n, u), v = new Float32Array(e.length), m = r[2] / t, l = r[3] / n, c = Math.min(m, l), f = Math.min(r[2], r[3]) * 0.08;
777
+ for (let a = 0; a < n; a++) for (let d = 0; d < t; d++) {
778
+ const x = a * t + d;
779
+ v[x] = (s ? Math.sqrt(y[x] * c * f) * 0.55 : 0) + (o ? rr(r[0] + (d + 0.5) * m, r[1] + (a + 0.5) * l, o) : 0);
780
+ }
781
+ const h = Math.max(1, Math.round(Math.min(t, n) * 0.02));
782
+ v.set(Et(Et(v, t, n, h), t, n, h));
783
+ const p = i ? or(i, e, t, n) : null, g = new Uint8Array(t * n * 4), b = (a, d) => v[Math.max(0, Math.min(n - 1, d)) * t + Math.max(0, Math.min(t - 1, a))];
784
+ for (let a = 0; a < n; a++) for (let d = 0; d < t; d++) {
785
+ const x = -(b(d + 2, a) - b(d - 2, a)) / (4 * m), w = -(b(d, a + 2) - b(d, a - 2)) / (4 * l), A = Math.hypot(x, w, 1), L = (a * t + d) * 4, z = a * t + d;
786
786
  g[L] = Math.round((x / A * 0.5 + 0.5) * 255), g[L + 1] = Math.round((w / A * 0.5 + 0.5) * 255), g[L + 2] = Math.round(((p?.[2 * z] ?? 0) * 0.5 + 0.5) * 255), g[L + 3] = Math.round(((p?.[2 * z + 1] ?? 0) * 0.5 + 0.5) * 255);
787
787
  }
788
788
  return g;
789
789
  }
790
- const hn = /* @__PURE__ */ new WeakMap();
791
- function or(t, e, n, r) {
792
- const o = JSON.stringify([e, n.head, n.body.chest, n.face.nose, n.cheeks, r]), a = hn.get(t);
793
- if (a?.key === o) return { ...a, computed: !1, ms: 0 };
794
- const i = performance.now(), u = Math.min(1, 512 / Math.max(t.width, t.height)), y = Math.max(1, Math.round(t.width * u)), v = Math.max(1, Math.round(t.height * u)), m = document.createElement("canvas");
790
+ const un = /* @__PURE__ */ new WeakMap();
791
+ function ar(e, t, n, r) {
792
+ const o = JSON.stringify([t, n.head, n.body.chest, n.face.nose, n.cheeks, r]), s = un.get(e);
793
+ if (s?.key === o) return { ...s, computed: !1, ms: 0 };
794
+ const i = performance.now(), u = Math.min(1, 512 / Math.max(e.width, e.height)), y = Math.max(1, Math.round(e.width * u)), v = Math.max(1, Math.round(e.height * u)), m = document.createElement("canvas");
795
795
  m.width = y, m.height = v;
796
796
  const l = m.getContext("2d", { willReadFrequently: !0 });
797
- l.drawImage(t, 0, 0, y, v);
797
+ l.drawImage(e, 0, 0, y, v);
798
798
  const c = l.getImageData(0, 0, y, v).data, f = new Uint8Array(y * v), h = new Float32Array(y * v);
799
799
  for (let g = 0; g < f.length; g++)
800
800
  f[g] = c[4 * g + 3], h[g] = (0.2126 * c[4 * g] + 0.7152 * c[4 * g + 1] + 0.0722 * c[4 * g + 2]) / 255;
801
- const p = { key: o, data: rr(f, y, v, e, n, r, r ? h : void 0), width: y, height: v };
802
- return hn.set(t, p), { ...p, computed: !0, ms: performance.now() - i };
801
+ const p = { key: o, data: sr(f, y, v, t, n, r, r ? h : void 0), width: y, height: v };
802
+ return un.set(e, p), { ...p, computed: !0, ms: performance.now() - i };
803
803
  }
804
804
  const et = Object.freeze({
805
805
  enabled: !1,
@@ -818,7 +818,7 @@ const et = Object.freeze({
818
818
  specular: 0.12,
819
819
  rim: 0.3,
820
820
  detail: 0.4
821
- }), un = {
821
+ }), fn = {
822
822
  x: [0, 1],
823
823
  y: [0, 1],
824
824
  z: [0.1, 2],
@@ -832,28 +832,28 @@ const et = Object.freeze({
832
832
  specular: [0, 1],
833
833
  rim: [0, 1],
834
834
  detail: [0, 1]
835
- }, ar = /* @__PURE__ */ new Set(["color", "ambientColor"]);
836
- function sr(t) {
837
- if (!t || typeof t != "object" || Array.isArray(t)) return null;
838
- const e = t;
839
- if (Object.keys(e).length !== Object.keys(et).length || Object.keys(e).some((r) => !(r in et)) || ![!0, !1].includes(e.enabled) || ![!0, !1].includes(e.shadow) || !["soft", "cel"].includes(e.mode)) return null;
840
- const n = { ...et, enabled: e.enabled, shadow: e.shadow, mode: e.mode };
841
- for (const r of Object.keys(un)) {
842
- const o = e[r], [a, i] = un[r];
843
- if (typeof o != "number" || !Number.isFinite(o) || ar.has(r) && !Number.isInteger(o)) return null;
844
- n[r] = Math.max(a, Math.min(i, o));
835
+ }, ir = /* @__PURE__ */ new Set(["color", "ambientColor"]);
836
+ function lr(e) {
837
+ if (!e || typeof e != "object" || Array.isArray(e)) return null;
838
+ const t = e;
839
+ if (Object.keys(t).length !== Object.keys(et).length || Object.keys(t).some((r) => !(r in et)) || ![!0, !1].includes(t.enabled) || ![!0, !1].includes(t.shadow) || !["soft", "cel"].includes(t.mode)) return null;
840
+ const n = { ...et, enabled: t.enabled, shadow: t.shadow, mode: t.mode };
841
+ for (const r of Object.keys(fn)) {
842
+ const o = t[r], [s, i] = fn[r];
843
+ if (typeof o != "number" || !Number.isFinite(o) || ir.has(r) && !Number.isInteger(o)) return null;
844
+ n[r] = Math.max(s, Math.min(i, o));
845
845
  }
846
846
  return n;
847
847
  }
848
- function xo(t) {
849
- return `#${t.toString(16).padStart(6, "0")}`;
848
+ function Eo(e) {
849
+ return `#${e.toString(16).padStart(6, "0")}`;
850
850
  }
851
- const wt = -0.1, ir = 0.9, lr = 1, cr = 1.06;
852
- function hr(t, e) {
853
- return [(0.5 - t) * 0.12, (0.5 - e) * 0.12];
851
+ const wt = -0.1, cr = 0.9, hr = 1, ur = 1.06;
852
+ function fr(e, t) {
853
+ return [(0.5 - e) * 0.12, (0.5 - t) * 0.12];
854
854
  }
855
- function ur(t, e, n, r) {
856
- const o = t * Math.PI / 180, a = e * Math.PI / 180, i = -n / 30 * r, u = Math.cos(o), y = Math.sin(o), v = Math.cos(a), m = Math.sin(a), l = Math.cos(i), c = Math.sin(i);
855
+ function mr(e, t, n, r) {
856
+ const o = e * Math.PI / 180, s = t * Math.PI / 180, i = -n / 30 * r, u = Math.cos(o), y = Math.sin(o), v = Math.cos(s), m = Math.sin(s), l = Math.cos(i), c = Math.sin(i);
857
857
  return [
858
858
  l * u,
859
859
  c * u,
@@ -866,9 +866,9 @@ function ur(t, e, n, r) {
866
866
  u * v
867
867
  ];
868
868
  }
869
- class fr {
870
- constructor(e, n) {
871
- this.gl = e, this.program = n(e, `#version 300 es
869
+ class pr {
870
+ constructor(t, n) {
871
+ this.gl = t, this.program = n(t, `#version 300 es
872
872
  out vec2 vUv;
873
873
  void main() { vec2 p = vec2(float((gl_VertexID << 1) & 2), float(gl_VertexID & 2)); vUv = p; gl_Position = vec4(p * 2.0 - 1.0, 0, 1); }`, `#version 300 es
874
874
  precision highp float; in vec2 vUv; out vec4 o;
@@ -881,34 +881,34 @@ class fr {
881
881
  a += (alphaAt(p + uStep * 1.384615) + alphaAt(p - uStep * 1.384615)) * 0.316216;
882
882
  a += (alphaAt(p + uStep * 3.230769) + alphaAt(p - uStep * 3.230769)) * 0.070270;
883
883
  o = uPass == 0 ? vec4(0, 0, 0, a) : vec4(vec3(0.035, 0.045, 0.065) * a * 0.28, a * 0.28);
884
- }`), this.vao = e.createVertexArray(), this.targets = [];
884
+ }`), this.vao = t.createVertexArray(), this.targets = [];
885
885
  }
886
- target(e, n) {
887
- const r = this.gl, o = r.createTexture(), a = r.createFramebuffer();
888
- if (r.bindTexture(r.TEXTURE_2D, o), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, e, n, 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, a), r.framebufferTexture2D(r.FRAMEBUFFER, r.COLOR_ATTACHMENT0, r.TEXTURE_2D, o, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
889
- return { texture: o, framebuffer: a };
886
+ target(t, n) {
887
+ const r = this.gl, o = r.createTexture(), s = r.createFramebuffer();
888
+ if (r.bindTexture(r.TEXTURE_2D, o), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, t, n, 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, o, 0), r.checkFramebufferStatus(r.FRAMEBUFFER) !== r.FRAMEBUFFER_COMPLETE) throw new Error("Shadow framebuffer unavailable");
889
+ return { texture: o, framebuffer: s };
890
890
  }
891
- begin(e, n) {
891
+ begin(t, n) {
892
892
  const r = this.gl;
893
- (this.width !== e || this.height !== n) && (this.clearTargets(), this.width = e, this.height = n, this.targets = [this.target(e, n), this.target(Math.ceil(e / 2), Math.ceil(n / 2))]), r.bindFramebuffer(r.FRAMEBUFFER, this.targets[0].framebuffer), r.viewport(0, 0, e, n), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT);
893
+ (this.width !== t || this.height !== n) && (this.clearTargets(), this.width = t, this.height = n, this.targets = [this.target(t, n), this.target(Math.ceil(t / 2), Math.ceil(n / 2))]), r.bindFramebuffer(r.FRAMEBUFFER, this.targets[0].framebuffer), r.viewport(0, 0, t, n), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT);
894
894
  }
895
- composite(e) {
896
- const n = this.gl, { prog: r, u: o } = this.program, a = this.width, i = this.height;
897
- n.useProgram(r), n.bindVertexArray(this.vao), n.activeTexture(n.TEXTURE0), n.uniform1i(o.uTex, 0), n.disable(n.BLEND), n.bindFramebuffer(n.FRAMEBUFFER, this.targets[1].framebuffer), n.viewport(0, 0, Math.ceil(a / 2), Math.ceil(i / 2)), n.bindTexture(n.TEXTURE_2D, this.targets[0].texture), n.uniform1i(o.uPass, 0), n.uniform2f(o.uShift, 0, 0), n.uniform2f(o.uStep, 3 / a, 0), n.drawArrays(n.TRIANGLES, 0, 3), n.bindFramebuffer(n.FRAMEBUFFER, null), n.viewport(0, 0, a, i), n.clearColor(0, 0, 0, 0), n.clear(n.COLOR_BUFFER_BIT), n.enable(n.BLEND), n.bindTexture(n.TEXTURE_2D, this.targets[1].texture);
898
- const u = hr(e.x, e.y);
895
+ composite(t) {
896
+ const n = this.gl, { prog: r, u: o } = this.program, s = this.width, i = this.height;
897
+ n.useProgram(r), n.bindVertexArray(this.vao), n.activeTexture(n.TEXTURE0), n.uniform1i(o.uTex, 0), n.disable(n.BLEND), n.bindFramebuffer(n.FRAMEBUFFER, this.targets[1].framebuffer), n.viewport(0, 0, Math.ceil(s / 2), Math.ceil(i / 2)), n.bindTexture(n.TEXTURE_2D, this.targets[0].texture), n.uniform1i(o.uPass, 0), n.uniform2f(o.uShift, 0, 0), n.uniform2f(o.uStep, 3 / s, 0), n.drawArrays(n.TRIANGLES, 0, 3), n.bindFramebuffer(n.FRAMEBUFFER, null), n.viewport(0, 0, s, i), n.clearColor(0, 0, 0, 0), n.clear(n.COLOR_BUFFER_BIT), n.enable(n.BLEND), n.bindTexture(n.TEXTURE_2D, this.targets[1].texture);
898
+ const u = fr(t.x, t.y);
899
899
  n.uniform1i(o.uPass, 1), n.uniform2f(o.uShift, u[0], -u[1]), n.uniform2f(o.uStep, 0, 3 / i), n.drawArrays(n.TRIANGLES, 0, 3), n.bindTexture(n.TEXTURE_2D, this.targets[0].texture), n.uniform1i(o.uPass, 2), n.drawArrays(n.TRIANGLES, 0, 3), n.bindVertexArray(null);
900
900
  }
901
901
  clearTargets() {
902
- for (const e of this.targets)
903
- this.gl.deleteTexture(e.texture), this.gl.deleteFramebuffer(e.framebuffer);
902
+ for (const t of this.targets)
903
+ this.gl.deleteTexture(t.texture), this.gl.deleteFramebuffer(t.framebuffer);
904
904
  this.targets = [];
905
905
  }
906
906
  destroy() {
907
907
  this.clearTargets(), this.gl.deleteProgram(this.program.prog), this.gl.deleteVertexArray(this.vao);
908
908
  }
909
909
  }
910
- function mr(t, e) {
911
- const { IMG: n, EYES: r, MOUTH: o, CHEEKS: a } = t, i = `#version 300 es
910
+ function dr(e, t) {
911
+ const { IMG: n, EYES: r, MOUTH: o, CHEEKS: s } = e, i = `#version 300 es
912
912
  in vec2 aPos; in vec2 aUv;
913
913
  uniform vec2 uScale; uniform vec2 uOffset;
914
914
  out vec2 vUv;
@@ -1028,7 +1028,7 @@ function mr(t, e) {
1028
1028
  vec4 encoded = texture(uNormal, vUv);
1029
1029
  vec2 base = encoded.rg * 2.0 - 1.0;
1030
1030
  vec3 n = vec3(base, sqrt(max(0.0, 1.0 - dot(base, base))));
1031
- n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${ir.toFixed(3)}, 0.0));
1031
+ n = normalize(n + vec3((encoded.ba * 2.0 - 1.0) * uSurface.w * ${cr.toFixed(3)}, 0.0));
1032
1032
  n = normalize(mix(n, uHeadRotation * n, vHeadWeight));
1033
1033
  vec2 toLight = (uLight.xy - vScreen) * vec2(uAspect, 1.0);
1034
1034
  vec3 light = normalize(vec3(toLight, uLight.z));
@@ -1045,12 +1045,12 @@ function mr(t, e) {
1045
1045
  float attenuation = 1.0 / (1.0 + reach);
1046
1046
  vec3 radiance = uLightColor * uLighting.y * attenuation;
1047
1047
  // A light close to the surface may brighten a little, but must not bleach painted colours.
1048
- vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${cr.toFixed(3)}));
1048
+ vec3 irradiance = min(uAmbientColor * uLighting.z + radiance * diffuse, vec3(${ur.toFixed(3)}));
1049
1049
  // Painted shadows are deeper versions of the base colour, not grey: multiply by the colour
1050
1050
  // itself as the surface turns away from the light.
1051
1051
  vec3 albedo = c.rgb / max(c.a, 1e-4);
1052
1052
  float dark = 1.0 - clamp(dot(irradiance, vec3(0.3333)), 0.0, 1.0);
1053
- vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${lr.toFixed(3)}) * irradiance;
1053
+ vec3 shaded = c.rgb * mix(vec3(1.0), albedo, dark * ${hr.toFixed(3)}) * irradiance;
1054
1054
  float specular = pow(max(dot(n, normalize(light + vec3(0.0, 0.0, 1.0))), 0.0), 60.0) * uSurface.y;
1055
1055
  if (uCel == 1) specular = smoothstep(0.3, 0.35, specular) * uSurface.y;
1056
1056
  vec2 side = length(n.xy) > 0.001 ? normalize(n.xy) : vec2(0.0);
@@ -1062,9 +1062,9 @@ function mr(t, e) {
1062
1062
  in vec2 aPos; uniform vec2 uScale; uniform vec2 uOffset;
1063
1063
  void main() { gl_Position = vec4(aPos * uScale + uOffset, 0.0, 1.0); gl_PointSize = 7.0; }`, l = `#version 300 es
1064
1064
  precision mediump float; uniform vec4 uColor; out vec4 o; void main() { o = uColor; }`;
1065
- function c(g, b, s) {
1065
+ function c(g, b, a) {
1066
1066
  const d = g.createProgram();
1067
- for (const [A, L] of [[g.VERTEX_SHADER, b], [g.FRAGMENT_SHADER, s]]) {
1067
+ for (const [A, L] of [[g.VERTEX_SHADER, b], [g.FRAGMENT_SHADER, a]]) {
1068
1068
  const z = g.createShader(A);
1069
1069
  if (g.shaderSource(z, L), g.compileShader(z), !g.getShaderParameter(z, g.COMPILE_STATUS)) throw new Error(g.getShaderInfoLog(z));
1070
1070
  g.attachShader(d, z), g.deleteShader(z);
@@ -1077,51 +1077,51 @@ function mr(t, e) {
1077
1077
  }
1078
1078
  return { prog: d, u: x };
1079
1079
  }
1080
- function f(g, b, s, d) {
1080
+ function f(g, b, a, d) {
1081
1081
  const x = [g];
1082
1082
  let w = g;
1083
1083
  for (; w < g + b - 0.5; ) {
1084
- const A = d && w >= d.from && w < d.to ? d.cell : s;
1084
+ const A = d && w >= d.from && w < d.to ? d.cell : a;
1085
1085
  w = Math.min(g + b, w + A), x.push(w);
1086
1086
  }
1087
1087
  return x;
1088
1088
  }
1089
- function h(g, b, s, d, x = null) {
1089
+ function h(g, b, a, d, x = null) {
1090
1090
  const [w, A, L, z] = g, Y = f(w, L, b, x && { from: x.x0, to: x.x1, cell: x.cell }), I = f(A, z, b, x && { from: x.y0, to: x.y1, cell: x.cell }), U = Y.length - 1, T = I.length - 1, F = (U + 1) * (T + 1), j = new Float32Array(F * 2), C = new Float32Array(F * 2);
1091
1091
  for (let Q = 0; Q <= T; Q++) for (let J = 0; J <= U; J++) {
1092
1092
  const X = Q * (U + 1) + J;
1093
1093
  j[X * 2] = Y[J], j[X * 2 + 1] = I[Q], C[X * 2] = (Y[J] - w) / L, C[X * 2 + 1] = (I[Q] - A) / z;
1094
1094
  }
1095
- const B = [], H = [], N = s.length / d, ne = d === 1 ? 0 : 1;
1095
+ const B = [], H = [], N = a.length / d, ne = d === 1 ? 0 : 1;
1096
1096
  for (let Q = 0; Q < T; Q++) for (let J = 0; J < U; J++) {
1097
1097
  const X = Math.floor(Y[J] - w) * ne - 2, G = Math.ceil(Y[J + 1] - w) * ne + 2, re = Math.floor(I[Q] - A) * ne - 2, W = Math.ceil(I[Q + 1] - A) * ne + 2;
1098
1098
  let te = !1;
1099
1099
  for (let O = Math.max(0, re); O < Math.min(N, W) && !te; O += 1)
1100
1100
  for (let k = Math.max(0, X); k < Math.min(d, G); k += 1)
1101
- if (s[O * d + k] > 3) {
1101
+ if (a[O * d + k] > 3) {
1102
1102
  te = !0;
1103
1103
  break;
1104
1104
  }
1105
1105
  if (!te) continue;
1106
- const se = Q * (U + 1) + J, V = se + 1, M = se + U + 1, E = M + 1;
1107
- B.push(se, V, M, V, E, M), H.push(se, V, se, M, V, M), J === U - 1 && H.push(V, E), Q === T - 1 && H.push(M, E);
1106
+ const ae = Q * (U + 1) + J, V = ae + 1, M = ae + U + 1, E = M + 1;
1107
+ B.push(ae, V, M, V, E, M), H.push(ae, V, ae, M, V, M), J === U - 1 && H.push(V, E), Q === T - 1 && H.push(M, E);
1108
1108
  }
1109
1109
  return { rect: g, cols: U, rows: T, rest: j, uv: C, pos: new Float32Array(j), tris: new Uint32Array(B), lines: new Uint32Array(H) };
1110
1110
  }
1111
1111
  class p {
1112
1112
  // padTop / padSide: margin around the image, as a share of its height / width. A negative
1113
1113
  // padTop pushes the top of the image above the canvas (hides a cut-off top edge).
1114
- constructor(b, { padTop: s = 0, padSide: d = 0, fit: x = "contain" } = {}) {
1115
- this.pad = { top: s, side: d }, this.fit = x;
1114
+ constructor(b, { padTop: a = 0, padSide: d = 0, fit: x = "contain" } = {}) {
1115
+ this.pad = { top: a, side: d }, this.fit = x;
1116
1116
  const w = b.getContext("webgl2", { premultipliedAlpha: !0, antialias: !0, alpha: !0, preserveDrawingBuffer: !0 });
1117
1117
  if (!w) throw new Error("WebGL2 is not available");
1118
1118
  this.gl = w, this.canvas = b, this.main = c(w, i, u), this.line = c(w, m, l), this.layers = [], this.lighting = et, this.lightingStats = { normalMs: 0, computedLayers: 0, cachedLayers: 0 }, w.enable(w.BLEND), w.blendFunc(w.ONE, w.ONE_MINUS_SRC_ALPHA);
1119
1119
  }
1120
1120
  texture(b) {
1121
- const s = this.gl, d = s.createTexture();
1122
- return s.bindTexture(s.TEXTURE_2D, d), s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, s.RGBA, s.UNSIGNED_BYTE, b), 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), d;
1121
+ const a = this.gl, d = a.createTexture();
1122
+ return a.bindTexture(a.TEXTURE_2D, d), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, a.RGBA, a.UNSIGNED_BYTE, b), a.generateMipmap(a.TEXTURE_2D), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR_MIPMAP_LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE), d;
1123
1123
  }
1124
- addLayer(b, s, d, x = {}) {
1124
+ addLayer(b, a, d, x = {}) {
1125
1125
  const w = this.gl, A = w.createVertexArray();
1126
1126
  w.bindVertexArray(A);
1127
1127
  const L = w.createBuffer();
@@ -1138,96 +1138,96 @@ function mr(t, e) {
1138
1138
  w.bindBuffer(w.ELEMENT_ARRAY_BUFFER, I), w.bufferData(w.ELEMENT_ARRAY_BUFFER, d.tris, w.STATIC_DRAW), w.bindVertexArray(null);
1139
1139
  const U = w.createBuffer();
1140
1140
  w.bindBuffer(w.ELEMENT_ARRAY_BUFFER, U), w.bufferData(w.ELEMENT_ARRAY_BUFFER, d.lines, w.STATIC_DRAW);
1141
- const T = { name: b, image: s, mesh: d, tex: this.texture(s), vao: A, posBuf: L, uvBuf: z, triBuf: I, lineBuf: U, visible: !0, face: !!x.face, eyeBall: x.eyeBall, color: x.color || [1, 1, 1, 1] };
1141
+ const T = { name: b, image: a, mesh: d, tex: this.texture(a), vao: A, posBuf: L, uvBuf: z, triBuf: I, lineBuf: U, visible: !0, face: !!x.face, eyeBall: x.eyeBall, color: x.color || [1, 1, 1, 1] };
1142
1142
  return this.layers.push(T), T;
1143
1143
  }
1144
1144
  destroy() {
1145
1145
  const b = this.gl;
1146
- for (const s of this.layers) {
1147
- b.deleteTexture(s.tex), s.normal && b.deleteTexture(s.normal), s.headBuf && b.deleteBuffer(s.headBuf), b.deleteVertexArray(s.vao);
1148
- for (const d of [s.posBuf, s.uvBuf, s.triBuf, s.lineBuf]) b.deleteBuffer(d);
1146
+ for (const a of this.layers) {
1147
+ b.deleteTexture(a.tex), a.normal && b.deleteTexture(a.normal), a.headBuf && b.deleteBuffer(a.headBuf), b.deleteVertexArray(a.vao);
1148
+ for (const d of [a.posBuf, a.uvBuf, a.triBuf, a.lineBuf]) b.deleteBuffer(d);
1149
1149
  }
1150
1150
  b.deleteProgram(this.main.prog), b.deleteProgram(this.line.prog), this.lit && b.deleteProgram(this.lit.prog), this.shadow?.destroy(), this.layers.length = 0;
1151
1151
  }
1152
1152
  setLighting(b) {
1153
- if (this.lighting = sr({ ...et, ...b }) ?? et, !this.lighting.enabled) return;
1154
- const s = this.gl;
1155
- this.lit || (this.lit = c(s, y, v));
1153
+ if (this.lighting = lr({ ...et, ...b }) ?? et, !this.lighting.enabled) return;
1154
+ const a = this.gl;
1155
+ this.lit || (this.lit = c(a, y, v));
1156
1156
  for (const d of this.layers) {
1157
1157
  if (d.normal || d.overlay) continue;
1158
- const x = or(d.image, d.mesh.rect, e, !/^(eye|mouth)/.test(d.name));
1159
- this.lightingStats.normalMs += x.ms, this.lightingStats[x.computed ? "computedLayers" : "cachedLayers"]++, d.normal = s.createTexture(), s.activeTexture(s.TEXTURE0), s.bindTexture(s.TEXTURE_2D, d.normal), s.pixelStorei(s.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, x.width, x.height, 0, s.RGBA, s.UNSIGNED_BYTE, x.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);
1158
+ const x = ar(d.image, d.mesh.rect, t, !/^(eye|mouth)/.test(d.name));
1159
+ this.lightingStats.normalMs += x.ms, this.lightingStats[x.computed ? "computedLayers" : "cachedLayers"]++, d.normal = a.createTexture(), a.activeTexture(a.TEXTURE0), a.bindTexture(a.TEXTURE_2D, d.normal), a.pixelStorei(a.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), a.texImage2D(a.TEXTURE_2D, 0, a.RGBA, x.width, x.height, 0, a.RGBA, a.UNSIGNED_BYTE, x.data), a.generateMipmap(a.TEXTURE_2D), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MIN_FILTER, a.LINEAR_MIPMAP_LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_MAG_FILTER, a.LINEAR), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_S, a.CLAMP_TO_EDGE), a.texParameteri(a.TEXTURE_2D, a.TEXTURE_WRAP_T, a.CLAMP_TO_EDGE);
1160
1160
  const w = new Float32Array(d.mesh.rest.length / 2);
1161
- for (let A = 0; A < w.length; A++) w[A] = t.headWeight(d.mesh.rest[A * 2], d.mesh.rest[A * 2 + 1]);
1162
- d.headBuf = s.createBuffer(), s.bindVertexArray(d.vao), s.bindBuffer(s.ARRAY_BUFFER, d.headBuf), s.bufferData(s.ARRAY_BUFFER, w, s.STATIC_DRAW), s.enableVertexAttribArray(2), s.vertexAttribPointer(2, 1, s.FLOAT, !1, 0, 0);
1161
+ for (let A = 0; A < w.length; A++) w[A] = e.headWeight(d.mesh.rest[A * 2], d.mesh.rest[A * 2 + 1]);
1162
+ d.headBuf = a.createBuffer(), a.bindVertexArray(d.vao), a.bindBuffer(a.ARRAY_BUFFER, d.headBuf), a.bufferData(a.ARRAY_BUFFER, w, a.STATIC_DRAW), a.enableVertexAttribArray(2), a.vertexAttribPointer(2, 1, a.FLOAT, !1, 0, 0);
1163
1163
  }
1164
- s.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new fr(s, c));
1164
+ a.bindVertexArray(null), this.lighting.shadow && !this.shadow && (this.shadow = new pr(a, c));
1165
1165
  }
1166
1166
  resize() {
1167
- const b = this.canvas, s = Math.min(window.devicePixelRatio || 1, 2), d = Math.round(b.clientWidth * s), x = Math.round(b.clientHeight * s);
1167
+ const b = this.canvas, a = Math.min(window.devicePixelRatio || 1, 2), d = Math.round(b.clientWidth * a), x = Math.round(b.clientHeight * a);
1168
1168
  (b.width !== d || b.height !== x) && (b.width = d, b.height = x);
1169
1169
  const w = (this.fit === "cover" ? Math.max : Math.min)(d / (n.w * (1 + 2 * this.pad.side)), x / (n.h * (1 + this.pad.top))), A = (d - n.w * w) / 2, L = (x - n.h * w) / (this.fit === "cover" ? 2 : 1);
1170
1170
  this.scale = [2 * w / d, -2 * w / x], this.offset = [-1 + 2 * A / d, 1 - 2 * L / x], this.pxScale = w, this.pxOff = [A, L];
1171
1171
  }
1172
1172
  draw(b) {
1173
- const s = this.gl;
1174
- this.resize(), s.viewport(0, 0, this.canvas.width, this.canvas.height), s.clearColor(0, 0, 0, 0), s.clear(s.COLOR_BUFFER_BIT);
1173
+ const a = this.gl;
1174
+ this.resize(), a.viewport(0, 0, this.canvas.width, this.canvas.height), a.clearColor(0, 0, 0, 0), a.clear(a.COLOR_BUFFER_BIT);
1175
1175
  const d = this.lighting.enabled, x = d && this.lighting.shadow;
1176
1176
  x && this.shadow.begin(this.canvas.width, this.canvas.height);
1177
1177
  const w = d ? this.lit : this.main;
1178
- if (this.current = w, s.useProgram(w.prog), d) {
1178
+ if (this.current = w, a.useProgram(w.prog), d) {
1179
1179
  const A = this.lighting;
1180
- s.uniform1i(w.u.uNormal, 1), s.uniform3f(w.u.uLight, A.x, A.y, A.z), s.uniform3f(w.u.uLightColor, (A.color >> 16 & 255) / 255, (A.color >> 8 & 255) / 255, (A.color & 255) / 255), s.uniform3f(w.u.uAmbientColor, (A.ambientColor >> 16 & 255) / 255, (A.ambientColor >> 8 & 255) / 255, (A.ambientColor & 255) / 255), s.uniform4f(w.u.uLighting, A.strength, A.intensity, A.ambient, A.reach), s.uniform4f(w.u.uSurface, A.softness, A.specular, A.rim, A.detail), s.uniform1f(w.u.uAspect, this.canvas.width / this.canvas.height), s.uniform1i(w.u.uCel, A.mode === "cel" ? 1 : 0), s.uniformMatrix3fv(w.u.uHeadRotation, !1, ur(b.angleX ?? 0, b.angleY ?? 0, b.angleZ ?? 0, e.head.maxRoll));
1180
+ a.uniform1i(w.u.uNormal, 1), a.uniform3f(w.u.uLight, A.x, A.y, A.z), a.uniform3f(w.u.uLightColor, (A.color >> 16 & 255) / 255, (A.color >> 8 & 255) / 255, (A.color & 255) / 255), a.uniform3f(w.u.uAmbientColor, (A.ambientColor >> 16 & 255) / 255, (A.ambientColor >> 8 & 255) / 255, (A.ambientColor & 255) / 255), a.uniform4f(w.u.uLighting, A.strength, A.intensity, A.ambient, A.reach), a.uniform4f(w.u.uSurface, A.softness, A.specular, A.rim, A.detail), a.uniform1f(w.u.uAspect, this.canvas.width / this.canvas.height), a.uniform1i(w.u.uCel, A.mode === "cel" ? 1 : 0), a.uniformMatrix3fv(w.u.uHeadRotation, !1, mr(b.angleX ?? 0, b.angleY ?? 0, b.angleZ ?? 0, t.head.maxRoll));
1181
1181
  }
1182
- s.uniform2fv(w.u.uScale, this.scale), s.uniform2fv(w.u.uOffset, this.offset), s.uniform1i(w.u.uTex, 0), s.uniform4fv(w.u.uEyeBox, r.flatMap((A) => [A.x0, A.x1, 0, 0])), s.uniform1fv(w.u.uEyeTop, r.flatMap((A) => A.top)), s.uniform1fv(w.u.uEyeBot, r.flatMap((A) => A.bot)), s.uniform4fv(w.u.uEyeState, b.eyes), s.uniform4f(w.u.uMouth, o.cx, o.cy, o.angle, o.halfLen), s.uniform4f(w.u.uMouthState, b.mouthOpen, b.mouthForm, o.bow, 0), s.uniform4f(w.u.uCheeks, a[0][0], a[0][1], a[1][0], a[1][1]), s.uniform1f(w.u.uCheek, b.cheek), s.activeTexture(s.TEXTURE0);
1182
+ a.uniform2fv(w.u.uScale, this.scale), a.uniform2fv(w.u.uOffset, this.offset), a.uniform1i(w.u.uTex, 0), a.uniform4fv(w.u.uEyeBox, r.flatMap((A) => [A.x0, A.x1, 0, 0])), a.uniform1fv(w.u.uEyeTop, r.flatMap((A) => A.top)), a.uniform1fv(w.u.uEyeBot, r.flatMap((A) => A.bot)), a.uniform4fv(w.u.uEyeState, b.eyes), a.uniform4f(w.u.uMouth, o.cx, o.cy, o.angle, o.halfLen), a.uniform4f(w.u.uMouthState, b.mouthOpen, b.mouthForm, o.bow, 0), a.uniform4f(w.u.uCheeks, s[0][0], s[0][1], s[1][0], s[1][1]), a.uniform1f(w.u.uCheek, b.cheek), a.activeTexture(a.TEXTURE0);
1183
1183
  for (const A of this.layers)
1184
1184
  !A.visible || A.overlay || this.drawLayer(A, A.alpha ?? 1);
1185
1185
  if (this.original && b.originalAlpha > 0 && this.drawLayer(this.original, b.originalAlpha), x && this.shadow.composite(this.lighting), b.showMesh) {
1186
1186
  const A = this.line;
1187
- s.useProgram(A.prog), s.uniform2fv(A.u.uScale, this.scale), s.uniform2fv(A.u.uOffset, this.offset);
1187
+ a.useProgram(A.prog), a.uniform2fv(A.u.uScale, this.scale), a.uniform2fv(A.u.uOffset, this.offset);
1188
1188
  for (const L of this.layers)
1189
- !L.visible || L.overlay || (s.bindVertexArray(L.vao), s.bindBuffer(s.ELEMENT_ARRAY_BUFFER, L.lineBuf), s.uniform4fv(A.u.uColor, L.color), s.drawElements(s.LINES, L.mesh.lines.length, s.UNSIGNED_INT, 0), s.bindBuffer(s.ELEMENT_ARRAY_BUFFER, L.triBuf));
1190
- b.joints?.length && this.drawPoints(b.joints), s.bindVertexArray(null);
1189
+ !L.visible || L.overlay || (a.bindVertexArray(L.vao), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, L.lineBuf), a.uniform4fv(A.u.uColor, L.color), a.drawElements(a.LINES, L.mesh.lines.length, a.UNSIGNED_INT, 0), a.bindBuffer(a.ELEMENT_ARRAY_BUFFER, L.triBuf));
1190
+ b.joints?.length && this.drawPoints(b.joints), a.bindVertexArray(null);
1191
1191
  }
1192
1192
  }
1193
- drawLayer(b, s) {
1193
+ drawLayer(b, a) {
1194
1194
  const d = this.gl, x = this.current;
1195
- d.useProgram(x.prog), d.bindVertexArray(b.vao), d.bindBuffer(d.ARRAY_BUFFER, b.posBuf), d.bufferSubData(d.ARRAY_BUFFER, 0, b.mesh.pos), this.lighting.enabled && (d.activeTexture(d.TEXTURE1), d.bindTexture(d.TEXTURE_2D, b.normal), d.activeTexture(d.TEXTURE0)), d.bindTexture(d.TEXTURE_2D, b.tex), d.uniform4fv(x.u.uRect, b.mesh.rect), d.uniform1i(x.u.uFace, b.eyeBall !== void 0 ? 2 + b.eyeBall : b.face ? 1 : 0), d.uniform1f(x.u.uAlpha, s), d.drawElements(d.TRIANGLES, b.mesh.tris.length, d.UNSIGNED_INT, 0);
1195
+ d.useProgram(x.prog), d.bindVertexArray(b.vao), d.bindBuffer(d.ARRAY_BUFFER, b.posBuf), d.bufferSubData(d.ARRAY_BUFFER, 0, b.mesh.pos), this.lighting.enabled && (d.activeTexture(d.TEXTURE1), d.bindTexture(d.TEXTURE_2D, b.normal), d.activeTexture(d.TEXTURE0)), d.bindTexture(d.TEXTURE_2D, b.tex), d.uniform4fv(x.u.uRect, b.mesh.rect), d.uniform1i(x.u.uFace, b.eyeBall !== void 0 ? 2 + b.eyeBall : b.face ? 1 : 0), d.uniform1f(x.u.uAlpha, a), d.drawElements(d.TRIANGLES, b.mesh.tris.length, d.UNSIGNED_INT, 0);
1196
1196
  }
1197
1197
  drawPoints(b) {
1198
- const s = this.gl, d = this.line;
1198
+ const a = this.gl, d = this.line;
1199
1199
  if (!this.pointBuf) {
1200
- this.pointBuf = s.createBuffer(), this.pointVao = s.createVertexArray(), s.bindVertexArray(this.pointVao), s.bindBuffer(s.ARRAY_BUFFER, this.pointBuf);
1201
- const x = s.getAttribLocation(d.prog, "aPos");
1202
- s.enableVertexAttribArray(x), s.vertexAttribPointer(x, 2, s.FLOAT, !1, 0, 0);
1200
+ this.pointBuf = a.createBuffer(), this.pointVao = a.createVertexArray(), a.bindVertexArray(this.pointVao), a.bindBuffer(a.ARRAY_BUFFER, this.pointBuf);
1201
+ const x = a.getAttribLocation(d.prog, "aPos");
1202
+ a.enableVertexAttribArray(x), a.vertexAttribPointer(x, 2, a.FLOAT, !1, 0, 0);
1203
1203
  }
1204
- s.bindVertexArray(this.pointVao), s.bindBuffer(s.ARRAY_BUFFER, this.pointBuf), s.bufferData(s.ARRAY_BUFFER, new Float32Array(b.flat()), s.DYNAMIC_DRAW), s.uniform4f(d.u.uColor, 1, 0.85, 0.2, 1), s.drawArrays(s.POINTS, 0, b.length);
1204
+ a.bindVertexArray(this.pointVao), a.bindBuffer(a.ARRAY_BUFFER, this.pointBuf), a.bufferData(a.ARRAY_BUFFER, new Float32Array(b.flat()), a.DYNAMIC_DRAW), a.uniform4f(d.u.uColor, 1, 0.85, 0.2, 1), a.drawArrays(a.POINTS, 0, b.length);
1205
1205
  }
1206
1206
  // canvas CSS px -> source image px
1207
- toImage(b, s) {
1207
+ toImage(b, a) {
1208
1208
  if (!this.pxOff) return null;
1209
1209
  const d = this.canvas.width / this.canvas.clientWidth;
1210
- return [(b * d - this.pxOff[0]) / this.pxScale, (s * d - this.pxOff[1]) / this.pxScale];
1210
+ return [(b * d - this.pxOff[0]) / this.pxScale, (a * d - this.pxOff[1]) / this.pxScale];
1211
1211
  }
1212
1212
  }
1213
1213
  return { Renderer: p, buildGrid: h };
1214
1214
  }
1215
- function pr(t, e) {
1216
- const { applyHead: n, applyBody: r, TASSELS: o, tasselAnchor: a } = t, i = (e.strands ?? []).map((s) => {
1217
- if (s.nodes.length === 4) return s;
1215
+ function gr(e, t) {
1216
+ const { applyHead: n, applyBody: r, TASSELS: o, tasselAnchor: s } = e, i = (t.strands ?? []).map((a) => {
1217
+ if (a.nodes.length === 4) return a;
1218
1218
  const d = Array.from({ length: 4 }, (x, w) => {
1219
- const A = w / 3 * (s.nodes.length - 1), L = Math.min(s.nodes.length - 2, Math.floor(A)), z = A - L;
1220
- return [0, 1].map((Y) => s.nodes[L][Y] + (s.nodes[L + 1][Y] - s.nodes[L][Y]) * z);
1219
+ const A = w / 3 * (a.nodes.length - 1), L = Math.min(a.nodes.length - 2, Math.floor(A)), z = A - L;
1220
+ return [0, 1].map((Y) => a.nodes[L][Y] + (a.nodes[L + 1][Y] - a.nodes[L][Y]) * z);
1221
1221
  });
1222
- return { ...s, nodes: d };
1223
- }), u = [0, 300, 200, 140], y = 0.9, v = 7, m = { 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), c = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, f = (s, d) => [s[0] * Math.cos(d) - s[1] * Math.sin(d), s[0] * Math.sin(d) + s[1] * Math.cos(d)], h = (s, d) => {
1224
- const x = Math.hypot(s[0], s[1]);
1225
- if (x < 1e-6) return s;
1222
+ return { ...a, nodes: d };
1223
+ }), u = [0, 300, 200, 140], y = 0.9, v = 7, m = { stiff: 1.7, damp: 1.6, couple: 0.85, reach: 0.9, bind: 4 }, l = Math.min(6, i.filter((a) => a.name.startsWith("bang")).length), c = { freq: 0.7, zeta: 0.22, hang: 0.85, inertia: 0.32, wind: 0.03, max: 0.55, smooth: 6 }, f = (a, d) => [a[0] * Math.cos(d) - a[1] * Math.sin(d), a[0] * Math.sin(d) + a[1] * Math.cos(d)], h = (a, d) => {
1224
+ const x = Math.hypot(a[0], a[1]);
1225
+ if (x < 1e-6) return a;
1226
1226
  const w = d * Math.tanh(x / d) / x;
1227
- return [s[0] * w, s[1] * w];
1228
- }, p = Object.fromEntries(Object.entries(e.buns ?? {}).map(([s, d]) => [s, { at: [d.cx, d.cy], k: 260, c: 11, hang: 3, max: 4 }])), g = (s, d) => {
1229
- const x = Math.hypot(s[0], s[1]);
1230
- x > d && (s[0] *= d / x, s[1] *= d / x);
1227
+ return [a[0] * w, a[1] * w];
1228
+ }, p = Object.fromEntries(Object.entries(t.buns ?? {}).map(([a, d]) => [a, { at: [d.cx, d.cy], k: 260, c: 11, hang: 3, max: 4 }])), g = (a, d) => {
1229
+ const x = Math.hypot(a[0], a[1]);
1230
+ x > d && (a[0] *= d / x, a[1] *= d / x);
1231
1231
  };
1232
1232
  class b {
1233
1233
  constructor() {
@@ -1244,8 +1244,8 @@ function pr(t, e) {
1244
1244
  return n(w, 1, x), r(w, d[1], x), w;
1245
1245
  }
1246
1246
  step(d, x) {
1247
- t.stepBody?.(d, x);
1248
- const w = Math.max(1, Math.ceil(x / (1 / 240))), A = Math.min(x, 0.05) / w, L = -d.angleZ / 30 * e.head.maxRoll - d.bodyAngleZ / 10 * e.body.maxRoll, z = this.gain;
1247
+ e.stepBody?.(d, x);
1248
+ const w = Math.max(1, Math.ceil(x / (1 / 240))), A = Math.min(x, 0.05) / w, L = -d.angleZ / 30 * t.head.maxRoll - d.bodyAngleZ / 10 * t.body.maxRoll, z = this.gain;
1249
1249
  i.forEach((I, U) => {
1250
1250
  const T = this.strands[U], F = this.out.strands[U], j = I.nodes.map((B) => this.hairAnchor(B, d));
1251
1251
  T.p || (T.p = j.map((B) => [...B]));
@@ -1253,8 +1253,8 @@ function pr(t, e) {
1253
1253
  for (let B = 0; B < w; B++) {
1254
1254
  const H = this.time + B * A;
1255
1255
  for (let N = 1; N < 4; N++) {
1256
- const ne = Math.hypot(I.nodes[N][0] - I.nodes[0][0], I.nodes[N][1] - I.nodes[0][1]), Q = (Math.sin(H * 1.3) * 0.5 + Math.sin(H * 3.1) * 0.3 + Math.sin(H * 4.7 + C) * 0.2) * I.max * 0.1 * N / 3, J = [T.p[N - 1][0] - j[N - 1][0], T.p[N - 1][1] - j[N - 1][1]], X = j[N][0] + J[0] * y * m.couple - Math.sin(L) * ne * 0.12 + Q, G = j[N][1] + J[1] * y * m.couple, re = u[N] * I.k * m.stiff / Math.max(0.35, z), W = v * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(z)), te = T.v[N], se = T.p[N];
1257
- te[0] += (re * (X - se[0]) - W * te[0]) * A, te[1] += (re * (G - se[1]) - W * te[1]) * A, se[0] += te[0] * A, se[1] += te[1] * A;
1256
+ const ne = Math.hypot(I.nodes[N][0] - I.nodes[0][0], I.nodes[N][1] - I.nodes[0][1]), Q = (Math.sin(H * 1.3) * 0.5 + Math.sin(H * 3.1) * 0.3 + Math.sin(H * 4.7 + C) * 0.2) * I.max * 0.1 * N / 3, J = [T.p[N - 1][0] - j[N - 1][0], T.p[N - 1][1] - j[N - 1][1]], X = j[N][0] + J[0] * y * m.couple - Math.sin(L) * ne * 0.12 + Q, G = j[N][1] + J[1] * y * m.couple, re = u[N] * I.k * m.stiff / Math.max(0.35, z), W = v * m.damp * Math.sqrt(m.stiff) / Math.max(0.5, Math.sqrt(z)), te = T.v[N], ae = T.p[N];
1257
+ te[0] += (re * (X - ae[0]) - W * te[0]) * A, te[1] += (re * (G - ae[1]) - W * te[1]) * A, ae[0] += te[0] * A, ae[1] += te[1] * A;
1258
1258
  }
1259
1259
  T.p[0] = [...j[0]];
1260
1260
  }
@@ -1282,15 +1282,15 @@ function pr(t, e) {
1282
1282
  }
1283
1283
  }
1284
1284
  for (const I of this.chains) {
1285
- const U = a(I.t, d, this.out, [0, 0]);
1285
+ const U = s(I.t, d, this.out, [0, 0]);
1286
1286
  I.st || (I.st = { th: [0, 0], w: [0, 0], pos: [...U], vel: [0, 0], acc: [0, 0] });
1287
1287
  const T = I.st, F = c, j = [(U[0] - T.pos[0]) / Math.max(x, 1e-3), (U[1] - T.pos[1]) / Math.max(x, 1e-3)], C = 1 - Math.exp(-x * F.smooth), B = [(j[0] - T.vel[0]) / Math.max(x, 1e-3), (j[1] - T.vel[1]) / Math.max(x, 1e-3)];
1288
1288
  T.acc = [T.acc[0] + (B[0] - T.acc[0]) * C, T.acc[1] + (B[1] - T.acc[1]) * C], T.vel = [T.vel[0] + (j[0] - T.vel[0]) * C, T.vel[1] + (j[1] - T.vel[1]) * C], T.pos = [...U];
1289
1289
  const H = [-I.dir[1], I.dir[0]], N = -(T.acc[0] * H[0] + T.acc[1] * H[1]) / (I.L1 + I.L2) * F.inertia, ne = (Math.sin(this.time * 0.9 + I.t.pivot[0]) * 0.6 + Math.sin(this.time * 0.37 + I.t.pivot[1]) * 0.4) * F.wind, Q = -L * F.hang + ne, J = 2 * Math.PI * F.freq / Math.sqrt(Math.max(0.4, z)), X = J * 1.35;
1290
1290
  for (let te = 0; te < w; te++) {
1291
- const se = -J * J * (T.th[0] - Q) - 2 * F.zeta * J * T.w[0] + N;
1292
- T.w[0] += se * A, T.th[0] += T.w[0] * A;
1293
- const V = -X * X * (T.th[1] - T.th[0]) - 2 * F.zeta * X * T.w[1] + N * 0.4 + se * 0.5;
1291
+ const ae = -J * J * (T.th[0] - Q) - 2 * F.zeta * J * T.w[0] + N;
1292
+ T.w[0] += ae * A, T.th[0] += T.w[0] * A;
1293
+ const V = -X * X * (T.th[1] - T.th[0]) - 2 * F.zeta * X * T.w[1] + N * 0.4 + ae * 0.5;
1294
1294
  T.w[1] += V * A, T.th[1] += T.w[1] * A;
1295
1295
  }
1296
1296
  T.th[0] = Math.max(-0.55, Math.min(F.max, T.th[0])), T.th[1] = Math.max(-0.55 * 1.4, Math.min(F.max * 1.4, T.th[1])), I.phi = [T.th[0], T.th[1]];
@@ -1302,67 +1302,67 @@ function pr(t, e) {
1302
1302
  }
1303
1303
  return { Physics: b };
1304
1304
  }
1305
- const kn = (t, e) => t.reduce((n, r, o) => n + r * e[o], 0);
1306
- function dr(t, e) {
1307
- const n = e.length, r = Array.from({ length: n }, () => Array(n).fill(0));
1305
+ const _n = (e, t) => e.reduce((n, r, o) => n + r * t[o], 0);
1306
+ function yr(e, t) {
1307
+ const n = t.length, r = Array.from({ length: n }, () => Array(n).fill(0));
1308
1308
  for (let i = 0; i < n; i++) for (let u = 0; u <= i; u++) {
1309
- let y = t[i][u];
1309
+ let y = e[i][u];
1310
1310
  for (let v = 0; v < u; v++) y -= r[i][v] * r[u][v];
1311
1311
  r[i][u] = i === u ? Math.sqrt(Math.max(1e-18, y)) : y / r[u][u];
1312
1312
  }
1313
- const o = [], a = [];
1314
- for (let i = 0; i < n; i++) o[i] = (e[i] - kn(r[i].slice(0, i), o)) / r[i][i];
1313
+ const o = [], s = [];
1314
+ for (let i = 0; i < n; i++) o[i] = (t[i] - _n(r[i].slice(0, i), o)) / r[i][i];
1315
1315
  for (let i = n - 1; i >= 0; i--) {
1316
1316
  let u = o[i];
1317
- for (let y = i + 1; y < n; y++) u -= r[y][i] * a[y];
1318
- a[i] = u / r[i][i];
1317
+ for (let y = i + 1; y < n; y++) u -= r[y][i] * s[y];
1318
+ s[i] = u / r[i][i];
1319
1319
  }
1320
- return a;
1320
+ return s;
1321
1321
  }
1322
- function gr(t) {
1323
- const e = t.map((o) => [...o]), n = e.length, r = e.map((o, a) => e.map((i, u) => +(a === u)));
1322
+ function vr(e) {
1323
+ const t = e.map((o) => [...o]), n = t.length, r = t.map((o, s) => t.map((i, u) => +(s === u)));
1324
1324
  for (let o = 0; o < 100 * n * n; o++) {
1325
- let a = 0, i = 1, u = 0;
1326
- for (let h = 0; h < n; h++) for (let p = h + 1; p < n; p++) Math.abs(e[h][p]) > u && (u = Math.abs(e[h][p]), a = h, i = p);
1325
+ let s = 0, i = 1, u = 0;
1326
+ for (let h = 0; h < n; h++) for (let p = h + 1; p < n; p++) Math.abs(t[h][p]) > u && (u = Math.abs(t[h][p]), s = h, i = p);
1327
1327
  if (u < 1e-12) break;
1328
- const y = 0.5 * Math.atan2(2 * e[a][i], e[i][i] - e[a][a]), v = Math.cos(y), m = Math.sin(y), l = e[a][a], c = e[i][i], f = e[a][i];
1329
- for (let h = 0; h < n; h++) if (h !== a && h !== i) {
1330
- const p = e[h][a], g = e[h][i];
1331
- e[h][a] = e[a][h] = v * p - m * g, e[h][i] = e[i][h] = m * p + v * g;
1328
+ const y = 0.5 * Math.atan2(2 * t[s][i], t[i][i] - t[s][s]), v = Math.cos(y), m = Math.sin(y), l = t[s][s], c = t[i][i], f = t[s][i];
1329
+ for (let h = 0; h < n; h++) if (h !== s && h !== i) {
1330
+ const p = t[h][s], g = t[h][i];
1331
+ t[h][s] = t[s][h] = v * p - m * g, t[h][i] = t[i][h] = m * p + v * g;
1332
1332
  }
1333
- e[a][a] = v * v * l - 2 * m * v * f + m * m * c, e[i][i] = m * m * l + 2 * m * v * f + v * v * c, e[a][i] = e[i][a] = 0;
1333
+ t[s][s] = v * v * l - 2 * m * v * f + m * m * c, t[i][i] = m * m * l + 2 * m * v * f + v * v * c, t[s][i] = t[i][s] = 0;
1334
1334
  for (let h = 0; h < n; h++) {
1335
- const p = r[h][a], g = r[h][i];
1336
- r[h][a] = v * p - m * g, r[h][i] = m * p + v * g;
1335
+ const p = r[h][s], g = r[h][i];
1336
+ r[h][s] = v * p - m * g, r[h][i] = m * p + v * g;
1337
1337
  }
1338
1338
  }
1339
- return { values: e.map((o, a) => o[a]), vectors: r };
1339
+ return { values: t.map((o, s) => o[s]), vectors: r };
1340
1340
  }
1341
- function yr(t, e, n, r = 1) {
1342
- const o = t.map((l, c) => t.slice(c).reduce((f, h) => f + h, 0)), a = t.map((l, c) => t.map((f, h) => o[Math.max(c, h)] * l * f)), i = t.map((l, c) => e * o[c] * l), u = i.map(Math.sqrt), y = gr(a.map((l, c) => l.map((f, h) => f / u[c] / u[h]))), v = y.values.indexOf(Math.max(...y.values)), m = t.map((l, c) => t.map((f, h) => u[c] * u[h] * y.values.reduce((p, g, b) => p + y.vectors[c][b] * y.vectors[h][b] * 2 * n * Math.sqrt(g) * (b === v ? 1 : r), 0)));
1343
- return { lengths: t, mass: o, coefficient: a, stiffness: i, damping: m, frequencies: y.values.map((l) => 1 / Math.sqrt(l) / (2 * Math.PI)).sort((l, c) => l - c), angles: t.map(() => 0), velocities: t.map(() => 0) };
1341
+ function br(e, t, n, r = 1) {
1342
+ const o = e.map((l, c) => e.slice(c).reduce((f, h) => f + h, 0)), s = e.map((l, c) => e.map((f, h) => o[Math.max(c, h)] * l * f)), i = e.map((l, c) => t * o[c] * l), u = i.map(Math.sqrt), y = vr(s.map((l, c) => l.map((f, h) => f / u[c] / u[h]))), v = y.values.indexOf(Math.max(...y.values)), m = e.map((l, c) => e.map((f, h) => u[c] * u[h] * y.values.reduce((p, g, b) => p + y.vectors[c][b] * y.vectors[h][b] * 2 * n * Math.sqrt(g) * (b === v ? 1 : r), 0)));
1343
+ return { lengths: e, mass: o, coefficient: s, stiffness: i, damping: m, frequencies: y.values.map((l) => 1 / Math.sqrt(l) / (2 * Math.PI)).sort((l, c) => l - c), angles: e.map(() => 0), velocities: e.map(() => 0) };
1344
1344
  }
1345
- function _t(t, e = t.angles, n = t.velocities) {
1346
- let r = t.stiffness.reduce((o, a, i) => o + a * (1 - Math.cos(e[i])), 0);
1347
- for (let o = 0; o < e.length; o++) for (let a = 0; a < e.length; a++) r += 0.5 * t.coefficient[o][a] * Math.cos(e[o] - e[a]) * n[o] * n[a];
1345
+ function Ft(e, t = e.angles, n = e.velocities) {
1346
+ let r = e.stiffness.reduce((o, s, i) => o + s * (1 - Math.cos(t[i])), 0);
1347
+ for (let o = 0; o < t.length; o++) for (let s = 0; s < t.length; s++) r += 0.5 * e.coefficient[o][s] * Math.cos(t[o] - t[s]) * n[o] * n[s];
1348
1348
  return r;
1349
1349
  }
1350
- function vr(t, e, n = 0, r = 1) {
1351
- const o = t.angles, a = t.velocities, i = t.coefficient.map((m, l) => m.map((c, f) => c * Math.cos(o[l] - o[f]))), u = o.map((m, l) => kn(i[l], a) + e * (-t.stiffness[l] * r * Math.sin(m) - n * t.mass[l] * t.lengths[l] * Math.cos(m) - t.coefficient[l].reduce((c, f, h) => c + f * Math.sin(m - o[h]) * a[h] * a[h], 0)));
1352
- let y = dr(i.map((m, l) => m.map((c, f) => c + e * t.damping[l][f])), u), v = o.map((m, l) => m + e * y[l]);
1350
+ function wr(e, t, n = 0, r = 1) {
1351
+ const o = e.angles, s = e.velocities, i = e.coefficient.map((m, l) => m.map((c, f) => c * Math.cos(o[l] - o[f]))), u = o.map((m, l) => _n(i[l], s) + t * (-e.stiffness[l] * r * Math.sin(m) - n * e.mass[l] * e.lengths[l] * Math.cos(m) - e.coefficient[l].reduce((c, f, h) => c + f * Math.sin(m - o[h]) * s[h] * s[h], 0)));
1352
+ let y = yr(i.map((m, l) => m.map((c, f) => c + t * e.damping[l][f])), u), v = o.map((m, l) => m + t * y[l]);
1353
1353
  if (n === 0 && r === 1) {
1354
- const m = _t(t), l = _t(t, v, y.map(() => 0)), c = _t(t, v, y);
1354
+ const m = Ft(e), l = Ft(e, v, y.map(() => 0)), c = Ft(e, v, y);
1355
1355
  if (c > m)
1356
1356
  if (l > m)
1357
- v = [...o], y = a.map((f) => f * 0.999);
1357
+ v = [...o], y = s.map((f) => f * 0.999);
1358
1358
  else {
1359
1359
  const f = Math.sqrt(Math.max(0, (m - l) / Math.max(1e-30, c - l)));
1360
1360
  y = y.map((h) => h * f);
1361
1361
  }
1362
1362
  }
1363
- t.angles = v, t.velocities = y;
1363
+ e.angles = v, e.velocities = y;
1364
1364
  }
1365
- const Ln = Object.freeze({
1365
+ const Fn = Object.freeze({
1366
1366
  responseGain: 1,
1367
1367
  swing: 1,
1368
1368
  stiffness: 1,
@@ -1371,38 +1371,38 @@ const Ln = Object.freeze({
1371
1371
  cohesion: 3,
1372
1372
  wind: 0.05,
1373
1373
  max: 20
1374
- }), _n = Object.freeze({ tierGain: 1, highModeDamping: 1 });
1375
- function br(t) {
1376
- if (!t || typeof t != "object" || Array.isArray(t)) throw new TypeError("Expected cloth tuning");
1377
- for (const [e, n] of Object.entries(t)) {
1378
- if (!Object.hasOwn(Ln, e) && !Object.hasOwn(_n, e)) throw new RangeError(`Unknown cloth tuning: ${e}`);
1379
- if (typeof n != "number" || !Number.isFinite(n)) throw new RangeError(`${e}: expected a finite number`);
1380
- if (["tierGain", "highModeDamping", "responseGain", "swing", "stiffness", "damping", "max"].includes(e) && n <= 0) throw new RangeError(`${e}: must be positive`);
1381
- if (["follow", "wind"].includes(e) && (n < 0 || e === "follow" && n > 1)) throw new RangeError(`${e}: out of range`);
1382
- if (e === "cohesion" && (!Number.isInteger(n) || n < 0 || n > 8)) throw new RangeError("cohesion: expected an integer from 0 to 8");
1383
- }
1384
- }
1385
- function fn(t, e) {
1374
+ }), jn = Object.freeze({ tierGain: 1, highModeDamping: 1 });
1375
+ function xr(e) {
1376
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError("Expected cloth tuning");
1377
+ for (const [t, n] of Object.entries(e)) {
1378
+ if (!Object.hasOwn(Fn, t) && !Object.hasOwn(jn, t)) throw new RangeError(`Unknown cloth tuning: ${t}`);
1379
+ if (typeof n != "number" || !Number.isFinite(n)) throw new RangeError(`${t}: expected a finite number`);
1380
+ if (["tierGain", "highModeDamping", "responseGain", "swing", "stiffness", "damping", "max"].includes(t) && n <= 0) throw new RangeError(`${t}: must be positive`);
1381
+ if (["follow", "wind"].includes(t) && (n < 0 || t === "follow" && n > 1)) throw new RangeError(`${t}: out of range`);
1382
+ if (t === "cohesion" && (!Number.isInteger(n) || n < 0 || n > 8)) throw new RangeError("cohesion: expected an integer from 0 to 8");
1383
+ }
1384
+ }
1385
+ function mn(e, t) {
1386
1386
  const n = [0];
1387
- for (let o = 1; o < t.length; o++)
1388
- n.push(n[o - 1] + Math.hypot(t[o][0] - t[o - 1][0], t[o][1] - t[o - 1][1]));
1387
+ for (let o = 1; o < e.length; o++)
1388
+ n.push(n[o - 1] + Math.hypot(e[o][0] - e[o - 1][0], e[o][1] - e[o - 1][1]));
1389
1389
  const r = n.at(-1);
1390
- return Array.from({ length: e }, (o, a) => {
1391
- const i = r * a / (e - 1);
1390
+ return Array.from({ length: t }, (o, s) => {
1391
+ const i = r * s / (t - 1);
1392
1392
  let u = 1;
1393
- for (; u < t.length - 1 && n[u] < i; ) u++;
1393
+ for (; u < e.length - 1 && n[u] < i; ) u++;
1394
1394
  const y = (i - n[u - 1]) / Math.max(1e-9, n[u] - n[u - 1]);
1395
- return [0, 1].map((v) => t[u - 1][v] + (t[u][v] - t[u - 1][v]) * y);
1395
+ return [0, 1].map((v) => e[u - 1][v] + (e[u][v] - e[u - 1][v]) * y);
1396
1396
  });
1397
1397
  }
1398
- function wr(t, e) {
1399
- const { baseWeights: n, deformBase: r } = t, o = { bounceHz: 2.6, zeta: 0.25 }, a = e.legs ? 0.8 / ((Math.hypot(...e.legs.left.ankle.map((c, f) => c - e.legs.left.hip[f])) + Math.hypot(...e.legs.right.ankle.map((c, f) => c - e.legs.right.hip[f]))) / 2) : 1.6 / e.image.height, i = 0.8, u = (e.cloth ?? []).map((c) => {
1400
- const f = Tn(c), h = f.custom ? f.cols : c.columns ?? 8, p = f.custom ? f.rows : c.rows ?? 5, g = fn(c.waist, h), b = fn(c.hem, h), s = new Float64Array(p * h * 2);
1398
+ function Mr(e, t) {
1399
+ const { baseWeights: n, deformBase: r } = e, o = { bounceHz: 2.6, zeta: 0.25 }, s = t.legs ? 0.8 / ((Math.hypot(...t.legs.left.ankle.map((c, f) => c - t.legs.left.hip[f])) + Math.hypot(...t.legs.right.ankle.map((c, f) => c - t.legs.right.hip[f]))) / 2) : 1.6 / t.image.height, i = 0.8, u = (t.cloth ?? []).map((c) => {
1400
+ const f = kn(c), h = f.custom ? f.cols : c.columns ?? 8, p = f.custom ? f.rows : c.rows ?? 5, g = mn(c.waist, h), b = mn(c.hem, h), a = new Float64Array(p * h * 2);
1401
1401
  for (let d = 0; d < p; d++) for (let x = 0; x < h; x++) {
1402
1402
  const w = d / (p - 1), A = (d * h + x) * 2;
1403
- s[A] = g[x][0] + (b[x][0] - g[x][0]) * w, s[A + 1] = g[x][1] + (b[x][1] - g[x][1]) * w;
1403
+ a[A] = g[x][0] + (b[x][0] - g[x][0]) * w, a[A + 1] = g[x][1] + (b[x][1] - g[x][1]) * w;
1404
1404
  }
1405
- return f.custom && s.set(f.rest), {
1405
+ return f.custom && a.set(f.rest), {
1406
1406
  grid: f,
1407
1407
  pendulums: (
1408
1408
  /** @type {ReturnType<typeof pendulumSystem>[]} */
@@ -1410,14 +1410,14 @@ function wr(t, e) {
1410
1410
  ),
1411
1411
  systemKey: null,
1412
1412
  c,
1413
- gravity: 9.80665 / (c.scale === void 0 ? a : c.scale / 1e3),
1414
- tuning: Object.fromEntries(Object.entries({ ...Ln, ..._n }).map(([d, x]) => [d, c[d] ?? x])),
1413
+ gravity: 9.80665 / (c.scale === void 0 ? s : c.scale / 1e3),
1414
+ tuning: Object.fromEntries(Object.entries({ ...Fn, ...jn }).map(([d, x]) => [d, c[d] ?? x])),
1415
1415
  cols: h,
1416
1416
  rows: p,
1417
- rest: s,
1417
+ rest: a,
1418
1418
  top: f.custom ? f.top : g,
1419
1419
  weights: (f.custom ? f.top : g).map(([d, x]) => n(d, x, 0)),
1420
- target: new Float64Array(s.length),
1420
+ target: new Float64Array(a.length),
1421
1421
  previous: null,
1422
1422
  pivotVelocity: new Float64Array(h * 2),
1423
1423
  angle: new Float64Array(h),
@@ -1426,8 +1426,8 @@ function wr(t, e) {
1426
1426
  lowerAngularVelocity: new Float64Array(h),
1427
1427
  bounce: new Float64Array(h),
1428
1428
  bounceVelocity: new Float64Array(h),
1429
- out: Float64Array.from(s),
1430
- physicalOut: Float64Array.from(s),
1429
+ out: Float64Array.from(a),
1430
+ physicalOut: Float64Array.from(a),
1431
1431
  parent: null,
1432
1432
  parentLoc: null,
1433
1433
  meshes: []
@@ -1436,7 +1436,7 @@ function wr(t, e) {
1436
1436
  function v(c, f, h) {
1437
1437
  let p = null;
1438
1438
  for (let g = 0; g < c.rows - 1; g++) for (let b = 0; b < c.cols - 1; b++) {
1439
- const s = [(g * c.cols + b) * 2, (g * c.cols + b + 1) * 2, ((g + 1) * c.cols + b + 1) * 2, ((g + 1) * c.cols + b) * 2], [d, x, w, A, L, z, Y, I] = s.flatMap((j) => [c.rest[j], c.rest[j + 1]]);
1439
+ const a = [(g * c.cols + b) * 2, (g * c.cols + b + 1) * 2, ((g + 1) * c.cols + b + 1) * 2, ((g + 1) * c.cols + b) * 2], [d, x, w, A, L, z, Y, I] = a.flatMap((j) => [c.rest[j], c.rest[j + 1]]);
1440
1440
  let U = 0.5, T = 0.5;
1441
1441
  for (let j = 0; j < 10; j++) {
1442
1442
  const C = d * (1 - U) * (1 - T) + w * U * (1 - T) + L * U * T + Y * (1 - U) * T - f, B = x * (1 - U) * (1 - T) + A * U * (1 - T) + z * U * T + I * (1 - U) * T - h, H = (w - d) * (1 - T) + (L - Y) * T, N = (A - x) * (1 - T) + (z - I) * T, ne = (Y - d) * (1 - U) + (L - w) * U, Q = (I - x) * (1 - U) + (z - A) * U, J = H * Q - N * ne;
@@ -1448,7 +1448,7 @@ function wr(t, e) {
1448
1448
  const j = Math.max(0, Math.min(1, U)), C = Math.max(0, Math.min(1, T)), B = d * (1 - j) * (1 - C) + w * j * (1 - C) + L * j * C + Y * (1 - j) * C, H = x * (1 - j) * (1 - C) + A * j * (1 - C) + z * j * C + I * (1 - j) * C;
1449
1449
  F = Math.hypot(B - f, H - h);
1450
1450
  }
1451
- (!p || F < p.miss) && (p = { q: s, s: U, t: T, miss: F });
1451
+ (!p || F < p.miss) && (p = { q: a, s: U, t: T, miss: F });
1452
1452
  }
1453
1453
  if (p.s = Math.min(c.grid.custom ? 1 : 4, Math.max(c.grid.custom ? 0 : -3, p.s)), p.t = Math.min(c.grid.custom ? 1 : 4, Math.max(c.grid.custom ? 0 : -3, p.t)), c.grid.custom) {
1454
1454
  const g = [0, 0];
@@ -1457,10 +1457,10 @@ function wr(t, e) {
1457
1457
  return p;
1458
1458
  }
1459
1459
  function m(c, f, h) {
1460
- const { q: p, s: g, t: b } = f, s = [(1 - g) * (1 - b), g * (1 - b), g * b, (1 - g) * b];
1460
+ const { q: p, s: g, t: b } = f, a = [(1 - g) * (1 - b), g * (1 - b), g * b, (1 - g) * b];
1461
1461
  h[0] = f.offset?.[0] ?? 0, h[1] = f.offset?.[1] ?? 0;
1462
1462
  for (let d = 0; d < 4; d++)
1463
- h[0] += c[p[d]] * s[d], h[1] += c[p[d] + 1] * s[d];
1463
+ h[0] += c[p[d]] * a[d], h[1] += c[p[d] + 1] * a[d];
1464
1464
  return h;
1465
1465
  }
1466
1466
  for (const c of u) c.c.parent && (c.parent = y[c.c.parent], c.parentLoc = c.top.map(([f, h]) => v(c.parent, f, h)));
@@ -1469,7 +1469,7 @@ function wr(t, e) {
1469
1469
  this.gain = 1, this.time = 0;
1470
1470
  }
1471
1471
  setTuning(f, h) {
1472
- if (br(h), f !== null && !Object.hasOwn(y, f)) throw new RangeError(`Unknown cloth: ${f}`);
1472
+ if (xr(h), f !== null && !Object.hasOwn(y, f)) throw new RangeError(`Unknown cloth: ${f}`);
1473
1473
  for (const p of u) (f === null || p.c.name === f) && Object.assign(p.tuning, h);
1474
1474
  }
1475
1475
  /** Skin a layer mesh (rest/pos arrays in source px) to the named garment. */
@@ -1480,13 +1480,13 @@ function wr(t, e) {
1480
1480
  }
1481
1481
  step(f, h, p) {
1482
1482
  if (h < 0) return;
1483
- const g = Math.min(h, 0.05), b = Math.max(1, Math.ceil(g * 240)), s = g / b, d = [0, 0];
1483
+ const g = Math.min(h, 0.05), b = Math.max(1, Math.ceil(g * 240)), a = g / b, d = [0, 0];
1484
1484
  for (const x of u) {
1485
- const { cols: w, rows: A, rest: L, target: z, out: Y, angle: I, angularVelocity: U, lowerAngle: T, lowerAngularVelocity: F, bounce: j, bounceVelocity: C } = x, { stiffness: B, damping: H, max: N, swing: ne, follow: Q, cohesion: J, wind: X, responseGain: G, tierGain: re, highModeDamping: W } = x.tuning, te = this.gain * (G ?? 1), se = new Float64Array(w * 2), V = new Float64Array(w * 2), M = new Float64Array(w * 2);
1485
+ const { cols: w, rows: A, rest: L, target: z, out: Y, angle: I, angularVelocity: U, lowerAngle: T, lowerAngularVelocity: F, bounce: j, bounceVelocity: C } = x, { stiffness: B, damping: H, max: N, swing: ne, follow: Q, cohesion: J, wind: X, responseGain: G, tierGain: re, highModeDamping: W } = x.tuning, te = this.gain * (G ?? 1), ae = new Float64Array(w * 2), V = new Float64Array(w * 2), M = new Float64Array(w * 2);
1486
1486
  for (let $ = 0; $ < w; $++) {
1487
- x.parent ? m(x.parent.physicalOut, x.parentLoc[$], d) : r(x.top[$][0], x.top[$][1], x.weights[$], f, p, d), se[$ * 2] = d[0], se[$ * 2 + 1] = d[1], x.parent && m(x.parent.out, x.parentLoc[$], d), V[$ * 2] = d[0], V[$ * 2 + 1] = d[1];
1487
+ x.parent ? m(x.parent.physicalOut, x.parentLoc[$], d) : r(x.top[$][0], x.top[$][1], x.weights[$], f, p, d), ae[$ * 2] = d[0], ae[$ * 2 + 1] = d[1], x.parent && m(x.parent.out, x.parentLoc[$], d), V[$ * 2] = d[0], V[$ * 2 + 1] = d[1];
1488
1488
  for (let Z = 0; Z < 2; Z++) {
1489
- const _ = $ * 2 + Z, D = x.previous && g > 0 ? (se[_] - x.previous[_]) / g : 0;
1489
+ const _ = $ * 2 + Z, D = x.previous && g > 0 ? (ae[_] - x.previous[_]) / g : 0;
1490
1490
  M[_] = g > 0 ? (D - x.pivotVelocity[_]) / g : 0, x.pivotVelocity[_] = D;
1491
1491
  }
1492
1492
  for (let Z = 0; Z < A; Z++) {
@@ -1494,14 +1494,14 @@ function wr(t, e) {
1494
1494
  z[_] = L[_] + d[0] - x.top[$][0], z[_ + 1] = L[_ + 1] + d[1] - x.top[$][1];
1495
1495
  }
1496
1496
  }
1497
- x.previous = se;
1497
+ x.previous = ae;
1498
1498
  const E = ne * Math.sqrt(B), O = 2 * Math.PI * o.bounceHz;
1499
1499
  if (x.grid.custom) {
1500
1500
  const $ = `${E}:${H}:${W}`;
1501
1501
  if (x.systemKey !== $) {
1502
1502
  const ee = x.pendulums;
1503
1503
  x.pendulums = x.grid.lengths.map((oe, S) => {
1504
- const R = x.grid.joints[S], P = yr(R.slice(1).map((ae, ie) => (ae - R[ie]) * oe * i), x.gravity * E ** 2, o.zeta * H, W);
1504
+ const R = x.grid.joints[S], P = br(R.slice(1).map((se, ie) => (se - R[ie]) * oe * i), x.gravity * E ** 2, o.zeta * H, W);
1505
1505
  return ee[S] && (P.angles = ee[S].angles, P.velocities = ee[S].velocities), P;
1506
1506
  }), x.systemKey = $;
1507
1507
  }
@@ -1509,43 +1509,43 @@ function wr(t, e) {
1509
1509
  for (let ee = 0; ee < _; ee++) {
1510
1510
  const oe = this.time + (ee + 1) * D, S = (Math.sin(oe * 1.1) * 0.6 + Math.sin(oe * 2.3) * 0.4) * N * X;
1511
1511
  for (let R = 0; R < w; R++) {
1512
- const P = M[R * 2 + 1], ae = Math.max(x.gravity * 0.1, x.gravity - P), ie = Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[R * 2])) - ae * S / x.grid.lengths[R];
1513
- vr(x.pendulums[R], D, ie, ae / x.gravity), C[R] += (-(O ** 2) * j[R] - 2 * O * C[R] - P * 0.15) * D, j[R] += C[R] * D;
1512
+ const P = M[R * 2 + 1], se = Math.max(x.gravity * 0.1, x.gravity - P), ie = Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[R * 2])) - se * S / x.grid.lengths[R];
1513
+ wr(x.pendulums[R], D, ie, se / x.gravity), C[R] += (-(O ** 2) * j[R] - 2 * O * C[R] - P * 0.15) * D, j[R] += C[R] * D;
1514
1514
  }
1515
1515
  }
1516
1516
  for (let ee = 0; g > 0 && ee < J; ee++) for (const oe of ["angles", "velocities"]) {
1517
1517
  const S = x.pendulums.map((R) => [...R[oe]]);
1518
1518
  x.pendulums.forEach((R, P) => {
1519
- R[oe] = S[P].map((ae, ie) => 0.5 * ae + 0.25 * (S[Math.max(0, P - 1)][ie] + S[Math.min(w - 1, P + 1)][ie]));
1519
+ R[oe] = S[P].map((se, ie) => 0.5 * se + 0.25 * (S[Math.max(0, P - 1)][ie] + S[Math.min(w - 1, P + 1)][ie]));
1520
1520
  });
1521
1521
  }
1522
1522
  const q = (ee, oe, S, R = 1) => {
1523
1523
  for (let P = 0; P < w; P++) {
1524
- const ae = x.grid.joints[P], ie = x.grid.seams[P], pe = x.grid.lengths[P], be = N * 0.1 * Math.tanh(j[P] * S / (N * 0.1)), Me = 2 * Math.asin(Math.min(0.95, (N - Math.abs(be)) / (2 * pe))), Be = x.pendulums[P].angles[0], Ee = x.pendulums[P].angles.map((K) => {
1524
+ const se = x.grid.joints[P], ie = x.grid.seams[P], pe = x.grid.lengths[P], be = N * 0.1 * Math.tanh(j[P] * S / (N * 0.1)), Me = 2 * Math.asin(Math.min(0.95, (N - Math.abs(be)) / (2 * pe))), Be = x.pendulums[P].angles[0], Ee = x.pendulums[P].angles.map((K) => {
1525
1525
  const ce = R === 1 ? K : Be + (K - Be) * R;
1526
1526
  return Me * Math.tanh(ce * S / Me);
1527
1527
  }), de = [Array.from(oe.slice(P * 2, P * 2 + 2))];
1528
1528
  for (let K = 0; K < Ee.length; K++) {
1529
- const ce = qe(ie, ae[K]), ue = qe(ie, ae[K + 1]), ke = ue[0] - ce[0], Se = ue[1] - ce[1], ye = Ee[K];
1529
+ const ce = qe(ie, se[K]), ue = qe(ie, se[K + 1]), ke = ue[0] - ce[0], Se = ue[1] - ce[1], ye = Ee[K];
1530
1530
  de.push([de[K][0] + ke * Math.cos(ye) + Se * Math.sin(ye), de[K][1] - ke * Math.sin(ye) + Se * Math.cos(ye)]);
1531
1531
  }
1532
1532
  for (let K = 0; K < A; K++) {
1533
1533
  const ce = x.grid.fractions[P][K];
1534
1534
  let ue = 0;
1535
- for (; ue < Ee.length - 1 && ce > ae[ue + 1] + 1e-9; ) ue++;
1536
- const ke = qe(ie, ae[ue]), Se = qe(ie, ce), ye = (ce - ae[ue]) / (ae[ue + 1] - ae[ue]), Le = Ee[ue] * (1 - 0.1 * (1 - Q) * (1 - ye)), $e = Se[0] - ke[0], nt = Se[1] - ke[1], rt = (K * w + P) * 2;
1535
+ for (; ue < Ee.length - 1 && ce > se[ue + 1] + 1e-9; ) ue++;
1536
+ const ke = qe(ie, se[ue]), Se = qe(ie, ce), ye = (ce - se[ue]) / (se[ue + 1] - se[ue]), Le = Ee[ue] * (1 - 0.1 * (1 - Q) * (1 - ye)), $e = Se[0] - ke[0], nt = Se[1] - ke[1], rt = (K * w + P) * 2;
1537
1537
  ee[rt] = de[ue][0] + $e * Math.cos(Le) + nt * Math.sin(Le), ee[rt + 1] = de[ue][1] - $e * Math.sin(Le) + nt * Math.cos(Le) + be * ce;
1538
1538
  }
1539
1539
  }
1540
1540
  };
1541
- q(x.physicalOut, se, 1), q(Y, V, te, re);
1541
+ q(x.physicalOut, ae, 1), q(Y, V, te, re);
1542
1542
  continue;
1543
1543
  }
1544
1544
  for (let $ = 0; $ < b; $++) {
1545
- const Z = this.time + ($ + 1) * s, _ = (Math.sin(Z * 1.1) * 0.6 + Math.sin(Z * 2.3) * 0.4) * N * X;
1545
+ const Z = this.time + ($ + 1) * a, _ = (Math.sin(Z * 1.1) * 0.6 + Math.sin(Z * 2.3) * 0.4) * N * X;
1546
1546
  for (let D = 0; D < w; D++) {
1547
- const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = Math.max(x.gravity * 0.1, x.gravity - M[q + 1]), R = i * oe / 2, P = S / R * E * E, ae = Math.sqrt(P), ie = o.zeta * H, pe = ae * Math.sqrt(2 - Math.SQRT2), be = ae * Math.sqrt(2 + Math.SQRT2), Me = 2 * ie * pe * be / (pe + be), Be = 2 * ie / (pe + be), Ee = I[D] - T[D], de = Math.cos(Ee), K = Math.sin(Ee), ce = U[D], ue = F[D], Se = (Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[q])) - S * _ / oe) / R, ye = Me * (2 * ce + de * ue) + Be * 2 * P * ce, Le = Me * (de * ce + ue) + Be * P * ue, $e = -2 * P * Math.sin(I[D]) - K * ue * ue - 2 * Se * Math.cos(I[D]) - ye, nt = -P * Math.sin(T[D]) + K * ce * ce - Se * Math.cos(T[D]) - Le, rt = 2 - de * de;
1548
- U[D] += ($e - de * nt) / rt * s, F[D] += (2 * nt - de * $e) / rt * s, I[D] += U[D] * s, T[D] += F[D] * s, C[D] += (-O * O * j[D] - 2 * O * C[D] - M[q + 1] * 0.15) * s, j[D] += C[D] * s;
1547
+ const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = Math.max(x.gravity * 0.1, x.gravity - M[q + 1]), R = i * oe / 2, P = S / R * E * E, se = Math.sqrt(P), ie = o.zeta * H, pe = se * Math.sqrt(2 - Math.SQRT2), be = se * Math.sqrt(2 + Math.SQRT2), Me = 2 * ie * pe * be / (pe + be), Be = 2 * ie / (pe + be), Ee = I[D] - T[D], de = Math.cos(Ee), K = Math.sin(Ee), ce = U[D], ue = F[D], Se = (Math.max(-8 * x.gravity, Math.min(8 * x.gravity, M[q])) - S * _ / oe) / R, ye = Me * (2 * ce + de * ue) + Be * 2 * P * ce, Le = Me * (de * ce + ue) + Be * P * ue, $e = -2 * P * Math.sin(I[D]) - K * ue * ue - 2 * Se * Math.cos(I[D]) - ye, nt = -P * Math.sin(T[D]) + K * ce * ce - Se * Math.cos(T[D]) - Le, rt = 2 - de * de;
1548
+ U[D] += ($e - de * nt) / rt * a, F[D] += (2 * nt - de * $e) / rt * a, I[D] += U[D] * a, T[D] += F[D] * a, C[D] += (-O * O * j[D] - 2 * O * C[D] - M[q + 1] * 0.15) * a, j[D] += C[D] * a;
1549
1549
  }
1550
1550
  }
1551
1551
  for (let $ = 0; g > 0 && $ < J; $++) for (const Z of [I, U, T, F]) {
@@ -1554,14 +1554,14 @@ function wr(t, e) {
1554
1554
  }
1555
1555
  const k = ($, Z, _) => {
1556
1556
  for (let D = 0; D < w; D++) {
1557
- const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = N * 0.1 * Math.tanh(j[D] * _ / (N * 0.1)), R = 2 * Math.asin(Math.min(0.95, (N - Math.abs(S)) / (2 * oe))), P = R * Math.tanh(I[D] * _ / R), ae = R * Math.tanh(T[D] * _ / R), ie = 0.1 * (1 - Q), pe = (L[ee] - L[q]) / 2, be = (L[ee + 1] - L[q + 1]) / 2, Me = Z[q] + pe * Math.cos(P) + be * Math.sin(P), Be = Z[q + 1] - pe * Math.sin(P) + be * Math.cos(P);
1557
+ const q = D * 2, ee = ((A - 1) * w + D) * 2, oe = Math.max(1, Math.hypot(L[ee] - L[q], L[ee + 1] - L[q + 1])), S = N * 0.1 * Math.tanh(j[D] * _ / (N * 0.1)), R = 2 * Math.asin(Math.min(0.95, (N - Math.abs(S)) / (2 * oe))), P = R * Math.tanh(I[D] * _ / R), se = R * Math.tanh(T[D] * _ / R), ie = 0.1 * (1 - Q), pe = (L[ee] - L[q]) / 2, be = (L[ee + 1] - L[q + 1]) / 2, Me = Z[q] + pe * Math.cos(P) + be * Math.sin(P), Be = Z[q + 1] - pe * Math.sin(P) + be * Math.cos(P);
1558
1558
  for (let Ee = 0; Ee < A; Ee++) {
1559
- const de = Ee / (A - 1), K = (Ee * w + D) * 2, ce = de <= 0.5, ue = ce ? de * 2 : (de - 0.5) * 2, ke = (ce ? P : ae) * (1 - ie + ie * ue), Se = Math.cos(ke), ye = Math.sin(ke), Le = pe * ue, $e = be * ue;
1559
+ const de = Ee / (A - 1), K = (Ee * w + D) * 2, ce = de <= 0.5, ue = ce ? de * 2 : (de - 0.5) * 2, ke = (ce ? P : se) * (1 - ie + ie * ue), Se = Math.cos(ke), ye = Math.sin(ke), Le = pe * ue, $e = be * ue;
1560
1560
  $[K] = (ce ? Z[q] : Me) + Le * Se + $e * ye, $[K + 1] = (ce ? Z[q + 1] : Be) - Le * ye + $e * Se + S * de;
1561
1561
  }
1562
1562
  }
1563
1563
  };
1564
- k(x.physicalOut, se, 1), k(Y, V, te);
1564
+ k(x.physicalOut, ae, 1), k(Y, V, te);
1565
1565
  }
1566
1566
  this.time += g;
1567
1567
  }
@@ -1578,11 +1578,11 @@ function wr(t, e) {
1578
1578
  }
1579
1579
  return { Cloth: l, garments: u };
1580
1580
  }
1581
- function xr(t, e) {
1582
- const { baseWeights: n, deformBase: r, MOUTH: o } = t, a = (w, A, L) => {
1581
+ function Ar(e, t) {
1582
+ const { baseWeights: n, deformBase: r, MOUTH: o } = e, s = (w, A, L) => {
1583
1583
  const z = Math.min(1, Math.max(0, (L - w) / (A - w)));
1584
1584
  return z * z * (3 - 2 * z);
1585
- }, i = e.mouth.area, u = {
1585
+ }, i = t.mouth.area, u = {
1586
1586
  a: { sprite: "mouth_a", ref: 0.9, width: 1 },
1587
1587
  aHalf: { sprite: "mouth_a_half", ref: 0.55, width: 1 },
1588
1588
  i: { sprite: "mouth_i", ref: 0.55, width: 1 },
@@ -1606,35 +1606,35 @@ function xr(t, e) {
1606
1606
  function b(w) {
1607
1607
  return o.cy + (w - o.cx) * Math.tan(o.angle);
1608
1608
  }
1609
- function s() {
1609
+ function a() {
1610
1610
  return i.cx;
1611
1611
  }
1612
1612
  function d(w, A) {
1613
1613
  const L = Math.cos(-i.angle), z = Math.sin(-i.angle), Y = w - i.cx, I = A - i.cy, U = (Y * L - I * z) / i.rx, T = (Y * z + I * L) / i.ry;
1614
- return 1 - a(0.55, 0.95, Math.hypot(U, T));
1614
+ return 1 - s(0.55, 0.95, Math.hypot(U, T));
1615
1615
  }
1616
1616
  function x(w, A, L, z, Y) {
1617
1617
  const I = {}, U = (X) => X.startsWith("eyes_closed") || X.startsWith("eyes_smile"), T = (X) => v.some((G) => X === `mouth_${G}`), F = (X) => U(X) ? 1 : X.startsWith("eyes_") ? 0 : T(X) ? 2 : 3, j = Object.entries(A.layers).sort((X, G) => F(X[0]) - F(G[0]));
1618
1618
  for (const [X, G] of j) {
1619
- const re = z(G, e.mesh.spriteCell, Y(L[X]), L[X].width), W = [], te = [];
1619
+ const re = z(G, t.mesh.spriteCell, Y(L[X]), L[X].width), W = [], te = [];
1620
1620
  for (let V = 0; V < re.rest.length / 2; V++) {
1621
1621
  const M = re.rest[V * 2], E = re.rest[V * 2 + 1];
1622
1622
  W.push(n(M, E, 0)), te.push(X.startsWith("mouth") ? d(M, E) : 0);
1623
1623
  }
1624
- const se = w.addLayer(X, L[X], re, { color: [0.4, 1, 0.8, 0.6] });
1625
- se.visible = !1, I[X] = { mesh: re, W, inner: te, layer: se };
1624
+ const ae = w.addLayer(X, L[X], re, { color: [0.4, 1, 0.8, 0.6] });
1625
+ ae.visible = !1, I[X] = { mesh: re, W, inner: te, layer: ae };
1626
1626
  }
1627
1627
  const C = [0, 1].map((X) => !!(I[`eyes_closed_${X}`] && I[`eyes_half_${X}`])), B = Object.values(u).some((X) => I[X.sprite]), H = (X, G) => (X === "eyes_smile" && !I[`eyes_smile_${G}`] && (X = "eyes_closed"), X === "open" || I[`${X}_${G}`] ? X : "open"), N = [0, 0];
1628
1628
  let ne = null;
1629
1629
  const Q = [0, 1].map(() => ({ cur: "open", prev: "open", t: 1 }));
1630
1630
  function J(X, G, re, W, te = 1) {
1631
- const se = X.mesh.rest, V = X.mesh.pos;
1631
+ const ae = X.mesh.rest, V = X.mesh.pos;
1632
1632
  for (let M = 0; M < X.W.length; M++) {
1633
- let E = se[M * 2], O = se[M * 2 + 1];
1633
+ let E = ae[M * 2], O = ae[M * 2 + 1];
1634
1634
  const k = X.inner[M];
1635
1635
  if (k > 0) {
1636
1636
  const $ = b(E);
1637
- O = $ + (O - $) * (1 + (W - 1) * k), E = s() + (E - s()) * (1 + (te - 1) * k);
1637
+ O = $ + (O - $) * (1 + (W - 1) * k), E = a() + (E - a()) * (1 + (te - 1) * k);
1638
1638
  }
1639
1639
  r(E, O, X.W[M], G, re, N), V[M * 2] = N[0], V[M * 2 + 1] = N[1];
1640
1640
  }
@@ -1656,10 +1656,10 @@ function xr(t, e) {
1656
1656
  ].forEach(([k, $], Z) => {
1657
1657
  const _ = Q[Z], D = h.includes(W) && I[`eyes_${W}_${Z}`] ? `eyes_${W}` : null, q = H(p(k, $, D) ?? "open", Z);
1658
1658
  q !== _.cur && (_.prev = _.cur, _.cur = q, _.t = 0), _.t = re > 0 ? Math.min(1, _.t + re / f) : 1;
1659
- const ee = a(0, 1, _.t), oe = (R, P) => {
1659
+ const ee = s(0, 1, _.t), oe = (R, P) => {
1660
1660
  if (R === "open" || P <= 1e-3) return;
1661
- const ae = I[`${R}_${Z}`];
1662
- ae && (ae.layer.visible = !0, ae.layer.alpha = P, J(ae, X, G, 1));
1661
+ const se = I[`${R}_${Z}`];
1662
+ se && (se.layer.visible = !0, se.layer.alpha = P, J(se, X, G, 1));
1663
1663
  }, S = (R) => R === "open" ? -1 : U(R) ? 1 : 0;
1664
1664
  _.t >= 1 ? oe(_.cur, 1) : S(_.cur) > S(_.prev) ? (oe(_.prev, 1), oe(_.cur, ee)) : (oe(_.cur, 1), oe(_.prev, 1 - ee)), te[Z] = _.cur !== "open" && ee >= 0.999;
1665
1665
  });
@@ -1667,7 +1667,7 @@ function xr(t, e) {
1667
1667
  ne = V;
1668
1668
  const M = V && u[V], E = M && I[M.sprite], O = v.includes(W) && I[`mouth_${W}`];
1669
1669
  if (O && (!E || X.mouthOpen < y + 0.04) && (O.layer.visible = !0, O.layer.alpha = 1, J(O, X, G, 1)), E) {
1670
- E.layer.visible = !0, E.layer.alpha = a(y, y + 0.04, X.mouthOpen);
1670
+ E.layer.visible = !0, E.layer.alpha = s(y, y + 0.04, X.mouthOpen);
1671
1671
  const k = Math.min(1.1, Math.max(0.5, X.mouthOpen / M.ref));
1672
1672
  J(E, X, G, k, M.width);
1673
1673
  }
@@ -1679,37 +1679,37 @@ function xr(t, e) {
1679
1679
  }
1680
1680
  return { createSprites: x, mouthShape: g, eyeSprite: p };
1681
1681
  }
1682
- const mn = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
1683
- function Mr(t, e) {
1684
- return t && t !== "neutral" ? mn[t] ?? null : (e && mn[e]) ?? null;
1682
+ const pn = { angry: "angry", angryTalk: "angry", sad: "sad", sadTalk: "sad", surprise: "surprise", surprisedTalk: "surprise" };
1683
+ function Er(e, t) {
1684
+ return e && e !== "neutral" ? pn[e] ?? null : (t && pn[t]) ?? null;
1685
1685
  }
1686
- function Ar(t, e, n, r = 6) {
1687
- let o = e, a = n, i = -1, u = -1;
1686
+ function Sr(e, t, n, r = 6) {
1687
+ let o = t, s = n, i = -1, u = -1;
1688
1688
  for (let m = 0; m < n; m++) {
1689
- const l = m * e;
1690
- for (let c = 0; c < e; c++)
1691
- t[l + c] > 3 && (c < o && (o = c), c > i && (i = c), m < a && (a = m), m > u && (u = m));
1689
+ const l = m * t;
1690
+ for (let c = 0; c < t; c++)
1691
+ e[l + c] > 3 && (c < o && (o = c), c > i && (i = c), m < s && (s = m), m > u && (u = m));
1692
1692
  }
1693
1693
  if (i < 0) return null;
1694
- const y = Math.max(0, o - r), v = Math.max(0, a - r);
1695
- return [y, v, Math.min(e, i + 1 + r) - y, Math.min(n, u + 1 + r) - v];
1694
+ const y = Math.max(0, o - r), v = Math.max(0, s - r);
1695
+ return [y, v, Math.min(t, i + 1 + r) - y, Math.min(n, u + 1 + r) - v];
1696
1696
  }
1697
- function Er(t, e, n, r, o, a, i = 16, u, y, v) {
1697
+ function Or(e, t, n, r, o, s, i = 16, u, y, v) {
1698
1698
  const m = /* @__PURE__ */ new Map();
1699
- for (const l of e.overlays) {
1699
+ for (const l of t.overlays) {
1700
1700
  const c = n[l.name];
1701
1701
  if (u !== void 0 && c.width !== u || y !== void 0 && c.height !== y)
1702
1702
  throw new Error(`overlay ${l.name}: image size does not match base.png`);
1703
- const f = o(c), h = Ar(f, c.width, c.height);
1703
+ const f = o(c), h = Sr(f, c.width, c.height);
1704
1704
  if (!h) continue;
1705
- const [p, g, b, s] = h, d = new Uint8Array(b * s);
1706
- for (let L = 0; L < s; L++) d.set(f.subarray((g + L) * c.width + p, (g + L) * c.width + p + b), L * b);
1705
+ const [p, g, b, a] = h, d = new Uint8Array(b * a);
1706
+ for (let L = 0; L < a; L++) d.set(f.subarray((g + L) * c.width + p, (g + L) * c.width + p + b), L * b);
1707
1707
  const x = r(h, i, d, b), w = [];
1708
1708
  for (let L = 0; L < x.rest.length; L += 2) {
1709
- const z = a(x.rest[L], x.rest[L + 1], 0);
1709
+ const z = s(x.rest[L], x.rest[L + 1], 0);
1710
1710
  w.push({ ...z, brow: 0, jaw: 0 });
1711
1711
  }
1712
- const A = t.addLayer(`overlay_${l.name}`, v(c, h), x);
1712
+ const A = e.addLayer(`overlay_${l.name}`, v(c, h), x);
1713
1713
  A.visible = !1, m.set(l.name, { mesh: x, weights: w, layer: A });
1714
1714
  }
1715
1715
  return {
@@ -1721,55 +1721,55 @@ function Er(t, e, n, r, o, a, i = 16, u, y, v) {
1721
1721
  update(l, c, f, h) {
1722
1722
  for (const { mesh: p, weights: g, layer: b } of m.values())
1723
1723
  if (b.visible)
1724
- for (let s = 0; s < g.length; s++)
1725
- f(p.rest[s * 2], p.rest[s * 2 + 1], g[s], l, c, h), p.pos[s * 2] = h[0], p.pos[s * 2 + 1] = h[1];
1724
+ for (let a = 0; a < g.length; a++)
1725
+ f(p.rest[a * 2], p.rest[a * 2 + 1], g[a], l, c, h), p.pos[a * 2] = h[0], p.pos[a * 2 + 1] = h[1];
1726
1726
  }
1727
1727
  };
1728
1728
  }
1729
- function en(t) {
1730
- if (!t || typeof t != "object" || Array.isArray(t)) throw new TypeError("lipSync: expected an object");
1731
- const e = t, n = {};
1729
+ function tn(e) {
1730
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new TypeError("lipSync: expected an object");
1731
+ const t = e, n = {};
1732
1732
  for (const r of ["granularity", "openness", "closeSpeed"]) {
1733
- const o = e[r];
1733
+ const o = t[r];
1734
1734
  if (o !== void 0) {
1735
1735
  if (typeof o != "number" || !Number.isFinite(o) || o < 0 || o > 1)
1736
1736
  throw new RangeError(`lipSync.${r}: expected 0–1`);
1737
1737
  n[r] = o;
1738
1738
  }
1739
1739
  }
1740
- if (e.preset !== void 0) {
1741
- if (!["calm", "default", "lively", "subtle", "big", "custom"].includes(e.preset))
1740
+ if (t.preset !== void 0) {
1741
+ if (!["calm", "default", "lively", "subtle", "big", "custom"].includes(t.preset))
1742
1742
  throw new RangeError("lipSync.preset: expected calm, default, lively, subtle, big or custom");
1743
- n.preset = e.preset;
1743
+ n.preset = t.preset;
1744
1744
  }
1745
1745
  return n;
1746
1746
  }
1747
- function pn(t = {}, e = {
1747
+ function dn(e = {}, t = {
1748
1748
  granularity: 0.5,
1749
1749
  openness: 0.5,
1750
1750
  closeSpeed: 0.5
1751
1751
  }) {
1752
- const n = en(t);
1752
+ const n = tn(e);
1753
1753
  return {
1754
- granularity: n.granularity ?? e.granularity,
1755
- openness: n.openness ?? e.openness,
1756
- closeSpeed: n.closeSpeed ?? e.closeSpeed
1754
+ granularity: n.granularity ?? t.granularity,
1755
+ openness: n.openness ?? t.openness,
1756
+ closeSpeed: n.closeSpeed ?? t.closeSpeed
1757
1757
  };
1758
1758
  }
1759
- const Pe = (t, e, n, r) => t === 0.5 ? n : t < 0.5 ? e + (n - e) * t * 2 : n + (r - n) * (t - 0.5) * 2;
1760
- function dn(t) {
1759
+ const Pe = (e, t, n, r) => e === 0.5 ? n : e < 0.5 ? t + (n - t) * e * 2 : n + (r - n) * (e - 0.5) * 2;
1760
+ function gn(e) {
1761
1761
  return {
1762
- arm: Pe(t.granularity, 0.2, 0.6, 0.9),
1763
- trigger: Pe(t.granularity, 0.65, 0.8, 0.95),
1764
- relax: Pe(t.granularity, 1.5, 5, 12),
1765
- range: Pe(t.granularity, 0.7, 0.3, 0.05),
1766
- risePower: Pe(t.granularity, 0.05, 0.3, 0.8),
1767
- openness: Pe(t.openness, 0.55, 1, 1.25),
1768
- audioRelease: Pe(t.closeSpeed, 6, 32, 45),
1769
- kanaRelease: Pe(t.closeSpeed, 6, 22, 45)
1762
+ arm: Pe(e.granularity, 0.2, 0.6, 0.9),
1763
+ trigger: Pe(e.granularity, 0.65, 0.8, 0.95),
1764
+ relax: Pe(e.granularity, 1.5, 5, 12),
1765
+ range: Pe(e.granularity, 0.7, 0.3, 0.05),
1766
+ risePower: Pe(e.granularity, 0.05, 0.3, 0.8),
1767
+ openness: Pe(e.openness, 0.55, 1, 1.25),
1768
+ audioRelease: Pe(e.closeSpeed, 6, 32, 45),
1769
+ kanaRelease: Pe(e.closeSpeed, 6, 22, 45)
1770
1770
  };
1771
1771
  }
1772
- const Sr = /* @__PURE__ */ new Set([
1772
+ const Tr = /* @__PURE__ */ new Set([
1773
1773
  "angleX",
1774
1774
  "angleY",
1775
1775
  "angleZ",
@@ -1779,7 +1779,7 @@ const Sr = /* @__PURE__ */ new Set([
1779
1779
  "handAngle",
1780
1780
  "gazeX",
1781
1781
  "gazeY"
1782
- ]), tn = {
1782
+ ]), nn = {
1783
1783
  nod: {
1784
1784
  label: "Nod",
1785
1785
  dur: 1.7,
@@ -1927,7 +1927,7 @@ const Sr = /* @__PURE__ */ new Set([
1927
1927
  blush: [[0, 0], [1.6, 0.3], [2.6, 0]]
1928
1928
  }
1929
1929
  }
1930
- }, nn = {
1930
+ }, rn = {
1931
1931
  lookAround: {
1932
1932
  label: "Look around",
1933
1933
  dur: 5.2,
@@ -2167,14 +2167,14 @@ const Sr = /* @__PURE__ */ new Set([
2167
2167
  }
2168
2168
  }
2169
2169
  };
2170
- function Or(t, e) {
2171
- if (e <= t[0][0]) return t[0][1];
2172
- const n = t.length - 1;
2173
- if (e >= t[n][0]) return t[n][1];
2170
+ function Rr(e, t) {
2171
+ if (t <= e[0][0]) return e[0][1];
2172
+ const n = e.length - 1;
2173
+ if (t >= e[n][0]) return e[n][1];
2174
2174
  let r = 0;
2175
- for (; e > t[r + 1][0]; ) r++;
2176
- const [o, a] = t[r], [i, u] = t[r + 1], y = (p) => p <= 0 || p >= n ? 0 : (t[p + 1][1] - t[p - 1][1]) / (t[p + 1][0] - t[p - 1][0]), v = i - o, m = (e - o) / v, l = y(r) * v, c = y(r + 1) * v, f = m * m, h = f * m;
2177
- return (2 * h - 3 * f + 1) * a + (h - 2 * f + m) * l + (-2 * h + 3 * f) * u + (h - f) * c;
2175
+ for (; t > e[r + 1][0]; ) r++;
2176
+ const [o, s] = e[r], [i, u] = e[r + 1], y = (p) => p <= 0 || p >= n ? 0 : (e[p + 1][1] - e[p - 1][1]) / (e[p + 1][0] - e[p - 1][0]), v = i - o, m = (t - o) / v, l = y(r) * v, c = y(r + 1) * v, f = m * m, h = f * m;
2177
+ return (2 * h - 3 * f + 1) * s + (h - 2 * f + m) * l + (-2 * h + 3 * f) * u + (h - f) * c;
2178
2178
  }
2179
2179
  const pt = {
2180
2180
  a: { open: 0.9, form: 0, label: "あ" },
@@ -2184,70 +2184,70 @@ const pt = {
2184
2184
  o: { open: 0.75, form: 0.6, label: "お" },
2185
2185
  n: { open: 0, form: null, label: "ん" }
2186
2186
  // closes with the previous shape
2187
- }, Tr = {
2187
+ }, kr = {
2188
2188
  a: "あかさたなはまやらわがざだばぱぁ",
2189
2189
  i: "いきしちにひみりぎじぢびぴぃ",
2190
2190
  u: "うくすつぬふむゆるぐずづぶぷぅゔ",
2191
2191
  e: "えけせてねへめれげぜでべぺぇ",
2192
2192
  o: "おこそとのほもよろをごぞどぼぽぉ"
2193
- }, Fn = {};
2194
- for (const [t, e] of Object.entries(Tr)) for (const n of e) Fn[n] = t;
2195
- const Rr = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), kr = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), gn = { ゃ: "a", ゅ: "u", ょ: "o" }, Lr = /* @__PURE__ */ new Set([..."、。,.,.!?!?  …"]), _r = (t) => t.replace(/[ァ-ヶ]/g, (e) => String.fromCharCode(e.charCodeAt(0) - 96));
2196
- function Fr(t, e = 0.14) {
2193
+ }, Bn = {};
2194
+ for (const [e, t] of Object.entries(kr)) for (const n of t) Bn[n] = e;
2195
+ const Lr = /* @__PURE__ */ new Set([..."まみむめもばびぶべぼぱぴぷぺぽ"]), _r = /* @__PURE__ */ new Set([..."あいうえおぁぃぅぇぉ"]), yn = { ゃ: "a", ゅ: "u", ょ: "o" }, Fr = /* @__PURE__ */ new Set([..."、。,.,.!?!?  …"]), jr = (e) => e.replace(/[ァ-ヶ]/g, (t) => String.fromCharCode(t.charCodeAt(0) - 96));
2196
+ function Br(e, t = 0.14) {
2197
2197
  const n = [];
2198
- for (const r of _r(t)) {
2198
+ for (const r of jr(e)) {
2199
2199
  const o = n[n.length - 1];
2200
- if (gn[r] && o) {
2201
- o.vowel = gn[r];
2200
+ if (yn[r] && o) {
2201
+ o.vowel = yn[r];
2202
2202
  continue;
2203
2203
  }
2204
2204
  if (r === "ー" && o) {
2205
- o.dur += e;
2205
+ o.dur += t;
2206
2206
  continue;
2207
2207
  }
2208
2208
  if (r === "っ") {
2209
- n.push({ vowel: "n", dur: e * 0.8, onset: null });
2209
+ n.push({ vowel: "n", dur: t * 0.8, onset: null });
2210
2210
  continue;
2211
2211
  }
2212
2212
  if (r === "ん") {
2213
- n.push({ vowel: "n", dur: e, onset: null });
2213
+ n.push({ vowel: "n", dur: t, onset: null });
2214
2214
  continue;
2215
2215
  }
2216
- if (Lr.has(r)) {
2217
- n.push({ vowel: "n", dur: e * 2.2, onset: null });
2216
+ if (Fr.has(r)) {
2217
+ n.push({ vowel: "n", dur: t * 2.2, onset: null });
2218
2218
  continue;
2219
2219
  }
2220
- const a = Fn[r];
2221
- a && n.push({ vowel: a, dur: e, onset: Rr.has(r) ? "lips" : kr.has(r) ? null : "consonant" });
2220
+ const s = Bn[r];
2221
+ s && n.push({ vowel: s, dur: t, onset: Lr.has(r) ? "lips" : _r.has(r) ? null : "consonant" });
2222
2222
  }
2223
2223
  return n;
2224
2224
  }
2225
- function jr(t, e, n = 0.5) {
2226
- if (n !== 0.5) return Br(t, e, n);
2225
+ function $r(e, t, n = 0.5) {
2226
+ if (n !== 0.5) return Ur(e, t, n);
2227
2227
  let r = 0;
2228
- for (const o of t) {
2229
- if (e < r + o.dur) {
2230
- const a = (e - r) / o.dur, i = pt[o.vowel], u = o.onset === "lips" ? 0.05 : o.onset === "consonant" ? 0.45 : 1, y = a < 0.35 ? u + (1 - u) * (a / 0.35) : 1;
2228
+ for (const o of e) {
2229
+ if (t < r + o.dur) {
2230
+ const s = (t - r) / o.dur, i = pt[o.vowel], u = o.onset === "lips" ? 0.05 : o.onset === "consonant" ? 0.45 : 1, y = s < 0.35 ? u + (1 - u) * (s / 0.35) : 1;
2231
2231
  return { open: i.open * y, form: i.form, vowel: o.vowel };
2232
2232
  }
2233
2233
  r += o.dur;
2234
2234
  }
2235
2235
  return null;
2236
2236
  }
2237
- function Br(t, e, n) {
2237
+ function Ur(e, t, n) {
2238
2238
  const r = n < 0.5 ? (0.5 - n) * 0.72 : 0;
2239
- let o = 0, a = 0, i = null;
2240
- for (const u of t) {
2239
+ let o = 0, s = 0, i = null;
2240
+ for (const u of e) {
2241
2241
  let y = u.vowel;
2242
- if (u.vowel === "n" ? r && u.dur <= 0.2 && i ? y = i : (a = 0, i = null) : ((!i || a >= r) && (i = u.vowel, a = 0), a += u.dur, r && (y = i)), e < o + u.dur) {
2243
- const v = pt[y], m = u.onset === "lips" ? 0.05 : u.onset === "consonant" ? 0.45 : 1, l = n < 0.5 ? 1 - (1 - m) * n * 2 : m * (2 - n * 2), c = Math.min(u.dur * 0.35, 0.05), f = (e - o) / c;
2242
+ if (u.vowel === "n" ? r && u.dur <= 0.2 && i ? y = i : (s = 0, i = null) : ((!i || s >= r) && (i = u.vowel, s = 0), s += u.dur, r && (y = i)), t < o + u.dur) {
2243
+ const v = pt[y], m = u.onset === "lips" ? 0.05 : u.onset === "consonant" ? 0.45 : 1, l = n < 0.5 ? 1 - (1 - m) * n * 2 : m * (2 - n * 2), c = Math.min(u.dur * 0.35, 0.05), f = (t - o) / c;
2244
2244
  return { open: v.open * (f < 1 ? l + (1 - l) * f : 1), form: v.form, vowel: y };
2245
2245
  }
2246
2246
  o += u.dur;
2247
2247
  }
2248
2248
  return null;
2249
2249
  }
2250
- const Ft = { ...tn, ...nn }, yn = { amp: 1, stiff: 1.8 }, $r = /^(angle|bodyAngle|armAngle|handAngle)/, Ur = /* @__PURE__ */ new Set([
2250
+ const jt = { ...nn, ...rn }, vn = { amp: 1, stiff: 1.8 }, Yr = /^(angle|bodyAngle|armAngle|handAngle)/, Ir = /* @__PURE__ */ new Set([
2251
2251
  "eyeOpen",
2252
2252
  "eyeOpenL",
2253
2253
  "eyeSmileL",
@@ -2257,18 +2257,18 @@ const Ft = { ...tn, ...nn }, yn = { amp: 1, stiff: 1.8 }, $r = /^(angle|bodyAngl
2257
2257
  "blush",
2258
2258
  "browY",
2259
2259
  "browAngle"
2260
- ]), xt = (t, e, n) => {
2261
- const r = Math.min(1, Math.max(0, (n - t) / (e - t)));
2260
+ ]), xt = (e, t, n) => {
2261
+ const r = Math.min(1, Math.max(0, (n - e) / (t - e)));
2262
2262
  return r * r * (3 - 2 * r);
2263
2263
  };
2264
- function vn(t, e) {
2265
- const n = Math.floor(t), r = t - n, o = (i) => {
2266
- const u = Math.sin((i + e * 57.3) * 127.1) * 43758.5453;
2264
+ function bn(e, t) {
2265
+ const n = Math.floor(e), r = e - n, o = (i) => {
2266
+ const u = Math.sin((i + t * 57.3) * 127.1) * 43758.5453;
2267
2267
  return u - Math.floor(u);
2268
- }, a = r * r * (3 - 2 * r);
2269
- return (o(n) * (1 - a) + o(n + 1) * a) * 2 - 1;
2268
+ }, s = r * r * (3 - 2 * r);
2269
+ return (o(n) * (1 - s) + o(n + 1) * s) * 2 - 1;
2270
2270
  }
2271
- const ze = (t, e) => vn(t, e) * 0.7 + vn(t * 2.3, e + 9) * 0.3, Te = (t, e, n) => Math.max(e, Math.min(n, t)), jn = {
2271
+ const ze = (e, t) => bn(e, t) * 0.7 + bn(e * 2.3, t + 9) * 0.3, Te = (e, t, n) => Math.max(t, Math.min(n, e)), $n = {
2272
2272
  normal: { label: "Neutral", p: {} },
2273
2273
  smile: { label: "Smile", p: { eyeOpen: 0, eyeSmile: 1, blush: 0.35, browY: 0.2 } },
2274
2274
  shy: { label: "Blush", p: { eyeOpen: 0.78, eyeSmile: 0.5, blush: 1, browAngle: -0.5, browY: -0.1, glance: [0.7, 0.35] } },
@@ -2282,14 +2282,14 @@ const ze = (t, e) => vn(t, e) * 0.7 + vn(t * 2.3, e + 9) * 0.3, Te = (t, e, n) =
2282
2282
  angryTalk: { label: "angry", p: { eyeOpen: 0.72, browAngle: 0.85, browY: -0.55, mouthForm: 0.2 } },
2283
2283
  surprisedTalk: { label: "surprised", p: { eyeOpen: 1.18, browY: 0.9, mouthForm: 0.9 } },
2284
2284
  relaxedTalk: { label: "relaxed", p: { eyeOpen: 0.82, eyeSmile: 0.35, blush: 0.15, browY: 0.1 } }
2285
- }, bn = {
2285
+ }, wn = {
2286
2286
  happy: ["happyTalk", "nod"],
2287
2287
  sad: ["sadTalk", "sigh"],
2288
2288
  angry: ["angryTalk", "no"],
2289
2289
  surprised: ["surprisedTalk", "surprise"],
2290
2290
  relaxed: ["relaxedTalk", "sway"],
2291
2291
  neutral: ["normal", null]
2292
- }, Yr = {
2292
+ }, Nr = {
2293
2293
  gazeX: [260, 0.9],
2294
2294
  gazeY: [260, 0.9],
2295
2295
  angleX: [55, 0.72],
@@ -2301,47 +2301,47 @@ const ze = (t, e) => vn(t, e) * 0.7 + vn(t * 2.3, e + 9) * 0.3, Te = (t, e, n) =
2301
2301
  armAngle: [20, 0.85],
2302
2302
  handAngle: [30, 0.8]
2303
2303
  };
2304
- function Ir(t) {
2305
- const n = (t + 0.45) % 5, r = n < 2.5 ? -0.7 : 0.7, o = -r, a = n % 2.5;
2306
- if (a >= 0.9) return o;
2307
- const i = a / 0.9, u = i * i * i * (10 + i * (-15 + 6 * i));
2304
+ function Xr(e) {
2305
+ const n = (e + 0.45) % 5, r = n < 2.5 ? -0.7 : 0.7, o = -r, s = n % 2.5;
2306
+ if (s >= 0.9) return o;
2307
+ const i = s / 0.9, u = i * i * i * (10 + i * (-15 + 6 * i));
2308
2308
  return r + (o - r) * u;
2309
2309
  }
2310
- class Nr {
2310
+ class zr {
2311
2311
  /** @param {number[]} gazeCenter @param {boolean} [planted] @param {import('../rig/types').Rig|null} [armRig] */
2312
- constructor(e, n = !1, r = null) {
2313
- this.armRig = r, this.armFollow = 0, this.armVelocity = 0, this.planted = n, this.mode = "auto", this.P = Object.fromEntries(bt.map((o) => [o.id, o.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(bt.map((o) => [o.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 = pn(), this.lipMotion = dn(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;
2312
+ constructor(t, n = !1, r = null) {
2313
+ this.armRig = r, this.armFollow = 0, this.armVelocity = 0, this.planted = n, this.mode = "auto", this.P = Object.fromEntries(bt.map((o) => [o.id, o.def])), this.manual = { ...this.P }, this.cur = { ...this.P }, this.vel = Object.fromEntries(bt.map((o) => [o.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 = [...t], this.lipOpen = null, this.lipForm = 0, this.speaking = !1, this.voice = 0, this.mouth = 0, this.vowel = "a", this.vowelForm = 0, this.lipSync = dn(), this.lipMotion = gn(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;
2314
2314
  }
2315
- setExpression(e) {
2316
- this.expr = e;
2315
+ setExpression(t) {
2316
+ this.expr = t;
2317
2317
  }
2318
- hasMotion(e) {
2319
- return e in Ft;
2318
+ hasMotion(t) {
2319
+ return t in jt;
2320
2320
  }
2321
2321
  // ---- speech (driven from outside, e.g. by the TTS audio analyser) ----
2322
- setVoiceLevel(e) {
2323
- this.voice = Math.min(1, Math.max(0, Number(e) || 0));
2322
+ setVoiceLevel(t) {
2323
+ this.voice = Math.min(1, Math.max(0, Number(t) || 0));
2324
2324
  }
2325
- setLipSync(e) {
2326
- this.lipSync = pn(e, this.lipSync), this.lipMotion = dn(this.lipSync);
2325
+ setLipSync(t) {
2326
+ this.lipSync = dn(t, this.lipSync), this.lipMotion = gn(this.lipSync);
2327
2327
  }
2328
- setSpeaking(e) {
2329
- e !== this.speaking && (this.speaking = !!e, e || (this.emotionUntil = this.t + 1.2, this.voice = 0));
2328
+ setSpeaking(t) {
2329
+ t !== this.speaking && (this.speaking = !!t, t || (this.emotionUntil = this.t + 1.2, this.voice = 0));
2330
2330
  }
2331
2331
  /** `playMotion: false` changes only the face (a caller that picks motions itself). */
2332
- setEmotion(e, { playMotion: n = !0 } = {}) {
2333
- const r = bn[e] ?? bn.neutral;
2332
+ setEmotion(t, { playMotion: n = !0 } = {}) {
2333
+ const r = wn[t] ?? wn.neutral;
2334
2334
  this.expr = r[0], this.emotionUntil = 1 / 0, r[1] && n && this.playMotion(r[1]);
2335
2335
  }
2336
2336
  /** Mouth shapes from kana text, without audio (preview / tuning). */
2337
2337
  /** @param {string} text @param {{ speed?: number, loop?: boolean }} [options] */
2338
- speakKana(e, { speed: n, loop: r = !1 } = {}) {
2338
+ speakKana(t, { speed: n, loop: r = !1 } = {}) {
2339
2339
  this.lipHold = null;
2340
- const o = Fr(e, n === void 0 ? 0.14 : 1 / Te(Number(n) || 7, 4, 12));
2341
- this.kana = o.length ? { moras: o, t: 0, loop: r, duration: o.reduce((a, i) => a + i.dur, 0) } : null;
2340
+ const o = Br(t, n === void 0 ? 0.14 : 1 / Te(Number(n) || 7, 4, 12));
2341
+ this.kana = o.length ? { moras: o, t: 0, loop: r, duration: o.reduce((s, i) => s + i.dur, 0) } : null;
2342
2342
  }
2343
- holdMouth(e) {
2344
- this.kana = null, this.lipHold = Object.hasOwn(pt, e) ? e : null;
2343
+ holdMouth(t) {
2344
+ this.kana = null, this.lipHold = Object.hasOwn(pt, t) ? t : null;
2345
2345
  }
2346
2346
  stopLipSync() {
2347
2347
  this.kana = null, this.lipHold = null, this.lipOpen = null, this.mouth = 0;
@@ -2355,15 +2355,15 @@ class Nr {
2355
2355
  // Syllables are found relative to the recent peak (not an absolute level), and the mouth
2356
2356
  // is scaled by where the voice sits between the recent trough and peak, so it closes in
2357
2357
  // the dip before each mora even when a loud voice never gets quiet.
2358
- speechMouth(e) {
2358
+ speechMouth(t) {
2359
2359
  if (this.kana || this.lipHold) {
2360
2360
  let c;
2361
- if (this.lipHold ? c = pt[this.lipHold] : (this.kana.t += e, this.kana.loop && (this.kana.t %= this.kana.duration), c = jr(this.kana.moras, this.kana.t, this.lipSync.granularity)), !c)
2362
- 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;
2363
- const f = this.lipMotion.openness === 1 ? c.open : Math.min(1, c.open * this.lipMotion.openness), h = f > this.mouth ? 1 - Math.exp(-e * 30) : 1 - Math.exp(-e * this.lipMotion.kanaRelease);
2361
+ if (this.lipHold ? c = pt[this.lipHold] : (this.kana.t += t, this.kana.loop && (this.kana.t %= this.kana.duration), c = $r(this.kana.moras, this.kana.t, this.lipSync.granularity)), !c)
2362
+ return this.kana = null, this.mouth > 0.01 ? [this.mouth *= this.lipSync.closeSpeed === 0.5 ? 0.6 : Math.exp(-t * this.lipMotion.kanaRelease), this.vowelForm] : null;
2363
+ const f = this.lipMotion.openness === 1 ? c.open : Math.min(1, c.open * this.lipMotion.openness), h = f > this.mouth ? 1 - Math.exp(-t * 30) : 1 - Math.exp(-t * this.lipMotion.kanaRelease);
2364
2364
  return this.mouth += (f - this.mouth) * h, c.form !== null && (this.vowelForm = c.form), [this.mouth, this.vowelForm];
2365
2365
  }
2366
- const n = this.speaking ? this.voice : 0, r = 1 - Math.exp(-e * this.lipMotion.relax);
2366
+ const n = this.speaking ? this.voice : 0, r = 1 - Math.exp(-t * this.lipMotion.relax);
2367
2367
  this.voicePeak = n > this.voicePeak ? n : this.voicePeak + (n - this.voicePeak) * r, this.voiceTrough = n < this.voiceTrough ? n : this.voiceTrough + (n - this.voiceTrough) * r;
2368
2368
  const o = Math.max(this.voicePeak, 0.05);
2369
2369
  if (n < o * this.lipMotion.arm) this.syllableArmed = !0;
@@ -2372,70 +2372,70 @@ class Nr {
2372
2372
  const c = Math.random();
2373
2373
  this.vowel = c < 0.4 ? "a" : c < 0.58 ? "o" : c < 0.74 ? "e" : c < 0.88 ? "i" : "u";
2374
2374
  }
2375
- const a = this.voicePeak - this.voiceTrough, i = a < o * this.lipMotion.range ? 1 : Math.max(0, (n - this.voiceTrough) / a), u = pt[this.vowel ?? "a"], y = Math.min(1, Math.pow(n, 0.7) * 1.15) * Math.pow(i, this.lipMotion.risePower), v = this.speaking ? Math.min(0.95, y) * (0.45 + 0.55 * u.open / 0.9) : 0, m = this.lipMotion.openness === 1 ? v : Math.min(1, v * this.lipMotion.openness), l = m > this.mouth ? 1 - Math.exp(-e * 40) : 1 - Math.exp(-e * this.lipMotion.audioRelease);
2375
+ const s = this.voicePeak - this.voiceTrough, i = s < o * this.lipMotion.range ? 1 : Math.max(0, (n - this.voiceTrough) / s), u = pt[this.vowel ?? "a"], y = Math.min(1, Math.pow(n, 0.7) * 1.15) * Math.pow(i, this.lipMotion.risePower), v = this.speaking ? Math.min(0.95, y) * (0.45 + 0.55 * u.open / 0.9) : 0, m = this.lipMotion.openness === 1 ? v : Math.min(1, v * this.lipMotion.openness), l = m > this.mouth ? 1 - Math.exp(-t * 40) : 1 - Math.exp(-t * this.lipMotion.audioRelease);
2376
2376
  return this.mouth += (m - this.mouth) * l, this.speaking && (this.vowelForm = u.form), this.speaking || this.mouth > 0.01 ? [this.mouth, this.vowelForm] : null;
2377
2377
  }
2378
2378
  // Breathing: inhale ~40% of the cycle, a slower exhale, a short pause at the bottom,
2379
2379
  // and a period that drifts between ~3.2 and 4.6 s so it never looks metronomic.
2380
- breathValue(e) {
2381
- this.breathPhase = (this.breathPhase ?? 0) + e / (this.breathPeriod ?? 3.8), this.breathPhase >= 1 && (this.breathPhase -= 1, this.breathPeriod = 3.2 + Math.random() * 1.4);
2380
+ breathValue(t) {
2381
+ this.breathPhase = (this.breathPhase ?? 0) + t / (this.breathPeriod ?? 3.8), this.breathPhase >= 1 && (this.breathPhase -= 1, this.breathPeriod = 3.2 + Math.random() * 1.4);
2382
2382
  const n = this.breathPhase;
2383
2383
  return n < 0.4 ? xt(0, 0.4, n) : n < 0.88 ? 1 - xt(0.4, 0.88, n) : 0;
2384
2384
  }
2385
2385
  // pick one at random, never the one that just played
2386
- playRandom(e) {
2387
- const n = e.filter((r) => r !== this.lastAuto);
2386
+ playRandom(t) {
2387
+ const n = t.filter((r) => r !== this.lastAuto);
2388
2388
  this.playMotion(n[Math.floor(Math.random() * n.length)]);
2389
2389
  }
2390
- playMotion(e) {
2391
- this.lastAuto = e, this.play = { id: e, t: 0 }, this.onMotion?.(e);
2390
+ playMotion(t) {
2391
+ this.lastAuto = t, this.play = { id: t, t: 0 }, this.onMotion?.(t);
2392
2392
  }
2393
- blinkValue(e) {
2393
+ blinkValue(t) {
2394
2394
  const n = this.blink;
2395
- if (n.t += e, n.t < n.start) return 1;
2395
+ if (n.t += t, n.t < n.start) return 1;
2396
2396
  const r = (n.t - n.start) / 0.17;
2397
2397
  return r >= 1 ? (n.double ? (n.double = !1, n.start = n.t + 0.07) : (n.start = n.t + 1.8 + Math.random() * 4.2, n.double = Math.random() < 0.18), 1) : r < 0.45 ? 1 - r / 0.45 : (r - 0.45) / 0.55;
2398
2398
  }
2399
- update(e) {
2400
- this.t += e;
2399
+ update(t) {
2400
+ this.t += t;
2401
2401
  const n = this.t, r = {};
2402
2402
  for (const h of bt) r[h.id] = h.def;
2403
2403
  if (this.mode === "manual")
2404
2404
  Object.assign(r, this.manual);
2405
2405
  else if (this.mode === "auto") {
2406
- if (r.angleX = ze(n * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = ze(n * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = ze(n * 0.12, 3) * 10, r.bodyAngleX = ze(n * 0.1, 4) * 5 * (this.planted ? 0.35 : 1), r.bodyAngleZ = ze(n * 0.09, 5) * 4 * (this.planted ? 0.35 : 1), r.weightShift = this.planted ? Ir(n) : 0.7 * Math.sin(n * Math.PI * 2 / 5), r.armAngle = ze(n * 0.14, 6) * 5, r.handAngle = ze(n * 0.21, 7) * 5, n > this.gaze.next) {
2406
+ if (r.angleX = ze(n * 0.18, 1) * 10 + this.gaze.x * 11, r.angleY = ze(n * 0.15, 2) * 6 - 1 + this.gaze.y * 7, r.angleZ = ze(n * 0.12, 3) * 10, r.bodyAngleX = ze(n * 0.1, 4) * 5 * (this.planted ? 0.35 : 1), r.bodyAngleZ = ze(n * 0.09, 5) * 4 * (this.planted ? 0.35 : 1), r.weightShift = this.planted ? Xr(n) : 0.7 * Math.sin(n * Math.PI * 2 / 5), r.armAngle = ze(n * 0.14, 6) * 5, r.handAngle = ze(n * 0.21, 7) * 5, n > this.gaze.next) {
2407
2407
  const h = Math.random();
2408
2408
  this.gaze.x = h < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.8, this.gaze.y = h < 0.45 ? 0 : (Math.random() * 2 - 1) * 0.5, this.gaze.next = n + 0.8 + Math.random() * 2.5;
2409
2409
  }
2410
2410
  if (r.gazeX = this.gaze.x + r.angleX / 60, r.gazeY = this.gaze.y + r.angleY / 60, n > this.tap.next && (this.tap.until = n + 1.1, this.tap.next = n + 5 + Math.random() * 6), this.speaking) {
2411
2411
  this.nextIdle = Math.max(this.nextIdle, n + 2.5), this.nextAuto = Math.max(this.nextAuto, n + 6);
2412
2412
  const h = this.talkGain;
2413
- this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * h - (this.talkNod ?? 0)) * Math.min(1, e * 6), r.angleY -= this.talkNod, r.angleX += ze(n * 0.6, 11) * 5 * h, r.angleZ += ze(n * 0.5, 12) * 4 * h;
2413
+ this.talkNod = (this.talkNod ?? 0) + (this.voice * 7 * h - (this.talkNod ?? 0)) * Math.min(1, t * 6), r.angleY -= this.talkNod, r.angleX += ze(n * 0.6, 11) * 5 * h, r.angleZ += ze(n * 0.5, 12) * 4 * h;
2414
2414
  }
2415
- !this.speaking && n > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && n > this.nextAuto ? (this.playRandom(Object.keys(tn).filter((h) => h !== "surprise")), this.nextAuto = n + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, n + 5)) : !this.play && this.autoIdle && n > this.nextIdle && (this.playRandom(Object.keys(nn)), this.nextIdle = n + 5 + Math.random() * 5));
2415
+ !this.speaking && n > this.emotionUntil && (this.expr = "normal", this.emotionUntil = 1 / 0), this.speaking || (!this.play && this.autoMotion && n > this.nextAuto ? (this.playRandom(Object.keys(nn).filter((h) => h !== "surprise")), this.nextAuto = n + 15 + Math.random() * 10, this.nextIdle = Math.max(this.nextIdle, n + 5)) : !this.play && this.autoIdle && n > this.nextIdle && (this.playRandom(Object.keys(rn)), this.nextIdle = n + 5 + Math.random() * 5));
2416
2416
  } else if (this.mode === "mouse" && this.pointer) {
2417
2417
  const h = (this.pointer[0] - this.faceCenter[0]) / 500, p = (this.pointer[1] - this.faceCenter[1]) / 500;
2418
2418
  r.angleX = Te(h * 30, -30, 30), r.angleY = Te(-p * 30, -30, 30), r.angleZ = Te(-h * p * 25, -12, 12), r.bodyAngleX = Te(h * 10, -10, 10) * 0.6, r.gazeX = Te(h * 1.4, -1, 1), r.gazeY = Te(-p * 1.4, -1, 1), r.handAngle = Te(h * 4, -5, 5);
2419
2419
  }
2420
- this.mode !== "manual" && (r.breath = this.breathValue(e), n < this.tap.until && (r.fingerTap = Math.max(0, Math.sin((this.tap.until - n) * Math.PI * 3.6)) ** 2));
2421
- let o = null, a = 0;
2420
+ this.mode !== "manual" && (r.breath = this.breathValue(t), n < this.tap.until && (r.fingerTap = Math.max(0, Math.sin((this.tap.until - n) * Math.PI * 3.6)) ** 2));
2421
+ let o = null, s = 0;
2422
2422
  if (this.play) {
2423
- const h = Ft[this.play.id];
2424
- if (this.play.t += e, this.play.t >= h.dur)
2423
+ const h = jt[this.play.id];
2424
+ if (this.play.t += t, this.play.t >= h.dur)
2425
2425
  this.play = null, this.onMotion?.(null);
2426
2426
  else {
2427
2427
  o = {};
2428
2428
  for (const [p, g] of Object.entries(h.tracks))
2429
- o[p] = Or(g, this.play.t) * (h.idle && $r.test(p) ? yn.amp : 1);
2430
- a = xt(0, 0.15, this.play.t) * (1 - xt(h.dur - 0.25, h.dur, this.play.t));
2429
+ o[p] = Rr(g, this.play.t) * (h.idle && Yr.test(p) ? vn.amp : 1);
2430
+ s = xt(0, 0.15, this.play.t) * (1 - xt(h.dur - 0.25, h.dur, this.play.t));
2431
2431
  for (const [p, g] of Object.entries(o))
2432
- Sr.has(p) ? r[p] += g : p === "breath" ? r[p] += (g - r[p]) * a : Ur.has(p) || (r[p] = Math.max(r[p], Math.max(0, g)));
2432
+ Tr.has(p) ? r[p] += g : p === "breath" ? r[p] += (g - r[p]) * s : Ir.has(p) || (r[p] = Math.max(r[p], Math.max(0, g)));
2433
2433
  }
2434
2434
  }
2435
2435
  if (this.mode !== "manual" && (r.angleY += r.breath * 1.6), this.armRig?.arms && this.mode !== "manual") {
2436
- const { arms: h, body: p, legs: g } = this.armRig, b = -r.bodyAngleZ / 10 * p.maxRoll + (g ? g.tilt * (1 - (g.spine ?? 0.7)) * r.weightShift : 0), s = Te(e, 0, 0.05), d = Math.ceil(s * 240);
2436
+ const { arms: h, body: p, legs: g } = this.armRig, b = -r.bodyAngleZ / 10 * p.maxRoll + (g ? g.tilt * (1 - (g.spine ?? 0.7)) * r.weightShift : 0), a = Te(t, 0, 0.05), d = Math.ceil(a * 240);
2437
2437
  for (let A = 0; A < d; A++) {
2438
- const L = s / d;
2438
+ const L = a / d;
2439
2439
  this.armVelocity += (100 * (-b * 0.65 - this.armFollow) - 18 * this.armVelocity) * L, this.armFollow += this.armVelocity * L;
2440
2440
  }
2441
2441
  const x = (h.swing ?? mt.swing) * Math.PI / 180, w = h.inward ?? mt.inward;
@@ -2444,7 +2444,7 @@ class Nr {
2444
2444
  r[`armSwing${A}`] = Te((Y > 0 ? z / Y : 0) + (r.breath - 0.5) * 0.06, -1, 1), r[`elbowBend${A}`] = r.breath * 0.025;
2445
2445
  }
2446
2446
  }
2447
- const i = jn[this.expr].p, u = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], y = {
2447
+ const i = $n[this.expr].p, u = ["eyeOpen", "eyeOpenL", "eyeSmileL", "eyeSmile", "mouthOpen", "mouthForm", "blush", "browY", "browAngle", "gx", "gy"], y = {
2448
2448
  eyeOpen: i.eyeOpen ?? 1,
2449
2449
  eyeOpenL: i.eyeOpenL ?? i.eyeOpen ?? 1,
2450
2450
  eyeSmileL: i.eyeSmileL ?? i.eyeSmile ?? 0,
@@ -2456,7 +2456,7 @@ class Nr {
2456
2456
  browAngle: i.browAngle ?? 0,
2457
2457
  gx: i.glance?.[0] ?? 0,
2458
2458
  gy: i.glance?.[1] ?? 0
2459
- }, v = 1 - Math.exp(-e * 9);
2459
+ }, v = 1 - Math.exp(-t * 9);
2460
2460
  for (const h of u)
2461
2461
  this.exprMix[h] === void 0 && (this.exprMix[h] = y[h]), this.exprMix[h] += (y[h] - this.exprMix[h]) * v;
2462
2462
  const m = this.exprMix, l = {};
@@ -2466,25 +2466,25 @@ class Nr {
2466
2466
  l[p] = r[p], this.cur[p] = r[p], this.vel[p] = 0;
2467
2467
  continue;
2468
2468
  }
2469
- let [g, b] = Yr[p] ?? [120, 0.95];
2470
- o && /^angle|^body/.test(p) && (Ft[this.play?.id ?? ""]?.idle ? (g *= yn.stiff, b = 0.8) : /^angle/.test(p) && (g *= 4.5, b = 0.75));
2471
- const s = 2 * Math.sqrt(g) * b;
2472
- this.vel[p] += (g * (r[p] - this.cur[p]) - s * this.vel[p]) * e, this.cur[p] += this.vel[p] * e, l[p] = this.cur[p];
2469
+ let [g, b] = Nr[p] ?? [120, 0.95];
2470
+ o && /^angle|^body/.test(p) && (jt[this.play?.id ?? ""]?.idle ? (g *= vn.stiff, b = 0.8) : /^angle/.test(p) && (g *= 4.5, b = 0.75));
2471
+ const a = 2 * Math.sqrt(g) * b;
2472
+ this.vel[p] += (g * (r[p] - this.cur[p]) - a * this.vel[p]) * t, this.cur[p] += this.vel[p] * t, l[p] = this.cur[p];
2473
2473
  }
2474
2474
  let c = 1;
2475
- if (this.mode !== "manual" ? (c = this.blinkValue(e), l.eyeROpen = m.eyeOpen * c, l.eyeLOpen = m.eyeOpenL * c, l.eyeSmile = m.eyeSmile, l.eyeSmileL = m.eyeSmileL, l.mouthOpen = m.mouthOpen, l.mouthForm = m.mouthForm, l.blush = m.blush, l.browY = m.browY + (l.angleY > 0 ? l.angleY / 60 : 0) - (1 - c) * 0.18, l.browAngle = m.browAngle, l.gazeX = Te(l.gazeX + m.gx, -1, 1), l.gazeY = Te(l.gazeY + m.gy, -1, 1)) : l.eyeSmileL = l.eyeSmile, o) {
2475
+ if (this.mode !== "manual" ? (c = this.blinkValue(t), l.eyeROpen = m.eyeOpen * c, l.eyeLOpen = m.eyeOpenL * c, l.eyeSmile = m.eyeSmile, l.eyeSmileL = m.eyeSmileL, l.mouthOpen = m.mouthOpen, l.mouthForm = m.mouthForm, l.blush = m.blush, l.browY = m.browY + (l.angleY > 0 ? l.angleY / 60 : 0) - (1 - c) * 0.18, l.browAngle = m.browAngle, l.gazeX = Te(l.gazeX + m.gx, -1, 1), l.gazeY = Te(l.gazeY + m.gy, -1, 1)) : l.eyeSmileL = l.eyeSmile, o) {
2476
2476
  const h = (g, b) => {
2477
- l[g] += (b - l[g]) * a;
2477
+ l[g] += (b - l[g]) * s;
2478
2478
  }, p = (g) => Math.min(1.3, Math.max(0, g));
2479
2479
  "eyeOpen" in o && (h("eyeROpen", p(o.eyeOpen) * c), "eyeOpenL" in o || h("eyeLOpen", p(o.eyeOpen) * c)), "eyeOpenL" in o && h("eyeLOpen", p(o.eyeOpenL) * c), "eyeSmile" in o && (h("eyeSmile", o.eyeSmile), "eyeSmileL" in o || h("eyeSmileL", o.eyeSmile)), "eyeSmileL" in o && h("eyeSmileL", o.eyeSmileL);
2480
2480
  for (const g of ["mouthOpen", "mouthForm", "blush", "browY", "browAngle"])
2481
2481
  g in o && h(g, g === "mouthOpen" || g === "blush" ? Math.max(0, o[g]) : o[g]);
2482
2482
  }
2483
- const f = this.speechMouth(e);
2483
+ const f = this.speechMouth(t);
2484
2484
  return f ? (this.lipOpen = f[0], this.lipForm = f[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 = Te(this.lipForm, -1, 1)), this.P = l, l;
2485
2485
  }
2486
2486
  }
2487
- const rn = {
2487
+ const Ot = {
2488
2488
  neutral: "normal",
2489
2489
  smile: "smile",
2490
2490
  shy: "shy",
@@ -2493,95 +2493,123 @@ const rn = {
2493
2493
  angry: "angryTalk",
2494
2494
  sad: "sadTalk",
2495
2495
  wink: "wink"
2496
- }, Xr = { sad: { pitch: -6, gy: -0.45 } }, lt = (t, e, n) => Math.max(e, Math.min(n, t)), ct = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, gx: 0, gy: 0, pitch: 0 });
2497
- function zr(t) {
2498
- const e = jn[rn[t]]?.p ?? {}, n = Xr[t] ?? {};
2496
+ }, Cr = { sad: { pitch: -6, gy: -0.45 } }, lt = (e, t, n) => Math.max(t, Math.min(n, e)), ct = Object.freeze({ eyeOpen: 1, eyeOpenL: 1, eyeSmile: 0, eyeSmileL: 0, blush: 0, browY: 0, browAngle: 0, mouthOpen: 0, mouthForm: 0, gx: 0, gy: 0, pitch: 0 });
2497
+ function Dr(e, t = {}) {
2498
+ const n = $n[Ot[e]]?.p ?? {}, r = Cr[e] ?? {}, o = e === "neutral" ? void 0 : t[e]?.mouthOpen;
2499
2499
  return {
2500
- eyeOpen: e.eyeOpen ?? 1,
2501
- eyeOpenL: e.eyeOpenL ?? e.eyeOpen ?? 1,
2502
- eyeSmile: e.eyeSmile ?? 0,
2503
- eyeSmileL: e.eyeSmileL ?? e.eyeSmile ?? 0,
2504
- blush: e.blush ?? 0,
2505
- browY: e.browY ?? 0,
2506
- browAngle: e.browAngle ?? 0,
2507
- mouthOpen: e.mouthOpen ?? 0,
2508
- gx: e.glance?.[0] ?? 0,
2509
- gy: n.gy ?? e.glance?.[1] ?? 0,
2510
- pitch: n.pitch ?? 0
2500
+ eyeOpen: n.eyeOpen ?? 1,
2501
+ eyeOpenL: n.eyeOpenL ?? n.eyeOpen ?? 1,
2502
+ eyeSmile: n.eyeSmile ?? 0,
2503
+ eyeSmileL: n.eyeSmileL ?? n.eyeSmile ?? 0,
2504
+ blush: n.blush ?? 0,
2505
+ browY: n.browY ?? 0,
2506
+ browAngle: n.browAngle ?? 0,
2507
+ mouthOpen: o ?? n.mouthOpen ?? 0,
2508
+ mouthForm: n.mouthForm ?? 0,
2509
+ gx: n.glance?.[0] ?? 0,
2510
+ gy: r.gy ?? n.glance?.[1] ?? 0,
2511
+ pitch: r.pitch ?? 0
2511
2512
  };
2512
2513
  }
2513
- function Cr(t, e) {
2514
- const n = { ...t };
2515
- return n.eyeROpen = (t.eyeROpen ?? 1) * e.eyeOpen, n.eyeLOpen = (t.eyeLOpen ?? 1) * e.eyeOpenL, n.eyeSmile = Math.max(t.eyeSmile ?? 0, e.eyeSmile), n.eyeSmileL = Math.max(t.eyeSmileL ?? t.eyeSmile ?? 0, e.eyeSmileL), n.blush = Math.max(t.blush ?? 0, e.blush), n.browY = lt((t.browY ?? 0) + e.browY, -1, 1), n.browAngle = lt((t.browAngle ?? 0) + e.browAngle, -1, 1), n.mouthOpen = Math.max(t.mouthOpen ?? 0, e.mouthOpen), n.gazeX = lt((t.gazeX ?? 0) + e.gx, -1, 1), n.gazeY = lt((t.gazeY ?? 0) + e.gy, -1, 1), n.angleY = lt((t.angleY ?? 0) + e.pitch, -30, 30), n;
2514
+ function Pr(e, t) {
2515
+ const n = { ...e };
2516
+ return n.eyeROpen = (e.eyeROpen ?? 1) * t.eyeOpen, n.eyeLOpen = (e.eyeLOpen ?? 1) * t.eyeOpenL, n.eyeSmile = Math.max(e.eyeSmile ?? 0, t.eyeSmile), n.eyeSmileL = Math.max(e.eyeSmileL ?? e.eyeSmile ?? 0, t.eyeSmileL), n.blush = Math.max(e.blush ?? 0, t.blush), n.browY = lt((e.browY ?? 0) + t.browY, -1, 1), n.browAngle = lt((e.browAngle ?? 0) + t.browAngle, -1, 1), n.mouthOpen = Math.max(e.mouthOpen ?? 0, t.mouthOpen), t.mouthOpen > (e.mouthOpen ?? 0) && (n.mouthForm = t.mouthForm), n.gazeX = lt((e.gazeX ?? 0) + t.gx, -1, 1), n.gazeY = lt((e.gazeY ?? 0) + t.gy, -1, 1), n.angleY = lt((e.angleY ?? 0) + t.pitch, -30, 30), n;
2516
2517
  }
2517
- class Dr {
2518
+ class Hr {
2518
2519
  /** @type {keyof typeof OVERLAY_EXPRESSIONS} */
2519
2520
  name = "neutral";
2520
2521
  mix = { ...ct };
2522
+ /** @param {Record<string, { mouthOpen?: number }>} [settings] parsed per-expression settings */
2523
+ constructor(t = {}) {
2524
+ this.settings = t;
2525
+ }
2521
2526
  /** @param {string} name */
2522
- set(e) {
2523
- this.name = Object.hasOwn(rn, e) ? (
2527
+ set(t) {
2528
+ this.name = Object.hasOwn(Ot, t) ? (
2524
2529
  /** @type {keyof typeof OVERLAY_EXPRESSIONS} */
2525
- e
2530
+ t
2526
2531
  ) : "neutral";
2527
2532
  }
2528
2533
  /** True while an expression is shown or still fading out. */
2529
2534
  get active() {
2530
- return this.name !== "neutral" || Object.keys(ct).some((e) => Math.abs(this.mix[e] - ct[e]) > 1e-3);
2535
+ return this.name !== "neutral" || Object.keys(ct).some((t) => Math.abs(this.mix[t] - ct[t]) > 1e-3);
2531
2536
  }
2532
- apply(e, n) {
2537
+ apply(t, n) {
2533
2538
  if (!this.active)
2534
- return this.mix = { ...ct }, e;
2535
- const r = zr(this.name), o = 1 - Math.exp(-Math.max(0, n) * 12);
2536
- for (const a of Object.keys(ct)) this.mix[a] += (r[a] - this.mix[a]) * o;
2537
- return Cr(e, this.mix);
2538
- }
2539
- }
2540
- const wn = ["ball", "low", "crease", "lash"], jt = /* @__PURE__ */ new Map(), Bt = /* @__PURE__ */ new Map();
2541
- async function $t(t) {
2542
- return Bt.has(t) || Bt.set(t, fetch(t).then((e) => {
2543
- if (!e.ok) throw new Error(`failed to load ${t}`);
2544
- return e.json();
2545
- })), Bt.get(t);
2546
- }
2547
- function Ut(t) {
2548
- if (jt.has(t)) return jt.get(t);
2549
- const e = new Promise((n, r) => {
2539
+ return this.mix = { ...ct }, t;
2540
+ const r = Dr(this.name, this.settings), o = 1 - Math.exp(-Math.max(0, n) * 12);
2541
+ for (const s of Object.keys(ct)) this.mix[s] += (r[s] - this.mix[s]) * o;
2542
+ return Pr(t, this.mix);
2543
+ }
2544
+ }
2545
+ const xn = (e) => !!e && typeof e == "object" && !Array.isArray(e);
2546
+ function on(e) {
2547
+ if (!xn(e)) throw new TypeError("expressions: expected an object");
2548
+ const t = {};
2549
+ for (const [n, r] of Object.entries(e)) {
2550
+ if (n === "neutral" || !Object.hasOwn(Ot, n)) continue;
2551
+ if (!xn(r)) throw new TypeError(`expressions.${n}: expected an object`);
2552
+ const o = {}, s = r.mouthOpen;
2553
+ if (s !== void 0) {
2554
+ if (typeof s != "number" || !Number.isFinite(s) || s < 0 || s > 1)
2555
+ throw new RangeError(`expressions.${n}.mouthOpen: expected 0–1`);
2556
+ o.mouthOpen = s;
2557
+ }
2558
+ t[n] = o;
2559
+ }
2560
+ return t;
2561
+ }
2562
+ function Vr(e = {}, t = {}) {
2563
+ const n = {};
2564
+ for (const r of /* @__PURE__ */ new Set([...Object.keys(e), ...Object.keys(t)]))
2565
+ n[r] = { ...e[r], ...t[r] };
2566
+ return n;
2567
+ }
2568
+ const Mn = ["ball", "low", "crease", "lash"], Bt = /* @__PURE__ */ new Map(), $t = /* @__PURE__ */ new Map();
2569
+ async function Ut(e) {
2570
+ return $t.has(e) || $t.set(e, fetch(e).then((t) => {
2571
+ if (!t.ok) throw new Error(`failed to load ${e}`);
2572
+ return t.json();
2573
+ })), $t.get(e);
2574
+ }
2575
+ function Yt(e) {
2576
+ if (Bt.has(e)) return Bt.get(e);
2577
+ const t = new Promise((n, r) => {
2550
2578
  const o = new Image();
2551
- o.onload = () => n(o), o.onerror = () => r(new Error(`failed to load ${t}`)), o.src = t;
2579
+ o.onload = () => n(o), o.onerror = () => r(new Error(`failed to load ${e}`)), o.src = e;
2552
2580
  });
2553
- return jt.set(t, e), e;
2581
+ return Bt.set(e, t), t;
2554
2582
  }
2555
- function Bn(t, e) {
2583
+ function Un(e, t) {
2556
2584
  const n = document.createElement("canvas");
2557
- n.width = t.width, n.height = t.height;
2585
+ n.width = e.width, n.height = e.height;
2558
2586
  const r = n.getContext("2d");
2559
- r.drawImage(t, 0, 0);
2560
- const o = r.getImageData(0, 0, n.width, n.height).data, a = new Uint8Array(n.width * n.height);
2561
- for (let i = 0; i < a.length; i++) a[i] = o[i * 4 + e];
2562
- return a;
2563
- }
2564
- const Ze = (t) => Bn(t, 3);
2565
- function Pr(t, [e, n, r, o]) {
2566
- const a = document.createElement("canvas");
2567
- return a.width = r, a.height = o, a.getContext("2d").drawImage(t, e, n, r, o, 0, 0, r, o), a;
2568
- }
2569
- function Hr(t, e) {
2570
- const [n, r] = t.t.pivot, o = t.dir, a = t.pts, i = (f, h, p) => {
2587
+ r.drawImage(e, 0, 0);
2588
+ const o = r.getImageData(0, 0, n.width, n.height).data, s = new Uint8Array(n.width * n.height);
2589
+ for (let i = 0; i < s.length; i++) s[i] = o[i * 4 + t];
2590
+ return s;
2591
+ }
2592
+ const Ze = (e) => Un(e, 3);
2593
+ function Zr(e, [t, n, r, o]) {
2594
+ const s = document.createElement("canvas");
2595
+ return s.width = r, s.height = o, s.getContext("2d").drawImage(e, t, n, r, o, 0, 0, r, o), s;
2596
+ }
2597
+ function Wr(e, t) {
2598
+ const [n, r] = e.t.pivot, o = e.dir, s = e.pts, i = (f, h, p) => {
2571
2599
  const g = Math.min(1, Math.max(0, (p - f) / (h - f)));
2572
2600
  return g * g * (3 - 2 * g);
2573
- }, u = Math.cos(t.phi[0]), y = Math.sin(t.phi[0]), v = Math.cos(t.phi[1]), m = Math.sin(t.phi[1]), l = e.rest, c = e.pos;
2601
+ }, u = Math.cos(e.phi[0]), y = Math.sin(e.phi[0]), v = Math.cos(e.phi[1]), m = Math.sin(e.phi[1]), l = t.rest, c = t.pos;
2574
2602
  for (let f = 0; f < l.length; f += 2) {
2575
- const h = l[f] - n, p = l[f + 1] - r, g = h * o[0] + p * o[1], b = a[0][0] + h * u - p * y, s = a[0][1] + h * y + p * u, d = h - o[0] * t.L1, x = p - o[1] * t.L1, w = a[1][0] + d * v - x * m, A = a[1][1] + d * m + x * v, L = i(t.L1 * 0.55, t.L1 * 1.35, g);
2576
- c[f] = b + (w - b) * L, c[f + 1] = s + (A - s) * L;
2603
+ const h = l[f] - n, p = l[f + 1] - r, g = h * o[0] + p * o[1], b = s[0][0] + h * u - p * y, a = s[0][1] + h * y + p * u, d = h - o[0] * e.L1, x = p - o[1] * e.L1, w = s[1][0] + d * v - x * m, A = s[1][1] + d * m + x * v, L = i(e.L1 * 0.55, e.L1 * 1.35, g);
2604
+ c[f] = b + (w - b) * L, c[f + 1] = a + (A - a) * L;
2577
2605
  }
2578
2606
  }
2579
- async function Vr(t, e) {
2580
- if (!e.assets && e.assetsBase === void 0)
2607
+ async function Gr(e, t) {
2608
+ if (!t.assets && t.assetsBase === void 0)
2581
2609
  throw new Error("createMeshAvatar requires assets or assetsBase.");
2582
- const n = e.rig, r = Qn(n), {
2610
+ const n = t.rig, r = tr(n), {
2583
2611
  IMG: o,
2584
- EYES: a,
2612
+ EYES: s,
2585
2613
  baseWeights: i,
2586
2614
  deformBase: u,
2587
2615
  eyePartY: y,
@@ -2590,19 +2618,19 @@ async function Vr(t, e) {
2590
2618
  handFrame: l,
2591
2619
  deformHand: c,
2592
2620
  TASSELS: f
2593
- } = r, { Renderer: h, buildGrid: p } = mr(r, n), { Physics: g } = pr(r, n), { Cloth: b } = wr(r, n), s = n.cloth ?? [], { createSprites: d } = xr(r, n), x = (e.assetsBase ?? "").replace(/\/?$/, "/"), w = (S, R) => {
2594
- if (e.assets) {
2595
- if (!e.assets[S]) throw new Error(`Missing project asset: ${S}`);
2596
- return e.assets[S];
2621
+ } = r, { Renderer: h, buildGrid: p } = dr(r, n), { Physics: g } = gr(r, n), { Cloth: b } = Mr(r, n), a = n.cloth ?? [], { createSprites: d } = Ar(r, n), x = (t.assetsBase ?? "").replace(/\/?$/, "/"), w = (S, R) => {
2622
+ if (t.assets) {
2623
+ if (!t.assets[S]) throw new Error(`Missing project asset: ${S}`);
2624
+ return t.assets[S];
2597
2625
  }
2598
2626
  return `${x}${S}${R === void 0 ? "" : `?b=${R}`}`;
2599
- }, A = await $t(w("layers.json")), z = [s.length ? "base_cloth" : "base", ...n.hand ? ["hand"] : [], ...f.map((S) => S.name), ...s.map((S) => `cloth_${S.name}`), ...[0, 1].flatMap((S) => wn.map((R) => `eye${S}_${R}`)), "hairmask"], Y = Object.fromEntries(await Promise.all(z.map(async (S) => [S, await Ut(w(`${S}.png`, A.build))])));
2600
- s.length && (Y.base = Y.base_cloth);
2601
- const I = Bn(Y.hairmask, 0), U = (S, R) => I[Math.min(o.h - 1, Math.max(0, Math.round(R))) * o.w + Math.min(o.w - 1, Math.max(0, Math.round(S)))] / 255, T = new h(t, { padTop: e.padTop ?? n.view.padTop, padSide: e.padSide ?? n.view.padSide, fit: e.fit }), F = { base: [0, 0, o.w, o.h], ...A.layers }, j = new b(), C = (S) => {
2627
+ }, A = await Ut(w("layers.json")), z = [a.length ? "base_cloth" : "base", ...n.hand ? ["hand"] : [], ...f.map((S) => S.name), ...a.map((S) => `cloth_${S.name}`), ...[0, 1].flatMap((S) => Mn.map((R) => `eye${S}_${R}`)), "hairmask"], Y = Object.fromEntries(await Promise.all(z.map(async (S) => [S, await Yt(w(`${S}.png`, A.build))])));
2628
+ a.length && (Y.base = Y.base_cloth);
2629
+ const I = Un(Y.hairmask, 0), U = (S, R) => I[Math.min(o.h - 1, Math.max(0, Math.round(R))) * o.w + Math.min(o.w - 1, Math.max(0, Math.round(S)))] / 255, T = new h(e, { padTop: t.padTop ?? n.view.padTop, padSide: t.padSide ?? n.view.padSide, fit: t.fit }), F = { base: [0, 0, o.w, o.h], ...A.layers }, j = new b(), C = (S) => {
2602
2630
  const R = `cloth_${S.name}`, P = p(F[R], n.mesh.clothCell ?? 8, Ze(Y[R]), Y[R].width);
2603
2631
  j.attach(S.name, P), T.addLayer(R, Y[R], P);
2604
2632
  };
2605
- s.filter((S) => S.behind).forEach(C);
2633
+ a.filter((S) => S.behind).forEach(C);
2606
2634
  const B = p(F.base, n.mesh.baseCell, Ze(Y.base), Y.base.width, n.mesh.fine), H = [];
2607
2635
  for (let S = 0; S < B.rest.length / 2; S++) {
2608
2636
  const R = B.rest[S * 2], P = B.rest[S * 2 + 1];
@@ -2610,30 +2638,30 @@ async function Vr(t, e) {
2610
2638
  }
2611
2639
  T.addLayer("base", Y.base, B, { face: !0 });
2612
2640
  const N = [];
2613
- a.forEach((S, R) => {
2614
- for (const P of wn) {
2615
- const ae = `eye${R}_${P}`, ie = p(F[ae], P === "ball" ? n.mesh.eyeBallCell : n.mesh.eyeCell, Ze(Y[ae]), Y[ae].width), pe = [];
2641
+ s.forEach((S, R) => {
2642
+ for (const P of Mn) {
2643
+ const se = `eye${R}_${P}`, ie = p(F[se], P === "ball" ? n.mesh.eyeBallCell : n.mesh.eyeCell, Ze(Y[se]), Y[se].width), pe = [];
2616
2644
  for (let Me = 0; Me < ie.rest.length / 2; Me++) pe.push(i(ie.rest[Me * 2], ie.rest[Me * 2 + 1], 0));
2617
- const be = T.addLayer(ae, Y[ae], ie, { eyeBall: P === "ball" ? R : void 0 });
2645
+ const be = T.addLayer(se, Y[se], ie, { eyeBall: P === "ball" ? R : void 0 });
2618
2646
  N.push({ e: S, eye: R, part: P, mesh: ie, W: pe, layer: be });
2619
2647
  }
2620
2648
  });
2621
2649
  let ne = null;
2622
2650
  try {
2623
2651
  {
2624
- const S = await $t(w("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(S.layers).map(async (P) => [P, await Ut(w(`sprites/${P}.png`, S.build))])));
2652
+ const S = await Ut(w("sprites/sprites.json")), R = Object.fromEntries(await Promise.all(Object.keys(S.layers).map(async (P) => [P, await Yt(w(`sprites/${P}.png`, S.build))])));
2625
2653
  ne = d(T, S, R, p, Ze);
2626
2654
  }
2627
2655
  } catch (S) {
2628
2656
  console.warn("eye / mouth sprites not loaded:", S);
2629
2657
  }
2630
- s.filter((S) => !S.behind).forEach(C);
2658
+ a.filter((S) => !S.behind).forEach(C);
2631
2659
  let Q = null;
2632
2660
  try {
2633
- const S = await $t(w("overlays/overlays.json")), R = Object.fromEntries(await Promise.all(S.overlays.map(async (P) => [P.name, await Ut(w(`overlays/${P.file}`))])));
2634
- Q = Er(T, S, R, p, Ze, i, n.mesh.spriteCell, o.w, o.h, Pr);
2661
+ const S = await Ut(w("overlays/overlays.json")), R = Object.fromEntries(await Promise.all(S.overlays.map(async (P) => [P.name, await Yt(w(`overlays/${P.file}`))])));
2662
+ Q = Or(T, S, R, p, Ze, i, n.mesh.spriteCell, o.w, o.h, Zr);
2635
2663
  } catch (S) {
2636
- e.assets?.["overlays/overlays.json"] && console.warn("overlay layers not loaded:", S);
2664
+ t.assets?.["overlays/overlays.json"] && console.warn("overlay layers not loaded:", S);
2637
2665
  }
2638
2666
  const J = f.map((S) => {
2639
2667
  const R = p(F[S.name], n.mesh.tasselCell, Ze(Y[S.name]), Y[S.name].width);
@@ -2641,28 +2669,28 @@ async function Vr(t, e) {
2641
2669
  }), X = n.hand ? p(F.hand, n.mesh.handCell, Ze(Y.hand), Y.hand.width) : { rest: [], pos: [] }, G = [];
2642
2670
  for (let S = 0; S < X.rest.length / 2; S++) G.push(m(X.rest[S * 2], X.rest[S * 2 + 1]));
2643
2671
  n.hand && T.addLayer("hand", Y.hand, X);
2644
- const re = new g(), W = new Nr(n.view.gazeCenter ?? [n.head.cx, n.head.cy], !!n.legs, n.arms ? n : null);
2645
- e.lipSync !== void 0 && W.setLipSync(e.lipSync);
2672
+ const re = new g(), W = new zr(n.view.gazeCenter ?? [n.head.cx, n.head.cy], !!n.legs, n.arms ? n : null);
2673
+ t.lipSync !== void 0 && W.setLipSync(t.lipSync);
2646
2674
  const te = /* @__PURE__ */ new Set();
2647
2675
  W.onMotion = (S) => {
2648
2676
  for (const R of te) R(S);
2649
2677
  };
2650
- let se = {}, V = 1, M = {}, E = {};
2651
- const O = new Dr(), k = [0, 0];
2678
+ let ae = {}, V = 1, M = {}, E = {};
2679
+ const O = new Hr(t.expressions === void 0 ? void 0 : on(t.expressions)), k = [0, 0];
2652
2680
  function $(S) {
2653
2681
  const R = { ...W.update(S) };
2654
- for (const [ae, ie] of Object.entries(se)) {
2655
- const pe = V * (M[ae] ?? 1);
2656
- R[ae] = pe === 1 ? ie : (R[ae] ?? 0) + (ie - (R[ae] ?? 0)) * pe;
2682
+ for (const [se, ie] of Object.entries(ae)) {
2683
+ const pe = V * (M[se] ?? 1);
2684
+ R[se] = pe === 1 ? ie : (R[se] ?? 0) + (ie - (R[se] ?? 0)) * pe;
2657
2685
  }
2658
- W.lipOpen !== null && (R.mouthOpen = W.P.mouthOpen, (!e.preserveMouthForm || se.mouthForm === void 0) && (R.mouthForm = W.P.mouthForm));
2686
+ W.lipOpen !== null && (R.mouthOpen = W.P.mouthOpen, (!t.preserveMouthForm || ae.mouthForm === void 0) && (R.mouthForm = W.P.mouthForm));
2659
2687
  const P = O.apply(R, S);
2660
2688
  return E = P, P;
2661
2689
  }
2662
2690
  function Z(S) {
2663
- const R = $(S), P = re.step(R, S), ae = B.pos, ie = B.rest;
2691
+ const R = $(S), P = re.step(R, S), se = B.pos, ie = B.rest;
2664
2692
  for (let K = 0; K < H.length; K++)
2665
- u(ie[K * 2], ie[K * 2 + 1], H[K], R, P, k), ae[K * 2] = k[0], ae[K * 2 + 1] = k[1];
2693
+ u(ie[K * 2], ie[K * 2 + 1], H[K], R, P, k), se[K * 2] = k[0], se[K * 2 + 1] = k[1];
2666
2694
  const pe = (K, ce) => ne?.eyesDrawn[ce] ? 1 : K;
2667
2695
  for (const K of N) {
2668
2696
  const ce = pe(K.eye === 0 ? R.eyeROpen : R.eyeLOpen, K.eye), ue = K.eye === 0 ? R.eyeSmile : R.eyeSmileL ?? R.eyeSmile;
@@ -2673,13 +2701,13 @@ async function Vr(t, e) {
2673
2701
  u(Le, y(K.e, K.part, Le, $e, ce, ue), K.W[ye], R, P, k), Se[ye * 2] = k[0], Se[ye * 2 + 1] = k[1];
2674
2702
  }
2675
2703
  }
2676
- const be = ne?.update(R, P, S, Mr(O.name, W.mode === "manual" ? null : W.expr));
2704
+ const be = ne?.update(R, P, S, Er(O.name, W.mode === "manual" ? null : W.expr));
2677
2705
  if (be) for (const K of N) be.eyes[K.eye] && (K.layer.alpha = 0);
2678
2706
  Q?.update(R, P, u, k);
2679
2707
  const Me = X.pos, Be = X.rest, Ee = l(R);
2680
2708
  for (let K = 0; K < G.length; K++)
2681
2709
  c(Be[K * 2], Be[K * 2 + 1], G[K], R, Ee, k), Me[K * 2] = k[0], Me[K * 2 + 1] = k[1];
2682
- re.chains.forEach((K, ce) => Hr(K, J[ce].mesh)), s.length && (j.step(R, S, P), j.deform());
2710
+ re.chains.forEach((K, ce) => Wr(K, J[ce].mesh)), a.length && (j.step(R, S, P), j.deform());
2683
2711
  const de = n.view.irisTravel ?? 7;
2684
2712
  T.draw({
2685
2713
  angleX: R.angleX,
@@ -2709,13 +2737,13 @@ async function Vr(t, e) {
2709
2737
  const R = Math.min(0.05, (S - D) / 1e3);
2710
2738
  D = S, Z(R), _ = requestAnimationFrame(ee);
2711
2739
  };
2712
- return e.manual || (_ = requestAnimationFrame(ee)), {
2740
+ return t.manual || (_ = requestAnimationFrame(ee)), {
2713
2741
  motions: [
2714
- ...Object.entries(tn).map(([S, R]) => ({ id: S, label: R.label, idle: !1 })),
2715
- ...Object.entries(nn).map(([S, R]) => ({ id: S, label: R.label, idle: !0 }))
2742
+ ...Object.entries(nn).map(([S, R]) => ({ id: S, label: R.label, idle: !1 })),
2743
+ ...Object.entries(rn).map(([S, R]) => ({ id: S, label: R.label, idle: !0 }))
2716
2744
  ],
2717
2745
  setParameters(S, R = 1, P = {}) {
2718
- se = { ...S }, V = Math.min(1, Math.max(0, Number(R) || 0)), M = Object.fromEntries(Object.entries(P ?? {}).map(([ae, ie]) => [ae, Math.min(1, Math.max(0, Number(ie) || 0))]));
2746
+ ae = { ...S }, V = Math.min(1, Math.max(0, Number(R) || 0)), M = Object.fromEntries(Object.entries(P ?? {}).map(([se, ie]) => [se, Math.min(1, Math.max(0, Number(ie) || 0))]));
2719
2747
  },
2720
2748
  getParameters() {
2721
2749
  return { ...E };
@@ -2806,153 +2834,159 @@ async function Vr(t, e) {
2806
2834
  }
2807
2835
  };
2808
2836
  }
2809
- const Mo = Object.keys(rn);
2810
- async function Zr(t, e) {
2811
- return Vr(t, { ...e, rig: Qt(e.rig) });
2837
+ const So = Object.keys(Ot);
2838
+ async function qr(e, t) {
2839
+ return Gr(e, { ...t, rig: en(t.rig) });
2812
2840
  }
2813
- function tt(t) {
2814
- if (!t || typeof t != "object" || Array.isArray(t))
2841
+ function tt(e) {
2842
+ if (!e || typeof e != "object" || Array.isArray(e))
2815
2843
  throw new Error("avatar.json: expected an object");
2816
- const e = t, n = [];
2817
- e.format !== "mesh-avatar" && n.push('avatar.json.format: expected "mesh-avatar"'), e.version !== 1 && n.push(`avatar.json.version: unsupported version ${JSON.stringify(e.version) ?? "missing"} (expected 1)`), (typeof e.name != "string" || !e.name.trim()) && n.push("avatar.json.name: expected a non-empty string");
2818
- const r = { format: "mesh-avatar", version: 1, name: e.name };
2844
+ const t = e, n = [];
2845
+ t.format !== "mesh-avatar" && n.push('avatar.json.format: expected "mesh-avatar"'), t.version !== 1 && n.push(`avatar.json.version: unsupported version ${JSON.stringify(t.version) ?? "missing"} (expected 1)`), (typeof t.name != "string" || !t.name.trim()) && n.push("avatar.json.name: expected a non-empty string");
2846
+ const r = { format: "mesh-avatar", version: 1, name: t.name };
2819
2847
  for (const o of ["author", "license", "thumbnail", "source"])
2820
- e[o] !== void 0 && (typeof e[o] != "string" ? n.push(`avatar.json.${o}: expected a string`) : r[o] = e[o]);
2821
- if (e.studio !== void 0) {
2822
- const o = e.studio;
2848
+ t[o] !== void 0 && (typeof t[o] != "string" ? n.push(`avatar.json.${o}: expected a string`) : r[o] = t[o]);
2849
+ if (t.studio !== void 0) {
2850
+ const o = t.studio;
2823
2851
  !o || typeof o != "object" || Array.isArray(o) || !("version" in o) || typeof o.version != "string" || !o.version.trim() ? n.push("avatar.json.studio.version: expected a non-empty string") : r.studio = { version: o.version };
2824
2852
  }
2825
- if (e.lipSync !== void 0)
2853
+ if (t.lipSync !== void 0)
2826
2854
  try {
2827
- r.lipSync = en(e.lipSync);
2855
+ r.lipSync = tn(t.lipSync);
2828
2856
  } catch (o) {
2829
2857
  n.push(`avatar.json.lipSync: ${o instanceof Error ? o.message : String(o)}`);
2830
2858
  }
2859
+ if (t.expressions !== void 0)
2860
+ try {
2861
+ r.expressions = on(t.expressions);
2862
+ } catch (o) {
2863
+ n.push(`avatar.json.expressions: ${o instanceof Error ? o.message : String(o)}`);
2864
+ }
2831
2865
  if (n.length) throw new Error(n.join(`
2832
2866
  `));
2833
2867
  return r;
2834
2868
  }
2835
- function $n(t) {
2836
- return tt({ format: "mesh-avatar", version: 1, name: t });
2869
+ function Yn(e) {
2870
+ return tt({ format: "mesh-avatar", version: 1, name: e });
2837
2871
  }
2838
- const Mt = (t) => !!t && typeof t == "object" && !Array.isArray(t), We = (t, e) => Array.isArray(t) && t.length === e && t.every((n) => typeof n == "number" && Number.isFinite(n)), Yt = (t, e) => Object.hasOwn(t, e);
2839
- function Un(t) {
2840
- const e = [];
2872
+ const Mt = (e) => !!e && typeof e == "object" && !Array.isArray(e), We = (e, t) => Array.isArray(e) && e.length === t && e.every((n) => typeof n == "number" && Number.isFinite(n)), It = (e, t) => Object.hasOwn(e, t);
2873
+ function In(e) {
2874
+ const t = [];
2841
2875
  function n(f, h = !0) {
2842
- if (!Yt(t, f)) {
2843
- h && e.push(`${f}: missing file`);
2876
+ if (!It(e, f)) {
2877
+ h && t.push(`${f}: missing file`);
2844
2878
  return;
2845
2879
  }
2846
- const p = t[f];
2880
+ const p = e[f];
2847
2881
  if (!(p instanceof Uint8Array)) {
2848
- e.push(`${f}: JSON bytes are required`);
2882
+ t.push(`${f}: JSON bytes are required`);
2849
2883
  return;
2850
2884
  }
2851
2885
  let g;
2852
2886
  try {
2853
2887
  g = JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(p));
2854
2888
  } catch {
2855
- e.push(`${f}: invalid UTF-8 JSON`);
2889
+ t.push(`${f}: invalid UTF-8 JSON`);
2856
2890
  return;
2857
2891
  }
2858
2892
  if (!Mt(g)) {
2859
- e.push(`${f}: expected an object`);
2893
+ t.push(`${f}: expected an object`);
2860
2894
  return;
2861
2895
  }
2862
2896
  return g;
2863
2897
  }
2864
2898
  function r(f, h, p = !0) {
2865
- return f.version === 1 || p && f.version === void 0 ? !0 : (e.push(`${h}.version: unsupported version ${JSON.stringify(f.version) ?? "missing"} (expected 1)`), !1);
2899
+ return f.version === 1 || p && f.version === void 0 ? !0 : (t.push(`${h}.version: unsupported version ${JSON.stringify(f.version) ?? "missing"} (expected 1)`), !1);
2866
2900
  }
2867
2901
  function o(f) {
2868
- if (!Yt(t, f)) {
2869
- e.push(`${f}: missing file`);
2902
+ if (!It(e, f)) {
2903
+ t.push(`${f}: missing file`);
2870
2904
  return;
2871
2905
  }
2872
- const h = t[f], p = h instanceof Uint8Array ? h.byteLength : h?.size;
2873
- (!Number.isSafeInteger(p) || p <= 0) && e.push(`${f}: expected a non-empty file`);
2906
+ const h = e[f], p = h instanceof Uint8Array ? h.byteLength : h?.size;
2907
+ (!Number.isSafeInteger(p) || p <= 0) && t.push(`${f}: expected a non-empty file`);
2874
2908
  }
2875
- function a(f, h, p, g) {
2909
+ function s(f, h, p, g) {
2876
2910
  if (!Mt(f)) {
2877
- e.push(`${h}.layers: expected a layer rectangle map`);
2911
+ t.push(`${h}.layers: expected a layer rectangle map`);
2878
2912
  return;
2879
2913
  }
2880
- for (const [b, s] of Object.entries(f)) {
2914
+ for (const [b, a] of Object.entries(f)) {
2881
2915
  const d = `${h}.layers.${b}`;
2882
2916
  if (!/^[A-Za-z0-9_-]+$/.test(b)) {
2883
- e.push(`${d}: expected a safe layer name (letters, digits, hyphens or underscores)`);
2917
+ t.push(`${d}: expected a safe layer name (letters, digits, hyphens or underscores)`);
2884
2918
  continue;
2885
2919
  }
2886
- !We(s, 4) || !s.every(Number.isInteger) || s[0] < 0 || s[1] < 0 || s[2] <= 0 || s[3] <= 0 ? e.push(`${d}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : g && (s[0] + s[2] > g[0] || s[1] + s[3] > g[1]) && e.push(`${d}: rectangle must stay inside the image`), o(`${p}/${b}.png`);
2920
+ !We(a, 4) || !a.every(Number.isInteger) || a[0] < 0 || a[1] < 0 || a[2] <= 0 || a[3] <= 0 ? t.push(`${d}: expected [x, y, width, height] with non-negative integer origins and positive integer dimensions`) : g && (a[0] + a[2] > g[0] || a[1] + a[3] > g[1]) && t.push(`${d}: rectangle must stay inside the image`), o(`${p}/${b}.png`);
2887
2921
  }
2888
2922
  return f;
2889
2923
  }
2890
2924
  function i(f, h) {
2891
- (typeof f.build != "string" || !f.build.trim()) && e.push(`${h}.build: expected a non-empty string`);
2925
+ (typeof f.build != "string" || !f.build.trim()) && t.push(`${h}.build: expected a non-empty string`);
2892
2926
  }
2893
2927
  const u = n("avatar.json", !1);
2894
2928
  if (u)
2895
2929
  try {
2896
2930
  tt(u);
2897
2931
  } catch (f) {
2898
- e.push(f.message);
2932
+ t.push(f.message);
2899
2933
  }
2900
2934
  const y = n("rig.json");
2901
2935
  let v;
2902
2936
  if (y && r(y, "rig.json", !1)) {
2903
- const f = Rn(y);
2904
- e.push(...f.map((h) => `rig.json: ${h}`)), f.length || (v = y);
2937
+ const f = Ln(y);
2938
+ t.push(...f.map((h) => `rig.json: ${h}`)), f.length || (v = y);
2905
2939
  }
2906
2940
  o("built/base.png"), o("built/hairmask.png"), v?.cloth?.length && o("built/base_cloth.png");
2907
2941
  const m = n("built/layers.json");
2908
2942
  if (m && r(m, "built/layers.json")) {
2909
2943
  i(m, "built/layers.json");
2910
2944
  let f;
2911
- !We(m.size, 2) || !m.size.every((p) => Number.isInteger(p) && p > 0) ? e.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (f = m.size, v && (f[0] !== v.image.width || f[1] !== v.image.height) && e.push("built/layers.json.size: must match rig.json.image"));
2912
- const h = a(m.layers, "built/layers.json", "built", f);
2945
+ !We(m.size, 2) || !m.size.every((p) => Number.isInteger(p) && p > 0) ? t.push("built/layers.json.size: expected [width, height] with positive integer dimensions") : (f = m.size, v && (f[0] !== v.image.width || f[1] !== v.image.height) && t.push("built/layers.json.size: must match rig.json.image"));
2946
+ const h = s(m.layers, "built/layers.json", "built", f);
2913
2947
  if (v && h) {
2914
2948
  const p = [
2915
- ...v.eyes.flatMap((g, b) => ["ball", "low", "crease", "lash"].map((s) => `eye${b}_${s}`)),
2949
+ ...v.eyes.flatMap((g, b) => ["ball", "low", "crease", "lash"].map((a) => `eye${b}_${a}`)),
2916
2950
  ...v.hand ? ["hand"] : [],
2917
2951
  ...(v.accessories ?? []).map((g) => g.name),
2918
2952
  ...(v.cloth ?? []).map((g) => `cloth_${g.name}`)
2919
2953
  ];
2920
- for (const g of p) Yt(h, g) || e.push(`built/layers.json.layers.${g}: missing required layer`);
2954
+ for (const g of p) It(h, g) || t.push(`built/layers.json.layers.${g}: missing required layer`);
2921
2955
  }
2922
- !Array.isArray(m.eyes) || m.eyes.length !== 2 ? e.push("built/layers.json.eyes: expected two eye curves") : m.eyes.forEach((p, g) => {
2956
+ !Array.isArray(m.eyes) || m.eyes.length !== 2 ? t.push("built/layers.json.eyes: expected two eye curves") : m.eyes.forEach((p, g) => {
2923
2957
  const b = `built/layers.json.eyes[${g}]`;
2924
2958
  if (!Mt(p)) {
2925
- e.push(`${b}: expected an object`);
2959
+ t.push(`${b}: expected an object`);
2926
2960
  return;
2927
2961
  }
2928
- We([p.x0, p.x1], 2) && p.x0 < p.x1 || e.push(`${b}: expected finite x0 < x1`);
2962
+ We([p.x0, p.x1], 2) && p.x0 < p.x1 || t.push(`${b}: expected finite x0 < x1`);
2929
2963
  for (const d of ["top", "bot"])
2930
- We(p[d], 24) || e.push(`${b}.${d}: expected 24 finite numbers`);
2931
- if (We(p.top, 24) && We(p.bot, 24) && p.top.some((d, x) => d > p.bot[x]) && e.push(`${b}.top: must not exceed bottom curve`), v) for (const d of ["x0", "x1", "top", "bot"]) {
2964
+ We(p[d], 24) || t.push(`${b}.${d}: expected 24 finite numbers`);
2965
+ if (We(p.top, 24) && We(p.bot, 24) && p.top.some((d, x) => d > p.bot[x]) && t.push(`${b}.top: must not exceed bottom curve`), v) for (const d of ["x0", "x1", "top", "bot"]) {
2932
2966
  const x = p[d], w = v.eyes[g][d];
2933
- (Array.isArray(w) ? We(x, w.length) && x.every((L, z) => L === w[z]) : x === w) || e.push(`${b}.${d}: must match rig.json.eyes[${g}].${d}`);
2967
+ (Array.isArray(w) ? We(x, w.length) && x.every((L, z) => L === w[z]) : x === w) || t.push(`${b}.${d}: must match rig.json.eyes[${g}].${d}`);
2934
2968
  }
2935
2969
  });
2936
2970
  }
2937
2971
  const l = n("built/sprites/sprites.json", !1);
2938
- l && r(l, "built/sprites/sprites.json") && (i(l, "built/sprites/sprites.json"), a(l.layers, "built/sprites/sprites.json", "built/sprites", v ? [v.image.width, v.image.height] : void 0));
2972
+ l && r(l, "built/sprites/sprites.json") && (i(l, "built/sprites/sprites.json"), s(l.layers, "built/sprites/sprites.json", "built/sprites", v ? [v.image.width, v.image.height] : void 0));
2939
2973
  const c = n("built/overlays/overlays.json", !1);
2940
2974
  if (c && r(c, "built/overlays/overlays.json"))
2941
- if (!Array.isArray(c.overlays)) e.push("built/overlays/overlays.json.overlays: expected an array");
2975
+ if (!Array.isArray(c.overlays)) t.push("built/overlays/overlays.json.overlays: expected an array");
2942
2976
  else {
2943
2977
  const f = /* @__PURE__ */ new Set();
2944
2978
  for (const [h, p] of c.overlays.entries()) {
2945
2979
  const g = `built/overlays/overlays.json.overlays[${h}]`;
2946
2980
  if (!Mt(p) || typeof p.name != "string" || !/^[A-Za-z0-9_-]+$/.test(p.name) || typeof p.file != "string" || !/^[A-Za-z0-9_-]+\.png$/.test(p.file)) {
2947
- e.push(`${g}: expected { name, file } with safe names`);
2981
+ t.push(`${g}: expected { name, file } with safe names`);
2948
2982
  continue;
2949
2983
  }
2950
- f.has(p.name) && e.push(`${g}.name: duplicate overlay name`), f.add(p.name), o(`built/overlays/${p.file}`);
2984
+ f.has(p.name) && t.push(`${g}.name: duplicate overlay name`), f.add(p.name), o(`built/overlays/${p.file}`);
2951
2985
  }
2952
2986
  }
2953
- return e;
2987
+ return t;
2954
2988
  }
2955
- var ge = Uint8Array, Re = Uint16Array, on = Int32Array, Ot = new ge([
2989
+ var ge = Uint8Array, Re = Uint16Array, sn = Int32Array, Tt = new ge([
2956
2990
  0,
2957
2991
  0,
2958
2992
  0,
@@ -2987,7 +3021,7 @@ var ge = Uint8Array, Re = Uint16Array, on = Int32Array, Ot = new ge([
2987
3021
  0,
2988
3022
  /* impossible */
2989
3023
  0
2990
- ]), Tt = new ge([
3024
+ ]), Rt = new ge([
2991
3025
  0,
2992
3026
  0,
2993
3027
  0,
@@ -3021,37 +3055,37 @@ var ge = Uint8Array, Re = Uint16Array, on = Int32Array, Ot = new ge([
3021
3055
  /* unused */
3022
3056
  0,
3023
3057
  0
3024
- ]), Pt = new ge([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), Yn = function(t, e) {
3058
+ ]), Ht = new ge([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]), Nn = function(e, t) {
3025
3059
  for (var n = new Re(31), r = 0; r < 31; ++r)
3026
- n[r] = e += 1 << t[r - 1];
3027
- for (var o = new on(n[30]), r = 1; r < 30; ++r)
3028
- for (var a = n[r]; a < n[r + 1]; ++a)
3029
- o[a] = a - n[r] << 5 | r;
3060
+ n[r] = t += 1 << e[r - 1];
3061
+ for (var o = new sn(n[30]), r = 1; r < 30; ++r)
3062
+ for (var s = n[r]; s < n[r + 1]; ++s)
3063
+ o[s] = s - n[r] << 5 | r;
3030
3064
  return { b: n, r: o };
3031
- }, In = Yn(Ot, 2), Nn = In.b, Ht = In.r;
3032
- Nn[28] = 258, Ht[258] = 28;
3033
- var Xn = Yn(Tt, 0), Wr = Xn.b, xn = Xn.r, Vt = new Re(32768);
3065
+ }, Xn = Nn(Tt, 2), zn = Xn.b, Vt = Xn.r;
3066
+ zn[28] = 258, Vt[258] = 28;
3067
+ var Cn = Nn(Rt, 0), Jr = Cn.b, An = Cn.r, Zt = new Re(32768);
3034
3068
  for (var fe = 0; fe < 32768; ++fe) {
3035
3069
  var He = (fe & 43690) >> 1 | (fe & 21845) << 1;
3036
- He = (He & 52428) >> 2 | (He & 13107) << 2, He = (He & 61680) >> 4 | (He & 3855) << 4, Vt[fe] = ((He & 65280) >> 8 | (He & 255) << 8) >> 1;
3037
- }
3038
- var Ne = (function(t, e, n) {
3039
- for (var r = t.length, o = 0, a = new Re(e); o < r; ++o)
3040
- t[o] && ++a[t[o] - 1];
3041
- var i = new Re(e);
3042
- for (o = 1; o < e; ++o)
3043
- i[o] = i[o - 1] + a[o - 1] << 1;
3070
+ He = (He & 52428) >> 2 | (He & 13107) << 2, He = (He & 61680) >> 4 | (He & 3855) << 4, Zt[fe] = ((He & 65280) >> 8 | (He & 255) << 8) >> 1;
3071
+ }
3072
+ var Ne = (function(e, t, n) {
3073
+ for (var r = e.length, o = 0, s = new Re(t); o < r; ++o)
3074
+ e[o] && ++s[e[o] - 1];
3075
+ var i = new Re(t);
3076
+ for (o = 1; o < t; ++o)
3077
+ i[o] = i[o - 1] + s[o - 1] << 1;
3044
3078
  var u;
3045
3079
  if (n) {
3046
- u = new Re(1 << e);
3047
- var y = 15 - e;
3080
+ u = new Re(1 << t);
3081
+ var y = 15 - t;
3048
3082
  for (o = 0; o < r; ++o)
3049
- if (t[o])
3050
- for (var v = o << 4 | t[o], m = e - t[o], l = i[t[o] - 1]++ << m, c = l | (1 << m) - 1; l <= c; ++l)
3051
- u[Vt[l] >> y] = v;
3083
+ if (e[o])
3084
+ for (var v = o << 4 | e[o], m = t - e[o], l = i[e[o] - 1]++ << m, c = l | (1 << m) - 1; l <= c; ++l)
3085
+ u[Zt[l] >> y] = v;
3052
3086
  } else
3053
3087
  for (u = new Re(r), o = 0; o < r; ++o)
3054
- t[o] && (u[o] = Vt[i[t[o] - 1]++] >> 15 - t[o]);
3088
+ e[o] && (u[o] = Zt[i[e[o] - 1]++] >> 15 - e[o]);
3055
3089
  return u;
3056
3090
  }), Ve = new ge(288);
3057
3091
  for (var fe = 0; fe < 144; ++fe)
@@ -3065,21 +3099,21 @@ for (var fe = 280; fe < 288; ++fe)
3065
3099
  var dt = new ge(32);
3066
3100
  for (var fe = 0; fe < 32; ++fe)
3067
3101
  dt[fe] = 5;
3068
- var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /* @__PURE__ */ Ne(dt, 5, 0), Kr = /* @__PURE__ */ Ne(dt, 5, 1), It = function(t) {
3069
- for (var e = t[0], n = 1; n < t.length; ++n)
3070
- t[n] > e && (e = t[n]);
3071
- return e;
3072
- }, je = function(t, e, n) {
3073
- var r = e / 8 | 0;
3074
- return (t[r] | t[r + 1] << 8) >> (e & 7) & n;
3075
- }, Nt = function(t, e) {
3076
- var n = e / 8 | 0;
3077
- return (t[n] | t[n + 1] << 8 | t[n + 2] << 16) >> (e & 7);
3078
- }, an = function(t) {
3079
- return (t + 7) / 8 | 0;
3080
- }, gt = function(t, e, n) {
3081
- return (e == null || e < 0) && (e = 0), (n == null || n > t.length) && (n = t.length), new ge(t.subarray(e, n));
3082
- }, Qr = [
3102
+ var Kr = /* @__PURE__ */ Ne(Ve, 9, 0), Qr = /* @__PURE__ */ Ne(Ve, 9, 1), eo = /* @__PURE__ */ Ne(dt, 5, 0), to = /* @__PURE__ */ Ne(dt, 5, 1), Nt = function(e) {
3103
+ for (var t = e[0], n = 1; n < e.length; ++n)
3104
+ e[n] > t && (t = e[n]);
3105
+ return t;
3106
+ }, je = function(e, t, n) {
3107
+ var r = t / 8 | 0;
3108
+ return (e[r] | e[r + 1] << 8) >> (t & 7) & n;
3109
+ }, Xt = function(e, t) {
3110
+ var n = t / 8 | 0;
3111
+ return (e[n] | e[n + 1] << 8 | e[n + 2] << 16) >> (t & 7);
3112
+ }, an = function(e) {
3113
+ return (e + 7) / 8 | 0;
3114
+ }, gt = function(e, t, n) {
3115
+ return (t == null || t < 0) && (t = 0), (n == null || n > e.length) && (n = e.length), new ge(e.subarray(t, n));
3116
+ }, no = [
3083
3117
  "unexpected EOF",
3084
3118
  "invalid block type",
3085
3119
  "invalid length/literal",
@@ -3096,16 +3130,16 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3096
3130
  "stream finishing",
3097
3131
  "invalid zip data"
3098
3132
  // determined by unknown compression method
3099
- ], xe = function(t, e, n) {
3100
- var r = new Error(e || Qr[t]);
3101
- if (r.code = t, Error.captureStackTrace && Error.captureStackTrace(r, xe), !n)
3133
+ ], xe = function(e, t, n) {
3134
+ var r = new Error(t || no[e]);
3135
+ if (r.code = e, Error.captureStackTrace && Error.captureStackTrace(r, xe), !n)
3102
3136
  throw r;
3103
3137
  return r;
3104
- }, eo = function(t, e, n, r) {
3105
- var o = t.length, a = r ? r.length : 0;
3106
- if (!o || e.f && !e.l)
3138
+ }, ro = function(e, t, n, r) {
3139
+ var o = e.length, s = r ? r.length : 0;
3140
+ if (!o || t.f && !t.l)
3107
3141
  return n || new ge(0);
3108
- var i = !n, u = i || e.i != 2, y = e.i;
3142
+ var i = !n, u = i || t.i != 2, y = t.i;
3109
3143
  i && (n = new ge(o * 3));
3110
3144
  var v = function(O) {
3111
3145
  var k = n.length;
@@ -3113,43 +3147,43 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3113
3147
  var $ = new ge(Math.max(k * 2, O));
3114
3148
  $.set(n), n = $;
3115
3149
  }
3116
- }, m = e.f || 0, l = e.p || 0, c = e.b || 0, f = e.l, h = e.d, p = e.m, g = e.n, b = o * 8;
3150
+ }, m = t.f || 0, l = t.p || 0, c = t.b || 0, f = t.l, h = t.d, p = t.m, g = t.n, b = o * 8;
3117
3151
  do {
3118
3152
  if (!f) {
3119
- m = je(t, l, 1);
3120
- var s = je(t, l + 1, 3);
3121
- if (l += 3, s)
3122
- if (s == 1)
3123
- f = qr, h = Kr, p = 9, g = 5;
3124
- else if (s == 2) {
3125
- var A = je(t, l, 31) + 257, L = je(t, l + 10, 15) + 4, z = A + je(t, l + 5, 31) + 1;
3153
+ m = je(e, l, 1);
3154
+ var a = je(e, l + 1, 3);
3155
+ if (l += 3, a)
3156
+ if (a == 1)
3157
+ f = Qr, h = to, p = 9, g = 5;
3158
+ else if (a == 2) {
3159
+ var A = je(e, l, 31) + 257, L = je(e, l + 10, 15) + 4, z = A + je(e, l + 5, 31) + 1;
3126
3160
  l += 14;
3127
3161
  for (var Y = new ge(z), I = new ge(19), U = 0; U < L; ++U)
3128
- I[Pt[U]] = je(t, l + U * 3, 7);
3162
+ I[Ht[U]] = je(e, l + U * 3, 7);
3129
3163
  l += L * 3;
3130
- for (var T = It(I), F = (1 << T) - 1, j = Ne(I, T, 1), U = 0; U < z; ) {
3131
- var C = j[je(t, l, F)];
3164
+ for (var T = Nt(I), F = (1 << T) - 1, j = Ne(I, T, 1), U = 0; U < z; ) {
3165
+ var C = j[je(e, l, F)];
3132
3166
  l += C & 15;
3133
3167
  var d = C >> 4;
3134
3168
  if (d < 16)
3135
3169
  Y[U++] = d;
3136
3170
  else {
3137
3171
  var B = 0, H = 0;
3138
- for (d == 16 ? (H = 3 + je(t, l, 3), l += 2, B = Y[U - 1]) : d == 17 ? (H = 3 + je(t, l, 7), l += 3) : d == 18 && (H = 11 + je(t, l, 127), l += 7); H--; )
3172
+ for (d == 16 ? (H = 3 + je(e, l, 3), l += 2, B = Y[U - 1]) : d == 17 ? (H = 3 + je(e, l, 7), l += 3) : d == 18 && (H = 11 + je(e, l, 127), l += 7); H--; )
3139
3173
  Y[U++] = B;
3140
3174
  }
3141
3175
  }
3142
3176
  var N = Y.subarray(0, A), ne = Y.subarray(A);
3143
- p = It(N), g = It(ne), f = Ne(N, p, 1), h = Ne(ne, g, 1);
3177
+ p = Nt(N), g = Nt(ne), f = Ne(N, p, 1), h = Ne(ne, g, 1);
3144
3178
  } else
3145
3179
  xe(1);
3146
3180
  else {
3147
- var d = an(l) + 4, x = t[d - 4] | t[d - 3] << 8, w = d + x;
3181
+ var d = an(l) + 4, x = e[d - 4] | e[d - 3] << 8, w = d + x;
3148
3182
  if (w > o) {
3149
3183
  y && xe(0);
3150
3184
  break;
3151
3185
  }
3152
- u && v(c + x), n.set(t.subarray(d, w), c), e.b = c += x, e.p = l = w * 8, e.f = m;
3186
+ u && v(c + x), n.set(e.subarray(d, w), c), t.b = c += x, t.p = l = w * 8, t.f = m;
3153
3187
  continue;
3154
3188
  }
3155
3189
  if (l > b) {
@@ -3159,7 +3193,7 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3159
3193
  }
3160
3194
  u && v(c + 131072);
3161
3195
  for (var Q = (1 << p) - 1, J = (1 << g) - 1, X = l; ; X = l) {
3162
- var B = f[Nt(t, l) & Q], G = B >> 4;
3196
+ var B = f[Xt(e, l) & Q], G = B >> 4;
3163
3197
  if (l += B & 15, l > b) {
3164
3198
  y && xe(0);
3165
3199
  break;
@@ -3172,15 +3206,15 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3172
3206
  } else {
3173
3207
  var re = G - 254;
3174
3208
  if (G > 264) {
3175
- var U = G - 257, W = Ot[U];
3176
- re = je(t, l, (1 << W) - 1) + Nn[U], l += W;
3209
+ var U = G - 257, W = Tt[U];
3210
+ re = je(e, l, (1 << W) - 1) + zn[U], l += W;
3177
3211
  }
3178
- var te = h[Nt(t, l) & J], se = te >> 4;
3212
+ var te = h[Xt(e, l) & J], ae = te >> 4;
3179
3213
  te || xe(3), l += te & 15;
3180
- var ne = Wr[se];
3181
- if (se > 3) {
3182
- var W = Tt[se];
3183
- ne += Nt(t, l) & (1 << W) - 1, l += W;
3214
+ var ne = Jr[ae];
3215
+ if (ae > 3) {
3216
+ var W = Rt[ae];
3217
+ ne += Xt(e, l) & (1 << W) - 1, l += W;
3184
3218
  }
3185
3219
  if (l > b) {
3186
3220
  y && xe(0);
@@ -3189,7 +3223,7 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3189
3223
  u && v(c + 131072);
3190
3224
  var V = c + re;
3191
3225
  if (c < ne) {
3192
- var M = a - ne, E = Math.min(ne, V);
3226
+ var M = s - ne, E = Math.min(ne, V);
3193
3227
  for (M + c < 0 && xe(3); c < E; ++c)
3194
3228
  n[c] = r[M + c];
3195
3229
  }
@@ -3197,23 +3231,23 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3197
3231
  n[c] = n[c - ne];
3198
3232
  }
3199
3233
  }
3200
- e.l = f, e.p = X, e.b = c, e.f = m, f && (m = 1, e.m = p, e.d = h, e.n = g);
3234
+ t.l = f, t.p = X, t.b = c, t.f = m, f && (m = 1, t.m = p, t.d = h, t.n = g);
3201
3235
  } while (!m);
3202
3236
  return c != n.length && i ? gt(n, 0, c) : n.subarray(0, c);
3203
- }, Ce = function(t, e, n) {
3204
- n <<= e & 7;
3205
- var r = e / 8 | 0;
3206
- t[r] |= n, t[r + 1] |= n >> 8;
3207
- }, ht = function(t, e, n) {
3208
- n <<= e & 7;
3209
- var r = e / 8 | 0;
3210
- t[r] |= n, t[r + 1] |= n >> 8, t[r + 2] |= n >> 16;
3211
- }, Xt = function(t, e) {
3212
- for (var n = [], r = 0; r < t.length; ++r)
3213
- t[r] && n.push({ s: r, f: t[r] });
3214
- var o = n.length, a = n.slice();
3237
+ }, Ce = function(e, t, n) {
3238
+ n <<= t & 7;
3239
+ var r = t / 8 | 0;
3240
+ e[r] |= n, e[r + 1] |= n >> 8;
3241
+ }, ht = function(e, t, n) {
3242
+ n <<= t & 7;
3243
+ var r = t / 8 | 0;
3244
+ e[r] |= n, e[r + 1] |= n >> 8, e[r + 2] |= n >> 16;
3245
+ }, zt = function(e, t) {
3246
+ for (var n = [], r = 0; r < e.length; ++r)
3247
+ e[r] && n.push({ s: r, f: e[r] });
3248
+ var o = n.length, s = n.slice();
3215
3249
  if (!o)
3216
- return { t: Cn, l: 0 };
3250
+ return { t: Pn, l: 0 };
3217
3251
  if (o == 1) {
3218
3252
  var i = new ge(n[0].s + 1);
3219
3253
  return i[n[0].s] = 1, { t: i, l: 1 };
@@ -3224,115 +3258,115 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3224
3258
  var u = n[0], y = n[1], v = 0, m = 1, l = 2;
3225
3259
  for (n[0] = { s: -1, f: u.f + y.f, l: u, r: y }; m != o - 1; )
3226
3260
  u = n[n[v].f < n[l].f ? v++ : l++], y = n[v != m && n[v].f < n[l].f ? v++ : l++], n[m++] = { s: -1, f: u.f + y.f, l: u, r: y };
3227
- for (var c = a[0].s, r = 1; r < o; ++r)
3228
- a[r].s > c && (c = a[r].s);
3229
- var f = new Re(c + 1), h = Zt(n[m - 1], f, 0);
3230
- if (h > e) {
3231
- var r = 0, p = 0, g = h - e, b = 1 << g;
3232
- for (a.sort(function(A, L) {
3261
+ for (var c = s[0].s, r = 1; r < o; ++r)
3262
+ s[r].s > c && (c = s[r].s);
3263
+ var f = new Re(c + 1), h = Wt(n[m - 1], f, 0);
3264
+ if (h > t) {
3265
+ var r = 0, p = 0, g = h - t, b = 1 << g;
3266
+ for (s.sort(function(A, L) {
3233
3267
  return f[L.s] - f[A.s] || A.f - L.f;
3234
3268
  }); r < o; ++r) {
3235
- var s = a[r].s;
3236
- if (f[s] > e)
3237
- p += b - (1 << h - f[s]), f[s] = e;
3269
+ var a = s[r].s;
3270
+ if (f[a] > t)
3271
+ p += b - (1 << h - f[a]), f[a] = t;
3238
3272
  else
3239
3273
  break;
3240
3274
  }
3241
3275
  for (p >>= g; p > 0; ) {
3242
- var d = a[r].s;
3243
- f[d] < e ? p -= 1 << e - f[d]++ - 1 : ++r;
3276
+ var d = s[r].s;
3277
+ f[d] < t ? p -= 1 << t - f[d]++ - 1 : ++r;
3244
3278
  }
3245
3279
  for (; r >= 0 && p; --r) {
3246
- var x = a[r].s;
3247
- f[x] == e && (--f[x], ++p);
3280
+ var x = s[r].s;
3281
+ f[x] == t && (--f[x], ++p);
3248
3282
  }
3249
- h = e;
3283
+ h = t;
3250
3284
  }
3251
3285
  return { t: new ge(f), l: h };
3252
- }, Zt = function(t, e, n) {
3253
- return t.s == -1 ? Math.max(Zt(t.l, e, n + 1), Zt(t.r, e, n + 1)) : e[t.s] = n;
3254
- }, Mn = function(t) {
3255
- for (var e = t.length; e && !t[--e]; )
3286
+ }, Wt = function(e, t, n) {
3287
+ return e.s == -1 ? Math.max(Wt(e.l, t, n + 1), Wt(e.r, t, n + 1)) : t[e.s] = n;
3288
+ }, En = function(e) {
3289
+ for (var t = e.length; t && !e[--t]; )
3256
3290
  ;
3257
- for (var n = new Re(++e), r = 0, o = t[0], a = 1, i = function(y) {
3291
+ for (var n = new Re(++t), r = 0, o = e[0], s = 1, i = function(y) {
3258
3292
  n[r++] = y;
3259
- }, u = 1; u <= e; ++u)
3260
- if (t[u] == o && u != e)
3261
- ++a;
3293
+ }, u = 1; u <= t; ++u)
3294
+ if (e[u] == o && u != t)
3295
+ ++s;
3262
3296
  else {
3263
- if (!o && a > 2) {
3264
- for (; a > 138; a -= 138)
3297
+ if (!o && s > 2) {
3298
+ for (; s > 138; s -= 138)
3265
3299
  i(32754);
3266
- a > 2 && (i(a > 10 ? a - 11 << 5 | 28690 : a - 3 << 5 | 12305), a = 0);
3267
- } else if (a > 3) {
3268
- for (i(o), --a; a > 6; a -= 6)
3300
+ s > 2 && (i(s > 10 ? s - 11 << 5 | 28690 : s - 3 << 5 | 12305), s = 0);
3301
+ } else if (s > 3) {
3302
+ for (i(o), --s; s > 6; s -= 6)
3269
3303
  i(8304);
3270
- a > 2 && (i(a - 3 << 5 | 8208), a = 0);
3304
+ s > 2 && (i(s - 3 << 5 | 8208), s = 0);
3271
3305
  }
3272
- for (; a--; )
3306
+ for (; s--; )
3273
3307
  i(o);
3274
- a = 1, o = t[u];
3308
+ s = 1, o = e[u];
3275
3309
  }
3276
- return { c: n.subarray(0, r), n: e };
3277
- }, ut = function(t, e) {
3278
- for (var n = 0, r = 0; r < e.length; ++r)
3279
- n += t[r] * e[r];
3310
+ return { c: n.subarray(0, r), n: t };
3311
+ }, ut = function(e, t) {
3312
+ for (var n = 0, r = 0; r < t.length; ++r)
3313
+ n += e[r] * t[r];
3280
3314
  return n;
3281
- }, zn = function(t, e, n) {
3282
- var r = n.length, o = an(e + 2);
3283
- t[o] = r & 255, t[o + 1] = r >> 8, t[o + 2] = t[o] ^ 255, t[o + 3] = t[o + 1] ^ 255;
3284
- for (var a = 0; a < r; ++a)
3285
- t[o + a + 4] = n[a];
3315
+ }, Dn = function(e, t, n) {
3316
+ var r = n.length, o = an(t + 2);
3317
+ e[o] = r & 255, e[o + 1] = r >> 8, e[o + 2] = e[o] ^ 255, e[o + 3] = e[o + 1] ^ 255;
3318
+ for (var s = 0; s < r; ++s)
3319
+ e[o + s + 4] = n[s];
3286
3320
  return (o + 4 + r) * 8;
3287
- }, An = function(t, e, n, r, o, a, i, u, y, v, m) {
3288
- Ce(e, m++, n), ++o[256];
3289
- for (var l = Xt(o, 15), c = l.t, f = l.l, h = Xt(a, 15), p = h.t, g = h.l, b = Mn(c), s = b.c, d = b.n, x = Mn(p), w = x.c, A = x.n, L = new Re(19), z = 0; z < s.length; ++z)
3290
- ++L[s[z] & 31];
3321
+ }, Sn = function(e, t, n, r, o, s, i, u, y, v, m) {
3322
+ Ce(t, m++, n), ++o[256];
3323
+ for (var l = zt(o, 15), c = l.t, f = l.l, h = zt(s, 15), p = h.t, g = h.l, b = En(c), a = b.c, d = b.n, x = En(p), w = x.c, A = x.n, L = new Re(19), z = 0; z < a.length; ++z)
3324
+ ++L[a[z] & 31];
3291
3325
  for (var z = 0; z < w.length; ++z)
3292
3326
  ++L[w[z] & 31];
3293
- for (var Y = Xt(L, 7), I = Y.t, U = Y.l, T = 19; T > 4 && !I[Pt[T - 1]]; --T)
3327
+ for (var Y = zt(L, 7), I = Y.t, U = Y.l, T = 19; T > 4 && !I[Ht[T - 1]]; --T)
3294
3328
  ;
3295
- var F = v + 5 << 3, j = ut(o, Ve) + ut(a, dt) + i, C = ut(o, c) + ut(a, p) + i + 14 + 3 * T + ut(L, I) + 2 * L[16] + 3 * L[17] + 7 * L[18];
3329
+ var F = v + 5 << 3, j = ut(o, Ve) + ut(s, dt) + i, C = ut(o, c) + ut(s, p) + i + 14 + 3 * T + ut(L, I) + 2 * L[16] + 3 * L[17] + 7 * L[18];
3296
3330
  if (y >= 0 && F <= j && F <= C)
3297
- return zn(e, m, t.subarray(y, y + v));
3331
+ return Dn(t, m, e.subarray(y, y + v));
3298
3332
  var B, H, N, ne;
3299
- if (Ce(e, m, 1 + (C < j)), m += 2, C < j) {
3333
+ if (Ce(t, m, 1 + (C < j)), m += 2, C < j) {
3300
3334
  B = Ne(c, f, 0), H = c, N = Ne(p, g, 0), ne = p;
3301
3335
  var Q = Ne(I, U, 0);
3302
- Ce(e, m, d - 257), Ce(e, m + 5, A - 1), Ce(e, m + 10, T - 4), m += 14;
3336
+ Ce(t, m, d - 257), Ce(t, m + 5, A - 1), Ce(t, m + 10, T - 4), m += 14;
3303
3337
  for (var z = 0; z < T; ++z)
3304
- Ce(e, m + 3 * z, I[Pt[z]]);
3338
+ Ce(t, m + 3 * z, I[Ht[z]]);
3305
3339
  m += 3 * T;
3306
- for (var J = [s, w], X = 0; X < 2; ++X)
3340
+ for (var J = [a, w], X = 0; X < 2; ++X)
3307
3341
  for (var G = J[X], z = 0; z < G.length; ++z) {
3308
3342
  var re = G[z] & 31;
3309
- Ce(e, m, Q[re]), m += I[re], re > 15 && (Ce(e, m, G[z] >> 5 & 127), m += G[z] >> 12);
3343
+ Ce(t, m, Q[re]), m += I[re], re > 15 && (Ce(t, m, G[z] >> 5 & 127), m += G[z] >> 12);
3310
3344
  }
3311
3345
  } else
3312
- B = Gr, H = Ve, N = Jr, ne = dt;
3346
+ B = Kr, H = Ve, N = eo, ne = dt;
3313
3347
  for (var z = 0; z < u; ++z) {
3314
3348
  var W = r[z];
3315
3349
  if (W > 255) {
3316
3350
  var re = W >> 18 & 31;
3317
- ht(e, m, B[re + 257]), m += H[re + 257], re > 7 && (Ce(e, m, W >> 23 & 31), m += Ot[re]);
3351
+ ht(t, m, B[re + 257]), m += H[re + 257], re > 7 && (Ce(t, m, W >> 23 & 31), m += Tt[re]);
3318
3352
  var te = W & 31;
3319
- ht(e, m, N[te]), m += ne[te], te > 3 && (ht(e, m, W >> 5 & 8191), m += Tt[te]);
3353
+ ht(t, m, N[te]), m += ne[te], te > 3 && (ht(t, m, W >> 5 & 8191), m += Rt[te]);
3320
3354
  } else
3321
- ht(e, m, B[W]), m += H[W];
3322
- }
3323
- return ht(e, m, B[256]), m + H[256];
3324
- }, to = /* @__PURE__ */ new on([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), Cn = /* @__PURE__ */ new ge(0), no = function(t, e, n, r, o, a) {
3325
- var i = a.z || t.length, u = new ge(r + i + 5 * (1 + Math.ceil(i / 7e3)) + o), y = u.subarray(r, u.length - o), v = a.l, m = (a.r || 0) & 7;
3326
- if (e) {
3327
- m && (y[0] = a.r >> 3);
3328
- for (var l = to[e - 1], c = l >> 13, f = l & 8191, h = (1 << n) - 1, p = a.p || new Re(32768), g = a.h || new Re(h + 1), b = Math.ceil(n / 3), s = 2 * b, d = function(Z) {
3329
- return (t[Z] ^ t[Z + 1] << b ^ t[Z + 2] << s) & h;
3330
- }, x = new on(25e3), w = new Re(288), A = new Re(32), L = 0, z = 0, Y = a.i || 0, I = 0, U = a.w || 0, T = 0; Y + 2 < i; ++Y) {
3355
+ ht(t, m, B[W]), m += H[W];
3356
+ }
3357
+ return ht(t, m, B[256]), m + H[256];
3358
+ }, oo = /* @__PURE__ */ new sn([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]), Pn = /* @__PURE__ */ new ge(0), so = function(e, t, n, r, o, s) {
3359
+ var i = s.z || e.length, u = new ge(r + i + 5 * (1 + Math.ceil(i / 7e3)) + o), y = u.subarray(r, u.length - o), v = s.l, m = (s.r || 0) & 7;
3360
+ if (t) {
3361
+ m && (y[0] = s.r >> 3);
3362
+ for (var l = oo[t - 1], c = l >> 13, f = l & 8191, h = (1 << n) - 1, p = s.p || new Re(32768), g = s.h || new Re(h + 1), b = Math.ceil(n / 3), a = 2 * b, d = function(Z) {
3363
+ return (e[Z] ^ e[Z + 1] << b ^ e[Z + 2] << a) & h;
3364
+ }, x = new sn(25e3), w = new Re(288), A = new Re(32), L = 0, z = 0, Y = s.i || 0, I = 0, U = s.w || 0, T = 0; Y + 2 < i; ++Y) {
3331
3365
  var F = d(Y), j = Y & 32767, C = g[F];
3332
3366
  if (p[j] = C, g[F] = j, U <= Y) {
3333
3367
  var B = i - Y;
3334
3368
  if ((L > 7e3 || I > 24576) && (B > 423 || !v)) {
3335
- m = An(t, y, 0, x, w, A, z, I, T, Y - T, m), I = L = z = 0, T = Y;
3369
+ m = Sn(e, y, 0, x, w, A, z, I, T, Y - T, m), I = L = z = 0, T = Y;
3336
3370
  for (var H = 0; H < 286; ++H)
3337
3371
  w[H] = 0;
3338
3372
  for (var H = 0; H < 30; ++H)
@@ -3341,183 +3375,183 @@ var Gr = /* @__PURE__ */ Ne(Ve, 9, 0), qr = /* @__PURE__ */ Ne(Ve, 9, 1), Jr = /
3341
3375
  var N = 2, ne = 0, Q = f, J = j - C & 32767;
3342
3376
  if (B > 2 && F == d(Y - J))
3343
3377
  for (var X = Math.min(c, B) - 1, G = Math.min(32767, Y), re = Math.min(258, B); J <= G && --Q && j != C; ) {
3344
- if (t[Y + N] == t[Y + N - J]) {
3345
- for (var W = 0; W < re && t[Y + W] == t[Y + W - J]; ++W)
3378
+ if (e[Y + N] == e[Y + N - J]) {
3379
+ for (var W = 0; W < re && e[Y + W] == e[Y + W - J]; ++W)
3346
3380
  ;
3347
3381
  if (W > N) {
3348
3382
  if (N = W, ne = J, W > X)
3349
3383
  break;
3350
- for (var te = Math.min(J, W - 2), se = 0, H = 0; H < te; ++H) {
3384
+ for (var te = Math.min(J, W - 2), ae = 0, H = 0; H < te; ++H) {
3351
3385
  var V = Y - J + H & 32767, M = p[V], E = V - M & 32767;
3352
- E > se && (se = E, C = V);
3386
+ E > ae && (ae = E, C = V);
3353
3387
  }
3354
3388
  }
3355
3389
  }
3356
3390
  j = C, C = p[j], J += j - C & 32767;
3357
3391
  }
3358
3392
  if (ne) {
3359
- x[I++] = 268435456 | Ht[N] << 18 | xn[ne];
3360
- var O = Ht[N] & 31, k = xn[ne] & 31;
3361
- z += Ot[O] + Tt[k], ++w[257 + O], ++A[k], U = Y + N, ++L;
3393
+ x[I++] = 268435456 | Vt[N] << 18 | An[ne];
3394
+ var O = Vt[N] & 31, k = An[ne] & 31;
3395
+ z += Tt[O] + Rt[k], ++w[257 + O], ++A[k], U = Y + N, ++L;
3362
3396
  } else
3363
- x[I++] = t[Y], ++w[t[Y]];
3397
+ x[I++] = e[Y], ++w[e[Y]];
3364
3398
  }
3365
3399
  }
3366
3400
  for (Y = Math.max(Y, U); Y < i; ++Y)
3367
- x[I++] = t[Y], ++w[t[Y]];
3368
- m = An(t, y, v, x, w, A, z, I, T, Y - T, m), v || (a.r = m & 7 | y[m / 8 | 0] << 3, m -= 7, a.h = g, a.p = p, a.i = Y, a.w = U);
3401
+ x[I++] = e[Y], ++w[e[Y]];
3402
+ m = Sn(e, y, v, x, w, A, z, I, T, Y - T, m), v || (s.r = m & 7 | y[m / 8 | 0] << 3, m -= 7, s.h = g, s.p = p, s.i = Y, s.w = U);
3369
3403
  } else {
3370
- for (var Y = a.w || 0; Y < i + v; Y += 65535) {
3404
+ for (var Y = s.w || 0; Y < i + v; Y += 65535) {
3371
3405
  var $ = Y + 65535;
3372
- $ >= i && (y[m / 8 | 0] = v, $ = i), m = zn(y, m + 1, t.subarray(Y, $));
3406
+ $ >= i && (y[m / 8 | 0] = v, $ = i), m = Dn(y, m + 1, e.subarray(Y, $));
3373
3407
  }
3374
- a.i = i;
3408
+ s.i = i;
3375
3409
  }
3376
3410
  return gt(u, 0, r + an(m) + o);
3377
- }, ro = /* @__PURE__ */ (function() {
3378
- for (var t = new Int32Array(256), e = 0; e < 256; ++e) {
3379
- for (var n = e, r = 9; --r; )
3411
+ }, ao = /* @__PURE__ */ (function() {
3412
+ for (var e = new Int32Array(256), t = 0; t < 256; ++t) {
3413
+ for (var n = t, r = 9; --r; )
3380
3414
  n = (n & 1 && -306674912) ^ n >>> 1;
3381
- t[e] = n;
3415
+ e[t] = n;
3382
3416
  }
3383
- return t;
3384
- })(), oo = function() {
3385
- var t = -1;
3417
+ return e;
3418
+ })(), io = function() {
3419
+ var e = -1;
3386
3420
  return {
3387
- p: function(e) {
3388
- for (var n = t, r = 0; r < e.length; ++r)
3389
- n = ro[n & 255 ^ e[r]] ^ n >>> 8;
3390
- t = n;
3421
+ p: function(t) {
3422
+ for (var n = e, r = 0; r < t.length; ++r)
3423
+ n = ao[n & 255 ^ t[r]] ^ n >>> 8;
3424
+ e = n;
3391
3425
  },
3392
3426
  d: function() {
3393
- return ~t;
3427
+ return ~e;
3394
3428
  }
3395
3429
  };
3396
- }, ao = function(t, e, n, r, o) {
3397
- if (!o && (o = { l: 1 }, e.dictionary)) {
3398
- var a = e.dictionary.subarray(-32768), i = new ge(a.length + t.length);
3399
- i.set(a), i.set(t, a.length), t = i, o.w = a.length;
3430
+ }, lo = function(e, t, n, r, o) {
3431
+ if (!o && (o = { l: 1 }, t.dictionary)) {
3432
+ var s = t.dictionary.subarray(-32768), i = new ge(s.length + e.length);
3433
+ i.set(s), i.set(e, s.length), e = i, o.w = s.length;
3400
3434
  }
3401
- return no(t, e.level == null ? 6 : e.level, e.mem == null ? o.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(t.length))) * 1.5) : 20 : 12 + e.mem, n, r, o);
3402
- }, Dn = function(t, e) {
3435
+ return so(e, t.level == null ? 6 : t.level, t.mem == null ? o.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(e.length))) * 1.5) : 20 : 12 + t.mem, n, r, o);
3436
+ }, Hn = function(e, t) {
3403
3437
  var n = {};
3404
- for (var r in t)
3405
- n[r] = t[r];
3406
3438
  for (var r in e)
3407
3439
  n[r] = e[r];
3440
+ for (var r in t)
3441
+ n[r] = t[r];
3408
3442
  return n;
3409
- }, Ie = function(t, e) {
3410
- return t[e] | t[e + 1] << 8;
3411
- }, Fe = function(t, e) {
3412
- return (t[e] | t[e + 1] << 8 | t[e + 2] << 16 | t[e + 3] << 24) >>> 0;
3413
- }, zt = function(t, e) {
3414
- return Fe(t, e) + Fe(t, e + 4) * 4294967296;
3415
- }, ve = function(t, e, n) {
3416
- for (; n; ++e)
3417
- t[e] = n, n >>>= 8;
3443
+ }, Ie = function(e, t) {
3444
+ return e[t] | e[t + 1] << 8;
3445
+ }, Fe = function(e, t) {
3446
+ return (e[t] | e[t + 1] << 8 | e[t + 2] << 16 | e[t + 3] << 24) >>> 0;
3447
+ }, Ct = function(e, t) {
3448
+ return Fe(e, t) + Fe(e, t + 4) * 4294967296;
3449
+ }, ve = function(e, t, n) {
3450
+ for (; n; ++t)
3451
+ e[t] = n, n >>>= 8;
3418
3452
  };
3419
- function so(t, e) {
3420
- return ao(t, e || {}, 0, 0);
3453
+ function co(e, t) {
3454
+ return lo(e, t || {}, 0, 0);
3421
3455
  }
3422
- function io(t, e) {
3423
- return eo(t, { i: 2 }, e && e.out, e && e.dictionary);
3456
+ function ho(e, t) {
3457
+ return ro(e, { i: 2 }, t && t.out, t && t.dictionary);
3424
3458
  }
3425
- var Pn = function(t, e, n, r) {
3426
- for (var o in t) {
3427
- var a = t[o], i = e + o, u = r;
3428
- Array.isArray(a) && (u = Dn(r, a[1]), a = a[0]), ArrayBuffer.isView(a) ? n[i] = [a, u] : (n[i += "/"] = [new ge(0), u], Pn(a, i, n, r));
3459
+ var Vn = function(e, t, n, r) {
3460
+ for (var o in e) {
3461
+ var s = e[o], i = t + o, u = r;
3462
+ Array.isArray(s) && (u = Hn(r, s[1]), s = s[0]), ArrayBuffer.isView(s) ? n[i] = [s, u] : (n[i += "/"] = [new ge(0), u], Vn(s, i, n, r));
3429
3463
  }
3430
- }, En = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), Wt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), lo = 0;
3464
+ }, On = typeof TextEncoder < "u" && /* @__PURE__ */ new TextEncoder(), Gt = typeof TextDecoder < "u" && /* @__PURE__ */ new TextDecoder(), uo = 0;
3431
3465
  try {
3432
- Wt.decode(Cn, { stream: !0 }), lo = 1;
3466
+ Gt.decode(Pn, { stream: !0 }), uo = 1;
3433
3467
  } catch {
3434
3468
  }
3435
- var co = function(t) {
3436
- for (var e = "", n = 0; ; ) {
3437
- var r = t[n++], o = (r > 127) + (r > 223) + (r > 239);
3438
- if (n + o > t.length)
3439
- return { s: e, r: gt(t, n - 1) };
3440
- o ? o == 3 ? (r = ((r & 15) << 18 | (t[n++] & 63) << 12 | (t[n++] & 63) << 6 | t[n++] & 63) - 65536, e += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : o & 1 ? e += String.fromCharCode((r & 31) << 6 | t[n++] & 63) : e += String.fromCharCode((r & 15) << 12 | (t[n++] & 63) << 6 | t[n++] & 63) : e += String.fromCharCode(r);
3469
+ var fo = function(e) {
3470
+ for (var t = "", n = 0; ; ) {
3471
+ var r = e[n++], o = (r > 127) + (r > 223) + (r > 239);
3472
+ if (n + o > e.length)
3473
+ return { s: t, r: gt(e, n - 1) };
3474
+ o ? o == 3 ? (r = ((r & 15) << 18 | (e[n++] & 63) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) - 65536, t += String.fromCharCode(55296 | r >> 10, 56320 | r & 1023)) : o & 1 ? t += String.fromCharCode((r & 31) << 6 | e[n++] & 63) : t += String.fromCharCode((r & 15) << 12 | (e[n++] & 63) << 6 | e[n++] & 63) : t += String.fromCharCode(r);
3441
3475
  }
3442
3476
  };
3443
- function Sn(t, e) {
3477
+ function Tn(e, t) {
3444
3478
  var n;
3445
- if (En)
3446
- return En.encode(t);
3447
- for (var r = t.length, o = new ge(t.length + (t.length >> 1)), a = 0, i = function(v) {
3448
- o[a++] = v;
3479
+ if (On)
3480
+ return On.encode(e);
3481
+ for (var r = e.length, o = new ge(e.length + (e.length >> 1)), s = 0, i = function(v) {
3482
+ o[s++] = v;
3449
3483
  }, n = 0; n < r; ++n) {
3450
- if (a + 5 > o.length) {
3451
- var u = new ge(a + 8 + (r - n << 1));
3484
+ if (s + 5 > o.length) {
3485
+ var u = new ge(s + 8 + (r - n << 1));
3452
3486
  u.set(o), o = u;
3453
3487
  }
3454
- var y = t.charCodeAt(n);
3455
- y < 128 || e ? i(y) : y < 2048 ? (i(192 | y >> 6), i(128 | y & 63)) : y > 55295 && y < 57344 ? (y = 65536 + (y & 1047552) | t.charCodeAt(++n) & 1023, i(240 | y >> 18), i(128 | y >> 12 & 63), i(128 | y >> 6 & 63), i(128 | y & 63)) : (i(224 | y >> 12), i(128 | y >> 6 & 63), i(128 | y & 63));
3488
+ var y = e.charCodeAt(n);
3489
+ y < 128 || t ? i(y) : y < 2048 ? (i(192 | y >> 6), i(128 | y & 63)) : y > 55295 && y < 57344 ? (y = 65536 + (y & 1047552) | e.charCodeAt(++n) & 1023, i(240 | y >> 18), i(128 | y >> 12 & 63), i(128 | y >> 6 & 63), i(128 | y & 63)) : (i(224 | y >> 12), i(128 | y >> 6 & 63), i(128 | y & 63));
3456
3490
  }
3457
- return gt(o, 0, a);
3491
+ return gt(o, 0, s);
3458
3492
  }
3459
- function ho(t, e) {
3460
- if (e) {
3461
- for (var n = "", r = 0; r < t.length; r += 16384)
3462
- n += String.fromCharCode.apply(null, t.subarray(r, r + 16384));
3493
+ function mo(e, t) {
3494
+ if (t) {
3495
+ for (var n = "", r = 0; r < e.length; r += 16384)
3496
+ n += String.fromCharCode.apply(null, e.subarray(r, r + 16384));
3463
3497
  return n;
3464
3498
  } else {
3465
- if (Wt)
3466
- return Wt.decode(t);
3467
- var o = co(t), a = o.s, n = o.r;
3468
- return n.length && xe(8), a;
3469
- }
3470
- }
3471
- var uo = function(t, e) {
3472
- return e + 30 + Ie(t, e + 26) + Ie(t, e + 28);
3473
- }, fo = function(t, e, n) {
3474
- var r = Ie(t, e + 28), o = Ie(t, e + 30), a = ho(t.subarray(e + 46, e + 46 + r), !(Ie(t, e + 8) & 2048)), i = e + 46 + r, u = mo(t, i, o, n, Fe(t, e + 20), Fe(t, e + 24), Fe(t, e + 42)), y = u[0], v = u[1], m = u[2];
3475
- return [Ie(t, e + 10), y, v, a, i + o + Ie(t, e + 32), m];
3476
- }, mo = function(t, e, n, r, o, a, i) {
3477
- var u = o == 4294967295, y = a == 4294967295, v = i == 4294967295, m = e + n, l = u + y + v;
3499
+ if (Gt)
3500
+ return Gt.decode(e);
3501
+ var o = fo(e), s = o.s, n = o.r;
3502
+ return n.length && xe(8), s;
3503
+ }
3504
+ }
3505
+ var po = function(e, t) {
3506
+ return t + 30 + Ie(e, t + 26) + Ie(e, t + 28);
3507
+ }, go = function(e, t, n) {
3508
+ var r = Ie(e, t + 28), o = Ie(e, t + 30), s = mo(e.subarray(t + 46, t + 46 + r), !(Ie(e, t + 8) & 2048)), i = t + 46 + r, u = yo(e, i, o, n, Fe(e, t + 20), Fe(e, t + 24), Fe(e, t + 42)), y = u[0], v = u[1], m = u[2];
3509
+ return [Ie(e, t + 10), y, v, s, i + o + Ie(e, t + 32), m];
3510
+ }, yo = function(e, t, n, r, o, s, i) {
3511
+ var u = o == 4294967295, y = s == 4294967295, v = i == 4294967295, m = t + n, l = u + y + v;
3478
3512
  if (r && l) {
3479
- for (; e + 4 < m; e += 4 + Ie(t, e + 2))
3480
- if (Ie(t, e) == 1)
3513
+ for (; t + 4 < m; t += 4 + Ie(e, t + 2))
3514
+ if (Ie(e, t) == 1)
3481
3515
  return [
3482
- u ? zt(t, e + 4 + 8 * y) : o,
3483
- y ? zt(t, e + 4) : a,
3484
- v ? zt(t, e + 4 + 8 * (y + u)) : i,
3516
+ u ? Ct(e, t + 4 + 8 * y) : o,
3517
+ y ? Ct(e, t + 4) : s,
3518
+ v ? Ct(e, t + 4 + 8 * (y + u)) : i,
3485
3519
  1
3486
3520
  ];
3487
3521
  r < 2 && xe(13);
3488
3522
  }
3489
- return [o, a, i, 0];
3490
- }, Gt = function(t) {
3491
- var e = 0;
3492
- if (t)
3493
- for (var n in t) {
3494
- var r = t[n].length;
3495
- r > 65535 && xe(9), e += r + 4;
3523
+ return [o, s, i, 0];
3524
+ }, qt = function(e) {
3525
+ var t = 0;
3526
+ if (e)
3527
+ for (var n in e) {
3528
+ var r = e[n].length;
3529
+ r > 65535 && xe(9), t += r + 4;
3496
3530
  }
3497
- return e;
3498
- }, On = function(t, e, n, r, o, a, i, u) {
3499
- var y = r.length, v = n.extra, m = u && u.length, l = Gt(v);
3500
- ve(t, e, i != null ? 33639248 : 67324752), e += 4, i != null && (t[e++] = 20, t[e++] = n.os), t[e] = 20, e += 2, t[e++] = n.flag << 1 | (a < 0 && 8), t[e++] = o && 8, t[e++] = n.compression & 255, t[e++] = n.compression >> 8;
3531
+ return t;
3532
+ }, Rn = function(e, t, n, r, o, s, i, u) {
3533
+ var y = r.length, v = n.extra, m = u && u.length, l = qt(v);
3534
+ ve(e, t, i != null ? 33639248 : 67324752), t += 4, i != null && (e[t++] = 20, e[t++] = n.os), e[t] = 20, t += 2, e[t++] = n.flag << 1 | (s < 0 && 8), e[t++] = o && 8, e[t++] = n.compression & 255, e[t++] = n.compression >> 8;
3501
3535
  var c = new Date(n.mtime == null ? Date.now() : n.mtime), f = c.getFullYear() - 1980;
3502
- if ((f < 0 || f > 119) && xe(10), ve(t, e, f << 25 | c.getMonth() + 1 << 21 | c.getDate() << 16 | c.getHours() << 11 | c.getMinutes() << 5 | c.getSeconds() >> 1), e += 4, a != -1 && (ve(t, e, n.crc), ve(t, e + 4, a < 0 ? -a - 2 : a), ve(t, e + 8, n.size)), ve(t, e + 12, y), ve(t, e + 14, l), e += 16, i != null && (ve(t, e, m), ve(t, e + 6, n.attrs), ve(t, e + 10, i), e += 14), t.set(r, e), e += y, l)
3536
+ if ((f < 0 || f > 119) && xe(10), ve(e, t, f << 25 | c.getMonth() + 1 << 21 | c.getDate() << 16 | c.getHours() << 11 | c.getMinutes() << 5 | c.getSeconds() >> 1), t += 4, s != -1 && (ve(e, t, n.crc), ve(e, t + 4, s < 0 ? -s - 2 : s), ve(e, t + 8, n.size)), ve(e, t + 12, y), ve(e, t + 14, l), t += 16, i != null && (ve(e, t, m), ve(e, t + 6, n.attrs), ve(e, t + 10, i), t += 14), e.set(r, t), t += y, l)
3503
3537
  for (var h in v) {
3504
3538
  var p = v[h], g = p.length;
3505
- ve(t, e, +h), ve(t, e + 2, g), t.set(p, e + 4), e += 4 + g;
3539
+ ve(e, t, +h), ve(e, t + 2, g), e.set(p, t + 4), t += 4 + g;
3506
3540
  }
3507
- return m && (t.set(u, e), e += m), e;
3508
- }, po = function(t, e, n, r, o) {
3509
- ve(t, e, 101010256), ve(t, e + 8, n), ve(t, e + 10, n), ve(t, e + 12, r), ve(t, e + 16, o);
3541
+ return m && (e.set(u, t), t += m), t;
3542
+ }, vo = function(e, t, n, r, o) {
3543
+ ve(e, t, 101010256), ve(e, t + 8, n), ve(e, t + 10, n), ve(e, t + 12, r), ve(e, t + 16, o);
3510
3544
  };
3511
- function go(t, e) {
3512
- e || (e = {});
3545
+ function bo(e, t) {
3546
+ t || (t = {});
3513
3547
  var n = {}, r = [];
3514
- Pn(t, "", n, e);
3515
- var o = 0, a = 0;
3548
+ Vn(e, "", n, t);
3549
+ var o = 0, s = 0;
3516
3550
  for (var i in n) {
3517
- var u = n[i], y = u[0], v = u[1], m = v.level == 0 ? 0 : 8, l = Sn(i), c = l.length, f = v.comment, h = f && Sn(f), p = h && h.length, g = Gt(v.extra);
3551
+ var u = n[i], y = u[0], v = u[1], m = v.level == 0 ? 0 : 8, l = Tn(i), c = l.length, f = v.comment, h = f && Tn(f), p = h && h.length, g = qt(v.extra);
3518
3552
  c > 65535 && xe(11);
3519
- var b = m ? so(y, v) : y, s = b.length, d = oo();
3520
- d.p(y), r.push(Dn(v, {
3553
+ var b = m ? co(y, v) : y, a = b.length, d = io();
3554
+ d.p(y), r.push(Hn(v, {
3521
3555
  size: y.length,
3522
3556
  crc: d.d(),
3523
3557
  c: b,
@@ -3526,53 +3560,53 @@ function go(t, e) {
3526
3560
  u: c != i.length || h && f.length != p,
3527
3561
  o,
3528
3562
  compression: m
3529
- })), o += 30 + c + g + s, a += 76 + 2 * (c + g) + (p || 0) + s;
3563
+ })), o += 30 + c + g + a, s += 76 + 2 * (c + g) + (p || 0) + a;
3530
3564
  }
3531
- for (var x = new ge(a + 22), w = o, A = a - o, L = 0; L < r.length; ++L) {
3565
+ for (var x = new ge(s + 22), w = o, A = s - o, L = 0; L < r.length; ++L) {
3532
3566
  var l = r[L];
3533
- On(x, l.o, l, l.f, l.u, l.c.length);
3534
- var z = 30 + l.f.length + Gt(l.extra);
3535
- x.set(l.c, l.o + z), On(x, o, l, l.f, l.u, l.c.length, l.o, l.m), o += 16 + z + (l.m ? l.m.length : 0);
3567
+ Rn(x, l.o, l, l.f, l.u, l.c.length);
3568
+ var z = 30 + l.f.length + qt(l.extra);
3569
+ x.set(l.c, l.o + z), Rn(x, o, l, l.f, l.u, l.c.length, l.o, l.m), o += 16 + z + (l.m ? l.m.length : 0);
3536
3570
  }
3537
- return po(x, o, r.length, A, w), x;
3571
+ return vo(x, o, r.length, A, w), x;
3538
3572
  }
3539
- function yo(t, e) {
3540
- for (var n = {}, r = t.length - 22; Fe(t, r) != 101010256; --r)
3541
- (!r || t.length - r > 65558) && xe(13);
3542
- var o = Ie(t, r + 8);
3573
+ function wo(e, t) {
3574
+ for (var n = {}, r = e.length - 22; Fe(e, r) != 101010256; --r)
3575
+ (!r || e.length - r > 65558) && xe(13);
3576
+ var o = Ie(e, r + 8);
3543
3577
  if (!o)
3544
3578
  return {};
3545
- var a = Fe(t, r + 16), i = Fe(t, r - 20) == 117853008;
3579
+ var s = Fe(e, r + 16), i = Fe(e, r - 20) == 117853008;
3546
3580
  if (i) {
3547
- var u = Fe(t, r - 12);
3548
- i = Fe(t, u) == 101075792, i && (o = Fe(t, u + 32), a = Fe(t, u + 48));
3581
+ var u = Fe(e, r - 12);
3582
+ i = Fe(e, u) == 101075792, i && (o = Fe(e, u + 32), s = Fe(e, u + 48));
3549
3583
  }
3550
- for (var y = e && e.filter, v = 0; v < o; ++v) {
3551
- var m = fo(t, a, i), l = m[0], c = m[1], f = m[2], h = m[3], p = m[4], g = m[5], b = uo(t, g);
3552
- a = p, (!y || y({
3584
+ for (var y = t && t.filter, v = 0; v < o; ++v) {
3585
+ var m = go(e, s, i), l = m[0], c = m[1], f = m[2], h = m[3], p = m[4], g = m[5], b = po(e, g);
3586
+ s = p, (!y || y({
3553
3587
  name: h,
3554
3588
  size: c,
3555
3589
  originalSize: f,
3556
3590
  compression: l
3557
- })) && (l ? l == 8 ? n[h] = io(t.subarray(b, b + c), { out: new ge(f) }) : xe(14, "unknown compression type " + l) : n[h] = gt(t, b, b + c));
3591
+ })) && (l ? l == 8 ? n[h] = ho(e.subarray(b, b + c), { out: new ge(f) }) : xe(14, "unknown compression type " + l) : n[h] = gt(e, b, b + c));
3558
3592
  }
3559
3593
  return n;
3560
3594
  }
3561
- const St = 200, qt = 64 * 1024 * 1024, Jt = new TextDecoder("utf-8", { fatal: !0 });
3562
- function sn(t) {
3563
- if (!t || t.startsWith("/") || /^[A-Za-z]:/.test(t) || t.includes("\\") || t.includes("\0") || t.split("/").includes(".."))
3564
- throw new Error(`ZIP entry ${JSON.stringify(t)}: path must be relative, without .. or backslashes`);
3595
+ const St = 200, Jt = 64 * 1024 * 1024, Kt = new TextDecoder("utf-8", { fatal: !0 });
3596
+ function ln(e) {
3597
+ if (!e || e.startsWith("/") || /^[A-Za-z]:/.test(e) || e.includes("\\") || e.includes("\0") || e.split("/").includes(".."))
3598
+ throw new Error(`ZIP entry ${JSON.stringify(e)}: path must be relative, without .. or backslashes`);
3565
3599
  }
3566
- function Kt(t) {
3567
- const e = new DataView(t.buffer, t.byteOffset, t.byteLength), n = (c = "(archive)") => {
3600
+ function Qt(e) {
3601
+ const t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (c = "(archive)") => {
3568
3602
  throw new Error(`ZIP entry ${JSON.stringify(c)}: invalid or truncated ZIP`);
3569
- }, r = (c) => c >= 0 && c + 2 <= t.length ? e.getUint16(c, !0) : n(), o = (c) => c >= 0 && c + 4 <= t.length ? e.getUint32(c, !0) : n();
3570
- let a = t.length - 22;
3571
- for (; a >= Math.max(0, t.length - 65557) && !(o(a) === 101010256 && a + 22 + r(a + 20) === t.length); a--)
3603
+ }, r = (c) => c >= 0 && c + 2 <= e.length ? t.getUint16(c, !0) : n(), o = (c) => c >= 0 && c + 4 <= e.length ? t.getUint32(c, !0) : n();
3604
+ let s = e.length - 22;
3605
+ for (; s >= Math.max(0, e.length - 65557) && !(o(s) === 101010256 && s + 22 + r(s + 20) === e.length); s--)
3572
3606
  ;
3573
- (a < 0 || a < t.length - 65557) && n(), (r(a + 4) || r(a + 6) || r(a + 8) !== r(a + 10)) && n();
3574
- const i = r(a + 10), u = o(a + 16), y = u + o(a + 12);
3575
- y !== a && n();
3607
+ (s < 0 || s < e.length - 65557) && n(), (r(s + 4) || r(s + 6) || r(s + 8) !== r(s + 10)) && n();
3608
+ const i = r(s + 10), u = o(s + 16), y = u + o(s + 12);
3609
+ y !== s && n();
3576
3610
  const v = [], m = /* @__PURE__ */ new Set();
3577
3611
  let l = u;
3578
3612
  for (let c = 0; c < i; c++) {
@@ -3581,59 +3615,59 @@ function Kt(t) {
3581
3615
  h > y && n();
3582
3616
  let p;
3583
3617
  try {
3584
- p = Jt.decode(t.subarray(l + 46, l + 46 + f));
3618
+ p = Kt.decode(e.subarray(l + 46, l + 46 + f));
3585
3619
  } catch {
3586
3620
  throw new Error("ZIP entry (invalid UTF-8 name): invalid filename");
3587
3621
  }
3588
- if (sn(p), c >= St) throw new Error(`ZIP entry ${JSON.stringify(p)}: more than ${St} entries`);
3622
+ if (ln(p), c >= St) throw new Error(`ZIP entry ${JSON.stringify(p)}: more than ${St} entries`);
3589
3623
  if (m.has(p)) throw new Error(`ZIP entry ${JSON.stringify(p)}: duplicate entry`);
3590
3624
  m.add(p);
3591
- const g = o(l + 24), b = o(l + 20), s = o(l + 42);
3592
- if (g > qt || b > qt) throw new Error(`ZIP entry ${JSON.stringify(p)}: exceeds 64 MB`);
3625
+ const g = o(l + 24), b = o(l + 20), a = o(l + 42);
3626
+ if (g > Jt || b > Jt) throw new Error(`ZIP entry ${JSON.stringify(p)}: exceeds 64 MB`);
3593
3627
  if (r(l + 10) !== 0) throw new Error(`ZIP entry ${JSON.stringify(p)}: expected stored compression (method 0)`);
3594
3628
  if (r(l + 8) & 1) throw new Error(`ZIP entry ${JSON.stringify(p)}: encrypted entries are not supported`);
3595
- (b !== g || s + 30 > u || o(s) !== 67324752) && n(p);
3596
- const d = s + 30 + r(s + 26) + r(s + 28);
3597
- (d + g > u || r(s + 8) !== 0 || r(s + 6) !== r(l + 8)) && n(p);
3629
+ (b !== g || a + 30 > u || o(a) !== 67324752) && n(p);
3630
+ const d = a + 30 + r(a + 26) + r(a + 28);
3631
+ (d + g > u || r(a + 8) !== 0 || r(a + 6) !== r(l + 8)) && n(p);
3598
3632
  let x;
3599
3633
  try {
3600
- x = Jt.decode(t.subarray(s + 30, s + 30 + r(s + 26)));
3634
+ x = Kt.decode(e.subarray(a + 30, a + 30 + r(a + 26)));
3601
3635
  } catch {
3602
3636
  n(p);
3603
3637
  }
3604
- x !== p && n(p), v.push({ name: p, offset: s, start: d, size: g, central: l }), l = h;
3638
+ x !== p && n(p), v.push({ name: p, offset: a, start: d, size: g, central: l }), l = h;
3605
3639
  }
3606
3640
  return l !== y && n(), { files: v };
3607
3641
  }
3608
- function vo(t) {
3609
- const e = t instanceof Uint8Array ? t : new Uint8Array(t), n = Kt(e), r = yo(e, { filter: (a) => a.name !== "__proto__" }), o = /* @__PURE__ */ Object.create(null);
3610
- for (const a of n.files) {
3611
- const i = a.name === "__proto__" ? e.slice(a.start, a.start + a.size) : r[a.name];
3612
- if (!(i instanceof Uint8Array) || i.length !== a.size) throw new Error(`ZIP entry ${JSON.stringify(a.name)}: invalid size`);
3613
- o[a.name] = i;
3642
+ function xo(e) {
3643
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e), n = Qt(t), r = wo(t, { filter: (s) => s.name !== "__proto__" }), o = /* @__PURE__ */ Object.create(null);
3644
+ for (const s of n.files) {
3645
+ const i = s.name === "__proto__" ? t.slice(s.start, s.start + s.size) : r[s.name];
3646
+ if (!(i instanceof Uint8Array) || i.length !== s.size) throw new Error(`ZIP entry ${JSON.stringify(s.name)}: invalid size`);
3647
+ o[s.name] = i;
3614
3648
  }
3615
3649
  return o;
3616
3650
  }
3617
- function Ao(t, e = {}) {
3618
- const n = Object.hasOwn(t, "avatar.json") ? t["avatar.json"] : void 0, r = n ? tt(JSON.parse(Jt.decode(n))) : $n("Avatar"), o = n && !e.manifest ? n : new TextEncoder().encode(JSON.stringify(tt({ ...r, ...e.manifest }), null, 2) + `
3619
- `), a = /* @__PURE__ */ Object.create(null);
3620
- a["avatar.json"] = o;
3621
- for (const [c, f] of Object.entries(t)) c !== "avatar.json" && (a[c] = f);
3622
- for (const [c, [f, h]] of Object.entries(a).entries()) {
3623
- if (sn(f), c >= St) throw new Error(`ZIP entry ${JSON.stringify(f)}: more than ${St} entries`);
3624
- if (h.byteLength > qt) throw new Error(`ZIP entry ${JSON.stringify(f)}: exceeds 64 MB`);
3651
+ function Oo(e, t = {}) {
3652
+ const n = Object.hasOwn(e, "avatar.json") ? e["avatar.json"] : void 0, r = n ? tt(JSON.parse(Kt.decode(n))) : Yn("Avatar"), o = n && !t.manifest ? n : new TextEncoder().encode(JSON.stringify(tt({ ...r, ...t.manifest }), null, 2) + `
3653
+ `), s = /* @__PURE__ */ Object.create(null);
3654
+ s["avatar.json"] = o;
3655
+ for (const [c, f] of Object.entries(e)) c !== "avatar.json" && (s[c] = f);
3656
+ for (const [c, [f, h]] of Object.entries(s).entries()) {
3657
+ if (ln(f), c >= St) throw new Error(`ZIP entry ${JSON.stringify(f)}: more than ${St} entries`);
3658
+ if (h.byteLength > Jt) throw new Error(`ZIP entry ${JSON.stringify(f)}: exceeds 64 MB`);
3625
3659
  }
3626
- const i = Un(a);
3660
+ const i = In(s);
3627
3661
  if (i.length) throw new Error(i.join(`
3628
3662
  `));
3629
3663
  let u = "proto0000";
3630
- for (let c = 0; Object.hasOwn(a, u); c++) u = `proto${String(c + 1).padStart(4, "0")}`;
3631
- const y = Object.fromEntries(Object.entries(a).map(([c, f]) => [c === "__proto__" ? u : c, f])), v = go(y, { level: 0 });
3632
- if (Object.hasOwn(a, "__proto__")) {
3633
- const c = Kt(v).files.find((h) => h.name === u), f = new TextEncoder().encode("__proto__");
3664
+ for (let c = 0; Object.hasOwn(s, u); c++) u = `proto${String(c + 1).padStart(4, "0")}`;
3665
+ const y = Object.fromEntries(Object.entries(s).map(([c, f]) => [c === "__proto__" ? u : c, f])), v = bo(y, { level: 0 });
3666
+ if (Object.hasOwn(s, "__proto__")) {
3667
+ const c = Qt(v).files.find((h) => h.name === u), f = new TextEncoder().encode("__proto__");
3634
3668
  v.set(f, c.offset + 30), v.set(f, c.central + 46);
3635
3669
  }
3636
- const m = Kt(v), l = m.files.find((c) => c.name === "avatar.json");
3670
+ const m = Qt(v), l = m.files.find((c) => c.name === "avatar.json");
3637
3671
  if (l.offset !== 0) {
3638
3672
  const c = l.start + l.size - l.offset, f = new Uint8Array(v.length);
3639
3673
  f.set(v.subarray(l.offset, l.offset + c)), f.set(v.subarray(0, l.offset), c), f.set(v.subarray(l.offset + c), l.offset + c);
@@ -3643,49 +3677,49 @@ function Ao(t, e = {}) {
3643
3677
  }
3644
3678
  return v;
3645
3679
  }
3646
- const bo = (t) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(t));
3647
- function Qe(t, e) {
3680
+ const Mo = (e) => JSON.parse(new TextDecoder("utf-8", { fatal: !0 }).decode(e));
3681
+ function Qe(e, t) {
3648
3682
  try {
3649
- return bo(t);
3683
+ return Mo(e);
3650
3684
  } catch {
3651
- throw new Error(`${e}: invalid UTF-8 JSON`);
3685
+ throw new Error(`${t}: invalid UTF-8 JSON`);
3652
3686
  }
3653
3687
  }
3654
- function Hn(t, e, n, r) {
3688
+ function Zn(e, t, n, r) {
3655
3689
  return [
3656
3690
  "layers.json",
3657
3691
  "base.png",
3658
3692
  "hairmask.png",
3659
3693
  ...r?.cloth?.length ? ["base_cloth.png"] : [],
3660
- ...Object.keys(t?.layers ?? {}).map((o) => `${o}.png`),
3661
- ...e ? ["sprites/sprites.json", ...Object.keys(e.layers ?? {}).map((o) => `sprites/${o}.png`)] : [],
3694
+ ...Object.keys(e?.layers ?? {}).map((o) => `${o}.png`),
3695
+ ...t ? ["sprites/sprites.json", ...Object.keys(t.layers ?? {}).map((o) => `sprites/${o}.png`)] : [],
3662
3696
  // malformed entries are left to validateAvatarFiles, which reports them
3663
3697
  ...n ? ["overlays/overlays.json", ...(Array.isArray(n.overlays) ? n.overlays : []).flatMap((o) => typeof o?.file == "string" ? [`overlays/${o.file}`] : [])] : []
3664
3698
  ];
3665
3699
  }
3666
- function Vn(t) {
3667
- const e = Un(t);
3668
- if (e.length) throw new Error(e.join(`
3700
+ function Wn(e) {
3701
+ const t = In(e);
3702
+ if (t.length) throw new Error(t.join(`
3669
3703
  `));
3670
3704
  }
3671
- function Zn(t) {
3672
- return !!t && typeof t == "object" && "manifest" in t && "rig" in t && "assets" in t && "release" in t;
3705
+ function Gn(e) {
3706
+ return !!e && typeof e == "object" && "manifest" in e && "rig" in e && "assets" in e && "release" in e;
3673
3707
  }
3674
- function Ct(t) {
3675
- const e = vo(t);
3676
- if (!Object.hasOwn(e, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
3677
- Vn(e);
3678
- const n = tt(Qe(e["avatar.json"], "avatar.json")), r = Qt(Qe(e["rig.json"], "rig.json")), o = e["built/overlays/overlays.json"] ? Qe(e["built/overlays/overlays.json"], "built/overlays/overlays.json") : void 0, a = Hn(
3679
- Qe(e["built/layers.json"], "built/layers.json"),
3680
- e["built/sprites/sprites.json"] ? Qe(e["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0,
3708
+ function Dt(e) {
3709
+ const t = xo(e);
3710
+ if (!Object.hasOwn(t, "avatar.json")) throw new Error("avatar.json: missing file in .mavatar archive");
3711
+ Wn(t);
3712
+ const n = tt(Qe(t["avatar.json"], "avatar.json")), r = en(Qe(t["rig.json"], "rig.json")), o = t["built/overlays/overlays.json"] ? Qe(t["built/overlays/overlays.json"], "built/overlays/overlays.json") : void 0, s = Zn(
3713
+ Qe(t["built/layers.json"], "built/layers.json"),
3714
+ t["built/sprites/sprites.json"] ? Qe(t["built/sprites/sprites.json"], "built/sprites/sprites.json") : void 0,
3681
3715
  o,
3682
3716
  r
3683
3717
  ), i = {}, u = [], y = () => {
3684
3718
  u.splice(0).forEach((v) => URL.revokeObjectURL(v));
3685
3719
  };
3686
3720
  try {
3687
- for (const v of new Set(a)) {
3688
- const m = URL.createObjectURL(new Blob([new Uint8Array(e[`built/${v}`])], { type: v.endsWith(".json") ? "application/json" : "image/png" }));
3721
+ for (const v of new Set(s)) {
3722
+ const m = URL.createObjectURL(new Blob([new Uint8Array(t[`built/${v}`])], { type: v.endsWith(".json") ? "application/json" : "image/png" }));
3689
3723
  u.push(m), i[v] = m;
3690
3724
  }
3691
3725
  } catch (v) {
@@ -3693,83 +3727,89 @@ function Ct(t) {
3693
3727
  }
3694
3728
  return { manifest: n, rig: r, assets: i, release: y };
3695
3729
  }
3696
- async function wo(t, e = {}) {
3697
- if (Zn(t)) return t;
3698
- if (t instanceof Blob) return Ct(await t.arrayBuffer());
3699
- if (t instanceof ArrayBuffer || t instanceof Uint8Array) return Ct(t);
3700
- const n = new URL(t, typeof location > "u" ? void 0 : location.href);
3730
+ async function Ao(e, t = {}) {
3731
+ if (Gn(e)) return e;
3732
+ if (e instanceof Blob) return Dt(await e.arrayBuffer());
3733
+ if (e instanceof ArrayBuffer || e instanceof Uint8Array) return Dt(e);
3734
+ const n = new URL(e, typeof location > "u" ? void 0 : location.href);
3701
3735
  if (/\.mavatar$/i.test(n.pathname)) {
3702
3736
  const g = await fetch(n);
3703
3737
  if (!g.ok) throw new Error(`.mavatar: could not load (${g.status})`);
3704
- return Ct(await g.arrayBuffer());
3738
+ return Dt(await g.arrayBuffer());
3705
3739
  }
3706
3740
  n.pathname.endsWith("/") || (n.pathname += "/");
3707
3741
  const r = (g) => {
3708
3742
  const b = new URL(n);
3709
- return b.pathname += g.split("/").map(encodeURIComponent).join("/"), e.version !== void 0 && b.searchParams.set("v", String(e.version)), b.href;
3743
+ return b.pathname += g.split("/").map(encodeURIComponent).join("/"), t.version !== void 0 && b.searchParams.set("v", String(t.version)), b.href;
3710
3744
  }, o = {};
3711
- async function a(g, b = !1) {
3712
- const s = await fetch(r(g));
3713
- if (b && (s.status === 404 || s.ok && s.headers.get("content-type")?.includes("text/html"))) return;
3714
- if (!s.ok) throw new Error(`${g}: could not load (${s.status})`);
3715
- const d = new Uint8Array(await s.arrayBuffer());
3745
+ async function s(g, b = !1) {
3746
+ const a = await fetch(r(g));
3747
+ if (b && (a.status === 404 || a.ok && a.headers.get("content-type")?.includes("text/html"))) return;
3748
+ if (!a.ok) throw new Error(`${g}: could not load (${a.status})`);
3749
+ const d = new Uint8Array(await a.arrayBuffer());
3716
3750
  return o[g] = d, Qe(d, g);
3717
3751
  }
3718
- const i = e.rigFile ?? "rig.json";
3719
- sn(i);
3752
+ const i = t.rigFile ?? "rig.json";
3753
+ ln(i);
3720
3754
  const [u, y, v, m, l] = await Promise.all([
3721
- a(i),
3722
- a("built/layers.json"),
3723
- a("avatar.json", !0),
3724
- a("built/sprites/sprites.json", !0),
3725
- a("built/overlays/overlays.json", !0)
3755
+ s(i),
3756
+ s("built/layers.json"),
3757
+ s("avatar.json", !0),
3758
+ s("built/sprites/sprites.json", !0),
3759
+ s("built/overlays/overlays.json", !0)
3726
3760
  ]);
3727
3761
  Array.isArray(u?.eyes) && Array.isArray(y?.eyes) && (u.eyes = u.eyes.map((g, b) => {
3728
3762
  if (!g || typeof g != "object") return g;
3729
- const s = { ...g };
3730
- for (const d of ["x0", "x1", "top", "bot"]) s[d] === void 0 && (s[d] = y.eyes[b]?.[d]);
3731
- return s;
3763
+ const a = { ...g };
3764
+ for (const d of ["x0", "x1", "top", "bot"]) a[d] === void 0 && (a[d] = y.eyes[b]?.[d]);
3765
+ return a;
3732
3766
  })), o["rig.json"] = new TextEncoder().encode(JSON.stringify(u));
3733
- const c = Hn(y, m, l, u);
3767
+ const c = Zn(y, m, l, u);
3734
3768
  for (const g of c) g.endsWith(".png") && (o[`built/${g}`] = { size: 1 });
3735
- Vn(o);
3736
- const f = Qt(u), h = Object.fromEntries(c.map((g) => [g, r(`built/${g}`)])), p = decodeURIComponent(n.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
3737
- return { manifest: v === void 0 ? $n(p) : tt(v), rig: f, assets: h, release() {
3769
+ Wn(o);
3770
+ const f = en(u), h = Object.fromEntries(c.map((g) => [g, r(`built/${g}`)])), p = decodeURIComponent(n.pathname.split("/").filter(Boolean).at(-1) ?? "Avatar");
3771
+ return { manifest: v === void 0 ? Yn(p) : tt(v), rig: f, assets: h, release() {
3738
3772
  } };
3739
3773
  }
3740
- async function Eo(t, e, n = {}) {
3741
- const r = !Zn(e), o = await wo(e);
3774
+ async function To(e, t, n = {}) {
3775
+ const r = !Gn(t), o = await Ao(t);
3742
3776
  try {
3743
- const a = n.lipSync === void 0 ? o.manifest.lipSync : { ...o.manifest.lipSync, ...en(n.lipSync) }, i = await Zr(t, { ...n, ...a === void 0 ? {} : { lipSync: a }, rig: o.rig, assets: o.assets }), u = i.destroy.bind(i);
3744
- let y = !1;
3745
- return Object.assign(i, { package: o, destroy() {
3746
- if (!y) {
3747
- y = !0;
3777
+ const s = n.lipSync === void 0 ? o.manifest.lipSync : { ...o.manifest.lipSync, ...tn(n.lipSync) }, i = n.expressions === void 0 ? o.manifest.expressions : Vr(o.manifest.expressions, on(n.expressions)), u = await qr(e, {
3778
+ ...n,
3779
+ ...s === void 0 ? {} : { lipSync: s },
3780
+ ...i === void 0 ? {} : { expressions: i },
3781
+ rig: o.rig,
3782
+ assets: o.assets
3783
+ }), y = u.destroy.bind(u);
3784
+ let v = !1;
3785
+ return Object.assign(u, { package: o, destroy() {
3786
+ if (!v) {
3787
+ v = !0;
3748
3788
  try {
3749
- u();
3789
+ y();
3750
3790
  } finally {
3751
3791
  r && o.release();
3752
3792
  }
3753
3793
  }
3754
3794
  } });
3755
- } catch (a) {
3756
- throw r && o.release(), a;
3795
+ } catch (s) {
3796
+ throw r && o.release(), s;
3757
3797
  }
3758
3798
  }
3759
3799
  export {
3760
3800
  mt as ARM_DEFAULTS,
3761
3801
  et as DEFAULT_LIGHTING,
3762
- Mo as LIVE_EXPRESSIONS,
3802
+ So as LIVE_EXPRESSIONS,
3763
3803
  bt as PARAMS,
3764
- xo as colorHex,
3765
- Zr as createMeshAvatar,
3766
- Eo as loadMeshAvatar,
3767
- wo as openAvatar,
3768
- Ao as packAvatar,
3769
- sr as parseLighting,
3804
+ Eo as colorHex,
3805
+ qr as createMeshAvatar,
3806
+ To as loadMeshAvatar,
3807
+ Ao as openAvatar,
3808
+ Oo as packAvatar,
3809
+ lr as parseLighting,
3770
3810
  tt as parseManifest,
3771
- Qt as parseRig,
3772
- vo as unpackAvatar,
3773
- Un as validateAvatarFiles,
3774
- Rn as validateRig
3811
+ en as parseRig,
3812
+ xo as unpackAvatar,
3813
+ In as validateAvatarFiles,
3814
+ Ln as validateRig
3775
3815
  };