@algorisys/tinyfly 0.78.0 → 0.81.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.
@@ -1,37 +1,428 @@
1
- import { s as xt, p as Dt, c as jt, b as ye } from "./sketch-CA8ZXhxI.js";
2
- import { a as jn } from "./sketch-CA8ZXhxI.js";
3
- import { createRandom as me, hashSeed as pe } from "@algorisys/tinyfly";
4
- function ht(t, e, n) {
5
- const o = t.length;
6
- if (o < 2) return [];
7
- const r = [], s = [], h = (i) => e + (n - e) * i / (o - 1);
8
- return t.forEach((i, l) => {
9
- const a = t[Math.max(0, l - 1)], c = t[Math.min(o - 1, l + 1)], g = Math.hypot(c.x - a.x, c.y - a.y) || 1, y = h(l) / 2, f = -(c.y - a.y) / g * y, d = (c.x - a.x) / g * y;
10
- r.push({ x: i.x + f, y: i.y + d }), s.push({ x: i.x - f, y: i.y - d });
11
- }), [...r, ...s.reverse()];
12
- }
13
- function Jt(t, e, n, o) {
1
+ import { b as on, s as Ue, p as Kt, c as tt } from "./sketch-CA8ZXhxI.js";
2
+ import { a as Vr } from "./sketch-CA8ZXhxI.js";
3
+ import { createRandom as rn, hashSeed as ln, getEasingFunction as nt } from "@algorisys/tinyfly";
4
+ function Me(e, t, n) {
14
5
  const r = e.length;
15
- if (r < 2) return;
16
- const s = ht(e, n, o), h = (i) => n + (o - n) * i / (r - 1);
17
- t.beginPath(), t.moveTo(s[0].x, s[0].y);
18
- for (const i of s.slice(1)) t.lineTo(i.x, i.y);
19
- t.closePath(), t.fill(), e.forEach((i, l) => {
20
- l !== 0 && l !== r - 1 && r > 3 || (t.beginPath(), t.arc(i.x, i.y, h(l) / 2, 0, Math.PI * 2), t.fill());
6
+ if (r < 2) return [];
7
+ const o = [], l = [], i = (s) => t + (n - t) * s / (r - 1);
8
+ return e.forEach((s, h) => {
9
+ const a = e[Math.max(0, h - 1)], f = e[Math.min(r - 1, h + 1)], u = Math.hypot(f.x - a.x, f.y - a.y) || 1, p = i(h) / 2, c = -(f.y - a.y) / u * p, g = (f.x - a.x) / u * p;
10
+ o.push({ x: s.x + c, y: s.y + g }), l.push({ x: s.x - c, y: s.y - g });
11
+ }), [...o, ...l.reverse()];
12
+ }
13
+ function ot(e, t, n, r) {
14
+ const o = t.length;
15
+ if (o < 2) return;
16
+ const l = Me(t, n, r), i = (s) => n + (r - n) * s / (o - 1);
17
+ e.beginPath(), e.moveTo(l[0].x, l[0].y);
18
+ for (const s of l.slice(1)) e.lineTo(s.x, s.y);
19
+ e.closePath(), e.fill(), t.forEach((s, h) => {
20
+ h !== 0 && h !== o - 1 && o > 3 || (e.beginPath(), e.arc(s.x, s.y, i(h) / 2, 0, Math.PI * 2), e.fill());
21
+ });
22
+ }
23
+ function fe(e, t, n, r, o = 16) {
24
+ const l = { x: 2 * t.x - (e.x + n.x) / 2, y: 2 * t.y - (e.y + n.y) / 2 }, i = [];
25
+ for (let s = 0; s <= o; s++) {
26
+ const h = s / o, a = h < 0.5 ? { x: e.x + (t.x - e.x) * 2 * h, y: e.y + (t.y - e.y) * 2 * h } : { x: t.x + (n.x - t.x) * (2 * h - 1), y: t.y + (n.y - t.y) * (2 * h - 1) }, f = 1 - h, u = {
27
+ x: f * f * e.x + 2 * f * h * l.x + h * h * n.x,
28
+ y: f * f * e.y + 2 * f * h * l.y + h * h * n.y
29
+ };
30
+ i.push({ x: a.x + (u.x - a.x) * r, y: a.y + (u.y - a.y) * r });
31
+ }
32
+ return i;
33
+ }
34
+ function ct(e, t, n, r, o, l = 0, i = 1, s = 40) {
35
+ const h = Math.cos(o), a = Math.sin(o);
36
+ return Array.from({ length: s + 1 }, (f, u) => {
37
+ const p = l + Math.PI * 2 * i * u / s, c = Math.cos(p) * n, g = Math.sin(p) * r;
38
+ return { x: e + c * h - g * a, y: t + c * a + g * h };
39
+ });
40
+ }
41
+ function Pt(e, t) {
42
+ return t.look === "pencil" ? fn(e, t) : sn(e, t.ink, t.look);
43
+ }
44
+ function Ae(e, t, n = !1) {
45
+ e.beginPath(), e.moveTo(t[0].x, t[0].y);
46
+ for (const r of t.slice(1)) e.lineTo(r.x, r.y);
47
+ n && e.closePath();
48
+ }
49
+ function sn(e, t, n) {
50
+ const r = n === "silhouette", o = r ? 1.25 : 1;
51
+ return {
52
+ look: n,
53
+ ink: t,
54
+ limb(l, i, s) {
55
+ e.fillStyle = t, ot(e, l, i * o, s * o);
56
+ },
57
+ line(l, i) {
58
+ l.length < 2 || (e.strokeStyle = t, e.lineWidth = i * o, e.lineCap = "round", e.lineJoin = "round", Ae(e, l), e.stroke());
59
+ },
60
+ shape(l, i, s) {
61
+ Ae(e, l, !0), (i !== null || r) && (e.fillStyle = r ? t : i, e.fill()), !(s <= 0) && (e.strokeStyle = t, e.lineWidth = s * o, e.lineJoin = "round", e.stroke());
62
+ },
63
+ ellipse(l, i, s, h, a, f, u) {
64
+ e.beginPath(), e.ellipse(l, i, s, h, a, 0, Math.PI * 2), (f !== null || r) && (e.fillStyle = r ? t : f, e.fill()), !(u <= 0) && (e.strokeStyle = t, e.lineWidth = u * o, e.stroke());
65
+ },
66
+ dot(l, i, s) {
67
+ e.fillStyle = t, e.beginPath(), e.arc(l, i, s * o, 0, Math.PI * 2), e.fill();
68
+ },
69
+ guide() {
70
+ },
71
+ guideEllipse() {
72
+ }
73
+ };
74
+ }
75
+ function hn(e, t) {
76
+ const n = [e[0]];
77
+ let r = 0;
78
+ for (let i = 1; i < e.length; i++) {
79
+ const s = e[i - 1], h = e[i], a = Math.hypot(h.x - s.x, h.y - s.y);
80
+ let f = t - r;
81
+ for (; f < a; ) {
82
+ const u = f / a;
83
+ n.push({ x: s.x + (h.x - s.x) * u, y: s.y + (h.y - s.y) * u }), f += t;
84
+ }
85
+ r = a - (f - t);
86
+ }
87
+ const o = e[e.length - 1], l = n[n.length - 1];
88
+ return Math.hypot(o.x - l.x, o.y - l.y) > t * 0.25 ? n.push(o) : n[n.length - 1] = o, n;
89
+ }
90
+ function an(e, t) {
91
+ const n = e.length;
92
+ return e.map((r, o) => {
93
+ const l = e[Math.max(0, o - 1)], i = e[Math.min(n - 1, o + 1)], s = Math.hypot(i.x - l.x, i.y - l.y) || 1, h = t(n === 1 ? 0 : o / (n - 1));
94
+ return { x: r.x - (i.y - l.y) / s * h, y: r.y + (i.x - l.x) / s * h };
95
+ });
96
+ }
97
+ function gt(e) {
98
+ const t = [0.6, 1.4, 2.9].map((r) => ({
99
+ frequency: r * (0.8 + e.next() * 0.4),
100
+ phase: e.next() * Math.PI * 2,
101
+ amount: 0.5 + e.next() * 0.5
102
+ })), n = t.reduce((r, o) => r + o.amount, 0);
103
+ return (r) => t.reduce((o, l) => o + l.amount * Math.sin(Math.PI * 2 * l.frequency * r + l.phase), 0) / n;
104
+ }
105
+ function fn(e, t) {
106
+ const n = t.pencil ?? {}, r = t.ink, o = n.roughness ?? Math.max(1, t.lineWidth * 0.12), l = Math.max(1, Math.round(n.passes ?? 2)), i = Math.min(1, Math.max(0, n.pressure ?? 0.25)), s = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), h = on(t.time, n.boil ?? 8);
107
+ let a = 0;
108
+ const f = (g, d, b = !1) => rn(ln(`${t.seed}:${b ? "paper" : h}:${g}:${d}`)), u = (g, d, b, m, S, k = 0) => {
109
+ if (g.length < 2) return;
110
+ const T = g.slice(1).reduce((W, M, y) => W + Math.hypot(M.x - g[y].x, M.y - g[y].y), 0);
111
+ let H = hn(g, Math.max(1.5, Math.min(t.lineWidth * 0.8, T / 24)));
112
+ if (k > 0 && H.length >= 2) {
113
+ const [W, M] = [H[H.length - 2], H[H.length - 1]], y = Math.hypot(M.x - W.x, M.y - W.y) || 1;
114
+ H = [...H, { x: M.x + (M.x - W.x) / y * k, y: M.y + (M.y - W.y) / y * k }];
115
+ }
116
+ const w = gt(b), E = gt(b), v = H.length, A = [], I = [];
117
+ H.forEach((W, M) => {
118
+ const y = v === 1 ? 0 : M / (v - 1), x = H[Math.max(0, M - 1)], O = H[Math.min(v - 1, M + 1)], K = Math.hypot(O.x - x.x, O.y - x.y) || 1, P = -(O.y - x.y) / K, $ = (O.x - x.x) / K, B = w(y) * S, F = Math.min(1, y / 0.08, (1 - y) / 0.08), C = (0.55 + 0.45 * Math.sqrt(Math.max(0, F))) * (1 + i * E(y)), L = Math.max(0.3, d(y) * C / 2), Q = W.x + P * B, ne = W.y + $ * B;
119
+ A.push({ x: Q + P * L, y: ne + $ * L }), I.push({ x: Q - P * L, y: ne - $ * L });
120
+ }), e.save(), e.globalAlpha *= m, e.fillStyle = r, Ae(e, [...A, ...I.reverse()], !0), e.fill(), e.restore();
121
+ }, p = (g, d) => {
122
+ const b = a++, m = f(b, 99, !0);
123
+ if (m.next() < s) {
124
+ const H = (m.next() * 2 - 1) * t.lineWidth * 1.4, w = (m.next() * 2 - 1) * t.lineWidth * 1.4, E = g.map((v) => ({ x: v.x + H, y: v.y + w }));
125
+ u(E, (v) => d(v) * 1.8, f(b, 98, !0), 0.035, o), u(E, (v) => d(v) * 0.45, f(b, 97, !0), 0.12, o * 1.5);
126
+ }
127
+ const S = g.slice(1).reduce((H, w, E) => H + Math.hypot(w.x - g[E].x, w.y - g[E].y), 0), k = d(0.5) > 4 && S > d(0.5) * 6, T = k ? [-0.3, 0.3, 0] : [0];
128
+ for (let H = 0; H < l; H++) {
129
+ const w = H === 0;
130
+ T.forEach((E, v) => {
131
+ const A = f(b, H * 10 + v), I = E === 0 ? g : an(g, (M) => d(M) * E * Math.sqrt(Math.sin(Math.PI * M))), W = !w && E === 0 ? t.lineWidth * (0.3 + A.next() * 0.8) : 0;
132
+ u(I, (M) => d(M) * (k ? 0.5 : 1) * (w ? 1 : 0.6), A, w ? 0.85 : 0.45, o * (w ? 0.6 : 1), W);
133
+ });
134
+ }
135
+ }, c = (g, d, b, m, S, k) => {
136
+ const H = f(a, 50).next() * Math.PI * 2;
137
+ p(ct(g, d, b, m, S, H, 1.08, 48), () => k);
138
+ };
139
+ return {
140
+ look: "pencil",
141
+ ink: r,
142
+ limb(g, d, b) {
143
+ p(g, (m) => d + (b - d) * m);
144
+ },
145
+ line(g, d) {
146
+ p(g, () => d);
147
+ },
148
+ shape(g, d, b) {
149
+ d !== null && (e.save(), e.globalAlpha *= 0.88, e.fillStyle = d, Ae(e, g, !0), e.fill(), e.restore()), b > 0 && p([...g, g[0]], () => b);
150
+ },
151
+ ellipse(g, d, b, m, S, k, T) {
152
+ k !== null && (e.save(), e.globalAlpha *= 0.9, e.fillStyle = k, e.beginPath(), e.ellipse(g, d, b, m, S, 0, Math.PI * 2), e.fill(), e.restore()), c(g, d, b, m, S, T);
153
+ },
154
+ dot(g, d, b) {
155
+ e.save(), e.globalAlpha *= 0.9, e.fillStyle = r, e.beginPath(), e.arc(g, d, b, 0, Math.PI * 2), e.fill(), e.restore();
156
+ },
157
+ guide(g) {
158
+ if (n.construction === !1 || g.length < 2) return;
159
+ const d = a++;
160
+ u(g, () => Math.max(0.6, t.lineWidth * 0.18), f(d, 0), 0.28, o * 1.2, t.lineWidth);
161
+ },
162
+ guideEllipse(g, d, b, m, S) {
163
+ if (n.construction === !1) return;
164
+ const k = a++, T = f(k, 0), H = ct(g, d, b, m, S, T.next() * Math.PI * 2, 1.12, 48);
165
+ u(H, () => Math.max(0.6, t.lineWidth * 0.18), T, 0.28, o * 1.5);
166
+ }
167
+ };
168
+ }
169
+ const cn = ["thumb", "index", "middle", "ring", "pinky"], R = {
170
+ "thumb.curl": 0.15,
171
+ "thumb.across": 0.15,
172
+ "index.curl": 0.12,
173
+ "middle.curl": 0.16,
174
+ "ring.curl": 0.2,
175
+ "pinky.curl": 0.25,
176
+ spread: 0.25,
177
+ turn: 0,
178
+ bend: 0,
179
+ tilt: 0,
180
+ roll: 0
181
+ };
182
+ function _(e = {}) {
183
+ return { ...R, ...e };
184
+ }
185
+ const X = (e, t, n, r, o) => ({
186
+ "thumb.curl": e,
187
+ "index.curl": t,
188
+ "middle.curl": n,
189
+ "ring.curl": r,
190
+ "pinky.curl": o
191
+ }), N = {
192
+ relaxed: R,
193
+ open: _({ ...X(0, 0, 0, 0, 0), "thumb.across": 0, spread: 0.55 }),
194
+ spread: _({ ...X(0, 0, 0, 0, 0), "thumb.across": 0, spread: 1 }),
195
+ flat: _({ ...X(0, 0, 0, 0, 0), "thumb.across": 0.35, spread: 0 }),
196
+ fist: _({ ...X(0.7, 1, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
197
+ point: _({ ...X(0.75, 0, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
198
+ /** The fist on its side, knuckles toward the viewer, the thumb up */
199
+ thumbsUp: _({ ...X(0, 1, 1, 1, 1), "thumb.across": 0, spread: 0, roll: 70 }),
200
+ peace: _({ ...X(0.75, 0, 0, 1, 1), "thumb.across": 0.9, spread: 1 }),
201
+ ok: _({ ...X(0.12, 0.6, 0.1, 0.15, 0.2), "thumb.across": 0.55, spread: 0.6 }),
202
+ pinch: _({ ...X(0.1, 0.65, 0.75, 0.85, 0.9), "thumb.across": 0.55, spread: 0 }),
203
+ cupped: _({ ...X(0.25, 0.4, 0.4, 0.4, 0.4), "thumb.across": 0.4, spread: 0.05, turn: 2 }),
204
+ wave: _({ ...X(0, 0.05, 0.05, 0.1, 0.12), "thumb.across": 0, spread: 0.7, turn: 2 }),
205
+ /** Holding a pencil to write: thumb and middle finger pinch it, the index finger rests on top */
206
+ pencilGrip: _({ ...X(0.1, 0.6, 0.72, 0.88, 0.95), "thumb.across": 0.5, spread: 0, turn: 0.8, bend: 10 }),
207
+ /** Holding a handle, a cup or a bar: every finger wrapped round it */
208
+ hold: _({ ...X(0.5, 0.7, 0.72, 0.74, 0.76), "thumb.across": 0.75, spread: 0, turn: 1 })
209
+ };
210
+ function be(e, t, n) {
211
+ const r = { ...e };
212
+ for (const [o, l] of Object.entries(t)) {
213
+ const i = e[o] ?? l;
214
+ r[o] = i + (l - i) * n;
215
+ }
216
+ return r;
217
+ }
218
+ const gn = {
219
+ index: { knuckle: [-0.16, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.125, fan: -1 },
220
+ middle: { knuckle: [-0.055, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.13, fan: -0.2 },
221
+ ring: { knuckle: [0.05, 0.475, -0.02], bones: [0.2, 0.125, 0.1], width: 0.122, fan: 0.55 },
222
+ pinky: { knuckle: [0.15, 0.43, -0.02], bones: [0.16, 0.1, 0.085], width: 0.108, fan: 1.25 }
223
+ }, un = {
224
+ index: { knuckle: [-0.14, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.15, fan: -1 },
225
+ middle: { knuckle: [0, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.155, fan: 0 },
226
+ pinky: { knuckle: [0.14, 0.45, -0.02], bones: [0.19, 0.115, 0.095], width: 0.145, fan: 1 }
227
+ }, V = {
228
+ base: [-0.11, 0.1, -0.05],
229
+ bones: [0.2, 0.15, 0.12],
230
+ widths: [0.2, 0.145, 0.135],
231
+ /** Where the thumb points with `across` 0 and 1 */
232
+ out: [-0.7, 0.68, -0.22],
233
+ across: [0.35, 0.5, -0.8]
234
+ }, dn = [82, 100, 62], pn = [48, 72], bn = 3, mn = 13, yn = 0.035, wn = -0.075, kn = [
235
+ [-0.17, 0],
236
+ [-0.215, 0.12],
237
+ [-0.235, 0.26],
238
+ [-0.225, 0.4],
239
+ [-0.185, 0.49],
240
+ [-0.075, 0.525],
241
+ [0.05, 0.51],
242
+ [0.16, 0.465],
243
+ [0.215, 0.4],
244
+ [0.225, 0.26],
245
+ [0.2, 0.1],
246
+ [0.16, 0]
247
+ ], le = (e) => e * Math.PI / 180, ze = (e, t) => [e[0] + t[0], e[1] + t[1], e[2] + t[2]], Te = (e, t) => [e[0] * t, e[1] * t, e[2] * t], Ge = (e, t) => [e[1] * t[2] - e[2] * t[1], e[2] * t[0] - e[0] * t[2], e[0] * t[1] - e[1] * t[0]], ce = (e) => {
248
+ const t = Math.hypot(e[0], e[1], e[2]) || 1;
249
+ return [e[0] / t, e[1] / t, e[2] / t];
250
+ };
251
+ function ie(e, t, n) {
252
+ const r = Math.cos(n), o = Math.sin(n), l = Ge(t, e), i = t[0] * e[0] + t[1] * e[1] + t[2] * e[2];
253
+ return [
254
+ e[0] * r + l[0] * o + t[0] * i * (1 - r),
255
+ e[1] * r + l[1] * o + t[1] * i * (1 - r),
256
+ e[2] * r + l[2] * o + t[2] * i * (1 - r)
257
+ ];
258
+ }
259
+ const ut = [1, 0, 0], dt = [0, 1, 0], de = [0, 0, 1];
260
+ function Sn(e, t, n) {
261
+ const r = le(e.fan * (bn + mn * n)), o = [Math.sin(r), Math.cos(r), 0], l = [Math.cos(r), -Math.sin(r), 0], i = [e.knuckle];
262
+ let s = 0;
263
+ e.bones.forEach((f, u) => {
264
+ s += le(dn[u] * t), i.push(ze(i[u], Te(ie(o, l, -s), f)));
21
265
  });
266
+ const h = ie(de, l, -s), a = i.map((f, u) => e.width * (1 - 0.14 * (u / (i.length - 1))));
267
+ return { joints: i, back: h, widths: a };
22
268
  }
23
- function z(t, e, n, o, r = 16) {
24
- const s = { x: 2 * e.x - (t.x + n.x) / 2, y: 2 * e.y - (t.y + n.y) / 2 }, h = [];
25
- for (let i = 0; i <= r; i++) {
26
- const l = i / r, a = l < 0.5 ? { x: t.x + (e.x - t.x) * 2 * l, y: t.y + (e.y - t.y) * 2 * l } : { x: e.x + (n.x - e.x) * (2 * l - 1), y: e.y + (n.y - e.y) * (2 * l - 1) }, c = 1 - l, g = {
27
- x: c * c * t.x + 2 * c * l * s.x + l * l * n.x,
28
- y: c * c * t.y + 2 * c * l * s.y + l * l * n.y
269
+ function En(e, t, n = 1, r = 1) {
270
+ const o = Math.min(1, Math.max(0, t)), l = ce(ze(Te(ce(V.out), 1 - o), Te(ce(V.across), o))), i = ce(Ge(de, l)), s = ce(Ge(l, i)), h = [[V.base[0] * r, V.base[1], V.base[2]]];
271
+ let a = 0;
272
+ V.bones.forEach((p, c) => {
273
+ c > 0 && (a += le(pn[c - 1] * e)), h.push(ze(h[c], Te(ie(l, i, a), p)));
274
+ });
275
+ const f = ie(s, i, a), u = [...V.widths, V.widths[V.widths.length - 1] * 0.92].map((p) => p * n);
276
+ return { joints: h, back: f, widths: u };
277
+ }
278
+ function Je(e, t = {}) {
279
+ const n = { ...R, ...e }, r = t.size ?? 100, o = t.side ?? "right", l = o === "left" ? -1 : 1, i = le(t.angle ?? 0), s = t.fingers === 4, h = Math.max(0.5, t.plump ?? 1), a = 1 + (h - 1) * 0.7, f = (M) => ({
280
+ ...M,
281
+ knuckle: [M.knuckle[0] * a, M.knuckle[1], M.knuckle[2]],
282
+ width: M.width * h
283
+ }), u = le(n.bend ?? 0), p = le(n.tilt ?? 0), c = le(90 * (n.turn ?? 0)), g = (M) => ie(ie(ie(M, ut, -u), de, -p), dt, c), d = Math.cos(i), b = Math.sin(i), m = le(n.roll ?? 0), S = Math.cos(m), k = Math.sin(m), T = (M) => {
284
+ const y = M[0] * r, x = -M[1] * r, O = (y * S - x * k) * l, K = y * k + x * S;
285
+ return { x: O * d - K * b, y: O * b + K * d };
286
+ }, H = (M) => {
287
+ const y = T(M), x = Math.hypot(y.x, y.y);
288
+ return x > 1e-6 * r ? { x: y.x / x, y: y.y / x } : { x: 0, y: 0 };
289
+ }, w = {
290
+ thumb: En(n["thumb.curl"] ?? 0, n["thumb.across"] ?? 0, h, a)
291
+ }, E = s ? un : gn;
292
+ for (const M of cn) {
293
+ const y = E[M];
294
+ y && (w[M] = Sn(f(y), n[`${M}.curl`] ?? 0, n.spread ?? 0));
295
+ }
296
+ const v = {};
297
+ for (const [M, y] of Object.entries(w)) {
298
+ const x = y.joints.map(g), O = g(y.back);
299
+ v[M] = {
300
+ points: x.map(T),
301
+ depths: x.map((K) => K[2] * r),
302
+ widths: y.widths.map((K) => K * r),
303
+ nail: O[2],
304
+ back: H(O)
29
305
  };
30
- h.push({ x: a.x + (g.x - a.x) * o, y: a.y + (g.y - a.y) * o });
31
306
  }
32
- return h;
307
+ const A = kn.flatMap(([M, y]) => [g([M * a, y, yn]), g([M * a, y, wn])]), I = Mn(A.map(T)), W = A.reduce((M, y) => M + y[2], 0) / A.length * r;
308
+ return {
309
+ size: r,
310
+ side: o,
311
+ wrist: { x: 0, y: 0 },
312
+ palm: I,
313
+ palmDepth: W,
314
+ palmFacing: -g(de)[2],
315
+ fingers: v,
316
+ axes: { up: H(g(dt)), across: H(g(ut)), out: H(g(de)) },
317
+ curls: Object.fromEntries(Object.keys(v).map((M) => [M, n[`${M}.curl`] ?? 0]))
318
+ };
33
319
  }
34
- const G = {
320
+ function Hn(e, t) {
321
+ const n = (o) => ({ x: o.x + t.x - e.wrist.x, y: o.y + t.y - e.wrist.y }), r = {};
322
+ for (const [o, l] of Object.entries(e.fingers))
323
+ r[o] = { ...l, points: l.points.map(n) };
324
+ return { ...e, wrist: n(e.wrist), palm: e.palm.map(n), fingers: r };
325
+ }
326
+ function Mn(e) {
327
+ const t = [...e].sort((l, i) => l.x - i.x || l.y - i.y);
328
+ if (t.length < 3) return t;
329
+ const n = (l, i, s) => (i.x - l.x) * (s.y - l.y) - (i.y - l.y) * (s.x - l.x), r = [];
330
+ for (const l of t) {
331
+ for (; r.length >= 2 && n(r[r.length - 2], r[r.length - 1], l) <= 0; ) r.pop();
332
+ r.push(l);
333
+ }
334
+ const o = [];
335
+ for (const l of [...t].reverse()) {
336
+ for (; o.length >= 2 && n(o[o.length - 2], o[o.length - 1], l) <= 0; ) o.pop();
337
+ o.push(l);
338
+ }
339
+ return [...r.slice(0, -1), ...o.slice(0, -1)];
340
+ }
341
+ const Tn = "#f1c9a5", vn = "#2f2f33";
342
+ function rt(e, t, n, r = {}, o = 0) {
343
+ const l = Hn(Je(n, r), t), i = r.ink ?? vn, s = r.lineWidth ?? l.size * 0.035, h = r.pen ?? Pt(e, {
344
+ look: r.look ?? "clean",
345
+ ink: i,
346
+ lineWidth: s,
347
+ seed: r.seed ?? 1,
348
+ time: o,
349
+ pencil: { construction: !1, ...r.pencil }
350
+ }), a = r.skin ?? Tn, f = r.nails ?? !0, u = [
351
+ {
352
+ depth: l.palmDepth,
353
+ draw: () => xn(h, l, a, s)
354
+ }
355
+ ];
356
+ for (const p of Object.values(l.fingers)) {
357
+ const c = p.depths.reduce((g, d) => g + d, 0) / p.depths.length;
358
+ u.push({
359
+ depth: c,
360
+ draw: () => An(e, h, p, a, s, f)
361
+ });
362
+ }
363
+ if (r.prop) {
364
+ const p = r.prop;
365
+ u.push({ depth: p.depth, draw: () => p.draw(h) });
366
+ }
367
+ e.save(), e.lineCap = "round", e.lineJoin = "round";
368
+ for (const p of [...u].sort((c, g) => c.depth - g.depth)) p.draw();
369
+ return e.restore(), l;
370
+ }
371
+ function xn(e, t, n, r) {
372
+ if (e.shape(t.palm, n, r), t.palmFacing < -0.3 && e.look !== "silhouette") {
373
+ const { up: o } = t.axes;
374
+ for (const [l, i] of Object.entries(t.fingers)) {
375
+ const s = t.curls[l] ?? 0;
376
+ if (l === "thumb" || s < 0.5) continue;
377
+ const h = i.points[0], a = i.widths[0] * 0.42, f = { x: h.x - o.x * a * 0.2, y: h.y - o.y * a * 0.2 }, u = Math.atan2(o.y, o.x), p = Array.from({ length: 7 }, (c, g) => {
378
+ const d = u - Math.PI / 2 + Math.PI * g / 6;
379
+ return { x: f.x + Math.cos(d) * a, y: f.y + Math.sin(d) * a };
380
+ });
381
+ e.line(p, r * 0.6);
382
+ }
383
+ }
384
+ if (t.palmFacing > 0.45 && e.look !== "silhouette") {
385
+ const { up: o, across: l } = t.axes, i = t.size, s = t.wrist, h = (f, u) => ({
386
+ x: s.x + (l.x * f + o.x * u) * i,
387
+ y: s.y + (l.y * f + o.y * u) * i
388
+ }), a = t.side === "left" ? -1 : 1;
389
+ e.line([h(-0.15 * a, 0.36), h(-0.04 * a, 0.3), h(0.1 * a, 0.33)], r * 0.5);
390
+ }
391
+ }
392
+ function An(e, t, n, r, o, l) {
393
+ const { widths: i } = n, s = Kn(n.points, 2), h = n.points[0], a = s[s.length - 1], f = i[0], u = i[i.length - 1];
394
+ if (e.save(), t.look !== "silhouette") {
395
+ e.beginPath(), e.rect(h.x - 1e5, h.y - 1e5, 2e5, 2e5);
396
+ const d = f / 2 + o * 1.6;
397
+ e.moveTo(h.x + d, h.y), e.arc(h.x, h.y, d, 0, Math.PI * 2), e.clip("evenodd");
398
+ }
399
+ if (t.limb(s, f + 2 * o, u + 2 * o), e.restore(), t.look !== "silhouette" && (e.fillStyle = r, ot(e, s, f, u)), t.look === "silhouette" || !l || n.nail < 0.25) return;
400
+ const p = s[s.length - 2], c = Pn({ x: a.x - p.x, y: a.y - p.y }) ?? {
401
+ x: 0,
402
+ y: -1
403
+ }, g = {
404
+ x: a.x - c.x * u * 0.22 + n.back.x * u * 0.1,
405
+ y: a.y - c.y * u * 0.22 + n.back.y * u * 0.1
406
+ };
407
+ t.ellipse(g.x, g.y, u * 0.24 * Math.max(0.35, n.nail), u * 0.19, Math.atan2(c.y, c.x), "#f8e3d3", o * 0.45);
408
+ }
409
+ function Kn(e, t) {
410
+ let n = e;
411
+ for (let r = 0; r < t; r++) {
412
+ if (n.length < 3) return n;
413
+ const o = [n[0]];
414
+ for (let l = 0; l < n.length - 1; l++) {
415
+ const i = n[l], s = n[l + 1];
416
+ l > 0 && o.push({ x: i.x * 0.75 + s.x * 0.25, y: i.y * 0.75 + s.y * 0.25 }), l < n.length - 2 && o.push({ x: i.x * 0.25 + s.x * 0.75, y: i.y * 0.25 + s.y * 0.75 });
417
+ }
418
+ o.push(n[n.length - 1]), n = o;
419
+ }
420
+ return n;
421
+ }
422
+ const Pn = (e) => {
423
+ const t = Math.hypot(e.x, e.y);
424
+ return t > 1e-6 ? { x: e.x / t, y: e.y / t } : null;
425
+ }, z = {
35
426
  lean: 0,
36
427
  headTilt: 0,
37
428
  leftShoulder: 18,
@@ -42,6 +433,12 @@ const G = {
42
433
  rightHip: 8,
43
434
  leftKnee: 0,
44
435
  rightKnee: 0,
436
+ leftWrist: 0,
437
+ rightWrist: 0,
438
+ leftAnkle: 0,
439
+ rightAnkle: 0,
440
+ leftFootOut: 0,
441
+ rightFootOut: 0,
45
442
  mouth: 0,
46
443
  smile: 0.6,
47
444
  mouthWidth: 1,
@@ -55,12 +452,14 @@ const G = {
55
452
  lookY: 0,
56
453
  stretch: 1,
57
454
  turn: 0,
58
- sit: 0
455
+ sit: 0,
456
+ spin: 0,
457
+ rise: 0
59
458
  };
60
- function B(t) {
61
- return { ...G, ...t };
459
+ function D(e) {
460
+ return { ...z, ...e };
62
461
  }
63
- const zt = {
462
+ const Wt = {
64
463
  mouth: 0,
65
464
  smile: 0,
66
465
  mouthWidth: 1,
@@ -71,779 +470,1415 @@ const zt = {
71
470
  browTilt: 0,
72
471
  lookX: 0,
73
472
  lookY: 0
74
- }, _ = (t) => ({ ...zt, ...t }), N = {
75
- neutral: zt,
76
- happy: _({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
77
- joyful: _({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
78
- sad: _({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
79
- crying: _({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
80
- surprised: _({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
81
- shocked: _({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
82
- angry: _({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
83
- furious: _({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
84
- worried: _({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
85
- scared: _({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
86
- confused: _({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
87
- skeptical: _({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
88
- thinking: _({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
89
- sleepy: _({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
90
- disgusted: _({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
91
- smug: _({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
92
- wink: _({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
473
+ }, Y = (e) => ({ ...Wt, ...e }), J = {
474
+ neutral: Wt,
475
+ happy: Y({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
476
+ joyful: Y({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
477
+ sad: Y({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
478
+ crying: Y({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
479
+ surprised: Y({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
480
+ shocked: Y({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
481
+ angry: Y({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
482
+ furious: Y({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
483
+ worried: Y({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
484
+ scared: Y({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
485
+ confused: Y({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
486
+ skeptical: Y({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
487
+ thinking: Y({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
488
+ sleepy: Y({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
489
+ disgusted: Y({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
490
+ smug: Y({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
491
+ wink: Y({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
93
492
  };
94
- function we(t, e) {
95
- return { ...t, ...typeof e == "string" ? N[e] : e };
96
- }
97
- const be = {
98
- rest: G,
99
- wave: B({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...N.happy }),
100
- cheer: B({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...N.joyful }),
101
- shrug: B({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...N.confused, lookX: 0, lookY: 0 }),
102
- point: B({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
493
+ function Ot(e, t) {
494
+ return { ...e, ...typeof t == "string" ? J[t] : t };
495
+ }
496
+ const Wn = {
497
+ rest: z,
498
+ wave: D({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...J.happy }),
499
+ cheer: D({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...J.joyful }),
500
+ shrug: D({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...J.confused, lookX: 0, lookY: 0 }),
501
+ point: D({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
103
502
  // The forearm passes 180° to fold back in, so the hand reaches the chin.
104
- think: B({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...N.thinking }),
105
- handsOnHips: B({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
106
- sad: B({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...N.sad }),
107
- surprised: B({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...N.surprised }),
503
+ think: D({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...J.thinking }),
504
+ handsOnHips: D({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
505
+ sad: D({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...J.sad }),
506
+ surprised: D({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...J.surprised }),
108
507
  // Squash and stretch: the wind-up before a jump (or the landing), and the jump itself.
109
- crouch: B({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
508
+ crouch: D({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
110
509
  // Seated, hands resting on the knees. Arm angles spread outward per side, so
111
510
  // reaching forward (+x, the way the figure faces) is negative for the left arm.
112
- sit: B({ sit: 1, turn: 0.5, leftShoulder: -25, rightShoulder: 25, leftElbow: -55, rightElbow: 55 }),
113
- jump: B({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...N.joyful })
114
- }, Gt = Object.keys(G);
115
- function Me(t, e, n) {
116
- const o = { ...t };
117
- for (const r of Gt) o[r] = t[r] + (e[r] - t[r]) * n;
118
- return o;
119
- }
120
- const St = 24, _t = 4, Yt = 28, ke = 40;
121
- function Ee(t, e = G, n = 1) {
122
- const o = Math.sin(t * Math.PI * 2) * n, r = Math.cos(t * Math.PI * 2) * n, s = (a) => a <= ke, h = (a) => s(a) ? 22 * o : a, i = s(e.leftShoulder) ? e.leftElbow - Yt * Math.max(0, -o) : e.leftElbow, l = s(e.rightShoulder) ? e.rightElbow + Yt * Math.max(0, o) : e.rightElbow;
511
+ sit: D({ sit: 1, turn: 0.5, leftShoulder: -25, rightShoulder: 25, leftElbow: -55, rightElbow: 55 }),
512
+ jump: D({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...J.joyful }),
513
+ // Full splits: legs flat along the floor, so the planted feet bring the hips right down to it.
514
+ // Side (straddle) split, seen front-on: each leg straight out to its side, toes pointed.
515
+ sideSplit: D({ leftHip: 90, rightHip: 90, leftAnkle: -45, rightAnkle: -45, leftShoulder: 120, rightShoulder: 120, leftElbow: 10, rightElbow: 10, ...J.happy }),
516
+ // Front split, in profile: the left leg forward (+x), the right leg back.
517
+ frontSplit: D({ turn: 1, leftHip: -90, rightHip: -90, leftAnkle: -45, rightAnkle: -45, leftShoulder: -150, rightShoulder: 150, leftElbow: 10, rightElbow: -10, ...J.happy })
518
+ }, It = Object.keys(z);
519
+ function me(e, t, n) {
520
+ const r = { ...e };
521
+ for (const o of It) r[o] = e[o] + (t[o] - e[o]) * n;
522
+ return r;
523
+ }
524
+ const Ze = 24, pt = 4, bt = 28, On = 40;
525
+ function In(e, t = z, n = 1) {
526
+ const r = Math.sin(e * Math.PI * 2) * n, o = Math.cos(e * Math.PI * 2) * n, l = (a) => a <= On, i = (a) => l(a) ? 22 * r : a, s = l(t.leftShoulder) ? t.leftElbow - bt * Math.max(0, -r) : t.leftElbow, h = l(t.rightShoulder) ? t.rightElbow + bt * Math.max(0, r) : t.rightElbow;
123
527
  return {
124
- ...e,
528
+ ...t,
125
529
  // Lean into the walk, and keep the head a little more level than the body.
126
- lean: e.lean + _t * n,
127
- headTilt: e.headTilt - _t * 0.5 * n,
128
- leftElbow: i,
129
- rightElbow: l,
530
+ lean: t.lean + pt * n,
531
+ headTilt: t.headTilt - pt * 0.5 * n,
532
+ leftElbow: s,
533
+ rightElbow: h,
130
534
  // Left foot forward while swing > 0, right foot back; then the other way.
131
- leftHip: -St * o,
132
- rightHip: -St * o,
535
+ leftHip: -Ze * r,
536
+ rightHip: -Ze * r,
133
537
  // The leg swinging forward lifts, its shin trailing backward (-x). A positive
134
538
  // knee folds toward the centre, which is backward only for the right leg.
135
- leftKnee: -30 * Math.max(0, r),
136
- rightKnee: 30 * Math.max(0, -r),
539
+ leftKnee: -30 * Math.max(0, o),
540
+ rightKnee: 30 * Math.max(0, -o),
137
541
  // Arms swing against the legs: left arm back while the left foot is forward.
138
- leftShoulder: h(e.leftShoulder),
139
- rightShoulder: h(e.rightShoulder)
542
+ leftShoulder: i(t.leftShoulder),
543
+ rightShoulder: i(t.rightShoulder)
140
544
  };
141
545
  }
142
- function Sn(t, e = 1) {
143
- return 4 * ((Pt + ct) * t) * Math.sin(St * e * Math.PI / 180);
546
+ function Sr(e, t = 1) {
547
+ return 4 * ((je + Ke) * e) * Math.sin(Ze * t * Math.PI / 180);
144
548
  }
145
- function xe(t) {
146
- const e = Math.abs(Math.sin(t / 65)), n = 0.55 + 0.45 * Math.sin(t / 310);
147
- return e * n;
549
+ function Bn(e) {
550
+ const t = Math.abs(Math.sin(e / 65)), n = 0.55 + 0.45 * Math.sin(e / 310);
551
+ return t * n;
148
552
  }
149
- const Zt = 0.12, $t = 0.46, Se = 1 - 2 * Zt, Pe = 0.1, Te = 0.21, ve = 0.19, Pt = 0.24, ct = 0.22, Qt = 0.12, We = 0.14, Vt = 0.33, Bt = 0.7, Rt = 0.3, Oe = 0.35, Ie = [1.7, 1.05], Ae = [1.3, 0.75], Lt = [1.45, 0.85], He = [1.15, 0.75], Ft = 0.06, _e = 0.7, Ye = 0.65, $e = 0.3, Be = 0.02, Re = 0.012, Le = 12, Fe = 0.25, ot = 90, Ne = 0.25, Ce = 0.01, J = (t) => Math.min(1, Math.max(0, t ?? 0));
150
- function Pn(t, e = 1) {
151
- return ct * t * e;
553
+ const Bt = 0.12, mt = 0.46, $n = 1 - 2 * Bt, Fn = 0.1, _n = 0.21, Rn = 0.19, je = 0.24, Ke = 0.22, $t = 0.12, Yn = 0.14, Ft = 0.33, yt = 0.7, wt = 0.3, Ln = 0.35, Nn = [1.7, 1.05], Cn = [1.3, 0.75], kt = [1.45, 0.85], Dn = [1.15, 0.75], St = 0.06, qn = 0.7, Xn = 0.65, _t = 0.075, Un = 0.3, zn = 0.02, Gn = 0.012, Jn = 12, Zn = 0.25, ye = 90, jn = 0.25, Qn = 0.04, Rt = 0.01, se = (e) => Math.min(1, Math.max(0, e ?? 0));
554
+ function Er(e, t = 1) {
555
+ return Ke * e * t;
152
556
  }
153
- const Tt = -0.12, te = 0.4, C = (t) => t * Math.PI / 180, Xe = (t, e) => ({ x: e * Math.sin(C(t)), y: Math.cos(C(t)) }), ee = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), ne = (t, e, n, o) => t - 0.3 * e - n * 0.14 * e - Math.max(0, o - 1) * 0.12 * e;
154
- function qe(t, e, n, o, r, s) {
155
- const h = Math.max(1, Math.min(s * 0.6, We * n)), i = J(e.turn), l = (Qt + Vt * i) * n, a = o + Tt * n, c = l + e.lookX * 0.08 * n, g = e.lookY * 0.07 * n, y = [
557
+ const Qe = -0.12, Yt = 0.4, Z = (e) => e * Math.PI / 180, Vn = (e, t) => ({ x: t * Math.sin(Z(e)), y: Math.cos(Z(e)) }), Lt = (e, t) => Math.max(0, e) * (1 - Math.min(1, Math.max(0, t))), Nt = (e, t, n, r) => e - 0.3 * t - n * 0.14 * t - Math.max(0, r - 1) * 0.12 * t;
558
+ function eo(e, t, n, r, o, l) {
559
+ const i = Math.max(1, Math.min(l * 0.6, Yn * n)), s = se(t.turn), h = ($t + Ft * s) * n, a = r + Qe * n, f = h + t.lookX * 0.08 * n, u = t.lookY * 0.07 * n, p = [
156
560
  // The left eye is on the far side; turning closes it up more than the near one.
157
- { x: -0.34 * n * (1 - Bt * i), squeeze: 1 - Bt * i, open: e.leftEye, brow: e.leftBrow, side: -1 },
158
- { x: 0.34 * n * (1 - Rt * i), squeeze: 1 - Rt * i, open: e.rightEye, brow: e.rightBrow, side: 1 }
561
+ { x: -0.34 * n * (1 - yt * s), squeeze: 1 - yt * s, open: t.leftEye, brow: t.leftBrow, side: -1 },
562
+ { x: 0.34 * n * (1 - wt * s), squeeze: 1 - wt * s, open: t.rightEye, brow: t.rightBrow, side: 1 }
159
563
  ];
160
- t.fillStyle = r, t.strokeStyle = r, t.lineWidth = h;
161
- for (const u of y) {
162
- const k = ee(u.open, e.blink);
163
- if (k < 0.2) {
164
- const P = e.smile > 0.5 ? -0.12 * n : 0.06 * n;
165
- t.beginPath(), t.moveTo(u.x + l - 0.12 * n, a), t.quadraticCurveTo(u.x + l, a + P, u.x + l + 0.12 * n, a), t.stroke();
564
+ e.fillStyle = o, e.strokeStyle = o, e.lineWidth = i;
565
+ for (const m of p) {
566
+ const S = Lt(m.open, t.blink);
567
+ if (S < 0.2) {
568
+ const w = t.smile > 0.5 ? -0.12 * n : 0.06 * n;
569
+ e.beginPath(), e.moveTo(m.x + h - 0.12 * n, a), e.quadraticCurveTo(m.x + h, a + w, m.x + h + 0.12 * n, a), e.stroke();
166
570
  } else {
167
- if (k > 1.2) {
168
- const S = 0.13 * n * k;
169
- t.beginPath(), t.ellipse(u.x + l, a, S * 0.85, S, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = r;
571
+ if (S > 1.2) {
572
+ const E = 0.13 * n * S;
573
+ e.beginPath(), e.ellipse(m.x + h, a, E * 0.85, E, 0, 0, Math.PI * 2), e.fillStyle = "#ffffff", e.fill(), e.stroke(), e.fillStyle = o;
170
574
  }
171
- const P = k > 1.2 ? 0.075 * n : 0.1 * n;
172
- t.beginPath(), t.ellipse(u.x + c, a + g, P, P * 1.1 * Math.min(k, 1), 0, 0, Math.PI * 2), t.fill();
575
+ const w = S > 1.2 ? 0.075 * n : 0.1 * n;
576
+ e.beginPath(), e.ellipse(m.x + f, a + u, w, w * 1.1 * Math.min(S, 1), 0, 0, Math.PI * 2), e.fill();
173
577
  }
174
- const E = ne(a, n, u.brow, k), b = u.x + l - u.side * 0.13 * n * u.squeeze, M = u.x + l + u.side * 0.13 * n * u.squeeze;
175
- t.beginPath(), t.moveTo(M, E), t.lineTo(b, E - e.browTilt * 0.1 * n), t.stroke();
578
+ const k = Nt(a, n, m.brow, S), T = m.x + h - m.side * 0.13 * n * m.squeeze, H = m.x + h + m.side * 0.13 * n * m.squeeze;
579
+ e.beginPath(), e.moveTo(H, k), e.lineTo(T, k - t.browTilt * 0.1 * n), e.stroke();
176
580
  }
177
- const f = o + te * n, d = 0.25 * n * Math.max(0.3, e.mouthWidth) * (1 - Oe * i), w = Math.min(1, Math.max(0, e.mouth));
178
- if (t.beginPath(), w <= 0.05) {
179
- t.moveTo(l - d, f), t.quadraticCurveTo(l, f + e.smile * 0.25 * n, l + d, f), t.stroke();
581
+ const c = r + Yt * n, g = 0.25 * n * Math.max(0.3, t.mouthWidth) * (1 - Ln * s), d = Math.min(1, Math.max(0, t.mouth));
582
+ if (e.beginPath(), d <= 0.05) {
583
+ e.moveTo(h - g, c), e.quadraticCurveTo(h, c + t.smile * 0.25 * n, h + g, c), e.stroke();
180
584
  return;
181
585
  }
182
- const m = 0.3 * n * w;
183
- e.smile > 0.3 ? (t.moveTo(l - d, f - 0.05 * n), t.lineTo(l + d, f - 0.05 * n), t.quadraticCurveTo(l, f + m * 2, l - d, f - 0.05 * n)) : e.smile < -0.3 ? (t.moveTo(l - d, f + m * 0.6), t.lineTo(l + d, f + m * 0.6), t.quadraticCurveTo(l, f - m * 1.4, l - d, f + m * 0.6)) : t.ellipse(l, f, d * 0.8, m, 0, 0, Math.PI * 2), t.fill();
184
- }
185
- function oe(t, e) {
186
- const n = e.height ?? 300, o = Math.min(3, Math.max(0.3, t.stretch ?? 1)), r = Math.sqrt(o), s = (e.headSize ?? 2 * Zt) / 2, h = e.headSize === void 0 ? Se : 1 - 2 * s, i = s * n, l = J(t.sit), a = t.leftHip + (-ot - t.leftHip) * l, c = t.leftKnee + (-ot - t.leftKnee) * l, g = t.rightHip + (ot - t.rightHip) * l, y = t.rightKnee + (ot - t.rightKnee) * l, f = e.classic === !0, d = J(t.turn), w = (x, p, T) => {
187
- const v = C(p - T) / 2, O = d + (1 - d) * x * _e;
188
- return f ? { x: 0, y: 0 } : { x: Math.cos(v) * Ft * O, y: Math.abs(Math.sin(v)) * Ft };
189
- };
190
- let m = 0;
191
- if (l > 0 || !f) {
192
- const x = (v, O, A) => Pt * Math.cos(C(O)) + ct * Math.cos(C(O - A)) + w(v, O, A).y, p = Math.max(x(-1, a, c), x(1, g, y)), T = f ? Math.min(1, l / Ne) : 1;
193
- m = ($t - p) * T * n * o;
586
+ const b = 0.3 * n * d;
587
+ t.smile > 0.3 ? (e.moveTo(h - g, c - 0.05 * n), e.lineTo(h + g, c - 0.05 * n), e.quadraticCurveTo(h, c + b * 2, h - g, c - 0.05 * n)) : t.smile < -0.3 ? (e.moveTo(h - g, c + b * 0.6), e.lineTo(h + g, c + b * 0.6), e.quadraticCurveTo(h, c - b * 1.4, h - g, c + b * 0.6)) : e.ellipse(h, c, g * 0.8, b, 0, 0, Math.PI * 2), e.fill();
588
+ }
589
+ function Ct(e, t) {
590
+ const n = t.height ?? 300, r = Math.min(3, Math.max(0.3, e.stretch ?? 1)), o = Math.sqrt(r), l = (t.headSize ?? 2 * Bt) / 2, i = t.headSize === void 0 ? $n : 1 - 2 * l, s = l * n, h = se(e.sit), a = e.leftHip + (-ye - e.leftHip) * h, f = e.leftKnee + (-ye - e.leftKnee) * h, u = e.rightHip + (ye - e.rightHip) * h, p = e.rightKnee + (ye - e.rightKnee) * h, c = t.classic === !0, g = se(e.turn), d = (K, P, $, B, F) => {
591
+ const C = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, Math.abs(Z(P - $) / 2) + Z(B))), L = Math.max(-1, Math.min(1, qn + F)), Q = g + (1 - g) * K * L;
592
+ return c ? { x: 0, y: 0 } : { x: Math.cos(C) * St * Q, y: Math.sin(C) * St };
593
+ }, b = { left: e.leftAnkle ?? 0, right: e.rightAnkle ?? 0 }, m = { left: e.leftFootOut ?? 0, right: e.rightFootOut ?? 0 };
594
+ let S = 0;
595
+ if (h > 0 || !c) {
596
+ const K = (F, C, L, Q, ne) => je * Math.cos(Z(C)) + Ke * Math.cos(Z(C - L)) + Math.max(0, d(F, C, L, Q, ne).y), P = Math.max(
597
+ K(-1, a, f, b.left, m.left),
598
+ K(1, u, p, b.right, m.right)
599
+ ), $ = 1 - se((e.rise ?? 0) / Qn), B = (c ? Math.min(1, h / jn) : 1) * $;
600
+ S = (mt - P) * B * n * r;
194
601
  }
195
- const u = -$t * n * o + m, k = -h * n * o + m, E = f ? 0 : (Be * J(t.turn) + Re * l) * n * o, b = E === 0 ? [{ x: 0, y: u }, { x: 0, y: k }] : z({ x: 0, y: u }, { x: -E, y: (u + k) / 2 }, { x: 0, y: k }, 1, 8), M = k + Pe * n * o, P = (e.shoulderWidth ?? 0) * n * Math.cos(d * Math.PI / 2), S = (x, p, T, v, O) => {
196
- const A = Xe(T, v);
197
- return { x: x + A.x * O * n, y: p + A.y * O * n };
198
- }, W = (x, p, T) => {
199
- const v = S(0, u, p, x, Pt * o);
200
- return { root: { x: 0, y: u }, joint: v, end: S(v.x, v.y, p - T, x, ct * o) };
201
- }, H = (x, p, T) => {
202
- const v = { x: x * P, y: M }, O = S(v.x, v.y, p, x, Te * r);
203
- return { root: v, joint: O, end: S(O.x, O.y, p + T, x, ve * r) };
204
- }, Y = { left: W(-1, a, c), right: W(1, g, y) }, I = (x, p, T, v) => {
205
- const O = w(x, T, v);
206
- return { x: p.end.x + O.x * n * o, y: p.end.y + O.y * n * o };
602
+ const k = -mt * n * r + S, T = -i * n * r + S, H = c ? 0 : (zn * se(e.turn) + Gn * h) * n * r, w = H === 0 ? [{ x: 0, y: k }, { x: 0, y: T }] : fe({ x: 0, y: k }, { x: -H, y: (k + T) / 2 }, { x: 0, y: T }, 1, 8), E = T + Fn * n * r, v = (t.shoulderWidth ?? 0) * n * Math.cos(g * Math.PI / 2), A = (K, P, $, B, F) => {
603
+ const C = Vn($, B);
604
+ return { x: K + C.x * F * n, y: P + C.y * F * n };
605
+ }, I = (K, P, $) => {
606
+ const B = A(0, k, P, K, je * r);
607
+ return { root: { x: 0, y: k }, joint: B, end: A(B.x, B.y, P - $, K, Ke * r) };
608
+ }, W = (K, P, $) => {
609
+ const B = { x: K * v, y: E }, F = A(B.x, B.y, P, K, _n * o);
610
+ return { root: B, joint: F, end: A(F.x, F.y, P + $, K, Rn * o) };
611
+ }, M = { left: I(-1, a, f), right: I(1, u, p) }, y = (K, P, $, B, F, C) => {
612
+ const L = d(K, $, B, F, C);
613
+ return { x: P.end.x + L.x * n * r, y: P.end.y + L.y * n * r };
614
+ }, x = (K, P, $, B, F) => A(P.end.x, P.end.y, $ + B + F, K, _t * o), O = {
615
+ left: W(-1, e.leftShoulder, e.leftElbow),
616
+ right: W(1, e.rightShoulder, e.rightElbow)
207
617
  };
208
618
  return {
209
619
  height: n,
210
- facing: (e.facing ?? 1) < 0 ? -1 : 1,
211
- stretch: o,
212
- lineWidth: e.lineWidth ?? n * 0.025,
213
- rubber: Math.min(1, Math.max(f ? 0 : $e, e.rubber ?? 0)),
214
- r: i,
620
+ facing: (t.facing ?? 1) < 0 ? -1 : 1,
621
+ stretch: r,
622
+ lineWidth: t.lineWidth ?? n * 0.025,
623
+ rubber: Math.min(1, Math.max(c ? 0 : Un, t.rubber ?? 0)),
624
+ r: s,
215
625
  // The head keeps its area: taller and narrower when stretched.
216
- headRx: i / Math.sqrt(o),
217
- headRy: i * Math.sqrt(o),
218
- hipY: u,
219
- neckY: k,
220
- drop: m,
221
- lean: f ? t.lean : t.lean + Le * Math.sin(Math.PI * l),
222
- classic: f,
223
- legs: Y,
224
- toes: { left: I(-1, Y.left, a, c), right: I(1, Y.right, g, y) },
225
- spine: b,
226
- arms: {
227
- left: H(-1, t.leftShoulder, t.leftElbow),
228
- right: H(1, t.rightShoulder, t.rightElbow)
626
+ headRx: s / Math.sqrt(r),
627
+ headRy: s * Math.sqrt(r),
628
+ hipY: k,
629
+ neckY: T,
630
+ drop: S,
631
+ lean: c ? e.lean : e.lean + Jn * Math.sin(Math.PI * h),
632
+ classic: c,
633
+ legs: M,
634
+ toes: {
635
+ left: y(-1, M.left, a, f, b.left, m.left),
636
+ right: y(1, M.right, u, p, b.right, m.right)
637
+ },
638
+ spine: w,
639
+ arms: O,
640
+ handTips: {
641
+ left: x(-1, O.left, e.leftShoulder, e.leftElbow, e.leftWrist ?? 0),
642
+ right: x(1, O.right, e.rightShoulder, e.rightElbow, e.rightWrist ?? 0)
229
643
  }
230
644
  };
231
645
  }
232
- const V = (t, e) => e === 0 ? [t.root, t.joint, t.end] : z(t.root, t.joint, t.end, e);
233
- function vt(t, e, n) {
234
- const o = Math.cos(n), r = Math.sin(n), s = t.x - e.x, h = t.y - e.y;
235
- return { x: e.x + s * o - h * r, y: e.y + s * r + h * o };
646
+ const ge = (e, t) => t === 0 ? [e.root, e.joint, e.end] : fe(e.root, e.joint, e.end, t);
647
+ function Pe(e, t, n) {
648
+ const r = Math.cos(n), o = Math.sin(n), l = e.x - t.x, i = e.y - t.y;
649
+ return { x: t.x + l * r - i * o, y: t.y + l * o + i * r };
650
+ }
651
+ function Dt(e, t, n = !0) {
652
+ const r = no(e, t), o = t.spin ?? 0, l = t.rise ?? 0;
653
+ return n && (o !== 0 || l !== 0) ? to(r, e, o, l) : r;
654
+ }
655
+ function qt(e, t, n) {
656
+ return { pivot: { x: 0, y: e.hipY }, angle: e.facing * Z(t), lift: n * e.height };
236
657
  }
237
- function se(t, e) {
238
- const n = C(t.lean), o = C(e.headTilt), r = { x: 0, y: t.hipY }, s = (u) => ({ x: t.facing * u.x, y: u.y }), h = (u) => s(vt(u, r, n)), i = (u) => h(vt({ x: u.x, y: u.y + t.neckY }, { x: 0, y: t.neckY }, o)), l = V(t.arms.left, t.rubber).map(h), a = V(t.arms.right, t.rubber).map(h), c = (u) => {
239
- const [k, E] = u.slice(-2);
240
- return Math.atan2(E.y - k.y, E.x - k.x);
658
+ function to(e, t, n, r) {
659
+ const { pivot: o, angle: l, lift: i } = qt(t, n, r), s = (p) => {
660
+ const c = Pe(p, o, l);
661
+ return { x: c.x, y: c.y - i };
662
+ }, h = (p) => ({ left: s(p.left), right: s(p.right) }), a = { left: Math.max(s(e.feet.left).y, s(e.toes.left).y), right: Math.max(s(e.feet.right).y, s(e.toes.right).y) }, f = Math.max(a.left, a.right), u = Rt * t.height;
663
+ return {
664
+ ...e,
665
+ hip: s(e.hip),
666
+ neck: s(e.neck),
667
+ shoulders: h(e.shoulders),
668
+ elbows: h(e.elbows),
669
+ hands: h(e.hands),
670
+ fingertips: h(e.fingertips),
671
+ knees: h(e.knees),
672
+ feet: h(e.feet),
673
+ toes: h(e.toes),
674
+ feetY: f,
675
+ grounded: { left: a.left >= f - u, right: a.right >= f - u },
676
+ handAngle: { left: e.handAngle.left + l, right: e.handAngle.right + l },
677
+ limbs: {
678
+ leftArm: e.limbs.leftArm.map(s),
679
+ rightArm: e.limbs.rightArm.map(s),
680
+ leftLeg: e.limbs.leftLeg.map(s),
681
+ rightLeg: e.limbs.rightLeg.map(s),
682
+ spine: e.limbs.spine.map(s)
683
+ },
684
+ head: { ...e.head, center: s(e.head.center), angle: e.head.angle + l }
241
685
  };
242
- let g = 1 / 0;
243
- for (const [u, k] of [
244
- [e.leftBrow, e.leftEye],
245
- [e.rightBrow, e.rightEye]
686
+ }
687
+ function no(e, t) {
688
+ const n = Z(e.lean), r = Z(t.headTilt), o = { x: 0, y: e.hipY }, l = (k) => ({ x: e.facing * k.x, y: k.y }), i = (k) => l(Pe(k, o, n)), s = (k) => i(Pe({ x: k.x, y: k.y + e.neckY }, { x: 0, y: e.neckY }, r)), h = ge(e.arms.left, e.rubber).map(i), a = ge(e.arms.right, e.rubber).map(i), f = (k, T) => Math.atan2(T.y - k.y, T.x - k.x), u = { left: i(e.handTips.left), right: i(e.handTips.right) }, p = (k, T) => {
689
+ const [H, w] = k.slice(-2), E = e.arms[T], v = f(i(E.end), u[T]) - f(i(E.joint), i(E.end));
690
+ return f(H, w) + v;
691
+ };
692
+ let c = 1 / 0;
693
+ for (const [k, T] of [
694
+ [t.leftBrow, t.leftEye],
695
+ [t.rightBrow, t.rightEye]
246
696
  ]) {
247
- const E = ne(Tt, 1, u, ee(k, e.blink));
248
- g = Math.min(g, E, E - e.browTilt * 0.1);
697
+ const H = Nt(Qe, 1, k, Lt(T, t.blink));
698
+ c = Math.min(c, H, H - t.browTilt * 0.1);
249
699
  }
250
- const y = { left: s(t.legs.left.end), right: s(t.legs.right.end) }, f = { left: s(t.toes.left), right: s(t.toes.right) }, d = { left: Math.max(y.left.y, f.left.y), right: Math.max(y.right.y, f.right.y) }, w = Math.max(d.left, d.right), m = Ce * t.height;
700
+ const g = { left: l(e.legs.left.end), right: l(e.legs.right.end) }, d = { left: l(e.toes.left), right: l(e.toes.right) }, b = { left: Math.max(g.left.y, d.left.y), right: Math.max(g.right.y, d.right.y) }, m = Math.max(b.left, b.right), S = Rt * e.height;
251
701
  return {
252
- facing: t.facing,
253
- height: t.height,
254
- stretch: t.stretch,
255
- lineWidth: t.lineWidth,
256
- hip: r,
257
- neck: h({ x: 0, y: t.neckY }),
258
- shoulders: { left: h(t.arms.left.root), right: h(t.arms.right.root) },
259
- elbows: { left: h(t.arms.left.joint), right: h(t.arms.right.joint) },
260
- hands: { left: h(t.arms.left.end), right: h(t.arms.right.end) },
261
- knees: { left: s(t.legs.left.joint), right: s(t.legs.right.joint) },
262
- feet: y,
263
- toes: f,
264
- feetY: w,
265
- grounded: { left: d.left >= w - m, right: d.right >= w - m },
266
- handAngle: { left: c(l), right: c(a) },
702
+ facing: e.facing,
703
+ height: e.height,
704
+ stretch: e.stretch,
705
+ lineWidth: e.lineWidth,
706
+ hip: o,
707
+ neck: i({ x: 0, y: e.neckY }),
708
+ shoulders: { left: i(e.arms.left.root), right: i(e.arms.right.root) },
709
+ elbows: { left: i(e.arms.left.joint), right: i(e.arms.right.joint) },
710
+ hands: { left: i(e.arms.left.end), right: i(e.arms.right.end) },
711
+ knees: { left: l(e.legs.left.joint), right: l(e.legs.right.joint) },
712
+ feet: g,
713
+ toes: d,
714
+ feetY: m,
715
+ grounded: { left: b.left >= m - S, right: b.right >= m - S },
716
+ fingertips: u,
717
+ handAngle: { left: p(h, "left"), right: p(a, "right") },
267
718
  limbs: {
268
- leftArm: l,
719
+ leftArm: h,
269
720
  rightArm: a,
270
- leftLeg: V(t.legs.left, t.rubber).map(s),
271
- rightLeg: V(t.legs.right, t.rubber).map(s),
272
- spine: t.spine.map(h)
721
+ leftLeg: ge(e.legs.left, e.rubber).map(l),
722
+ rightLeg: ge(e.legs.right, e.rubber).map(l),
723
+ spine: e.spine.map(i)
273
724
  },
274
725
  head: {
275
- center: i({ x: 0, y: -t.headRy }),
276
- rx: t.headRx,
277
- ry: t.headRy,
726
+ center: s({ x: 0, y: -e.headRy }),
727
+ rx: e.headRx,
728
+ ry: e.headRy,
278
729
  // Mirroring a turn reverses it.
279
- angle: t.facing * (n + o),
280
- eyeY: Tt,
281
- browTopY: g,
282
- mouthY: te,
283
- faceX: t.facing * (Qt + Vt * J(e.turn))
730
+ angle: e.facing * (n + r),
731
+ eyeY: Qe,
732
+ browTopY: c,
733
+ mouthY: Yt,
734
+ faceX: e.facing * ($t + Ft * se(t.turn))
284
735
  }
285
736
  };
286
737
  }
287
- function Ue(t, e = {}) {
288
- return se(oe(t, e), t);
738
+ function oo(e, t = {}) {
739
+ return Dt(Ct(e, t), e);
289
740
  }
290
- function Tn(t, e, n) {
291
- return vt({ x: t.center.x + e * t.rx, y: t.center.y + n * t.ry }, t.center, t.angle);
741
+ function Hr(e, t, n) {
742
+ return Pe({ x: e.center.x + t * e.rx, y: e.center.y + n * e.ry }, e.center, e.angle);
292
743
  }
293
- function Ke(t, e, n) {
294
- const o = (s) => ({ x: s.x + e, y: s.y + n }), r = (s) => ({ left: o(s.left), right: o(s.right) });
744
+ function ro(e, t, n) {
745
+ const r = (l) => ({ x: l.x + t, y: l.y + n }), o = (l) => ({ left: r(l.left), right: r(l.right) });
295
746
  return {
296
- ...t,
297
- hip: o(t.hip),
298
- neck: o(t.neck),
299
- shoulders: r(t.shoulders),
300
- elbows: r(t.elbows),
301
- hands: r(t.hands),
302
- knees: r(t.knees),
303
- feet: r(t.feet),
304
- toes: r(t.toes),
305
- feetY: t.feetY + n,
306
- grounded: { ...t.grounded },
307
- handAngle: { ...t.handAngle },
747
+ ...e,
748
+ hip: r(e.hip),
749
+ neck: r(e.neck),
750
+ shoulders: o(e.shoulders),
751
+ elbows: o(e.elbows),
752
+ hands: o(e.hands),
753
+ knees: o(e.knees),
754
+ feet: o(e.feet),
755
+ toes: o(e.toes),
756
+ feetY: e.feetY + n,
757
+ grounded: { ...e.grounded },
758
+ handAngle: { ...e.handAngle },
308
759
  limbs: {
309
- leftArm: t.limbs.leftArm.map(o),
310
- rightArm: t.limbs.rightArm.map(o),
311
- leftLeg: t.limbs.leftLeg.map(o),
312
- rightLeg: t.limbs.rightLeg.map(o),
313
- spine: t.limbs.spine.map(o)
760
+ leftArm: e.limbs.leftArm.map(r),
761
+ rightArm: e.limbs.rightArm.map(r),
762
+ leftLeg: e.limbs.leftLeg.map(r),
763
+ rightLeg: e.limbs.rightLeg.map(r),
764
+ spine: e.limbs.spine.map(r)
314
765
  },
315
- head: { ...t.head, center: o(t.head.center) }
766
+ head: { ...e.head, center: r(e.head.center) }
316
767
  };
317
768
  }
318
- function De(t, e, n = {}, o = 0) {
319
- const r = oe(e, n), s = n.color ?? "#1e293b", h = n.layers ?? {}, i = n.layers ? se(r, e) : void 0, l = n.sketch ? xt(t, n.sketch, o) : void 0, a = n.sketch && n.layers ? xt(t, n.sketch, o) : void 0, c = (b) => {
320
- t.save(), b(), t.restore();
321
- }, g = (b) => {
322
- b && i && c(() => b(t, i, o, a));
323
- }, y = () => t.scale(r.facing, 1), f = () => {
324
- y(), t.translate(0, r.hipY), t.rotate(C(r.lean)), t.translate(0, -r.hipY);
325
- }, d = (b, M, P) => {
326
- if (l) return M ? l.curve(b) : l.line(b);
327
- if (r.classic) {
328
- t.beginPath(), t.moveTo(b[0].x, b[0].y);
329
- for (const S of b.slice(1)) t.lineTo(S.x, S.y);
330
- t.stroke();
769
+ function lo(e, t, n = {}, r = 0) {
770
+ const o = Ct(t, n), l = n.color ?? "#1e293b", i = n.layers ?? {}, s = n.layers ? Dt(o, t, !1) : void 0, h = n.sketch ? Ue(e, n.sketch, r) : void 0, a = n.sketch && n.layers ? Ue(e, n.sketch, r) : void 0, f = (w) => {
771
+ e.save(), w(), e.restore();
772
+ }, u = (w) => {
773
+ w && s && f(() => w(e, s, r, a));
774
+ }, p = () => e.scale(o.facing, 1), c = () => {
775
+ p(), e.translate(0, o.hipY), e.rotate(Z(o.lean)), e.translate(0, -o.hipY);
776
+ }, g = (w, E, v) => {
777
+ if (h) return E ? h.curve(w) : h.line(w);
778
+ if (o.classic) {
779
+ e.beginPath(), e.moveTo(w[0].x, w[0].y);
780
+ for (const A of w.slice(1)) e.lineTo(A.x, A.y);
781
+ e.stroke();
331
782
  return;
332
783
  }
333
- Jt(t, b, P[0] * r.lineWidth, P[1] * r.lineWidth);
334
- }, w = (b, M) => d(V(b, r.rubber), r.rubber > 0, M), m = (b) => {
335
- r.classic || d([r.legs[b].end, r.toes[b]], !1, He);
336
- }, u = (b) => {
337
- if (r.classic || l) return;
338
- const M = r.arms[b].end;
339
- t.beginPath(), t.arc(M.x, M.y, Ye * r.lineWidth, 0, Math.PI * 2), t.fill();
784
+ ot(e, w, v[0] * o.lineWidth, v[1] * o.lineWidth);
785
+ }, d = (w, E) => g(ge(w, o.rubber), o.rubber > 0, E), b = (w) => {
786
+ o.classic || g([o.legs[w].end, o.toes[w]], !1, Dn);
787
+ }, m = (w) => {
788
+ if (n.hands && !o.classic) return k(w);
789
+ if (o.classic || h) return;
790
+ const E = o.arms[w].end;
791
+ e.beginPath(), e.arc(E.x, E.y, Xn * o.lineWidth, 0, Math.PI * 2), e.fill();
340
792
  };
341
- t.save(), t.strokeStyle = s, t.fillStyle = s, t.lineWidth = r.lineWidth, t.lineCap = "round", t.lineJoin = "round";
342
- const k = (b) => {
343
- c(() => {
344
- f(), w(r.arms[b], Ae), u(b);
793
+ e.save(), e.strokeStyle = l, e.fillStyle = l, e.lineWidth = o.lineWidth, e.lineCap = "round", e.lineJoin = "round";
794
+ const S = qt(o, t.spin ?? 0, t.rise ?? 0);
795
+ (S.angle !== 0 || S.lift !== 0) && (e.translate(0, -S.lift), e.translate(S.pivot.x, S.pivot.y), e.rotate(S.angle), e.translate(-S.pivot.x, -S.pivot.y));
796
+ function k(w) {
797
+ const E = n.hands ?? {}, v = o.arms[w].end, A = o.handTips[w], I = n.headFill ?? "#ffffff";
798
+ rt(e, v, E[w] ?? R, {
799
+ side: w,
800
+ // Degrees clockwise from straight up, in the frame the hand is drawn in.
801
+ angle: Math.atan2(A.x - v.x, v.y - A.y) * 180 / Math.PI,
802
+ size: (E.size ?? _t) * o.height * Math.sqrt(o.stretch),
803
+ skin: E.skin ?? (I === "none" ? void 0 : I),
804
+ ink: l,
805
+ lineWidth: o.lineWidth * 0.45,
806
+ fingers: E.fingers,
807
+ plump: E.plump,
808
+ look: n.sketch ? "pencil" : "clean",
809
+ seed: n.sketch?.seed
810
+ }, r);
811
+ }
812
+ const T = (w) => {
813
+ f(() => {
814
+ c(), d(o.arms[w], Cn), m(w);
345
815
  });
346
- const M = h.sleeve;
347
- M && i && c(() => M(t, i, b, o, a));
348
- }, E = J(e.turn) > Fe;
349
- g(h.behind), c(() => {
350
- y(), w(r.legs.left, Lt), m("left"), w(r.legs.right, Lt), m("right");
351
- }), E && k("left"), c(() => {
352
- f(), d(r.spine, r.spine.length > 2, Ie);
353
- const { left: b, right: M } = { left: r.arms.left.root, right: r.arms.right.root };
354
- if (b.x !== M.x)
355
- if (r.classic) d([b, M], !1, [1, 1]);
816
+ const E = i.sleeve;
817
+ E && s && f(() => E(e, s, w, r, a));
818
+ }, H = se(t.turn) > Zn;
819
+ u(i.behind), f(() => {
820
+ p(), d(o.legs.left, kt), b("left"), d(o.legs.right, kt), b("right");
821
+ }), H && T("left"), f(() => {
822
+ c(), g(o.spine, o.spine.length > 2, Nn);
823
+ const { left: w, right: E } = { left: o.arms.left.root, right: o.arms.right.root };
824
+ if (w.x !== E.x)
825
+ if (o.classic) g([w, E], !1, [1, 1]);
356
826
  else {
357
- const P = { x: (b.x + M.x) / 2, y: b.y - 0.3 * Math.abs(M.x - b.x) };
358
- d(z(b, P, M, 1, 8), !0, [1.1, 1.1]);
827
+ const v = { x: (w.x + E.x) / 2, y: w.y - 0.3 * Math.abs(E.x - w.x) };
828
+ g(fe(w, v, E, 1, 8), !0, [1.1, 1.1]);
359
829
  }
360
- }), g(h.body), E || k("left"), k("right"), g(h.behindHead), c(() => {
361
- f(), t.translate(0, r.neckY), t.rotate(C(e.headTilt));
362
- const b = -r.headRy;
363
- t.beginPath(), t.ellipse(0, b, r.headRx, r.headRy, 0, 0, Math.PI * 2);
364
- const M = n.headFill ?? "#ffffff";
365
- if (M !== "none" && (t.fillStyle = M, t.fill()), l) {
366
- l.ellipse(0, b, r.headRx, r.headRy);
367
- const P = l.nudge();
368
- t.translate(P.x, P.y);
830
+ }), u(i.body), H || T("left"), T("right"), u(i.behindHead), f(() => {
831
+ c(), e.translate(0, o.neckY), e.rotate(Z(t.headTilt));
832
+ const w = -o.headRy;
833
+ e.beginPath(), e.ellipse(0, w, o.headRx, o.headRy, 0, 0, Math.PI * 2);
834
+ const E = n.headFill ?? "#ffffff";
835
+ if (E !== "none" && (e.fillStyle = E, e.fill()), h) {
836
+ h.ellipse(0, w, o.headRx, o.headRy);
837
+ const v = h.nudge();
838
+ e.translate(v.x, v.y);
369
839
  } else
370
- t.stroke();
371
- t.translate(0, b), t.scale(r.headRx / r.r, r.headRy / r.r), qe(t, e, r.r, 0, s, r.lineWidth);
372
- }), g(h.overHead), g(h.front), t.restore(), n.label && (t.save(), t.fillStyle = s, t.font = n.labelFont ?? `700 ${Math.round(r.height * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(n.label, 0, -r.height * r.stretch - 0.04 * r.height + r.drop), t.restore());
373
- }
374
- function re(t, e) {
375
- const n = { ...t };
376
- let o = t.walking > 0 ? Me(n, Ee(t.walk, n), t.walking) : n;
377
- return t.talk > 0 && (o = { ...o, mouth: Math.max(o.mouth, t.talk * xe(e)) }), o;
378
- }
379
- function vn(t) {
380
- const e = t.style ?? {}, n = e.height ?? 300, o = n * 0.8, r = { ...B(t.pose ?? {}), walk: 0, walking: 0, talk: 0, rubber: e.rubber ?? 0 };
840
+ e.stroke();
841
+ e.translate(0, w), e.scale(o.headRx / o.r, o.headRy / o.r), eo(e, t, o.r, 0, l, o.lineWidth);
842
+ }), u(i.overHead), u(i.front), e.restore(), n.label && (e.save(), e.fillStyle = l, e.font = n.labelFont ?? `700 ${Math.round(o.height * 0.11)}px sans-serif`, e.textAlign = "center", e.textBaseline = "bottom", e.fillText(n.label, 0, -o.height * o.stretch - 0.04 * o.height + o.drop), e.restore());
843
+ }
844
+ function Xt(e, t, n) {
845
+ const r = { ...e };
846
+ let o = e.walking > 0 ? me(r, In(e.walk, r), e.walking) : r, l = io(e);
847
+ const i = e.dancing ?? 0;
848
+ if (n && i > 0) {
849
+ const s = n(e.beat ?? 0);
850
+ if (o = me(o, s.pose, i), s.hands) {
851
+ const h = (a, f) => f ? be(a ?? R, f, i) : a;
852
+ l = { left: h(l?.left, s.hands.left), right: h(l?.right, s.hands.right) };
853
+ }
854
+ }
855
+ return e.talk > 0 && (o = { ...o, mouth: Math.max(o.mouth, e.talk * Bn(t)) }), { pose: o, hands: l };
856
+ }
857
+ function so(e, t, n) {
858
+ return Xt(e, t, n).pose;
859
+ }
860
+ const We = (e, t) => `hand.${e}.${t}`;
861
+ function io(e) {
862
+ const t = (o) => {
863
+ if (typeof e[We(o, "spread")] == "number")
864
+ return Object.fromEntries(Object.keys(R).map((l) => [l, e[We(o, l)]]));
865
+ }, n = t("left"), r = t("right");
866
+ return n || r ? { left: n, right: r } : void 0;
867
+ }
868
+ function ho(e, t) {
869
+ return !t || !e.hands ? e : { ...e, hands: { ...e.hands, left: t.left ?? e.hands.left, right: t.right ?? e.hands.right } };
870
+ }
871
+ function Mr(e) {
872
+ const t = e.style ?? {}, n = t.height ?? 300, r = n * 0.8, o = { ...D(e.pose ?? {}), walk: 0, walking: 0, talk: 0, rubber: t.rubber ?? 0, beat: 0, dancing: 0 }, l = {};
873
+ if (t.hands)
874
+ for (const i of ["left", "right"]) {
875
+ const s = t.hands[i] ?? R;
876
+ for (const h of Object.keys(R)) l[We(i, h)] = s[h] ?? R[h];
877
+ }
381
878
  return {
382
879
  type: "custom",
383
- x: t.x - o / 2,
384
- y: t.y - n,
385
- width: o,
880
+ x: e.x - r / 2,
881
+ y: e.y - n,
882
+ width: r,
386
883
  height: n,
387
- props: { ...r },
388
- figureStyle: e,
389
- draw(s, h, i) {
390
- const l = h.props;
391
- s.translate(o / 2, n), De(s, re(l, i), { ...e, rubber: l.rubber }, i);
884
+ props: { ...o, ...l },
885
+ figureStyle: t,
886
+ figureDance: e.dance,
887
+ draw(i, s, h) {
888
+ const a = s.props, f = Xt(a, h, e.dance);
889
+ i.translate(r / 2, n), lo(i, f.pose, ho({ ...t, rubber: a.rubber }, f.hands), h);
392
890
  }
393
891
  };
394
892
  }
395
- function Wn(t, e, n) {
396
- const o = t.figureStyle;
397
- if (!o) throw new Error("stickFigureAt: the target was not made by stickFigureTarget");
398
- const r = { ...t.props };
399
- let s = 0, h = 0;
400
- for (const [a, c] of e.state?.values.get(n) ?? [])
401
- typeof c == "number" && (a === "x" || a === "motionPathX" ? s = c : a === "y" || a === "motionPathY" ? h = c : a in r && (r[a] = c));
402
- const i = re(r, e.time), l = Ue(i, { ...o, rubber: r.rubber });
403
- return { pose: i, joints: Ke(l, t.x + s + t.width / 2, t.y + h + t.height) };
404
- }
405
- function On(t, e) {
893
+ function Tr(e, t, n) {
894
+ const r = e.figureStyle;
895
+ if (!r) throw new Error("stickFigureAt: the target was not made by stickFigureTarget");
896
+ const o = { ...e.props };
897
+ let l = 0, i = 0;
898
+ for (const [a, f] of t.state?.values.get(n) ?? [])
899
+ typeof f == "number" && (a === "x" || a === "motionPathX" ? l = f : a === "y" || a === "motionPathY" ? i = f : a in o && (o[a] = f));
900
+ const s = so(o, t.time, e.figureDance), h = oo(s, { ...r, rubber: o.rubber });
901
+ return { pose: s, joints: ro(h, e.x + l + e.width / 2, e.y + i + e.height) };
902
+ }
903
+ function vr(e, t) {
406
904
  const n = [];
407
- return e.forEach((o, r) => {
408
- const s = r === 0 ? G : n[r - 1], h = typeof o.pose == "string" ? be[o.pose] : { ...s, ...o.pose };
409
- n.push(o.expression ? we(h, o.expression) : h);
410
- }), Gt.filter((o) => n.some((r) => r[o] !== G[o])).map((o) => ({
411
- id: `${t}-${o}`,
412
- target: t,
413
- property: o,
414
- keyframes: e.map((r, s) => ({
415
- time: r.time,
416
- value: n[s][o],
417
- ...r.easing ? { easing: r.easing } : {}
905
+ return t.forEach((r, o) => {
906
+ const l = o === 0 ? z : n[o - 1], i = typeof r.pose == "string" ? Wn[r.pose] : { ...l, ...r.pose };
907
+ n.push(r.expression ? Ot(i, r.expression) : i);
908
+ }), It.filter((r) => n.some((o) => o[r] !== z[r])).map((r) => ({
909
+ id: `${e}-${r}`,
910
+ target: e,
911
+ property: r,
912
+ keyframes: t.map((o, l) => ({
913
+ time: o.time,
914
+ value: n[l][r],
915
+ ...o.easing ? { easing: o.easing } : {}
418
916
  }))
419
917
  }));
420
918
  }
421
- function je(t, e, n = {}, o) {
422
- const r = n.length ?? 240, s = 9, h = 28, i = r - 22;
423
- t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -30) * Math.PI / 180), t.fillStyle = n.color ?? "#f4c542", t.fillRect(h, -s, i - h, 2 * s), t.fillStyle = "#e8b4a0", t.fillRect(i, -s, r - i, 2 * s), t.fillStyle = "#f1dcbf", t.beginPath(), t.moveTo(0, 0), t.lineTo(h, -s), t.lineTo(h, s), t.closePath(), t.fill(), t.fillStyle = n.outline ?? "#2f2f33", t.beginPath(), t.moveTo(0, 0), t.lineTo(h * 0.35, -s * 0.35), t.lineTo(h * 0.35, s * 0.35), t.closePath(), t.fill(), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round", t.lineCap = "round";
424
- const l = [
425
- [{ x: 0, y: 0 }, { x: h, y: -s }, { x: r, y: -s }, { x: r, y: s }, { x: h, y: s }, { x: 0, y: 0 }],
426
- [{ x: h, y: -s }, { x: h, y: s }],
427
- [{ x: i, y: -s }, { x: i, y: s }]
428
- ];
429
- for (const a of l) he(t, a, o);
430
- t.restore();
431
- }
432
- function ie(t, e, n = {}, o) {
433
- const r = n.length ?? 90, s = n.thickness ?? 34;
434
- t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -35) * Math.PI / 180);
435
- const h = -s / 2;
436
- t.fillStyle = n.color ?? "#f4a7b9", t.fillRect(0, h, r, s), t.fillStyle = "#e9edf2", t.fillRect(r * 0.45, h, r * 0.55, s), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round";
437
- const i = [
438
- { x: 0, y: h },
439
- { x: r, y: h },
440
- { x: r, y: -h },
441
- { x: 0, y: -h },
442
- { x: 0, y: h }
443
- ], l = [{ x: r * 0.45, y: h }, { x: r * 0.45, y: -h }];
444
- if (o)
445
- o.line(i), o.line(l);
446
- else
447
- for (const a of [i, l]) {
448
- t.beginPath(), t.moveTo(a[0].x, a[0].y);
449
- for (const c of a.slice(1)) t.lineTo(c.x, c.y);
450
- t.stroke();
451
- }
452
- t.restore();
453
- }
454
- function le(t, e, n = {}, o) {
455
- const r = n.tool ?? "pencil", s = n.skin ?? "#f1c9a5", h = n.outline ?? "#2f2f33", i = r === "eraser" ? 17 : 9, l = r === "eraser" ? -40 : 0, a = o ? o.nudge(0.6) : { x: 0, y: 0 };
456
- t.save(), t.translate(e.x + a.x, e.y + a.y), t.rotate((n.angle ?? -30) * Math.PI / 180), t.scale(n.scale ?? 1, n.scale ?? 1), t.lineCap = "round", t.lineJoin = "round";
457
- const c = (f, d, w, m) => {
458
- for (const [u, k] of [
459
- [h, w + 6],
460
- [m, w]
461
- ])
462
- t.strokeStyle = u, t.lineWidth = k, t.beginPath(), t.moveTo(f.x, f.y), t.lineTo(d.x, d.y), t.stroke();
463
- };
464
- t.save(), t.translate(l, 0);
465
- const g = { x: 165, y: -i - 26 }, y = (f) => ({ x: g.x + f * 0.8, y: g.y + f * 0.6 });
466
- c(g, y(2e3), 64, s), c(y(110), y(2e3), 92, n.sleeve ?? "#5b7db1"), t.fillStyle = s, t.strokeStyle = h, t.lineWidth = 3, t.beginPath(), t.ellipse(g.x, g.y, 54, 40, 0.25, 0, Math.PI * 2), t.fill(), t.stroke(), t.restore(), r === "eraser" ? ie(t, { x: 0, y: 0 }, { angle: 0, outline: h }, o) : je(t, { x: 0, y: 0 }, { angle: 0, outline: h }, o), t.translate(l, 0), c({ x: 150, y: i + 8 }, { x: 92, y: i + 12 }, 22, s), c({ x: 140, y: -i - 18 }, { x: 58, y: -i - 6 }, 20, s), c({ x: 150, y: -i - 30 }, { x: 112, y: -i + 2 }, 20, s), c({ x: 172, y: -i - 30 }, { x: 140, y: -i + 4 }, 20, s), t.restore();
467
- }
468
- function In(t, e, n, o = 0.08, r = 32) {
469
- const s = Math.PI * 2 * (1 + o), h = [];
470
- for (let i = 0; i <= r; i++) {
471
- const l = -Math.PI / 2 + s * i / r;
472
- h.push({ x: t + Math.cos(l) * n, y: e + Math.sin(l) * n });
919
+ const Re = 0.5, Et = {
920
+ /** Flag: fingers together and straight, thumb bent in */
921
+ pataka: _({ "thumb.curl": 0.3, "thumb.across": 0.6, "index.curl": 0, "middle.curl": 0, "ring.curl": 0, "pinky.curl": 0, spread: 0, turn: 2 }),
922
+ /** Pataka with the ring finger bent */
923
+ tripataka: _({ "thumb.curl": 0.3, "thumb.across": 0.6, "index.curl": 0, "middle.curl": 0, "ring.curl": 1, "pinky.curl": 0, spread: 0, turn: 2 }),
924
+ /** Lotus in bloom: fingers fanned, each a little more curled than the last */
925
+ alapadma: _({ "thumb.curl": 0.1, "thumb.across": 0, "index.curl": 0.05, "middle.curl": 0.15, "ring.curl": 0.25, "pinky.curl": 0.35, spread: 1, turn: 2 }),
926
+ /** Fist */
927
+ mushti: N.fist,
928
+ /** Fist, thumb up */
929
+ shikhara: N.thumbsUp,
930
+ /** Swan's beak: thumb and index touch, the others fanned */
931
+ hamsasya: _({ "thumb.curl": 0.15, "thumb.across": 0.6, "index.curl": 0.6, "middle.curl": 0, "ring.curl": 0, "pinky.curl": 0, spread: 0.7, turn: 2 }),
932
+ /** Bracelet: thumb, index and middle meet, ring and little finger out */
933
+ katakamukha: _({ "thumb.curl": 0.2, "thumb.across": 0.6, "index.curl": 0.65, "middle.curl": 0.7, "ring.curl": 0, "pinky.curl": 0, spread: 0.4, turn: 2 })
934
+ };
935
+ function Oe(e) {
936
+ return typeof e != "string" ? e : e in Et ? Et[e] : N[e];
937
+ }
938
+ function ao(e, t, n) {
939
+ const r = [];
940
+ for (const o of e.keys) {
941
+ const l = r[r.length - 1], i = !l || o.reset ? { pose: t, ...n } : l;
942
+ r.push({
943
+ beat: o.beat,
944
+ pose: { ...i.pose, ...o.pose },
945
+ left: o.hands?.left ? Oe(o.hands.left) : i.left,
946
+ right: o.hands?.right ? Oe(o.hands.right) : i.right,
947
+ easing: o.easing ?? e.easing
948
+ });
473
949
  }
474
- return h;
475
- }
476
- function An(t) {
477
- const { path: e } = t, n = e.map((i) => i.x), o = e.map((i) => i.y), r = Math.min(...n), s = Math.min(...o), h = t.hand === !1 ? void 0 : t.hand === !0 || t.hand === void 0 ? {} : t.hand;
950
+ return r;
951
+ }
952
+ const lt = (e, t) => (e % t + t) % t;
953
+ function fo(e, t, n, r) {
954
+ const o = ao(e, n, r);
955
+ if (o.length === 0) return { pose: n, hands: r };
956
+ const l = lt(t, e.beats);
957
+ let i = o.length - 1;
958
+ for (let c = 0; c < o.length; c++) o[c].beat <= l && (i = c);
959
+ const s = o[i], h = o[(i + 1) % o.length], a = s.beat <= l ? s.beat : s.beat - e.beats, f = h.beat > a ? h.beat : h.beat + e.beats, u = f > a ? (l - a) / (f - a) : 0, p = nt(h.easing ?? "ease-in-out")(Math.min(1, Math.max(0, u)));
478
960
  return {
479
- type: "custom",
480
- x: r,
481
- y: s,
482
- width: Math.max(1, Math.max(...n) - r),
483
- height: Math.max(1, Math.max(...o) - s),
484
- props: { draw: 0 },
485
- draw(i, l, a) {
486
- const c = Math.min(1, Math.max(0, Number(l.props?.draw ?? 0)));
487
- i.translate(-r, -s), i.strokeStyle = t.color ?? "#2f2f33", i.lineWidth = t.lineWidth ?? 5, i.lineCap = "round", i.lineJoin = "round";
488
- const g = t.sketch ? xt(i, t.sketch, a) : void 0;
489
- c > 0 && (g ? t.smooth ? g.curve(e, c) : g.line(e, c) : he(i, Dt(e, c))), h && c > 0 && c < 1 && le(i, jt(e, c), h, g);
490
- }
961
+ pose: me(s.pose, h.pose, p),
962
+ hands: { left: be(s.left, h.left, p), right: be(s.right, h.right, p) }
491
963
  };
492
964
  }
493
- function he(t, e, n) {
494
- if (!(e.length < 2)) {
495
- if (n) return n.line(e);
496
- t.beginPath(), t.moveTo(e[0].x, e[0].y);
497
- for (const o of e.slice(1)) t.lineTo(o.x, o.y);
498
- t.stroke();
965
+ const co = [
966
+ ["leftShoulder", "rightShoulder"],
967
+ ["leftElbow", "rightElbow"],
968
+ ["leftWrist", "rightWrist"],
969
+ ["leftHip", "rightHip"],
970
+ ["leftKnee", "rightKnee"],
971
+ ["leftAnkle", "rightAnkle"],
972
+ ["leftFootOut", "rightFootOut"],
973
+ ["leftEye", "rightEye"],
974
+ ["leftBrow", "rightBrow"]
975
+ ], go = ["lean", "headTilt", "lookX", "spin"], uo = /* @__PURE__ */ new Set(["leftShoulder", "rightShoulder", "leftElbow", "rightElbow", "leftWrist", "rightWrist", "leftHip", "rightHip", "leftKnee", "rightKnee"]);
976
+ function po(e) {
977
+ const t = { ...e }, n = (e.turn ?? 0) >= 0.5;
978
+ for (const [r, o] of co) {
979
+ const l = n && uo.has(r) ? -1 : 1;
980
+ t[r] = l * e[o], t[o] = l * e[r];
499
981
  }
982
+ if (!n) for (const r of go) t[r] = -e[r];
983
+ return t;
500
984
  }
501
- const st = 1e5;
502
- function Hn(t, e, n, o, r = 6) {
503
- const s = [], h = Math.max(1, Math.round(r));
504
- for (let i = 0; i <= h; i++)
505
- s.push({ x: i % 2 === 0 ? t : t + n, y: e + o * i / h });
506
- return s;
507
- }
508
- function ae(t, e, n, o) {
509
- if (o <= 0 || e.length === 0) return;
510
- const r = Dt(e, o), s = n / 2, h = (i) => {
511
- t.beginPath(), t.rect(-st, -st, 2 * st, 2 * st), i(), t.clip("evenodd");
985
+ const bo = (e) => Math.min(1, Math.max(-1, (0.5 - e) * 4));
986
+ function mo(e, t, n) {
987
+ const r = lt(n, 1), o = (1 + Math.cos(2 * Math.PI * r)) / 2, l = t.bounce * (t.accent === "up" ? 1 - o : o), i = Math.min(1, Math.max(0, e.turn ?? 0)), s = bo(i);
988
+ return {
989
+ ...e,
990
+ leftHip: e.leftHip + s * l / 2,
991
+ rightHip: e.rightHip + l / 2,
992
+ leftKnee: e.leftKnee + s * l,
993
+ rightKnee: e.rightKnee + l,
994
+ lean: e.lean + (t.sway ?? 0) * (1 - i) * Math.sin(Math.PI * n)
512
995
  };
513
- for (const i of r)
514
- h(() => {
515
- t.moveTo(i.x + s, i.y), t.arc(i.x, i.y, s, 0, Math.PI * 2);
516
- });
517
- for (let i = 1; i < r.length; i++) {
518
- const l = r[i - 1], a = r[i], c = Math.hypot(a.x - l.x, a.y - l.y);
519
- if (c === 0) continue;
520
- const g = -(a.y - l.y) / c * s, y = (a.x - l.x) / c * s;
521
- h(() => {
522
- t.moveTo(l.x + g, l.y + y), t.lineTo(a.x + g, a.y + y), t.lineTo(a.x - g, a.y - y), t.lineTo(l.x - g, l.y - y), t.closePath();
523
- });
524
- }
525
996
  }
526
- function _n(t, e, n, o, r) {
527
- t.save(), ae(t, e, n, o), r(), t.restore();
997
+ function yo(e) {
998
+ const t = { ...z, ...e.stance };
999
+ return e.expression ? Ot(t, e.expression) : t;
528
1000
  }
529
- function Yn(t, e) {
530
- const n = e.width ?? 40, o = e.hand === !0 ? {} : e.hand || void 0, r = e.eraser === !1 ? void 0 : e.eraser === !0 || e.eraser === void 0 ? {} : e.eraser;
1001
+ function wo(e) {
531
1002
  return {
532
- ...t,
533
- props: { ...t.props, erase: 0 },
534
- draw(s, h, i) {
535
- const l = Number(h.props?.erase ?? 0);
536
- if (s.save(), ae(s, e.path, n, l), t.draw(s, h, i), s.restore(), !r || l <= 0 || l >= 1) return;
537
- const a = jt(e.path, l);
538
- o ? le(s, a, { ...o, tool: "eraser" }) : ie(s, a, r);
539
- }
1003
+ left: e.hands?.left ? Oe(e.hands.left) : R,
1004
+ right: e.hands?.right ? Oe(e.hands.right) : R
540
1005
  };
541
1006
  }
542
- const q = (t) => t * Math.PI / 180;
543
- function ce([t, e, n], o) {
544
- const r = Math.cos(o), s = Math.sin(o);
545
- return [t, e * r + n * s, -e * s + n * r];
1007
+ function Ye(e, t, n) {
1008
+ const r = e.moves[t.move];
1009
+ if (!r) throw new Error(`dance: "${e.label}" has no move "${t.move}"`);
1010
+ const o = fo(r, n, yo(e), wo(e));
1011
+ return t.mirror ? { pose: po(o.pose), hands: { left: o.hands?.right, right: o.hands?.left } } : o;
1012
+ }
1013
+ function st(e, t, n = {}) {
1014
+ const r = typeof e == "string" ? $e[e] : e;
1015
+ let o;
1016
+ if (n.move)
1017
+ o = Ye(r, { move: n.move, mirror: n.mirror }, t);
1018
+ else {
1019
+ const l = r.routine, i = l.reduce((u, p) => u + p.beats, 0), s = lt(t, i);
1020
+ let h = 0, a = 0;
1021
+ for (; a < l.length - 1 && s >= h + l[a].beats; ) h += l[a++].beats;
1022
+ const f = s - h;
1023
+ if (o = Ye(r, l[a], f), f < Re && l.length > 1 && t >= Re) {
1024
+ const u = l[(a - 1 + l.length) % l.length], p = Ye(r, u, u.beats + f), c = nt("ease-in-out")(f / Re);
1025
+ o = {
1026
+ pose: me(p.pose, o.pose, c),
1027
+ hands: { left: be(p.hands.left, o.hands.left, c), right: be(p.hands.right, o.hands.right, c) }
1028
+ };
1029
+ }
1030
+ }
1031
+ return { ...o, pose: mo(o.pose, r.groove, t) };
546
1032
  }
547
- function fe([t, e, n], o) {
548
- const r = Math.cos(o), s = Math.sin(o);
549
- return [t * r - e * s, t * s + e * r, n];
1033
+ function xr(e, t, n = {}) {
1034
+ return st(e, t, n).pose;
550
1035
  }
551
- function et([t, e, n], o) {
552
- const r = Math.cos(o), s = Math.sin(o);
553
- return [t * r + n * s, e, -t * s + n * r];
1036
+ function Ut(e) {
1037
+ return (typeof e == "string" ? $e[e] : e).routine.reduce((n, r) => n + r.beats, 0);
554
1038
  }
555
- const pt = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], Nt = (t, e) => [t[0] * e, t[1] * e, t[2] * e], at = (t, e) => fe(ce(t, e.swing), e.spread);
556
- function wt(t, e) {
557
- const n = et(t, e);
558
- return { point: { x: n[0], y: -n[1] }, depth: n[2] };
1039
+ const ko = { leftToe: "rightToe", rightToe: "leftToe", leftHeel: "rightHeel", rightHeel: "leftHeel" };
1040
+ function Ht(e, t, n, r, o, l, i) {
1041
+ for (let s = 0; s * e.beats < n; s++)
1042
+ for (const h of e.keys) {
1043
+ const a = s * e.beats + h.beat, f = t + a;
1044
+ if (!(a >= n || f < l || f >= i))
1045
+ for (const u of h.taps ?? []) o.push({ beat: f, tap: r ? ko[u] : u });
1046
+ }
559
1047
  }
560
- function It(t, e, n) {
561
- const o = n.height, r = q(90 * (e.turn ?? 0)), h = [0, t.hipHeight * o * (t.boneScale?.(e, null) ?? 1), 0], i = {};
562
- for (const p of t.chains) {
563
- const T = p.parent ? i[p.parent] : void 0;
564
- if (p.parent && !T) throw new Error(`body plan ${t.id}: chain ${p.id} comes before its parent ${p.parent}`);
565
- const v = p.at ?? (T ? T.joints3.length - 1 : 0), O = T ? T.joints3[v] : h, A = T ? T.frames[Math.max(0, v - 1)] : { swing: 0, spread: 0 }, Z = p.offset ? pt(O, at(Nt(p.offset, o), A)) : O, nt = p.side ?? 1, ut = t.boneScale?.(e, p) ?? 1, gt = t.angles(e, p), X = [Z], Q = [];
566
- let D = A.swing, yt = A.spread;
567
- p.bones.forEach((ue, Ht) => {
568
- const mt = gt[Ht] ?? { swing: 0, spread: 0 };
569
- D += q(mt.swing), yt += q(mt.spread) * nt, Q.push({ swing: D, spread: yt });
570
- const ge = et(at(p.rest, { swing: D, spread: yt }), q(mt.yaw ?? 0));
571
- X.push(pt(X[Ht], Nt(ge, ue.length * o * ut)));
572
- }), i[p.id] = { joints3: X, frames: Q };
573
- }
574
- const l = i[t.head.on], a = t.headPose?.(e) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 }, c = l.frames[l.frames.length - 1], g = t.head.size / 2 * o, y = g * a.sx, f = g * a.sy, d = (p) => at(et(ce(fe(p, -q(a.tilt)), -q(a.nod)), q(a.yaw)), c), w = pt(l.joints3[l.joints3.length - 1], d([0, f, 0])), m = {};
575
- for (const p of t.chains) {
576
- const { joints3: T, frames: v } = i[p.id], O = T.map((A) => wt(A, r));
577
- m[p.id] = {
578
- id: p.id,
579
- joints3: T,
580
- frames: v,
581
- points: O.map((A) => A.point),
582
- depths: O.map((A) => A.depth)
583
- };
1048
+ function Ar(e, t, n, r = {}) {
1049
+ const o = typeof e == "string" ? $e[e] : e, l = [];
1050
+ if (n <= t) return l;
1051
+ if (r.move) {
1052
+ const i = o.moves[r.move], s = Math.floor(t / i.beats) * i.beats;
1053
+ Ht(i, s, Math.ceil((n - s) / i.beats) * i.beats, r.mirror, l, t, n);
1054
+ } else {
1055
+ const i = Ut(o);
1056
+ for (let s = Math.floor(t / i) * i; s < n; s += i) {
1057
+ let h = s;
1058
+ for (const a of o.routine)
1059
+ Ht(o.moves[a.move], h, a.beats, a.mirror, l, t, n), h += a.beats;
1060
+ }
584
1061
  }
585
- const u = wt(w, r), k = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map((p) => et(d(p), r)), E = wt(h, r).point, b = q(e.roll ?? 0), M = (p) => {
586
- const T = p.x - E.x, v = p.y - E.y;
587
- return { x: E.x + T * Math.cos(b) - v * Math.sin(b), y: E.y + T * Math.sin(b) + v * Math.cos(b) };
588
- }, P = ([p, T, v]) => [p * Math.cos(b) + T * Math.sin(b), -p * Math.sin(b) + T * Math.cos(b), v];
589
- for (const p of Object.values(m)) p.points = p.points.map(M);
590
- const S = {
591
- center: M(u.point),
592
- depth: u.depth,
593
- rx: y,
594
- ry: f,
595
- angle: 0,
596
- axes: k.map(P)
597
- }, W = S.axes[1];
598
- S.angle = Math.atan2(W[0], W[1]);
599
- const H = (p) => {
600
- if ("head" in p) return { x: S.center.x + W[0] * f, y: S.center.y - W[1] * f };
601
- const T = m[p.chain];
602
- return T.points[Math.min(p.joint, T.points.length - 1)];
603
- };
604
- let Y = 0;
605
- (n.contact ?? "ground") === "ground" && (Y = -Math.max(...t.contacts.map((p) => H(p).y))), Y -= (e.lift ?? 0) * o;
606
- const I = (p) => ({ x: p.x, y: p.y + Y });
607
- for (const p of Object.values(m)) p.points = p.points.map(I);
608
- S.center = I(S.center);
609
- const x = t.contacts.map((p) => ({ spec: p, point: H(p) }));
610
- return {
611
- height: o,
612
- view: r,
613
- chains: m,
614
- head: S,
615
- hip: I(M(E)),
616
- contacts: x,
617
- groundY: Math.max(...x.map((p) => p.point.y))
618
- };
619
- }
620
- function de(t, [e, n, o]) {
621
- const [r, s, h] = t.axes, i = [
622
- r[0] * e * t.rx + s[0] * n * t.ry + h[0] * o * t.rx,
623
- r[1] * e * t.rx + s[1] * n * t.ry + h[1] * o * t.rx,
624
- r[2] * e * t.rx + s[2] * n * t.ry + h[2] * o * t.rx
625
- ], l = Math.hypot(e, n, o) || 1, a = (r[2] * e + s[2] * n + h[2] * o) / l;
626
- return { point: { x: t.center.x + i[0], y: t.center.y - i[1] }, depth: t.depth + i[2], facing: a };
627
- }
628
- const rt = (t) => t * 180 / Math.PI, j = (t, e) => [t[0] - e[0], t[1] - e[1], t[2] - e[2]], bt = (t, e) => t[0] * e[0] + t[1] * e[1] + t[2] * e[2], tt = (t) => Math.hypot(t[0], t[1], t[2]), Wt = (t) => {
629
- const e = tt(t) || 1;
630
- return [t[0] / e, t[1] / e, t[2] / e];
631
- }, it = (t) => Math.atan2(Math.sin(t), Math.cos(t));
632
- function Ct(t) {
633
- const [e, n, o] = Wt(t);
634
- return { swing: Math.asin(Math.max(-1, Math.min(1, o))), spread: Math.atan2(e, -n) };
635
- }
636
- function Je(t, e, n, o, r) {
637
- const s = t.chains.find((Y) => Y.id === n);
638
- if (!s) throw new Error(`reach: no chain ${n} in ${t.id}`);
639
- if (s.bones.length < 2 || s.rest[1] > -0.99) throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);
640
- if (!t.withAngles) throw new Error(`reach: the ${t.id} plan cannot set angles`);
641
- const h = It(t, { ...e, turn: 0, roll: 0, lift: 0 }, { height: r.height, contact: "none" }), i = h.chains[n], l = i.joints3[0], a = tt(j(i.joints3[1], i.joints3[0])), c = tt(j(i.joints3[2], i.joints3[1])), g = s.parent ? h.chains[s.parent].frames[Math.max(0, (s.at ?? h.chains[s.parent].joints3.length - 1) - 1)] : { swing: 0, spread: 0 }, y = j(o, l), f = Math.min(a + c - 1e-6, Math.max(Math.abs(a - c) + 1e-6, tt(y))), d = Wt(y), w = s.parent !== null, m = at(s.pole ?? (w ? [0, -0.35, -1] : [0, 0, 1]), g);
642
- let u = j(m, [d[0] * bt(m, d), d[1] * bt(m, d), d[2] * bt(m, d)]);
643
- tt(u) < 1e-6 && (u = et([1, 0, 0], 0)), u = Wt(u);
644
- const k = (a * a + f * f - c * c) / (2 * a * f), E = Math.sqrt(Math.max(0, 1 - k * k)), b = [
645
- l[0] + a * (k * d[0] + E * u[0]),
646
- l[1] + a * (k * d[1] + E * u[1]),
647
- l[2] + a * (k * d[2] + E * u[2])
648
- ], M = [l[0] + d[0] * f, l[1] + d[1] * f, l[2] + d[2] * f], P = s.side ?? 1, S = Ct(j(b, l)), W = Ct(j(M, b)), H = [
649
- { swing: rt(it(S.swing - g.swing)), spread: rt(it(S.spread - g.spread)) * P },
650
- { swing: rt(it(W.swing - S.swing)), spread: rt(it(W.spread - S.spread)) * P }
1062
+ return l.sort((i, s) => i.beat - s.beat);
1063
+ }
1064
+ function Kr(e, t, n = 0) {
1065
+ return (e - n) * t / 6e4;
1066
+ }
1067
+ function Pr(e, t = {}) {
1068
+ return (n) => st(e, n, t);
1069
+ }
1070
+ function Wr(e, t) {
1071
+ const n = t.start ?? 0, r = 6e4 / t.bpm, o = n + t.beats * r, l = Math.min((t.fade ?? 1) * r, (o - n) / 2);
1072
+ return [
1073
+ {
1074
+ id: `${e}-beat`,
1075
+ target: e,
1076
+ property: "beat",
1077
+ keyframes: [
1078
+ { time: n, value: 0 },
1079
+ { time: o, value: t.beats, easing: "linear" }
1080
+ ]
1081
+ },
1082
+ {
1083
+ id: `${e}-dancing`,
1084
+ target: e,
1085
+ property: "dancing",
1086
+ keyframes: [
1087
+ { time: n, value: 0 },
1088
+ { time: n + l, value: 1, easing: "ease-in-out" },
1089
+ { time: o - l, value: 1 },
1090
+ { time: o, value: 0, easing: "ease-in-out" }
1091
+ ]
1092
+ }
651
1093
  ];
652
- return t.withAngles(e, s, H);
653
1094
  }
654
- function Xt(t, e, n, o, r, s = 0, h = 1, i = 40) {
655
- const l = Math.cos(r), a = Math.sin(r);
656
- return Array.from({ length: i + 1 }, (c, g) => {
657
- const y = s + Math.PI * 2 * h * g / i, f = Math.cos(y) * n, d = Math.sin(y) * o;
658
- return { x: t + f * l - d * a, y: e + f * a + d * l };
659
- });
660
- }
661
- function ze(t, e) {
662
- return e.look === "pencil" ? Ve(t, e) : Ge(t, e.ink, e.look);
663
- }
664
- function ft(t, e, n = !1) {
665
- t.beginPath(), t.moveTo(e[0].x, e[0].y);
666
- for (const o of e.slice(1)) t.lineTo(o.x, o.y);
667
- n && t.closePath();
668
- }
669
- function Ge(t, e, n) {
670
- const o = n === "silhouette", r = o ? 1.25 : 1;
671
- return {
672
- look: n,
673
- ink: e,
674
- limb(s, h, i) {
675
- t.fillStyle = e, Jt(t, s, h * r, i * r);
1095
+ function Or(e, t, n = {}) {
1096
+ const r = typeof t == "string" ? $e[t] : t, o = n.bpm ?? r.bpm, l = n.beats ?? (n.move ? r.moves[n.move].beats : Ut(r)), i = n.samplesPerBeat ?? 4, s = n.start ?? 0, h = Math.round(l * i), a = Array.from({ length: h + 1 }, (g, d) => {
1097
+ const b = d / i;
1098
+ return { time: s + b * 6e4 / o, frame: st(r, b, n) };
1099
+ }), f = (g, d) => ({
1100
+ id: `${e}-${g}`,
1101
+ target: e,
1102
+ property: g,
1103
+ keyframes: a.map((b) => ({ time: b.time, value: d(b.frame) }))
1104
+ }), p = Object.keys(z).filter((g) => a.some((d) => d.frame.pose[g] !== a[0].frame.pose[g]) || a[0].frame.pose[g] !== z[g]).map((g) => f(g, (d) => d.pose[g]));
1105
+ if (n.hands === !1) return p;
1106
+ const c = [];
1107
+ for (const g of ["left", "right"])
1108
+ for (const d of Object.keys(R)) {
1109
+ const b = (m) => m.hands?.[g]?.[d] ?? R[d];
1110
+ a.some((m) => b(m.frame) !== R[d]) && c.push(f(We(g, d), b));
1111
+ }
1112
+ return [...p, ...c];
1113
+ }
1114
+ const ve = { type: "back", mode: "out", overshoot: 1.1 }, q = "ease-out-cubic", So = {
1115
+ label: "Disco",
1116
+ bpm: 120,
1117
+ stance: { leftHip: 10, rightHip: 10, leftKnee: 6, rightKnee: 6 },
1118
+ expression: { smile: 0.9, mouth: 0.15, leftBrow: 0.3, rightBrow: 0.3 },
1119
+ groove: { bounce: 10, accent: "down", sway: 2 },
1120
+ moves: {
1121
+ point: {
1122
+ label: "The point",
1123
+ beats: 2,
1124
+ easing: q,
1125
+ keys: [
1126
+ {
1127
+ beat: 0,
1128
+ pose: { rightShoulder: 150, rightElbow: 0, rightWrist: 0, leftShoulder: 40, leftElbow: -105, leftWrist: -20, lean: -5, headTilt: 8, rightHip: 18, leftHip: 6, lookX: 0.6, lookY: -0.7 },
1129
+ hands: { right: "point", left: "fist" }
1130
+ },
1131
+ { beat: 1, pose: { rightShoulder: -30, rightWrist: 10, lean: 5, headTilt: -6, rightHip: 6, leftHip: 18, lookX: -0.4, lookY: 0.6 } }
1132
+ ]
676
1133
  },
677
- line(s, h) {
678
- s.length < 2 || (t.strokeStyle = e, t.lineWidth = h * r, t.lineCap = "round", t.lineJoin = "round", ft(t, s), t.stroke());
1134
+ roll: {
1135
+ label: "Roll the arms",
1136
+ beats: 2,
1137
+ easing: "linear",
1138
+ keys: [
1139
+ { beat: 0, pose: { leftShoulder: 42, leftElbow: -128, rightShoulder: 26, rightElbow: -100, rightHip: 18, leftHip: 6, lean: -3 }, hands: { left: "fist", right: "fist" } },
1140
+ { beat: 0.5, pose: { leftShoulder: 26, leftElbow: -100, rightShoulder: 42, rightElbow: -128 } },
1141
+ { beat: 1, pose: { leftShoulder: 42, leftElbow: -128, rightShoulder: 26, rightElbow: -100, rightHip: 6, leftHip: 18, lean: 3 } },
1142
+ { beat: 1.5, pose: { leftShoulder: 26, leftElbow: -100, rightShoulder: 42, rightElbow: -128 } }
1143
+ ]
679
1144
  },
680
- shape(s, h, i) {
681
- ft(t, s, !0), (h !== null || o) && (t.fillStyle = o ? e : h, t.fill()), !(i <= 0) && (t.strokeStyle = e, t.lineWidth = i * r, t.lineJoin = "round", t.stroke());
1145
+ bump: {
1146
+ label: "Bump and clap",
1147
+ beats: 4,
1148
+ keys: [
1149
+ { beat: 0, pose: { lean: -10, rightHip: 22, leftHip: 4, leftShoulder: 140, rightShoulder: 140, leftElbow: 0, rightElbow: 0, leftWrist: 20, rightWrist: 20 }, hands: { left: "spread", right: "spread" }, easing: q },
1150
+ { beat: 1, pose: { lean: 0, rightHip: 10, leftHip: 10, leftShoulder: 168, rightShoulder: 168, leftElbow: 22, rightElbow: 22, leftWrist: 0, rightWrist: 0 }, hands: { left: "flat", right: "flat" } },
1151
+ { beat: 2, pose: { lean: 10, rightHip: 4, leftHip: 22, leftShoulder: 140, rightShoulder: 140, leftElbow: 0, rightElbow: 0, leftWrist: 20, rightWrist: 20 }, hands: { left: "spread", right: "spread" }, easing: q },
1152
+ { beat: 3, pose: { lean: 0, rightHip: 10, leftHip: 10, leftShoulder: 168, rightShoulder: 168, leftElbow: 22, rightElbow: 22, leftWrist: 0, rightWrist: 0 }, hands: { left: "flat", right: "flat" } }
1153
+ ]
1154
+ }
1155
+ },
1156
+ routine: [
1157
+ { move: "point", beats: 8 },
1158
+ { move: "roll", beats: 4 },
1159
+ { move: "point", beats: 8, mirror: !0 },
1160
+ { move: "bump", beats: 8 }
1161
+ ]
1162
+ }, Eo = {
1163
+ label: "Hip hop",
1164
+ bpm: 95,
1165
+ stance: { leftHip: 14, rightHip: 14, leftKnee: 20, rightKnee: 20, leftShoulder: 22, rightShoulder: 22, leftElbow: -30, rightElbow: -30, leftFootOut: 0.15, rightFootOut: 0.15 },
1166
+ expression: "smug",
1167
+ hands: { left: "relaxed", right: "relaxed" },
1168
+ groove: { bounce: 18, accent: "down" },
1169
+ moves: {
1170
+ bounce: {
1171
+ label: "Bounce",
1172
+ beats: 2,
1173
+ keys: [
1174
+ { beat: 0, pose: { leftShoulder: 30, rightShoulder: 30, leftElbow: -50, rightElbow: -50, lean: -3, headTilt: -5, leftWrist: -20, rightWrist: -20 } },
1175
+ { beat: 1, pose: { leftShoulder: 14, rightShoulder: 14, leftElbow: -18, rightElbow: -18, lean: 3, headTilt: 5, leftWrist: 0, rightWrist: 0 } }
1176
+ ]
682
1177
  },
683
- ellipse(s, h, i, l, a, c, g) {
684
- t.beginPath(), t.ellipse(s, h, i, l, a, 0, Math.PI * 2), (c !== null || o) && (t.fillStyle = o ? e : c, t.fill()), !(g <= 0) && (t.strokeStyle = e, t.lineWidth = g * r, t.stroke());
1178
+ runningMan: {
1179
+ label: "Running man",
1180
+ beats: 2,
1181
+ keys: [
1182
+ {
1183
+ beat: 0,
1184
+ reset: !0,
1185
+ pose: { turn: 0.85, leftHip: -84, leftKnee: -112, leftAnkle: 25, rightHip: -26, rightKnee: 8, leftShoulder: 35, leftElbow: -50, rightShoulder: 45, rightElbow: 75, lean: 6 },
1186
+ hands: { left: "fist", right: "fist" }
1187
+ },
1188
+ { beat: 0.5, pose: { leftHip: -4, leftKnee: -18, leftAnkle: 0, rightHip: 4, rightKnee: 18, leftShoulder: 5, leftElbow: -40, rightShoulder: 5, rightElbow: 40 } },
1189
+ { beat: 1, pose: { rightHip: 84, rightKnee: 112, rightAnkle: 25, leftHip: 26, leftKnee: -8, rightShoulder: -35, rightElbow: 50, leftShoulder: -45, leftElbow: -75 } },
1190
+ { beat: 1.5, pose: { rightHip: 4, rightKnee: 18, rightAnkle: 0, leftHip: -4, leftKnee: -18, rightShoulder: -5, rightElbow: 40, leftShoulder: -5, leftElbow: -40 } }
1191
+ ]
685
1192
  },
686
- dot(s, h, i) {
687
- t.fillStyle = e, t.beginPath(), t.arc(s, h, i * r, 0, Math.PI * 2), t.fill();
1193
+ armWave: {
1194
+ label: "Arm wave",
1195
+ beats: 4,
1196
+ keys: [
1197
+ { beat: 0, reset: !0, pose: { leftShoulder: 90, rightShoulder: 90, leftElbow: 0, rightElbow: 0 }, hands: { left: "flat", right: "flat" } },
1198
+ { beat: 0.5, pose: { leftWrist: 45, leftElbow: -15 } },
1199
+ { beat: 1, pose: { leftWrist: -35, leftElbow: 40, leftShoulder: 84 } },
1200
+ { beat: 1.5, pose: { leftWrist: 0, leftElbow: -10, leftShoulder: 102, headTilt: -8 } },
1201
+ { beat: 2, pose: { leftElbow: 0, leftShoulder: 90, rightShoulder: 102, headTilt: 8 } },
1202
+ { beat: 2.5, pose: { rightShoulder: 84, rightElbow: 40, headTilt: 0 } },
1203
+ { beat: 3, pose: { rightElbow: -15, rightWrist: 45 } },
1204
+ { beat: 3.5, pose: { rightElbow: 0, rightWrist: -35 } }
1205
+ ]
1206
+ }
1207
+ },
1208
+ routine: [
1209
+ { move: "bounce", beats: 8 },
1210
+ { move: "runningMan", beats: 8 },
1211
+ { move: "armWave", beats: 8 },
1212
+ { move: "bounce", beats: 4 }
1213
+ ]
1214
+ }, Ho = {
1215
+ label: "Breaking (toprock)",
1216
+ bpm: 110,
1217
+ stance: { leftHip: 14, rightHip: 14, leftKnee: 14, rightKnee: 14, leftShoulder: 35, rightShoulder: 35, leftElbow: -90, rightElbow: -90 },
1218
+ expression: { smile: 0.3, leftBrow: -0.3, rightBrow: -0.3, browTilt: -0.3 },
1219
+ hands: { left: "fist", right: "fist" },
1220
+ groove: { bounce: 8, accent: "down" },
1221
+ moves: {
1222
+ toprock: {
1223
+ label: "Toprock (Indian step)",
1224
+ beats: 4,
1225
+ keys: [
1226
+ { beat: 0, pose: { rightHip: -24, rightKnee: 10, leftHip: 10, leftShoulder: 80, leftElbow: 40, rightShoulder: 55, rightElbow: -50, lean: 6, headTilt: -6 }, easing: q },
1227
+ { beat: 1, reset: !0, pose: { leftHip: 18, rightHip: 18 } },
1228
+ { beat: 2, pose: { leftHip: -24, leftKnee: 10, rightHip: 10, rightShoulder: 80, rightElbow: 40, leftShoulder: 55, leftElbow: -50, lean: -6, headTilt: 6 }, easing: q },
1229
+ { beat: 3, reset: !0, pose: { leftHip: 18, rightHip: 18 } }
1230
+ ]
688
1231
  },
689
- guide() {
1232
+ kick: {
1233
+ label: "Kick out",
1234
+ beats: 2,
1235
+ keys: [
1236
+ { beat: 0, pose: { rightHip: 72, rightKnee: 4, rightAnkle: -20, leftHip: 4, lean: -12, leftShoulder: 100, leftElbow: 20 }, easing: q },
1237
+ { beat: 1, reset: !0 }
1238
+ ]
690
1239
  },
691
- guideEllipse() {
1240
+ freeze: {
1241
+ label: "B-boy stance",
1242
+ beats: 4,
1243
+ keys: [
1244
+ { beat: 0, reset: !0, pose: { leftShoulder: 26, leftElbow: -122, rightShoulder: 22, rightElbow: -118, leftHip: 18, rightHip: 18, leftKnee: 6, rightKnee: 6, lean: -4, headTilt: 10, smile: 0.6, leftEye: 0.6, rightEye: 0.6 }, easing: ve },
1245
+ { beat: 2, pose: { headTilt: 14, lean: -6 } }
1246
+ ]
692
1247
  }
693
- };
694
- }
695
- function Ze(t, e) {
696
- const n = [t[0]];
697
- let o = 0;
698
- for (let h = 1; h < t.length; h++) {
699
- const i = t[h - 1], l = t[h], a = Math.hypot(l.x - i.x, l.y - i.y);
700
- let c = e - o;
701
- for (; c < a; ) {
702
- const g = c / a;
703
- n.push({ x: i.x + (l.x - i.x) * g, y: i.y + (l.y - i.y) * g }), c += e;
1248
+ },
1249
+ routine: [
1250
+ { move: "toprock", beats: 8 },
1251
+ { move: "kick", beats: 4 },
1252
+ { move: "toprock", beats: 8 },
1253
+ { move: "kick", beats: 4, mirror: !0 },
1254
+ { move: "freeze", beats: 4 }
1255
+ ]
1256
+ }, Mo = {
1257
+ label: "Jazz",
1258
+ bpm: 130,
1259
+ stance: { leftHip: 10, rightHip: 10 },
1260
+ expression: { mouth: 0.55, smile: 1, mouthWidth: 1.2, leftBrow: 0.6, rightBrow: 0.6 },
1261
+ hands: { left: "spread", right: "spread" },
1262
+ groove: { bounce: 6, accent: "up" },
1263
+ moves: {
1264
+ jazzHands: {
1265
+ label: "Jazz hands",
1266
+ beats: 2,
1267
+ easing: "linear",
1268
+ keys: [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75].map((e, t) => ({
1269
+ beat: e,
1270
+ // The hands shimmer: the wrists flick a little each quarter beat.
1271
+ pose: { leftShoulder: 128, rightShoulder: 128, leftElbow: 8, rightElbow: 8, leftWrist: t % 2 ? 4 : 26, rightWrist: t % 2 ? 26 : 4, leftHip: 16, rightHip: 16, leftKnee: e < 1 ? 26 : 8, rightKnee: e < 1 ? 26 : 8 },
1272
+ hands: t === 0 ? { left: { ...N.spread, turn: 2 }, right: { ...N.spread, turn: 2 } } : void 0
1273
+ }))
1274
+ },
1275
+ kickBallChange: {
1276
+ label: "Kick ball change",
1277
+ beats: 2,
1278
+ keys: [
1279
+ { beat: 0, reset: !0, pose: { rightHip: 88, rightKnee: 0, rightAnkle: 55, leftHip: 4, lean: -12, leftShoulder: 112, rightShoulder: 112, leftWrist: 15, rightWrist: 15 }, hands: { left: "flat", right: "flat" }, easing: q },
1280
+ { beat: 1, reset: !0, pose: { rightHip: 10, rightKnee: 24, rightAnkle: 45, leftShoulder: 60, rightShoulder: 60, leftElbow: -20, rightElbow: -20 } },
1281
+ { beat: 1.5, pose: { rightAnkle: 0, rightKnee: 6, leftAnkle: 45, leftKnee: 20 } }
1282
+ ]
1283
+ },
1284
+ splitDrop: {
1285
+ label: "Drop into the splits",
1286
+ beats: 8,
1287
+ keys: [
1288
+ { beat: 0, reset: !0 },
1289
+ // Slide down into a full side split, arms up…
1290
+ { beat: 2, reset: !0, pose: { leftHip: 90, rightHip: 90, leftKnee: 0, rightKnee: 0, leftAnkle: -45, rightAnkle: -45, leftShoulder: 125, rightShoulder: 125, leftElbow: 10, rightElbow: 10 }, easing: "ease-in-out-cubic" },
1291
+ // …hold and sell it…
1292
+ { beat: 4, pose: { leftShoulder: 95, rightShoulder: 95, leftElbow: 0, rightElbow: 0, leftWrist: 50, rightWrist: 50, headTilt: 8 } },
1293
+ // …then gather up through a crouch and stand.
1294
+ { beat: 6, reset: !0, pose: { leftHip: 30, rightHip: 30, leftKnee: 60, rightKnee: 60, leftShoulder: 40, rightShoulder: 40 }, easing: "ease-in-out-cubic" },
1295
+ { beat: 7.5, reset: !0 }
1296
+ ]
1297
+ },
1298
+ jazzSquare: {
1299
+ label: "Jazz square",
1300
+ beats: 4,
1301
+ keys: [
1302
+ { beat: 0, reset: !0, pose: { rightHip: -18, leftHip: 8, leftShoulder: 38, rightShoulder: 46, leftElbow: 100, rightElbow: 96, lean: 4 }, hands: { left: "pinch", right: "pinch" } },
1303
+ { beat: 1, pose: { leftHip: 18, rightHip: 6, leftShoulder: 46, rightShoulder: 38, lean: -4 } },
1304
+ { beat: 2, pose: { rightHip: 22, leftHip: 6, leftShoulder: 38, rightShoulder: 46, lean: 4 } },
1305
+ { beat: 3, pose: { leftHip: 10, rightHip: 10, leftShoulder: 46, rightShoulder: 38, lean: 0 } }
1306
+ ]
704
1307
  }
705
- o = a - (c - e);
706
- }
707
- const r = t[t.length - 1], s = n[n.length - 1];
708
- return Math.hypot(r.x - s.x, r.y - s.y) > e * 0.25 ? n.push(r) : n[n.length - 1] = r, n;
709
- }
710
- function Qe(t, e) {
711
- const n = t.length;
712
- return t.map((o, r) => {
713
- const s = t[Math.max(0, r - 1)], h = t[Math.min(n - 1, r + 1)], i = Math.hypot(h.x - s.x, h.y - s.y) || 1, l = e(n === 1 ? 0 : r / (n - 1));
714
- return { x: o.x - (h.y - s.y) / i * l, y: o.y + (h.x - s.x) / i * l };
715
- });
716
- }
717
- function qt(t) {
718
- const e = [0.6, 1.4, 2.9].map((o) => ({
719
- frequency: o * (0.8 + t.next() * 0.4),
720
- phase: t.next() * Math.PI * 2,
721
- amount: 0.5 + t.next() * 0.5
722
- })), n = e.reduce((o, r) => o + r.amount, 0);
723
- return (o) => e.reduce((r, s) => r + s.amount * Math.sin(Math.PI * 2 * s.frequency * o + s.phase), 0) / n;
724
- }
725
- function Ve(t, e) {
726
- const n = e.pencil ?? {}, o = e.ink, r = n.roughness ?? Math.max(1, e.lineWidth * 0.12), s = Math.max(1, Math.round(n.passes ?? 2)), h = Math.min(1, Math.max(0, n.pressure ?? 0.25)), i = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), l = ye(e.time, n.boil ?? 8);
727
- let a = 0;
728
- const c = (d, w, m = !1) => me(pe(`${e.seed}:${m ? "paper" : l}:${d}:${w}`)), g = (d, w, m, u, k, E = 0) => {
729
- if (d.length < 2) return;
730
- const b = d.slice(1).reduce((I, x, p) => I + Math.hypot(x.x - d[p].x, x.y - d[p].y), 0);
731
- let M = Ze(d, Math.max(1.5, Math.min(e.lineWidth * 0.8, b / 24)));
732
- if (E > 0 && M.length >= 2) {
733
- const [I, x] = [M[M.length - 2], M[M.length - 1]], p = Math.hypot(x.x - I.x, x.y - I.y) || 1;
734
- M = [...M, { x: x.x + (x.x - I.x) / p * E, y: x.y + (x.y - I.y) / p * E }];
1308
+ },
1309
+ routine: [
1310
+ { move: "jazzHands", beats: 4 },
1311
+ { move: "kickBallChange", beats: 4 },
1312
+ { move: "kickBallChange", beats: 4, mirror: !0 },
1313
+ { move: "jazzSquare", beats: 8 },
1314
+ { move: "jazzHands", beats: 4 },
1315
+ { move: "splitDrop", beats: 8 }
1316
+ ]
1317
+ }, To = {
1318
+ label: "K-pop",
1319
+ bpm: 125,
1320
+ stance: { leftHip: 9, rightHip: 9, leftKnee: 4, rightKnee: 4 },
1321
+ expression: "happy",
1322
+ groove: { bounce: 5, accent: "down" },
1323
+ moves: {
1324
+ pointCombo: {
1325
+ label: "Point combo",
1326
+ beats: 4,
1327
+ easing: ve,
1328
+ keys: [
1329
+ { beat: 0, reset: !0, pose: { rightShoulder: 142, rightElbow: 0, leftShoulder: 25, leftElbow: -125, headTilt: 6, lean: -3, lookX: 0.6, lookY: -0.6 }, hands: { right: "point", left: "flat" } },
1330
+ { beat: 1, pose: { rightShoulder: -38, headTilt: -6, lean: 3, lookX: -0.3, lookY: 0.5, rightHip: 18 } },
1331
+ { beat: 2, reset: !0, pose: { leftShoulder: 36, leftElbow: -96, rightShoulder: 36, rightElbow: -96, leftWrist: 20, rightWrist: 20 }, hands: { left: "fist", right: "fist" } },
1332
+ { beat: 3, reset: !0, pose: { leftShoulder: 96, rightShoulder: 96, leftElbow: 0, rightElbow: 0, leftWrist: 50, rightWrist: 50, headTilt: 8, leftHip: 18, rightHip: 18 }, hands: { left: "flat", right: "flat" } }
1333
+ ]
1334
+ },
1335
+ heart: {
1336
+ label: "Big heart, finger heart",
1337
+ beats: 4,
1338
+ keys: [
1339
+ { beat: 0, reset: !0, pose: { leftShoulder: 165, rightShoulder: 165, leftElbow: 46, rightElbow: 46, headTilt: -8, lean: -4 }, hands: { left: "cupped", right: "cupped" }, easing: ve },
1340
+ { beat: 1, pose: { headTilt: 8, lean: 4 } },
1341
+ { beat: 2, reset: !0, pose: { rightShoulder: 32, rightElbow: 112, rightWrist: 10, leftShoulder: 20, leftElbow: -30, headTilt: 10, leftEye: 0, smile: 1 }, hands: { right: "pinch", left: "relaxed" }, easing: ve },
1342
+ { beat: 3, pose: { headTilt: 4 } }
1343
+ ]
1344
+ },
1345
+ isolations: {
1346
+ label: "Isolations",
1347
+ beats: 2,
1348
+ easing: q,
1349
+ keys: [
1350
+ { beat: 0, reset: !0, pose: { lean: -9, headTilt: 11, leftShoulder: 55, leftElbow: -112, rightShoulder: 55, rightElbow: -112, rightHip: 18 }, hands: { left: "fist", right: "fist" } },
1351
+ { beat: 0.5, pose: { lean: 0, headTilt: 0, rightHip: 9 } },
1352
+ { beat: 1, pose: { lean: 9, headTilt: -11, leftHip: 18 } },
1353
+ { beat: 1.5, pose: { lean: 0, headTilt: 0, leftHip: 9 } }
1354
+ ]
735
1355
  }
736
- const P = qt(m), S = qt(m), W = M.length, H = [], Y = [];
737
- M.forEach((I, x) => {
738
- const p = W === 1 ? 0 : x / (W - 1), T = M[Math.max(0, x - 1)], v = M[Math.min(W - 1, x + 1)], O = Math.hypot(v.x - T.x, v.y - T.y) || 1, A = -(v.y - T.y) / O, Z = (v.x - T.x) / O, nt = P(p) * k, ut = Math.min(1, p / 0.08, (1 - p) / 0.08), gt = (0.55 + 0.45 * Math.sqrt(Math.max(0, ut))) * (1 + h * S(p)), X = Math.max(0.3, w(p) * gt / 2), Q = I.x + A * nt, D = I.y + Z * nt;
739
- H.push({ x: Q + A * X, y: D + Z * X }), Y.push({ x: Q - A * X, y: D - Z * X });
740
- }), t.save(), t.globalAlpha *= u, t.fillStyle = o, ft(t, [...H, ...Y.reverse()], !0), t.fill(), t.restore();
741
- }, y = (d, w) => {
742
- const m = a++, u = c(m, 99, !0);
743
- if (u.next() < i) {
744
- const M = (u.next() * 2 - 1) * e.lineWidth * 1.4, P = (u.next() * 2 - 1) * e.lineWidth * 1.4, S = d.map((W) => ({ x: W.x + M, y: W.y + P }));
745
- g(S, (W) => w(W) * 1.8, c(m, 98, !0), 0.035, r), g(S, (W) => w(W) * 0.45, c(m, 97, !0), 0.12, r * 1.5);
1356
+ },
1357
+ routine: [
1358
+ { move: "pointCombo", beats: 8 },
1359
+ { move: "isolations", beats: 4 },
1360
+ { move: "heart", beats: 8 },
1361
+ { move: "pointCombo", beats: 8, mirror: !0 },
1362
+ { move: "isolations", beats: 4 }
1363
+ ]
1364
+ }, vo = {
1365
+ label: "Bollywood",
1366
+ bpm: 120,
1367
+ stance: { leftHip: 10, rightHip: 10 },
1368
+ expression: { smile: 1, mouth: 0.3, leftBrow: 0.4, rightBrow: 0.4 },
1369
+ groove: { bounce: 8, accent: "down", sway: 3 },
1370
+ moves: {
1371
+ lightBulb: {
1372
+ label: "Screw the bulb, pat the dog",
1373
+ beats: 2,
1374
+ keys: [
1375
+ { beat: 0, reset: !0, pose: { rightShoulder: 160, rightElbow: 12, rightWrist: -15, leftShoulder: 40, leftElbow: -12, leftWrist: -45, lean: -4, rightHip: 16, lookX: 0.5, lookY: -0.6 }, hands: { right: { ...N.cupped, roll: -30 }, left: { ...N.flat, turn: 0 } } },
1376
+ { beat: 0.5, pose: { rightWrist: 25, rightElbow: 22, leftWrist: 10, lean: 4, rightHip: 6, leftHip: 16 }, hands: { right: { ...N.cupped, roll: 30 } } },
1377
+ { beat: 1, pose: { rightWrist: -15, rightElbow: 12, leftWrist: -45, lean: -4, rightHip: 16, leftHip: 6 }, hands: { right: { ...N.cupped, roll: -30 } } },
1378
+ { beat: 1.5, pose: { rightWrist: 25, rightElbow: 22, leftWrist: 10, lean: 4, rightHip: 6, leftHip: 16 }, hands: { right: { ...N.cupped, roll: 30 } } }
1379
+ ]
1380
+ },
1381
+ thumka: {
1382
+ label: "Thumka",
1383
+ beats: 2,
1384
+ keys: [
1385
+ { beat: 0, reset: !0, pose: { lean: -11, rightHip: 22, leftHip: 2, leftKnee: 14, rightShoulder: 45, rightElbow: -105, leftShoulder: 128, leftElbow: 18, leftWrist: 35, headTilt: 10, lookX: -0.5 }, hands: { right: "fist", left: { ...N.open, turn: 2 } }, easing: q },
1386
+ { beat: 0.5, pose: { lean: -4, rightHip: 12, headTilt: 6 } },
1387
+ { beat: 1, pose: { lean: -11, rightHip: 22, headTilt: 10 }, easing: q },
1388
+ { beat: 1.5, pose: { lean: -4, rightHip: 12, headTilt: 6 } }
1389
+ ]
1390
+ },
1391
+ flick: {
1392
+ label: "Cross and flick",
1393
+ beats: 4,
1394
+ keys: [
1395
+ { beat: 0, reset: !0, pose: { leftShoulder: 22, rightShoulder: 22, leftElbow: -62, rightElbow: -62, leftHip: 16, rightHip: 16, leftKnee: 26, rightKnee: 26 }, hands: { left: "fist", right: "fist" } },
1396
+ { beat: 1, pose: { leftShoulder: 132, rightShoulder: 132, leftElbow: 0, rightElbow: 0, leftWrist: 30, rightWrist: 30, leftKnee: 0, rightKnee: 0, leftHip: 10, rightHip: 10, stretch: 1.03 }, hands: { left: "spread", right: "spread" }, easing: q },
1397
+ { beat: 2, pose: { leftShoulder: 22, rightShoulder: 22, leftElbow: -62, rightElbow: -62, leftWrist: 0, rightWrist: 0, leftHip: 16, rightHip: 16, leftKnee: 26, rightKnee: 26, stretch: 1 }, hands: { left: "fist", right: "fist" } },
1398
+ { beat: 3, pose: { leftShoulder: 62, rightShoulder: 62, leftElbow: 0, rightElbow: 0, leftWrist: 35, rightWrist: 35, leftKnee: 0, rightKnee: 0, leftHip: 10, rightHip: 10 }, hands: { left: "spread", right: "spread" }, easing: q }
1399
+ ]
746
1400
  }
747
- const k = d.slice(1).reduce((M, P, S) => M + Math.hypot(P.x - d[S].x, P.y - d[S].y), 0), E = w(0.5) > 4 && k > w(0.5) * 6, b = E ? [-0.3, 0.3, 0] : [0];
748
- for (let M = 0; M < s; M++) {
749
- const P = M === 0;
750
- b.forEach((S, W) => {
751
- const H = c(m, M * 10 + W), Y = S === 0 ? d : Qe(d, (x) => w(x) * S * Math.sqrt(Math.sin(Math.PI * x))), I = !P && S === 0 ? e.lineWidth * (0.3 + H.next() * 0.8) : 0;
752
- g(Y, (x) => w(x) * (E ? 0.5 : 1) * (P ? 1 : 0.6), H, P ? 0.85 : 0.45, r * (P ? 0.6 : 1), I);
753
- });
1401
+ },
1402
+ routine: [
1403
+ { move: "thumka", beats: 4 },
1404
+ { move: "lightBulb", beats: 8 },
1405
+ { move: "flick", beats: 8 },
1406
+ { move: "thumka", beats: 4, mirror: !0 },
1407
+ { move: "lightBulb", beats: 8, mirror: !0 }
1408
+ ]
1409
+ }, xo = {
1410
+ label: "Bhangra",
1411
+ bpm: 100,
1412
+ stance: { leftShoulder: 150, rightShoulder: 150, leftElbow: 18, rightElbow: 18, leftHip: 10, rightHip: 10 },
1413
+ expression: { mouth: 0.6, smile: 1, mouthWidth: 1.2, leftBrow: 0.5, rightBrow: 0.5 },
1414
+ hands: { left: "open", right: "open" },
1415
+ groove: { bounce: 12, accent: "down" },
1416
+ moves: {
1417
+ basic: {
1418
+ label: "Bhangra step",
1419
+ beats: 2,
1420
+ keys: [
1421
+ { beat: 0, reset: !0, pose: { rightHip: 58, rightKnee: 104, rightAnkle: 30, leftShoulder: 162, rightShoulder: 140, headTilt: 7 } },
1422
+ { beat: 0.5, reset: !0, pose: { stretch: 0.98 } },
1423
+ { beat: 1, reset: !0, pose: { leftHip: 58, leftKnee: 104, leftAnkle: 30, rightShoulder: 162, leftShoulder: 140, headTilt: -7 } },
1424
+ { beat: 1.5, reset: !0, pose: { stretch: 0.98 } }
1425
+ ]
1426
+ },
1427
+ dhamaal: {
1428
+ label: "Dhamaal (jump, arms up)",
1429
+ beats: 2,
1430
+ keys: [
1431
+ { beat: 0, reset: !0, pose: { leftHip: 20, rightHip: 20, leftKnee: 40, rightKnee: 40, stretch: 0.94 } },
1432
+ { beat: 0.5, reset: !0, pose: { rise: 0.07, stretch: 1.06, leftHip: 6, rightHip: 6, leftAnkle: 45, rightAnkle: 45, leftShoulder: 172, rightShoulder: 172, leftElbow: 0, rightElbow: 0 }, hands: { left: "point", right: "point" }, easing: "ease-out-quad" },
1433
+ { beat: 1, reset: !0, pose: { leftHip: 20, rightHip: 20, leftKnee: 40, rightKnee: 40, stretch: 0.94 }, hands: { left: "open", right: "open" }, easing: "ease-in-quad" },
1434
+ { beat: 1.5, reset: !0, pose: { rise: 0.07, stretch: 1.06, leftHip: 6, rightHip: 6, leftAnkle: 45, rightAnkle: 45, leftShoulder: 172, rightShoulder: 172, leftElbow: 0, rightElbow: 0 }, hands: { left: "point", right: "point" }, easing: "ease-out-quad" }
1435
+ ]
754
1436
  }
755
- }, f = (d, w, m, u, k, E) => {
756
- const M = c(a, 50).next() * Math.PI * 2;
757
- y(Xt(d, w, m, u, k, M, 1.08, 48), () => E);
758
- };
759
- return {
760
- look: "pencil",
761
- ink: o,
762
- limb(d, w, m) {
763
- y(d, (u) => w + (m - w) * u);
1437
+ },
1438
+ routine: [
1439
+ { move: "basic", beats: 8 },
1440
+ { move: "dhamaal", beats: 4 },
1441
+ { move: "basic", beats: 8 },
1442
+ { move: "dhamaal", beats: 4 }
1443
+ ]
1444
+ }, Ao = { leftHip: 42, rightHip: 42, leftKnee: 82, rightKnee: 82, leftFootOut: 0.3, rightFootOut: 0.3 }, Ko = {
1445
+ label: "Bharatanatyam",
1446
+ bpm: 80,
1447
+ // Natyarambhe: arms out at shoulder height, hands raised in pataka.
1448
+ stance: { ...Ao, leftShoulder: 90, rightShoulder: 90, leftElbow: 0, rightElbow: 0, leftWrist: 75, rightWrist: 75 },
1449
+ expression: { smile: 0.5, leftEye: 1.2, rightEye: 1.2, leftBrow: 0.3, rightBrow: 0.3 },
1450
+ hands: { left: "pataka", right: "pataka" },
1451
+ groove: { bounce: 0 },
1452
+ moves: {
1453
+ tatta: {
1454
+ label: "Tatta adavu (stamps)",
1455
+ beats: 2,
1456
+ keys: [
1457
+ { beat: 0, reset: !0, pose: { rightHip: 48, rightKnee: 104, rightAnkle: -18 } },
1458
+ { beat: 0.3, reset: !0, easing: "ease-in-quad", taps: ["rightToe", "rightHeel"] },
1459
+ { beat: 1, reset: !0, pose: { leftHip: 48, leftKnee: 104, leftAnkle: -18 } },
1460
+ { beat: 1.3, reset: !0, easing: "ease-in-quad", taps: ["leftToe", "leftHeel"] }
1461
+ ]
764
1462
  },
765
- line(d, w) {
766
- y(d, () => w);
1463
+ natta: {
1464
+ label: "Natta adavu (stretch and look)",
1465
+ beats: 4,
1466
+ keys: [
1467
+ { beat: 0, reset: !0, pose: { rightHip: 52, rightKnee: 0, rightAnkle: -40, rightShoulder: 125, rightWrist: 60, leftShoulder: 25, leftElbow: -125, leftWrist: 0, headTilt: 8, lookX: 0.9, lookY: -0.4, lean: -6 } },
1468
+ { beat: 1, reset: !0 },
1469
+ { beat: 2, reset: !0, pose: { leftHip: 52, leftKnee: 0, leftAnkle: -40, leftShoulder: 125, leftWrist: 60, rightShoulder: 25, rightElbow: -125, rightWrist: 0, headTilt: -8, lookX: -0.9, lookY: -0.4, lean: 6 } },
1470
+ { beat: 3, reset: !0 }
1471
+ ]
1472
+ },
1473
+ alapadma: {
1474
+ label: "Alapadma (lotus) to the sky",
1475
+ beats: 4,
1476
+ keys: [
1477
+ { beat: 0, reset: !0, pose: { rightShoulder: 145, rightElbow: 20, rightWrist: 30, leftShoulder: 28, leftElbow: -125, leftWrist: 0, lookX: 0.7, lookY: -0.9, headTilt: 6 }, hands: { right: "alapadma", left: "pataka" } },
1478
+ { beat: 1, pose: { rightWrist: 55, headTilt: 9 } },
1479
+ { beat: 2, reset: !0, pose: { leftShoulder: 145, leftElbow: 20, leftWrist: 30, rightShoulder: 28, rightElbow: -125, rightWrist: 0, lookX: -0.7, lookY: -0.9, headTilt: -6 }, hands: { left: "alapadma", right: "pataka" } },
1480
+ { beat: 3, pose: { leftWrist: 55, headTilt: -9 } }
1481
+ ]
1482
+ }
1483
+ },
1484
+ routine: [
1485
+ { move: "tatta", beats: 8 },
1486
+ { move: "natta", beats: 8 },
1487
+ { move: "alapadma", beats: 8 },
1488
+ { move: "tatta", beats: 4 }
1489
+ ]
1490
+ }, Po = {
1491
+ label: "Charleston",
1492
+ bpm: 150,
1493
+ stance: { leftHip: 10, rightHip: 10, leftKnee: 10, rightKnee: 10, leftShoulder: 30, rightShoulder: 30, leftElbow: 20, rightElbow: 20 },
1494
+ expression: { mouth: 0.4, smile: 1, leftBrow: 0.5, rightBrow: 0.5 },
1495
+ hands: { left: { ...N.spread, turn: 2 }, right: { ...N.spread, turn: 2 } },
1496
+ groove: { bounce: 8, accent: "down" },
1497
+ moves: {
1498
+ basic: {
1499
+ label: "Kick forward, kick back",
1500
+ beats: 4,
1501
+ keys: [
1502
+ { beat: 0, reset: !0, pose: { rightHip: 48, rightKnee: 8, rightAnkle: 45, leftShoulder: 75, rightShoulder: 15, leftElbow: 30, rightElbow: -10, lean: -7, headTilt: -5 }, easing: q },
1503
+ { beat: 1, reset: !0 },
1504
+ { beat: 2, reset: !0, pose: { leftHip: 18, leftKnee: 85, leftAnkle: 35, rightShoulder: 75, leftShoulder: 15, rightElbow: 30, leftElbow: -10, lean: 7, headTilt: 5 }, easing: q },
1505
+ { beat: 3, reset: !0 }
1506
+ ]
767
1507
  },
768
- shape(d, w, m) {
769
- w !== null && (t.save(), t.globalAlpha *= 0.88, t.fillStyle = w, ft(t, d, !0), t.fill(), t.restore()), m > 0 && y([...d, d[0]], () => m);
1508
+ twist: {
1509
+ label: "Swivel (heels in, heels out)",
1510
+ beats: 2,
1511
+ keys: [
1512
+ // Toes in, knees in: the heels swivel out.
1513
+ { beat: 0, reset: !0, pose: { leftFootOut: -0.9, rightFootOut: -0.9, leftHip: 4, rightHip: 4, leftKnee: 4, rightKnee: 4, leftAnkle: -10, rightAnkle: -10, leftShoulder: 18, rightShoulder: 48, leftElbow: -10, rightElbow: 50 } },
1514
+ // Toes out, knees out: the heels swivel in.
1515
+ { beat: 0.5, pose: { leftFootOut: 0.6, rightFootOut: 0.6, leftHip: 16, rightHip: 16, leftKnee: 22, rightKnee: 22, leftAnkle: 10, rightAnkle: 10, leftShoulder: 48, rightShoulder: 18, leftElbow: 50, rightElbow: -10 } },
1516
+ { beat: 1, pose: { leftFootOut: -0.9, rightFootOut: -0.9, leftHip: 4, rightHip: 4, leftKnee: 4, rightKnee: 4, leftAnkle: -10, rightAnkle: -10, leftShoulder: 18, rightShoulder: 48, leftElbow: -10, rightElbow: 50 } },
1517
+ { beat: 1.5, pose: { leftFootOut: 0.6, rightFootOut: 0.6, leftHip: 16, rightHip: 16, leftKnee: 22, rightKnee: 22, leftAnkle: 10, rightAnkle: 10, leftShoulder: 48, rightShoulder: 18, leftElbow: 50, rightElbow: -10 } }
1518
+ ]
770
1519
  },
771
- ellipse(d, w, m, u, k, E, b) {
772
- E !== null && (t.save(), t.globalAlpha *= 0.9, t.fillStyle = E, t.beginPath(), t.ellipse(d, w, m, u, k, 0, Math.PI * 2), t.fill(), t.restore()), f(d, w, m, u, k, b);
1520
+ kneeCross: {
1521
+ label: "Crossing knees",
1522
+ beats: 2,
1523
+ keys: [
1524
+ // Knees knock together while the hands cross over them…
1525
+ { beat: 0, reset: !0, pose: { leftHip: -6, rightHip: -6, leftKnee: -16, rightKnee: -16, leftFootOut: -0.4, rightFootOut: -0.4, leftShoulder: -12, rightShoulder: -12, leftElbow: 0, rightElbow: 0, lean: 0, lookY: 0.6 } },
1526
+ // …then swing apart, hands open.
1527
+ { beat: 0.5, pose: { leftHip: 18, rightHip: 18, leftKnee: 28, rightKnee: 28, leftFootOut: 0.3, rightFootOut: 0.3, leftShoulder: 16, rightShoulder: 16, lookY: 0 } },
1528
+ { beat: 1, pose: { leftHip: -6, rightHip: -6, leftKnee: -16, rightKnee: -16, leftFootOut: -0.4, rightFootOut: -0.4, leftShoulder: -12, rightShoulder: -12, lookY: 0.6 } },
1529
+ { beat: 1.5, pose: { leftHip: 18, rightHip: 18, leftKnee: 28, rightKnee: 28, leftFootOut: 0.3, rightFootOut: 0.3, leftShoulder: 16, rightShoulder: 16, lookY: 0 } }
1530
+ ]
1531
+ }
1532
+ },
1533
+ routine: [
1534
+ { move: "basic", beats: 8 },
1535
+ { move: "twist", beats: 8 },
1536
+ { move: "kneeCross", beats: 8 },
1537
+ { move: "basic", beats: 8, mirror: !0 },
1538
+ { move: "twist", beats: 4 }
1539
+ ]
1540
+ }, Wo = {
1541
+ label: "Tap",
1542
+ bpm: 120,
1543
+ // Three-quarters to side-on, so shuffles read as brushes forward and back. Side-on,
1544
+ // forward is a positive angle for the right limbs and a negative one for the left.
1545
+ stance: {
1546
+ turn: 0.8,
1547
+ leftHip: -3,
1548
+ rightHip: 3,
1549
+ leftKnee: -10,
1550
+ rightKnee: 10,
1551
+ leftShoulder: 12,
1552
+ rightShoulder: 12,
1553
+ leftElbow: -40,
1554
+ rightElbow: 40,
1555
+ leftWrist: -15,
1556
+ rightWrist: 15,
1557
+ lean: 4
1558
+ },
1559
+ expression: { smile: 0.9, mouth: 0.2, leftBrow: 0.3, rightBrow: 0.3, lookY: 0.3 },
1560
+ hands: { left: "relaxed", right: "relaxed" },
1561
+ groove: { bounce: 6, accent: "down" },
1562
+ moves: {
1563
+ shuffleBallChange: {
1564
+ label: "Shuffle ball change",
1565
+ beats: 2,
1566
+ easing: "ease-out-quad",
1567
+ keys: [
1568
+ // Knee up, the foot brushes forward (toe strikes)…
1569
+ { beat: 0, reset: !0, pose: { rightHip: 34, rightKnee: 8, rightAnkle: 30, leftShoulder: 30, rightShoulder: -10 }, taps: ["rightToe"] },
1570
+ // …and back from the knee (toe strikes again)…
1571
+ { beat: 0.25, pose: { rightHip: 24, rightKnee: 62, rightAnkle: 40 }, taps: ["rightToe"] },
1572
+ // …step on the ball behind, then change weight to the other foot.
1573
+ { beat: 0.5, pose: { rightHip: -8, rightKnee: 14, rightAnkle: 50, leftAnkle: 15, leftShoulder: 12, rightShoulder: 12 }, taps: ["rightToe"] },
1574
+ { beat: 0.75, pose: { rightHip: 3, rightKnee: 10, rightAnkle: 0, leftAnkle: 0 }, taps: ["leftHeel"] },
1575
+ { beat: 1, reset: !0, pose: { leftHip: -34, leftKnee: -8, leftAnkle: 30, rightShoulder: -30, leftShoulder: 10 }, taps: ["leftToe"] },
1576
+ { beat: 1.25, pose: { leftHip: -24, leftKnee: -62, leftAnkle: 40 }, taps: ["leftToe"] },
1577
+ { beat: 1.5, pose: { leftHip: 8, leftKnee: -14, leftAnkle: 50, rightAnkle: 15, leftShoulder: 12, rightShoulder: 12 }, taps: ["leftToe"] },
1578
+ { beat: 1.75, pose: { leftHip: -3, leftKnee: -10, leftAnkle: 0, rightAnkle: 0 }, taps: ["rightHeel"] }
1579
+ ]
773
1580
  },
774
- dot(d, w, m) {
775
- t.save(), t.globalAlpha *= 0.9, t.fillStyle = o, t.beginPath(), t.arc(d, w, m, 0, Math.PI * 2), t.fill(), t.restore();
1581
+ timeStep: {
1582
+ label: "Single time step",
1583
+ beats: 4,
1584
+ easing: "ease-out-quad",
1585
+ keys: [
1586
+ // Stamp the right foot flat…
1587
+ { beat: 0, reset: !0, pose: { rightHip: 8, rightKnee: 4, rightAnkle: 0, leftShoulder: 25, rightShoulder: -20 }, taps: ["rightToe", "rightHeel"] },
1588
+ // …shuffle (brush forward, brush back)…
1589
+ { beat: 0.5, pose: { rightHip: 34, rightKnee: 8, rightAnkle: 30 }, taps: ["rightToe"] },
1590
+ { beat: 0.75, pose: { rightHip: 22, rightKnee: 62, rightAnkle: 40 }, taps: ["rightToe"] },
1591
+ // …hop on the left (up, then land)…
1592
+ { beat: 1, pose: { rise: 0.05, leftAnkle: 45, leftKnee: -4, leftHip: -2, rightHip: 26, rightKnee: 70, stretch: 1.03 } },
1593
+ { beat: 1.25, pose: { rise: 0, leftAnkle: 0, leftKnee: -14, stretch: 1 }, taps: ["leftToe"] },
1594
+ // …step right, flap left (brush forward and step), step right.
1595
+ { beat: 1.5, pose: { rightHip: 4, rightKnee: 12, rightAnkle: 0, rightShoulder: 25, leftShoulder: -20 }, taps: ["rightToe"] },
1596
+ { beat: 2, pose: { leftHip: -30, leftKnee: -6, leftAnkle: 35 }, taps: ["leftToe"] },
1597
+ { beat: 2.25, pose: { leftHip: -4, leftKnee: -12, leftAnkle: 0 }, taps: ["leftToe"] },
1598
+ { beat: 3, pose: { rightHip: 10, rightAnkle: 35, rightKnee: 18, leftShoulder: 12, rightShoulder: 12 }, taps: ["rightToe"] },
1599
+ { beat: 3.5, pose: { rightHip: 3, rightKnee: 10, rightAnkle: 0 } }
1600
+ ]
776
1601
  },
777
- guide(d) {
778
- if (n.construction === !1 || d.length < 2) return;
779
- const w = a++;
780
- g(d, () => Math.max(0.6, e.lineWidth * 0.18), c(w, 0), 0.28, r * 1.2, e.lineWidth);
1602
+ heelToe: {
1603
+ label: "Heel toe",
1604
+ beats: 2,
1605
+ easing: "ease-out-quad",
1606
+ keys: [
1607
+ // Dig the heel in front (toe up), then the toe behind (heel up); the arms swing against the feet.
1608
+ { beat: 0, reset: !0, pose: { rightHip: 26, rightKnee: 0, rightAnkle: -35, leftShoulder: 30, rightShoulder: -20 }, taps: ["rightHeel"] },
1609
+ { beat: 0.5, pose: { rightHip: -16, rightKnee: 24, rightAnkle: 55, leftShoulder: -15, rightShoulder: 25 }, taps: ["rightToe"] },
1610
+ { beat: 1, reset: !0, pose: { leftHip: -26, leftKnee: 0, leftAnkle: -35, rightShoulder: -30, leftShoulder: 20 }, taps: ["leftHeel"] },
1611
+ { beat: 1.5, pose: { leftHip: 16, leftKnee: -24, leftAnkle: 55, rightShoulder: 15, leftShoulder: -25 }, taps: ["leftToe"] }
1612
+ ]
781
1613
  },
782
- guideEllipse(d, w, m, u, k) {
783
- if (n.construction === !1) return;
784
- const E = a++, b = c(E, 0), M = Xt(d, w, m, u, k, b.next() * Math.PI * 2, 1.12, 48);
785
- g(M, () => Math.max(0.6, e.lineWidth * 0.18), b, 0.28, r * 1.5);
1614
+ crampRoll: {
1615
+ label: "Cramp roll",
1616
+ beats: 2,
1617
+ easing: "ease-out-quad",
1618
+ keys: [
1619
+ // Up on both balls, right then left, then the heels drop, right then left: four quick sounds.
1620
+ { beat: 0, reset: !0, pose: { rightHip: 12, rightKnee: 26, leftHip: -12, leftKnee: -26 } },
1621
+ { beat: 0.5, pose: { rightAnkle: 40, rise: 0.02 }, taps: ["rightToe"] },
1622
+ { beat: 0.625, pose: { leftAnkle: 40 }, taps: ["leftToe"] },
1623
+ { beat: 0.75, pose: { rightAnkle: 0, rise: 0 }, taps: ["rightHeel"] },
1624
+ { beat: 0.875, pose: { leftAnkle: 0 }, taps: ["leftHeel"] },
1625
+ // Arms flare on the finish: one up in front, one up behind.
1626
+ { beat: 1, pose: { rightShoulder: 135, leftShoulder: 125, leftElbow: 0, rightElbow: 0, leftWrist: 0, rightWrist: 30, rightKnee: 8, leftKnee: -8, rightHip: 4, leftHip: -4 }, hands: { left: { ...N.spread, turn: 2 }, right: { ...N.spread, turn: 2 } } },
1627
+ { beat: 1.75, reset: !0 }
1628
+ ]
786
1629
  }
787
- };
1630
+ },
1631
+ routine: [
1632
+ { move: "shuffleBallChange", beats: 8 },
1633
+ { move: "timeStep", beats: 4 },
1634
+ { move: "timeStep", beats: 4, mirror: !0 },
1635
+ { move: "heelToe", beats: 8 },
1636
+ { move: "crampRoll", beats: 4 }
1637
+ ]
1638
+ }, $e = {
1639
+ disco: So,
1640
+ hipHop: Eo,
1641
+ breaking: Ho,
1642
+ jazz: Mo,
1643
+ kpop: To,
1644
+ bollywood: vo,
1645
+ bhangra: xo,
1646
+ bharatanatyam: Ko,
1647
+ charleston: Po,
1648
+ tap: Wo
1649
+ }, Ie = (e) => Math.min(1, Math.max(0, e));
1650
+ function Oo(e) {
1651
+ const t = { ...z, turn: e.view }, n = [];
1652
+ for (const r of e.keys) {
1653
+ const o = n[n.length - 1], l = !o || r.reset ? t : o.pose;
1654
+ n.push({ at: r.at, pose: { ...l, ...r.pose }, easing: r.easing });
1655
+ }
1656
+ return n;
788
1657
  }
789
- const tn = 0.34, U = 0.12, L = -0.4, F = (t, e, n) => t[e] ?? n, en = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), nn = 0.45, on = 0.35, sn = 0.7;
790
- function dt(t, e, n) {
791
- const o = (f) => Math.sqrt(Math.max(0, 1 - f.x * f.x - f.y * f.y)), r = de(t, [n.x, n.y, o(n)]).facing, s = t.axes[2], h = Math.atan2(s[0], s[2]), i = Math.cos(h), l = i >= 0 ? 1 : -1, a = l * Math.max(on, Math.abs(i)), c = l * Math.max(sn, Math.abs(i)), g = Math.cos(t.angle), y = Math.sin(t.angle);
792
- return {
793
- facing: r,
794
- points: e.map((f) => {
795
- const d = nn * Math.sin(h) + n.x * a + (f.x - n.x) * c, w = f.y + s[1] * o(f), m = d * t.rx, u = w * t.ry;
796
- return { x: t.center.x + m * g + u * y, y: t.center.y + m * y - u * g };
797
- })
1658
+ function Io(e) {
1659
+ return e - Bo * Math.sin(2 * Math.PI * e) / (2 * Math.PI);
1660
+ }
1661
+ const Bo = 0.5;
1662
+ function $o(e, t) {
1663
+ if (!(t <= e.takeoff || t >= e.landing))
1664
+ return (t - e.takeoff) / (e.landing - e.takeoff);
1665
+ }
1666
+ function Fo(e, t) {
1667
+ const n = typeof e == "string" ? it[e] : e, r = Oo(n), o = Ie(t);
1668
+ let l = 0;
1669
+ for (let u = 0; u < r.length; u++) r[u].at <= o && (l = u);
1670
+ const i = r[l], s = r[Math.min(l + 1, r.length - 1)], h = s.at > i.at ? (o - i.at) / (s.at - i.at) : 0, a = me(i.pose, s.pose, nt(s.easing ?? "ease-in-out")(Ie(h))), f = $o(n, o);
1671
+ return f === void 0 ? { ...a, spin: 0, rise: 0 } : {
1672
+ ...a,
1673
+ spin: n.spin * Io(f),
1674
+ rise: 4 * n.height * f * (1 - f)
798
1675
  };
799
1676
  }
800
- const lt = (t, e, n, o = 12) => Array.from({ length: o + 1 }, (r, s) => {
801
- const h = s / o, i = 1 - h;
802
- return { x: i * i * t.x + 2 * i * h * e.x + h * h * n.x, y: i * i * t.y + 2 * i * h * e.y + h * h * n.y };
803
- }), Mt = (t, e, n, o, r = 16) => Array.from({ length: r }, (s, h) => {
804
- const i = Math.PI * 2 * h / r;
805
- return { x: t + Math.cos(i) * n, y: e + Math.sin(i) * o };
806
- }), Ut = 0.05;
807
- function rn(t, e, n, o) {
808
- const r = Math.max(1, Math.min(o * 0.6, 0.14 * e.rx)), s = (u, k) => dt(e, u, k).points, h = (u, k) => dt(e, [], { x: u, y: k }).facing, i = F(n, "smile", 0), l = F(n, "blink", 0), a = F(n, "lookX", 0), c = F(n, "lookY", 0), g = F(n, "browTilt", 0);
809
- for (const u of [1, -1]) {
810
- const k = u === 1 ? "left" : "right", E = tn * u;
811
- if (h(E, U) < Ut) continue;
812
- const b = { x: E, y: U }, M = en(F(n, `eye.${k}`, 1), l);
813
- if (M < 0.2) {
814
- const H = i > 0.5 ? 0.12 : -0.06;
815
- t.line(s(lt({ x: E - 0.12, y: U }, { x: E, y: U + H }, { x: E + 0.12, y: U }), b), r);
816
- } else {
817
- if (M > 1.2) {
818
- const x = 0.13 * M;
819
- t.shape(s(Mt(E, U, x * 0.85, x), b), "#ffffff", r);
820
- }
821
- const H = M > 1.2 ? 0.075 : 0.1, Y = E + a * 0.08, I = U - c * 0.07;
822
- t.shape(s(Mt(Y, I, H, H * 1.1 * Math.min(M, 1)), b), t.ink, 0);
823
- }
824
- const P = U + 0.3 + F(n, `brow.${k}`, 0) * 0.14 + Math.max(0, M - 1) * 0.12, S = { x: E + u * 0.13, y: P }, W = { x: E - u * 0.13, y: P + g * 0.1 };
825
- t.line(s([S, { x: (S.x + W.x) / 2, y: (S.y + W.y) / 2 }, W], { x: E, y: P }), r);
826
- }
827
- const y = { x: 0, y: L };
828
- if (h(0, L) < -Ut) return;
829
- const f = 0.25 * Math.max(0.3, F(n, "mouthWidth", 1)), d = Math.min(1, Math.max(0, F(n, "mouth", 0)));
830
- if (d <= 0.05) {
831
- t.line(s(lt({ x: -f, y: L }, { x: 0, y: L - i * 0.25 }, { x: f, y: L }), y), r);
832
- return;
1677
+ function _o(e, t, n) {
1678
+ const r = typeof e == "string" ? it[e] : e, o = Ie(t), l = Ie((o - r.takeoff) / (r.landing - r.takeoff));
1679
+ return r.travel * n * l;
1680
+ }
1681
+ function Ir(e, t, n = {}) {
1682
+ const r = typeof t == "string" ? it[t] : t, o = n.start ?? 0, l = n.duration ?? r.duration, i = n.samples ?? 48, s = Array.from({ length: i + 1 }, (f, u) => {
1683
+ const p = u / i;
1684
+ return { time: o + p * l, progress: p, pose: Fo(r, p) };
1685
+ }), a = Object.keys(z).filter((f) => s.some((u) => u.pose[f] !== z[f])).map((f) => ({
1686
+ id: `${e}-${f}`,
1687
+ target: e,
1688
+ property: f,
1689
+ keyframes: s.map((u) => ({ time: u.time, value: u.pose[f] }))
1690
+ }));
1691
+ if (n.height !== void 0 && r.travel !== 0) {
1692
+ const f = (n.facing ?? 1) < 0 ? -1 : 1;
1693
+ a.push({
1694
+ id: `${e}-x`,
1695
+ target: e,
1696
+ property: "x",
1697
+ keyframes: s.map((u) => ({ time: u.time, value: (n.x ?? 0) + f * _o(r, u.progress, n.height) }))
1698
+ });
833
1699
  }
834
- const w = 0.3 * d;
835
- let m;
836
- if (i > 0.3) {
837
- const u = L + 0.05;
838
- m = [...lt({ x: f, y: u }, { x: 0, y: L - w * 2 }, { x: -f, y: u })];
839
- } else if (i < -0.3) {
840
- const u = L - w * 0.6;
841
- m = [...lt({ x: f, y: u }, { x: 0, y: L + w * 1.4 }, { x: -f, y: u })];
842
- } else
843
- m = Mt(0, L, f * 0.8, w);
844
- t.shape(s(m, y), t.ink, 0);
1700
+ return a;
1701
+ }
1702
+ const Ro = {
1703
+ leftHip: -55,
1704
+ leftKnee: -95,
1705
+ rightHip: 55,
1706
+ rightKnee: 95,
1707
+ leftShoulder: 45,
1708
+ rightShoulder: -45,
1709
+ leftElbow: 10,
1710
+ rightElbow: -10,
1711
+ lean: 22,
1712
+ stretch: 0.94,
1713
+ headTilt: 6
1714
+ }, Yo = {
1715
+ leftHip: 0,
1716
+ leftKnee: 0,
1717
+ rightHip: 0,
1718
+ rightKnee: 0,
1719
+ leftAnkle: 55,
1720
+ rightAnkle: 55,
1721
+ leftShoulder: -172,
1722
+ rightShoulder: 172,
1723
+ leftElbow: 0,
1724
+ rightElbow: 0,
1725
+ lean: 0,
1726
+ stretch: 1.08,
1727
+ headTilt: 0
1728
+ }, we = {
1729
+ leftHip: -128,
1730
+ leftKnee: -152,
1731
+ rightHip: 128,
1732
+ rightKnee: 152,
1733
+ leftAnkle: 30,
1734
+ rightAnkle: 30,
1735
+ leftShoulder: -78,
1736
+ rightShoulder: 78,
1737
+ leftElbow: -48,
1738
+ rightElbow: 48,
1739
+ lean: 26,
1740
+ stretch: 1,
1741
+ headTilt: 14
1742
+ }, Lo = {
1743
+ leftHip: -22,
1744
+ leftKnee: -30,
1745
+ rightHip: 22,
1746
+ rightKnee: 30,
1747
+ leftAnkle: 10,
1748
+ rightAnkle: 10,
1749
+ leftShoulder: -125,
1750
+ rightShoulder: 125,
1751
+ leftElbow: 0,
1752
+ rightElbow: 0,
1753
+ lean: 8,
1754
+ headTilt: 0
1755
+ }, No = {
1756
+ leftHip: -58,
1757
+ leftKnee: -100,
1758
+ rightHip: 58,
1759
+ rightKnee: 100,
1760
+ leftAnkle: 0,
1761
+ rightAnkle: 0,
1762
+ leftShoulder: -80,
1763
+ rightShoulder: 80,
1764
+ leftElbow: -10,
1765
+ rightElbow: 10,
1766
+ lean: 20,
1767
+ stretch: 0.93
1768
+ };
1769
+ function he(e, t, n, r, o, l = 1300) {
1770
+ return {
1771
+ label: e,
1772
+ view: 1,
1773
+ spin: t,
1774
+ height: n,
1775
+ travel: r,
1776
+ takeoff: 0.27,
1777
+ landing: 0.8,
1778
+ duration: l,
1779
+ keys: [
1780
+ { at: 0, reset: !0 },
1781
+ { at: 0.16, pose: Ro },
1782
+ { at: 0.27, pose: Yo, easing: "ease-out-quad" },
1783
+ ...o,
1784
+ { at: 0.76, pose: Lo },
1785
+ { at: 0.86, pose: No, easing: "ease-out-quad" },
1786
+ { at: 1, reset: !0 }
1787
+ ]
1788
+ };
845
1789
  }
846
- const kt = 0.215, Et = 0.205, ln = 0.065, Kt = 0.035, hn = 0.165, an = 0.155, cn = 12, K = {
1790
+ const it = {
1791
+ frontFlip: he("Front flip (tuck)", 360, 0.56, 0.35, [
1792
+ { at: 0.38, pose: we, easing: "ease-out-cubic" },
1793
+ { at: 0.64, pose: we }
1794
+ ]),
1795
+ backFlip: he("Back flip (tuck)", -360, 0.58, -0.15, [
1796
+ { at: 0.36, pose: { ...we, lean: 18 }, easing: "ease-out-cubic" },
1797
+ { at: 0.64, pose: { ...we, lean: 18 } }
1798
+ ]),
1799
+ layout: he("Back layout (straight body)", -360, 0.66, -0.2, [
1800
+ // Arched, arms overhead, legs together and long.
1801
+ { at: 0.4, pose: { leftHip: 8, rightHip: -8, leftKnee: 0, rightKnee: 0, leftAnkle: 60, rightAnkle: 60, leftShoulder: -178, rightShoulder: 178, lean: -18, headTilt: -14 } },
1802
+ { at: 0.64, pose: { leftHip: -4, rightHip: 4, lean: -6, headTilt: -4, leftShoulder: -150, rightShoulder: 150 } }
1803
+ ], 1400),
1804
+ scissorFlip: he("Scissor flip", 360, 0.6, 0.45, [
1805
+ // The legs scissor through the turn: left kicks high, then they switch.
1806
+ { at: 0.36, pose: { leftHip: -105, leftKnee: 0, rightHip: -40, rightKnee: -20, leftAnkle: 50, rightAnkle: 50, leftShoulder: -150, rightShoulder: 150, leftElbow: 0, rightElbow: 0, lean: 12 }, easing: "ease-out-cubic" },
1807
+ { at: 0.52, pose: { leftHip: 40, leftKnee: 20, rightHip: 105, rightKnee: 0, leftShoulder: -140, rightShoulder: 140 } },
1808
+ { at: 0.66, pose: { leftHip: -30, leftKnee: -20, rightHip: 30, rightKnee: 20, leftShoulder: -110, rightShoulder: 110, lean: 6 } }
1809
+ ]),
1810
+ sideFlip: {
1811
+ label: "Side flip (tuck)",
1812
+ view: 0,
1813
+ spin: 360,
1814
+ height: 0.55,
1815
+ travel: 0.4,
1816
+ takeoff: 0.27,
1817
+ landing: 0.8,
1818
+ duration: 1300,
1819
+ keys: [
1820
+ { at: 0, reset: !0 },
1821
+ { at: 0.16, pose: { leftHip: 22, rightHip: 22, leftKnee: 44, rightKnee: 44, leftShoulder: 20, rightShoulder: 20, lean: -10, stretch: 0.94 } },
1822
+ { at: 0.27, pose: { leftHip: 4, rightHip: 4, leftKnee: 0, rightKnee: 0, leftAnkle: 55, rightAnkle: 55, leftShoulder: 165, rightShoulder: 165, lean: 6, stretch: 1.08 }, easing: "ease-out-quad" },
1823
+ { at: 0.38, pose: { leftHip: 105, rightHip: 105, leftKnee: 135, rightKnee: 135, leftShoulder: 40, rightShoulder: 40, leftElbow: -95, rightElbow: -95, lean: 0, stretch: 1, headTilt: 10 }, easing: "ease-out-cubic" },
1824
+ { at: 0.64, pose: {} },
1825
+ { at: 0.76, pose: { leftHip: 20, rightHip: 20, leftKnee: 20, rightKnee: 20, leftAnkle: 10, rightAnkle: 10, leftShoulder: 100, rightShoulder: 100, leftElbow: 0, rightElbow: 0, headTilt: 0 } },
1826
+ { at: 0.86, pose: { leftHip: 24, rightHip: 24, leftKnee: 48, rightKnee: 48, leftAnkle: 0, rightAnkle: 0, leftShoulder: 70, rightShoulder: 70, stretch: 0.93 }, easing: "ease-out-quad" },
1827
+ { at: 1, reset: !0 }
1828
+ ]
1829
+ },
1830
+ cartwheel: {
1831
+ label: "Cartwheel",
1832
+ view: 0,
1833
+ spin: 360,
1834
+ // Upside down half way round, the hands (arms overhead) just reach the ground.
1835
+ height: 0.155,
1836
+ travel: 0.9,
1837
+ takeoff: 0.2,
1838
+ landing: 0.86,
1839
+ duration: 1600,
1840
+ keys: [
1841
+ { at: 0, reset: !0 },
1842
+ { at: 0.12, pose: { leftShoulder: 165, rightShoulder: 165, rightHip: 30, rightKnee: 0, lean: -6 } },
1843
+ { at: 0.24, pose: { leftShoulder: 172, rightShoulder: 172, leftHip: 55, rightHip: 55, leftKnee: 0, rightKnee: 0, leftAnkle: 40, rightAnkle: 40, lean: 0 } },
1844
+ { at: 0.75, pose: {} },
1845
+ { at: 0.9, pose: { leftHip: 30, rightHip: 12, leftAnkle: 0, rightAnkle: 0, leftShoulder: 150, rightShoulder: 150 } },
1846
+ { at: 1, reset: !0 }
1847
+ ]
1848
+ },
1849
+ // Leaps: no turn, the shape is the trick.
1850
+ splitLeap: he("Split leap (grand jeté)", 0, 0.36, 0.9, [
1851
+ // A front split in the air: front leg reaching, back leg long, arms open.
1852
+ { at: 0.4, pose: { leftHip: -96, rightHip: -84, leftKnee: 0, rightKnee: 0, leftAnkle: 55, rightAnkle: 55, leftShoulder: -130, rightShoulder: -105, leftElbow: 0, rightElbow: 0, lean: 4, headTilt: -6 }, easing: "ease-out-cubic" },
1853
+ { at: 0.64, pose: { lean: 2 } }
1854
+ ]),
1855
+ toeTouch: {
1856
+ label: "Toe touch (straddle jump)",
1857
+ view: 0,
1858
+ spin: 0,
1859
+ height: 0.36,
1860
+ travel: 0,
1861
+ takeoff: 0.27,
1862
+ landing: 0.8,
1863
+ duration: 1200,
1864
+ keys: [
1865
+ { at: 0, reset: !0 },
1866
+ { at: 0.16, pose: { leftHip: 22, rightHip: 22, leftKnee: 44, rightKnee: 44, leftShoulder: -20, rightShoulder: -20, stretch: 0.94 } },
1867
+ { at: 0.27, pose: { leftHip: 4, rightHip: 4, leftKnee: 0, rightKnee: 0, leftAnkle: 55, rightAnkle: 55, leftShoulder: 170, rightShoulder: 170, stretch: 1.06 }, easing: "ease-out-quad" },
1868
+ // Legs straddled up past level, hands reaching out toward the toes.
1869
+ { at: 0.42, pose: { leftHip: 104, rightHip: 104, leftShoulder: 96, rightShoulder: 96, leftElbow: 0, rightElbow: 0, stretch: 1, headTilt: 0 }, easing: "ease-out-cubic" },
1870
+ { at: 0.62, pose: {} },
1871
+ { at: 0.76, pose: { leftHip: 12, rightHip: 12, leftAnkle: 10, rightAnkle: 10, leftShoulder: 120, rightShoulder: 120 } },
1872
+ { at: 0.86, pose: { leftHip: 22, rightHip: 22, leftKnee: 44, rightKnee: 44, leftAnkle: 0, rightAnkle: 0, leftShoulder: 60, rightShoulder: 60, stretch: 0.94 }, easing: "ease-out-quad" },
1873
+ { at: 1, reset: !0 }
1874
+ ]
1875
+ },
1876
+ backHandspring: he("Back handspring", -360, 0.16, -0.7, [
1877
+ // Arms reach back overhead to the ground, legs snap over.
1878
+ { at: 0.38, pose: { leftHip: 10, rightHip: -10, leftKnee: 0, rightKnee: 0, leftShoulder: -178, rightShoulder: 178, lean: -26, headTilt: -20 } },
1879
+ { at: 0.6, pose: { leftHip: -40, rightHip: 40, leftKnee: -20, rightKnee: 20, lean: 6, headTilt: 0 } }
1880
+ ], 1200)
1881
+ }, Le = 0.215, Ne = 0.205, Co = 0.065, Mt = 0.035, Do = 0.165, qo = 0.155, Xo = 12, Uo = (e) => e * Math.PI / 180, te = {
847
1882
  turn: 0,
848
1883
  lean: 0,
849
1884
  side: 0,
@@ -862,10 +1897,14 @@ const kt = 0.215, Et = 0.205, ln = 0.065, Kt = 0.035, hn = 0.165, an = 0.155, cn
862
1897
  "leg.left.spread": 3,
863
1898
  "leg.left.knee": 0,
864
1899
  "leg.left.ankle": 0,
1900
+ "leg.left.toeOut": 0,
1901
+ "leg.left.rotate": 0,
865
1902
  "leg.right.swing": 0,
866
1903
  "leg.right.spread": 3,
867
1904
  "leg.right.knee": 0,
868
1905
  "leg.right.ankle": 0,
1906
+ "leg.right.toeOut": 0,
1907
+ "leg.right.rotate": 0,
869
1908
  stretch: 1,
870
1909
  lift: 0,
871
1910
  roll: 0,
@@ -881,24 +1920,24 @@ const kt = 0.215, Et = 0.205, ln = 0.065, Kt = 0.035, hn = 0.165, an = 0.155, cn
881
1920
  lookX: 0,
882
1921
  lookY: 0
883
1922
  };
884
- function R(t = {}) {
885
- return { ...K, ...t };
1923
+ function G(e = {}) {
1924
+ return { ...te, ...e };
886
1925
  }
887
- function $(t, e) {
1926
+ function U(e, t) {
888
1927
  const n = {};
889
- for (const o of ["left", "right"]) for (const [r, s] of Object.entries(e)) n[`${t}.${o}.${r}`] = s;
1928
+ for (const r of ["left", "right"]) for (const [o, l] of Object.entries(t)) n[`${e}.${r}.${o}`] = l;
890
1929
  return n;
891
1930
  }
892
- const fn = {
893
- rest: K,
894
- wave: R({ "arm.right.spread": 115, "arm.right.bend": 55, "arm.right.elbow": 0, "head.tilt": -6, smile: 0.9 }),
895
- cheer: R({ ...$("arm", { spread: 140, bend: 20, elbow: 0 }), mouth: 0.6, smile: 1, "eye.left": 0, "eye.right": 0 }),
896
- point: R({ "arm.right.spread": 88, "arm.right.elbow": 0, "arm.right.bend": 0, "head.turn": -20, smile: 0.4 }),
897
- handsOnHips: R({ ...$("arm", { spread: 50, bend: -105, elbow: 0 }), ...$("leg", { spread: 9 }), smile: 0.8 }),
898
- think: R({ "arm.right.spread": 22, "arm.right.bend": -150, "arm.right.elbow": 0, "head.tilt": 10, lookX: -0.5, lookY: -0.8, smile: 0 }),
899
- shrug: R({ ...$("arm", { spread: 35, bend: 75, elbow: 0 }), "head.tilt": -10, smile: -0.2 }),
900
- sit: R({ ...$("leg", { swing: 90, knee: 90, spread: 4 }), ...$("arm", { swing: 25, elbow: 45, spread: 8 }) }),
901
- kneel: R({
1931
+ const zo = {
1932
+ rest: te,
1933
+ wave: G({ "arm.right.spread": 115, "arm.right.bend": 55, "arm.right.elbow": 0, "head.tilt": -6, smile: 0.9 }),
1934
+ cheer: G({ ...U("arm", { spread: 140, bend: 20, elbow: 0 }), mouth: 0.6, smile: 1, "eye.left": 0, "eye.right": 0 }),
1935
+ point: G({ "arm.right.spread": 88, "arm.right.elbow": 0, "arm.right.bend": 0, "head.turn": -20, smile: 0.4 }),
1936
+ handsOnHips: G({ ...U("arm", { spread: 50, bend: -105, elbow: 0 }), ...U("leg", { spread: 9 }), smile: 0.8 }),
1937
+ think: G({ "arm.right.spread": 22, "arm.right.bend": -150, "arm.right.elbow": 0, "head.tilt": 10, lookX: -0.5, lookY: -0.8, smile: 0 }),
1938
+ shrug: G({ ...U("arm", { spread: 35, bend: 75, elbow: 0 }), "head.tilt": -10, smile: -0.2 }),
1939
+ sit: G({ ...U("leg", { swing: 90, knee: 90, spread: 4 }), ...U("arm", { swing: 25, elbow: 45, spread: 8 }) }),
1940
+ kneel: G({
902
1941
  "leg.left.swing": 90,
903
1942
  "leg.left.knee": 90,
904
1943
  // The back thigh leans back a little so its knee meets the ground beside the
@@ -906,111 +1945,114 @@ const fn = {
906
1945
  "leg.right.swing": -18,
907
1946
  "leg.right.knee": 108,
908
1947
  "leg.right.ankle": 16,
909
- ...$("arm", { swing: 20, elbow: 30 })
1948
+ ...U("arm", { swing: 20, elbow: 30 })
910
1949
  }),
911
- crouch: R({ ...$("leg", { swing: 75, knee: 140, spread: 6 }), lean: 25, ...$("arm", { swing: 50, elbow: 40 }), "head.nod": -15 }),
1950
+ crouch: G({ ...U("leg", { swing: 75, knee: 140, spread: 6 }), lean: 25, ...U("arm", { swing: 50, elbow: 40 }), "head.nod": -15 }),
912
1951
  // On hands and knees: the back nearly level, arms straight down, the toes
913
1952
  // pointed back along the ground.
914
- crawl: R({ lean: 82, "head.nod": -35, ...$("arm", { swing: 80, elbow: 0, spread: 4 }), ...$("leg", { knee: 92, ankle: -88 }) }),
915
- lieDown: R({ roll: 90, ...$("arm", { spread: 8 }), "head.nod": 0 })
1953
+ crawl: G({ lean: 82, "head.nod": -35, ...U("arm", { swing: 80, elbow: 0, spread: 4 }), ...U("leg", { knee: 92, ankle: -88 }) }),
1954
+ lieDown: G({ roll: 90, ...U("arm", { spread: 8 }), "head.nod": 0 })
916
1955
  };
917
- function dn(t = {}) {
918
- const e = t.headSize ?? 0.3, n = t.shoulderWidth ?? 0.06, o = t.hipWidth ?? 0.022, r = Math.max(0.12, 1 - e - Kt - (kt + Et)), s = (l) => ({
919
- id: `arm.${l}`,
1956
+ function Go(e = {}) {
1957
+ const t = e.headSize ?? 0.3, n = e.shoulderWidth ?? 0.06, r = e.hipWidth ?? 0.022, o = Math.max(0.12, 1 - t - Mt - (Le + Ne)), l = (h) => ({
1958
+ id: `arm.${h}`,
920
1959
  parent: "spine",
921
- offset: [(l === "left" ? 1 : -1) * n, -0.035, 0],
1960
+ offset: [(h === "left" ? 1 : -1) * n, -0.035, 0],
922
1961
  rest: [0, -1, 0],
923
- side: l === "left" ? 1 : -1,
1962
+ side: h === "left" ? 1 : -1,
924
1963
  bones: [
925
- { length: hn, width: [1.25, 0.9] },
926
- { length: an, width: [0.9, 0.75] }
1964
+ { length: Do, width: [1.25, 0.9] },
1965
+ { length: qo, width: [0.9, 0.75] }
927
1966
  ]
928
- }), h = (l) => ({
929
- id: `leg.${l}`,
1967
+ }), i = (h) => ({
1968
+ id: `leg.${h}`,
930
1969
  parent: null,
931
- offset: [(l === "left" ? 1 : -1) * o, 0, 0],
1970
+ offset: [(h === "left" ? 1 : -1) * r, 0, 0],
932
1971
  rest: [0, -1, 0],
933
- side: l === "left" ? 1 : -1,
1972
+ side: h === "left" ? 1 : -1,
934
1973
  bones: [
935
- { length: kt, width: [1.45, 1.05] },
936
- { length: Et, width: [1.05, 0.85] },
937
- { length: ln, width: [0.95, 0.7] }
1974
+ { length: Le, width: [1.45, 1.05] },
1975
+ { length: Ne, width: [1.05, 0.85] },
1976
+ { length: Co, width: [0.95, 0.7] }
938
1977
  ]
939
- }), i = (l, a) => l[a] ?? K[a] ?? 0;
1978
+ }), s = (h, a) => h[a] ?? te[a] ?? 0;
940
1979
  return {
941
1980
  id: "human",
942
- hipHeight: kt + Et,
1981
+ hipHeight: Le + Ne,
943
1982
  // Tie order: legs, then the body, then the arms (in front of the chest unless turned away), then the head.
944
1983
  chains: [
945
- h("left"),
946
- h("right"),
1984
+ i("left"),
1985
+ i("right"),
947
1986
  {
948
1987
  id: "spine",
949
1988
  parent: null,
950
1989
  rest: [0, 1, 0],
951
1990
  bones: [
952
- { length: r / 2, width: [1.7, 1.4] },
953
- { length: r / 2, width: [1.4, 1.1] }
1991
+ { length: o / 2, width: [1.7, 1.4] },
1992
+ { length: o / 2, width: [1.4, 1.1] }
954
1993
  ]
955
1994
  },
956
- { id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length: Kt, width: [1, 0.9] }] },
957
- s("left"),
958
- s("right")
1995
+ { id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length: Mt, width: [1, 0.9] }] },
1996
+ l("left"),
1997
+ l("right")
959
1998
  ],
960
- head: { on: "neck", size: e },
1999
+ head: { on: "neck", size: t },
961
2000
  contacts: [
962
- ...["left", "right"].flatMap((l) => [
963
- { chain: `leg.${l}`, joint: 1 },
964
- { chain: `leg.${l}`, joint: 2 },
965
- { chain: `leg.${l}`, joint: 3 },
966
- { chain: `arm.${l}`, joint: 1 },
967
- { chain: `arm.${l}`, joint: 2 }
2001
+ ...["left", "right"].flatMap((h) => [
2002
+ { chain: `leg.${h}`, joint: 1 },
2003
+ { chain: `leg.${h}`, joint: 2 },
2004
+ { chain: `leg.${h}`, joint: 3 },
2005
+ { chain: `arm.${h}`, joint: 1 },
2006
+ { chain: `arm.${h}`, joint: 2 }
968
2007
  ]),
969
2008
  { chain: "spine", joint: 0 },
970
2009
  { chain: "spine", joint: 1 },
971
2010
  { chain: "spine", joint: 2 },
972
2011
  { head: "top" }
973
2012
  ],
974
- angles(l, a) {
2013
+ angles(h, a) {
975
2014
  if (a.id === "spine") {
976
- const f = -i(l, "lean") / 2, d = i(l, "side") / 2;
2015
+ const d = -s(h, "lean") / 2, b = s(h, "side") / 2;
977
2016
  return [
978
- { swing: f, spread: d },
979
- { swing: f, spread: d }
2017
+ { swing: d, spread: b },
2018
+ { swing: d, spread: b }
980
2019
  ];
981
2020
  }
982
2021
  if (a.id === "neck") return [{ swing: 0, spread: 0 }];
983
- const [c, g] = a.id.split("."), y = (f) => i(l, `${c}.${g}.${f}`);
984
- return c === "arm" ? [
985
- { swing: y("swing"), spread: y("spread") },
986
- { swing: y("elbow"), spread: y("bend") }
987
- ] : [
988
- { swing: y("swing"), spread: y("spread") },
989
- { swing: -y("knee"), spread: 0 },
990
- // The foot points forward, square to the shin, turned out a little.
991
- { swing: 90 + y("ankle"), spread: 0, yaw: cn * (a.side ?? 1) }
2022
+ const [f, u] = a.id.split("."), p = (d) => s(h, `${f}.${u}.${d}`);
2023
+ if (f === "arm")
2024
+ return [
2025
+ { swing: p("swing"), spread: p("spread") },
2026
+ { swing: p("elbow"), spread: p("bend") }
2027
+ ];
2028
+ const c = (a.side ?? 1) * p("rotate"), g = 1 - Math.cos(Uo(p("rotate")));
2029
+ return [
2030
+ { swing: p("swing"), spread: p("spread"), yaw: c },
2031
+ { swing: -p("knee"), spread: 0, yaw: c },
2032
+ // The foot points forward, square to the shin, turned out a little (more with `toeOut`).
2033
+ { swing: 90 + p("ankle") - g * (p("swing") - p("knee")), spread: 0, yaw: (Xo + p("toeOut")) * (a.side ?? 1) }
992
2034
  ];
993
2035
  },
994
- withAngles(l, a, c) {
995
- const [g, y] = a.id.split("."), f = (d) => `${g}.${y}.${d}`;
996
- return g === "arm" ? {
997
- ...l,
998
- [f("swing")]: c[0].swing,
999
- [f("spread")]: c[0].spread,
1000
- [f("elbow")]: c[1].swing,
1001
- [f("bend")]: c[1].spread
1002
- } : g === "leg" ? { ...l, [f("swing")]: c[0].swing, [f("spread")]: c[0].spread, [f("knee")]: -c[1].swing } : l;
2036
+ withAngles(h, a, f) {
2037
+ const [u, p] = a.id.split("."), c = (g) => `${u}.${p}.${g}`;
2038
+ return u === "arm" ? {
2039
+ ...h,
2040
+ [c("swing")]: f[0].swing,
2041
+ [c("spread")]: f[0].spread,
2042
+ [c("elbow")]: f[1].swing,
2043
+ [c("bend")]: f[1].spread
2044
+ } : u === "leg" ? { ...h, [c("swing")]: f[0].swing, [c("spread")]: f[0].spread, [c("knee")]: -f[1].swing } : h;
1003
2045
  },
1004
- boneScale(l, a) {
1005
- const c = Math.min(3, Math.max(0.3, i(l, "stretch")));
1006
- return a?.id.startsWith("arm.") ? Math.sqrt(c) : c;
2046
+ boneScale(h, a) {
2047
+ const f = Math.min(3, Math.max(0.3, s(h, "stretch")));
2048
+ return a?.id.startsWith("arm.") ? Math.sqrt(f) : f;
1007
2049
  },
1008
- headPose(l) {
1009
- const a = Math.min(3, Math.max(0.3, i(l, "stretch")));
2050
+ headPose(h) {
2051
+ const a = Math.min(3, Math.max(0.3, s(h, "stretch")));
1010
2052
  return {
1011
- yaw: i(l, "head.turn"),
1012
- nod: i(l, "head.nod"),
1013
- tilt: i(l, "head.tilt"),
2053
+ yaw: s(h, "head.turn"),
2054
+ nod: s(h, "head.nod"),
2055
+ tilt: s(h, "head.tilt"),
1014
2056
  // The head keeps its area: taller and narrower when stretched.
1015
2057
  sx: 1 / Math.sqrt(a),
1016
2058
  sy: Math.sqrt(a)
@@ -1035,18 +2077,24 @@ function dn(t = {}) {
1035
2077
  }
1036
2078
  };
1037
2079
  }
1038
- function $n(t) {
1039
- const e = t.split(".");
1040
- if (e.length === 3) {
1041
- const [o, r, s] = e;
1042
- return `${`${r === "left" ? "Left" : "Right"} ${o}`} · ${{
2080
+ function Br(e) {
2081
+ const t = e.split(".");
2082
+ if (t[0] === "hand" && t.length >= 3) {
2083
+ const r = `${t[1] === "left" ? "Left" : "Right"} hand`, o = { spread: "finger spread", turn: "wrist turn", bend: "wrist bend", tilt: "wrist tilt", roll: "roll" }, l = t.slice(2).join(".");
2084
+ return `${r} · ${o[l] ?? l.replace(".curl", " curl").replace(".across", " across")}`;
2085
+ }
2086
+ if (t.length === 3) {
2087
+ const [r, o, l] = t;
2088
+ return `${`${o === "left" ? "Left" : "Right"} ${r}`} · ${{
1043
2089
  swing: "forward / back",
1044
2090
  spread: "out / in",
1045
2091
  elbow: "elbow bend",
1046
2092
  bend: "forearm out / in",
1047
2093
  knee: "knee bend",
1048
- ankle: "foot tilt"
1049
- }[s] ?? s}`;
2094
+ ankle: "foot tilt",
2095
+ toeOut: "toes out / in",
2096
+ rotate: "turn out at the hip"
2097
+ }[l] ?? l}`;
1050
2098
  }
1051
2099
  return {
1052
2100
  turn: "View (front → side → back)",
@@ -1069,292 +2117,714 @@ function $n(t) {
1069
2117
  browTilt: "Brow slant",
1070
2118
  lookX: "Look left / right",
1071
2119
  lookY: "Look up / down"
1072
- }[t] ?? t;
2120
+ }[e] ?? e;
1073
2121
  }
1074
- const un = {
2122
+ const Jo = {
1075
2123
  leftEye: "eye.left",
1076
2124
  rightEye: "eye.right",
1077
2125
  leftBrow: "brow.left",
1078
2126
  rightBrow: "brow.right"
1079
- }, Bn = Object.fromEntries(
1080
- Object.entries(N).map(([t, e]) => [
1081
- t,
1082
- Object.fromEntries(Object.entries(e).map(([n, o]) => [un[n] ?? n, o]))
2127
+ }, $r = Object.fromEntries(
2128
+ Object.entries(J).map(([e, t]) => [
2129
+ e,
2130
+ Object.fromEntries(Object.entries(t).map(([n, r]) => [Jo[n] ?? n, r]))
1083
2131
  ])
1084
2132
  );
1085
- function Rn(t = {}) {
1086
- const e = (t.proportions ?? "bold") === "bold", n = t.figure ?? "fluid", o = t.look ?? "clean", r = t.height ?? 300, s = n === "stick";
2133
+ function Fr(e, t) {
2134
+ const n = Math.min(1, Math.max(0, e.turn ?? 0)), r = 1 - n, o = { ...te, turn: n }, l = [
2135
+ { stick: "right", human: "left", s: 1 },
2136
+ { stick: "left", human: "right", s: -1 }
2137
+ ];
2138
+ for (const { stick: i, human: s, s: h } of l) {
2139
+ const a = e[`${i}Shoulder`], f = e[`${i}Elbow`];
2140
+ o[`arm.${s}.spread`] = a * r, o[`arm.${s}.swing`] = h * a * n, o[`arm.${s}.bend`] = f * r, o[`arm.${s}.elbow`] = h * f * n;
2141
+ const u = e[`${i}Hip`], p = e[`${i}Knee`], c = r + h * n;
2142
+ o[`leg.${s}.rotate`] = 90 * r, o[`leg.${s}.spread`] = 0, o[`leg.${s}.swing`] = u * c, o[`leg.${s}.knee`] = p * c, o[`leg.${s}.ankle`] = -(e[`${i}Ankle`] ?? 0), o[`leg.${s}.toeOut`] = (e[`${i}FootOut`] ?? 0) * Zo, o[`eye.${s}`] = e[`${i}Eye`], o[`brow.${s}`] = e[`${i}Brow`], t && Object.assign(o, jo(s, t[i] ?? R, e[`${i}Wrist`] ?? 0, n));
2143
+ }
2144
+ o.lean = e.lean * n, o.side = e.lean * r, o["head.tilt"] = e.headTilt * r, o["head.nod"] = e.headTilt * n;
2145
+ for (const i of ["mouth", "smile", "mouthWidth", "blink", "browTilt", "lookX", "lookY", "stretch"]) o[i] = e[i];
2146
+ return o.lift = e.rise ?? 0, o.roll = e.spin ?? 0, o;
2147
+ }
2148
+ const Zo = 70;
2149
+ function jo(e, t, n, r) {
2150
+ const o = e === "right" ? 1 - r : 1 + r, l = {};
2151
+ for (const i of Object.keys(R)) l[`hand.${e}.${i}`] = t[i] ?? R[i];
2152
+ return l[`hand.${e}.turn`] = (t.turn ?? 0) - o, l[`hand.${e}.roll`] = (t.roll ?? 0) + n, l;
2153
+ }
2154
+ function Qo(e, t, n = {}, r) {
2155
+ const o = n.length ?? 240, l = 9, i = 28, s = o - 22;
2156
+ e.save(), e.translate(t.x, t.y), e.rotate((n.angle ?? -30) * Math.PI / 180), e.fillStyle = n.color ?? "#f4c542", e.fillRect(i, -l, s - i, 2 * l), e.fillStyle = "#e8b4a0", e.fillRect(s, -l, o - s, 2 * l), e.fillStyle = "#f1dcbf", e.beginPath(), e.moveTo(0, 0), e.lineTo(i, -l), e.lineTo(i, l), e.closePath(), e.fill(), e.fillStyle = n.outline ?? "#2f2f33", e.beginPath(), e.moveTo(0, 0), e.lineTo(i * 0.35, -l * 0.35), e.lineTo(i * 0.35, l * 0.35), e.closePath(), e.fill(), e.strokeStyle = n.outline ?? "#2f2f33", e.lineWidth = 3, e.lineJoin = "round", e.lineCap = "round";
2157
+ const h = [
2158
+ [{ x: 0, y: 0 }, { x: i, y: -l }, { x: o, y: -l }, { x: o, y: l }, { x: i, y: l }, { x: 0, y: 0 }],
2159
+ [{ x: i, y: -l }, { x: i, y: l }],
2160
+ [{ x: s, y: -l }, { x: s, y: l }]
2161
+ ];
2162
+ for (const a of h) Zt(e, a, r);
2163
+ e.restore();
2164
+ }
2165
+ function zt(e, t, n = {}, r) {
2166
+ const o = n.length ?? 90, l = n.thickness ?? 34;
2167
+ e.save(), e.translate(t.x, t.y), e.rotate((n.angle ?? -35) * Math.PI / 180);
2168
+ const i = -l / 2;
2169
+ e.fillStyle = n.color ?? "#f4a7b9", e.fillRect(0, i, o, l), e.fillStyle = "#e9edf2", e.fillRect(o * 0.45, i, o * 0.55, l), e.strokeStyle = n.outline ?? "#2f2f33", e.lineWidth = 3, e.lineJoin = "round";
2170
+ const s = [
2171
+ { x: 0, y: i },
2172
+ { x: o, y: i },
2173
+ { x: o, y: -i },
2174
+ { x: 0, y: -i },
2175
+ { x: 0, y: i }
2176
+ ], h = [{ x: o * 0.45, y: i }, { x: o * 0.45, y: -i }];
2177
+ if (r)
2178
+ r.line(s), r.line(h);
2179
+ else
2180
+ for (const a of [s, h]) {
2181
+ e.beginPath(), e.moveTo(a[0].x, a[0].y);
2182
+ for (const f of a.slice(1)) e.lineTo(f.x, f.y);
2183
+ e.stroke();
2184
+ }
2185
+ e.restore();
2186
+ }
2187
+ const Gt = 150, Vo = { pencil: 44, eraser: 30 };
2188
+ function Jt(e, t, n = {}, r) {
2189
+ const o = n.tool ?? "pencil", l = n.skin ?? "#f1c9a5", i = n.outline ?? "#2f2f33", s = n.scale ?? 1, h = Math.min(1, Math.max(0, n.lift ?? 0)), a = (n.angle ?? -30) * Math.PI / 180, f = r ? r.nudge(0.6) : { x: 0, y: 0 }, u = Gt * s * (1 + 0.05 * h);
2190
+ h > 0 && (e.save(), e.fillStyle = i, e.globalAlpha = 0.15 * h, e.beginPath(), e.ellipse(t.x, t.y, 9 * s, 4 * s, 0, 0, Math.PI * 2), e.fill(), e.restore());
2191
+ const p = { x: t.x + f.x + 6 * h * s, y: t.y + f.y - 18 * h * s }, c = N.pencilGrip, g = (E) => {
2192
+ const v = E.fingers.thumb, A = E.fingers.index, I = E.fingers.middle, W = Tt([v.points[3], A.points[3], I.points[3]]), M = Tt([v.points[1], A.points[0]]), y = (v.depths[3] + A.depths[3] + I.depths[3]) / 3;
2193
+ return { pinch: W, direction: Math.atan2(M.y - W.y, M.x - W.x), depth: y };
2194
+ }, d = Je(c, { size: u }), b = a - g(d).direction, m = Je(c, { size: u, angle: b * 180 / Math.PI }), S = g(m), k = Vo[o] * s, T = { x: S.pinch.x - Math.cos(a) * k, y: S.pinch.y - Math.sin(a) * k }, H = { x: p.x - T.x, y: p.y - T.y }, w = m.axes.up;
2195
+ er(e, H, { x: -w.x, y: -w.y }, u, n.arm ?? 300 * s, l, n.sleeve ?? "#5b7db1", i), rt(e, H, c, {
2196
+ size: u,
2197
+ angle: b * 180 / Math.PI,
2198
+ skin: l,
2199
+ ink: i,
2200
+ lineWidth: 3 * s,
2201
+ prop: {
2202
+ depth: S.depth,
2203
+ draw: () => {
2204
+ e.save(), e.translate(p.x, p.y), e.scale(s, s), o === "eraser" ? zt(e, { x: 0, y: 0 }, { angle: a * 180 / Math.PI, outline: i }, r) : Qo(e, { x: 0, y: 0 }, { angle: a * 180 / Math.PI, length: 190, outline: i }, r), e.restore();
2205
+ }
2206
+ }
2207
+ });
2208
+ }
2209
+ const Tt = (e) => ({
2210
+ x: e.reduce((t, n) => t + n.x, 0) / e.length,
2211
+ y: e.reduce((t, n) => t + n.y, 0) / e.length
2212
+ });
2213
+ function er(e, t, n, r, o, l, i, s) {
2214
+ const h = { x: -n.y, y: n.x }, a = r * 0.15, f = (d, b, m) => ({
2215
+ x: t.x + n.x * d + h.x * b * m,
2216
+ y: t.y + n.y * d + h.y * b * m
2217
+ }), u = f(o, 0, 0), p = (d) => {
2218
+ const b = e.createLinearGradient(t.x, t.y, u.x, u.y);
2219
+ return b.addColorStop(0, d), b.addColorStop(0.6, d), b.addColorStop(1, tr(d)), b;
2220
+ }, c = Math.min(r * 0.55, o * 0.35);
2221
+ e.save(), e.lineJoin = "round", e.lineCap = "round", e.lineWidth = 3 * (r / Gt), e.beginPath(), e.moveTo(f(-r * 0.1, -1, a).x, f(-r * 0.1, -1, a).y), e.lineTo(f(c + 4, -1, a * 1.1).x, f(c + 4, -1, a * 1.1).y), e.lineTo(f(c + 4, 1, a * 1.1).x, f(c + 4, 1, a * 1.1).y), e.lineTo(f(-r * 0.1, 1, a).x, f(-r * 0.1, 1, a).y), e.closePath(), e.fillStyle = l, e.fill(), e.strokeStyle = s, e.beginPath(), e.moveTo(f(0, -1, a).x, f(0, -1, a).y), e.lineTo(f(c, -1, a * 1.1).x, f(c, -1, a * 1.1).y), e.moveTo(f(0, 1, a).x, f(0, 1, a).y), e.lineTo(f(c, 1, a * 1.1).x, f(c, 1, a * 1.1).y), e.stroke();
2222
+ const g = [f(c, -1, a * 1.3), f(o, -1, a * 1.5), f(o, 1, a * 1.5), f(c, 1, a * 1.3)];
2223
+ e.beginPath(), g.forEach((d, b) => b ? e.lineTo(d.x, d.y) : e.moveTo(d.x, d.y)), e.closePath(), e.fillStyle = p(i), e.fill(), e.strokeStyle = p(s), e.beginPath(), e.moveTo(g[1].x, g[1].y), e.lineTo(g[0].x, g[0].y), e.lineTo(g[3].x, g[3].y), e.lineTo(g[2].x, g[2].y), e.stroke(), e.restore();
2224
+ }
2225
+ function _r(e, t, n = {}) {
2226
+ const r = n.offstage ?? { x: 2e3, y: 1400 }, o = n.enter ?? 450, l = n.exit ?? 450, i = n.linger ?? 1500, s = [...e].filter((d) => d.path.length > 0).sort((d, b) => d.start - b.start), h = (d) => d.tool ?? "pencil", a = (d) => {
2227
+ const b = Math.min(1, Math.max(0, d));
2228
+ return b * b * (3 - 2 * b);
2229
+ }, f = (d, b, m) => ({ x: d.x + (b.x - d.x) * m, y: d.y + (b.y - d.y) * m }), u = s.find((d) => t >= d.start && t <= d.end);
2230
+ if (u) {
2231
+ const d = u.end - u.start, b = d > 0 ? (t - u.start) / d : 1;
2232
+ return { at: tt(u.path, b), tool: h(u), lift: 0, drawing: !0 };
2233
+ }
2234
+ const p = [...s].reverse().find((d) => d.end < t), c = s.find((d) => d.start > t), g = (d) => d.path[d.path.length - 1];
2235
+ if (p && c && c.start - p.end <= i) {
2236
+ const d = (t - p.end) / (c.start - p.end), b = d < 0.5 ? h(p) : h(c);
2237
+ return { at: f(g(p), c.path[0], a(d)), tool: b, lift: Math.sin(Math.PI * d), drawing: !1 };
2238
+ }
2239
+ if (c && c.start - t <= o) {
2240
+ const d = 1 - (c.start - t) / o;
2241
+ return { at: f(r, c.path[0], a(d)), tool: h(c), lift: 1 - a(d), drawing: !1 };
2242
+ }
2243
+ if (p && t - p.end <= l) {
2244
+ const d = (t - p.end) / l;
2245
+ return { at: f(g(p), r, a(d)), tool: h(p), lift: a(d), drawing: !1 };
2246
+ }
2247
+ return null;
2248
+ }
2249
+ function Rr(e, t, n, r = 0.08, o = 32) {
2250
+ const l = Math.PI * 2 * (1 + r), i = [];
2251
+ for (let s = 0; s <= o; s++) {
2252
+ const h = -Math.PI / 2 + l * s / o;
2253
+ i.push({ x: e + Math.cos(h) * n, y: t + Math.sin(h) * n });
2254
+ }
2255
+ return i;
2256
+ }
2257
+ function Yr(e) {
2258
+ const { path: t } = e, n = t.map((s) => s.x), r = t.map((s) => s.y), o = Math.min(...n), l = Math.min(...r), i = e.hand === !1 ? void 0 : e.hand === !0 || e.hand === void 0 ? {} : e.hand;
1087
2259
  return {
1088
- plan: t.plan ?? dn({
1089
- headSize: t.headSize ?? (e ? 0.3 : 0.24),
1090
- shoulderWidth: s ? 0 : t.shoulderWidth ?? 0.06,
1091
- hipWidth: s ? 0 : t.hipWidth ?? 0.022
2260
+ type: "custom",
2261
+ x: o,
2262
+ y: l,
2263
+ width: Math.max(1, Math.max(...n) - o),
2264
+ height: Math.max(1, Math.max(...r) - l),
2265
+ props: { draw: 0 },
2266
+ draw(s, h, a) {
2267
+ const f = Math.min(1, Math.max(0, Number(h.props?.draw ?? 0)));
2268
+ s.translate(-o, -l), s.strokeStyle = e.color ?? "#2f2f33", s.lineWidth = e.lineWidth ?? 5, s.lineCap = "round", s.lineJoin = "round";
2269
+ const u = e.sketch ? Ue(s, e.sketch, a) : void 0;
2270
+ f > 0 && (u ? e.smooth ? u.curve(t, f) : u.line(t, f) : Zt(s, Kt(t, f))), i && f > 0 && f < 1 && Jt(s, tt(t, f), i, u);
2271
+ }
2272
+ };
2273
+ }
2274
+ function tr(e) {
2275
+ const t = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e.trim());
2276
+ if (!t) return "rgba(0, 0, 0, 0)";
2277
+ const n = t[1].length === 3 ? [...t[1]].map((i) => i + i).join("") : t[1], [r, o, l] = [0, 2, 4].map((i) => parseInt(n.slice(i, i + 2), 16));
2278
+ return `rgba(${r}, ${o}, ${l}, 0)`;
2279
+ }
2280
+ function Zt(e, t, n) {
2281
+ if (!(t.length < 2)) {
2282
+ if (n) return n.line(t);
2283
+ e.beginPath(), e.moveTo(t[0].x, t[0].y);
2284
+ for (const r of t.slice(1)) e.lineTo(r.x, r.y);
2285
+ e.stroke();
2286
+ }
2287
+ }
2288
+ const ke = 1e5;
2289
+ function Lr(e, t, n, r, o = 6) {
2290
+ const l = [], i = Math.max(1, Math.round(o));
2291
+ for (let s = 0; s <= i; s++)
2292
+ l.push({ x: s % 2 === 0 ? e : e + n, y: t + r * s / i });
2293
+ return l;
2294
+ }
2295
+ function jt(e, t, n, r) {
2296
+ if (r <= 0 || t.length === 0) return;
2297
+ const o = Kt(t, r), l = n / 2, i = (s) => {
2298
+ e.beginPath(), e.rect(-ke, -ke, 2 * ke, 2 * ke), s(), e.clip("evenodd");
2299
+ };
2300
+ for (const s of o)
2301
+ i(() => {
2302
+ e.moveTo(s.x + l, s.y), e.arc(s.x, s.y, l, 0, Math.PI * 2);
2303
+ });
2304
+ for (let s = 1; s < o.length; s++) {
2305
+ const h = o[s - 1], a = o[s], f = Math.hypot(a.x - h.x, a.y - h.y);
2306
+ if (f === 0) continue;
2307
+ const u = -(a.y - h.y) / f * l, p = (a.x - h.x) / f * l;
2308
+ i(() => {
2309
+ e.moveTo(h.x + u, h.y + p), e.lineTo(a.x + u, a.y + p), e.lineTo(a.x - u, a.y - p), e.lineTo(h.x - u, h.y - p), e.closePath();
2310
+ });
2311
+ }
2312
+ }
2313
+ function Nr(e, t, n, r, o) {
2314
+ e.save(), jt(e, t, n, r), o(), e.restore();
2315
+ }
2316
+ function Cr(e, t) {
2317
+ const n = t.width ?? 40, r = t.hand === !0 ? {} : t.hand || void 0, o = t.eraser === !1 ? void 0 : t.eraser === !0 || t.eraser === void 0 ? {} : t.eraser;
2318
+ return {
2319
+ ...e,
2320
+ props: { ...e.props, erase: 0 },
2321
+ draw(l, i, s) {
2322
+ const h = Number(i.props?.erase ?? 0);
2323
+ if (l.save(), jt(l, t.path, n, h), e.draw(l, i, s), l.restore(), !o || h <= 0 || h >= 1) return;
2324
+ const a = tt(t.path, h);
2325
+ r ? Jt(l, a, { ...r, tool: "eraser" }) : zt(l, a, o);
2326
+ }
2327
+ };
2328
+ }
2329
+ const oe = (e) => e * Math.PI / 180;
2330
+ function Qt([e, t, n], r) {
2331
+ const o = Math.cos(r), l = Math.sin(r);
2332
+ return [e, t * o + n * l, -t * l + n * o];
2333
+ }
2334
+ function Vt([e, t, n], r) {
2335
+ const o = Math.cos(r), l = Math.sin(r);
2336
+ return [e * o - t * l, e * l + t * o, n];
2337
+ }
2338
+ function pe([e, t, n], r) {
2339
+ const o = Math.cos(r), l = Math.sin(r);
2340
+ return [e * o + n * l, t, -e * l + n * o];
2341
+ }
2342
+ const Ce = (e, t) => [e[0] + t[0], e[1] + t[1], e[2] + t[2]], vt = (e, t) => [e[0] * t, e[1] * t, e[2] * t], xe = (e, t) => Vt(Qt(e, t.swing), t.spread);
2343
+ function De(e, t) {
2344
+ const n = pe(e, t);
2345
+ return { point: { x: n[0], y: -n[1] }, depth: n[2] };
2346
+ }
2347
+ function ht(e, t, n) {
2348
+ const r = n.height, o = oe(90 * (t.turn ?? 0)), i = [0, e.hipHeight * r * (e.boneScale?.(t, null) ?? 1), 0], s = {};
2349
+ for (const y of e.chains) {
2350
+ const x = y.parent ? s[y.parent] : void 0;
2351
+ if (y.parent && !x) throw new Error(`body plan ${e.id}: chain ${y.id} comes before its parent ${y.parent}`);
2352
+ const O = y.at ?? (x ? x.joints3.length - 1 : 0), K = x ? x.joints3[O] : i, P = x ? x.frames[Math.max(0, O - 1)] : { swing: 0, spread: 0 }, $ = y.offset ? Ce(K, xe(vt(y.offset, r), P)) : K, B = y.side ?? 1, F = e.boneScale?.(t, y) ?? 1, C = e.angles(t, y), L = [$], Q = [];
2353
+ let ne = P.swing, Fe = P.spread;
2354
+ y.bones.forEach((tn, ft) => {
2355
+ const _e = C[ft] ?? { swing: 0, spread: 0 };
2356
+ ne += oe(_e.swing), Fe += oe(_e.spread) * B, Q.push({ swing: ne, spread: Fe });
2357
+ const nn = pe(xe(y.rest, { swing: ne, spread: Fe }), oe(_e.yaw ?? 0));
2358
+ L.push(Ce(L[ft], vt(nn, tn.length * r * F)));
2359
+ }), s[y.id] = { joints3: L, frames: Q };
2360
+ }
2361
+ const h = s[e.head.on], a = e.headPose?.(t) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 }, f = h.frames[h.frames.length - 1], u = e.head.size / 2 * r, p = u * a.sx, c = u * a.sy, g = (y) => xe(pe(Qt(Vt(y, -oe(a.tilt)), -oe(a.nod)), oe(a.yaw)), f), d = Ce(h.joints3[h.joints3.length - 1], g([0, c, 0])), b = {};
2362
+ for (const y of e.chains) {
2363
+ const { joints3: x, frames: O } = s[y.id], K = x.map((P) => De(P, o));
2364
+ b[y.id] = {
2365
+ id: y.id,
2366
+ joints3: x,
2367
+ frames: O,
2368
+ points: K.map((P) => P.point),
2369
+ depths: K.map((P) => P.depth)
2370
+ };
2371
+ }
2372
+ const m = De(d, o), S = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map((y) => pe(g(y), o)), k = De(i, o).point, T = oe(t.roll ?? 0), H = (y) => {
2373
+ const x = y.x - k.x, O = y.y - k.y;
2374
+ return { x: k.x + x * Math.cos(T) - O * Math.sin(T), y: k.y + x * Math.sin(T) + O * Math.cos(T) };
2375
+ }, w = ([y, x, O]) => [y * Math.cos(T) + x * Math.sin(T), -y * Math.sin(T) + x * Math.cos(T), O];
2376
+ for (const y of Object.values(b)) y.points = y.points.map(H);
2377
+ const E = {
2378
+ center: H(m.point),
2379
+ depth: m.depth,
2380
+ rx: p,
2381
+ ry: c,
2382
+ angle: 0,
2383
+ axes: S.map(w)
2384
+ }, v = E.axes[1];
2385
+ E.angle = Math.atan2(v[0], v[1]);
2386
+ const A = (y) => {
2387
+ if ("head" in y) return { x: E.center.x + v[0] * c, y: E.center.y - v[1] * c };
2388
+ const x = b[y.chain];
2389
+ return x.points[Math.min(y.joint, x.points.length - 1)];
2390
+ };
2391
+ let I = 0;
2392
+ (n.contact ?? "ground") === "ground" && (I = -Math.max(...e.contacts.map((y) => A(y).y))), I -= (t.lift ?? 0) * r;
2393
+ const W = (y) => ({ x: y.x, y: y.y + I });
2394
+ for (const y of Object.values(b)) y.points = y.points.map(W);
2395
+ E.center = W(E.center);
2396
+ const M = e.contacts.map((y) => ({ spec: y, point: A(y) }));
2397
+ return {
2398
+ height: r,
2399
+ view: o,
2400
+ chains: b,
2401
+ head: E,
2402
+ hip: W(H(k)),
2403
+ contacts: M,
2404
+ groundY: Math.max(...M.map((y) => y.point.y))
2405
+ };
2406
+ }
2407
+ function en(e, [t, n, r]) {
2408
+ const [o, l, i] = e.axes, s = [
2409
+ o[0] * t * e.rx + l[0] * n * e.ry + i[0] * r * e.rx,
2410
+ o[1] * t * e.rx + l[1] * n * e.ry + i[1] * r * e.rx,
2411
+ o[2] * t * e.rx + l[2] * n * e.ry + i[2] * r * e.rx
2412
+ ], h = Math.hypot(t, n, r) || 1, a = (o[2] * t + l[2] * n + i[2] * r) / h;
2413
+ return { point: { x: e.center.x + s[0], y: e.center.y - s[1] }, depth: e.depth + s[2], facing: a };
2414
+ }
2415
+ const Se = (e) => e * 180 / Math.PI, ae = (e, t) => [e[0] - t[0], e[1] - t[1], e[2] - t[2]], qe = (e, t) => e[0] * t[0] + e[1] * t[1] + e[2] * t[2], ue = (e) => Math.hypot(e[0], e[1], e[2]), Ve = (e) => {
2416
+ const t = ue(e) || 1;
2417
+ return [e[0] / t, e[1] / t, e[2] / t];
2418
+ }, Ee = (e) => Math.atan2(Math.sin(e), Math.cos(e));
2419
+ function xt(e) {
2420
+ const [t, n, r] = Ve(e);
2421
+ return { swing: Math.asin(Math.max(-1, Math.min(1, r))), spread: Math.atan2(t, -n) };
2422
+ }
2423
+ function nr(e, t, n, r, o) {
2424
+ const l = e.chains.find((I) => I.id === n);
2425
+ if (!l) throw new Error(`reach: no chain ${n} in ${e.id}`);
2426
+ if (l.bones.length < 2 || l.rest[1] > -0.99) throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);
2427
+ if (!e.withAngles) throw new Error(`reach: the ${e.id} plan cannot set angles`);
2428
+ const i = ht(e, { ...t, turn: 0, roll: 0, lift: 0 }, { height: o.height, contact: "none" }), s = i.chains[n], h = s.joints3[0], a = ue(ae(s.joints3[1], s.joints3[0])), f = ue(ae(s.joints3[2], s.joints3[1])), u = l.parent ? i.chains[l.parent].frames[Math.max(0, (l.at ?? i.chains[l.parent].joints3.length - 1) - 1)] : { swing: 0, spread: 0 }, p = ae(r, h), c = Math.min(a + f - 1e-6, Math.max(Math.abs(a - f) + 1e-6, ue(p))), g = Ve(p), d = l.parent !== null, b = xe(l.pole ?? (d ? [0, -0.35, -1] : [0, 0, 1]), u);
2429
+ let m = ae(b, [g[0] * qe(b, g), g[1] * qe(b, g), g[2] * qe(b, g)]);
2430
+ ue(m) < 1e-6 && (m = pe([1, 0, 0], 0)), m = Ve(m);
2431
+ const S = (a * a + c * c - f * f) / (2 * a * c), k = Math.sqrt(Math.max(0, 1 - S * S)), T = [
2432
+ h[0] + a * (S * g[0] + k * m[0]),
2433
+ h[1] + a * (S * g[1] + k * m[1]),
2434
+ h[2] + a * (S * g[2] + k * m[2])
2435
+ ], H = [h[0] + g[0] * c, h[1] + g[1] * c, h[2] + g[2] * c], w = l.side ?? 1, E = xt(ae(T, h)), v = xt(ae(H, T)), A = [
2436
+ { swing: Se(Ee(E.swing - u.swing)), spread: Se(Ee(E.spread - u.spread)) * w },
2437
+ { swing: Se(Ee(v.swing - E.swing)), spread: Se(Ee(v.spread - E.spread)) * w }
2438
+ ];
2439
+ return e.withAngles(t, l, A);
2440
+ }
2441
+ const or = 0.34, re = 0.12, j = -0.4, ee = (e, t, n) => e[t] ?? n, rr = (e, t) => Math.max(0, e) * (1 - Math.min(1, Math.max(0, t))), lr = 0.45, sr = 0.35, ir = 0.7;
2442
+ function Be(e, t, n) {
2443
+ const r = (c) => Math.sqrt(Math.max(0, 1 - c.x * c.x - c.y * c.y)), o = en(e, [n.x, n.y, r(n)]).facing, l = e.axes[2], i = Math.atan2(l[0], l[2]), s = Math.cos(i), h = s >= 0 ? 1 : -1, a = h * Math.max(sr, Math.abs(s)), f = h * Math.max(ir, Math.abs(s)), u = Math.cos(e.angle), p = Math.sin(e.angle);
2444
+ return {
2445
+ facing: o,
2446
+ points: t.map((c) => {
2447
+ const g = lr * Math.sin(i) + n.x * a + (c.x - n.x) * f, d = c.y + l[1] * r(c), b = g * e.rx, m = d * e.ry;
2448
+ return { x: e.center.x + b * u + m * p, y: e.center.y + b * p - m * u };
2449
+ })
2450
+ };
2451
+ }
2452
+ const He = (e, t, n, r = 12) => Array.from({ length: r + 1 }, (o, l) => {
2453
+ const i = l / r, s = 1 - i;
2454
+ return { x: s * s * e.x + 2 * s * i * t.x + i * i * n.x, y: s * s * e.y + 2 * s * i * t.y + i * i * n.y };
2455
+ }), Xe = (e, t, n, r, o = 16) => Array.from({ length: o }, (l, i) => {
2456
+ const s = Math.PI * 2 * i / o;
2457
+ return { x: e + Math.cos(s) * n, y: t + Math.sin(s) * r };
2458
+ }), At = 0.05;
2459
+ function hr(e, t, n, r) {
2460
+ const o = Math.max(1, Math.min(r * 0.6, 0.14 * t.rx)), l = (m, S) => Be(t, m, S).points, i = (m, S) => Be(t, [], { x: m, y: S }).facing, s = ee(n, "smile", 0), h = ee(n, "blink", 0), a = ee(n, "lookX", 0), f = ee(n, "lookY", 0), u = ee(n, "browTilt", 0);
2461
+ for (const m of [1, -1]) {
2462
+ const S = m === 1 ? "left" : "right", k = or * m;
2463
+ if (i(k, re) < At) continue;
2464
+ const T = { x: k, y: re }, H = rr(ee(n, `eye.${S}`, 1), h);
2465
+ if (H < 0.2) {
2466
+ const A = s > 0.5 ? 0.12 : -0.06;
2467
+ e.line(l(He({ x: k - 0.12, y: re }, { x: k, y: re + A }, { x: k + 0.12, y: re }), T), o);
2468
+ } else {
2469
+ if (H > 1.2) {
2470
+ const M = 0.13 * H;
2471
+ e.shape(l(Xe(k, re, M * 0.85, M), T), "#ffffff", o);
2472
+ }
2473
+ const A = H > 1.2 ? 0.075 : 0.1, I = k + a * 0.08, W = re - f * 0.07;
2474
+ e.shape(l(Xe(I, W, A, A * 1.1 * Math.min(H, 1)), T), e.ink, 0);
2475
+ }
2476
+ const w = re + 0.3 + ee(n, `brow.${S}`, 0) * 0.14 + Math.max(0, H - 1) * 0.12, E = { x: k + m * 0.13, y: w }, v = { x: k - m * 0.13, y: w + u * 0.1 };
2477
+ e.line(l([E, { x: (E.x + v.x) / 2, y: (E.y + v.y) / 2 }, v], { x: k, y: w }), o);
2478
+ }
2479
+ const p = { x: 0, y: j };
2480
+ if (i(0, j) < -At) return;
2481
+ const c = 0.25 * Math.max(0.3, ee(n, "mouthWidth", 1)), g = Math.min(1, Math.max(0, ee(n, "mouth", 0)));
2482
+ if (g <= 0.05) {
2483
+ e.line(l(He({ x: -c, y: j }, { x: 0, y: j - s * 0.25 }, { x: c, y: j }), p), o);
2484
+ return;
2485
+ }
2486
+ const d = 0.3 * g;
2487
+ let b;
2488
+ if (s > 0.3) {
2489
+ const m = j + 0.05;
2490
+ b = [...He({ x: c, y: m }, { x: 0, y: j - d * 2 }, { x: -c, y: m })];
2491
+ } else if (s < -0.3) {
2492
+ const m = j - d * 0.6;
2493
+ b = [...He({ x: c, y: m }, { x: 0, y: j + d * 1.4 }, { x: -c, y: m })];
2494
+ } else
2495
+ b = Xe(0, j, c * 0.8, d);
2496
+ e.shape(l(b, p), e.ink, 0);
2497
+ }
2498
+ function Dr(e = {}) {
2499
+ const t = (e.proportions ?? "bold") === "bold", n = e.figure ?? "fluid", r = e.look ?? "clean", o = e.height ?? 300, l = n === "stick";
2500
+ return {
2501
+ plan: e.plan ?? Go({
2502
+ headSize: e.headSize ?? (t ? 0.3 : 0.24),
2503
+ shoulderWidth: l ? 0 : e.shoulderWidth ?? 0.06,
2504
+ hipWidth: l ? 0 : e.hipWidth ?? 0.022
1092
2505
  }),
1093
2506
  figure: n,
1094
- look: o,
1095
- height: r,
1096
- lineWidth: t.lineWidth ?? r * (e ? 0.045 : 0.022),
1097
- ink: t.ink ?? (o === "pencil" ? "#2f2f33" : "#1e293b"),
1098
- skin: t.skin ?? (o === "pencil" ? "none" : "#ffffff"),
1099
- seed: t.seed ?? 1,
1100
- pencil: t.pencil ?? {},
1101
- layers: t.layers ?? {},
1102
- contact: t.contact ?? "ground"
2507
+ look: r,
2508
+ height: o,
2509
+ lineWidth: e.lineWidth ?? o * (t ? 0.045 : 0.022),
2510
+ ink: e.ink ?? (r === "pencil" ? "#2f2f33" : "#1e293b"),
2511
+ skin: e.skin ?? (r === "pencil" ? "none" : "#ffffff"),
2512
+ seed: e.seed ?? 1,
2513
+ pencil: e.pencil ?? {},
2514
+ layers: e.layers ?? {},
2515
+ contact: e.contact ?? "ground",
2516
+ hands: e.hands ?? "dot",
2517
+ handStyle: e.handStyle ?? "glove",
2518
+ handSize: e.handSize ?? (e.handStyle === "natural" ? 0.14 : 0.17)
1103
2519
  };
1104
2520
  }
1105
- function Ln(t, e, n, o) {
1106
- const { point: r, facing: s } = de(t, [e, n, o]);
1107
- return { point: r, facing: s };
1108
- }
1109
- const Ot = (t) => t.rest[1] < -0.5, gn = 0.3;
1110
- function yn(t, e, n) {
1111
- return t.figure === "stick" ? Ot(e) ? n.slice(0, 3) : n : Ot(e) && n.length >= 3 ? z(n[0], n[1], n[2], gn) : n.length === 3 ? z(n[0], n[1], n[2], 1) : n;
1112
- }
1113
- function At(t, e) {
1114
- const n = t.plan.id === "human" ? { ...K, ...e } : e, o = It(t.plan, n, { height: t.height, contact: t.contact }), r = {}, s = {}, h = {}, i = 0.01 * t.height;
1115
- t.plan.chains.forEach((f) => {
1116
- const d = o.chains[f.id];
1117
- r[f.id] = d.points;
1118
- const w = d.depths.reduce((E, b) => E + b, 0) / d.depths.length, m = f.parent ? o.chains[f.parent] : void 0, u = m ? m.depths[f.at ?? m.depths.length - 1] : 0, k = w - u;
1119
- h[f.id] = Math.abs(k) < i ? 0 : k, s[f.id] = { points: yn(t, f, d.points), depth: w };
1120
- }), s.head = { points: [o.head.center], depth: o.head.depth }, h.head = 0;
1121
- const l = [...t.plan.chains.map((f) => f.id), "head"], a = [...l].sort((f, d) => h[f] - h[d] || l.indexOf(f) - l.indexOf(d)), c = { hip: o.hip };
1122
- for (const [f, [d, w]] of Object.entries(t.plan.landmarks ?? {})) {
1123
- const m = o.chains[d]?.points;
1124
- m && (c[f] = m[Math.min(w, m.length - 1)]);
2521
+ function qr(e, t, n, r) {
2522
+ const { point: o, facing: l } = en(e, [t, n, r]);
2523
+ return { point: o, facing: l };
2524
+ }
2525
+ const et = (e) => e.rest[1] < -0.5, ar = 0.3;
2526
+ function fr(e, t, n) {
2527
+ return e.figure === "stick" ? et(t) ? n.slice(0, 3) : n : et(t) && n.length >= 3 ? fe(n[0], n[1], n[2], ar) : n.length === 3 ? fe(n[0], n[1], n[2], 1) : n;
2528
+ }
2529
+ function at(e, t) {
2530
+ const n = e.plan.id === "human" ? { ...te, ...t } : t, r = ht(e.plan, n, { height: e.height, contact: e.contact }), o = {}, l = {}, i = {}, s = 0.01 * e.height;
2531
+ e.plan.chains.forEach((c) => {
2532
+ const g = r.chains[c.id];
2533
+ o[c.id] = g.points;
2534
+ const d = g.depths.reduce((k, T) => k + T, 0) / g.depths.length, b = c.parent ? r.chains[c.parent] : void 0, m = b ? b.depths[c.at ?? b.depths.length - 1] : 0, S = d - m;
2535
+ i[c.id] = Math.abs(S) < s ? 0 : S, l[c.id] = { points: fr(e, c, g.points), depth: d };
2536
+ }), l.head = { points: [r.head.center], depth: r.head.depth }, i.head = 0;
2537
+ const h = [...e.plan.chains.map((c) => c.id), "head"], a = [...h].sort((c, g) => i[c] - i[g] || h.indexOf(c) - h.indexOf(g)), f = { hip: r.hip };
2538
+ for (const [c, [g, d]] of Object.entries(e.plan.landmarks ?? {})) {
2539
+ const b = r.chains[g]?.points;
2540
+ b && (f[c] = b[Math.min(d, b.length - 1)]);
1125
2541
  }
1126
- const g = {};
1127
- for (const [f, d] of Object.entries(c)) g[f] = d.y >= o.groundY - 0.01 * t.height;
1128
- const y = {
1129
- height: t.height,
1130
- lineWidth: t.lineWidth,
2542
+ const u = {};
2543
+ for (const [c, g] of Object.entries(f)) u[c] = g.y >= r.groundY - 0.01 * e.height;
2544
+ const p = {
2545
+ height: e.height,
2546
+ lineWidth: e.lineWidth,
1131
2547
  turn: n.turn ?? 0,
1132
- points: c,
1133
- chains: r,
1134
- parts: s,
1135
- head: o.head,
1136
- groundY: o.groundY,
1137
- grounded: g
2548
+ points: f,
2549
+ chains: o,
2550
+ parts: l,
2551
+ head: r.head,
2552
+ groundY: r.groundY,
2553
+ grounded: u
1138
2554
  };
1139
- return { skeleton: o, joints: y, order: a };
1140
- }
1141
- function mn(t, e) {
1142
- return At(t, e).joints;
1143
- }
1144
- function pn(t, e, n) {
1145
- const { head: o } = n;
1146
- t.guideEllipse(o.center.x, o.center.y, o.rx * 1.03, o.ry * 1.03, o.angle);
1147
- const r = Array.from({ length: 13 }, (l, a) => ({ x: 0, y: -0.95 + 1.9 * a / 12 })), s = Array.from({ length: 13 }, (l, a) => ({ x: -0.95 + 1.9 * a / 12, y: 0.12 })), h = dt(o, r, { x: 0, y: 0 });
1148
- h.facing > 0 && t.guide(h.points), t.guide(dt(o, s, { x: 0, y: 0.12 }).points), t.guide(n.chains.spine ?? []);
1149
- const i = e.lineWidth * 0.9;
1150
- for (const l of ["shoulder.left", "shoulder.right", "elbow.left", "elbow.right", "hip.left", "hip.right", "knee.left", "knee.right"]) {
1151
- const a = n.points[l];
1152
- a && t.guideEllipse(a.x, a.y, i, i, 0);
2555
+ return { skeleton: r, joints: p, order: a };
2556
+ }
2557
+ function cr(e, t) {
2558
+ return at(e, t).joints;
2559
+ }
2560
+ function gr(e, t, n) {
2561
+ const { head: r } = n;
2562
+ e.guideEllipse(r.center.x, r.center.y, r.rx * 1.03, r.ry * 1.03, r.angle);
2563
+ const o = Array.from({ length: 13 }, (h, a) => ({ x: 0, y: -0.95 + 1.9 * a / 12 })), l = Array.from({ length: 13 }, (h, a) => ({ x: -0.95 + 1.9 * a / 12, y: 0.12 })), i = Be(r, o, { x: 0, y: 0 });
2564
+ i.facing > 0 && e.guide(i.points), e.guide(Be(r, l, { x: 0, y: 0.12 }).points), e.guide(n.chains.spine ?? []);
2565
+ const s = t.lineWidth * 0.9;
2566
+ for (const h of ["shoulder.left", "shoulder.right", "elbow.left", "elbow.right", "hip.left", "hip.right", "knee.left", "knee.right"]) {
2567
+ const a = n.points[h];
2568
+ a && e.guideEllipse(a.x, a.y, s, s, 0);
1153
2569
  }
1154
2570
  }
1155
- function wn(t, e, n, o, r) {
1156
- const s = e.lineWidth;
2571
+ function ur(e, t, n, r, o, l) {
2572
+ const i = n.lineWidth;
1157
2573
  if (o === "head") {
1158
- const { head: y } = n, f = e.skin === "none" ? null : e.skin;
1159
- t.ellipse(y.center.x, y.center.y, y.rx, y.ry, y.angle, f, s), t.look !== "silhouette" && rn(t, y, r, s);
2574
+ const { head: c } = r, g = n.skin === "none" ? null : n.skin;
2575
+ t.ellipse(c.center.x, c.center.y, c.rx, c.ry, c.angle, g, i), t.look !== "silhouette" && hr(t, c, l, i);
1160
2576
  return;
1161
2577
  }
1162
- const h = e.plan.chains.find((y) => y.id === o), i = n.chains[o], l = n.parts[o].points;
1163
- if (e.figure === "stick") {
2578
+ const s = n.plan.chains.find((c) => c.id === o), h = r.chains[o], a = r.parts[o].points;
2579
+ if (n.figure === "stick") {
1164
2580
  if (o === "neck") return;
1165
- const y = o === "spine" ? [...i, ...n.chains.neck?.slice(1) ?? []] : l;
1166
- t.line(y, s);
2581
+ const c = o === "spine" ? [...h, ...r.chains.neck?.slice(1) ?? []] : a;
2582
+ t.line(c, i);
1167
2583
  return;
1168
2584
  }
1169
- const a = (y, f) => [h.bones[y].width[0] * s, h.bones[f].width[1] * s];
1170
- if (Ot(h)) {
1171
- const [y, f] = a(0, 1);
1172
- if (t.limb(l, y, f), h.bones.length >= 3)
1173
- t.limb([i[2], i[3]], h.bones[2].width[0] * s, h.bones[2].width[1] * s);
2585
+ const f = (c, g) => [s.bones[c].width[0] * i, s.bones[g].width[1] * i];
2586
+ if (et(s)) {
2587
+ const [c, g] = f(0, 1);
2588
+ if (t.limb(a, c, g), s.bones.length >= 3)
2589
+ t.limb([h[2], h[3]], s.bones[2].width[0] * i, s.bones[2].width[1] * i);
2590
+ else if (n.hands === "cartoon" && o.startsWith("arm."))
2591
+ pr(e, t, n, h, o.endsWith(".left") ? "left" : "right", l);
1174
2592
  else {
1175
- const d = i[i.length - 1];
1176
- t.dot(d.x, d.y, s * 0.62);
2593
+ const d = h[h.length - 1];
2594
+ t.dot(d.x, d.y, i * 0.62);
1177
2595
  }
1178
2596
  return;
1179
2597
  }
1180
2598
  if (o === "spine") {
1181
- const y = n.points["hip.left"], f = n.points["hip.right"];
1182
- y && f && Math.hypot(y.x - f.x, y.y - f.y) > 0.5 && t.limb([y, f], s * 1.3, s * 1.3);
1183
- const [d, w] = a(0, h.bones.length - 1);
1184
- t.limb(l, d, w);
1185
- const m = n.points["shoulder.left"], u = n.points["shoulder.right"];
1186
- m && u && Math.hypot(m.x - u.x, m.y - u.y) > 0.5 && t.limb(z(m, i[i.length - 1], u, 1, 10), s * 1.15, s * 1.15);
2599
+ const c = r.points["hip.left"], g = r.points["hip.right"];
2600
+ c && g && Math.hypot(c.x - g.x, c.y - g.y) > 0.5 && t.limb([c, g], i * 1.3, i * 1.3);
2601
+ const [d, b] = f(0, s.bones.length - 1);
2602
+ t.limb(a, d, b);
2603
+ const m = r.points["shoulder.left"], S = r.points["shoulder.right"];
2604
+ m && S && Math.hypot(m.x - S.x, m.y - S.y) > 0.5 && t.limb(fe(m, h[h.length - 1], S, 1, 10), i * 1.15, i * 1.15);
1187
2605
  return;
1188
2606
  }
1189
- const [c, g] = a(0, h.bones.length - 1);
1190
- t.limb(l, c, g);
2607
+ const [u, p] = f(0, s.bones.length - 1);
2608
+ t.limb(a, u, p);
2609
+ }
2610
+ function dr(e, t) {
2611
+ const n = `hand.${t}.`, r = {};
2612
+ for (const [i, s] of Object.entries(e)) i.startsWith(n) && (r[i.slice(n.length)] = s);
2613
+ const o = e.turn ?? 0, l = t === "right" ? 1 - o : 1 + o;
2614
+ return { ...R, ...r, turn: l + (r.turn ?? 0) };
2615
+ }
2616
+ function pr(e, t, n, r, o, l) {
2617
+ const i = r[r.length - 1], s = r[r.length - 2], h = Math.atan2(i.x - s.x, -(i.y - s.y)) * 180 / Math.PI;
2618
+ rt(e, i, dr(l, o), {
2619
+ size: n.handSize * n.height,
2620
+ side: o,
2621
+ angle: h,
2622
+ pen: t,
2623
+ skin: n.skin === "none" ? "#ffffff" : n.skin,
2624
+ // A cartoon glove: three fingers and a thumb, plump enough to match the limbs.
2625
+ // Natural: five fingers, a little fuller than a real hand so they hold up against the limbs.
2626
+ fingers: n.handStyle === "natural" ? 5 : 4,
2627
+ plump: n.handStyle === "natural" ? 1.15 : 1.6,
2628
+ lineWidth: n.lineWidth * 0.3
2629
+ });
1191
2630
  }
1192
- function bn(t, e, n, o = 0) {
1193
- const r = e.plan.id === "human" ? { ...K, ...n } : n, { joints: s, order: h } = At(e, r), i = ze(t, {
1194
- look: e.look,
1195
- ink: e.ink,
1196
- lineWidth: e.lineWidth,
1197
- seed: e.seed,
1198
- time: o,
1199
- pencil: e.pencil
1200
- }), l = (a) => {
1201
- a && (t.save(), a(t, s, i, o), t.restore());
2631
+ function br(e, t, n, r = 0) {
2632
+ const o = t.plan.id === "human" ? { ...te, ...n } : n, { joints: l, order: i } = at(t, o), s = Pt(e, {
2633
+ look: t.look,
2634
+ ink: t.ink,
2635
+ lineWidth: t.lineWidth,
2636
+ seed: t.seed,
2637
+ time: r,
2638
+ pencil: t.pencil
2639
+ }), h = (a) => {
2640
+ a && (e.save(), a(e, l, s, r), e.restore());
1202
2641
  };
1203
- t.save(), t.lineCap = "round", t.lineJoin = "round", e.look === "pencil" && e.pencil.construction !== !1 && pn(i, e, s), l(e.layers.behind);
1204
- for (const a of h) {
1205
- const c = e.layers.parts?.[a];
1206
- l(c?.under), wn(i, e, s, a, r), l(c?.over);
2642
+ e.save(), e.lineCap = "round", e.lineJoin = "round", t.look === "pencil" && t.pencil.construction !== !1 && gr(s, t, l), h(t.layers.behind);
2643
+ for (const a of i) {
2644
+ const f = t.layers.parts?.[a];
2645
+ h(f?.under), ur(e, s, t, l, a, o), h(f?.over);
1207
2646
  }
1208
- l(e.layers.front), t.restore();
2647
+ h(t.layers.front), e.restore();
1209
2648
  }
1210
- function Fn(t, e, n) {
1211
- const o = { ...t };
1212
- for (const [r, s] of Object.entries(e)) {
1213
- const h = t[r] ?? s;
1214
- o[r] = h + (s - h) * n;
2649
+ function Xr(e, t, n) {
2650
+ const r = { ...e };
2651
+ for (const [o, l] of Object.entries(t)) {
2652
+ const i = e[o] ?? l;
2653
+ r[o] = i + (l - i) * n;
1215
2654
  }
1216
- return o;
2655
+ return r;
1217
2656
  }
1218
- function Nn(t, e, n, o) {
1219
- const r = t.plan.id === "human" ? { ...K, ...e } : e;
1220
- let s;
1221
- if (Array.isArray(o))
1222
- s = o;
2657
+ function Ur(e, t, n, r) {
2658
+ const o = e.plan.id === "human" ? { ...te, ...t } : t;
2659
+ let l;
2660
+ if (Array.isArray(r))
2661
+ l = r;
1223
2662
  else {
1224
- const { skeleton: h } = At(t, r), i = It(t.plan, { ...r, roll: 0 }, { height: t.height, contact: "none" }), l = (r.roll ?? 0) * Math.PI / 180, a = o.x - h.hip.x, c = o.y - h.hip.y, g = i.hip.x + a * Math.cos(-l) - c * Math.sin(-l), y = i.hip.y + a * Math.sin(-l) + c * Math.cos(-l), f = Math.PI / 2 * (r.turn ?? 0), d = o.depth ?? h.chains[n].depths[h.chains[n].depths.length - 1], w = Math.cos(f), m = Math.sin(f);
1225
- s = [g * w - d * m, -y, g * m + d * w];
2663
+ const { skeleton: i } = at(e, o), s = ht(e.plan, { ...o, roll: 0 }, { height: e.height, contact: "none" }), h = (o.roll ?? 0) * Math.PI / 180, a = r.x - i.hip.x, f = r.y - i.hip.y, u = s.hip.x + a * Math.cos(-h) - f * Math.sin(-h), p = s.hip.y + a * Math.sin(-h) + f * Math.cos(-h), c = Math.PI / 2 * (o.turn ?? 0), g = r.depth ?? i.chains[n].depths[i.chains[n].depths.length - 1], d = Math.cos(c), b = Math.sin(c);
2664
+ l = [u * d - g * b, -p, u * b + g * d];
1226
2665
  }
1227
- return Je(t.plan, r, n, s, { height: t.height });
2666
+ return nr(e.plan, o, n, l, { height: e.height });
1228
2667
  }
1229
- function Cn(t) {
1230
- const { character: e } = t, n = e.height * 0.8, o = e.height, r = e.plan.id === "human" ? K : {};
2668
+ function zr(e) {
2669
+ const { character: t } = e, n = t.height * 0.8, r = t.height, o = t.plan.id === "human" ? te : {};
1231
2670
  return {
1232
2671
  type: "custom",
1233
- x: t.x - n / 2,
1234
- y: t.y - o,
2672
+ x: e.x - n / 2,
2673
+ y: e.y - r,
1235
2674
  width: n,
1236
- height: o,
1237
- props: { ...r, ...t.pose },
1238
- character: e,
1239
- draw(s, h, i) {
1240
- s.translate(n / 2, o), bn(s, e, h.props, i);
2675
+ height: r,
2676
+ props: { ...o, ...e.pose },
2677
+ character: t,
2678
+ draw(l, i, s) {
2679
+ l.translate(n / 2, r), br(l, t, i.props, s);
1241
2680
  }
1242
2681
  };
1243
2682
  }
1244
- function Mn(t, e, n) {
1245
- const o = (s) => ({ x: s.x + e, y: s.y + n }), r = (s) => Object.fromEntries(Object.entries(s).map(([h, i]) => [h, i.map(o)]));
2683
+ function mr(e, t, n) {
2684
+ const r = (l) => ({ x: l.x + t, y: l.y + n }), o = (l) => Object.fromEntries(Object.entries(l).map(([i, s]) => [i, s.map(r)]));
1246
2685
  return {
1247
- ...t,
1248
- points: Object.fromEntries(Object.entries(t.points).map(([s, h]) => [s, o(h)])),
1249
- chains: r(t.chains),
1250
- parts: Object.fromEntries(Object.entries(t.parts).map(([s, h]) => [s, { ...h, points: h.points.map(o) }])),
1251
- head: { ...t.head, center: o(t.head.center) },
1252
- groundY: t.groundY + n
2686
+ ...e,
2687
+ points: Object.fromEntries(Object.entries(e.points).map(([l, i]) => [l, r(i)])),
2688
+ chains: o(e.chains),
2689
+ parts: Object.fromEntries(Object.entries(e.parts).map(([l, i]) => [l, { ...i, points: i.points.map(r) }])),
2690
+ head: { ...e.head, center: r(e.head.center) },
2691
+ groundY: e.groundY + n
1253
2692
  };
1254
2693
  }
1255
- function Xn(t, e, n) {
1256
- const o = t.character;
1257
- if (!o) throw new Error("characterAt: the target was not made by characterTarget");
1258
- const r = { ...t.props };
1259
- let s = 0, h = 0;
1260
- for (const [l, a] of e.state?.values.get(n) ?? [])
1261
- typeof a == "number" && (l === "x" || l === "motionPathX" ? s = a : l === "y" || l === "motionPathY" ? h = a : l in r && (r[l] = a));
1262
- const i = mn(o, r);
1263
- return { pose: r, joints: Mn(i, t.x + s + t.width / 2, t.y + h + t.height) };
1264
- }
1265
- function qn(t, e, n = K) {
1266
- const o = [];
1267
- return e.forEach((s, h) => {
1268
- const i = h === 0 ? n : o[h - 1], l = typeof s.pose == "string" ? fn[s.pose] : void 0;
1269
- o.push(l ? { ...l, turn: i.turn ?? 0 } : { ...i, ...s.pose });
1270
- }), Object.keys(n).filter((s) => o.some((h) => (h[s] ?? n[s]) !== n[s])).map((s) => ({
1271
- id: `${t}-${s}`,
1272
- target: t,
1273
- property: s,
1274
- keyframes: e.map((h, i) => ({
1275
- time: h.time,
1276
- value: o[i][s] ?? n[s],
1277
- ...h.easing ? { easing: h.easing } : {}
2694
+ function Gr(e, t, n) {
2695
+ const r = e.character;
2696
+ if (!r) throw new Error("characterAt: the target was not made by characterTarget");
2697
+ const o = { ...e.props };
2698
+ let l = 0, i = 0;
2699
+ for (const [h, a] of t.state?.values.get(n) ?? [])
2700
+ typeof a == "number" && (h === "x" || h === "motionPathX" ? l = a : h === "y" || h === "motionPathY" ? i = a : h in o && (o[h] = a));
2701
+ const s = cr(r, o);
2702
+ return { pose: o, joints: mr(s, e.x + l + e.width / 2, e.y + i + e.height) };
2703
+ }
2704
+ function Jr(e, t, n = te) {
2705
+ const r = [];
2706
+ return t.forEach((l, i) => {
2707
+ const s = i === 0 ? n : r[i - 1], h = typeof l.pose == "string" ? zo[l.pose] : void 0;
2708
+ r.push(h ? { ...h, turn: s.turn ?? 0 } : { ...s, ...l.pose });
2709
+ }), Object.keys(n).filter((l) => r.some((i) => (i[l] ?? n[l]) !== n[l])).map((l) => ({
2710
+ id: `${e}-${l}`,
2711
+ target: e,
2712
+ property: l,
2713
+ keyframes: t.map((i, s) => ({
2714
+ time: i.time,
2715
+ value: r[s][l] ?? n[l],
2716
+ ...i.easing ? { easing: i.easing } : {}
1278
2717
  }))
1279
2718
  }));
1280
2719
  }
1281
- const kn = (t, e, n) => t.slice(Math.floor((t.length - 1) * e), Math.ceil((t.length - 1) * n) + 1);
1282
- function Un(t = {}) {
1283
- const e = t.shirt ?? "#e2493b", n = t.trousers ?? "#24476b", o = (i) => i.lineWidth * 0.45, r = (i, l, a) => {
1284
- const c = i.parts[`leg.${a}`].points;
1285
- l.shape(ht(c, i.height * 0.08, i.height * 0.05), n, o(i));
1286
- }, s = (i, l) => {
1287
- const a = i.chains.spine, c = a[0], g = a[a.length - 1], y = { x: c.x - (g.x - c.x) * 0.25, y: c.y - (g.y - c.y) * 0.25 };
1288
- l.shape(ht([y, ...i.parts.spine.points], i.height * 0.15, i.height * 0.14), e, o(i));
1289
- }, h = (i, l, a) => {
1290
- const c = i.parts[`arm.${a}`].points, g = c[0], y = i.chains.spine[i.chains.spine.length - 1], d = [{ x: g.x + (y.x - g.x) * 0.45, y: g.y + (y.y - g.y) * 0.45 }, ...kn(c, 0, 0.45)], w = ht(d, i.height * 0.085, i.height * 0.06), m = d.length, u = w.slice(0, m), k = w.slice(m).reverse();
1291
- l.shape(w, e, 0);
1292
- const E = (P) => Math.hypot(P[1].x - y.x, P[1].y - y.y), [b, M] = E(u) > E(k) ? [u, k] : [k, u];
1293
- l.line(b.slice(1), o(i)), l.line(M.slice(Math.ceil(m * 0.45)), o(i)), l.line([u[m - 1], k[m - 1]], o(i));
2720
+ const yr = (e, t, n) => e.slice(Math.floor((e.length - 1) * t), Math.ceil((e.length - 1) * n) + 1);
2721
+ function Zr(e = {}) {
2722
+ const t = e.shirt ?? "#e2493b", n = e.trousers ?? "#24476b", r = (s) => s.lineWidth * 0.45, o = (s, h, a) => {
2723
+ const f = s.parts[`leg.${a}`].points;
2724
+ h.shape(Me(f, s.height * 0.08, s.height * 0.05), n, r(s));
2725
+ }, l = (s, h) => {
2726
+ const a = s.chains.spine, f = a[0], u = a[a.length - 1], p = { x: f.x - (u.x - f.x) * 0.25, y: f.y - (u.y - f.y) * 0.25 };
2727
+ h.shape(Me([p, ...s.parts.spine.points], s.height * 0.15, s.height * 0.14), t, r(s));
2728
+ }, i = (s, h, a) => {
2729
+ const f = s.parts[`arm.${a}`].points, u = f[0], p = s.chains.spine[s.chains.spine.length - 1], g = [{ x: u.x + (p.x - u.x) * 0.45, y: u.y + (p.y - u.y) * 0.45 }, ...yr(f, 0, 0.45)], d = Me(g, s.height * 0.085, s.height * 0.06), b = g.length, m = d.slice(0, b), S = d.slice(b).reverse();
2730
+ h.shape(d, t, 0);
2731
+ const k = (w) => Math.hypot(w[1].x - p.x, w[1].y - p.y), [T, H] = k(m) > k(S) ? [m, S] : [S, m];
2732
+ h.line(T.slice(1), r(s)), h.line(H.slice(Math.ceil(b * 0.45)), r(s)), h.line([m[b - 1], S[b - 1]], r(s));
1294
2733
  };
1295
2734
  return {
1296
2735
  parts: {
1297
- "leg.left": { over: (i, l, a) => r(l, a, "left") },
1298
- "leg.right": { over: (i, l, a) => r(l, a, "right") },
1299
- spine: { over: (i, l, a) => s(l, a) },
1300
- "arm.left": { over: (i, l, a) => h(l, a, "left") },
1301
- "arm.right": { over: (i, l, a) => h(l, a, "right") }
2736
+ "leg.left": { over: (s, h, a) => o(h, a, "left") },
2737
+ "leg.right": { over: (s, h, a) => o(h, a, "right") },
2738
+ spine: { over: (s, h, a) => l(h, a) },
2739
+ "arm.left": { over: (s, h, a) => i(h, a, "left") },
2740
+ "arm.right": { over: (s, h, a) => i(h, a, "right") }
1302
2741
  }
1303
2742
  };
1304
2743
  }
1305
2744
  export {
1306
- N as EXPRESSIONS,
1307
- Bn as HUMAN_EXPRESSIONS,
1308
- fn as HUMAN_POSES,
1309
- K as HUMAN_REST,
1310
- be as POSES,
1311
- G as REST_POSE,
1312
- Un as basicOutfit,
1313
- Me as blendPose,
1314
- ye as boilFrame,
1315
- Rn as character,
1316
- Xn as characterAt,
1317
- mn as characterJoints,
1318
- qn as characterPoseTracks,
1319
- Cn as characterTarget,
1320
- In as circlePath,
1321
- ae as clipErased,
1322
- ze as createPen,
1323
- bn as drawCharacter,
1324
- ie as drawEraser,
1325
- le as drawHand,
1326
- je as drawPencil,
1327
- De as drawStickFigure,
1328
- An as drawnPathTarget,
1329
- Xt as ellipsePoints,
1330
- Yn as erasable,
1331
- Tn as headPoint,
1332
- $n as humanFieldLabel,
1333
- dn as humanPlan,
1334
- R as humanPose,
1335
- Mn as jointsInScene,
1336
- Ke as jointsToScene,
1337
- Fn as mixPoses,
1338
- Dt as partialPath,
1339
- jn as pathLength,
1340
- jt as pointAlong,
1341
- Ln as pointOnHead,
1342
- B as pose,
1343
- On as poseTracks,
1344
- Nn as reachCharacter,
1345
- re as resolveStickPose,
1346
- z as rubberLimb,
1347
- Hn as scrubPath,
1348
- Pn as seatHeight,
1349
- xt as sketchPen,
1350
- Wn as stickFigureAt,
1351
- Ue as stickFigureJoints,
1352
- vn as stickFigureTarget,
1353
- Sn as strideLength,
1354
- xe as talkingMouth,
1355
- Jt as taperedLine,
1356
- ht as taperedOutline,
1357
- Ee as walkPose,
1358
- _n as withErased,
1359
- we as withExpression
2745
+ $e as DANCE_STYLES,
2746
+ J as EXPRESSIONS,
2747
+ cn as FINGERS,
2748
+ it as FLIPS,
2749
+ R as HAND_REST,
2750
+ N as HAND_SHAPES,
2751
+ $r as HUMAN_EXPRESSIONS,
2752
+ zo as HUMAN_POSES,
2753
+ te as HUMAN_REST,
2754
+ Et as MUDRAS,
2755
+ Wn as POSES,
2756
+ z as REST_POSE,
2757
+ mo as applyGroove,
2758
+ Or as bakeDanceTracks,
2759
+ Zr as basicOutfit,
2760
+ Kr as beatAt,
2761
+ me as blendPose,
2762
+ on as boilFrame,
2763
+ Dr as character,
2764
+ Gr as characterAt,
2765
+ dr as characterHandPose,
2766
+ cr as characterJoints,
2767
+ Jr as characterPoseTracks,
2768
+ zr as characterTarget,
2769
+ Rr as circlePath,
2770
+ jt as clipErased,
2771
+ Pt as createPen,
2772
+ st as danceFrame,
2773
+ xr as dancePose,
2774
+ yo as danceStance,
2775
+ Ar as danceTaps,
2776
+ Wr as danceTracks,
2777
+ Pr as dancer,
2778
+ rt as drawCartoonHand,
2779
+ br as drawCharacter,
2780
+ zt as drawEraser,
2781
+ Jt as drawHand,
2782
+ Qo as drawPencil,
2783
+ lo as drawStickFigure,
2784
+ Yr as drawnPathTarget,
2785
+ ct as ellipsePoints,
2786
+ Cr as erasable,
2787
+ Fo as flipPose,
2788
+ Ir as flipTracks,
2789
+ _o as flipTravel,
2790
+ _r as handAt,
2791
+ Je as handJoints,
2792
+ Hn as handJointsAt,
2793
+ _ as handPose,
2794
+ We as handProp,
2795
+ Hr as headPoint,
2796
+ Br as humanFieldLabel,
2797
+ Go as humanPlan,
2798
+ G as humanPose,
2799
+ mr as jointsInScene,
2800
+ ro as jointsToScene,
2801
+ po as mirrorPose,
2802
+ be as mixHandPoses,
2803
+ Xr as mixPoses,
2804
+ Kt as partialPath,
2805
+ Vr as pathLength,
2806
+ tt as pointAlong,
2807
+ qr as pointOnHead,
2808
+ D as pose,
2809
+ vr as poseTracks,
2810
+ Ur as reachCharacter,
2811
+ Xt as resolveStickFrame,
2812
+ so as resolveStickPose,
2813
+ ie as rotateAbout,
2814
+ Ut as routineBeats,
2815
+ fe as rubberLimb,
2816
+ Lr as scrubPath,
2817
+ Er as seatHeight,
2818
+ Ue as sketchPen,
2819
+ Tr as stickFigureAt,
2820
+ oo as stickFigureJoints,
2821
+ Mr as stickFigureTarget,
2822
+ Fr as stickToHuman,
2823
+ Sr as strideLength,
2824
+ Bn as talkingMouth,
2825
+ ot as taperedLine,
2826
+ Me as taperedOutline,
2827
+ In as walkPose,
2828
+ Nr as withErased,
2829
+ Ot as withExpression
1360
2830
  };