@algorisys/tinyfly 0.111.0 → 0.112.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,4312 +0,0 @@
1
- import { createRandom as vs, hashSeed as vo, unknownName as Es, TrackPlayer as An } from "@algorisys/tinyfly";
2
- import { c as Ss, s as In } from "./sketch-CYPUbk3Q.js";
3
- import { c as Ps, b as As } from "./shots-DR_ViiAC.js";
4
- const ht = (t) => ({ description: t, unit: "degrees" }), st = (t, e = 0, n = 1) => ({ description: t, unit: `${e}..${n}`, min: e, max: n }), Is = {
5
- lean: ht("Upper body tipped about the hips (+ toward the way it faces)"),
6
- bend: ht("Line of action: the spine curved (+ curls forward, − arches back)"),
7
- headTilt: ht("Head tilt"),
8
- leftShoulder: ht("Left upper arm: 0 hangs down, 90 straight out to its side, 180 straight up; in profile, forward is negative for the left arm"),
9
- rightShoulder: ht("Right upper arm: 0 hangs down, 90 straight out (forward, in profile), 180 straight up"),
10
- leftElbow: ht("Left elbow bend, added to the upper arm"),
11
- rightElbow: ht("Right elbow bend, added to the upper arm"),
12
- leftHip: ht("Left thigh: 0 straight down; in profile negative is forward"),
13
- rightHip: ht("Right thigh: 0 straight down; in profile positive is forward"),
14
- leftKnee: ht("Left knee bend (negative folds the shin back)"),
15
- rightKnee: ht("Right knee bend (positive folds the shin back)"),
16
- leftWrist: ht("Left wrist bend, added to the forearm"),
17
- rightWrist: ht("Right wrist bend, added to the forearm"),
18
- leftAnkle: ht("Left ankle: + points the toe down (tiptoe), − onto the heel"),
19
- rightAnkle: ht("Right ankle: + points the toe down (tiptoe), − onto the heel"),
20
- leftFootOut: st("Left foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in", -1, 1),
21
- rightFootOut: st("Right foot turned out (seen from the front): 0 natural, 1 sideways, negative turned in", -1, 1),
22
- mouth: st("Mouth open: 0 closed, 1 wide open"),
23
- smile: st("−1 frown, 0 flat, 1 smile", -1, 1),
24
- mouthWidth: { description: "Mouth width: 1 normal, 0.5 pursed, 1.5 wide", unit: "factor", min: 0.3, max: 2 },
25
- blink: st("Eyes closed by a blink: 0 open, 1 shut"),
26
- leftEye: { description: "Left eye openness: 0 shut, 1 normal, 1.6 wide", unit: "factor", min: 0, max: 2 },
27
- rightEye: { description: "Right eye openness: 0 shut, 1 normal, 1.6 wide", unit: "factor", min: 0, max: 2 },
28
- leftBrow: st("Left eyebrow: −1 lowered, 0 rest, 1 raised", -1, 1),
29
- rightBrow: st("Right eyebrow: −1 lowered, 0 rest, 1 raised", -1, 1),
30
- browTilt: st("Eyebrow slant: −1 angry, 1 worried", -1, 1),
31
- lookX: st("Eyes look across: + the way it faces", -1, 1),
32
- lookY: st("Eyes look down (+) or up (−)", -1, 1),
33
- stretch: { description: "Squash and stretch: 1 normal, above taller (a jump), below squashed (a landing)", unit: "factor", min: 0.3, max: 3 },
34
- turn: st("0 front-on, 1 in profile, turned the way it faces"),
35
- sit: st("0 standing, 1 seated"),
36
- spin: ht("Whole body turned about the hips: + rolls forward (a front flip), 360 a full turn"),
37
- rise: { description: "Lift off the ground, as a fraction of its height (the arc of a jump)", unit: "× height" }
38
- }, Os = {
39
- walk: { description: "Walk-cycle phase, in strides: animate 0 → n for n strides", unit: "strides" },
40
- walking: st("How much of the walk cycle is applied (0 standing)"),
41
- gait: { description: "How it walks: a gait name (walk, bouncy, doubleBounce, sneak, strut, tired, run, shove); a string track switches it", kind: "string" },
42
- talk: st("How much the mouth chatters"),
43
- rubber: st("Limbs from jointed (0) to rubber hose (1)"),
44
- facing: { description: "Which way it faces: 1 right, −1 left (key the flip while turn is near 0)", unit: "±1", min: -1, max: 1 },
45
- beat: { description: "Beats into its dance (with a dance)", unit: "beats" },
46
- dancing: st("How much of the dance is applied")
47
- }, Ts = {
48
- "thumb.curl": st("Thumb curled in"),
49
- "thumb.across": st("Thumb across the palm"),
50
- "index.curl": st("Index finger curled"),
51
- "middle.curl": st("Middle finger curled"),
52
- "ring.curl": st("Ring finger curled"),
53
- "pinky.curl": st("Little finger curled"),
54
- spread: st("Fingers spread apart"),
55
- turn: ht("Hand turned about the forearm"),
56
- bend: ht("Hand bent at the wrist, palm-ward"),
57
- tilt: ht("Hand tilted sideways"),
58
- roll: ht("Hand rolled to show the back or the palm")
59
- };
60
- let Eo;
61
- function Ya(t) {
62
- Eo = t;
63
- }
64
- function Ws(t) {
65
- return Eo?.(t) ?? {};
66
- }
67
- function ut(t, e, n) {
68
- const o = t.length;
69
- if (o < 2) return [];
70
- const s = [], r = [], i = (a) => e + (n - e) * a / (o - 1);
71
- return t.forEach((a, l) => {
72
- const c = t[Math.max(0, l - 1)], h = t[Math.min(o - 1, l + 1)], f = Math.hypot(h.x - c.x, h.y - c.y) || 1, y = i(l) / 2, u = -(h.y - c.y) / f * y, g = (h.x - c.x) / f * y;
73
- s.push({ x: a.x + u, y: a.y + g }), r.push({ x: a.x - u, y: a.y - g });
74
- }), [...s, ...r.reverse()];
75
- }
76
- function pn(t, e, n, o) {
77
- const s = e.length;
78
- if (s < 2) return;
79
- const r = ut(e, n, o), i = (a) => n + (o - n) * a / (s - 1);
80
- t.beginPath(), t.moveTo(r[0].x, r[0].y);
81
- for (const a of r.slice(1)) t.lineTo(a.x, a.y);
82
- t.closePath(), t.fill(), e.forEach((a, l) => {
83
- l !== 0 && l !== s - 1 && s > 3 || (t.beginPath(), t.arc(a.x, a.y, i(l) / 2, 0, Math.PI * 2), t.fill());
84
- });
85
- }
86
- function ne(t, e, n, o, s = 16) {
87
- const r = { x: 2 * e.x - (t.x + n.x) / 2, y: 2 * e.y - (t.y + n.y) / 2 }, i = [];
88
- for (let a = 0; a <= s; a++) {
89
- const l = a / s, c = 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) }, h = 1 - l, f = {
90
- x: h * h * t.x + 2 * h * l * r.x + l * l * n.x,
91
- y: h * h * t.y + 2 * h * l * r.y + l * l * n.y
92
- };
93
- i.push({ x: c.x + (f.x - c.x) * o, y: c.y + (f.y - c.y) * o });
94
- }
95
- return i;
96
- }
97
- function en(t, e, n, o, s, r = 0, i = 1, a = 40) {
98
- const l = Math.cos(s), c = Math.sin(s);
99
- return Array.from({ length: a + 1 }, (h, f) => {
100
- const y = r + Math.PI * 2 * i * f / a, u = Math.cos(y) * n, g = Math.sin(y) * o;
101
- return { x: t + u * l - g * c, y: e + u * c + g * l };
102
- });
103
- }
104
- function bn(t, e) {
105
- return e.look === "pencil" ? _s(t, e) : So(t, e.ink, e.look);
106
- }
107
- function Oe(t, e, n = !1) {
108
- t.beginPath(), t.moveTo(e[0].x, e[0].y);
109
- for (const o of e.slice(1)) t.lineTo(o.x, o.y);
110
- n && t.closePath();
111
- }
112
- function ye(t, e) {
113
- return e.look === "silhouette" ? So(t, e.ink, "silhouette", !1) : e;
114
- }
115
- function So(t, e, n, o = !0) {
116
- const s = n === "silhouette", r = s ? 1.25 : 1;
117
- return {
118
- look: n,
119
- ink: e,
120
- limb(i, a, l) {
121
- t.fillStyle = e, pn(t, i, a * r, l * r);
122
- },
123
- line(i, a) {
124
- i.length < 2 || (t.strokeStyle = e, t.lineWidth = a * r, t.lineCap = "round", t.lineJoin = "round", Oe(t, i), t.stroke());
125
- },
126
- shape(i, a, l) {
127
- Oe(t, i, !0), (a !== null || s && o) && (t.fillStyle = s ? e : a, t.fill()), !(l <= 0) && (t.strokeStyle = e, t.lineWidth = l * r, t.lineJoin = "round", t.stroke());
128
- },
129
- ellipse(i, a, l, c, h, f, y) {
130
- t.beginPath(), t.ellipse(i, a, l, c, h, 0, Math.PI * 2), (f !== null || s && o) && (t.fillStyle = s ? e : f, t.fill()), !(y <= 0) && (t.strokeStyle = e, t.lineWidth = y * r, t.stroke());
131
- },
132
- dot(i, a, l) {
133
- t.fillStyle = e, t.beginPath(), t.arc(i, a, l * r, 0, Math.PI * 2), t.fill();
134
- },
135
- guide() {
136
- },
137
- guideEllipse() {
138
- }
139
- };
140
- }
141
- function Hs(t, e) {
142
- const n = [t[0]];
143
- let o = 0;
144
- for (let i = 1; i < t.length; i++) {
145
- const a = t[i - 1], l = t[i], c = Math.hypot(l.x - a.x, l.y - a.y);
146
- let h = e - o;
147
- for (; h < c; ) {
148
- const f = h / c;
149
- n.push({ x: a.x + (l.x - a.x) * f, y: a.y + (l.y - a.y) * f }), h += e;
150
- }
151
- o = c - (h - e);
152
- }
153
- const s = t[t.length - 1], r = n[n.length - 1];
154
- return Math.hypot(s.x - r.x, s.y - r.y) > e * 0.25 ? n.push(s) : n[n.length - 1] = s, n;
155
- }
156
- function $s(t, e) {
157
- const n = t.length;
158
- return t.map((o, s) => {
159
- const r = t[Math.max(0, s - 1)], i = t[Math.min(n - 1, s + 1)], a = Math.hypot(i.x - r.x, i.y - r.y) || 1, l = e(n === 1 ? 0 : s / (n - 1));
160
- return { x: o.x - (i.y - r.y) / a * l, y: o.y + (i.x - r.x) / a * l };
161
- });
162
- }
163
- function On(t) {
164
- const e = [0.6, 1.4, 2.9].map((o) => ({
165
- frequency: o * (0.8 + t.next() * 0.4),
166
- phase: t.next() * Math.PI * 2,
167
- amount: 0.5 + t.next() * 0.5
168
- })), n = e.reduce((o, s) => o + s.amount, 0);
169
- return (o) => e.reduce((s, r) => s + r.amount * Math.sin(Math.PI * 2 * r.frequency * o + r.phase), 0) / n;
170
- }
171
- function _s(t, e) {
172
- const n = e.pencil ?? {}, o = e.ink, s = n.roughness ?? Math.max(1, e.lineWidth * 0.12), r = Math.max(1, Math.round(n.passes ?? 2)), i = Math.min(1, Math.max(0, n.pressure ?? 0.25)), a = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), l = Ss(e.time, n.boil ?? 8);
173
- let c = 0;
174
- const h = (g, m, d = !1) => vs(vo(`${e.seed}:${d ? "paper" : l}:${g}:${m}`)), f = (g, m, d, b, x, M = 0) => {
175
- if (g.length < 2) return;
176
- const v = g.slice(1).reduce((R, w, E) => R + Math.hypot(w.x - g[E].x, w.y - g[E].y), 0);
177
- let P = Hs(g, Math.max(1.5, Math.min(e.lineWidth * 0.8, v / 24)));
178
- if (M > 0 && P.length >= 2) {
179
- const [R, w] = [P[P.length - 2], P[P.length - 1]], E = Math.hypot(w.x - R.x, w.y - R.y) || 1;
180
- P = [...P, { x: w.x + (w.x - R.x) / E * M, y: w.y + (w.y - R.y) / E * M }];
181
- }
182
- const C = On(d), I = On(d), $ = P.length, A = [], z = [];
183
- P.forEach((R, w) => {
184
- const E = $ === 1 ? 0 : w / ($ - 1), H = P[Math.max(0, w - 1)], N = P[Math.min($ - 1, w + 1)], D = Math.hypot(N.x - H.x, N.y - H.y) || 1, X = -(N.y - H.y) / D, K = (N.x - H.x) / D, q = C(E) * x, J = Math.min(1, E / 0.08, (1 - E) / 0.08), j = (0.55 + 0.45 * Math.sqrt(Math.max(0, J))) * (1 + i * I(E)), Q = Math.max(0.3, m(E) * j / 2), nt = R.x + X * q, lt = R.y + K * q;
185
- A.push({ x: nt + X * Q, y: lt + K * Q }), z.push({ x: nt - X * Q, y: lt - K * Q });
186
- }), t.save(), t.globalAlpha *= b, t.fillStyle = o, Oe(t, [...A, ...z.reverse()], !0), t.fill(), t.restore();
187
- }, y = (g, m) => {
188
- const d = c++, b = h(d, 99, !0);
189
- if (b.next() < a) {
190
- const P = (b.next() * 2 - 1) * e.lineWidth * 1.4, C = (b.next() * 2 - 1) * e.lineWidth * 1.4, I = g.map(($) => ({ x: $.x + P, y: $.y + C }));
191
- f(I, ($) => m($) * 1.8, h(d, 98, !0), 0.035, s), f(I, ($) => m($) * 0.45, h(d, 97, !0), 0.12, s * 1.5);
192
- }
193
- const x = g.slice(1).reduce((P, C, I) => P + Math.hypot(C.x - g[I].x, C.y - g[I].y), 0), M = m(0.5) > 4 && x > m(0.5) * 6, v = M ? [-0.3, 0.3, 0] : [0];
194
- for (let P = 0; P < r; P++) {
195
- const C = P === 0;
196
- v.forEach((I, $) => {
197
- const A = h(d, P * 10 + $), z = I === 0 ? g : $s(g, (w) => m(w) * I * Math.sqrt(Math.sin(Math.PI * w))), R = !C && I === 0 ? e.lineWidth * (0.3 + A.next() * 0.8) : 0;
198
- f(z, (w) => m(w) * (M ? 0.5 : 1) * (C ? 1 : 0.6), A, C ? 0.85 : 0.45, s * (C ? 0.6 : 1), R);
199
- });
200
- }
201
- }, u = (g, m, d, b, x, M) => {
202
- const P = h(c, 50).next() * Math.PI * 2;
203
- y(en(g, m, d, b, x, P, 1.08, 48), () => M);
204
- };
205
- return {
206
- look: "pencil",
207
- ink: o,
208
- limb(g, m, d) {
209
- y(g, (b) => m + (d - m) * b);
210
- },
211
- line(g, m) {
212
- y(g, () => m);
213
- },
214
- shape(g, m, d) {
215
- m !== null && (t.save(), t.globalAlpha *= 0.88, t.fillStyle = m, Oe(t, g, !0), t.fill(), t.restore()), d > 0 && y([...g, g[0]], () => d);
216
- },
217
- ellipse(g, m, d, b, x, M, v) {
218
- M !== null && (t.save(), t.globalAlpha *= 0.9, t.fillStyle = M, t.beginPath(), t.ellipse(g, m, d, b, x, 0, Math.PI * 2), t.fill(), t.restore()), u(g, m, d, b, x, v);
219
- },
220
- dot(g, m, d) {
221
- t.save(), t.globalAlpha *= 0.9, t.fillStyle = o, t.beginPath(), t.arc(g, m, d, 0, Math.PI * 2), t.fill(), t.restore();
222
- },
223
- guide(g) {
224
- if (n.construction === !1 || g.length < 2) return;
225
- const m = c++;
226
- f(g, () => Math.max(0.6, e.lineWidth * 0.18), h(m, 0), 0.28, s * 1.2, e.lineWidth);
227
- },
228
- guideEllipse(g, m, d, b, x) {
229
- if (n.construction === !1) return;
230
- const M = c++, v = h(M, 0), P = en(g, m, d, b, x, v.next() * Math.PI * 2, 1.12, 48);
231
- f(P, () => Math.max(0.6, e.lineWidth * 0.18), v, 0.28, s * 1.5);
232
- }
233
- };
234
- }
235
- const Fs = ["thumb", "index", "middle", "ring", "pinky"], It = {
236
- "thumb.curl": 0.15,
237
- "thumb.across": 0.15,
238
- "index.curl": 0.12,
239
- "middle.curl": 0.16,
240
- "ring.curl": 0.2,
241
- "pinky.curl": 0.25,
242
- spread: 0.25,
243
- turn: 0,
244
- bend: 0,
245
- tilt: 0,
246
- roll: 0
247
- };
248
- function wt(t = {}) {
249
- return { ...It, ...t };
250
- }
251
- const xt = (t, e, n, o, s) => ({
252
- "thumb.curl": t,
253
- "index.curl": e,
254
- "middle.curl": n,
255
- "ring.curl": o,
256
- "pinky.curl": s
257
- }), za = {
258
- relaxed: It,
259
- open: wt({ ...xt(0, 0, 0, 0, 0), "thumb.across": 0, spread: 0.55 }),
260
- spread: wt({ ...xt(0, 0, 0, 0, 0), "thumb.across": 0, spread: 1 }),
261
- flat: wt({ ...xt(0, 0, 0, 0, 0), "thumb.across": 0.35, spread: 0 }),
262
- fist: wt({ ...xt(0.7, 1, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
263
- point: wt({ ...xt(0.75, 0, 1, 1, 1), "thumb.across": 0.9, spread: 0 }),
264
- /** The fist on its side, knuckles toward the viewer, the thumb up */
265
- thumbsUp: wt({ ...xt(0, 1, 1, 1, 1), "thumb.across": 0, spread: 0, roll: 70 }),
266
- peace: wt({ ...xt(0.75, 0, 0, 1, 1), "thumb.across": 0.9, spread: 1 }),
267
- ok: wt({ ...xt(0.12, 0.6, 0.1, 0.15, 0.2), "thumb.across": 0.55, spread: 0.6 }),
268
- pinch: wt({ ...xt(0.1, 0.65, 0.75, 0.85, 0.9), "thumb.across": 0.55, spread: 0 }),
269
- cupped: wt({ ...xt(0.25, 0.4, 0.4, 0.4, 0.4), "thumb.across": 0.4, spread: 0.05, turn: 2 }),
270
- wave: wt({ ...xt(0, 0.05, 0.05, 0.1, 0.12), "thumb.across": 0, spread: 0.7, turn: 2 }),
271
- /** Holding a pencil to write: thumb and middle finger pinch it, the index finger rests on top */
272
- pencilGrip: wt({ ...xt(0.1, 0.6, 0.72, 0.88, 0.95), "thumb.across": 0.5, spread: 0, turn: 0.8, bend: 10 }),
273
- /** Holding a handle, a cup or a bar: every finger wrapped round it */
274
- hold: wt({ ...xt(0.5, 0.7, 0.72, 0.74, 0.76), "thumb.across": 0.75, spread: 0, turn: 1 })
275
- };
276
- function Ls(t, e, n) {
277
- const o = { ...t };
278
- for (const [s, r] of Object.entries(e)) {
279
- const i = t[s] ?? r;
280
- o[s] = i + (r - i) * n;
281
- }
282
- return o;
283
- }
284
- const Cs = {
285
- index: { knuckle: [-0.16, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.125, fan: -1 },
286
- middle: { knuckle: [-0.055, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.13, fan: -0.2 },
287
- ring: { knuckle: [0.05, 0.475, -0.02], bones: [0.2, 0.125, 0.1], width: 0.122, fan: 0.55 },
288
- pinky: { knuckle: [0.15, 0.43, -0.02], bones: [0.16, 0.1, 0.085], width: 0.108, fan: 1.25 }
289
- }, Rs = {
290
- index: { knuckle: [-0.14, 0.47, -0.02], bones: [0.2, 0.125, 0.1], width: 0.15, fan: -1 },
291
- middle: { knuckle: [0, 0.49, -0.02], bones: [0.22, 0.135, 0.1], width: 0.155, fan: 0 },
292
- pinky: { knuckle: [0.14, 0.45, -0.02], bones: [0.19, 0.115, 0.095], width: 0.145, fan: 1 }
293
- }, Wt = {
294
- base: [-0.11, 0.1, -0.05],
295
- bones: [0.2, 0.15, 0.12],
296
- widths: [0.2, 0.145, 0.135],
297
- /** Where the thumb points with `across` 0 and 1 */
298
- out: [-0.7, 0.68, -0.22],
299
- across: [0.35, 0.5, -0.8]
300
- }, Bs = [82, 100, 62], Ns = [48, 72], Ys = 3, zs = 13, Ds = 0.035, qs = -0.075, Us = [
301
- [-0.17, 0],
302
- [-0.215, 0.12],
303
- [-0.235, 0.26],
304
- [-0.225, 0.4],
305
- [-0.185, 0.49],
306
- [-0.075, 0.525],
307
- [0.05, 0.51],
308
- [0.16, 0.465],
309
- [0.215, 0.4],
310
- [0.225, 0.26],
311
- [0.2, 0.1],
312
- [0.16, 0]
313
- ], Ct = (t) => t * Math.PI / 180, nn = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], Pe = (t, e) => [t[0] * e, t[1] * e, t[2] * e], on = (t, e) => [t[1] * e[2] - t[2] * e[1], t[2] * e[0] - t[0] * e[2], t[0] * e[1] - t[1] * e[0]], re = (t) => {
314
- const e = Math.hypot(t[0], t[1], t[2]) || 1;
315
- return [t[0] / e, t[1] / e, t[2] / e];
316
- };
317
- function Dt(t, e, n) {
318
- const o = Math.cos(n), s = Math.sin(n), r = on(e, t), i = e[0] * t[0] + e[1] * t[1] + e[2] * t[2];
319
- return [
320
- t[0] * o + r[0] * s + e[0] * i * (1 - o),
321
- t[1] * o + r[1] * s + e[1] * i * (1 - o),
322
- t[2] * o + r[2] * s + e[2] * i * (1 - o)
323
- ];
324
- }
325
- const Tn = [1, 0, 0], Wn = [0, 1, 0], ae = [0, 0, 1];
326
- function Xs(t, e, n) {
327
- const o = Ct(t.fan * (Ys + zs * n)), s = [Math.sin(o), Math.cos(o), 0], r = [Math.cos(o), -Math.sin(o), 0], i = [t.knuckle];
328
- let a = 0;
329
- t.bones.forEach((h, f) => {
330
- a += Ct(Bs[f] * e), i.push(nn(i[f], Pe(Dt(s, r, -a), h)));
331
- });
332
- const l = Dt(ae, r, -a), c = i.map((h, f) => t.width * (1 - 0.14 * (f / (i.length - 1))));
333
- return { joints: i, back: l, widths: c };
334
- }
335
- function Gs(t, e, n = 1, o = 1) {
336
- const s = Math.min(1, Math.max(0, e)), r = re(nn(Pe(re(Wt.out), 1 - s), Pe(re(Wt.across), s))), i = re(on(ae, r)), a = re(on(r, i)), l = [[Wt.base[0] * o, Wt.base[1], Wt.base[2]]];
337
- let c = 0;
338
- Wt.bones.forEach((y, u) => {
339
- u > 0 && (c += Ct(Ns[u - 1] * t)), l.push(nn(l[u], Pe(Dt(r, i, c), y)));
340
- });
341
- const h = Dt(a, i, c), f = [...Wt.widths, Wt.widths[Wt.widths.length - 1] * 0.92].map((y) => y * n);
342
- return { joints: l, back: h, widths: f };
343
- }
344
- function Ks(t, e = {}) {
345
- const n = { ...It, ...t }, o = e.size ?? 100, s = e.side ?? "right", r = s === "left" ? -1 : 1, i = Ct(e.angle ?? 0), a = e.fingers === 4, l = Math.max(0.5, e.plump ?? 1), c = 1 + (l - 1) * 0.7, h = (w) => ({
346
- ...w,
347
- knuckle: [w.knuckle[0] * c, w.knuckle[1], w.knuckle[2]],
348
- width: w.width * l
349
- }), f = Ct(n.bend ?? 0), y = Ct(n.tilt ?? 0), u = Ct(90 * (n.turn ?? 0)), g = (w) => Dt(Dt(Dt(w, Tn, -f), ae, -y), Wn, u), m = Math.cos(i), d = Math.sin(i), b = Ct(n.roll ?? 0), x = Math.cos(b), M = Math.sin(b), v = (w) => {
350
- const E = w[0] * o, H = -w[1] * o, N = (E * x - H * M) * r, D = E * M + H * x;
351
- return { x: N * m - D * d, y: N * d + D * m };
352
- }, P = (w) => {
353
- const E = v(w), H = Math.hypot(E.x, E.y);
354
- return H > 1e-6 * o ? { x: E.x / H, y: E.y / H } : { x: 0, y: 0 };
355
- }, C = {
356
- thumb: Gs(n["thumb.curl"] ?? 0, n["thumb.across"] ?? 0, l, c)
357
- }, I = a ? Rs : Cs;
358
- for (const w of Fs) {
359
- const E = I[w];
360
- E && (C[w] = Xs(h(E), n[`${w}.curl`] ?? 0, n.spread ?? 0));
361
- }
362
- const $ = {};
363
- for (const [w, E] of Object.entries(C)) {
364
- const H = E.joints.map(g), N = g(E.back);
365
- $[w] = {
366
- points: H.map(v),
367
- depths: H.map((D) => D[2] * o),
368
- widths: E.widths.map((D) => D * o),
369
- nail: N[2],
370
- back: P(N)
371
- };
372
- }
373
- const A = Us.flatMap(([w, E]) => [g([w * c, E, Ds]), g([w * c, E, qs])]), z = Js(A.map(v)), R = A.reduce((w, E) => w + E[2], 0) / A.length * o;
374
- return {
375
- size: o,
376
- side: s,
377
- wrist: { x: 0, y: 0 },
378
- palm: z,
379
- palmDepth: R,
380
- palmFacing: -g(ae)[2],
381
- fingers: $,
382
- axes: { up: P(g(Wn)), across: P(g(Tn)), out: P(g(ae)) },
383
- curls: Object.fromEntries(Object.keys($).map((w) => [w, n[`${w}.curl`] ?? 0]))
384
- };
385
- }
386
- function Vs(t, e) {
387
- const n = (s) => ({ x: s.x + e.x - t.wrist.x, y: s.y + e.y - t.wrist.y }), o = {};
388
- for (const [s, r] of Object.entries(t.fingers))
389
- o[s] = { ...r, points: r.points.map(n) };
390
- return { ...t, wrist: n(t.wrist), palm: t.palm.map(n), fingers: o };
391
- }
392
- function Js(t) {
393
- const e = [...t].sort((r, i) => r.x - i.x || r.y - i.y);
394
- if (e.length < 3) return e;
395
- const n = (r, i, a) => (i.x - r.x) * (a.y - r.y) - (i.y - r.y) * (a.x - r.x), o = [];
396
- for (const r of e) {
397
- for (; o.length >= 2 && n(o[o.length - 2], o[o.length - 1], r) <= 0; ) o.pop();
398
- o.push(r);
399
- }
400
- const s = [];
401
- for (const r of [...e].reverse()) {
402
- for (; s.length >= 2 && n(s[s.length - 2], s[s.length - 1], r) <= 0; ) s.pop();
403
- s.push(r);
404
- }
405
- return [...o.slice(0, -1), ...s.slice(0, -1)];
406
- }
407
- function Po(t, e, n, o) {
408
- if (o.mode !== "cel" || e.length < 3) return;
409
- const s = Math.hypot(...o.light), r = e.map((a) => {
410
- const l = a.x - n.x, c = a.y - n.y, h = (l * o.light[0] + c * o.light[1]) / ((Math.hypot(l, c) || 1) * s), f = Math.max(0, -h) * 0.24;
411
- return { x: a.x - l * f, y: a.y - c * f };
412
- }), i = (a) => {
413
- t.beginPath(), t.moveTo(a[0].x, a[0].y);
414
- for (const l of a.slice(1)) t.lineTo(l.x, l.y);
415
- t.closePath();
416
- };
417
- t.save(), i(e), t.clip(), i([...e, ...r.reverse()]), t.globalAlpha *= o.opacity, t.fillStyle = o.shadow, t.fill(), t.restore();
418
- }
419
- const Zs = "#f1c9a5", Qs = "#2f2f33";
420
- function Ao(t, e, n, o = {}, s = 0) {
421
- const r = Vs(Ks(n, o), e), i = o.ink ?? Qs, a = o.lineWidth ?? r.size * 0.035;
422
- let l = o.pen ?? bn(t, {
423
- look: o.look ?? "clean",
424
- ink: i,
425
- lineWidth: a,
426
- seed: o.seed ?? 1,
427
- time: s,
428
- pencil: { construction: !1, ...o.pencil }
429
- });
430
- const c = o.skin ?? Zs;
431
- c === "none" && (l = ye(t, l));
432
- const h = o.nails ?? !0, f = [
433
- {
434
- depth: r.palmDepth,
435
- draw: () => js(t, l, r, c, a, o)
436
- }
437
- ];
438
- for (const y of Object.values(r.fingers)) {
439
- const u = y.depths.reduce((g, m) => g + m, 0) / y.depths.length;
440
- f.push({
441
- depth: u,
442
- draw: () => tr(t, l, y, c, a, h)
443
- });
444
- }
445
- if (o.prop) {
446
- const y = o.prop;
447
- f.push({ depth: y.depth, draw: () => y.draw(l) });
448
- }
449
- t.save(), t.lineCap = "round", t.lineJoin = "round";
450
- for (const y of [...f].sort((u, g) => u.depth - g.depth)) y.draw();
451
- return t.restore(), r;
452
- }
453
- function js(t, e, n, o, s, r) {
454
- if (e.shape(n.palm, o === "none" ? null : o, r.connected ? 0 : s), o !== "none" && r.shading && e.look === "clean") {
455
- const i = n.palm.reduce((a, l) => ({ x: a.x + l.x / n.palm.length, y: a.y + l.y / n.palm.length }), { x: 0, y: 0 });
456
- Po(t, n.palm, i, r.shading);
457
- }
458
- if (r.connected && s > 0 && (e.look !== "silhouette" || o === "none")) {
459
- const { up: i } = n.axes;
460
- let a = [];
461
- for (let l = 0; l <= n.palm.length; l++) {
462
- const c = n.palm[l % n.palm.length], h = n.palm[(l + 1) % n.palm.length];
463
- ((c.x + h.x) / 2 - n.wrist.x) * i.x + ((c.y + h.y) / 2 - n.wrist.y) * i.y < n.size * 0.08 ? (a.length > 1 && e.line(a, s), a = []) : (a.length === 0 && a.push(c), a.push(h));
464
- }
465
- a.length > 1 && e.line(a, s);
466
- }
467
- if (n.palmFacing < -0.3 && e.look !== "silhouette") {
468
- const { up: i } = n.axes;
469
- for (const [a, l] of Object.entries(n.fingers)) {
470
- const c = n.curls[a] ?? 0;
471
- if (a === "thumb" || c < 0.5) continue;
472
- const h = l.points[0], f = l.widths[0] * 0.42, y = { x: h.x - i.x * f * 0.2, y: h.y - i.y * f * 0.2 }, u = Math.atan2(i.y, i.x), g = Array.from({ length: 7 }, (m, d) => {
473
- const b = u - Math.PI / 2 + Math.PI * d / 6;
474
- return { x: y.x + Math.cos(b) * f, y: y.y + Math.sin(b) * f };
475
- });
476
- e.line(g, s * 0.6);
477
- }
478
- }
479
- if (n.palmFacing > 0.45 && e.look !== "silhouette") {
480
- const { up: i, across: a } = n.axes, l = n.size, c = n.wrist, h = (y, u) => ({
481
- x: c.x + (a.x * y + i.x * u) * l,
482
- y: c.y + (a.y * y + i.y * u) * l
483
- }), f = n.side === "left" ? -1 : 1;
484
- e.line([h(-0.15 * f, 0.36), h(-0.04 * f, 0.3), h(0.1 * f, 0.33)], s * 0.5);
485
- }
486
- }
487
- function tr(t, e, n, o, s, r) {
488
- const { widths: i } = n, a = er(n.points, 2), l = n.points[0], c = a[a.length - 1], h = i[0], f = i[i.length - 1];
489
- if (t.save(), e.look !== "silhouette" || o === "none") {
490
- t.beginPath(), t.rect(l.x - 1e5, l.y - 1e5, 2e5, 2e5);
491
- const m = h / 2 + s * 1.6;
492
- t.moveTo(l.x + m, l.y), t.arc(l.x, l.y, m, 0, Math.PI * 2), t.clip("evenodd");
493
- }
494
- if (o === "none") {
495
- const m = ut(a, h, f), d = a[a.length - 2], b = Math.atan2(c.y - d.y, c.x - d.x), x = Array.from({ length: 13 }, (M, v) => {
496
- const P = b + Math.PI / 2 - v * Math.PI / 12;
497
- return { x: c.x + Math.cos(P) * f / 2, y: c.y + Math.sin(P) * f / 2 };
498
- });
499
- e.shape([...m.slice(0, a.length), ...x.slice(1), ...m.slice(a.length)], null, s);
500
- } else e.limb(a, h + 2 * s, f + 2 * s);
501
- if (t.restore(), o !== "none" && e.look !== "silhouette" && (t.fillStyle = o, pn(t, a, h, f)), o === "none" || e.look === "silhouette" || !r || n.nail < 0.25) return;
502
- const y = a[a.length - 2], u = nr({ x: c.x - y.x, y: c.y - y.y }) ?? {
503
- x: 0,
504
- y: -1
505
- }, g = {
506
- x: c.x - u.x * f * 0.22 + n.back.x * f * 0.1,
507
- y: c.y - u.y * f * 0.22 + n.back.y * f * 0.1
508
- };
509
- e.ellipse(g.x, g.y, f * 0.24 * Math.max(0.35, n.nail), f * 0.19, Math.atan2(u.y, u.x), "#f8e3d3", s * 0.45);
510
- }
511
- function er(t, e) {
512
- let n = t;
513
- for (let o = 0; o < e; o++) {
514
- if (n.length < 3) return n;
515
- const s = [n[0]];
516
- for (let r = 0; r < n.length - 1; r++) {
517
- const i = n[r], a = n[r + 1];
518
- r > 0 && s.push({ x: i.x * 0.75 + a.x * 0.25, y: i.y * 0.75 + a.y * 0.25 }), r < n.length - 2 && s.push({ x: i.x * 0.25 + a.x * 0.75, y: i.y * 0.25 + a.y * 0.75 });
519
- }
520
- s.push(n[n.length - 1]), n = s;
521
- }
522
- return n;
523
- }
524
- const nr = (t) => {
525
- const e = Math.hypot(t.x, t.y);
526
- return e > 1e-6 ? { x: t.x / e, y: t.y / e } : null;
527
- }, le = {
528
- walk: { swing: 24, knee: 30, arm: 22, elbow: 28, lean: 4 },
529
- bouncy: { swing: 26, knee: 45, arm: 34, elbow: 30, lean: 2, bend: -4, bounce: 0.035, squash: 0.06 },
530
- doubleBounce: { swing: 22, knee: 40, arm: 26, elbow: 24, lean: 3, bounce: 0.02, bounces: 2, squash: 0.04 },
531
- sneak: { swing: 28, knee: 70, arm: 6, elbow: 0, forearm: 110, shoulder: 55, lean: 16, bend: 14, headTilt: -8, crouch: 50, tiptoe: 25 },
532
- strut: { swing: 26, knee: 30, arm: 30, elbow: 20, lean: -4, bend: -10, headTilt: -6, sway: 4, bounce: 0.01 },
533
- tired: { swing: 14, knee: 14, arm: 6, elbow: 6, lean: 10, bend: 16, headTilt: 12 },
534
- run: { swing: 40, knee: 95, arm: 45, elbow: 0, forearm: 90, lean: 16, bend: 6, bounce: 0.05, squash: 0.06 },
535
- shove: { swing: 18, knee: 28, arm: 0, elbow: 0, lean: 0 }
536
- }, or = 40;
537
- function Ce(t) {
538
- return t === void 0 ? le.walk : typeof t == "string" ? le[t] ?? le.walk : t;
539
- }
540
- function sr(t, e, n = Gt, o = 1) {
541
- const s = Ce(t);
542
- if (s === le.walk) return lr(e, n, o);
543
- const r = e * Math.PI * 2, i = Math.sin(r) * o, a = Math.cos(r) * o, l = (b) => Math.abs(b) <= or, c = s.shoulder ?? 0, h = (b, x) => l(b) ? x * c + s.arm * i : b, f = s.forearm ?? 0, y = l(n.leftShoulder) ? n.leftElbow - f - s.elbow * Math.max(0, -i) : n.leftElbow, u = l(n.rightShoulder) ? n.rightElbow + f + s.elbow * Math.max(0, i) : n.rightElbow, g = s.bounces ?? 1, m = (1 + Math.cos(r * 2 * g)) / 2, d = s.crouch ?? 0;
544
- return {
545
- ...n,
546
- lean: n.lean + s.lean * o + (s.sway ?? 0) * Math.sin(r) * (1 - (n.turn ?? 0)),
547
- bend: (n.bend ?? 0) + (s.bend ?? 0),
548
- headTilt: n.headTilt - s.lean * 0.5 * o + (s.headTilt ?? 0),
549
- leftElbow: y,
550
- rightElbow: u,
551
- // A crouch brings both thighs forward and folds both shins back.
552
- leftHip: -s.swing * i - d * 0.5,
553
- rightHip: -s.swing * i + d * 0.5,
554
- // The leg swinging forward lifts its knee; a crouch keeps both bent. A positive
555
- // knee folds toward the centre, which is backward only for the right leg.
556
- leftKnee: -s.knee * Math.max(0, a) - d,
557
- rightKnee: s.knee * Math.max(0, -a) + d,
558
- leftAnkle: (n.leftAnkle ?? 0) + (s.tiptoe ?? 0),
559
- rightAnkle: (n.rightAnkle ?? 0) + (s.tiptoe ?? 0),
560
- leftShoulder: h(n.leftShoulder, -1),
561
- rightShoulder: h(n.rightShoulder, 1),
562
- rise: (n.rise ?? 0) + (s.bounce ?? 0) * o * m,
563
- stretch: n.stretch * (1 + (s.squash ?? 0) * (m - 0.5))
564
- };
565
- }
566
- function Da(t, e, n = 1) {
567
- const o = Ce(t), s = le.walk.swing, r = (i) => Math.sin(i * Math.PI / 180);
568
- return hr(e, n) * r(o.swing * n) / r(s * n);
569
- }
570
- const Gt = {
571
- lean: 0,
572
- bend: 0,
573
- headTilt: 0,
574
- leftShoulder: 18,
575
- rightShoulder: 18,
576
- leftElbow: -6,
577
- rightElbow: -6,
578
- leftHip: 8,
579
- rightHip: 8,
580
- leftKnee: 0,
581
- rightKnee: 0,
582
- leftWrist: 0,
583
- rightWrist: 0,
584
- leftAnkle: 0,
585
- rightAnkle: 0,
586
- leftFootOut: 0,
587
- rightFootOut: 0,
588
- mouth: 0,
589
- smile: 0.6,
590
- mouthWidth: 1,
591
- blink: 0,
592
- leftEye: 1,
593
- rightEye: 1,
594
- leftBrow: 0,
595
- rightBrow: 0,
596
- browTilt: 0,
597
- lookX: 0,
598
- lookY: 0,
599
- stretch: 1,
600
- turn: 0,
601
- sit: 0,
602
- spin: 0,
603
- rise: 0
604
- };
605
- function ft(t) {
606
- return { ...Gt, ...t };
607
- }
608
- const Io = {
609
- mouth: 0,
610
- smile: 0,
611
- mouthWidth: 1,
612
- leftEye: 1,
613
- rightEye: 1,
614
- leftBrow: 0,
615
- rightBrow: 0,
616
- browTilt: 0,
617
- lookX: 0,
618
- lookY: 0
619
- }, ct = (t) => ({ ...Io, ...t }), kt = {
620
- neutral: Io,
621
- happy: ct({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
622
- joyful: ct({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
623
- sad: ct({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
624
- crying: ct({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
625
- surprised: ct({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
626
- shocked: ct({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
627
- angry: ct({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
628
- furious: ct({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
629
- worried: ct({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
630
- scared: ct({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
631
- confused: ct({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
632
- skeptical: ct({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
633
- thinking: ct({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
634
- sleepy: ct({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
635
- disgusted: ct({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
636
- smug: ct({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
637
- wink: ct({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
638
- };
639
- function rr(t, e) {
640
- return { ...t, ...typeof e == "string" ? kt[e] : e };
641
- }
642
- const ir = {
643
- rest: Gt,
644
- wave: ft({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...kt.happy }),
645
- cheer: ft({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...kt.joyful }),
646
- shrug: ft({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...kt.confused, lookX: 0, lookY: 0 }),
647
- point: ft({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
648
- // The forearm passes 180° to fold back in, so the hand reaches the chin.
649
- think: ft({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...kt.thinking }),
650
- handsOnHips: ft({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
651
- sad: ft({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...kt.sad }),
652
- surprised: ft({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...kt.surprised }),
653
- // Squash and stretch: the wind-up before a jump (or the landing), and the jump itself.
654
- crouch: ft({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
655
- // Seated, hands resting on the knees. Arm angles spread outward per side, so
656
- // reaching forward (+x, the way the figure faces) is negative for the left arm.
657
- sit: ft({ sit: 1, turn: 0.5, leftShoulder: -25, rightShoulder: 25, leftElbow: -55, rightElbow: 55 }),
658
- jump: ft({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...kt.joyful }),
659
- // Ducking: squashed low, bent over, arms over the head.
660
- duck: ft({ stretch: 0.62, bend: 28, headTilt: -8, leftShoulder: 150, rightShoulder: 150, leftElbow: 130, rightElbow: 130, leftHip: 25, rightHip: 25, ...kt.scared }),
661
- // Lying on its back on the floor (rolled back about the hips and lowered), hands behind the head.
662
- lie: ft({ spin: -90, rise: -0.42, leftShoulder: 165, rightShoulder: 165, leftElbow: 150, rightElbow: 150, ...kt.sleepy }),
663
- // Full splits: legs flat along the floor, so the planted feet bring the hips right down to it.
664
- // Side (straddle) split, seen front-on: each leg straight out to its side, toes pointed.
665
- sideSplit: ft({ leftHip: 90, rightHip: 90, leftAnkle: -45, rightAnkle: -45, leftShoulder: 120, rightShoulder: 120, leftElbow: 10, rightElbow: 10, ...kt.happy }),
666
- // Front split, in profile: the left leg forward (+x), the right leg back.
667
- frontSplit: ft({ turn: 1, leftHip: -90, rightHip: -90, leftAnkle: -45, rightAnkle: -45, leftShoulder: -150, rightShoulder: 150, leftElbow: 10, rightElbow: -10, ...kt.happy })
668
- }, Oo = Object.keys(Gt);
669
- function Hn(t, e, n) {
670
- const o = { ...t };
671
- for (const s of Oo) o[s] = t[s] + (e[s] - t[s]) * n;
672
- return o;
673
- }
674
- const sn = 24, $n = 4, _n = 28, ar = 40;
675
- function lr(t, e = Gt, n = 1) {
676
- const o = Math.sin(t * Math.PI * 2) * n, s = Math.cos(t * Math.PI * 2) * n, r = (c) => Math.abs(c) <= ar, i = (c) => r(c) ? 22 * o : c, a = r(e.leftShoulder) ? e.leftElbow - _n * Math.max(0, -o) : e.leftElbow, l = r(e.rightShoulder) ? e.rightElbow + _n * Math.max(0, o) : e.rightElbow;
677
- return {
678
- ...e,
679
- // Lean into the walk, and keep the head a little more level than the body.
680
- lean: e.lean + $n * n,
681
- headTilt: e.headTilt - $n * 0.5 * n,
682
- leftElbow: a,
683
- rightElbow: l,
684
- // Left foot forward while swing > 0, right foot back; then the other way.
685
- leftHip: -sn * o,
686
- rightHip: -sn * o,
687
- // The leg swinging forward lifts, its shin trailing backward (-x). A positive
688
- // knee folds toward the centre, which is backward only for the right leg.
689
- leftKnee: -30 * Math.max(0, s),
690
- rightKnee: 30 * Math.max(0, -s),
691
- // Arms swing against the legs: left arm back while the left foot is forward.
692
- leftShoulder: i(e.leftShoulder),
693
- rightShoulder: i(e.rightShoulder)
694
- };
695
- }
696
- function hr(t, e = 1) {
697
- return 4 * ((rn + Te) * t) * Math.sin(sn * e * Math.PI / 180);
698
- }
699
- function cr(t) {
700
- const e = Math.abs(Math.sin(t / 65)), n = 0.55 + 0.45 * Math.sin(t / 310);
701
- return e * n;
702
- }
703
- const To = 0.12, Fn = 0.46, fr = 1 - 2 * To, ur = 0.1, dr = 0.21, gr = 0.19, rn = 0.24, Te = 0.22, Wo = 0.12, yr = 0.14, Ho = 0.33, Ln = 0.7, Cn = 0.3, mr = 0.35, pr = [1.7, 1.05], br = [1.3, 0.75], Rn = [1.45, 0.85], wr = [1.15, 0.75], Bn = 0.06, xr = 0.7, Mr = 0.65, $o = 0.075, kr = 0.3, vr = 0.02, Er = 0.012, Sr = 12, Pr = 0.25, we = 90, Ar = 0.25, Ir = 0.04, _o = 0.01, zt = (t) => Math.min(1, Math.max(0, t ?? 0));
704
- function qa(t, e = 1) {
705
- return Te * t * e;
706
- }
707
- const an = -0.12, Fo = 0.4, St = (t) => t * Math.PI / 180, Or = (t, e) => ({ x: e * Math.sin(St(t)), y: Math.cos(St(t)) }), Lo = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), Co = (t, e, n, o) => t - 0.3 * e - n * 0.14 * e - Math.max(0, o - 1) * 0.12 * e;
708
- function Tr(t, e, n, o, s, r) {
709
- const i = Math.max(1, Math.min(r * 0.6, yr * n)), a = zt(e.turn), l = (Wo + Ho * a) * n, c = o + an * n, h = l + e.lookX * 0.08 * n, f = e.lookY * 0.07 * n, y = [
710
- // The left eye is on the far side; turning closes it up more than the near one.
711
- { x: -0.34 * n * (1 - Ln * a), squeeze: 1 - Ln * a, open: e.leftEye, brow: e.leftBrow, side: -1 },
712
- { x: 0.34 * n * (1 - Cn * a), squeeze: 1 - Cn * a, open: e.rightEye, brow: e.rightBrow, side: 1 }
713
- ];
714
- t.fillStyle = s, t.strokeStyle = s, t.lineWidth = i;
715
- for (const b of y) {
716
- const x = Lo(b.open, e.blink);
717
- if (x < 0.2) {
718
- const C = e.smile > 0.5 ? -0.12 * n : 0.06 * n;
719
- t.beginPath(), t.moveTo(b.x + l - 0.12 * n, c), t.quadraticCurveTo(b.x + l, c + C, b.x + l + 0.12 * n, c), t.stroke();
720
- } else {
721
- if (x > 1.2) {
722
- const I = 0.13 * n * x;
723
- t.beginPath(), t.ellipse(b.x + l, c, I * 0.85, I, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = s;
724
- }
725
- const C = x > 1.2 ? 0.075 * n : 0.1 * n;
726
- t.beginPath(), t.ellipse(b.x + h, c + f, C, C * 1.1 * Math.min(x, 1), 0, 0, Math.PI * 2), t.fill();
727
- }
728
- const M = Co(c, n, b.brow, x), v = b.x + l - b.side * 0.13 * n * b.squeeze, P = b.x + l + b.side * 0.13 * n * b.squeeze;
729
- t.beginPath(), t.moveTo(P, M), t.lineTo(v, M - e.browTilt * 0.1 * n), t.stroke();
730
- }
731
- const u = o + Fo * n, g = 0.25 * n * Math.max(0.3, e.mouthWidth) * (1 - mr * a), m = Math.min(1, Math.max(0, e.mouth));
732
- if (t.beginPath(), m <= 0.05) {
733
- t.moveTo(l - g, u), t.quadraticCurveTo(l, u + e.smile * 0.25 * n, l + g, u), t.stroke();
734
- return;
735
- }
736
- const d = 0.3 * n * m;
737
- e.smile > 0.3 ? (t.moveTo(l - g, u - 0.05 * n), t.lineTo(l + g, u - 0.05 * n), t.quadraticCurveTo(l, u + d * 2, l - g, u - 0.05 * n)) : e.smile < -0.3 ? (t.moveTo(l - g, u + d * 0.6), t.lineTo(l + g, u + d * 0.6), t.quadraticCurveTo(l, u - d * 1.4, l - g, u + d * 0.6)) : t.ellipse(l, u, g * 0.8, d, 0, 0, Math.PI * 2), t.fill();
738
- }
739
- function Ro(t, e) {
740
- const n = e.height ?? 300, o = Math.min(3, Math.max(0.3, t.stretch ?? 1)), s = Math.sqrt(o), r = e.armLength ?? 1;
741
- if (!Number.isFinite(r) || r <= 0) throw new Error("stick figure: armLength must be a positive finite multiplier");
742
- const i = (e.headSize ?? 2 * To) / 2, a = e.headSize === void 0 ? fr : 1 - 2 * i, l = i * n, c = zt(t.sit), h = t.leftHip + (-we - t.leftHip) * c, f = t.leftKnee + (-we - t.leftKnee) * c, y = t.rightHip + (we - t.rightHip) * c, u = t.rightKnee + (we - t.rightKnee) * c, g = e.classic === !0, m = zt(t.turn), d = (q, J, j, Q, nt) => {
743
- const lt = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, Math.abs(St(J - j) / 2) + St(Q))), bt = Math.max(-1, Math.min(1, xr + nt)), p = m + (1 - m) * q * bt;
744
- return g ? { x: 0, y: 0 } : { x: Math.cos(lt) * Bn * p, y: Math.sin(lt) * Bn };
745
- }, b = { left: t.leftAnkle ?? 0, right: t.rightAnkle ?? 0 }, x = { left: t.leftFootOut ?? 0, right: t.rightFootOut ?? 0 };
746
- let M = 0;
747
- if (c > 0 || !g) {
748
- const q = (nt, lt, bt, p, k) => rn * Math.cos(St(lt)) + Te * Math.cos(St(lt - bt)) + Math.max(0, d(nt, lt, bt, p, k).y), J = Math.max(
749
- q(-1, h, f, b.left, x.left),
750
- q(1, y, u, b.right, x.right)
751
- ), j = 1 - zt((t.rise ?? 0) / Ir), Q = (g ? Math.min(1, c / Ar) : 1) * j;
752
- M = (Fn - J) * Q * n * o;
753
- }
754
- const v = -Fn * n * o + M, P = -a * n * o + M, C = g ? 0 : (vr * zt(t.turn) + Er * c) * n * o, I = St(t.bend ?? 0), $ = { end: Yn(v, P, I, 1), bend: I };
755
- let A;
756
- if (I !== 0) {
757
- A = [];
758
- for (let q = 0; q <= Nn; q++) {
759
- const J = q / Nn, j = Yn(v, P, I, J);
760
- A.push({ x: j.x - C * Math.sin(Math.PI * J), y: j.y });
761
- }
762
- } else
763
- A = C === 0 ? [{ x: 0, y: v }, { x: 0, y: P }] : ne({ x: 0, y: v }, { x: -C, y: (v + P) / 2 }, { x: 0, y: P }, 1, 8);
764
- const z = P + ur * n * o, R = (e.shoulderWidth ?? 0) * n * Math.cos(m * Math.PI / 2), w = (q, J, j, Q, nt) => {
765
- const lt = Or(j, Q);
766
- return { x: q + lt.x * nt * n, y: J + lt.y * nt * n };
767
- }, E = (q, J, j) => {
768
- const Q = w(0, v, J, q, rn * o);
769
- return { root: { x: 0, y: v }, joint: Q, end: w(Q.x, Q.y, J - j, q, Te * o) };
770
- }, H = (q, J, j) => {
771
- const Q = { x: q * R, y: z }, nt = w(Q.x, Q.y, J, q, dr * s * r);
772
- return { root: Q, joint: nt, end: w(nt.x, nt.y, J + j, q, gr * s * r) };
773
- }, N = { left: E(-1, h, f), right: E(1, y, u) }, D = (q, J, j, Q, nt, lt) => {
774
- const bt = d(q, j, Q, nt, lt);
775
- return { x: J.end.x + bt.x * n * o, y: J.end.y + bt.y * n * o };
776
- }, X = (q, J, j, Q, nt) => w(J.end.x, J.end.y, j + Q + nt, q, $o * s), K = {
777
- left: H(-1, t.leftShoulder, t.leftElbow),
778
- right: H(1, t.rightShoulder, t.rightElbow)
779
- };
780
- return {
781
- height: n,
782
- facing: (e.facing ?? 1) < 0 ? -1 : 1,
783
- stretch: o,
784
- lineWidth: e.lineWidth ?? n * 0.025,
785
- rubber: Math.min(1, Math.max(g ? 0 : kr, e.rubber ?? 0)),
786
- r: l,
787
- // The head keeps its area: taller and narrower when stretched.
788
- headRx: l / Math.sqrt(o),
789
- headRy: l * Math.sqrt(o),
790
- hipY: v,
791
- neckY: P,
792
- drop: M,
793
- lean: g ? t.lean : t.lean + Sr * Math.sin(Math.PI * c),
794
- classic: g,
795
- legs: N,
796
- toes: {
797
- left: D(-1, N.left, h, f, b.left, x.left),
798
- right: D(1, N.right, y, u, b.right, x.right)
799
- },
800
- spine: A,
801
- chest: $,
802
- arms: K,
803
- handTips: {
804
- left: X(-1, K.left, t.leftShoulder, t.leftElbow, t.leftWrist ?? 0),
805
- right: X(1, K.right, t.rightShoulder, t.rightElbow, t.rightWrist ?? 0)
806
- }
807
- };
808
- }
809
- const Nn = 10;
810
- function Yn(t, e, n, o) {
811
- const s = t - e, r = n * o;
812
- if (Math.abs(n) < 1e-9) return { x: 0, y: t - s * o };
813
- const i = s / n;
814
- return { x: i * (1 - Math.cos(r)), y: t - i * Math.sin(r) };
815
- }
816
- function Wr(t, e) {
817
- if (t.chest.bend === 0) return e;
818
- const n = fe(e, { x: 0, y: t.neckY }, t.chest.bend);
819
- return { x: n.x + t.chest.end.x, y: n.y + t.chest.end.y - t.neckY };
820
- }
821
- const ie = (t, e) => e === 0 ? [t.root, t.joint, t.end] : ne(t.root, t.joint, t.end, e);
822
- function fe(t, e, n) {
823
- const o = Math.cos(n), s = Math.sin(n), r = t.x - e.x, i = t.y - e.y;
824
- return { x: e.x + r * o - i * s, y: e.y + r * s + i * o };
825
- }
826
- function Bo(t, e, n = !0) {
827
- const o = $r(t, e), s = e.spin ?? 0, r = e.rise ?? 0;
828
- return n && (s !== 0 || r !== 0) ? Hr(o, t, s, r) : o;
829
- }
830
- function No(t, e, n) {
831
- return { pivot: { x: 0, y: t.hipY }, angle: t.facing * St(e), lift: n * t.height };
832
- }
833
- function Hr(t, e, n, o) {
834
- const { pivot: s, angle: r, lift: i } = No(e, n, o), a = (y) => {
835
- const u = fe(y, s, r);
836
- return { x: u.x, y: u.y - i };
837
- }, l = (y) => ({ left: a(y.left), right: a(y.right) }), c = { left: Math.max(a(t.feet.left).y, a(t.toes.left).y), right: Math.max(a(t.feet.right).y, a(t.toes.right).y) }, h = Math.max(c.left, c.right), f = _o * e.height;
838
- return {
839
- ...t,
840
- hip: a(t.hip),
841
- neck: a(t.neck),
842
- shoulders: l(t.shoulders),
843
- elbows: l(t.elbows),
844
- hands: l(t.hands),
845
- fingertips: l(t.fingertips),
846
- knees: l(t.knees),
847
- feet: l(t.feet),
848
- toes: l(t.toes),
849
- feetY: h,
850
- grounded: { left: c.left >= h - f, right: c.right >= h - f },
851
- handAngle: { left: t.handAngle.left + r, right: t.handAngle.right + r },
852
- limbs: {
853
- leftArm: t.limbs.leftArm.map(a),
854
- rightArm: t.limbs.rightArm.map(a),
855
- leftLeg: t.limbs.leftLeg.map(a),
856
- rightLeg: t.limbs.rightLeg.map(a),
857
- spine: t.limbs.spine.map(a)
858
- },
859
- head: { ...t.head, center: a(t.head.center), angle: t.head.angle + r }
860
- };
861
- }
862
- function $r(t, e) {
863
- const n = St(t.lean), o = St(e.headTilt), s = { x: 0, y: t.hipY }, r = (v) => ({ x: t.facing * v.x, y: v.y }), i = (v) => r(fe(v, s, n)), a = (v) => i(Wr(t, v)), l = (v) => a(fe({ x: v.x, y: v.y + t.neckY }, { x: 0, y: t.neckY }, o)), c = ie(t.arms.left, t.rubber).map(a), h = ie(t.arms.right, t.rubber).map(a), f = (v, P) => Math.atan2(P.y - v.y, P.x - v.x), y = { left: a(t.handTips.left), right: a(t.handTips.right) }, u = (v, P) => {
864
- const [C, I] = v.slice(-2), $ = t.arms[P], A = f(a($.end), y[P]) - f(a($.joint), a($.end));
865
- return f(C, I) + A;
866
- };
867
- let g = 1 / 0;
868
- for (const [v, P] of [
869
- [e.leftBrow, e.leftEye],
870
- [e.rightBrow, e.rightEye]
871
- ]) {
872
- const C = Co(an, 1, v, Lo(P, e.blink));
873
- g = Math.min(g, C, C - e.browTilt * 0.1);
874
- }
875
- const m = { left: r(t.legs.left.end), right: r(t.legs.right.end) }, d = { left: r(t.toes.left), right: r(t.toes.right) }, b = { left: Math.max(m.left.y, d.left.y), right: Math.max(m.right.y, d.right.y) }, x = Math.max(b.left, b.right), M = _o * t.height;
876
- return {
877
- facing: t.facing,
878
- height: t.height,
879
- stretch: t.stretch,
880
- lineWidth: t.lineWidth,
881
- hip: s,
882
- neck: a({ x: 0, y: t.neckY }),
883
- shoulders: { left: a(t.arms.left.root), right: a(t.arms.right.root) },
884
- elbows: { left: a(t.arms.left.joint), right: a(t.arms.right.joint) },
885
- hands: { left: a(t.arms.left.end), right: a(t.arms.right.end) },
886
- knees: { left: r(t.legs.left.joint), right: r(t.legs.right.joint) },
887
- feet: m,
888
- toes: d,
889
- feetY: x,
890
- grounded: { left: b.left >= x - M, right: b.right >= x - M },
891
- fingertips: y,
892
- handAngle: { left: u(c, "left"), right: u(h, "right") },
893
- limbs: {
894
- leftArm: c,
895
- rightArm: h,
896
- leftLeg: ie(t.legs.left, t.rubber).map(r),
897
- rightLeg: ie(t.legs.right, t.rubber).map(r),
898
- spine: t.spine.map(i)
899
- },
900
- head: {
901
- center: l({ x: 0, y: -t.headRy }),
902
- rx: t.headRx,
903
- ry: t.headRy,
904
- // Mirroring a turn reverses it.
905
- angle: t.facing * (n + t.chest.bend + o),
906
- eyeY: an,
907
- browTopY: g,
908
- mouthY: Fo,
909
- faceX: t.facing * (Wo + Ho * zt(e.turn))
910
- }
911
- };
912
- }
913
- function _r(t, e = {}) {
914
- return Bo(Ro(t, e), t);
915
- }
916
- function Ua(t, e, n) {
917
- return fe({ x: t.center.x + e * t.rx, y: t.center.y + n * t.ry }, t.center, t.angle);
918
- }
919
- function Fr(t, e, n) {
920
- const o = (r) => ({ x: r.x + e, y: r.y + n }), s = (r) => ({ left: o(r.left), right: o(r.right) });
921
- return {
922
- ...t,
923
- hip: o(t.hip),
924
- neck: o(t.neck),
925
- shoulders: s(t.shoulders),
926
- elbows: s(t.elbows),
927
- hands: s(t.hands),
928
- fingertips: s(t.fingertips),
929
- knees: s(t.knees),
930
- feet: s(t.feet),
931
- toes: s(t.toes),
932
- feetY: t.feetY + n,
933
- grounded: { ...t.grounded },
934
- handAngle: { ...t.handAngle },
935
- limbs: {
936
- leftArm: t.limbs.leftArm.map(o),
937
- rightArm: t.limbs.rightArm.map(o),
938
- leftLeg: t.limbs.leftLeg.map(o),
939
- rightLeg: t.limbs.rightLeg.map(o),
940
- spine: t.limbs.spine.map(o)
941
- },
942
- head: { ...t.head, center: o(t.head.center) }
943
- };
944
- }
945
- function Lr(t, e, n = {}, o = 0) {
946
- const s = Ro(e, n), r = n.color ?? "#1e293b", i = n.layers ?? {}, a = n.layers ? Bo(s, e, !1) : void 0, l = n.sketch ? In(t, n.sketch, o) : void 0, c = n.sketch && n.layers ? In(t, n.sketch, o) : void 0, h = (I) => {
947
- t.save(), I(), t.restore();
948
- }, f = (I) => {
949
- I && a && h(() => I(t, a, o, c));
950
- }, y = () => t.scale(s.facing, 1), u = () => {
951
- y(), t.translate(0, s.hipY), t.rotate(St(s.lean)), t.translate(0, -s.hipY);
952
- }, g = () => {
953
- u(), s.chest.bend !== 0 && (t.translate(s.chest.end.x, s.chest.end.y), t.rotate(s.chest.bend), t.translate(0, -s.neckY));
954
- }, m = (I, $, A) => {
955
- if (l) return $ ? l.curve(I) : l.line(I);
956
- if (s.classic) {
957
- t.beginPath(), t.moveTo(I[0].x, I[0].y);
958
- for (const z of I.slice(1)) t.lineTo(z.x, z.y);
959
- t.stroke();
960
- return;
961
- }
962
- pn(t, I, A[0] * s.lineWidth, A[1] * s.lineWidth);
963
- }, d = (I, $) => m(ie(I, s.rubber), s.rubber > 0, $), b = (I) => {
964
- s.classic || m([s.legs[I].end, s.toes[I]], !1, wr);
965
- }, x = (I) => {
966
- if (n.hands && !s.classic) return v(I);
967
- if (s.classic || l) return;
968
- const $ = s.arms[I].end;
969
- t.beginPath(), t.arc($.x, $.y, Mr * s.lineWidth, 0, Math.PI * 2), t.fill();
970
- };
971
- t.save(), t.strokeStyle = r, t.fillStyle = r, t.lineWidth = s.lineWidth, t.lineCap = "round", t.lineJoin = "round";
972
- const M = No(s, e.spin ?? 0, e.rise ?? 0);
973
- (M.angle !== 0 || M.lift !== 0) && (t.translate(0, -M.lift), t.translate(M.pivot.x, M.pivot.y), t.rotate(M.angle), t.translate(-M.pivot.x, -M.pivot.y));
974
- function v(I) {
975
- const $ = n.hands ?? {}, A = s.arms[I].end, z = s.handTips[I], R = n.headFill ?? "#ffffff";
976
- Ao(t, A, $[I] ?? It, {
977
- side: I,
978
- // Degrees clockwise from straight up, in the frame the hand is drawn in.
979
- angle: Math.atan2(z.x - A.x, A.y - z.y) * 180 / Math.PI,
980
- size: ($.size ?? $o) * s.height * Math.sqrt(s.stretch),
981
- skin: $.skin ?? (R === "none" ? void 0 : R),
982
- ink: r,
983
- lineWidth: s.lineWidth * 0.45,
984
- fingers: $.fingers,
985
- plump: $.plump,
986
- look: n.sketch ? "pencil" : "clean",
987
- seed: n.sketch?.seed
988
- }, o);
989
- }
990
- const P = (I) => {
991
- h(() => {
992
- g(), d(s.arms[I], br), x(I);
993
- });
994
- const $ = i.sleeve;
995
- $ && a && h(() => $(t, a, I, o, c));
996
- }, C = zt(e.turn) > Pr;
997
- f(i.behind), h(() => {
998
- y(), d(s.legs.left, Rn), b("left"), d(s.legs.right, Rn), b("right");
999
- }), C && P("left"), h(() => {
1000
- u(), m(s.spine, s.spine.length > 2, pr);
1001
- }), h(() => {
1002
- g();
1003
- const { left: I, right: $ } = { left: s.arms.left.root, right: s.arms.right.root };
1004
- if (I.x !== $.x)
1005
- if (s.classic) m([I, $], !1, [1, 1]);
1006
- else {
1007
- const A = { x: (I.x + $.x) / 2, y: I.y - 0.3 * Math.abs($.x - I.x) };
1008
- m(ne(I, A, $, 1, 8), !0, [1.1, 1.1]);
1009
- }
1010
- }), f(i.body), C || P("left"), P("right"), f(i.behindHead), h(() => {
1011
- g(), t.translate(0, s.neckY), t.rotate(St(e.headTilt));
1012
- const I = -s.headRy;
1013
- t.beginPath(), t.ellipse(0, I, s.headRx, s.headRy, 0, 0, Math.PI * 2);
1014
- const $ = n.headFill ?? "#ffffff";
1015
- if ($ !== "none" && (t.fillStyle = $, t.fill()), l) {
1016
- l.ellipse(0, I, s.headRx, s.headRy);
1017
- const A = l.nudge();
1018
- t.translate(A.x, A.y);
1019
- } else
1020
- t.stroke();
1021
- t.translate(0, I), t.scale(s.headRx / s.r, s.headRy / s.r), Tr(t, e, s.r, 0, r, s.lineWidth);
1022
- }), f(i.overHead), f(i.front), t.restore(), n.label && (t.save(), t.fillStyle = r, t.font = n.labelFont ?? `700 ${Math.round(s.height * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(n.label, 0, -s.height * s.stretch - 0.04 * s.height + s.drop), t.restore());
1023
- }
1024
- function Yo(t, e, n, o) {
1025
- const s = { ...t }, r = t.gait && o?.[t.gait] || t.gait;
1026
- let i = t.walking > 0 ? Hn(s, sr(r, t.walk, s), t.walking) : s, a = Rr(t);
1027
- const l = t.dancing ?? 0;
1028
- if (n && l > 0) {
1029
- const c = n(t.beat ?? 0);
1030
- if (i = Hn(i, c.pose, l), c.hands) {
1031
- const h = (f, y) => y ? Ls(f ?? It, y, l) : f;
1032
- a = { left: h(a?.left, c.hands.left), right: h(a?.right, c.hands.right) };
1033
- }
1034
- }
1035
- return t.talk > 0 && (i = { ...i, mouth: Math.max(i.mouth, t.talk * cr(e)) }), { pose: i, hands: a };
1036
- }
1037
- function Cr(t, e, n, o) {
1038
- return Yo(t, e, n, o).pose;
1039
- }
1040
- const zo = (t, e) => (t.facing ?? e.facing ?? 1) < 0 ? -1 : 1, ln = (t, e) => `hand.${t}.${e}`;
1041
- function Rr(t) {
1042
- const e = (s) => {
1043
- if (typeof t[ln(s, "spread")] == "number")
1044
- return Object.fromEntries(Object.keys(It).map((r) => [r, t[ln(s, r)]]));
1045
- }, n = e("left"), o = e("right");
1046
- return n || o ? { left: n, right: o } : void 0;
1047
- }
1048
- function Br(t, e) {
1049
- return !e || !t.hands ? t : { ...t, hands: { ...t.hands, left: e.left ?? t.hands.left, right: e.right ?? t.hands.right } };
1050
- }
1051
- function Xa(t) {
1052
- const e = t.style ?? {}, n = e.height ?? 300, o = n * 0.8, s = { ...ft(t.pose ?? {}), walk: 0, walking: 0, gait: "walk", facing: (e.facing ?? 1) < 0 ? -1 : 1, talk: 0, rubber: e.rubber ?? 0, beat: 0, dancing: 0 }, r = {};
1053
- if (e.hands)
1054
- for (const i of ["left", "right"]) {
1055
- const a = e.hands[i] ?? It;
1056
- for (const l of Object.keys(It)) r[ln(i, l)] = a[l] ?? It[l];
1057
- }
1058
- return {
1059
- type: "custom",
1060
- x: t.x - o / 2,
1061
- y: t.y - n,
1062
- width: o,
1063
- height: n,
1064
- props: { ...s, ...r },
1065
- about: Nr(Object.keys(r), t.cast),
1066
- figureStyle: e,
1067
- figureDance: t.dance,
1068
- figureGaits: t.cast?.gaits,
1069
- draw(i, a, l) {
1070
- const c = a.props, h = Yo(c, l, t.dance, t.cast?.gaits);
1071
- i.translate(o / 2, n), Lr(i, h.pose, Br({ ...e, rubber: c.rubber, facing: zo(c, e) }, h.hands), l);
1072
- }
1073
- };
1074
- }
1075
- function Nr(t, e) {
1076
- const n = { ...Is, ...Os };
1077
- for (const o of t) {
1078
- const [, s, ...r] = o.split("."), i = Ts[r.join(".")];
1079
- i && (n[o] = { ...i, description: `${s === "left" ? "Left" : "Right"} hand: ${i.description.toLowerCase()}` });
1080
- }
1081
- return {
1082
- kind: "stick figure",
1083
- summary: "A poseable stick figure: pose it with joint tracks, or give it beats (`scriptTracks`) that compile into acted tracks.",
1084
- props: n,
1085
- // Read when asked: the list is registered by the acting module (see figure-actions).
1086
- get actions() {
1087
- return Ws(e);
1088
- }
1089
- };
1090
- }
1091
- function Ga(t, e, n) {
1092
- const o = t.figureStyle;
1093
- if (!o) throw new Error("stickFigureAt: the target was not made by stickFigureTarget");
1094
- const s = { ...t.props };
1095
- let r = 0, i = 0;
1096
- for (const [c, h] of e.state?.values.get(n) ?? [])
1097
- c === "gait" && typeof h == "string" && (s.gait = h), typeof h == "number" && (c === "x" || c === "motionPathX" ? r = h : c === "y" || c === "motionPathY" ? i = h : c in s && (s[c] = h));
1098
- const a = Cr(s, e.time, t.figureDance, t.figureGaits), l = _r(a, { ...o, rubber: s.rubber, facing: zo(s, o) });
1099
- return { pose: a, joints: Fr(l, t.x + r + t.width / 2, t.y + i + t.height) };
1100
- }
1101
- function Yr(t) {
1102
- const e = [];
1103
- return t.forEach((n, o) => {
1104
- const s = o === 0 ? Gt : e[o - 1], r = typeof n.pose == "string" ? ir[n.pose] : { ...s, ...n.pose };
1105
- e.push(n.expression ? rr(r, n.expression) : r);
1106
- }), e;
1107
- }
1108
- function Ka(t, e) {
1109
- const n = Yr(e);
1110
- return Oo.filter((o) => n.some((s) => s[o] !== Gt[o])).map((o) => ({
1111
- id: `${t}-${o}`,
1112
- target: t,
1113
- property: o,
1114
- keyframes: e.map((s, r) => ({
1115
- time: s.time,
1116
- value: n[r][o],
1117
- ...s.easing ? { easing: s.easing } : {}
1118
- }))
1119
- }));
1120
- }
1121
- const zn = {
1122
- standard: {},
1123
- slim: { headSize: 0.24, shoulderWidth: 0.05, hipWidth: 0.02 },
1124
- tall: { headSize: 0.25, legLength: 1.1, armLength: 1.05 },
1125
- short: { headSize: 0.33, legLength: 0.92, shoulderWidth: 0.065, hipWidth: 0.03 },
1126
- broad: { shoulderWidth: 0.11, hipWidth: 0.04 },
1127
- curvy: { shoulderWidth: 0.055, hipWidth: 0.065 },
1128
- stocky: { headSize: 0.34, shoulderWidth: 0.1, hipWidth: 0.06 },
1129
- kid: { headSize: 0.42 },
1130
- child: { headSize: 0.4, legLength: 0.88, armLength: 0.9, shoulderWidth: 0.05, hipWidth: 0.02 },
1131
- toddler: { headSize: 0.46, legLength: 0.78, armLength: 0.82, shoulderWidth: 0.05, hipWidth: 0.025 }
1132
- }, Ue = 0.215, Xe = 0.205, zr = 0.065, Dn = 0.035, Dr = 0.165, qr = 0.155, Ur = 12, Xr = 0.3, Gr = 0.7, Kr = 0.35, Vr = (t) => t * Math.PI / 180, at = {
1133
- turn: 0,
1134
- lean: 0,
1135
- bend: 0,
1136
- side: 0,
1137
- "head.turn": 0,
1138
- "head.nod": 0,
1139
- "head.tilt": 0,
1140
- "arm.left.swing": 0,
1141
- "arm.left.spread": 12,
1142
- "arm.left.elbow": 8,
1143
- "arm.left.bend": 0,
1144
- "arm.right.swing": 0,
1145
- "arm.right.spread": 12,
1146
- "arm.right.elbow": 8,
1147
- "arm.right.bend": 0,
1148
- "leg.left.swing": 0,
1149
- "leg.left.spread": 3,
1150
- "leg.left.knee": 0,
1151
- "leg.left.ankle": 0,
1152
- "leg.left.toeOut": 0,
1153
- "leg.left.rotate": 0,
1154
- "leg.right.swing": 0,
1155
- "leg.right.spread": 3,
1156
- "leg.right.knee": 0,
1157
- "leg.right.ankle": 0,
1158
- "leg.right.toeOut": 0,
1159
- "leg.right.rotate": 0,
1160
- stretch: 1,
1161
- lift: 0,
1162
- roll: 0,
1163
- mouth: 0,
1164
- smile: 0.5,
1165
- mouthWidth: 1,
1166
- blink: 0,
1167
- "eye.left": 1,
1168
- "eye.right": 1,
1169
- pupil: 1,
1170
- lid: 0,
1171
- bulge: 0,
1172
- "brow.left": 0,
1173
- "brow.right": 0,
1174
- browTilt: 0,
1175
- lookX: 0,
1176
- lookY: 0,
1177
- blush: 0,
1178
- tears: 0,
1179
- sweat: 0,
1180
- "hair.swing": 0,
1181
- "hair.trail": 0,
1182
- "hair.lift": 0,
1183
- "held.left": 1,
1184
- "held.right": 1,
1185
- "held.both": 1
1186
- };
1187
- function tt(t = {}) {
1188
- return { ...at, ...t };
1189
- }
1190
- const Jr = /* @__PURE__ */ new Set(["turn", "side", "head.turn", "head.tilt", "roll", "lookX", "hair.swing"]);
1191
- function Va(t) {
1192
- const e = {};
1193
- for (const [n, o] of Object.entries(t)) {
1194
- const s = n.replace(/(^|\.)(left|right)(\.|$)/, (r, i, a, l) => `${i}${a === "left" ? "right" : "left"}${l}`);
1195
- e[s] = Jr.has(n) ? -o : o;
1196
- }
1197
- return e;
1198
- }
1199
- function ot(t, e) {
1200
- const n = {};
1201
- for (const o of ["left", "right"]) for (const [s, r] of Object.entries(e)) n[`${t}.${o}.${s}`] = r;
1202
- return n;
1203
- }
1204
- const Zr = {
1205
- rest: at,
1206
- wave: tt({ "arm.right.spread": 115, "arm.right.bend": 55, "arm.right.elbow": 0, "head.tilt": -6, smile: 0.9 }),
1207
- cheer: tt({ ...ot("arm", { spread: 140, bend: 20, elbow: 0 }), mouth: 0.6, smile: 1, "eye.left": 0, "eye.right": 0 }),
1208
- point: tt({ "arm.right.spread": 88, "arm.right.elbow": 0, "arm.right.bend": 0, "head.turn": -20, smile: 0.4 }),
1209
- handsOnHips: tt({ ...ot("arm", { spread: 50, bend: -105, elbow: 0 }), ...ot("leg", { spread: 9 }), smile: 0.8 }),
1210
- think: tt({ "arm.right.spread": 22, "arm.right.bend": -150, "arm.right.elbow": 0, "head.tilt": 10, lookX: -0.5, lookY: -0.8, smile: 0 }),
1211
- shrug: tt({ ...ot("arm", { spread: 35, bend: 75, elbow: 0 }), "head.tilt": -10, smile: -0.2 }),
1212
- sit: tt({ ...ot("leg", { swing: 90, knee: 90, spread: 4 }), ...ot("arm", { swing: 25, elbow: 45, spread: 8 }) }),
1213
- kneel: tt({
1214
- "leg.left.swing": 90,
1215
- "leg.left.knee": 90,
1216
- // The back thigh leans back a little so its knee meets the ground beside the
1217
- // front foot; the shin slopes up from it and the foot points down to tucked toes.
1218
- "leg.right.swing": -18,
1219
- "leg.right.knee": 108,
1220
- "leg.right.ankle": 16,
1221
- ...ot("arm", { swing: 20, elbow: 30 })
1222
- }),
1223
- crouch: tt({ ...ot("leg", { swing: 75, knee: 140, spread: 6 }), lean: 25, ...ot("arm", { swing: 50, elbow: 40 }), "head.nod": -15 }),
1224
- // On hands and knees: the back nearly level, arms straight down, the toes
1225
- // pointed back along the ground.
1226
- crawl: tt({ lean: 82, "head.nod": -35, ...ot("arm", { swing: 80, elbow: 0, spread: 4 }), ...ot("leg", { knee: 92, ankle: -88 }) }),
1227
- lieDown: tt({ roll: 90, ...ot("arm", { spread: 8 }), "head.nod": 0 }),
1228
- // Everyday actions (the motion and everyday-life reference sheets). Hands that hold
1229
- // something are where its grip goes: see `holding` and `handGrip`.
1230
- sleep: tt({ roll: 90, ...ot("arm", { spread: 8, swing: 20, elbow: 40 }), "leg.left.knee": 20, "leg.left.swing": 15, blink: 1, smile: 0.2 }),
1231
- stretch: tt({ side: -16, "arm.left.spread": 165, "arm.left.bend": 35, "arm.left.elbow": 0, "arm.right.spread": 40, "arm.right.bend": -110, "arm.right.elbow": 0, "head.tilt": -10, "eye.left": 0, "eye.right": 0, smile: 0.4 }),
1232
- sitFloor: tt({ ...ot("leg", { swing: 80, spread: 22, rotate: 75, knee: 145 }), ...ot("arm", { swing: 25, spread: 18, elbow: 30 }), lean: 5, smile: 0.5 }),
1233
- carry: tt({ ...ot("arm", { spread: 16, elbow: 4 }), lean: -3, smile: 0.4 }),
1234
- cane: tt({ "arm.right.swing": 16, "arm.right.spread": 10, "arm.right.elbow": 0, "arm.right.bend": 0, "arm.left.swing": 2, side: -3, lean: 4, "leg.right.swing": 4, smile: 0.3 }),
1235
- lift: tt({ ...ot("arm", { swing: 28, spread: 24, elbow: 85, bend: -45 }), ...ot("leg", { swing: 12, knee: 22, spread: 6 }), lean: -4, smile: 0.2 }),
1236
- push: tt({ lean: 28, ...ot("arm", { swing: 82, spread: 12, elbow: 18 }), "leg.left.swing": 28, "leg.left.knee": 30, "leg.right.swing": -28, "leg.right.knee": 6, "head.nod": -20, browTilt: -0.6, smile: -0.2 }),
1237
- pull: tt({ lean: -22, ...ot("arm", { swing: 70, spread: 6, elbow: 0 }), "leg.left.swing": 32, "leg.left.knee": 8, "leg.right.swing": -8, "leg.right.knee": 34, "head.nod": 12, browTilt: -0.6, smile: -0.2 }),
1238
- drink: tt({ "arm.right.swing": 85, "arm.right.spread": 8, "arm.right.elbow": 120, "arm.right.bend": 0, "head.nod": -14, "eye.left": 0.5, "eye.right": 0.5, smile: 0 }),
1239
- phone: tt({ "arm.right.swing": 80, "arm.right.spread": 8, "arm.right.elbow": 80, "arm.right.bend": -10, "head.nod": 18, lookY: 0.7, lookX: -0.3, smile: 0.4 }),
1240
- read: tt({ ...ot("arm", { swing: 32, spread: 10, elbow: 82, bend: -28 }), "head.nod": 22, lookY: 0.8, smile: 0.2 }),
1241
- type: tt({ ...ot("leg", { swing: 90, knee: 90, spread: 4 }), ...ot("arm", { swing: 40, spread: 10, elbow: 55, bend: -20 }), lean: 8, "head.nod": 10, lookY: 0.5, smile: 0 })
1242
- }, Ja = ["round", "flat", "pointed", "big"], Qr = {
1243
- round: { length: 1, width: [0.95, 0.7] },
1244
- flat: { length: 1.12, width: [0.85, 0.85] },
1245
- pointed: { length: 1.25, width: [1, 0.3] },
1246
- big: { length: 1.5, width: [1.25, 1.1] }
1247
- };
1248
- function jr(t = {}) {
1249
- const e = t.headSize ?? 0.3, n = t.shoulderWidth ?? 0.06, o = t.hipWidth ?? 0.022, s = t.legLength ?? 1, r = t.armLength ?? 1, i = Qr[t.feet ?? "round"], a = Math.max(0.12, 1 - e - Dn - (Ue + Xe) * s), l = (f) => ({
1250
- id: `arm.${f}`,
1251
- parent: "spine",
1252
- offset: [(f === "left" ? 1 : -1) * n, -0.035, 0],
1253
- rest: [0, -1, 0],
1254
- side: f === "left" ? 1 : -1,
1255
- bones: [
1256
- { length: Dr * r, width: [1.25, 0.9] },
1257
- { length: qr * r, width: [0.9, 0.75] }
1258
- ]
1259
- }), c = (f) => ({
1260
- id: `leg.${f}`,
1261
- parent: null,
1262
- offset: [(f === "left" ? 1 : -1) * o, 0, 0],
1263
- rest: [0, -1, 0],
1264
- side: f === "left" ? 1 : -1,
1265
- bones: [
1266
- { length: Ue * s, width: [1.45, 1.05] },
1267
- { length: Xe * s, width: [1.05, 0.85] },
1268
- { length: zr * Math.sqrt(s) * i.length, width: i.width }
1269
- ]
1270
- }), h = (f, y) => f[y] ?? at[y] ?? 0;
1271
- return {
1272
- id: "human",
1273
- hipHeight: (Ue + Xe) * s,
1274
- // Tie order: legs, then the body, then the arms (in front of the chest unless turned away), then the head.
1275
- chains: [
1276
- c("left"),
1277
- c("right"),
1278
- {
1279
- id: "spine",
1280
- parent: null,
1281
- rest: [0, 1, 0],
1282
- bones: [
1283
- { length: a / 2, width: [1.7, 1.4] },
1284
- { length: a / 2, width: [1.4, 1.1] }
1285
- ]
1286
- },
1287
- { id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length: Dn, width: [1, 0.9] }] },
1288
- l("left"),
1289
- l("right")
1290
- ],
1291
- head: { on: "neck", size: e },
1292
- contacts: [
1293
- ...["left", "right"].flatMap((f) => [
1294
- { chain: `leg.${f}`, joint: 1 },
1295
- { chain: `leg.${f}`, joint: 2 },
1296
- { chain: `leg.${f}`, joint: 3 },
1297
- { chain: `arm.${f}`, joint: 1 },
1298
- { chain: `arm.${f}`, joint: 2 }
1299
- ]),
1300
- { chain: "spine", joint: 0 },
1301
- { chain: "spine", joint: 1 },
1302
- { chain: "spine", joint: 2 },
1303
- { head: "top" }
1304
- ],
1305
- angles(f, y) {
1306
- if (y.id === "spine") {
1307
- const x = -h(f, "lean") / 2, M = h(f, "side") / 2, v = -h(f, "bend");
1308
- return [
1309
- { swing: x + v * Xr, spread: M },
1310
- { swing: x + v * Gr, spread: M }
1311
- ];
1312
- }
1313
- if (y.id === "neck") return [{ swing: -h(f, "bend") * Kr, spread: 0 }];
1314
- const [u, g] = y.id.split("."), m = (x) => h(f, `${u}.${g}.${x}`);
1315
- if (u === "arm")
1316
- return [
1317
- { swing: m("swing"), spread: m("spread") },
1318
- { swing: m("elbow"), spread: m("bend") }
1319
- ];
1320
- const d = (y.side ?? 1) * m("rotate"), b = 1 - Math.cos(Vr(m("rotate")));
1321
- return [
1322
- { swing: m("swing"), spread: m("spread"), yaw: d },
1323
- { swing: -m("knee"), spread: 0, yaw: d },
1324
- // The foot points forward, square to the shin, turned out a little (more with `toeOut`).
1325
- { swing: 90 + m("ankle") - b * (m("swing") - m("knee")), spread: 0, yaw: (Ur + m("toeOut")) * (y.side ?? 1) }
1326
- ];
1327
- },
1328
- withAngles(f, y, u) {
1329
- const [g, m] = y.id.split("."), d = (b) => `${g}.${m}.${b}`;
1330
- return g === "arm" ? {
1331
- ...f,
1332
- [d("swing")]: u[0].swing,
1333
- [d("spread")]: u[0].spread,
1334
- [d("elbow")]: u[1].swing,
1335
- [d("bend")]: u[1].spread
1336
- } : g === "leg" ? { ...f, [d("swing")]: u[0].swing, [d("spread")]: u[0].spread, [d("knee")]: -u[1].swing } : f;
1337
- },
1338
- boneScale(f, y) {
1339
- const u = Math.min(3, Math.max(0.3, h(f, "stretch")));
1340
- return y?.id.startsWith("arm.") ? Math.sqrt(u) : u;
1341
- },
1342
- headPose(f) {
1343
- const y = Math.min(3, Math.max(0.3, h(f, "stretch")));
1344
- return {
1345
- yaw: h(f, "head.turn"),
1346
- nod: h(f, "head.nod"),
1347
- tilt: h(f, "head.tilt"),
1348
- // The head keeps its area: taller and narrower when stretched.
1349
- sx: 1 / Math.sqrt(y),
1350
- sy: Math.sqrt(y)
1351
- };
1352
- },
1353
- landmarks: {
1354
- neck: ["neck", 0],
1355
- "shoulder.left": ["arm.left", 0],
1356
- "elbow.left": ["arm.left", 1],
1357
- "hand.left": ["arm.left", 2],
1358
- "shoulder.right": ["arm.right", 0],
1359
- "elbow.right": ["arm.right", 1],
1360
- "hand.right": ["arm.right", 2],
1361
- "hip.left": ["leg.left", 0],
1362
- "knee.left": ["leg.left", 1],
1363
- "ankle.left": ["leg.left", 2],
1364
- "toe.left": ["leg.left", 3],
1365
- "hip.right": ["leg.right", 0],
1366
- "knee.right": ["leg.right", 1],
1367
- "ankle.right": ["leg.right", 2],
1368
- "toe.right": ["leg.right", 3]
1369
- }
1370
- };
1371
- }
1372
- function Za(t) {
1373
- const e = t.split(".");
1374
- if (e[0] === "hand" && e.length >= 3) {
1375
- const o = `${e[1] === "left" ? "Left" : "Right"} hand`, s = { spread: "finger spread", turn: "wrist turn", bend: "wrist bend", tilt: "wrist tilt", roll: "roll" }, r = e.slice(2).join(".");
1376
- return `${o} · ${s[r] ?? r.replace(".curl", " curl").replace(".across", " across")}`;
1377
- }
1378
- if (e.length === 3) {
1379
- const [o, s, r] = e;
1380
- return `${`${s === "left" ? "Left" : "Right"} ${o}`} · ${{
1381
- swing: "forward / back",
1382
- spread: "out / in",
1383
- elbow: "elbow bend",
1384
- bend: "forearm out / in",
1385
- knee: "knee bend",
1386
- ankle: "foot tilt",
1387
- toeOut: "toes out / in",
1388
- rotate: "turn out at the hip"
1389
- }[r] ?? r}`;
1390
- }
1391
- return {
1392
- turn: "View (front → side → back)",
1393
- lean: "Lean forward / back",
1394
- bend: "Back curve (line of action)",
1395
- side: "Lean sideways",
1396
- "head.turn": "Head · turn",
1397
- "head.nod": "Head · nod",
1398
- "head.tilt": "Head · tilt",
1399
- stretch: "Squash / stretch",
1400
- lift: "Lift off the ground",
1401
- roll: "Roll (whole figure)",
1402
- mouth: "Mouth open",
1403
- smile: "Smile",
1404
- mouthWidth: "Mouth width",
1405
- blink: "Blink",
1406
- "eye.left": "Left eye open",
1407
- "eye.right": "Right eye open",
1408
- pupil: "Pupil size",
1409
- lid: "Eyelids lowered",
1410
- bulge: "Eyes bulging",
1411
- "brow.left": "Left brow",
1412
- "brow.right": "Right brow",
1413
- browTilt: "Brow slant",
1414
- lookX: "Look left / right",
1415
- lookY: "Look up / down",
1416
- blush: "Blush",
1417
- tears: "Tears",
1418
- sweat: "Sweat",
1419
- "hair.swing": "Hair · swing",
1420
- "hair.trail": "Hair · trail",
1421
- "hair.lift": "Hair · lift",
1422
- "held.left": "Left hand · holding",
1423
- "held.right": "Right hand · holding",
1424
- "held.both": "Both hands · holding"
1425
- }[t] ?? t;
1426
- }
1427
- const ti = {
1428
- leftEye: "eye.left",
1429
- rightEye: "eye.right",
1430
- leftBrow: "brow.left",
1431
- rightBrow: "brow.right"
1432
- }, ei = { blush: 0, tears: 0, sweat: 0, pupil: 1, lid: 0, bulge: 0 }, Kt = Object.fromEntries(
1433
- Object.entries(kt).map(([t, e]) => [
1434
- t,
1435
- { ...Object.fromEntries(Object.entries(e).map(([n, o]) => [ti[n] ?? n, o])), ...ei }
1436
- ])
1437
- );
1438
- Kt.crying.tears = 1;
1439
- Kt.scared.sweat = 0.8;
1440
- Kt.scared.bulge = 0.4;
1441
- Kt.sleepy.lid = 0.5;
1442
- Kt.worried.sweat = 0.6;
1443
- const vt = (t) => ({ ...Kt.neutral, ...t }), ni = {
1444
- ...Kt,
1445
- laughing: vt({ mouth: 0.75, smile: 1, mouthWidth: 1.25, "eye.left": 0, "eye.right": 0, "brow.left": 0.5, "brow.right": 0.5 }),
1446
- afraid: vt({ mouth: 0.4, smile: -0.6, mouthWidth: 0.9, "eye.left": 1.3, "eye.right": 1.3, "brow.left": 0.6, "brow.right": 0.6, browTilt: 1, sweat: 1, pupil: 0.8, bulge: 0.5 }),
1447
- bored: vt({ smile: -0.05, mouthWidth: 0.6, "eye.left": 0.45, "eye.right": 0.45, "brow.left": -0.4, "brow.right": -0.4, lookX: 0.5 }),
1448
- tired: vt({ mouth: 0.2, smile: -0.3, mouthWidth: 0.7, "eye.left": 0.3, "eye.right": 0.3, "brow.left": -0.1, "brow.right": -0.1, browTilt: 0.6, lookY: 0.6 }),
1449
- embarrassed: vt({ smile: 0.4, mouthWidth: 0.7, "eye.left": 0.9, "eye.right": 0.9, browTilt: 0.7, "brow.left": 0.2, "brow.right": 0.2, lookX: -0.6, lookY: 0.5, blush: 1 }),
1450
- proud: vt({ smile: 0.75, mouthWidth: 1, "eye.left": 0.75, "eye.right": 0.75, "brow.left": 0.5, "brow.right": 0.5, lookY: -0.2 }),
1451
- determined: vt({ smile: 0.35, mouthWidth: 0.8, "eye.left": 0.85, "eye.right": 0.85, "brow.left": -0.5, "brow.right": -0.5, browTilt: -0.9 }),
1452
- affectionate: vt({ smile: 0.85, "eye.left": 0, "eye.right": 0, "brow.left": 0.3, "brow.right": 0.3, blush: 0.8 }),
1453
- hurt: vt({ smile: -0.7, mouthWidth: 0.8, "eye.left": 1.1, "eye.right": 1.1, "brow.left": 0.2, "brow.right": 0.2, browTilt: 1, lookY: 0.3, tears: 0.35 }),
1454
- suspicious: vt({ smile: -0.25, mouthWidth: 0.7, "eye.left": 0.5, "eye.right": 0.85, "brow.left": -0.6, "brow.right": 0.4, browTilt: -0.3, lookX: 0.8, lid: 0.3 }),
1455
- relieved: vt({ smile: 0.7, "eye.left": 0, "eye.right": 0, "brow.left": 0.4, "brow.right": 0.4, browTilt: 0.4 }),
1456
- excited: vt({ mouth: 0.6, smile: 1, mouthWidth: 1.1, "eye.left": 1.4, "eye.right": 1.4, "brow.left": 0.9, "brow.right": 0.9, blush: 0.4, pupil: 1.3 })
1457
- }, Et = (t) => t * Math.PI / 180;
1458
- function Do([t, e, n], o) {
1459
- const s = Math.cos(o), r = Math.sin(o);
1460
- return [t, e * s + n * r, -e * r + n * s];
1461
- }
1462
- function Re([t, e, n], o) {
1463
- const s = Math.cos(o), r = Math.sin(o);
1464
- return [t * s - e * r, t * r + e * s, n];
1465
- }
1466
- function Pt([t, e, n], o) {
1467
- const s = Math.cos(o), r = Math.sin(o);
1468
- return [t * s + n * r, e, -t * r + n * s];
1469
- }
1470
- const _t = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], We = (t, e) => [t[0] * e, t[1] * e, t[2] * e], Ae = (t, e) => Re(Do(t, e.swing), e.spread);
1471
- function xe(t, e) {
1472
- const n = Pt(t, e);
1473
- return { point: { x: n[0], y: -n[1] }, depth: n[2] };
1474
- }
1475
- function wn(t, e, n) {
1476
- const o = n, r = [0, t.hipHeight * o * (t.boneScale?.(e, null) ?? 1), 0], i = {};
1477
- for (const m of t.chains) {
1478
- const d = m.parent ? i[m.parent] : void 0;
1479
- if (m.parent && !d) throw new Error(`body plan ${t.id}: chain ${m.id} comes before its parent ${m.parent}`);
1480
- const b = m.at ?? (d ? d.joints3.length - 1 : 0), x = d ? d.joints3[b] : r, M = d ? d.frames[Math.max(0, b - 1)] : { swing: 0, spread: 0 }, v = m.offset ? _t(x, Ae(We(m.offset, o), M)) : x, P = m.side ?? 1, C = t.boneScale?.(e, m) ?? 1, I = t.angles(e, m), $ = [v], A = [];
1481
- let z = M.swing, R = M.spread;
1482
- m.bones.forEach((w, E) => {
1483
- const H = I[E] ?? { swing: 0, spread: 0 };
1484
- z += Et(H.swing), R += Et(H.spread) * P, A.push({ swing: z, spread: R });
1485
- const N = Pt(Ae(m.rest, { swing: z, spread: R }), Et(H.yaw ?? 0));
1486
- $.push(_t($[E], We(N, w.length * o * C)));
1487
- }), i[m.id] = { joints3: $, frames: A };
1488
- }
1489
- const a = i[t.head.on], l = t.headPose?.(e) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 }, c = a.frames[a.frames.length - 1], h = t.head.size / 2 * o, f = h * l.sx, y = h * l.sy, u = (m) => Ae(Pt(Do(Re(m, -Et(l.tilt)), -Et(l.nod)), Et(l.yaw)), c), g = _t(a.joints3[a.joints3.length - 1], u([0, y, 0]));
1490
- return { height: o, root: r, chains: i, head: { center: g, rx: f, ry: y, toBody: u } };
1491
- }
1492
- function xn(t, e, n) {
1493
- const o = n.height, s = Et(90 * (e.turn ?? 0)), r = wn(t, e, o), { root: i } = r, a = r.chains, { rx: l, ry: c } = r.head, h = r.head.toBody, f = r.head.center, y = {};
1494
- for (const A of t.chains) {
1495
- const { joints3: z, frames: R } = a[A.id], w = z.map((E) => xe(E, s));
1496
- y[A.id] = {
1497
- id: A.id,
1498
- joints3: z,
1499
- frames: R,
1500
- points: w.map((E) => E.point),
1501
- depths: w.map((E) => E.depth)
1502
- };
1503
- }
1504
- const u = xe(f, s), g = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map((A) => Pt(h(A), s)), m = xe(i, s).point, d = Et(e.roll ?? 0), b = (A) => {
1505
- const z = A.x - m.x, R = A.y - m.y;
1506
- return { x: m.x + z * Math.cos(d) - R * Math.sin(d), y: m.y + z * Math.sin(d) + R * Math.cos(d) };
1507
- }, x = ([A, z, R]) => [A * Math.cos(d) + z * Math.sin(d), -A * Math.sin(d) + z * Math.cos(d), R];
1508
- for (const A of Object.values(y)) A.points = A.points.map(b);
1509
- const M = {
1510
- center: b(u.point),
1511
- depth: u.depth,
1512
- rx: l,
1513
- ry: c,
1514
- angle: 0,
1515
- axes: g.map(x)
1516
- }, v = M.axes[1];
1517
- M.angle = Math.atan2(v[0], v[1]);
1518
- const P = (A) => {
1519
- if ("head" in A) return { x: M.center.x + v[0] * c, y: M.center.y - v[1] * c };
1520
- const z = y[A.chain];
1521
- return z.points[Math.min(A.joint, z.points.length - 1)];
1522
- };
1523
- let C = 0;
1524
- (n.contact ?? "ground") === "ground" && (C = -Math.max(...t.contacts.map((A) => P(A).y))), C -= (e.lift ?? 0) * o;
1525
- const I = (A) => ({ x: A.x, y: A.y + C });
1526
- for (const A of Object.values(y)) A.points = A.points.map(I);
1527
- M.center = I(M.center);
1528
- const $ = t.contacts.map((A) => ({ spec: A, point: P(A) }));
1529
- return {
1530
- height: o,
1531
- view: s,
1532
- chains: y,
1533
- head: M,
1534
- hip: I(b(m)),
1535
- hipDepth: xe(i, s).depth,
1536
- contacts: $,
1537
- groundY: Math.max(...$.map((A) => A.point.y))
1538
- };
1539
- }
1540
- const He = (t, e) => [t[0] - e[0], t[1] - e[1], t[2] - e[2]], hn = (t) => {
1541
- const e = Math.hypot(t[0], t[1], t[2]) || 1;
1542
- return [t[0] / e, t[1] / e, t[2] / e];
1543
- };
1544
- function oi(t, e, n) {
1545
- const o = n.height, s = Et(90 * (e.turn ?? 0)), r = Et(e.roll ?? 0), i = wn(t, e, o), a = Pt(i.root, s), l = (d) => _t(Re(He(Pt(d, s), a), -r), a), c = {};
1546
- for (const d of t.chains) c[d.id] = i.chains[d.id].joints3.map(l);
1547
- const h = l(i.head.center), f = (d) => hn(He(l(_t(i.head.center, i.head.toBody(d))), h)), y = [f([1, 0, 0]), f([0, 1, 0]), f([0, 0, 1])], u = (d) => {
1548
- if ("head" in d) return _t(h, We(y[1], i.head.ry));
1549
- const b = c[d.chain];
1550
- return b[Math.min(d.joint, b.length - 1)];
1551
- };
1552
- let g = 0;
1553
- (n.contact ?? "ground") === "ground" && (g = -Math.min(...t.contacts.map((d) => u(d)[1]))), g += (e.lift ?? 0) * o;
1554
- const m = (d) => [d[0], d[1] + g, d[2]];
1555
- return {
1556
- height: o,
1557
- hip: m(a),
1558
- chains: Object.fromEntries(Object.entries(c).map(([d, b]) => [d, b.map(m)])),
1559
- head: { center: m(h), rx: i.head.rx, ry: i.head.ry, axes: y }
1560
- };
1561
- }
1562
- function Mn(t, e, n, o) {
1563
- const s = n.height, r = Et(90 * (e.turn ?? 0)), i = wn(t, e, s), a = oi(t, e, n), l = a.hip, c = a.chains, h = a.head.center, f = (R) => {
1564
- if ("head" in R) return _t(h, We(a.head.axes[1], a.head.ry));
1565
- const w = c[R.chain];
1566
- return w[Math.min(R.joint, w.length - 1)];
1567
- }, y = o.toView(l), u = Re(Pt([0, 0, 1], r), -Et(e.roll ?? 0)), g = hn(He(o.toView(_t(l, u)), y)), m = o.toScreen(y), d = o.toScreen([y[0] + 1, y[1], y[2]]), b = Math.hypot(d.x - m.x, d.y - m.y), x = (R) => {
1568
- const w = o.toView(R);
1569
- return { point: o.toScreen(w), depth: w[2] * b };
1570
- }, M = {};
1571
- for (const R of t.chains) {
1572
- const w = c[R.id].map(x);
1573
- M[R.id] = {
1574
- id: R.id,
1575
- joints3: i.chains[R.id].joints3,
1576
- frames: i.chains[R.id].frames,
1577
- points: w.map((E) => E.point),
1578
- depths: w.map((E) => E.depth)
1579
- };
1580
- }
1581
- const v = o.toView(h), P = o.toScreen(v), C = o.toScreen([v[0] + 1, v[1], v[2]]), I = Math.hypot(C.x - P.x, C.y - P.y), $ = a.head.axes.map((R) => hn(He(o.toView(_t(h, R)), v))), A = {
1582
- center: P,
1583
- depth: v[2] * b,
1584
- rx: i.head.rx * I,
1585
- ry: i.head.ry * I,
1586
- angle: Math.atan2($[1][0], $[1][1]),
1587
- axes: $
1588
- }, z = t.contacts.map((R) => ({ spec: R, point: x(f(R)).point }));
1589
- return {
1590
- height: s * b,
1591
- view: r,
1592
- bodyForward: g,
1593
- chains: M,
1594
- head: A,
1595
- hip: m,
1596
- hipDepth: y[2] * b,
1597
- contacts: z,
1598
- groundY: Math.max(...z.map((R) => R.point.y))
1599
- };
1600
- }
1601
- function oe(t, [e, n, o]) {
1602
- const [s, r, i] = t.axes, a = [
1603
- s[0] * e * t.rx + r[0] * n * t.ry + i[0] * o * t.rx,
1604
- s[1] * e * t.rx + r[1] * n * t.ry + i[1] * o * t.rx,
1605
- s[2] * e * t.rx + r[2] * n * t.ry + i[2] * o * t.rx
1606
- ], l = Math.hypot(e, n, o) || 1, c = (s[2] * e + r[2] * n + i[2] * o) / l;
1607
- return { point: { x: t.center.x + a[0], y: t.center.y - a[1] }, depth: t.depth + a[2], facing: c };
1608
- }
1609
- const Me = (t) => t * 180 / Math.PI, Nt = (t, e) => [t[0] - e[0], t[1] - e[1], t[2] - e[2]], Ge = (t, e) => t[0] * e[0] + t[1] * e[1] + t[2] * e[2], Qt = (t) => Math.hypot(t[0], t[1], t[2]), cn = (t) => {
1610
- const e = Qt(t) || 1;
1611
- return [t[0] / e, t[1] / e, t[2] / e];
1612
- }, ke = (t) => Math.atan2(Math.sin(t), Math.cos(t));
1613
- function qn(t) {
1614
- const [e, n, o] = cn(t);
1615
- return { swing: Math.asin(Math.max(-1, Math.min(1, o))), spread: Math.atan2(e, -n) };
1616
- }
1617
- function si(t, e, n, o, s) {
1618
- const r = t.chains.find((w) => w.id === n);
1619
- if (!r) throw new Error(`reach: no chain ${n} in ${t.id}`);
1620
- if (r.bones.length < 2 || r.rest[1] > -0.99) throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);
1621
- if (!t.withAngles) throw new Error(`reach: the ${t.id} plan cannot set angles`);
1622
- const i = xn(t, { ...e, turn: 0, roll: 0, lift: 0 }, { height: s.height, contact: "none" }), a = i.chains[n];
1623
- if (Qt(Nt(o, a.joints3[2])) < s.height * 1e-12) return e;
1624
- const l = a.joints3[0], c = Qt(Nt(a.joints3[1], a.joints3[0])), h = Qt(Nt(a.joints3[2], a.joints3[1])), f = r.parent ? i.chains[r.parent].frames[Math.max(0, (r.at ?? i.chains[r.parent].joints3.length - 1) - 1)] : { swing: 0, spread: 0 }, y = Nt(o, l), u = t.angles(e, r), g = (w) => (u[w]?.yaw ?? 0) * Math.PI / 180, m = Math.min(c + h - 1e-6, Math.max(Math.abs(c - h) + 1e-6, Qt(y))), d = cn(y), b = r.parent !== null, x = Pt(Ae(r.pole ?? (b ? [0, -0.35, -1] : [0, 0, 1]), f), g(0));
1625
- let M = Nt(x, [d[0] * Ge(x, d), d[1] * Ge(x, d), d[2] * Ge(x, d)]);
1626
- Qt(M) < 1e-6 && (M = Pt([1, 0, 0], g(0))), M = cn(M);
1627
- const v = (c * c + m * m - h * h) / (2 * c * m), P = Math.sqrt(Math.max(0, 1 - v * v)), C = [
1628
- l[0] + c * (v * d[0] + P * M[0]),
1629
- l[1] + c * (v * d[1] + P * M[1]),
1630
- l[2] + c * (v * d[2] + P * M[2])
1631
- ], I = [l[0] + d[0] * m, l[1] + d[1] * m, l[2] + d[2] * m], $ = r.side ?? 1, A = qn(Pt(Nt(C, l), -g(0))), z = qn(Pt(Nt(I, C), -g(1))), R = [
1632
- { swing: Me(ke(A.swing - f.swing)), spread: Me(ke(A.spread - f.spread)) * $ },
1633
- { swing: Me(ke(z.swing - A.swing)), spread: Me(ke(z.spread - A.spread)) * $ }
1634
- ];
1635
- return t.withAngles(e, r, R);
1636
- }
1637
- function jt(t, e, n, o) {
1638
- if (!Number.isFinite(t) || t < n || t > o) throw new Error(`organic body: ${e} must be ${n}..${o}`);
1639
- return t;
1640
- }
1641
- function ve(t, e) {
1642
- if (t.length < 2 || t[0].at !== 0 || t.at(-1).at !== 1) throw new Error(`organic body: ${e} must run from 0 to 1`);
1643
- return t.map((n, o) => {
1644
- if (jt(n.at, `${e}.at`, 0, 1), jt(n.width, `${e}.width`, 1e-3, 0.3), o > 0 && n.at <= t[o - 1].at) throw new Error(`organic body: ${e} positions must increase`);
1645
- return { at: n.at, width: n.width };
1646
- });
1647
- }
1648
- function ri(t, e) {
1649
- const n = Math.max(0.095, e.shoulderWidth + 0.025), o = Math.max(0.085, e.hipWidth + 0.032), s = t.shading ?? {}, r = s.light ?? [-0.8, -0.6];
1650
- if (r.length !== 2 || !r.every(Number.isFinite) || Math.hypot(...r) === 0) throw new Error("organic body: light must be a finite nonzero 2D vector");
1651
- if (s.mode !== void 0 && s.mode !== "none" && s.mode !== "cel") throw new Error("organic body: unknown shading mode");
1652
- return {
1653
- torso: ve(t.torso ?? [
1654
- { at: 0, width: o },
1655
- { at: 0.2, width: o },
1656
- { at: 0.42, width: o * 0.72 },
1657
- { at: 0.68, width: n * 0.9 },
1658
- { at: 0.86, width: n },
1659
- { at: 1, width: 0.024 }
1660
- ], "torso"),
1661
- arm: ve(t.arm ?? [
1662
- { at: 0, width: 0.028 },
1663
- { at: 0.22, width: 0.027 },
1664
- { at: 0.5, width: 0.019 },
1665
- { at: 0.68, width: 0.023 },
1666
- { at: 1, width: 0.012 }
1667
- ], "arm"),
1668
- leg: ve(t.leg ?? [
1669
- { at: 0, width: 0.04 },
1670
- { at: 0.24, width: 0.042 },
1671
- { at: 0.5, width: 0.027 },
1672
- { at: 0.68, width: 0.032 },
1673
- { at: 1, width: 0.016 }
1674
- ], "leg"),
1675
- neck: ve(t.neck ?? [{ at: 0, width: 0.024 }, { at: 1, width: 0.023 }], "neck"),
1676
- depth: jt(t.depth ?? 0.55, "depth", 0.2, 1),
1677
- fill: t.fill ?? e.skin,
1678
- outline: { color: t.outline?.color ?? e.ink, width: jt(t.outline?.width ?? e.lineWidth, "outline.width", 0, 100) },
1679
- shading: {
1680
- mode: s.mode ?? "cel",
1681
- light: [...r],
1682
- shadow: s.shadow ?? "#633923",
1683
- opacity: jt(s.opacity ?? 0.17, "shading.opacity", 0, 1),
1684
- highlight: jt(s.highlight ?? 0.12, "shading.highlight", 0, 1)
1685
- }
1686
- };
1687
- }
1688
- function ii(t, e) {
1689
- const n = Math.min(1, Math.max(0, e)), o = t.findIndex((a) => a.at >= n);
1690
- if (o <= 0) return t[0].width;
1691
- const s = t[o - 1], r = t[o], i = (n - s.at) / (r.at - s.at);
1692
- return s.width + (r.width - s.width) * i * i * (3 - 2 * i);
1693
- }
1694
- const Un = 8, ai = (t, e, n) => ({ x: t.x + (e.x - t.x) * n, y: t.y + (e.y - t.y) * n }), Yt = (t, e) => {
1695
- const n = Math.hypot(e.x - t.x, e.y - t.y) || 1;
1696
- return { x: (e.x - t.x) / n, y: (e.y - t.y) / n };
1697
- }, $e = (t, e, n) => ({ x: t.x + e.x * n, y: t.y + e.y * n });
1698
- function Ee(t, e = 12) {
1699
- if (!Number.isInteger(e) || e < 1 || e > 128) throw new Error("organicCenterLine: steps must be an integer from 1 to 128");
1700
- if (t.length < 2) return t.map((s) => ({ ...s }));
1701
- const n = t.map((s, r) => {
1702
- const i = Yt(t[Math.max(0, r - 1)], s), a = Yt(s, t[Math.min(t.length - 1, r + 1)]), l = Math.hypot(i.x + a.x, i.y + a.y);
1703
- return l > 1e-6 ? { x: (i.x + a.x) / l, y: (i.y + a.y) / l } : a;
1704
- }), o = [];
1705
- for (let s = 0; s < t.length - 1; s++) {
1706
- const r = t[s], i = t[s + 1], a = Math.hypot(i.x - r.x, i.y - r.y) * 0.28, l = $e(r, n[s], a), c = $e(i, n[s + 1], -a);
1707
- for (let h = s === 0 ? 0 : 1; h <= e; h++) {
1708
- const f = h / e, y = 1 - f;
1709
- o.push({
1710
- x: y ** 3 * r.x + 3 * y * y * f * l.x + 3 * y * f * f * c.x + f ** 3 * i.x,
1711
- y: y ** 3 * r.y + 3 * y * y * f * l.y + 3 * y * f * f * c.y + f ** 3 * i.y
1712
- });
1713
- }
1714
- }
1715
- return o;
1716
- }
1717
- function Se(t, e, n, o = 1, s = 1) {
1718
- const r = t.map((h, f) => {
1719
- const y = t[Math.max(0, f - 1)], u = t[Math.min(t.length - 1, f + 1)];
1720
- let g = Yt(y, u);
1721
- Math.hypot(g.x, g.y) < 1e-6 && (g = { x: 0, y: 1 });
1722
- const m = { x: -g.y, y: g.x }, d = f / Math.max(1, t.length - 1), b = ii(e, d) * n * o, x = Yt(y, h), M = Yt(h, u), v = x.x * M.y - x.y * M.x, P = Math.acos(Math.min(1, Math.max(-1, x.x * M.x + x.y * M.y))), C = (Math.hypot(h.x - y.x, h.y - y.y) + Math.hypot(u.x - h.x, u.y - h.y)) / (2 * Math.max(1e-6, P)), I = Math.min(b, Math.max(b * 0.2, C * 0.8));
1723
- return { center: h, width: b, at: d, left: $e(h, m, v > 0 ? I : b), right: $e(h, m, v < 0 ? -I : -b) };
1724
- }), i = [], a = [], l = (h, f) => {
1725
- i.push(h), a.push(f);
1726
- };
1727
- for (const h of r) l(h.left, h.at);
1728
- const c = (h, f, y) => {
1729
- const u = { x: -f.y, y: f.x };
1730
- for (let g = 1; g < Un; g++) {
1731
- const m = g * Math.PI / Un, d = (y ? 1 : -1) * Math.cos(m), b = (y ? 1 : -s) * Math.sin(m);
1732
- l({
1733
- x: h.center.x + h.width * (u.x * d + f.x * b),
1734
- y: h.center.y + h.width * (u.y * d + f.y * b)
1735
- }, h.at);
1736
- }
1737
- };
1738
- c(r.at(-1), Yt(t[Math.max(0, t.length - 2)], t.at(-1)), !0);
1739
- for (const h of [...r].reverse()) l(h.right, h.at);
1740
- return c(r[0], Yt(t[0], t[Math.min(1, t.length - 1)]), !1), { outline: i, samples: r, positions: a };
1741
- }
1742
- function li(t, e, n) {
1743
- const o = {}, s = e.height, r = e.chains.spine;
1744
- if (r?.length >= 2) {
1745
- const i = e.points["shoulder.left"], a = e.points["shoulder.right"], l = n.chains.find((u) => u.id === "arm.left")?.offset?.[0] ?? 0.07, c = Math.max(1e-6, Math.abs(l) * s * 2), h = i && a ? Math.min(1, Math.hypot(i.x - a.x, i.y - a.y) / c) : Math.abs(Math.cos(e.turn * Math.PI / 2)), f = Math.sqrt(h * h + t.depth * t.depth * (1 - h * h)), y = [ai(r[0], r[1], -0.16), ...r.slice(1)];
1746
- o.spine = Se(Ee(y), t.torso, s, f, 0.25);
1747
- }
1748
- e.chains.neck?.length >= 2 && (o.neck = Se(Ee(e.chains.neck), t.neck, s));
1749
- for (const i of ["left", "right"])
1750
- for (const a of ["arm", "leg"]) {
1751
- const l = e.chains[`${a}.${i}`];
1752
- !l || l.length < 3 || (o[`${a}.${i}`] = Se(Ee(l.slice(0, 3)), t[a], s), a === "leg" && l.length > 3 && (o[`foot.${i}`] = Se(Ee(l.slice(2)), [{ at: 0, width: 0.019 }, { at: 1, width: 0.014 }], s)));
1753
- }
1754
- return o;
1755
- }
1756
- function qo(t, e) {
1757
- let n = !1;
1758
- for (let o = 0, s = e.length - 1; o < e.length; s = o++) {
1759
- const r = e[o], i = e[s];
1760
- r.y > t.y != i.y > t.y && t.x < (i.x - r.x) * (t.y - r.y) / (i.y - r.y) + r.x && (n = !n);
1761
- }
1762
- return n;
1763
- }
1764
- function Ke(t, e, n, o = 0) {
1765
- const s = t.samples.filter((a) => a.at >= e && a.at <= n), r = (a, l) => {
1766
- const c = a[l], h = a.center, f = Math.hypot(c.x - h.x, c.y - h.y) || 1;
1767
- return { x: c.x + (c.x - h.x) * o / f, y: c.y + (c.y - h.y) * o / f };
1768
- }, i = [...s.map((a) => r(a, "left")), ...[...s].reverse().map((a) => r(a, "right"))];
1769
- {
1770
- const a = t.samples[0].center;
1771
- for (const l of t.outline.slice(-7)) {
1772
- const c = Math.hypot(l.x - a.x, l.y - a.y) || 1;
1773
- i.push({ x: l.x + (l.x - a.x) * o / c, y: l.y + (l.y - a.y) * o / c });
1774
- }
1775
- }
1776
- return i;
1777
- }
1778
- function Xn(t, e) {
1779
- t.beginPath(), t.moveTo(e[0].x, e[0].y);
1780
- for (const n of e.slice(1)) t.lineTo(n.x, n.y);
1781
- t.closePath();
1782
- }
1783
- function hi(t, e, n) {
1784
- const o = n.shading;
1785
- if (o.mode === "none" || n.fill === "none") return;
1786
- const s = Math.hypot(...o.light), r = { x: o.light[0] / s, y: o.light[1] / s }, i = t.globalAlpha;
1787
- t.save(), Xn(t, e.outline), t.clip();
1788
- for (const a of ["left", "right"]) {
1789
- const l = e.samples.map((h) => h[a]), c = e.samples.map((h) => {
1790
- const f = h[a], y = h.center, u = f.x - y.x, g = f.y - y.y, m = (u * r.x + g * r.y) / (Math.hypot(u, g) || 1), d = Math.max(0, -m) * 0.44;
1791
- return { x: f.x + (y.x - f.x) * d, y: f.y + (y.y - f.y) * d };
1792
- });
1793
- if (Xn(t, [...l, ...c.reverse()]), t.fillStyle = o.shadow, t.globalAlpha = i * o.opacity, t.fill(), o.highlight > 0) {
1794
- const h = e.samples.map((u) => {
1795
- const g = u[a], m = u.center;
1796
- return { x: g.x + (m.x - g.x) * 0.2, y: g.y + (m.y - g.y) * 0.2 };
1797
- }), f = e.samples[Math.floor(e.samples.length / 2)][a], y = e.samples[Math.floor(e.samples.length / 2)].center;
1798
- if ((f.x - y.x) * r.x + (f.y - y.y) * r.y > 0) {
1799
- t.globalAlpha = i * o.highlight, t.strokeStyle = "#ffffff", t.lineWidth = Math.max(1, e.samples[0].width * 0.16), t.beginPath(), t.moveTo(h[0].x, h[0].y);
1800
- for (const u of h.slice(1)) t.lineTo(u.x, u.y);
1801
- t.stroke();
1802
- }
1803
- }
1804
- }
1805
- t.restore();
1806
- }
1807
- function ci(t, e, n, o) {
1808
- const s = o.bodyContours, r = (i) => s[i] && qo(t, s[i].outline);
1809
- if (n.startsWith("arm.")) return e < 0.2 && r("spine");
1810
- if (n.startsWith("leg.")) return e < 0.2 && r("spine") || e > 0.85 && r(n.replace("leg.", "foot."));
1811
- if (n.startsWith("foot.")) return e < 0.25 && r(n.replace("foot.", "leg."));
1812
- if (n === "neck") return e < 0.6 && r("spine");
1813
- if (n === "spine") {
1814
- if (e > 0.85 && r("neck")) return !0;
1815
- for (const i of ["left", "right"]) {
1816
- if (e > 0.6 && r(`arm.${i}`)) {
1817
- const a = o.chains[`arm.${i}`]?.[0];
1818
- if (a && Math.hypot(a.x - t.x, a.y - t.y) < o.height * 0.07) return !0;
1819
- }
1820
- if (e < 0.25 && r(`leg.${i}`)) return !0;
1821
- }
1822
- }
1823
- return !1;
1824
- }
1825
- function Gn(t, e, n, o, s) {
1826
- const r = o.bodyContours?.[s];
1827
- if (!r) return !1;
1828
- if (n.fill === "none" && (e = ye(t, e)), e.shape(r.outline, n.fill === "none" ? null : n.fill, 0), e.look === "clean" && hi(t, r, n), (e.look !== "silhouette" || n.fill === "none") && o.lineWidth > 0) {
1829
- let i = [];
1830
- for (let a = 0; a <= r.outline.length; a++) {
1831
- const l = a % r.outline.length, c = r.outline[l], h = r.outline[(l + 1) % r.outline.length], f = { x: (c.x + h.x) / 2, y: (c.y + h.y) / 2 };
1832
- s.startsWith("arm.") && r.positions[l] === 1 || ci(f, r.positions[l], s, o) ? (i.length >= 2 && e.line(i, o.lineWidth), i = []) : (i.length === 0 && i.push(c), i.push(h));
1833
- }
1834
- i.length >= 2 && e.line(i, o.lineWidth);
1835
- }
1836
- return !0;
1837
- }
1838
- function Uo(t) {
1839
- return [[0.01, -0.12, 0.8], [0, -0.25, 0.98], [-0.04, -0.31, 0.8]].map((e) => oe(t, e).point);
1840
- }
1841
- function Xo(t, e) {
1842
- const n = e.shape === "angular" ? fi(t, e) : e.projection === "volume" ? ui(t) : en(t.center.x, t.center.y, t.rx, t.ry, t.angle);
1843
- if (e.projection !== "volume" || !e.nose) return n;
1844
- const o = Math.cos(t.angle), s = Math.sin(t.angle), r = (f) => ({
1845
- x: ((f.x - t.center.x) * o + (f.y - t.center.y) * s) / t.rx,
1846
- y: ((f.x - t.center.x) * s - (f.y - t.center.y) * o) / t.ry
1847
- }), i = r(Uo(t)[1]), a = Math.sign(i.x), l = i.y, c = n.flatMap((f, y) => {
1848
- const u = r(f), g = r(n[(y + 1) % n.length]);
1849
- if (u.y > l == g.y > l) return [];
1850
- const m = (l - u.y) / (g.y - u.y);
1851
- return [(u.x + (g.x - u.x) * m) * a];
1852
- }), h = Math.max(0, i.x * a - Math.max(...c));
1853
- return !Number.isFinite(h) || h === 0 ? n : n.flatMap((f, y) => {
1854
- const u = n[(y + 1) % n.length], g = r(f), m = r(u), d = Math.max(1, Math.ceil(Math.hypot(m.x - g.x, m.y - g.y) / 0.025));
1855
- return Array.from({ length: d }, (b, x) => {
1856
- const M = x / d, v = { x: f.x + (u.x - f.x) * M, y: f.y + (u.y - f.y) * M }, P = r(v), C = (P.y - l + 0.115) / 0.23;
1857
- if (P.x * a < 0.5 || C <= 0 || C >= 1) return v;
1858
- const I = Math.sin(C * Math.PI) ** 2 * h * t.rx * a;
1859
- return { x: v.x + I * o, y: v.y + I * s };
1860
- });
1861
- });
1862
- }
1863
- function fi(t, e) {
1864
- const n = Math.min(0.95, Math.max(0.55, e.jawWidth ?? 0.74)), o = Math.min(0.35, Math.max(0.03, e.chinWidth ?? 0.14)), s = [[-1, 0], [-0.92, o], [-0.5, n], [-0.12, Math.sqrt(1 - 0.12 ** 2)]];
1865
- for (let r = 0; r <= 12; r++) {
1866
- const i = r * Math.PI / 24;
1867
- s.push([Math.sin(i), Math.cos(i)]);
1868
- }
1869
- return Go(t, s, e.jawRoundness ?? 0, e.projection === "volume");
1870
- }
1871
- function ui(t) {
1872
- const e = Array.from({ length: 41 }, (n, o) => {
1873
- const s = -Math.PI / 2 + o * Math.PI / 40;
1874
- return [Math.sin(s), Math.cos(s)];
1875
- });
1876
- return Go(t, e, 0, !0);
1877
- }
1878
- function Go(t, e, n, o) {
1879
- const s = [];
1880
- for (const [a, l] of e)
1881
- for (let c = 0; c < 40; c++) {
1882
- const h = c * Math.PI / 20, f = l * Math.sin(h);
1883
- s.push(oe(t, [l * Math.cos(h), a, o ? Math.min(f, 0.82) : f]).point);
1884
- }
1885
- let r = kn(s);
1886
- if (n = Math.min(1, Math.max(0, n)), n === 0) return r;
1887
- const i = n * 0.25;
1888
- for (let a = 0; a < 3; a++)
1889
- r = r.flatMap((l, c) => {
1890
- const h = r[(c + 1) % r.length];
1891
- return [
1892
- { x: l.x + (h.x - l.x) * i, y: l.y + (h.y - l.y) * i },
1893
- { x: h.x + (l.x - h.x) * i, y: h.y + (l.y - h.y) * i }
1894
- ];
1895
- });
1896
- return r;
1897
- }
1898
- function kn(t) {
1899
- const e = t.sort((s, r) => s.x - r.x || s.y - r.y), n = (s, r, i) => (r.x - s.x) * (i.y - s.y) - (r.y - s.y) * (i.x - s.x), o = (s) => {
1900
- const r = [];
1901
- for (const i of s) {
1902
- for (; r.length >= 2 && n(r[r.length - 2], r[r.length - 1], i) <= 0; ) r.pop();
1903
- r.push(i);
1904
- }
1905
- return r.slice(0, -1);
1906
- };
1907
- return [...o(e), ...o([...e].reverse())];
1908
- }
1909
- const Ko = 0.34, yt = 0.12, dt = -0.4, gt = (t, e, n) => t[e] ?? n, di = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), gi = 0.45, yi = 0.35, mi = 0.7, Kn = 0.78;
1910
- function et(t, e, n, o = "cartoon") {
1911
- const s = (u) => Math.sqrt(Math.max(0, 1 - u.x * u.x - u.y * u.y));
1912
- let r = oe(t, [n.x, n.y, s(n)]).facing;
1913
- const i = t.axes[2];
1914
- o === "volume" && n.x * i[0] > 0 && (r = Math.max(r, i[2]));
1915
- const a = Math.atan2(i[0], i[2]), l = Math.cos(a), c = Math.max(yi, l), h = Math.max(mi, l), f = Math.cos(t.angle), y = Math.sin(t.angle);
1916
- if (o === "volume") {
1917
- const u = oe(t, [n.x, n.y, s(n) * Kn]).point, g = Math.abs(n.x) > 0.1 ? Math.min(1, Math.max(0, r) / 0.25) : 1, m = Math.max(n.x * i[0] > 0 ? 0.2 : 0.5, l);
1918
- return { facing: r, points: e.map((d) => {
1919
- const b = (d.x - n.x) * m * t.rx * g, x = (d.y - n.y + i[1] * (s(d) - s(n)) * Kn) * t.ry * g;
1920
- return { x: u.x + b * f + x * y, y: u.y + b * y - x * f };
1921
- }) };
1922
- }
1923
- return {
1924
- facing: r,
1925
- points: e.map((u) => {
1926
- const g = gi * Math.sin(a) + n.x * c + (u.x - n.x) * h, m = u.y + i[1] * s(u), d = g * t.rx, b = m * t.ry;
1927
- return { x: t.center.x + d * f + b * y, y: t.center.y + d * y - b * f };
1928
- })
1929
- };
1930
- }
1931
- const Rt = (t, e, n, o = 12) => Array.from({ length: o + 1 }, (s, r) => {
1932
- const i = r / o, a = 1 - i;
1933
- return { x: a * a * t.x + 2 * a * i * e.x + i * i * n.x, y: a * a * t.y + 2 * a * i * e.y + i * i * n.y };
1934
- }), he = (t, e, n, o) => {
1935
- const s = Math.min(1, Math.max(0, (o - t.x) / (n.x - t.x))), r = 1 - s;
1936
- return r * r * t.y + 2 * r * s * e.y + s * s * n.y;
1937
- }, $t = (t, e, n, o, s = 16) => Array.from({ length: s }, (r, i) => {
1938
- const a = Math.PI * 2 * i / s;
1939
- return { x: t + Math.cos(a) * n, y: e + Math.sin(a) * o };
1940
- }), qt = 0.05, pi = 0.3, bi = "#e06b7d";
1941
- function wi(t, e, n, o, s = {}, r) {
1942
- const i = Math.max(1, Math.min(o * 0.6, 0.14 * e.rx)), a = (w, E) => et(e, w, E, s.projection).points, l = (w, E) => et(e, [], { x: w, y: E }, s.projection).facing, c = gt(n, "smile", 0), h = gt(n, "blink", 0), f = gt(n, "lookX", 0), y = gt(n, "lookY", 0), u = gt(n, "browTilt", 0), g = Math.max(0.2, gt(n, "pupil", 1)), m = Math.min(1, Math.max(0, gt(n, "lid", 0))), d = Math.min(1, Math.max(0, gt(n, "bulge", 0)));
1943
- for (const w of [1, -1]) {
1944
- const E = w === 1 ? "left" : "right", H = Ko * w;
1945
- if (l(H, yt) < qt) continue;
1946
- const N = { x: H, y: yt }, D = di(gt(n, `eye.${E}`, 1), h);
1947
- if (D < 0.2 || s.style === "anime" && m >= 0.98) {
1948
- const J = c > 0.5 ? 0.12 : -0.06;
1949
- t.line(a(Rt({ x: H - 0.12, y: yt }, { x: H, y: yt + J }, { x: H + 0.12, y: yt }), N), i);
1950
- } else if (s.style === "anime")
1951
- xi(t, e, N, w, D, m, d, g, f, y, i, s, r);
1952
- else {
1953
- const J = D > 1.2 || d > 0.02, j = 0.13 * Math.max(D, 1) * (1 + d * 0.7);
1954
- J && t.shape(a($t(H, yt, j * 0.85, j), N), "#ffffff", i);
1955
- const Q = (D > 1.2 ? 0.075 : 0.1) * g * (1 + d * 0.3), nt = H + f * 0.08, lt = yt - y * 0.07, bt = $t(nt, lt, Q, Q * 1.1 * Math.min(D, 1));
1956
- if (t.shape(a(bt, N), t.ink, 0), s.inPupil && r) {
1957
- const [p] = a([{ x: nt, y: lt }], N), k = a(bt, N), O = Math.min(...k.map((T) => Math.hypot(T.x - p.x, T.y - p.y)));
1958
- O > 0.5 && (r.save(), r.beginPath(), r.arc(p.x, p.y, O, 0, Math.PI * 2), r.clip(), s.inPupil(r, { x: p.x, y: p.y, r: O, side: E }), r.restore());
1959
- }
1960
- if (m > 0.02) {
1961
- const p = J ? j * 1.15 : Q * 1.4, k = yt + p, O = k - p * 2 * m, T = p * 1.1;
1962
- t.shape(a([{ x: H - T, y: k + 0.02 }, { x: H + T, y: k + 0.02 }, { x: H + T, y: O }, { x: H - T, y: O }], N), s.skin ?? "#ffffff", 0), t.line(a([{ x: H - T, y: O }, { x: H + T, y: O }], N), i);
1963
- }
1964
- }
1965
- const X = yt + (s.style === "anime" ? 0.38 : 0.3) + gt(n, `brow.${E}`, 0) * 0.14 + Math.max(0, D - 1) * 0.12, K = { x: H + w * 0.13, y: X }, q = { x: H - w * 0.13, y: X + u * 0.1 };
1966
- t.line(a([K, { x: (K.x + q.x) / 2, y: (K.y + q.y) / 2 }, q], { x: H, y: X }), i);
1967
- }
1968
- ki(t, e, n, i, s.projection), Mi(t, e, s.ageLines ?? 0, i, s.projection);
1969
- const b = { x: 0, y: dt };
1970
- if (l(0, dt) < -qt) return;
1971
- s.nose && l(0, yt - 0.15) >= qt && (s.projection === "volume" ? t.line(Uo(e), i) : t.line(a([{ x: 0.01, y: yt - 0.1 }, { x: 0.03, y: dt + 0.2 }, { x: -0.05, y: dt + 0.17 }], { x: 0, y: dt + 0.22 }), i));
1972
- const x = 0.25 * Math.max(0.3, gt(n, "mouthWidth", 1)), M = Math.min(1, Math.max(0, gt(n, "mouth", 0)));
1973
- if (M <= 0.05) {
1974
- t.line(a(Rt({ x: -x, y: dt }, { x: 0, y: dt - c * 0.25 }, { x, y: dt }), b), i);
1975
- return;
1976
- }
1977
- const v = 0.3 * M;
1978
- let P, C, I, $;
1979
- if (c > 0.3) {
1980
- const w = dt + 0.05, E = { x: 0, y: dt - v * 2 };
1981
- P = [...Rt({ x, y: w }, E, { x: -x, y: w })], C = () => w, I = (H) => he({ x, y: w }, E, { x: -x, y: w }, H), $ = 0.85;
1982
- } else if (c < -0.3) {
1983
- const w = dt - v * 0.6, E = { x: 0, y: dt + v * 1.4 };
1984
- P = [...Rt({ x, y: w }, E, { x: -x, y: w })], C = (H) => he({ x, y: w }, E, { x: -x, y: w }, H), I = () => w, $ = 0.5;
1985
- } else {
1986
- const w = x * 0.8;
1987
- P = $t(0, dt, w, v);
1988
- const E = (H) => v * Math.sqrt(Math.max(0, 1 - (H / w) ** 2));
1989
- C = (H) => dt + E(H), I = (H) => dt - E(H), $ = 0.5;
1990
- }
1991
- if (t.shape(a(P, b), t.ink, 0), M < pi) return;
1992
- const A = C(0) - I(0), z = x * $, R = (w, E, H = 8) => Array.from({ length: H + 1 }, (N, D) => w + (E - w) * D / H);
1993
- if (s.tongue) {
1994
- const w = z * 0.55, E = R(w, -w).map((N) => ({ x: N, y: I(N) })), H = Rt({ x: -w, y: I(-w) }, { x: 0, y: I(0) + A * 0.8 }, { x: w, y: I(w) }, 8);
1995
- t.shape(a([...E, ...H.slice(1, -1)], b), bi, 0);
1996
- }
1997
- if (s.teeth) {
1998
- const w = Math.min(0.06, A * 0.4), E = R(-z, z).map((N) => ({ x: N, y: C(N) })), H = E.map(({ x: N, y: D }) => ({ x: N * 0.92, y: D - w })).reverse();
1999
- t.shape(a([...E, ...H], b), "#ffffff", 0);
2000
- for (const N of [-0.5, 0, 0.5]) {
2001
- const D = z * N;
2002
- t.line(a([{ x: D, y: C(D) }, { x: D * 0.92, y: C(D) - w }], b), i * 0.6);
2003
- }
2004
- }
2005
- }
2006
- function xi(t, e, n, o, s, r, i, a, l, c, h, f, y) {
2007
- const { x: u, y: g } = n, m = Math.min(1.2, Math.max(0.5, f.eyeScale ?? 1)), d = Math.min(1.2, Math.max(0.45, f.eyeAspect ?? 1)), b = 0.21 * m * (1 + i * 0.15), x = 0.25 * m * d * Math.min(s, 1.6) * (1 - r) * (1 + i * 0.3), M = { x: u - b, y: g }, v = { x: u + b, y: g }, P = { x: u, y: g + x * 1.9 }, C = { x: u, y: g - x * 1.35 }, I = Rt(M, P, v), $ = Rt(v, C, M), A = (X) => et(e, X, n, f.projection).points, z = (X) => X.map((K) => {
2008
- const q = Math.min(v.x, Math.max(M.x, K.x));
2009
- return { x: q, y: Math.min(he(M, P, v, q), Math.max(he(v, C, M, q), K.y)) };
2010
- });
2011
- t.shape(A([...I, ...$.slice(1, -1)]), "#ffffff", h * 0.5);
2012
- const R = u + Math.max(-1, Math.min(1, l)) * 0.07 * m, w = g - Math.max(-1, Math.min(1, c)) * 0.055 * m, E = 0.115 * m, H = 0.185 * m;
2013
- t.shape(A(z($t(R, w, E, H, 24))), f.iris ?? "#4b7fce", h * 0.4), t.shape(A(z($t(R, w - 0.075 * m, E * 0.7, H * 0.35))), "rgba(255,255,255,0.25)", 0);
2014
- const N = Math.min(0.085, 0.042 * a) * m, D = z($t(R, w, N, N * 1.35));
2015
- if (t.shape(A(D), t.ink, 0), f.inPupil && y) {
2016
- const [X] = A([{ x: R, y: w }]), K = Math.min(...A(D).map((q) => Math.hypot(q.x - X.x, q.y - X.y)));
2017
- K > 0.5 && (y.save(), y.beginPath(), y.arc(X.x, X.y, K, 0, Math.PI * 2), y.clip(), f.inPupil(y, { ...X, r: K, side: o === 1 ? "left" : "right" }), y.restore());
2018
- }
2019
- if (t.shape(A(z($t(R - 0.038 * m, w + 0.075 * m, 0.035 * m, 0.045 * m))), "#ffffff", 0), t.shape(A(z($t(R + 0.04 * m, w - 0.04 * m, 0.014 * m, 0.02 * m))), "#ffffff", 0), t.line(A(I), h * 1.1), f.lashes !== !1)
2020
- for (const X of [0, 0.035]) {
2021
- const K = u + o * (b - X), q = he(M, P, v, K);
2022
- t.line(A([{ x: K, y: q }, { x: K + o * 0.055, y: q + 0.07 }]), h * 0.75);
2023
- }
2024
- }
2025
- function Mi(t, e, n, o, s) {
2026
- const r = Math.min(1, Math.max(0, n));
2027
- if (!(r <= 0))
2028
- for (const i of [-1, 1]) {
2029
- const a = { x: i * 0.59, y: yt };
2030
- if (et(e, [], a, s).facing < qt) continue;
2031
- for (const h of [-0.06, 0.035]) {
2032
- const f = [{ x: a.x, y: a.y }, { x: a.x + i * 0.1, y: a.y + h }];
2033
- t.line(et(e, f, a, s).points, o * 0.45 * r);
2034
- }
2035
- const l = { x: i * 0.3, y: -0.38 }, c = Rt({ x: l.x, y: -0.31 }, { x: l.x + i * 0.07, y: -0.4 }, { x: l.x + i * 0.035, y: -0.49 });
2036
- t.line(et(e, c, l, s).points, o * 0.35 * r);
2037
- }
2038
- }
2039
- const Vn = "#8fd0f5", Jn = (t, e, n) => Array.from({ length: 18 }, (o, s) => {
2040
- const r = Math.PI * 2 * s / 18, i = Math.sin(r / 2);
2041
- return { x: t + Math.sin(r) * n * i, y: e - n * 0.9 + Math.cos(r) * n * 1.6 * (0.55 + 0.45 * i) - n * 0.4 };
2042
- });
2043
- function ki(t, e, n, o, s) {
2044
- const r = Math.min(1, Math.max(0, gt(n, "blush", 0))), i = Math.min(1, Math.max(0, gt(n, "tears", 0))), a = Math.min(1, Math.max(0, gt(n, "sweat", 0)));
2045
- if (!(r + i + a <= 0.01)) {
2046
- for (const l of [1, -1]) {
2047
- const c = { x: 0.5 * l, y: -0.16 }, h = et(e, [], c, s).facing >= qt;
2048
- if (r > 0.01 && h) {
2049
- const { points: y } = et(e, $t(c.x, c.y, 0.17, 0.1), c, s);
2050
- if (t.shape(y, `rgba(240, 120, 140, ${(0.75 * r).toFixed(3)})`, 0), r > 0.5)
2051
- for (const u of [-0.07, 0, 0.07]) {
2052
- const g = [{ x: c.x + u - 0.018, y: c.y - 0.03 }, { x: c.x + u + 0.018, y: c.y + 0.03 }];
2053
- t.line(et(e, g, c, s).points, o * 0.3);
2054
- }
2055
- }
2056
- const f = { x: Ko * l, y: yt };
2057
- if (i > 0.01 && et(e, [], f, s).facing >= qt) {
2058
- const y = 0.05 + 0.04 * i, u = { x: f.x + 0.06 * l, y: yt - 0.2 - 0.12 * i };
2059
- if (t.shape(et(e, Jn(u.x, u.y, y), u, s).points, Vn, o * 0.35), i > 0.6) {
2060
- const g = [{ x: f.x + 0.05 * l, y: yt - 0.1 }, { x: u.x, y: u.y + y * 0.8 }];
2061
- t.line(et(e, g, u, s).points, o * 0.3);
2062
- }
2063
- }
2064
- }
2065
- if (a > 0.01) {
2066
- const l = { x: 0.64, y: 0.42 };
2067
- et(e, [], l, s).facing >= qt && t.shape(et(e, Jn(l.x, l.y, 0.05 + 0.05 * a), l, s).points, Vn, o * 0.35);
2068
- }
2069
- }
2070
- }
2071
- const vi = 15;
2072
- function Ot(t, e) {
2073
- const n = Math.sqrt(Math.max(0, 1 - e * e));
2074
- return [n * Math.sin(t), e, n * Math.cos(t)];
2075
- }
2076
- const Ei = ([t, e, n]) => {
2077
- const o = Math.hypot(t, e, n) || 1;
2078
- return [t / o, e / o, n / o];
2079
- };
2080
- function pt(t, [e, n, o]) {
2081
- const [s, r, i] = t.axes;
2082
- return s[2] * e + r[2] * n + i[2] * o;
2083
- }
2084
- function it(t, e) {
2085
- return oe(t, e).point;
2086
- }
2087
- function _e(t, e) {
2088
- const n = Math.abs(t - e) % (Math.PI * 2);
2089
- return n > Math.PI ? Math.PI * 2 - n : n;
2090
- }
2091
- function Be(t, e, n = 64) {
2092
- const o = e.top ?? 1, s = e.bottom ?? -1, r = Math.max(8, Math.ceil((o - s) * vi)), i = (g) => Math.min(o, Math.max(s, o - (o - s) * (g - 1) / r)), a = (g) => -Math.PI + Math.PI * 2 * g / n, l = (g, m) => e.normal ? e.normal(g, m) : Ei(e.position(g, m)), c = r + 3, h = new Float64Array(n * c), f = new Float64Array(n * c);
2093
- for (let g = 0; g < c; g++) {
2094
- const m = g === 0 || g === c - 1, d = i(g);
2095
- for (let b = 0; b < n; b++) {
2096
- const x = g * n + b;
2097
- if (m) {
2098
- h[x] = -1;
2099
- continue;
2100
- }
2101
- const M = a(b);
2102
- h[x] = e.inside(M, d), f[x] = h[x] > -0.35 ? pt(t, l(M, d)) : 0;
2103
- }
2104
- }
2105
- const y = (g) => (g % n + n) % n, u = (g) => {
2106
- const m = n + 1, d = new Float64Array(m * c);
2107
- for (let w = 0; w < c; w++)
2108
- for (let E = 0; E <= n; E++) {
2109
- const H = w * n + (E === n ? 0 : E);
2110
- d[w * m + E] = Math.min(h[H], g * f[H]);
2111
- }
2112
- const b = (w, E) => d[E * m + w], x = (w, E, H, N) => {
2113
- const D = b(w, E), X = b(H, N), K = D === X ? 0.5 : Math.min(1, Math.max(0, D / (D - X)));
2114
- return it(t, e.position(a(w + (H - w) * K), i(E + (N - E) * K)));
2115
- }, M = n * c * 2, v = new Int32Array(M).fill(-1), P = new Int32Array(M).fill(-1), C = /* @__PURE__ */ new Map(), I = (w, E, H) => {
2116
- const N = (H * n + y(E)) * 2 + (w ? 1 : 0);
2117
- return C.has(N) || C.set(N, w ? x(y(E), H, y(E), H + 1) : x(E, H, E + 1, H)), N;
2118
- }, $ = (w, E) => {
2119
- v[w] === -1 ? v[w] = E : P[w] = E;
2120
- }, A = (w, E) => {
2121
- $(w, E), $(E, w);
2122
- };
2123
- for (let w = 0; w < c - 1; w++)
2124
- for (let E = 0; E < n; E++) {
2125
- const H = w * m + E, N = (d[H] > 0 ? 8 : 0) | (d[H + 1] > 0 ? 4 : 0) | (d[H + m + 1] > 0 ? 2 : 0) | (d[H + m] > 0 ? 1 : 0);
2126
- if (N === 0 || N === 15) continue;
2127
- const D = () => I(!1, E, w), X = () => I(!1, E, w + 1), K = () => I(!0, E, w), q = () => I(!0, E + 1, w);
2128
- switch (N) {
2129
- case 1:
2130
- case 14:
2131
- A(K(), X());
2132
- break;
2133
- case 2:
2134
- case 13:
2135
- A(X(), q());
2136
- break;
2137
- case 3:
2138
- case 12:
2139
- A(K(), q());
2140
- break;
2141
- case 4:
2142
- case 11:
2143
- A(D(), q());
2144
- break;
2145
- case 6:
2146
- case 9:
2147
- A(D(), X());
2148
- break;
2149
- case 7:
2150
- case 8:
2151
- A(K(), D());
2152
- break;
2153
- case 5:
2154
- case 10: {
2155
- const J = (b(E, w) + b(E + 1, w) + b(E + 1, w + 1) + b(E, w + 1)) / 4 > 0;
2156
- N === 5 === J ? (A(K(), D()), A(X(), q())) : (A(K(), X()), A(D(), q()));
2157
- break;
2158
- }
2159
- }
2160
- }
2161
- const z = [], R = new Uint8Array(M);
2162
- for (const w of C.keys()) {
2163
- if (R[w]) continue;
2164
- const E = [];
2165
- let H = -1, N = w;
2166
- for (; N !== -1 && !R[N]; ) {
2167
- R[N] = 1, E.push(C.get(N));
2168
- const D = v[N], X = P[N], K = D !== -1 && D !== H && !R[D] ? D : X !== -1 && X !== H && !R[X] ? X : -1;
2169
- H = N, N = K;
2170
- }
2171
- E.length >= 3 && z.push(E);
2172
- }
2173
- return z;
2174
- };
2175
- return { near: u(1), far: u(-1) };
2176
- }
2177
- const Zn = /* @__PURE__ */ new WeakMap();
2178
- function vn(t, e, n) {
2179
- let o = Zn.get(t);
2180
- o || Zn.set(t, o = /* @__PURE__ */ new Map());
2181
- let s = o.get(e);
2182
- return s || o.set(e, s = n()), s;
2183
- }
2184
- function En(t, e, n, o) {
2185
- if (t.save(), t.beginPath(), t.rect(-1e5, -1e5, 2e5, 2e5), o?.length) {
2186
- t.moveTo(o[0].x, o[0].y);
2187
- for (const s of o.slice(1)) t.lineTo(s.x, s.y);
2188
- t.closePath();
2189
- } else
2190
- t.ellipse(e.center.x, e.center.y, e.rx, e.ry, e.angle, 0, Math.PI * 2);
2191
- t.clip("evenodd"), n(), t.restore();
2192
- }
2193
- function Vo(t, e, n, o = 0.04) {
2194
- const s = [];
2195
- let r = [];
2196
- return e.forEach((i, a) => {
2197
- pt(t, n[a]) > o ? r.push(it(t, i)) : (r.length >= 2 && s.push(r), r = []);
2198
- }), r.length >= 2 && s.push(r), s;
2199
- }
2200
- const Qn = (t) => t * Math.PI / 180, fn = (t) => {
2201
- const e = Math.hypot(...t) || 1;
2202
- return t.map((n) => n / e);
2203
- }, Si = (t, e) => [t[1] * e[2] - t[2] * e[1], t[2] * e[0] - t[0] * e[2], t[0] * e[1] - t[1] * e[0]];
2204
- function jn(t, e, n) {
2205
- return t >= e + n ? t : t <= e - n ? e : e + (t - e + n) ** 2 / (4 * n);
2206
- }
2207
- function Ve(t, e, n) {
2208
- const o = fn(n), s = t.reduce((c, h, f) => c + h * o[f], 0), i = t.map((c, h) => c - s * o[h]).reduce((c, h) => c + h * h, 0), a = Math.sqrt(jn(1 - i, e * e, e * e)), l = jn(s, a, e) - s;
2209
- return l === 0 ? t : t.map((c, h) => c + o[h] * l);
2210
- }
2211
- function Pi(t) {
2212
- if (t.path.length < 4 || (t.path.length - 1) % 3 !== 0) throw new Error("hair: a lock path needs a root and groups of three cubic points");
2213
- if (!Number.isFinite(t.width) || t.width <= 0 || t.follow !== void 0 && (!Number.isFinite(t.follow) || t.follow < 0))
2214
- throw new Error("hair: lock width must be positive and follow must be nonnegative");
2215
- for (const n of t.path)
2216
- if (!Number.isFinite(n.around) || !Number.isFinite(n.up) || n.up > 1 || n.lift !== void 0 && (!Number.isFinite(n.lift) || n.lift < 0))
2217
- throw new Error("hair: lock points need finite around/up values, up <= 1 and nonnegative lift");
2218
- const e = t.path[0];
2219
- if (e.up < 0 || (e.lift ?? 0) !== 0) throw new Error("hair: a lock root must lie on the scalp (up 0..1, lift 0)");
2220
- return { ...t, path: t.path.map((n) => ({ ...n })) };
2221
- }
2222
- function Ai(t, e, n, o) {
2223
- const s = (t.path.length - 1) / 3, r = s * 20, i = [], a = [], l = o.trail !== 0 || o.lift !== 0, c = Math.max(0, e + n);
2224
- for (let h = 0; h <= r; h++) {
2225
- const f = h / r, y = Math.min(s - 1, Math.floor(f * s)), u = f * s - y, g = 1 - u, m = [g ** 3, 3 * g * g * u, 3 * g * u * u, u ** 3], d = t.path.slice(y * 3, y * 3 + 4), b = Qn(d.reduce((H, N, D) => H + N.around * m[D], 0)), x = d.reduce((H, N, D) => H + N.up * m[D], 0), M = d.reduce((H, N, D) => H + (N.lift ?? 0) * m[D], 0), v = 1 + e + n + M, P = x >= 0 ? Math.sqrt(Math.max(0, 1 - x * x)) : 1, C = f * f * (t.follow ?? 1), I = Qn(o.swing) * C, $ = b - I, A = [Math.sin($) * P * v, x * (x >= 0 ? v : 1), Math.cos($) * P * v], z = [A[0], A[1] + o.lift * C, A[2] - o.trail * C], R = [Math.sin($) * P, Math.max(0, x), Math.cos($) * P], w = fn(A), E = l && C > 0 ? Ve(z, c, w) : z;
2226
- a.push(w), i.push({ center: E, normal: R, left: E, right: E, t: f });
2227
- }
2228
- return i.forEach((h, f) => {
2229
- const y = i[Math.max(0, f - 1)].center, g = i[Math.min(r, f + 1)].center.map((b, x) => b - y[x]), m = fn(Si(h.normal, g)), d = t.width * Math.sin(Math.PI * h.t) ** 0.6 * 0.5;
2230
- h.left = h.center.map((b, x) => b + m[x] * d), h.right = h.center.map((b, x) => b - m[x] * d), l && h.t > 0 && (t.follow ?? 1) > 0 && (h.left = Ve(h.left, c, a[f]), h.right = Ve(h.right, c, a[f]));
2231
- }), i;
2232
- }
2233
- const te = (t, e, n) => t.map((o, s) => o + (e[s] - o) * n);
2234
- function Ii(t, e, n) {
2235
- const o = n ? 1 : -1, s = [];
2236
- let r = [];
2237
- for (let i = 0; i < e.length; i++) {
2238
- const a = e[i], l = o * pt(t, a.normal) >= 0;
2239
- if (i > 0) {
2240
- const c = e[i - 1], h = o * pt(t, c.normal), f = o * pt(t, a.normal);
2241
- if (h >= 0 !== l) {
2242
- const y = h / (h - f), u = {
2243
- center: te(c.center, a.center, y),
2244
- left: te(c.left, a.left, y),
2245
- right: te(c.right, a.right, y),
2246
- normal: te(c.normal, a.normal, y),
2247
- t: c.t + (a.t - c.t) * y
2248
- };
2249
- l ? r = [u] : (r.push(u), r.length >= 2 && s.push(r), r = []);
2250
- }
2251
- }
2252
- l && r.push(a);
2253
- }
2254
- return r.length >= 2 && s.push(r), s;
2255
- }
2256
- function Jo(t, e, n, o, s, r, i) {
2257
- const a = (n.locks ?? []).map((h) => Ai(h, n.volume, o, s)), l = (h) => h.reduce((f, y) => f + pt(e, y.center), 0) / h.length;
2258
- a.sort((h, f) => l(h) - l(f));
2259
- const c = Math.max(0.7, r * 0.35);
2260
- for (const h of a)
2261
- for (const f of Ii(e, h, i)) {
2262
- const y = f.map((m) => it(e, m.left)), u = f.map((m) => it(e, m.right));
2263
- if (t.shape([...y, ...u.slice().reverse()], n.color, 0), t.look === "clean" && (n.shine ?? 0) > 0) {
2264
- const m = f.filter((d) => d.t >= 0.2 && d.t <= 0.75);
2265
- if (m.length >= 3) {
2266
- const d = m.map((x, M) => {
2267
- const v = 0.16 * Math.sin(Math.PI * M / (m.length - 1));
2268
- return it(e, te(x.center, x.left, 0.16 + v));
2269
- }), b = m.map((x) => it(e, te(x.center, x.left, 0.16)));
2270
- t.shape([...d, ...b.reverse()], `rgba(255,255,255,${n.shine})`, 0);
2271
- }
2272
- }
2273
- const g = f.filter((m) => m.t > 0.3);
2274
- g.length >= 2 && t.line(g.map((m) => it(e, m.left)), c);
2275
- }
2276
- }
2277
- const rt = (t, e, n = 0) => ({ around: t, up: e, lift: n }), Je = () => [
2278
- { width: 0.66, follow: 0.22, path: [rt(-38, 0.88), rt(-12, 0.94, 0.08), rt(58, 0.76, 0.09), rt(94, 0.16, 0.03)] },
2279
- { width: 0.58, follow: 0.3, path: [rt(-42, 0.8), rt(-24, 0.7, 0.12), rt(18, 0.57, 0.09), rt(64, 0.3)] },
2280
- { width: 0.36, follow: 0.18, path: [rt(-58, 0.76), rt(-76, 0.56, 0.07), rt(-90, 0.12, 0.06), rt(-102, -0.36)] }
2281
- ];
2282
- function to(t) {
2283
- return [-100, -130, -160, -190, -220, -250, -280].map((e, n) => {
2284
- const o = n % 2 === 0 ? 1 : -1, s = t ? -2.45 - n % 3 * 0.12 : -1.06 - n % 3 * 0.09;
2285
- return {
2286
- width: t ? 0.88 : 0.92,
2287
- follow: t ? 0.8 + n % 3 * 0.12 : 0.38 + n % 3 * 0.08,
2288
- path: t ? [
2289
- rt(e, 0.7),
2290
- rt(e + o * 9, 0.2, 0.12),
2291
- rt(e - o * 13, -0.5, 0.2),
2292
- rt(e - o * 8, -0.95, 0.16),
2293
- rt(e - o * 3, -1.4, 0.12),
2294
- rt(e + o * 18, s + 0.35, 0.22),
2295
- rt(e + o * 12, s, 0.03)
2296
- ] : [
2297
- rt(e, 0.7),
2298
- rt(e + o * 7, 0.15, 0.2),
2299
- rt(e - o * 8, -0.75, 0.25),
2300
- rt(e + o * 5, s)
2301
- ]
2302
- };
2303
- });
2304
- }
2305
- const Oi = {
2306
- softSweep: {
2307
- volume: 0.12,
2308
- shine: 0.16,
2309
- part: -38,
2310
- strands: "part",
2311
- sweep: -0.08,
2312
- hairline: { front: 0.64, side: 0.12, back: -0.8 },
2313
- locks: Je()
2314
- },
2315
- flowingBob: {
2316
- volume: 0.15,
2317
- shine: 0.16,
2318
- length: 0.96,
2319
- fall: { taper: 0.08, wave: 0.08 },
2320
- part: -38,
2321
- strands: "part",
2322
- sweep: -0.08,
2323
- hairline: { front: 0.64, side: 0.08, back: -0.8 },
2324
- coversEars: !0,
2325
- locks: [...to(!1), ...Je()]
2326
- },
2327
- cascadingWaves: {
2328
- volume: 0.16,
2329
- shine: 0.16,
2330
- length: 2.38,
2331
- fall: { taper: 0.18, wave: 0.12 },
2332
- part: -38,
2333
- strands: "part",
2334
- sweep: -0.08,
2335
- hairline: { front: 0.64, side: 0.08, back: -0.8 },
2336
- coversEars: !0,
2337
- locks: [...to(!0), ...Je()]
2338
- }
2339
- }, ue = { swing: 0, trail: 0, lift: 0 };
2340
- function Fe(t) {
2341
- if (!t) return ue;
2342
- const e = t["hair.swing"] ?? 0, n = t["hair.trail"] ?? 0, o = t["hair.lift"] ?? 0;
2343
- return e === 0 && n === 0 && o === 0 ? ue : { swing: e, trail: n, lift: o };
2344
- }
2345
- const Zo = (t) => t.swing === 0 && t.trail === 0 && t.lift === 0;
2346
- function Qa(t) {
2347
- return t.length > 0 || t.ties.some((e) => e.kind !== "bun") || (t.locks ?? []).some((e) => (e.follow ?? 1) > 0);
2348
- }
2349
- function un([t, e, n], o) {
2350
- if (o === 0) return [t, e, n];
2351
- const s = Math.cos(o), r = Math.sin(o);
2352
- return [t * s - n * r, e, n * s + t * r];
2353
- }
2354
- const eo = {
2355
- color: "#6b4630",
2356
- volume: 0.1,
2357
- hairline: { front: 0.5, side: 0.12, back: -0.82 },
2358
- sweep: 0,
2359
- recede: 0,
2360
- length: 0,
2361
- opening: 84,
2362
- texture: "smooth",
2363
- textureAmount: 0,
2364
- quiff: 0,
2365
- flat: 0,
2366
- part: null,
2367
- strands: "none",
2368
- fill: "solid",
2369
- ties: [],
2370
- coversEars: !1
2371
- }, no = 1.75, Ti = {
2372
- ...Oi,
2373
- // Short hair and hairlines
2374
- bald: { volume: 0, hairline: { front: 2, side: 2, back: 2 } },
2375
- buzzCut: { volume: 0, fill: "stipple", hairline: { front: 0.52, side: 0.1, back: -0.8 } },
2376
- crewCut: { volume: 0.1, texture: "spiky", textureAmount: 0.07, hairline: { front: 0.55, side: 0.1, back: -0.8 } },
2377
- short: { volume: 0.12, texture: "spiky", textureAmount: 0.1, hairline: { front: 0.42, side: 0.1, back: -0.82 }, sweep: 0.12 },
2378
- sidePart: { volume: 0.14, part: 35, strands: "sweep", sweep: -0.22, hairline: { front: 0.5, side: 0.08, back: -0.82 } },
2379
- sideSwept: { volume: 0.15, part: 45, strands: "sweep", sweep: -0.38, hairline: { front: 0.42, side: 0.05, back: -0.82 } },
2380
- slickBack: { volume: 0.12, strands: "combed", hairline: { front: 0.62, side: 0.15, back: -0.8 } },
2381
- quiff: { volume: 0.12, quiff: 0.42, strands: "combed", hairline: { front: 0.6, side: 0.15, back: -0.8 } },
2382
- spiky: { volume: 0.12, texture: "spiky", textureAmount: 0.34, hairline: { front: 0.5, side: 0.12, back: -0.8 } },
2383
- mangaSpikes: { volume: 0.12, texture: "spiky", textureAmount: 0.08, hairline: { front: 0.55, side: 0.12, back: -0.7 }, spikes: [
2384
- { around: -100, up: 0.4, length: 0.55, width: 0.24 },
2385
- { around: -65, up: 0.7, length: 0.6, width: 0.25 },
2386
- { around: -25, up: 0.93, length: 0.6, width: 0.24 },
2387
- { around: 40, up: 0.87, length: 0.7, width: 0.25 },
2388
- { around: 85, up: 0.55, length: 0.55, width: 0.24 },
2389
- { around: 160, up: 0.8, length: 0.5, width: 0.24 },
2390
- { around: -160, up: 0.65, length: 0.55, width: 0.24 }
2391
- ] },
2392
- mangaSweep: { volume: 0.14, texture: "spiky", textureAmount: 0.1, sweep: -0.35, hairline: { front: 0.5, side: 0.08, back: -0.8 }, spikes: [
2393
- { around: -95, up: 0.45, length: 0.35, width: 0.2 },
2394
- { around: -60, up: 0.8, length: 0.4, width: 0.24 },
2395
- { around: 75, up: 0.55, length: 0.4, width: 0.23 },
2396
- { around: 150, up: 0.75, length: 0.35, width: 0.2 }
2397
- ] },
2398
- undercut: { volume: 0.16, quiff: 0.18, part: 40, strands: "sweep", sweep: -0.15, hairline: { front: 0.55, side: 0.42, back: -0.3 } },
2399
- curlyCrop: { volume: 0.14, texture: "curly", textureAmount: 0.12, hairline: { front: 0.5, side: 0.1, back: -0.8 } },
2400
- afro: { volume: 0.5, texture: "curly", textureAmount: 0.12, hairline: { front: 0.5, side: -0.1, back: -0.85 }, coversEars: !0 },
2401
- wavyCrop: { volume: 0.16, texture: "wavy", textureAmount: 0.08, part: 30, hairline: { front: 0.45, side: 0.05, back: -0.82 } },
2402
- shortLocs: { volume: 0.16, texture: "locs", textureAmount: 0.1, hairline: { front: 0.38, side: -0.25, back: -0.85 }, strands: "hanging", coversEars: !0 },
2403
- flatTop: { volume: 0.1, flat: 0.42, hairline: { front: 0.5, side: 0.15, back: -0.78 } },
2404
- receding: { volume: 0.14, recede: 0.28, strands: "thin", hairline: { front: 0.74, side: 0.1, back: -0.8 } },
2405
- thinning: { volume: 0.05, strands: "thin", hairline: { front: 0.72, side: 0.05, back: -0.78 } },
2406
- // Medium and long hair
2407
- pixie: { volume: 0.16, texture: "spiky", textureAmount: 0.07, sweep: 0.3, hairline: { front: 0.32, side: -0.1, back: -0.82 } },
2408
- bob: { volume: 0.2, length: 1.05, opening: 84, sweep: 0.2, part: -25, hairline: { front: 0.34, side: 0.05, back: -0.85 }, coversEars: !0 },
2409
- longBob: { volume: 0.18, length: 1.35, opening: 84, part: 0, strands: "part", hairline: { front: 0.5, side: 0.05, back: -0.85 }, coversEars: !0 },
2410
- wavyBob: { volume: 0.22, length: 1.2, opening: 84, part: 18, texture: "wavy", textureAmount: 0.1, hairline: { front: 0.45, side: 0.05, back: -0.85 }, coversEars: !0 },
2411
- shoulderStraight: { volume: 0.16, length: no, opening: 84, part: 0, strands: "part", hairline: { front: 0.5, side: 0.05, back: -0.85 }, coversEars: !0 },
2412
- shoulderWaves: { volume: 0.22, length: no, opening: 84, part: 22, texture: "wavy", textureAmount: 0.12, hairline: { front: 0.45, side: 0.05, back: -0.85 }, coversEars: !0 },
2413
- longStraight: { volume: 0.14, length: 2.6, opening: 84, part: 0, strands: "hanging", hairline: { front: 0.5, side: 0.05, back: -0.85 }, coversEars: !0 },
2414
- longWaves: { volume: 0.2, length: 2.5, opening: 84, part: 20, texture: "wavy", textureAmount: 0.14, hairline: { front: 0.45, side: 0.05, back: -0.85 }, coversEars: !0 },
2415
- longCurls: { volume: 0.26, length: 2.5, opening: 84, texture: "curly", textureAmount: 0.13, hairline: { front: 0.45, side: 0.05, back: -0.85 }, coversEars: !0 },
2416
- longLocs: { volume: 0.2, length: 2.6, opening: 84, texture: "locs", textureAmount: 0.12, strands: "hanging", part: 0, hairline: { front: 0.45, side: 0.05, back: -0.85 }, coversEars: !0 },
2417
- lowPonytail: { volume: 0.12, part: 0, strands: "combed", hairline: { front: 0.5, side: 0.1, back: -0.82 }, ties: [{ kind: "ponytail", at: "low", length: 1.5 }] },
2418
- highPonytail: { volume: 0.12, part: 18, strands: "combed", hairline: { front: 0.45, side: 0.1, back: -0.78 }, ties: [{ kind: "ponytail", at: "high", length: 2 }] },
2419
- ponytail: { volume: 0.12, sweep: 0.2, hairline: { front: 0.42, side: 0.1, back: -0.78 }, ties: [{ kind: "ponytail", at: "high", length: 1.8 }] },
2420
- sidePonytail: { volume: 0.12, part: -20, strands: "combed", hairline: { front: 0.45, side: 0.1, back: -0.82 }, ties: [{ kind: "ponytail", at: "left", length: 1.5 }] },
2421
- topBun: { volume: 0.12, part: 0, strands: "combed", hairline: { front: 0.5, side: 0.1, back: -0.8 }, ties: [{ kind: "bun", at: "top", size: 0.32 }] },
2422
- lowBun: { volume: 0.12, part: 0, strands: "combed", hairline: { front: 0.5, side: 0.1, back: -0.8 }, ties: [{ kind: "bun", at: "low", size: 0.34 }] },
2423
- singleBraid: { volume: 0.12, part: 0, strands: "combed", hairline: { front: 0.5, side: 0.1, back: -0.82 }, ties: [{ kind: "braid", at: "low", length: 2.2 }] },
2424
- twinBraids: { volume: 0.12, part: 0, strands: "part", hairline: { front: 0.5, side: 0.05, back: -0.82 }, ties: [{ kind: "braid", at: "left", length: 1.9 }, { kind: "braid", at: "right", length: 1.9 }], coversEars: !0 },
2425
- braids: { volume: 0.12, part: 0, strands: "part", hairline: { front: 0.5, side: 0.05, back: -0.82 }, ties: [{ kind: "braid", at: "left", length: 1.6 }, { kind: "braid", at: "right", length: 1.6 }], coversEars: !0 }
2426
- }, ja = {
2427
- black: "#22201f",
2428
- brown: "#6b4630",
2429
- chestnut: "#7b4a2b",
2430
- auburn: "#9a4426",
2431
- blond: "#d9b55a",
2432
- ginger: "#c8662f",
2433
- gray: "#a7a29c",
2434
- white: "#ecebe7"
2435
- };
2436
- function Wi(t) {
2437
- const e = typeof t == "string" ? { style: t } : t, n = e.style ? Ti[e.style] : {};
2438
- if (e.style && !n) throw new Error(`hair: unknown style '${e.style}'`);
2439
- const { style: o, hairline: s, ...r } = e, i = {
2440
- ...eo,
2441
- ...n,
2442
- ...r,
2443
- hairline: { ...eo.hairline, ...n.hairline, ...s },
2444
- ties: (r.ties ?? n.ties ?? []).map((a) => ({ ...a })),
2445
- ...r.spikes ?? n.spikes ? { spikes: (r.spikes ?? n.spikes).map((a) => ({ ...a })) } : {},
2446
- ...r.locks ?? n.locks ? { locks: (r.locks ?? n.locks).map(Pi) } : {},
2447
- ...r.fall ?? n.fall ? { fall: { ...r.fall ?? n.fall } } : {}
2448
- };
2449
- if (i.shine !== void 0 && (!Number.isFinite(i.shine) || i.shine < 0 || i.shine > 1)) throw new Error("hair: shine must be between 0 and 1");
2450
- if (i.fall && (!Number.isFinite(i.fall.taper) || i.fall.taper < 0 || i.fall.taper > 1 || !Number.isFinite(i.fall.wave) || i.fall.wave < 0))
2451
- throw new Error("hair: fall needs taper between 0 and 1 and nonnegative wave");
2452
- return i;
2453
- }
2454
- const Ut = (t) => t * Math.PI / 180, ee = (t, e, n) => {
2455
- const o = Math.min(1, Math.max(0, (n - t) / (e - t)));
2456
- return o * o * (3 - 2 * o);
2457
- }, dn = (t) => 1 - Math.abs(2 * (t - Math.floor(t)) - 1);
2458
- function Le(t, e) {
2459
- const { front: n, side: o, back: s } = t.hairline, r = (n - s) / 2, i = (n + s) / 2, a = (i + o) / 2, l = (i - o) / 2, c = Math.max(0, Math.cos(e));
2460
- let h = a + r * Math.cos(e) + l * Math.cos(2 * e);
2461
- return h -= t.sweep * Math.sin(e) * c, h += t.recede * Math.exp(-(((Math.abs(e) - 0.75) / 0.32) ** 2)), (t.texture === "spiky" || t.texture === "curly") && (h -= t.textureAmount * 0.6 * dn(e * 11 / (Math.PI * 2)) * c), h;
2462
- }
2463
- function oo(t, e, n) {
2464
- const o = t.textureAmount;
2465
- switch (t.texture) {
2466
- case "spiky":
2467
- return o * (dn(e * 11 / (Math.PI * 2)) * dn(n * 2.6 + 0.5)) ** 1.2 * ee(-0.3, 0.4, n);
2468
- case "curly":
2469
- return o * Math.sqrt(Math.abs(Math.sin(e * 7)) * Math.abs(Math.sin(n * Math.PI * 2.6)));
2470
- case "wavy":
2471
- return o * (0.5 + 0.5 * Math.sin(e * 6 + n * 6));
2472
- case "locs":
2473
- return o * Math.abs(Math.sin(e * 10)) ** 0.6;
2474
- default:
2475
- return 0;
2476
- }
2477
- }
2478
- function Qo(t, e, n = ue) {
2479
- const o = t.length > 0, s = /* @__PURE__ */ new Map(), r = (h) => {
2480
- let f = s.get(h);
2481
- return f === void 0 && s.set(h, f = Le(t, h)), f;
2482
- }, i = Ut(t.opening), a = (h) => t.length + (t.texture === "wavy" || t.texture === "curly" || t.texture === "locs" ? 0.12 * Math.sin(h * 9) : 0) + (t.fall?.wave ?? 0) * Math.cos(h * 3 + 0.6), l = (h, f, y) => {
2483
- if (t.flat <= 0 || f < 0.45) return null;
2484
- const u = (f - 0.45) / 0.55, g = Math.sqrt(1 - 0.45 * 0.45) * y * (1 - u ** 5), m = 0.45 + (1 + t.flat - 0.45) * Math.min(1, u * 1.8);
2485
- return [g * Math.sin(h), m * (1 + e), g * Math.cos(h)];
2486
- }, c = {
2487
- top: 1,
2488
- bottom: o ? -(t.length + 0.25 + Math.abs(t.fall?.wave ?? 0)) : -1,
2489
- inside(h, f) {
2490
- const y = f - r(h);
2491
- if (!o) return y;
2492
- const u = Math.min(f + a(h), _e(h, 0) - i);
2493
- return Math.max(y, u);
2494
- },
2495
- position(h, f) {
2496
- if (o && f < 0) {
2497
- const M = t.length < 1.5 ? 0.14 * ee(-t.length + 0.45, -t.length - 0.1, f) : 0, v = (t.fall?.taper ?? 0) * ee(0, -Math.max(0.1, a(h)), f), P = 1 + e + t.volume * (1 - M * 2.5) + oo(t, h, f) - M - v;
2498
- return [P * Math.sin(h), f, P * Math.cos(h)];
2499
- }
2500
- const y = 0.4 + 0.6 * ee(0, 0.3, f - Le(t, h)), u = 1 + e + (t.volume + oo(t, h, f)) * y, g = l(h, f, u);
2501
- if (g) return g;
2502
- const [m, d, b] = Ot(h, f), x = [m * u, d * u, b * u];
2503
- if (t.quiff > 0) {
2504
- const M = t.quiff * Math.exp(-((h / 0.7) ** 2)) * ee(0.15, 0.85, f);
2505
- x[1] += M * 0.7, x[2] += M * 0.45;
2506
- }
2507
- return x;
2508
- },
2509
- normal(h, f) {
2510
- return o && f < 0 ? [Math.sin(h), 0, Math.cos(h)] : Ot(h, f);
2511
- }
2512
- };
2513
- return o && !Zo(n) ? Hi(c, t, n) : c;
2514
- }
2515
- function Hi(t, e, n) {
2516
- const o = (r) => r < 0 ? ee(-0.15, -Math.max(0.7, e.length), r) : 0, s = (r) => Ut(n.swing) * o(r);
2517
- return {
2518
- top: t.top,
2519
- bottom: t.bottom,
2520
- inside: (r, i) => t.inside(r + s(i), i),
2521
- position(r, i) {
2522
- const a = o(i);
2523
- if (a === 0) return t.position(r, i);
2524
- const l = s(i), [c, h, f] = un(t.position(r + l, i), l);
2525
- return [c, h + n.lift * a, f - n.trail * a];
2526
- },
2527
- normal: (r, i) => un(t.normal(r + s(i), i), s(i))
2528
- };
2529
- }
2530
- const $i = (t) => t.texture === "spiky" || t.texture === "curly" || t.texture === "locs" ? 104 : t.texture === "wavy" ? 80 : 64;
2531
- function jo(t, e, n, o) {
2532
- return vn(t, Fi(e, o), () => Be(t, n, $i(e)));
2533
- }
2534
- const so = /* @__PURE__ */ new WeakMap();
2535
- let _i = 1;
2536
- function Fi(t, e) {
2537
- if (Zo(e)) return t;
2538
- let n = so.get(t);
2539
- return n || so.set(t, n = _i++), `${n}:${e.swing}:${e.trail}:${e.lift}`;
2540
- }
2541
- function ts(t) {
2542
- switch (t) {
2543
- case "top":
2544
- return { point: [0, 1.02, -0.12], out: [0, 1, -0.15] };
2545
- case "high":
2546
- return { point: [0, 0.72, -0.78], out: [0, 0.55, -0.85] };
2547
- case "low":
2548
- return { point: [0, -0.2, -1.02], out: [0, -0.1, -1] };
2549
- case "left":
2550
- return { point: [0.82, -0.32, -0.45], out: [0.8, -0.2, -0.5] };
2551
- case "right":
2552
- return { point: [-0.82, -0.32, -0.45], out: [-0.8, -0.2, -0.5] };
2553
- }
2554
- }
2555
- function Ze(t, [e, n, o]) {
2556
- const s = it(t, [e, n, o]);
2557
- return { x: s.x - t.center.x, y: s.y - t.center.y };
2558
- }
2559
- function Li(t, e, n, o = 16) {
2560
- return Array.from({ length: o + 1 }, (s, r) => {
2561
- const i = r / o, a = 1 - i;
2562
- return { x: a * a * t.x + 2 * a * i * e.x + i * i * n.x, y: a * a * t.y + 2 * a * i * e.y + i * i * n.y };
2563
- });
2564
- }
2565
- function Ci(t, e, n, o, s) {
2566
- const r = t.ry, i = (e.length ?? 1.8) * r, a = Ze(t, un(o, Ut(s.swing))), l = Ze(t, [0, s.lift, -s.trail]), c = Math.hypot(a.x, a.y) || 1, h = e.at === "high" || e.at === "low" || e.at === "top" ? Ze(t, [0.95, 0, 0]) : { x: 0 }, f = e.kind === "braid" ? 0.15 : 0.5, y = {
2567
- x: n.x + a.x / c * r * f + h.x * 0.9 + l.x * 0.5,
2568
- y: n.y + a.y / c * r * f * 0.6 + l.y * 0.5
2569
- }, u = { x: n.x + a.x / c * r * f * 0.6 + h.x * 1.3 + l.x, y: n.y + i + l.y };
2570
- return Li(n, y, u);
2571
- }
2572
- const Ne = (t) => Math.max(1, t * 0.5), es = (t, e) => Math.max(0.8, Math.min(t * 0.4, 0.1 * e.rx));
2573
- function ns(t, e, n, o, s, r) {
2574
- const { point: i, out: a } = ts(o.at), l = 1 + n.volume, c = it(e, [i[0] * l, i[1] * l, i[2] * l]), h = Ne(s), f = es(s, e);
2575
- if (o.kind === "bun") {
2576
- const m = o.size ?? 0.32, d = it(e, [i[0] * l + a[0] * m, i[1] * l + a[1] * m, i[2] * l + a[2] * m]);
2577
- t.ellipse(d.x, d.y, m * e.rx, m * e.ry, e.angle, n.color, h);
2578
- const b = m * e.rx * 0.55;
2579
- t.line(
2580
- Array.from({ length: 9 }, (x, M) => {
2581
- const v = -0.4 + M / 8 * Math.PI * 1.3;
2582
- return { x: d.x + Math.cos(v) * b, y: d.y + Math.sin(v) * b * 0.8 };
2583
- }),
2584
- f
2585
- );
2586
- return;
2587
- }
2588
- const y = Ci(e, o, c, a, r), u = (o.size ?? (o.kind === "braid" ? 0.2 : 0.34)) * e.rx * 2;
2589
- if (o.kind === "ponytail")
2590
- t.shape(ut(y, u, u * 0.15), n.color, h), t.line(y.slice(3, y.length - 3), f);
2591
- else {
2592
- const d = y.slice(0, y.length - 3);
2593
- for (let M = 0; M < 7; M++) {
2594
- const v = d[Math.floor(M / 7 * (d.length - 1))], P = d[Math.floor((M + 1) / 7 * (d.length - 1))], C = Math.atan2(P.y - v.y, P.x - v.x), I = Math.hypot(P.x - v.x, P.y - v.y), $ = u * (1 - M / (7 * 2.2)), A = (M % 2 === 0 ? 1 : -1) * 0.35, z = { x: (v.x + P.x) / 2, y: (v.y + P.y) / 2 };
2595
- t.ellipse(z.x, z.y, I * 0.62, $ * 0.5, C + A, n.color, h * 0.8);
2596
- }
2597
- const b = d[d.length - 1], x = y[y.length - 1];
2598
- t.shape(ut([b, x], u * 0.7, u * 0.2), n.color, h * 0.8);
2599
- }
2600
- const g = y[o.kind === "braid" ? y.length - 4 : 2];
2601
- t.ellipse(g.x, g.y, u * 0.32, u * 0.22, e.angle, n.color, h);
2602
- }
2603
- function os(t, e) {
2604
- return pt(t, ts(e.at).out) < -0.2;
2605
- }
2606
- function Ri(t) {
2607
- const e = (s, r, i = 0, a = 14) => Array.from({ length: a + 1 }, (l, c) => {
2608
- const h = c / a;
2609
- return [s[0] + (r[0] - s[0]) * h + i * Math.sin(Math.PI * h), s[1] + (r[1] - s[1]) * h];
2610
- }), n = Ut(t.part ?? 0), o = (s) => Le(t, s) + 0.04;
2611
- switch (t.strands) {
2612
- case "part":
2613
- return [e([n, o(n)], [n, 0.97])];
2614
- case "sweep": {
2615
- const s = Math.sign(t.sweep || -1), r = [0.9, 0.72, 0.55].map((i, a) => {
2616
- const l = n + s * (0.6 + a * 0.35);
2617
- return e([n, i], [l, Math.max(o(l) + 0.05, i - 0.35)], 0.05 * s);
2618
- });
2619
- return [e([n, o(n)], [n, 0.97]), ...r];
2620
- }
2621
- case "combed":
2622
- return [-0.75, -0.35, 0.35, 0.75].map((s) => e([s, o(s) + 0.02], [s * 0.3, 0.86]));
2623
- case "thin":
2624
- return [-0.5, 0.05, 0.6].map((s) => e([s, o(s) + 0.02], [s * 0.5, 0.95], 0.12));
2625
- case "hanging": {
2626
- const s = t.length > 0 ? -t.length + 0.25 : -0.4, r = [-2.6, -2, -1.4, 1.4, 2, 2.6, 3.05].map((i) => e([i, Le(t, i) < 0.9 ? 0.6 : 0.9], [i, s], 0));
2627
- return t.part !== null && r.push(e([n, o(n)], [n, 0.97])), r;
2628
- }
2629
- default:
2630
- return [];
2631
- }
2632
- }
2633
- function Bi(t, e, n, o, s) {
2634
- if (o.fill === "stipple" || o.hairline.front > 1.5) return;
2635
- const r = s.motion ?? ue, i = s.lineWidth * 0.45 / n.rx, { far: a } = jo(n, o, Qo(o, i, r), r);
2636
- En(e, n, () => {
2637
- for (const l of o.ties) os(n, l) && ns(t, n, o, l, s.lineWidth, r);
2638
- ss(t, n, o, s.lineWidth, i, !1);
2639
- for (const l of a) t.shape(l, o.color, Ne(s.lineWidth));
2640
- Jo(t, n, o, i, r, s.lineWidth, !1);
2641
- }, s.headOutline);
2642
- }
2643
- function gn(t, e, n, o) {
2644
- if (n.hairline.front > 1.5) return;
2645
- const s = o.motion ?? ue, r = o.lineWidth * 0.45 / e.rx, i = Qo(n, r, s), a = es(o.lineWidth, e);
2646
- if (n.fill === "stipple") {
2647
- for (let h = 0.97; h > -1; h -= 0.17)
2648
- for (let f = -Math.PI; f < Math.PI; f += 0.27) {
2649
- const y = Math.round(h * 100) % 2 * 0.13;
2650
- if (i.inside(f + y, h) < 0.02) continue;
2651
- const u = Ot(f + y, h);
2652
- if (pt(e, u) < 0.12) continue;
2653
- const g = it(e, u);
2654
- t.dot(g.x, g.y, a * 0.4);
2655
- }
2656
- return;
2657
- }
2658
- const { near: l } = jo(e, n, i, s), c = Ne(o.lineWidth);
2659
- ss(t, e, n, o.lineWidth, r, !0);
2660
- for (const h of l) t.shape(h, n.color, c);
2661
- Jo(t, e, n, r, s, o.lineWidth, !0);
2662
- for (const h of Ri(n)) {
2663
- const f = h.map(([u, g]) => {
2664
- const [m, d, b] = i.position(u, g);
2665
- return [m * 0.985, d * 0.985, b * 0.985];
2666
- }), y = h.map(([u, g]) => i.normal(u, g));
2667
- for (const u of Vo(e, f, y, 0.12)) t.line(u, a);
2668
- }
2669
- for (const h of n.ties) os(e, h) || ns(t, e, n, h, o.lineWidth, s);
2670
- }
2671
- function ss(t, e, n, o, s, r) {
2672
- for (const i of n.spikes ?? []) {
2673
- const a = Ot(Ut(i.around), Math.max(-1, Math.min(1, i.up)));
2674
- if (pt(e, a) >= 0 !== r) continue;
2675
- const l = [Math.cos(Ut(i.around)), 0, -Math.sin(Ut(i.around))], c = [a[1] * l[2], a[2] * l[0] - a[0] * l[2], -a[1] * l[0]], h = 1 + n.volume + s, f = Math.max(0, i.width), y = Math.max(0, i.length), u = [it(e, a.map((g) => g * (h + y)))];
2676
- for (let g = 0; g < 8; g++) {
2677
- const m = g * Math.PI / 4, d = a.map((b, x) => b * h + f * (l[x] * Math.cos(m) + c[x] * Math.sin(m)));
2678
- u.push(it(e, d));
2679
- }
2680
- t.shape(kn(u), n.color, Ne(o));
2681
- }
2682
- }
2683
- const rs = 0.35, Sn = (t) => ({ centre: [t * 0.98, -0.02, -0.08], out: [t, 0, -0.12] });
2684
- function is(t, e, n, o, s) {
2685
- const { centre: r, out: i } = Sn(n), a = pt(e, i), l = Math.max(1, o.lineWidth * 0.55), c = o.skin === "none" ? null : o.skin, h = e.ry * 0.27;
2686
- if (!s) {
2687
- const d = it(e, [r[0] * 1.06, r[1], r[2]]);
2688
- t.ellipse(d.x, d.y, e.rx * 0.17, h, e.angle, c, l);
2689
- return;
2690
- }
2691
- const f = it(e, r), y = e.rx * (0.12 + 0.08 * a);
2692
- t.ellipse(f.x, f.y, y, h, e.angle, c, l);
2693
- const u = Math.cos(e.angle), g = Math.sin(e.angle), m = Array.from({ length: 9 }, (d, b) => {
2694
- const x = -Math.PI * 0.55 + b / 8 * Math.PI * 1.1, M = Math.cos(x) * y * 0.45 * -n, v = Math.sin(x) * h * 0.55;
2695
- return { x: f.x + M * u - v * g, y: f.y + M * g + v * u };
2696
- });
2697
- t.line(m, Math.max(0.8, l * 0.7));
2698
- }
2699
- function Ni(t, e, n, o) {
2700
- En(e, n, () => {
2701
- for (const s of [1, -1]) pt(n, Sn(s).out) < rs && is(t, n, s, o, !1);
2702
- }, o.headOutline);
2703
- }
2704
- function Yi(t, e, n) {
2705
- for (const o of [1, -1]) pt(e, Sn(o).out) >= rs && is(t, e, o, n, !0);
2706
- }
2707
- const zi = {
2708
- cleanShaven: { moustache: "none", beard: "none" },
2709
- stubble: { moustache: "none", beard: "stubble" },
2710
- pencilMoustache: { moustache: "pencil", beard: "none" },
2711
- shortMoustache: { moustache: "short", beard: "none" },
2712
- chevron: { moustache: "chevron", beard: "none" },
2713
- handlebar: { moustache: "handlebar", beard: "none" },
2714
- walrus: { moustache: "walrus", beard: "none" },
2715
- goatee: { moustache: "none", beard: "goatee" },
2716
- vanDyke: { moustache: "chevron", beard: "goatee" },
2717
- circleBeard: { moustache: "short", beard: "circle" },
2718
- shortBoxed: { moustache: "short", beard: "boxed" },
2719
- fullBeard: { moustache: "chevron", beard: "full" },
2720
- longBeard: { moustache: "walrus", beard: "long" },
2721
- roundedBeard: { moustache: "chevron", beard: "rounded" },
2722
- pointedBeard: { moustache: "chevron", beard: "pointed" },
2723
- chinStrap: { moustache: "none", beard: "chinStrap" },
2724
- soulPatch: { moustache: "none", beard: "soulPatch" },
2725
- sideburns: { moustache: "none", beard: "sideburns" },
2726
- muttonChops: { moustache: "none", beard: "muttonChops" },
2727
- moustacheStubble: { moustache: "short", beard: "stubble" }
2728
- };
2729
- function Di(t, e) {
2730
- const n = typeof t == "string" ? { style: t } : t, o = n.style ? zi[n.style] : void 0;
2731
- if (n.style && !o) throw new Error(`facialHair: unknown style '${n.style}'`);
2732
- return {
2733
- color: n.color ?? e ?? "#6b4630",
2734
- moustache: n.moustache ?? o?.moustache ?? "none",
2735
- beard: n.beard ?? o?.beard ?? "none"
2736
- };
2737
- }
2738
- const Lt = (t) => t * Math.PI / 180, Ie = (t, e, n) => {
2739
- const o = Math.min(1, Math.max(0, (n - t) / (e - t)));
2740
- return o * o * (3 - 2 * o);
2741
- }, as = {
2742
- goatee: { top: [-0.55, -0.55], reach: 22, band: 0, length: 0.22, shape: "point", volume: 0.06, aroundMouth: !1 },
2743
- circle: { top: [-0.24, -0.3], reach: 42, band: 0, length: 0.08, shape: "round", volume: 0.06, aroundMouth: !0 },
2744
- boxed: { top: [-0.38, 0.02], reach: 100, band: 0, length: 0.18, shape: "square", volume: 0.08, aroundMouth: !0 },
2745
- full: { top: [-0.36, 0.05], reach: 100, band: 0, length: 0.32, shape: "round", volume: 0.12, aroundMouth: !0 },
2746
- rounded: { top: [-0.36, 0.05], reach: 100, band: 0, length: 0.55, shape: "round", volume: 0.14, aroundMouth: !0 },
2747
- pointed: { top: [-0.36, 0.05], reach: 100, band: 0, length: 0.8, shape: "point", volume: 0.12, aroundMouth: !0 },
2748
- long: { top: [-0.36, 0.05], reach: 100, band: 0, length: 1.4, shape: "round", volume: 0.14, aroundMouth: !0 },
2749
- chinStrap: { top: [-0.68, 0.05], reach: 100, band: 0.18, length: 0, shape: "round", volume: 0.04, aroundMouth: !1 },
2750
- sideburns: { top: [0.08, 0.08], reach: 100, band: 0.42, length: 0, shape: "round", volume: 0.05, aroundMouth: !1 },
2751
- muttonChops: { top: [0.08, 0.08], reach: 100, band: 0.75, length: 0, shape: "round", volume: 0.08, aroundMouth: !1 }
2752
- }, qi = (t, e) => {
2753
- const n = Ie(Lt(48), Lt(100), _e(e, 0));
2754
- return t.top[0] + (t.top[1] - t.top[0]) * n;
2755
- }, Ui = (t) => t === "sideburns" || t === "muttonChops";
2756
- function yn(t, e) {
2757
- const n = as[t];
2758
- if (!n) return null;
2759
- const o = Lt(n.reach), s = (r) => {
2760
- const i = _e(r, 0);
2761
- return n.shape === "point" ? Math.exp(-((i / 0.42) ** 2)) : n.shape === "square" ? 1 - Ie(Lt(45), Lt(85), i) : Math.cos(Math.min(i, Math.PI / 2)) ** 0.7;
2762
- };
2763
- return {
2764
- top: Math.max(n.top[0], n.top[1]) + 0.05,
2765
- bottom: -1,
2766
- inside(r, i) {
2767
- const a = _e(r, 0), l = qi(n, r);
2768
- let c = Math.min(l - i, o - a);
2769
- if (n.band > 0 && (c = Math.min(c, i - (l - n.band))), Ui(t)) {
2770
- const h = t === "muttonChops" ? Lt(70) - Lt(22) * Ie(0.08, -0.6, i) : Lt(72);
2771
- c = Math.min(c, a - h);
2772
- }
2773
- return c;
2774
- },
2775
- position(r, i) {
2776
- const [a, l, c] = Ot(r, i), h = 1 + e + n.volume, f = n.length * s(r) * Ie(-0.45, -1, i);
2777
- return [a * h, l * h - f, c * h + f * 0.25];
2778
- },
2779
- normal: (r, i) => Ot(r, i)
2780
- };
2781
- }
2782
- function Xi(t) {
2783
- const n = (o) => o.map(([s, r]) => ({ x: s, y: -0.24 + r }));
2784
- switch (t) {
2785
- case "short":
2786
- return n([[-0.17, -0.02], [-0.1, 0.04], [0, 0.03], [0.1, 0.04], [0.17, -0.02], [0.08, -0.05], [0, -0.03], [-0.08, -0.05]]);
2787
- case "chevron":
2788
- return n([[-0.28, -0.1], [-0.16, 0.05], [0, 0.07], [0.16, 0.05], [0.28, -0.1], [0.12, -0.08], [0, -0.06], [-0.12, -0.08]]);
2789
- case "walrus":
2790
- return n([[-0.38, -0.2], [-0.3, 0.02], [-0.12, 0.09], [0, 0.07], [0.12, 0.09], [0.3, 0.02], [0.38, -0.2], [0.2, -0.13], [0, -0.11], [-0.2, -0.13]]);
2791
- case "handlebar":
2792
- return n([[-0.24, -0.03], [-0.12, 0.04], [0, 0.03], [0.12, 0.04], [0.24, -0.03], [0.1, -0.05], [0, -0.03], [-0.1, -0.05]]);
2793
- default:
2794
- return null;
2795
- }
2796
- }
2797
- const de = (t) => Math.max(1, t * 0.45);
2798
- function Gi(t, e, n, o) {
2799
- for (let s = 0.1; s > -1; s -= 0.13)
2800
- for (let r = -Math.PI / 1.7; r < Math.PI / 1.7; r += 0.2) {
2801
- const i = Math.round(s * 100) % 2 * 0.1;
2802
- if (n.inside(r + i, s) < 0.02) continue;
2803
- const a = Ot(r + i, s);
2804
- if (pt(e, a) < 0.15) continue;
2805
- const l = it(e, a);
2806
- t.dot(l.x, l.y, o);
2807
- }
2808
- }
2809
- function Ki(t, e, n, o, s) {
2810
- const r = o.beard === "stubble" ? null : yn(o.beard, s.lineWidth * 0.45 / n.rx);
2811
- if (!r) return;
2812
- const { far: i } = vn(n, o, () => Be(n, r));
2813
- En(e, n, () => {
2814
- for (const a of i) t.shape(a, o.color, de(s.lineWidth));
2815
- }, s.headOutline);
2816
- }
2817
- function Vi(t, e, n, o, s) {
2818
- if (n.beard === "none") return;
2819
- const r = o.lineWidth * 0.45 / e.rx;
2820
- if (n.beard === "stubble") {
2821
- Gi(t, e, yn("full", r), Math.max(0.5, o.lineWidth * 0.09));
2822
- return;
2823
- }
2824
- if (n.beard === "soulPatch") {
2825
- const l = [{ x: -0.05, y: -0.55 }, { x: 0.05, y: -0.55 }, { x: 0, y: -0.68 }], { points: c, facing: h } = et(e, l, { x: 0, y: -0.6 }, o.face?.projection);
2826
- h > -0.05 && t.shape(c, n.color, de(o.lineWidth) * 0.7);
2827
- return;
2828
- }
2829
- const i = yn(n.beard, r);
2830
- if (!i) return;
2831
- const { near: a } = vn(e, n, () => Be(e, i));
2832
- for (const l of a) t.shape(l, n.color, de(o.lineWidth));
2833
- if (as[n.beard]?.aroundMouth) {
2834
- const l = 0.27 * Math.max(0.3, s), c = Array.from({ length: 20 }, (y, u) => {
2835
- const g = Math.PI * 2 * u / 20;
2836
- return { x: Math.cos(g) * l, y: -0.42 + Math.sin(g) * 0.13 };
2837
- }), { points: h, facing: f } = et(e, c, { x: 0, y: -0.42 }, o.face?.projection);
2838
- f > -0.05 && t.shape(h, o.skin === "none" ? "#ffffff" : o.skin, 0);
2839
- }
2840
- }
2841
- function Ji(t, e, n, o) {
2842
- if (n.moustache === "none") return;
2843
- const s = { x: 0, y: -0.24 };
2844
- if (n.moustache === "pencil") {
2845
- const l = [-0.2, -0.1, 0, 0.1, 0.2].map((f) => ({ x: f, y: -0.25 + 0.03 * Math.cos(f / 0.2 * Math.PI) })), { points: c, facing: h } = et(e, l, s, o.face?.projection);
2846
- h > -0.05 && t.line(c, Math.max(1, o.lineWidth * 0.32));
2847
- return;
2848
- }
2849
- const r = Xi(n.moustache);
2850
- if (!r) return;
2851
- const { points: i, facing: a } = et(e, r, s, o.face?.projection);
2852
- if (!(a <= -0.05) && (t.shape(i, n.color, de(o.lineWidth) * 0.8), n.moustache === "handlebar"))
2853
- for (const l of [1, -1]) {
2854
- const c = Array.from({ length: 10 }, (h, f) => {
2855
- const y = -Math.PI / 2 + f / 9 * Math.PI * 1.4;
2856
- return { x: l * (0.27 + 0.05 * Math.cos(y)), y: -0.21 + 0.05 * (1 + Math.sin(y)) };
2857
- });
2858
- c.unshift({ x: l * 0.22, y: -0.27 }), t.line(et(e, c, s, o.face?.projection).points, de(o.lineWidth) * 0.8);
2859
- }
2860
- }
2861
- const Zi = { round: !0, square: !0, sunglasses: !0 };
2862
- function Qi(t) {
2863
- const n = (typeof t == "string" ? { style: t } : t).style ?? "round";
2864
- if (!(n in Zi)) throw new Error(`glasses: unknown style '${n}'`);
2865
- return { style: n };
2866
- }
2867
- const ro = 0.34, At = 0.12, ji = 0.05;
2868
- function ta(t, e) {
2869
- return Array.from({ length: 28 }, (o, s) => {
2870
- const r = Math.PI * 2 * s / 28;
2871
- if (t === "round") return { x: e + Math.cos(r) * 0.2, y: At + Math.sin(r) * 0.19 };
2872
- const i = Math.cos(r), a = Math.sin(r), l = t === "sunglasses" ? 0.22 : 0.21, c = t === "sunglasses" ? 0.17 : 0.16;
2873
- return { x: e + Math.sign(i) * Math.abs(i) ** 0.45 * l, y: At - 0.01 + Math.sign(a) * Math.abs(a) ** 0.45 * c };
2874
- });
2875
- }
2876
- function ea(t, e, n, o) {
2877
- const s = Math.max(1, Math.min(o.lineWidth * 0.5, 0.11 * e.rx)), r = [];
2878
- for (const i of [1, -1]) {
2879
- const a = ro * i, { points: l, facing: c } = et(e, ta(n.style, a), { x: a, y: At }, o.face?.projection);
2880
- if (c < ji) continue;
2881
- r.push(i), t.shape(l, n.style === "sunglasses" ? "#1f2328" : null, s);
2882
- const h = [i * 0.97, At + 0.02, -0.1];
2883
- if (pt(e, [i, 0, 0]) > 0.15) {
2884
- const f = et(e, [{ x: a + i * 0.21, y: At + 0.02 }], { x: a, y: At }, o.face?.projection).points[0];
2885
- t.line([f, it(e, h)], s * 0.9);
2886
- }
2887
- }
2888
- if (r.length === 2) {
2889
- const i = [
2890
- { x: ro - 0.2, y: At + 0.02 },
2891
- { x: 0, y: At + 0.07 },
2892
- { x: -0.14, y: At + 0.02 }
2893
- ];
2894
- t.line(et(e, i, { x: 0, y: At }, o.face?.projection).points, s);
2895
- }
2896
- }
2897
- const ls = {
2898
- cap: { color: "#d64535", brim: [0.36, 0.16], height: 1, peak: 0.7, detail: "seams" },
2899
- beanie: { color: "#3a6ea5", brim: [0.3, 0.12], height: 1.08, detail: "fold" },
2900
- hardHat: { color: "#f2c230", brim: [0.34, 0.22], height: 1.12, ring: 0.16, detail: "ridge" },
2901
- sunHat: { color: "#e3c98f", brim: [0.36, 0.3], height: 1.02, ring: 0.62, detail: "band" },
2902
- bowler: { color: "#2f2b2a", brim: [0.36, 0.28], height: 1.15, ring: 0.2, detail: "band" }
2903
- };
2904
- function na(t) {
2905
- const e = typeof t == "string" ? { style: t } : t, n = e.style ?? "cap", o = ls[n];
2906
- if (!o) throw new Error(`hat: unknown style '${n}'`);
2907
- return { style: n, color: e.color ?? o.color };
2908
- }
2909
- const Xt = (t, e) => t.brim[1] + (t.brim[0] - t.brim[1]) * (1 + Math.cos(e)) / 2;
2910
- function oa(t, e) {
2911
- return {
2912
- top: 1,
2913
- bottom: Math.min(...t.brim) - 0.05,
2914
- inside: (n, o) => o - Xt(t, n),
2915
- position(n, o) {
2916
- const [s, r, i] = Ot(n, o), a = Xt(t, n), l = o > a ? (r - a) * (t.height - 1) : 0;
2917
- return [s * e, r * e + l, i * e];
2918
- },
2919
- normal: (n, o) => Ot(n, o)
2920
- };
2921
- }
2922
- function sa(t, e, n) {
2923
- const s = (r, i, a) => {
2924
- const l = Xt(e, r) * n - a;
2925
- return [Math.sin(r) * i, l, Math.cos(r) * i];
2926
- };
2927
- if (e.peak) {
2928
- const r = [], i = [];
2929
- for (let a = 0; a <= 24; a++) {
2930
- const l = (-80 + 160 * a / 24) * (Math.PI / 180), c = e.peak * Math.cos(l) ** 0.6;
2931
- r.push(it(t, [Math.sin(l) * (n + c * 0.25), Xt(e, l) * n - 0.07 * Math.cos(l), Math.cos(l) * (n + c)])), i.push(it(t, s(l, n, 0)));
2932
- }
2933
- return [...r, ...i.reverse()];
2934
- }
2935
- return e.ring ? Array.from({ length: 48 }, (r, i) => it(t, s(Math.PI * 2 * i / 48, n + e.ring, 0.07))) : null;
2936
- }
2937
- function ra(t) {
2938
- const e = (o) => Array.from({ length: 13 }, (s, r) => [o, Xt(t, o) + (0.97 - Xt(t, o)) * r / 12]), n = (o) => Array.from({ length: 49 }, (s, r) => {
2939
- const i = -Math.PI + Math.PI * 2 * r / 48;
2940
- return [i, Xt(t, i) + o];
2941
- });
2942
- switch (t.detail) {
2943
- case "seams":
2944
- return [e(0.55), e(-0.55)];
2945
- case "fold":
2946
- return [n(0.2)];
2947
- case "ridge":
2948
- return [e(0), e(Math.PI)];
2949
- case "band":
2950
- return [n(0.12)];
2951
- }
2952
- }
2953
- function hs(t, e, n, o) {
2954
- const s = ls[n.style], i = 1 + o.lineWidth * 0.45 / e.rx + Math.max(0.05, Math.min(0.3, o.hairVolume) + 0.04), a = Math.max(1, o.lineWidth * 0.5), l = sa(e, s, i);
2955
- l && t.shape(l, n.color, a);
2956
- const c = oa(s, i), { near: h, far: f } = Be(e, c);
2957
- for (const u of [...f, ...h]) t.shape(u, n.color, a);
2958
- const y = Math.max(0.8, a * 0.7);
2959
- for (const u of ra(s)) {
2960
- const g = u.map(([d, b]) => {
2961
- const [x, M, v] = c.position(d, b);
2962
- return [x * 0.99, M * 0.99, v * 0.99];
2963
- }), m = u.map(([d, b]) => Ot(d, b));
2964
- for (const d of Vo(e, g, m, 0.1)) t.line(d, y);
2965
- }
2966
- if (s.detail === "seams") {
2967
- const u = it(e, [0, i * 1.01, 0]);
2968
- t.dot(u.x, u.y, a * 0.9);
2969
- }
2970
- }
2971
- function ia(t) {
2972
- const e = t.hair ? Wi(t.hair) : null;
2973
- return {
2974
- hair: e,
2975
- facialHair: t.facialHair ? Di(t.facialHair, e?.color) : null,
2976
- glasses: t.glasses ? Qi(t.glasses) : null,
2977
- hat: t.hat ? na(t.hat) : null,
2978
- ears: t.ears ?? !1
2979
- };
2980
- }
2981
- const cs = (t) => !t.hair && !t.facialHair && !t.glasses && !t.hat && !t.ears, fs = (t) => t.axes[2][2] < -0.3, us = (t) => t.ears && !t.hair?.coversEars;
2982
- function ds(t, e, n, o, s, r) {
2983
- if (cs(n)) return;
2984
- const i = { ...r, headOutline: r.face && (r.face.shape === "angular" || r.face.projection === "volume") ? Xo(o, r.face) : void 0 };
2985
- n.hair && Bi(e, t, o, n.hair, { ...i, motion: Fe(s) }), n.facialHair && Ki(e, t, o, n.facialHair, i), us(n) && Ni(e, t, o, i);
2986
- }
2987
- function aa(t, e, n, o, s, r, i) {
2988
- if (cs(n)) {
2989
- i();
2990
- return;
2991
- }
2992
- const a = fs(o);
2993
- us(n) && Yi(e, o, r), n.hair && !a && !r.faceUnderHair && gn(e, o, n.hair, { ...r, motion: Fe(s) }), n.facialHair && Vi(e, o, n.facialHair, r, s.mouthWidth ?? 1), i(), n.hair && !a && r.faceUnderHair && gn(e, o, n.hair, { ...r, motion: Fe(s) }), n.facialHair && Ji(e, o, n.facialHair, r), n.glasses && ea(e, o, n.glasses, r), n.hat && !a && hs(e, o, n.hat, { lineWidth: r.lineWidth, hairVolume: n.hair?.volume ?? 0 });
2994
- }
2995
- function gs(t, e, n, o, s, r) {
2996
- fs(o) && (n.hair && gn(e, o, n.hair, { ...r, motion: Fe(s) }), n.hat && hs(e, o, n.hat, { lineWidth: r.lineWidth, hairVolume: n.hair?.volume ?? 0 }));
2997
- }
2998
- const io = 40, la = 0.215 + 0.205, Mt = (t, e) => {
2999
- const n = {};
3000
- for (const o of ["left", "right"]) for (const [s, r] of Object.entries(e)) n[`${t}.${o}.${s}`] = r;
3001
- return n;
3002
- }, G = (t, e) => t[e] ?? at[e] ?? 0;
3003
- function ha(t, e, n = at, o = 1) {
3004
- const s = Ce(t), r = e * Math.PI * 2, i = Math.sin(r) * o, a = Math.cos(r) * o, l = (1 + Math.cos(r * 2 * (s.bounces ?? 1))) / 2, c = s.crouch ?? 0, h = s.shoulder ?? 0, f = s.forearm ?? 0, y = { ...at, ...n };
3005
- y["leg.left.swing"] = s.swing * i + c * 0.6, y["leg.right.swing"] = -s.swing * i + c * 0.6, y["leg.left.knee"] = s.knee * Math.max(0, a) + c * 1.2, y["leg.right.knee"] = s.knee * Math.max(0, -a) + c * 1.2, y["leg.left.ankle"] = G(n, "leg.left.ankle") - (s.tiptoe ?? 0), y["leg.right.ankle"] = G(n, "leg.right.ankle") - (s.tiptoe ?? 0);
3006
- for (const [u, g] of [["left", -1], ["right", 1]])
3007
- G(n, `arm.${u}.spread`) > io || G(n, `arm.${u}.swing`) > io || (y[`arm.${u}.swing`] = h + g * s.arm * i, y[`arm.${u}.elbow`] = G(n, `arm.${u}.elbow`) + f + s.elbow * Math.max(0, g * i));
3008
- return y.lean = G(n, "lean") + s.lean * o, y.bend = G(n, "bend") + (s.bend ?? 0), y["head.nod"] = G(n, "head.nod") - s.lean * 0.5 * o + (s.headTilt ?? 0), y.side = G(n, "side") + (s.sway ?? 0) * Math.sin(r), y.lift = G(n, "lift") + (s.bounce ?? 0) * o * l, y.stretch = G(n, "stretch") * (1 + (s.squash ?? 0) * (l - 0.5)), y;
3009
- }
3010
- function t0(t, e, n = 1, o = 1) {
3011
- const s = Ce(t);
3012
- return 4 * la * o * e * Math.sin(s.swing * n * Math.PI / 180);
3013
- }
3014
- const Vt = (t) => ni[t], ca = {
3015
- /** Squash down in a squint, shoot up stretched with arms flung up, hang, land squashed, end surprised. */
3016
- take: (t) => [
3017
- { after: 140, pose: { stretch: 0.8, bend: 10, lean: G(t, "lean") - 4, ...Mt("arm", { spread: 6, swing: 0, elbow: 10 }), "eye.left": 0.35, "eye.right": 0.35, "brow.left": -0.6, "brow.right": -0.6, mouth: 0 }, easing: "ease-in-out" },
3018
- { after: 260, pose: { stretch: 0.78 } },
3019
- { after: 360, pose: { lift: 0.22, stretch: 1.35, bend: -14, ...Mt("arm", { spread: 150, bend: 35, swing: 0, elbow: 0 }), ...Mt("leg", { swing: 25, knee: 60 }), ...Vt("shocked") }, easing: "ease-out-cubic" },
3020
- { after: 720, pose: { lift: 0.25, stretch: 1.25, bend: -10, ...Mt("arm", { spread: 140 }) }, easing: "ease-in-out" },
3021
- { after: 900, pose: { lift: 0, stretch: 0.74, bend: 12, ...Mt("arm", { spread: 70, bend: 0 }), ...Mt("leg", { swing: 30, knee: 60 }) }, easing: "ease-in-quad" },
3022
- {
3023
- after: 1060,
3024
- pose: {
3025
- stretch: 1.06,
3026
- bend: -3,
3027
- ...Mt("arm", { spread: 60 }),
3028
- "leg.left.swing": G(t, "leg.left.swing"),
3029
- "leg.right.swing": G(t, "leg.right.swing"),
3030
- "leg.left.knee": G(t, "leg.left.knee"),
3031
- "leg.right.knee": G(t, "leg.right.knee")
3032
- },
3033
- easing: "ease-out"
3034
- },
3035
- { after: 1260, pose: { stretch: G(t, "stretch"), bend: G(t, "bend"), ...Vt("surprised"), ...Mt("arm", { spread: 55, bend: 60 }) }, easing: "ease-in-out" }
3036
- ],
3037
- /** Glance ahead, look away unbothered, then snap back in shock with a little hop. */
3038
- doubleTake: (t) => [
3039
- { after: 160, pose: { lookX: 1, lookY: 0, "head.turn": 0 }, easing: "ease-out" },
3040
- { after: 520, pose: { lookX: -0.6, "head.turn": 30, "head.nod": G(t, "head.nod") - 4, smile: 0.6, mouth: 0 }, easing: "ease-in-out" },
3041
- { after: 1100, pose: { lookX: -0.6 } },
3042
- { after: 1180, pose: { "head.turn": 0, "head.nod": G(t, "head.nod") - 10, bend: G(t, "bend") - 10, lift: 0.05, stretch: 1.18, ...Vt("shocked"), lookX: 1, lookY: 0 }, easing: "ease-out-cubic" },
3043
- { after: 1360, pose: { lift: 0, stretch: 0.88, "head.nod": G(t, "head.nod") - 4, bend: G(t, "bend") + 4 }, easing: "ease-in-quad" },
3044
- { after: 1560, pose: { stretch: G(t, "stretch"), "head.nod": G(t, "head.nod"), bend: G(t, "bend") }, easing: { type: "elastic", mode: "out", amplitude: 1, period: 0.35 } }
3045
- ],
3046
- /** Rear back for a zip-off: lean back, a knee up, arms cocked; hold; pitch forward ready to run. */
3047
- windUp: () => [
3048
- {
3049
- after: 220,
3050
- pose: {
3051
- lean: -18,
3052
- bend: -16,
3053
- "head.nod": -6,
3054
- "arm.left.swing": 60,
3055
- "arm.left.elbow": 100,
3056
- "arm.right.swing": -40,
3057
- "arm.right.elbow": 90,
3058
- "leg.left.swing": 55,
3059
- "leg.left.knee": 95,
3060
- stretch: 0.92,
3061
- ...Vt("angry"),
3062
- lookX: 1
3063
- },
3064
- easing: "ease-out"
3065
- },
3066
- { after: 620, pose: { lean: -20, bend: -18, stretch: 0.9 } },
3067
- { after: 700, pose: { lean: 28, bend: 14, "head.nod": 6, "arm.left.swing": -30, "arm.right.swing": 60, "leg.left.swing": -20, "leg.left.knee": 30, "leg.right.swing": 20, stretch: 1.12 }, easing: "ease-out-cubic" }
3068
- ],
3069
- /** Coming down: stretched in the fall, squashed on contact, a spring back up. */
3070
- land: (t) => [
3071
- { after: 120, pose: { lift: 0, stretch: 0.7, bend: 14, ...Mt("arm", { spread: 75 }), ...Mt("leg", { swing: 25, knee: 50 }) }, easing: "ease-in-quad" },
3072
- { after: 300, pose: { stretch: 1.05, bend: -4, "arm.left.spread": G(t, "arm.left.spread"), "arm.right.spread": G(t, "arm.right.spread") }, easing: "ease-out" },
3073
- { after: 460, pose: { lift: 0, stretch: G(t, "stretch"), bend: G(t, "bend"), ...Mt("leg", { swing: 0, knee: 0 }) }, easing: "ease-in-out" }
3074
- ],
3075
- /** A frightened shiver: paws up, fast small shakes side to side, then still. */
3076
- tremble: (t) => {
3077
- const e = [{ after: 80, pose: { ...Vt("scared"), ...Mt("arm", { swing: 40, elbow: 110, spread: 14 }), stretch: 0.94, bend: G(t, "bend") + 8 }, easing: "ease-out" }];
3078
- for (let n = 1; n <= 14; n++) {
3079
- const o = n % 2 === 0 ? 1 : -1;
3080
- e.push({ after: 80 + n * 45, pose: { side: G(t, "side") + 2.5 * o, "head.tilt": G(t, "head.tilt") - 2 * o } });
3081
- }
3082
- return e.push({ after: 755, pose: { side: G(t, "side"), "head.tilt": G(t, "head.tilt"), bend: G(t, "bend") } }), e;
3083
- },
3084
- /** A sigh: the body sags, the back curls, the head and arms drop. */
3085
- deflate: (t) => [
3086
- { after: 260, pose: { stretch: 1.04, "head.nod": G(t, "head.nod") - 4, "brow.left": 0.3, "brow.right": 0.3 }, easing: "ease-in-out" },
3087
- { after: 900, pose: { ...Vt("sad"), bend: 18, stretch: 0.92, lean: G(t, "lean") + 5, "head.nod": 14, ...Mt("arm", { spread: 6, swing: 0, elbow: 4, bend: 0 }) }, easing: "ease-in-out" }
3088
- ]
3089
- };
3090
- function e0(t, e) {
3091
- const n = tt(e.from ?? {}), o = e.speed ?? 1;
3092
- let s = n;
3093
- return [
3094
- { time: e.at, pose: n },
3095
- ...ca[t](n).map((r) => (s = { ...s, ...r.pose }, { time: e.at + r.after * o, pose: s, act: !1, ...r.easing ? { easing: r.easing } : {} }))
3096
- ];
3097
- }
3098
- function fa(t, e = at) {
3099
- const n = t * Math.PI * 2, o = Math.sin(n);
3100
- return {
3101
- ...e,
3102
- lean: (e.lean ?? 0) + 14,
3103
- bend: (e.bend ?? 0) + 8,
3104
- side: 5 * o,
3105
- "head.nod": 22,
3106
- "arm.right.swing": 38 + 22 * o,
3107
- "arm.right.spread": 6,
3108
- "arm.right.elbow": 20 + 10 * Math.max(0, -o),
3109
- "arm.right.bend": -10,
3110
- "arm.left.swing": 52 + 22 * o,
3111
- "arm.left.spread": 14,
3112
- "arm.left.elbow": 35 + 10 * Math.max(0, o),
3113
- "arm.left.bend": -20,
3114
- "leg.left.swing": 10,
3115
- "leg.right.swing": -10,
3116
- "leg.left.knee": 8,
3117
- "leg.right.knee": 4,
3118
- "leg.left.spread": 8,
3119
- "leg.right.spread": 8
3120
- };
3121
- }
3122
- function ua(t, e = at) {
3123
- const n = t * Math.PI * 2, o = Math.sin(n), s = Math.cos(n);
3124
- return {
3125
- ...e,
3126
- lean: (e.lean ?? 0) + 4,
3127
- side: 2 * o,
3128
- "head.nod": 6,
3129
- "arm.right.swing": 62,
3130
- "arm.right.spread": 18 + 16 * o,
3131
- "arm.right.elbow": 48 - 18 * Math.abs(o),
3132
- "arm.right.bend": -30 + 8 * s,
3133
- "arm.left.swing": 12,
3134
- "arm.left.spread": 14,
3135
- "arm.left.elbow": 12,
3136
- "leg.left.spread": 6,
3137
- "leg.right.spread": 6
3138
- };
3139
- }
3140
- const ao = { sweeping: fa, brushing: ua };
3141
- function n0(t, e, n = at) {
3142
- const o = ao[t];
3143
- if (!o) throw new Error(`humanCyclePose: ${Es("cycle", t, Object.keys(ao))}`);
3144
- return o(e, n);
3145
- }
3146
- function ys(t) {
3147
- const e = t.top ?? !0, n = t.length ?? 0.32, o = t.color ?? "#638c39", s = t.accent ?? "#87ae4e";
3148
- if (typeof e != "boolean") throw new Error("leafOutfit: top must be a boolean");
3149
- if (!Number.isFinite(n) || n < 0.2 || n > 0.45) throw new Error("leafOutfit: length must be 0.2..0.45");
3150
- if (typeof o != "string" || typeof s != "string") throw new Error("leafOutfit: color and accent must be strings");
3151
- return { top: e, length: n, color: o, accent: s };
3152
- }
3153
- function lo(t, e) {
3154
- const n = t.flatMap((s) => Array.from({ length: 8 }, (r, i) => ({
3155
- x: s.x + Math.cos(i * Math.PI / 4) * e,
3156
- y: s.y + Math.sin(i * Math.PI / 4) * e
3157
- })));
3158
- let o = kn(n);
3159
- for (let s = 0; s < 2; s++) o = o.flatMap((r, i) => {
3160
- const a = o[(i + 1) % o.length];
3161
- return [{ x: r.x * 0.75 + a.x * 0.25, y: r.y * 0.75 + a.y * 0.25 }, { x: r.x * 0.25 + a.x * 0.75, y: r.y * 0.25 + a.y * 0.75 }];
3162
- });
3163
- return o;
3164
- }
3165
- const ho = (t) => t.flatMap((e) => [e.left, e.right]);
3166
- function ms(t, e = {}) {
3167
- const { top: n, length: o } = ys(e), s = t.bodyContours;
3168
- if (!s?.spine) throw new Error("leafOutfit requires organic body contours");
3169
- const r = s.spine.samples.filter((a) => a.at <= 0.3), i = ["left", "right"].flatMap((a) => s[`leg.${a}`]?.samples.filter((l) => l.at <= o) ?? []);
3170
- return {
3171
- ...n ? { top: lo(ho(s.spine.samples.filter((a) => a.at >= 0.52 && a.at <= 0.91)), t.height * 0.01) } : {},
3172
- skirt: lo(ho([...r, ...i]), t.height * 0.012)
3173
- };
3174
- }
3175
- function da(t, e) {
3176
- t.beginPath(), t.moveTo(e[0].x, e[0].y);
3177
- for (const n of e.slice(1)) t.lineTo(n.x, n.y);
3178
- t.closePath();
3179
- }
3180
- function ga(t, e, n) {
3181
- const o = e.x - t.x, s = e.y - t.y, r = Math.hypot(o, s) || 1, i = -s / r, a = o / r, l = [];
3182
- for (const c of [1, -1]) for (let h = 0; h <= 16; h++) {
3183
- const f = c === 1 ? h / 16 : 1 - h / 16, u = 3 * (1 - f) * f * n * c;
3184
- l.push({ x: t.x + o * f + i * u, y: t.y + s * f + a * u });
3185
- }
3186
- return l;
3187
- }
3188
- function co(t, e, n, o, s, r) {
3189
- const i = e.lineWidth * 0.7;
3190
- if (n.shape(o, s, i), n.look === "silhouette") return;
3191
- t.save(), da(t, o), t.clip();
3192
- const a = Math.min(...o.map((u) => u.x)), l = Math.max(...o.map((u) => u.x)), c = Math.min(...o.map((u) => u.y)), h = Math.max(...o.map((u) => u.y)), f = l - a, y = h - c;
3193
- for (let u = 0; u < 2; u++) for (let g = 0; g < 5; g++) {
3194
- const m = { x: a + f * (g / 4 + (u ? 0.07 : -0.04)), y: c + y * (u ? 0.38 : -0.1) }, d = { x: m.x + f * 0.09, y: m.y + y * 0.78 };
3195
- n.shape(ga(m, d, f * 0.13), (g + u) % 2 ? s : r, i * 0.6), n.line([m, { x: m.x * 0.45 + d.x * 0.55, y: m.y * 0.45 + d.y * 0.55 }, d], i * 0.45);
3196
- for (const b of [0.32, 0.52, 0.7]) {
3197
- const x = { x: m.x + (d.x - m.x) * b, y: m.y + (d.y - m.y) * b };
3198
- n.line([{ x: x.x - f * 0.045, y: x.y - y * 0.065 }, x, { x: x.x + f * 0.045, y: x.y - y * 0.05 }], i * 0.3);
3199
- }
3200
- }
3201
- t.restore();
3202
- }
3203
- function ya(t = {}) {
3204
- const e = ys(t), { color: n, accent: o } = e, s = (r) => (i, a, l) => {
3205
- const c = ms(a, e);
3206
- r === "spine" && c.top && co(i, a, l, c.top, n, o);
3207
- const h = ["spine", "leg.left", "leg.right"].reduce((f, y) => a.parts[f].order > a.parts[y].order ? f : y);
3208
- r === h && co(i, a, l, c.skirt, n, o);
3209
- };
3210
- return { parts: { spine: { over: s("spine") }, "leg.left": { over: s("leg.left") }, "leg.right": { over: s("leg.right") } } };
3211
- }
3212
- const ma = { apron: "#d8b48a", labCoat: "#f4f6f8", hoodie: "#6b7280", cardigan: "#6b8e4e", overalls: "", sari: "#16a34a" }, Qe = (t, e, n) => t.slice(Math.floor((t.length - 1) * e), Math.ceil((t.length - 1) * n) + 1), Z = (t, e, n) => ({ x: t.x + (e.x - t.x) * n, y: t.y + (e.y - t.y) * n });
3213
- function pa(t) {
3214
- return t.parts["leg.left"].order > t.parts["leg.right"].order ? "left" : "right";
3215
- }
3216
- const fo = (t) => Math.max(t.parts["leg.left"].order, t.parts["leg.right"].order) > t.parts.spine.order, mt = (t) => t.bodyForward?.[2] ?? Math.cos(t.turn * Math.PI / 2), Ht = (t) => t.bodyForward?.[0] ?? Math.sin(t.turn * Math.PI / 2);
3217
- function uo(t, e, n) {
3218
- t.save(), t.beginPath(), t.moveTo(e[0].x, e[0].y);
3219
- for (const o of e.slice(1)) t.lineTo(o.x, o.y);
3220
- t.closePath(), t.clip(), n(), t.restore();
3221
- }
3222
- function go(t, e, n = 0) {
3223
- const o = e * (t.length - 1), s = Math.min(t.length - 2, Math.floor(o)), r = t[s], i = t[s + 1], a = Z(r, i, o - s), l = Math.hypot(i.x - r.x, i.y - r.y) || 1;
3224
- return { x: a.x + (i.y - r.y) / l * n, y: a.y - (i.x - r.x) / l * n };
3225
- }
3226
- function ba(t = {}) {
3227
- if (t = { ...t }, t.top !== void 0 && !["tshirt", "shirt", "blouse", "dress"].includes(t.top)) throw new Error(`basicOutfit: unknown top '${t.top}'`);
3228
- if (t.trouserStyle !== void 0 && !["plain", "jeans", "cargo"].includes(t.trouserStyle)) throw new Error(`basicOutfit: unknown trouser style '${t.trouserStyle}'`);
3229
- const e = t.top, n = t.trouserStyle ?? "plain", o = t.collar ?? e === "shirt", s = t.shirt ?? "#e2493b", r = e === "dress" ? s : t.trousers ?? "#24476b", i = t.sleeves ?? "short", a = e === "dress" ? "skirt" : t.bottom ?? "trousers", l = t.over === "labCoat", c = t.over === "hoodie", h = t.over === "cardigan", f = t.over === "overalls", y = t.over === "sari", u = t.overColor ?? (t.over && t.over !== "overalls" ? ma[t.over] : r), g = t.shoes === "boots", m = t.shoeColor ?? "#3b2a1e", d = (p) => p.lineWidth * 0.45, b = (p, k, O, T) => {
3230
- const _ = k.parts[`leg.${T}`].points;
3231
- if (a === "skirt" && !f) return;
3232
- const W = a === "shorts" && !f, F = k.bodyContours?.[`leg.${T}`], B = F ? Ke(F, 0, W ? 0.5 : 1, k.height * 6e-3) : ut(W ? Qe(_, 0, 0.5) : _, k.height * (W ? 0.085 : 0.08), k.height * (W ? 0.07 : 0.05));
3233
- O.shape(B, r, d(k)), !(n === "plain" || mt(k) < 0.15) && uo(p, B, () => {
3234
- const S = (L, Y = 0) => go(_, L, Y * k.height);
3235
- if (n === "jeans")
3236
- O.line([S(0.07, -0.018), S(0.17, -0.02), S(0.23, 0), S(0.17, 0.02), S(0.07, 0.018)], d(k) * 0.65), O.line([S(0.27, 0.013), ...[0.4, 0.55, 0.7, 0.85, 0.96].filter((L) => !W || L < 0.5).map((L) => S(L, 0.013))], d(k) * 0.5);
3237
- else {
3238
- const L = [S(0.25, -0.024), S(0.25, 0.024), S(0.43, 0.024), S(0.43, -0.024)];
3239
- O.shape(L, r, d(k) * 0.65), O.line([S(0.28, -0.024), S(0.32, 0), S(0.28, 0.024)], d(k) * 0.65);
3240
- const Y = S(0.32);
3241
- O.dot(Y.x, Y.y, d(k) * 0.8);
3242
- }
3243
- });
3244
- }, x = (p, k, O) => {
3245
- const T = p.parts[`leg.${O}`].points, _ = Qe(T, 0.7, 1);
3246
- if (_.length < 2) return;
3247
- k.shape(ut(_, p.height * 0.075, p.height * 0.07), m, d(p));
3248
- const W = _[0], F = _[1], B = F.x - W.x, S = F.y - W.y, L = Math.hypot(B, S) || 1, Y = p.height * 0.04;
3249
- k.line([{ x: W.x - S / L * Y, y: W.y + B / L * Y }, { x: W.x + S / L * Y, y: W.y - B / L * Y }], d(p) * 0.9);
3250
- }, M = (p) => {
3251
- const k = p.chains.spine, O = k[0], T = k[k.length - 1], _ = { x: O.x - (T.x - O.x) * 0.25, y: O.y - (T.y - O.y) * 0.25 };
3252
- return { hip: O, top: T, below: _, line: [_, ...p.parts.spine.points] };
3253
- }, v = (p) => {
3254
- if (p.bodyContours?.spine) return Ke(p.bodyContours.spine, 0, 0.97, p.height * (c ? 0.014 : 6e-3));
3255
- const k = c ? 1.14 : 1, O = Math.hypot(p.points["hip.left"].x - p.points["hip.right"].x, p.points["hip.left"].y - p.points["hip.right"].y), T = Math.max(p.height * 0.15 * k, O + Math.max(p.height * 0.08, p.lineWidth * 1.45) + d(p));
3256
- return ut(M(p).line, T, p.height * 0.14 * k);
3257
- }, P = (p, k) => {
3258
- const O = [v(k)], { top: T, hip: _ } = M(k);
3259
- h && O.push(ut([T, Z(T, _, 0.5), Z(T, _, 1.08)], k.height * 0.155, k.height * 0.15)), l && O.push(ut([T, Z(T, _, 0.5), _], k.height * 0.14, k.height * 0.15));
3260
- const W = Object.values(k.points), F = Math.min(...W.map((Y) => Y.x)) - k.height, B = Math.min(...W.map((Y) => Y.y)) - k.height, S = Math.max(...W.map((Y) => Y.x)) + k.height, L = Math.max(...W.map((Y) => Y.y)) + k.height;
3261
- for (const Y of O) {
3262
- p.beginPath(), p.rect(F, B, S - F, L - B), p.moveTo(Y[0].x, Y[0].y);
3263
- for (const V of Y.slice(1)) p.lineTo(V.x, V.y);
3264
- p.closePath(), p.clip("evenodd");
3265
- }
3266
- }, C = (p, k) => {
3267
- const O = c ? u : s;
3268
- k.shape(v(p), O, d(p));
3269
- }, I = (p, k, O) => {
3270
- const T = mt(k);
3271
- if (!e || T < 0.2 || c) return;
3272
- const { top: _, hip: W } = M(k), F = Ht(k) * k.height * 0.025, B = [_, W], S = (L, Y = 0) => go(B, L, F + Y * k.height * T);
3273
- uo(p, v(k), () => {
3274
- if (e === "shirt") {
3275
- O.line([S(0.12), S(0.92)], d(k) * 0.65);
3276
- for (const L of [0.24, 0.4, 0.56, 0.72, 0.88]) {
3277
- const Y = S(L, 8e-3);
3278
- O.dot(Y.x, Y.y, d(k) * 0.9);
3279
- }
3280
- } else if (e === "blouse") {
3281
- O.line([S(0.025, -0.04), S(0.24), S(0.025, 0.04)], d(k) * 0.75);
3282
- const L = S(0.31);
3283
- O.dot(L.x, L.y, d(k));
3284
- } else e === "dress" ? O.line([S(0.04, -0.035), S(0.17, -0.028), S(0.17, 0.028), S(0.04, 0.035)], d(k) * 0.75) : O.line([S(0.025, -0.035), S(0.1, -0.02), S(0.12), S(0.1, 0.02), S(0.025, 0.035)], d(k) * 0.65);
3285
- });
3286
- }, $ = (p, k) => {
3287
- const O = mt(p), { top: T, hip: _ } = M(p), W = p.height * 0.07, F = { x: (T.x - _.x) * 0.16, y: (T.y - _.y) * 0.16 };
3288
- if (O >= 0) {
3289
- k.shape(
3290
- [
3291
- { x: T.x - W, y: T.y + F.y * 0.25 },
3292
- { x: T.x - W * 0.8 + F.x, y: T.y + F.y },
3293
- { x: T.x + F.x * 1.2, y: T.y + F.y * 1.35 },
3294
- { x: T.x + W * 0.8 + F.x, y: T.y + F.y },
3295
- { x: T.x + W, y: T.y + F.y * 0.25 }
3296
- ],
3297
- u,
3298
- d(p)
3299
- );
3300
- return;
3301
- }
3302
- const B = Z(T, _, 0.42);
3303
- k.shape(
3304
- [
3305
- { x: T.x - W * 0.9, y: T.y },
3306
- { x: T.x + W * 0.9, y: T.y },
3307
- { x: B.x + W * 0.7, y: B.y },
3308
- { x: B.x, y: B.y + p.height * 0.02 },
3309
- { x: B.x - W * 0.7, y: B.y }
3310
- ],
3311
- u,
3312
- d(p)
3313
- );
3314
- }, A = (p, k) => {
3315
- const O = mt(p);
3316
- if (O < 0.2) return;
3317
- const { top: T, hip: _ } = M(p), W = Ht(p) * p.height * 0.03, F = p.height * 0.06 * O, B = Z(T, _, 0.62), S = Z(T, _, 0.9);
3318
- k.line([{ x: B.x + W - F, y: B.y }, { x: S.x + W - F * 1.1, y: S.y }], d(p) * 0.7), k.line([{ x: B.x + W + F, y: B.y }, { x: S.x + W + F * 1.1, y: S.y }], d(p) * 0.7);
3319
- const L = Z(T, _, 0.1);
3320
- for (const Y of [-1, 1]) k.line([{ x: L.x + W + Y * F * 0.2, y: L.y }, { x: L.x + W + Y * F * 0.35, y: L.y + p.height * 0.07 }], d(p) * 0.6);
3321
- }, z = (p, k) => {
3322
- const { top: O, hip: T } = M(p), _ = mt(p);
3323
- if (k.shape(ut([O, Z(O, T, 0.5), Z(O, T, 1.08)], p.height * 0.155, p.height * 0.15), u, d(p)), _ < 0.2) return;
3324
- const W = Ht(p) * p.height * 0.03, F = p.height * 0.02 * _, B = Z(O, T, 0.12), S = Z(O, T, 1.05);
3325
- k.shape([{ x: B.x + W - F, y: B.y }, { x: B.x + W + F, y: B.y }, { x: S.x + W + F * 1.3, y: S.y }, { x: S.x + W - F * 1.3, y: S.y }], s, d(p) * 0.7);
3326
- for (const L of [0.35, 0.55, 0.75]) {
3327
- const Y = Z(O, T, L);
3328
- k.dot(Y.x + W + F * 1.6, Y.y, d(p) * 1.2);
3329
- }
3330
- }, R = (p, k) => {
3331
- const O = mt(p), { top: T, hip: _ } = M(p), W = Ht(p) * p.height * 0.04, F = Z(_, T, 0.12), B = Z(_, T, 0.74);
3332
- if (O < 0.15) {
3333
- if (O < -0.3) {
3334
- const V = p.points["shoulder.left"], U = p.points["shoulder.right"];
3335
- k.line([V, { x: F.x + p.height * 0.03, y: F.y }], d(p) * 0.8), k.line([U, { x: F.x - p.height * 0.03, y: F.y }], d(p) * 0.8);
3336
- }
3337
- return;
3338
- }
3339
- const S = p.height * 0.07 * O;
3340
- k.shape(
3341
- [
3342
- { x: B.x + W - S * 0.75, y: B.y },
3343
- { x: B.x + W + S * 0.75, y: B.y },
3344
- { x: F.x + W + S * 1.1, y: F.y },
3345
- { x: F.x + W - S * 1.1, y: F.y }
3346
- ],
3347
- r,
3348
- d(p)
3349
- );
3350
- for (const V of ["left", "right"]) {
3351
- const U = p.points[`shoulder.${V}`], Tt = { x: B.x + W + (U.x > B.x + W ? 1 : -1) * S * 0.55, y: B.y };
3352
- k.line([Tt, { x: U.x + (Tt.x - U.x) * 0.15, y: U.y + (Tt.y - U.y) * 0.15 }], d(p) * 1.6);
3353
- }
3354
- const L = Z(B, F, 0.3), Y = S * 0.4;
3355
- k.line([{ x: L.x + W - Y, y: L.y }, { x: L.x + W - Y, y: L.y + Y * 1.4 }, { x: L.x + W + Y, y: L.y + Y * 1.4 }, { x: L.x + W + Y, y: L.y }], d(p) * 0.6);
3356
- }, w = (p, k) => {
3357
- const { hip: O, top: T } = M(p), _ = Z(O, T, 0.2), W = [p.points["ankle.left"], p.points["ankle.right"]], F = Z(O, { x: (W[0].x + W[1].x) / 2, y: (W[0].y + W[1].y) / 2 }, 0.98), B = p.height * 0.075, S = Math.max(p.height * 0.12, Math.abs(W[0].x - W[1].x) / 2 + p.height * 0.07), L = F.x - _.x, Y = F.y - _.y, V = Math.hypot(L, Y) || 1, U = { x: -Y / V, y: L / V };
3358
- if (k.shape(
3359
- [
3360
- { x: _.x + U.x * B, y: _.y + U.y * B },
3361
- { x: F.x + U.x * S, y: F.y + U.y * S },
3362
- { x: F.x - U.x * S, y: F.y - U.y * S },
3363
- { x: _.x - U.x * B, y: _.y - U.y * B }
3364
- ],
3365
- u,
3366
- d(p)
3367
- ), mt(p) > 0.2) {
3368
- const Bt = Ht(p) * p.height * 0.03;
3369
- for (const se of [-0.35, 0, 0.35]) {
3370
- const me = B * 0.5 * se, pe = S * 0.45 * se;
3371
- k.line([{ x: _.x + Bt + U.x * me, y: _.y + U.y * me + p.height * 0.02 }, { x: F.x + Bt + U.x * pe, y: F.y + U.y * pe }], d(p) * 0.5);
3372
- }
3373
- }
3374
- }, E = (p, k) => {
3375
- const O = mt(p), { top: T, hip: _ } = M(p), W = Ht(p), F = W >= 0 ? "left" : "right", B = F === "left" ? "right" : "left", S = p.points[`shoulder.${F}`], L = p.height * 0.035;
3376
- if (O < 0.15) {
3377
- const U = Z(T, _, 0.9);
3378
- k.shape(ut([S, { x: U.x + (S.x - T.x) * 0.5, y: U.y }], L * 2.2, L * 2.6), u, d(p));
3379
- return;
3380
- }
3381
- const Y = { x: _.x + (p.points[`hip.${B}`].x - _.x) * 1.2, y: Z(_, T, 0.08).y };
3382
- k.shape(ut([Y, Z(Y, S, 0.5), S], L * 2.4, L * 2), u, d(p));
3383
- const V = { x: S.x - (_.x - S.x) * 0.05 - W * p.height * 0.03, y: S.y + p.height * 0.16 };
3384
- k.shape(ut([S, V], L * 2, L * 1.6), u, d(p));
3385
- }, H = (p, k) => {
3386
- if (p.bodyContours) {
3387
- k.shape(ms(p, { top: !1, length: 0.45 }).skirt, r, d(p));
3388
- return;
3389
- }
3390
- const { hip: O, top: T } = M(p), _ = Z(O, T, 0.18), W = [p.points["knee.left"], p.points["knee.right"]], F = Z(O, { x: (W[0].x + W[1].x) / 2, y: (W[0].y + W[1].y) / 2 }, 1.05), B = p.height * 0.075, S = Math.max(p.height * 0.13, Math.abs(W[0].x - W[1].x) / 2 + p.height * 0.08), L = F.x - _.x, Y = F.y - _.y, V = Math.hypot(L, Y) || 1, U = { x: -Y / V, y: L / V };
3391
- k.shape(
3392
- [
3393
- { x: _.x + U.x * B, y: _.y + U.y * B },
3394
- { x: F.x + U.x * S, y: F.y + U.y * S },
3395
- { x: F.x - U.x * S, y: F.y - U.y * S },
3396
- { x: _.x - U.x * B, y: _.y - U.y * B }
3397
- ],
3398
- r,
3399
- d(p)
3400
- );
3401
- }, N = (p, k) => {
3402
- const O = mt(p);
3403
- if (O < 0.2) return;
3404
- const { top: T, hip: _ } = M(p), W = { x: (_.x - T.x) * 0.12, y: (_.y - T.y) * 0.12 }, F = p.height * 0.045 * O;
3405
- for (const B of [-1, 1])
3406
- k.shape(
3407
- [
3408
- { x: T.x + B * F * 0.2, y: T.y + W.y * 0.1 },
3409
- { x: T.x + B * F * 1.3, y: T.y - W.y * 0.1 },
3410
- { x: T.x + B * F * 0.6 + W.x, y: T.y + W.y }
3411
- ],
3412
- s,
3413
- d(p) * 0.8
3414
- );
3415
- }, D = (p, k, O) => {
3416
- const T = mt(p);
3417
- if (T < 0.25) return;
3418
- const { top: _, hip: W } = M(p), F = Ht(p) * p.height * 0.03, B = (V) => ({ x: Z(_, W, V).x + F, y: Z(_, W, V).y }), S = p.height * 0.022 * T, L = B(0.08), Y = B(0.62);
3419
- k.shape([{ x: L.x - S, y: L.y - S }, { x: L.x + S, y: L.y - S }, { x: L.x + S * 0.6, y: L.y + S }, { x: L.x - S * 0.6, y: L.y + S }], O, d(p) * 0.7), k.shape([{ x: L.x - S * 0.6, y: L.y + S }, { x: L.x + S * 0.6, y: L.y + S }, { x: Y.x + S * 1.4, y: Y.y - S * 2 }, Y, { x: Y.x - S * 1.4, y: Y.y - S * 2 }], O, d(p) * 0.7);
3420
- }, X = (p, k) => {
3421
- const O = mt(p), { top: T, hip: _ } = M(p), W = Z(_, T, 0.72), F = [p.points["knee.left"], p.points["knee.right"]], B = Z(_, { x: (F[0].x + F[1].x) / 2, y: (F[0].y + F[1].y) / 2 }, 0.9), S = Ht(p) * p.height * 0.04;
3422
- if (O < 0.15) {
3423
- const V = Z(_, T, 0.2);
3424
- O < -0.3 && k.line([{ x: V.x - p.height * 0.05, y: V.y }, { x: V.x + p.height * 0.05, y: V.y }], d(p));
3425
- return;
3426
- }
3427
- const L = p.height * 0.075 * O, Y = Z(_, T, 0.2);
3428
- k.shape(
3429
- [
3430
- { x: W.x + S - L * 0.7, y: W.y },
3431
- { x: W.x + S + L * 0.7, y: W.y },
3432
- { x: Y.x + S + L, y: Y.y },
3433
- { x: B.x + S + L * 1.15, y: B.y },
3434
- { x: B.x + S - L * 1.15, y: B.y },
3435
- { x: Y.x + S - L, y: Y.y }
3436
- ],
3437
- u,
3438
- d(p)
3439
- ), k.line([{ x: W.x + S - L * 0.6, y: W.y }, { x: T.x - L * 0.2, y: T.y }, { x: W.x + S + L * 0.6, y: W.y }], d(p) * 0.8);
3440
- }, K = (p, k, O) => {
3441
- const { top: T, hip: _ } = M(p), W = [p.points["knee.left"], p.points["knee.right"]], F = Z(_, { x: (W[0].x + W[1].x) / 2, y: (W[0].y + W[1].y) / 2 }, 0.95);
3442
- O ? k.shape(ut([Z(T, _, 0.8), _, F], p.height * 0.145, p.height * 0.17), u, d(p)) : k.shape(ut([T, Z(T, _, 0.5), _], p.height * 0.14, p.height * 0.15), u, d(p));
3443
- const B = mt(p);
3444
- if (B > 0.2) {
3445
- const S = Ht(p) * p.height * 0.03, [L, Y] = O ? [_, F] : [T, _];
3446
- if (k.line([{ x: L.x + S, y: L.y }, { x: Y.x + S, y: Y.y }], d(p) * 0.8), !O) {
3447
- const V = Z(T, _, 0.35), U = p.height * 0.025 * B;
3448
- k.shape([{ x: V.x + S - U * 2.4, y: V.y }, { x: V.x + S - U * 0.6, y: V.y }, { x: V.x + S - U * 0.6, y: V.y + U * 1.6 }, { x: V.x + S - U * 2.4, y: V.y + U * 1.6 }], u, d(p) * 0.6);
3449
- }
3450
- }
3451
- }, q = (p, k, O, T, _) => {
3452
- const W = p.bodyContours?.[`arm.${O}`];
3453
- if (W) {
3454
- const Ft = Ke(W, 0, _, p.height * 6e-3);
3455
- k.shape(Ft, T, 0);
3456
- const ks = v(p);
3457
- for (let be = 0; be < Ft.length; be++) {
3458
- const De = Ft[be], qe = Ft[(be + 1) % Ft.length];
3459
- qo({ x: (De.x + qe.x) / 2, y: (De.y + qe.y) / 2 }, ks) || k.line([De, qe], d(p));
3460
- }
3461
- return;
3462
- }
3463
- const F = p.parts[`arm.${O}`].points, B = F[0], S = p.chains.spine[p.chains.spine.length - 1], Y = [{ x: B.x + (S.x - B.x) * 0.45, y: B.y + (S.y - B.y) * 0.45 }, ...Qe(F, 0, _)], V = ut(Y, p.height * 0.085, p.height * (_ > 0.6 ? 0.045 : 0.06)), U = Y.length, Tt = V.slice(0, U), Bt = V.slice(U).reverse();
3464
- k.shape(V, T, 0);
3465
- const se = (Ft) => Math.hypot(Ft[1].x - S.x, Ft[1].y - S.y), [me, pe] = se(Tt) > se(Bt) ? [Tt, Bt] : [Bt, Tt];
3466
- k.line(me.slice(1), d(p)), k.line(pe.slice(Math.ceil(U * 0.45)), d(p)), k.line([Tt[U - 1], Bt[U - 1]], d(p));
3467
- }, J = l || c || h, j = J ? u : s, Q = J || i === "long" ? 0.95 : 0.45, nt = J || i !== "none", lt = (p, k) => {
3468
- a === "skirt" && !f && !y && H(p, k), y && w(p, k), l && K(p, k, !0), t.over === "apron" && X(p, k);
3469
- }, bt = (p) => (k, O, T) => {
3470
- k.save(), P(k, O), b(k, O, T, p), g && x(O, T, p), k.restore(), pa(O) === p && fo(O) && lt(O, T);
3471
- };
3472
- return {
3473
- parts: {
3474
- "leg.left": { clip: P, over: bt("left") },
3475
- "leg.right": { clip: P, over: bt("right") },
3476
- spine: {
3477
- over: (p, k, O) => {
3478
- c && mt(k) >= 0 && $(k, O), C(k, O), I(p, k, O), o && !c && N(k, O), t.tie && !c && D(k, O, t.tie), l && K(k, O, !1), h && z(k, O), c && (mt(k) < 0 && $(k, O), A(k, O)), f && R(k, O), y && E(k, O), fo(k) || lt(k, O);
3479
- }
3480
- },
3481
- "arm.left": { over: nt ? (p, k, O) => q(k, O, "left", j, Q) : void 0 },
3482
- "arm.right": { over: nt ? (p, k, O) => q(k, O, "right", j, Q) : void 0 }
3483
- }
3484
- };
3485
- }
3486
- const wa = {
3487
- mug: { color: "#e2493b", hands: "one" },
3488
- phone: { color: "#2b2f36", hands: "one" },
3489
- book: { color: "#3a6ea5", hands: "either" },
3490
- bag: { color: "#e9d8b4", hands: "one" },
3491
- briefcase: { color: "#6b4630", hands: "one" },
3492
- umbrella: { color: "#3c9a6e", hands: "one" },
3493
- broom: { color: "#c8963e", hands: "one" },
3494
- cane: { color: "#6b4630", hands: "one" },
3495
- parcel: { color: "#c9a06a", hands: "both" }
3496
- };
3497
- function xa(t) {
3498
- const e = {};
3499
- for (const n of ["left", "right", "both"]) {
3500
- const o = t[n];
3501
- if (!o) continue;
3502
- const s = typeof o == "string" ? o : o.item, r = wa[s];
3503
- if (!r) throw new Error(`holding: unknown item '${s}'`);
3504
- if (n === "both" && r.hands === "one") throw new Error(`holding: a ${s} is held in one hand ('left' or 'right'), not 'both'`);
3505
- if (n !== "both" && r.hands === "both") throw new Error(`holding: a ${s} is held in both hands ('both')`);
3506
- e[n] = { item: s, color: (typeof o == "object" ? o.color : void 0) ?? r.color };
3507
- }
3508
- return e;
3509
- }
3510
- function je(t, e) {
3511
- const n = t.chains[`arm.${e}`], o = n[n.length - 1], s = n[n.length - 2], r = Math.hypot(o.x - s.x, o.y - s.y) || 1, i = { x: (o.x - s.x) / r, y: (o.y - s.y) / r }, a = t.lineWidth * 0.5;
3512
- return { point: { x: o.x + i.x * a, y: o.y + i.y * a }, along: i, depth: t.parts[`arm.${e}`]?.depth ?? 0 };
3513
- }
3514
- function Jt(t, e, n, o = 0) {
3515
- const s = Math.cos(o), r = Math.sin(o);
3516
- return [
3517
- [-e / 2, -n / 2],
3518
- [e / 2, -n / 2],
3519
- [e / 2, n / 2],
3520
- [-e / 2, n / 2]
3521
- ].map(([i, a]) => ({ x: t.x + i * s - a * r, y: t.y + i * r + a * s }));
3522
- }
3523
- const Zt = (t, e, n, o, s = 12) => Array.from({ length: s + 1 }, (r, i) => {
3524
- const a = n + (o - n) * i / s;
3525
- return { x: t.x + Math.cos(a) * e, y: t.y + Math.sin(a) * e };
3526
- });
3527
- function yo(t, e, n, o, s, r = 1, i) {
3528
- const { point: a, along: l } = n, c = o / 300;
3529
- switch (e.item) {
3530
- case "mug": {
3531
- const h = Jt({ x: a.x, y: a.y - 4 * c }, 20 * c, 24 * c);
3532
- t.line(Zt({ x: a.x + 10 * c * Math.sign(r || 1), y: a.y - 4 * c }, 7 * c, -Math.PI / 2, Math.PI / 2).map((f) => ({ x: a.x + (f.x - a.x) * Math.sign(r || 1), y: f.y })), s), t.shape(h, e.color, s);
3533
- return;
3534
- }
3535
- case "phone": {
3536
- const h = Math.atan2(l.y, l.x) - Math.PI / 2;
3537
- t.shape(Jt(a, 13 * c, 24 * c, h), e.color, s), t.shape(Jt(a, 9 * c, 17 * c, h), "#8fd0f5", 0);
3538
- return;
3539
- }
3540
- case "book": {
3541
- const h = 26 * c, f = 34 * c;
3542
- t.shape([{ x: a.x, y: a.y - f / 2 }, { x: a.x - h, y: a.y - f / 2 - 3 * c }, { x: a.x - h, y: a.y + f / 2 - 3 * c }, { x: a.x, y: a.y + f / 2 }], e.color, s), t.shape([{ x: a.x, y: a.y - f / 2 }, { x: a.x + h, y: a.y - f / 2 - 3 * c }, { x: a.x + h, y: a.y + f / 2 - 3 * c }, { x: a.x, y: a.y + f / 2 }], e.color, s);
3543
- for (const y of [-1, 1])
3544
- for (const u of [0.3, 0.5, 0.7]) {
3545
- const g = a.y - f / 2 + f * u;
3546
- t.line([{ x: a.x + y * 5 * c, y: g }, { x: a.x + y * (h - 5 * c), y: g - 2 * c }], Math.max(0.8, s * 0.5));
3547
- }
3548
- return;
3549
- }
3550
- case "bag": {
3551
- const h = a.y + 10 * c;
3552
- t.line([{ x: a.x - 9 * c, y: h }, { x: a.x - 5 * c, y: a.y - 2 * c }, { x: a.x + 5 * c, y: a.y - 2 * c }, { x: a.x + 9 * c, y: h }], s), t.shape([{ x: a.x - 17 * c, y: h }, { x: a.x + 17 * c, y: h }, { x: a.x + 20 * c, y: h + 40 * c }, { x: a.x - 20 * c, y: h + 40 * c }], e.color, s);
3553
- return;
3554
- }
3555
- case "briefcase": {
3556
- t.line(Zt({ x: a.x, y: a.y + 6 * c }, 7 * c, Math.PI, Math.PI * 2), s), t.shape(Jt({ x: a.x, y: a.y + 22 * c }, 46 * c, 32 * c), e.color, s), t.line([{ x: a.x - 23 * c, y: a.y + 14 * c }, { x: a.x + 23 * c, y: a.y + 14 * c }], Math.max(0.8, s * 0.6));
3557
- return;
3558
- }
3559
- case "umbrella": {
3560
- const h = 78 * c, f = (i ?? a.y - 120 * c) - 14 * c, y = { x: a.x, y: Math.min(a.y - 60 * c, f - h * 0.55) };
3561
- t.line([{ x: a.x, y: a.y + 10 * c }, y], s), t.line(Zt({ x: a.x + 5 * c, y: a.y + 10 * c }, 5 * c, Math.PI, 0, 8), s);
3562
- const u = [...Zt({ x: y.x, y: y.y + h * 0.55 }, h, Math.PI, Math.PI * 2, 24)], g = [];
3563
- for (let m = 4; m >= 0; m--) {
3564
- const d = y.x - h + 2 * h * m / 5;
3565
- g.push(...Zt({ x: d + h / 5, y: y.y + h * 0.55 }, h / 5, 0, -Math.PI, 6).reverse());
3566
- }
3567
- t.shape([...u, ...g], e.color, s);
3568
- return;
3569
- }
3570
- case "broom": {
3571
- const h = { x: l.x * 0.4 + 0.25 * Math.sign(r || 1), y: Math.max(0.6, l.y) }, f = Math.hypot(h.x, h.y), y = { x: h.x / f, y: h.y / f }, u = { x: a.x - y.x * 40 * c, y: a.y - y.y * 40 * c }, g = { x: a.x + y.x * 120 * c, y: a.y + y.y * 120 * c };
3572
- t.line([u, g], s * 1.1);
3573
- const m = { x: -y.y, y: y.x }, d = [
3574
- { x: g.x + m.x * 6 * c, y: g.y + m.y * 6 * c },
3575
- { x: g.x - m.x * 6 * c, y: g.y - m.y * 6 * c },
3576
- { x: g.x - m.x * 16 * c + y.x * 34 * c, y: g.y - m.y * 16 * c + y.y * 34 * c },
3577
- { x: g.x + m.x * 16 * c + y.x * 34 * c, y: g.y + m.y * 16 * c + y.y * 34 * c }
3578
- ];
3579
- t.shape(d, e.color, s);
3580
- return;
3581
- }
3582
- case "cane": {
3583
- const h = Math.min(0.56 * o, Math.max(0.3 * o, -a.y)), f = 0.12 * Math.sign(r || 1), y = { x: f / Math.hypot(f, 1), y: 1 / Math.hypot(f, 1) }, u = { x: a.x + y.x * h, y: a.y + y.y * h }, g = Zt({ x: a.x + 7 * c * Math.sign(r || 1), y: a.y - 2 * c }, 7 * c, Math.PI, Math.PI * 2, 8).map((m) => ({ x: a.x + (m.x - a.x) * Math.sign(r || 1), y: m.y }));
3584
- t.line([...g, { x: a.x, y: a.y + 2 * c }, u], s * 1.2), t.shape(Jt({ x: u.x, y: u.y - 3 * c }, 9 * c, 7 * c), e.color, 0);
3585
- return;
3586
- }
3587
- case "parcel": {
3588
- const h = { x: a.x, y: a.y - 6 * c };
3589
- t.shape(Jt(h, 50 * c, 40 * c), e.color, s), t.line([{ x: h.x - 25 * c, y: h.y - 6 * c }, { x: h.x + 25 * c, y: h.y - 6 * c }], Math.max(0.8, s * 0.7)), t.line([{ x: h.x, y: h.y - 20 * c }, { x: h.x, y: h.y + 20 * c }], Math.max(0.8, s * 0.7));
3590
- return;
3591
- }
3592
- }
3593
- }
3594
- const mo = (t, e) => (t[`held.${e}`] ?? 1) >= 0.5, po = (t) => Math.sin(t * Math.PI / 2);
3595
- function Ma(t) {
3596
- const e = (r) => Math.max(1, r.lineWidth * 0.45), n = (r) => (i, a, l, c, h) => {
3597
- const f = t[r];
3598
- f && mo(h ?? {}, r) && yo(l, f, je(a, r), a.height, e(a), po(a.turn), a.head.center.y - a.head.ry);
3599
- }, o = (r, i, a, l, c) => {
3600
- const h = t.both;
3601
- if (!h || !mo(c ?? {}, "both")) return;
3602
- const f = je(i, "left"), y = je(i, "right"), u = {
3603
- point: { x: (f.point.x + y.point.x) / 2, y: (f.point.y + y.point.y) / 2 },
3604
- along: { x: (f.along.x + y.along.x) / 2, y: (f.along.y + y.along.y) / 2 },
3605
- depth: (f.depth + y.depth) / 2
3606
- };
3607
- yo(a, h, u, i.height, e(i), po(i.turn), i.head.center.y - i.head.ry);
3608
- }, s = { parts: {} };
3609
- if (t.left && (s.parts["arm.left"] = { over: n("left") }), t.right && (s.parts["arm.right"] = { over: n("right") }), t.both) {
3610
- const r = (i) => (a, l, c, h, f) => {
3611
- const y = i === "left" ? "right" : "left";
3612
- (i === "left" ? l.parts["arm.left"].depth >= l.parts["arm.right"].depth : l.parts["arm.right"].depth > l.parts[`arm.${y}`].depth) && o(a, l, c, h, f);
3613
- };
3614
- for (const i of ["left", "right"]) s.parts[`arm.${i}`] = { ...s.parts[`arm.${i}`], over: ka(s.parts[`arm.${i}`]?.over, r(i)) };
3615
- }
3616
- return s;
3617
- }
3618
- function ka(t, e) {
3619
- return t ? (n, o, s, r, i) => {
3620
- t(n, o, s, r, i), e(n, o, s, r, i);
3621
- } : e;
3622
- }
3623
- function tn(t, e) {
3624
- const n = (s, r) => s && r ? (i, a, l, c, h) => {
3625
- s(i, a, l, c, h), r(i, a, l, c, h);
3626
- } : s ?? r, o = {};
3627
- for (const s of /* @__PURE__ */ new Set([...Object.keys(t.parts ?? {}), ...Object.keys(e.parts ?? {})])) {
3628
- const r = t.parts?.[s], i = e.parts?.[s];
3629
- o[s] = { under: n(r?.under, i?.under), clip: n(r?.clip, i?.clip), over: n(r?.over, i?.over) };
3630
- }
3631
- return { behind: n(t.behind, e.behind), parts: o, front: n(t.front, e.front) };
3632
- }
3633
- function va(t = {}) {
3634
- if (t.build && !(t.build in zn)) throw new Error(`character: unknown build '${t.build}'`);
3635
- const e = t.build ? zn[t.build] : {}, n = (t.proportions ?? "bold") === "bold", o = t.figure ?? "fluid", s = t.look ?? "clean", r = t.height ?? 300, i = o === "stick", a = o === "organic", l = t.shoulderWidth ?? e.shoulderWidth ?? (a ? 0.07 : 0.06), c = t.hipWidth ?? e.hipWidth ?? (a ? 0.045 : 0.022), h = t.lineWidth ?? r * (a ? 5e-3 : n ? 0.045 : 0.022), f = t.ink ?? (a ? "#53362d" : s === "pencil" ? "#2f2f33" : "#1e293b"), y = t.skin ?? (a ? "#f1bf98" : s === "pencil" ? "none" : "#ffffff"), u = a ? ri(t.body ?? {}, { skin: y, ink: f, lineWidth: h, shoulderWidth: l, hipWidth: c }) : void 0;
3636
- if (t.leafOutfit && !a) throw new Error("character: leafOutfit requires figure: 'organic'");
3637
- const g = t.outfit ? ba(t.outfit) : null, m = t.holding ? xa(t.holding) : {};
3638
- let d = g ? tn(g, t.layers ?? {}) : t.layers ?? {};
3639
- return t.leafOutfit && (d = tn(ya(t.leafOutfit), d)), Object.keys(m).length > 0 && (d = tn(d, Ma(m))), {
3640
- plan: t.plan ?? jr({
3641
- headSize: t.headSize ?? e.headSize ?? (a ? 0.27 : n ? 0.3 : 0.24),
3642
- shoulderWidth: i ? 0 : l,
3643
- hipWidth: i ? 0 : c,
3644
- legLength: t.legLength ?? e.legLength ?? 1,
3645
- armLength: t.armLength ?? e.armLength ?? 1,
3646
- feet: t.feet ?? e.feet
3647
- }),
3648
- figure: o,
3649
- ...u ? { body: u } : {},
3650
- look: s,
3651
- height: r,
3652
- lineWidth: u?.outline.width ?? h,
3653
- ink: u?.outline.color ?? f,
3654
- skin: u?.fill ?? y,
3655
- seed: t.seed ?? 1,
3656
- pencil: a ? { construction: !1, ...t.pencil } : t.pencil ?? {},
3657
- layers: d,
3658
- holding: m,
3659
- contact: t.contact ?? "ground",
3660
- hands: t.hands ?? (a ? "cartoon" : "dot"),
3661
- handStyle: t.handStyle ?? (a ? "natural" : "glove"),
3662
- handSize: t.handSize ?? (a ? 0.073 : t.handStyle === "natural" ? 0.14 : 0.17),
3663
- head: ia(t),
3664
- face: { ...a ? { style: "anime", projection: "volume", iris: "#66422e", nose: !0 } : {}, ...t.face, teeth: t.face?.teeth ?? !1, tongue: t.face?.tongue ?? !1 }
3665
- };
3666
- }
3667
- function o0(t, e, n, o) {
3668
- const { point: s, facing: r } = oe(t, [e, n, o]);
3669
- return { point: s, facing: r };
3670
- }
3671
- const mn = (t) => t.rest[1] < -0.5, Ea = 0.3;
3672
- function Sa(t, e, n) {
3673
- return t.figure === "stick" ? mn(e) ? n.slice(0, 3) : n : mn(e) && n.length >= 3 ? ne(n[0], n[1], n[2], Ea) : n.length === 3 ? ne(n[0], n[1], n[2], 1) : n;
3674
- }
3675
- function ge(t, e) {
3676
- const n = t.plan.id === "human" ? { ...at, ...e } : e;
3677
- return Ye(t, n, xn(t.plan, n, { height: t.height, contact: t.contact }));
3678
- }
3679
- function Ye(t, e, n) {
3680
- const o = {}, s = {}, r = {}, i = 0.01 * t.height;
3681
- t.plan.chains.forEach((u) => {
3682
- const g = n.chains[u.id];
3683
- o[u.id] = g.points;
3684
- const m = g.depths.reduce((M, v) => M + v, 0) / g.depths.length, d = u.parent ? n.chains[u.parent] : void 0, b = d ? d.depths[u.at ?? d.depths.length - 1] : n.hipDepth, x = m - b;
3685
- r[u.id] = Math.abs(x) < i ? 0 : x, s[u.id] = { points: Sa(t, u, g.points), depth: m, order: 0 };
3686
- }), s.head = { points: [n.head.center], depth: n.head.depth, order: 0 }, r.head = 0;
3687
- const a = [...t.plan.chains.map((u) => u.id), "head"], l = (u) => t.body && u.startsWith("arm.") && r[u] >= 0 ? 1 : 0, c = [...a].sort((u, g) => l(u) - l(g) || r[u] - r[g] || a.indexOf(u) - a.indexOf(g));
3688
- c.forEach((u, g) => {
3689
- s[u].order = g;
3690
- });
3691
- const h = { hip: n.hip };
3692
- for (const [u, [g, m]] of Object.entries(t.plan.landmarks ?? {})) {
3693
- const d = n.chains[g]?.points;
3694
- d && (h[u] = d[Math.min(m, d.length - 1)]);
3695
- }
3696
- const f = {};
3697
- for (const [u, g] of Object.entries(h)) f[u] = g.y >= n.groundY - 0.01 * t.height;
3698
- const y = {
3699
- height: t.height,
3700
- lineWidth: t.lineWidth,
3701
- turn: e.turn ?? 0,
3702
- ...n.bodyForward ? { bodyForward: n.bodyForward } : {},
3703
- points: h,
3704
- chains: o,
3705
- parts: s,
3706
- head: n.head,
3707
- groundY: n.groundY,
3708
- grounded: f
3709
- };
3710
- return t.body && (y.bodyContours = li(t.body, y, t.plan)), { skeleton: n, joints: y, order: c };
3711
- }
3712
- function Pa(t, e) {
3713
- return ge(t, e).joints;
3714
- }
3715
- function ps(t, e, n) {
3716
- const { head: o } = n;
3717
- t.guideEllipse(o.center.x, o.center.y, o.rx * 1.03, o.ry * 1.03, o.angle);
3718
- const s = Array.from({ length: 13 }, (l, c) => ({ x: 0, y: -0.95 + 1.9 * c / 12 })), r = Array.from({ length: 13 }, (l, c) => ({ x: -0.95 + 1.9 * c / 12, y: 0.12 })), i = et(o, s, { x: 0, y: 0 });
3719
- i.facing > 0 && t.guide(i.points), t.guide(et(o, r, { x: 0, y: 0.12 }).points), t.guide(n.chains.spine ?? []);
3720
- const a = e.lineWidth * 0.9;
3721
- for (const l of ["shoulder.left", "shoulder.right", "elbow.left", "elbow.right", "hip.left", "hip.right", "knee.left", "knee.right"]) {
3722
- const c = n.points[l];
3723
- c && t.guideEllipse(c.x, c.y, a, a, 0);
3724
- }
3725
- }
3726
- function bs(t, e, n, o, s, r) {
3727
- const i = n.lineWidth;
3728
- if (n.body && n.skin === "none" && (e = ye(t, e)), s === "head") {
3729
- const { head: u } = o;
3730
- let g;
3731
- const m = () => g ??= Xo(u, n.face), d = n.skin === "none" ? null : n.skin;
3732
- n.face.projection === "volume" || n.face.shape === "angular" ? e.shape(m(), d, i) : e.ellipse(u.center.x, u.center.y, u.rx, u.ry, u.angle, d, i), n.body && n.skin !== "none" && e.look === "clean" && Po(t, m(), u.center, n.body.shading), aa(t, e, n.head, u, r, { lineWidth: i, skin: n.skin, face: n.face, faceUnderHair: !!n.body }, () => {
3733
- e.look !== "silhouette" && (t.save(), n.body && (t.beginPath(), m().forEach((b, x) => x ? t.lineTo(b.x, b.y) : t.moveTo(b.x, b.y)), t.closePath(), t.clip()), wi(e, u, r, i, { ...n.face, skin: n.skin === "none" ? "#ffffff" : n.skin }, t), t.restore());
3734
- });
3735
- return;
3736
- }
3737
- const a = n.plan.chains.find((u) => u.id === s), l = o.chains[s], c = o.parts[s].points;
3738
- if (n.body && Gn(t, e, n.body, o, s)) {
3739
- if (s.startsWith("leg.") && Gn(t, e, n.body, o, s.replace("leg.", "foot.")), s.startsWith("arm."))
3740
- if (n.hands === "cartoon") bo(t, e, n, l, s.endsWith(".left") ? "left" : "right", r);
3741
- else {
3742
- const u = l.at(-1);
3743
- e.ellipse(u.x, u.y, n.height * 0.014, n.height * 0.014, 0, n.skin === "none" ? null : n.skin, i);
3744
- }
3745
- return;
3746
- }
3747
- if (n.figure === "stick") {
3748
- if (s === "neck") return;
3749
- const u = s === "spine" ? [...l, ...o.chains.neck?.slice(1) ?? []] : c;
3750
- e.line(u, i);
3751
- return;
3752
- }
3753
- const h = (u, g) => [a.bones[u].width[0] * i, a.bones[g].width[1] * i];
3754
- if (mn(a)) {
3755
- const [u, g] = h(0, 1);
3756
- if (e.limb(c, u, g), a.bones.length >= 3)
3757
- e.limb([l[2], l[3]], a.bones[2].width[0] * i, a.bones[2].width[1] * i);
3758
- else if (n.hands === "cartoon" && s.startsWith("arm."))
3759
- bo(t, e, n, l, s.endsWith(".left") ? "left" : "right", r);
3760
- else {
3761
- const m = l[l.length - 1];
3762
- e.dot(m.x, m.y, i * 0.62);
3763
- }
3764
- return;
3765
- }
3766
- if (s === "spine") {
3767
- const u = o.points["hip.left"], g = o.points["hip.right"];
3768
- u && g && Math.hypot(u.x - g.x, u.y - g.y) > 0.5 && e.limb([u, g], i * 1.3, i * 1.3);
3769
- const [m, d] = h(0, a.bones.length - 1);
3770
- e.limb(c, m, d);
3771
- const b = o.points["shoulder.left"], x = o.points["shoulder.right"];
3772
- b && x && Math.hypot(b.x - x.x, b.y - x.y) > 0.5 && e.limb(ne(b, l[l.length - 1], x, 1, 10), i * 1.15, i * 1.15);
3773
- return;
3774
- }
3775
- const [f, y] = h(0, a.bones.length - 1);
3776
- e.limb(c, f, y);
3777
- }
3778
- function Aa(t, e) {
3779
- const n = `hand.${e}.`, o = {};
3780
- for (const [i, a] of Object.entries(t)) i.startsWith(n) && (o[i.slice(n.length)] = a);
3781
- const s = t.turn ?? 0, r = e === "right" ? 1 - s : 1 + s;
3782
- return { ...It, ...o, turn: r + (o.turn ?? 0) };
3783
- }
3784
- function bo(t, e, n, o, s, r) {
3785
- const i = o[o.length - 1], a = o[o.length - 2], l = Math.atan2(i.x - a.x, -(i.y - a.y)) * 180 / Math.PI;
3786
- Ao(t, i, Aa(r, s), {
3787
- size: n.handSize * n.height,
3788
- side: s,
3789
- angle: l,
3790
- pen: e,
3791
- skin: n.skin === "none" && !n.body ? "#ffffff" : n.skin,
3792
- // A cartoon glove: three fingers and a thumb, plump enough to match the limbs.
3793
- // Natural: five fingers, a little fuller than a real hand so they hold up against the limbs.
3794
- fingers: n.handStyle === "natural" ? 5 : 4,
3795
- plump: n.handStyle === "natural" ? 1.15 : 1.6,
3796
- lineWidth: n.lineWidth * (n.body ? 0.65 : 0.3),
3797
- connected: !!n.body,
3798
- shading: n.body?.shading,
3799
- nails: n.body ? !1 : void 0
3800
- });
3801
- }
3802
- function Ia(t, e, n, o = 0) {
3803
- const s = e.plan.id === "human" ? { ...at, ...n } : n;
3804
- Pn(t, e, s, ge(e, s), o);
3805
- }
3806
- function ze(t, e) {
3807
- const n = e / t.height;
3808
- return { ...t, height: e, lineWidth: t.lineWidth * n };
3809
- }
3810
- function s0(t, e, n, o) {
3811
- const s = t.plan.id === "human" ? { ...at, ...e } : e, r = Mn(t.plan, s, { height: o.height, contact: t.contact }, n);
3812
- return Ye(ze(t, r.height), s, r).joints;
3813
- }
3814
- function r0(t, e, n, o, s) {
3815
- const r = e.plan.id === "human" ? { ...at, ...n } : n, i = Mn(e.plan, r, { height: s.height, contact: e.contact }, o), a = ze(e, i.height);
3816
- Pn(t, a, r, Ye(a, r, i), s.time ?? 0);
3817
- }
3818
- function i0(t, e, n, o) {
3819
- const s = t.plan.id === "human" ? { ...at, ...e } : e, r = Mn(t.plan, s, { height: o.height, contact: t.contact }, n), i = ze(t, r.height), { joints: a, order: l } = Ye(i, s, r), c = r.height / o.height, h = l.map((g) => (a.parts[g]?.depth ?? 0) / c), f = l.filter((g) => g === "spine" || g.startsWith("leg.")), y = Math.max(...f.map((g) => a.parts[g].depth / c)), u = Math.max(...f.map((g) => a.parts[g].order));
3820
- return l.map((g, m) => ({
3821
- part: g,
3822
- depth: h[m],
3823
- ...i.body ? { sortDepth: g.startsWith("arm.") && m > u ? Math.max(h[m], y) : h[m] } : {},
3824
- draw(d, b = 0) {
3825
- const x = bn(d, { look: i.look, ink: i.ink, lineWidth: i.lineWidth, seed: vo(`${i.seed}:${g}`), time: b, pencil: i.pencil }), M = (P) => {
3826
- P && (d.save(), P(d, a, x, b, s), d.restore());
3827
- };
3828
- d.save(), d.lineCap = "round", d.lineJoin = "round", m === 0 && (i.look === "pencil" && i.pencil.construction !== !1 && ps(x, i, a), M(i.layers.behind), ds(d, i.body && i.skin === "none" ? ye(d, x) : x, i.head, a.head, s, { lineWidth: i.lineWidth, skin: i.skin, face: i.face }));
3829
- const v = i.layers.parts?.[g];
3830
- M(v?.under), d.save(), v?.clip?.(d, a, x, b, s), bs(d, x, i, a, g, s), d.restore(), M(v?.over), g === "head" && gs(d, x, i.head, a.head, s, { lineWidth: i.lineWidth, skin: i.skin, face: i.face }), m === l.length - 1 && M(i.layers.front), d.restore();
3831
- }
3832
- }));
3833
- }
3834
- function Pn(t, e, n, o, s, r) {
3835
- const { joints: i } = o, a = r ? o.order.filter((h) => r.has(h)) : o.order, l = bn(t, {
3836
- look: e.look,
3837
- ink: e.ink,
3838
- lineWidth: e.lineWidth,
3839
- seed: e.seed,
3840
- time: s,
3841
- pencil: e.pencil
3842
- }), c = (h) => {
3843
- h && (t.save(), h(t, i, l, s, n), t.restore());
3844
- };
3845
- t.save(), t.lineCap = "round", t.lineJoin = "round", !r && e.look === "pencil" && e.pencil.construction !== !1 && ps(l, e, i), r || c(e.layers.behind), ds(t, e.body && e.skin === "none" ? ye(t, l) : l, e.head, i.head, n, { lineWidth: e.lineWidth, skin: e.skin, face: e.face });
3846
- for (const h of a) {
3847
- const f = e.layers.parts?.[h];
3848
- c(f?.under), t.save(), f?.clip?.(t, i, l, s, n), bs(t, l, e, i, h, n), t.restore(), c(f?.over);
3849
- }
3850
- gs(t, l, e.head, i.head, n, { lineWidth: e.lineWidth, skin: e.skin }), r || c(e.layers.front), t.restore();
3851
- }
3852
- function a0(t, e, n, o) {
3853
- const s = e.plan.id === "human" ? { ...at, ...n } : n, r = ge(e, s).joints.head.rx, i = ze(e, e.height * o.radius / Math.max(1e-6, r)), a = ge(i, s);
3854
- t.save(), t.translate(o.x - a.joints.head.center.x, o.y - a.joints.head.center.y), Pn(t, i, s, a, o.time ?? 0, /* @__PURE__ */ new Set(["head"])), t.restore();
3855
- }
3856
- function l0(t, e, n) {
3857
- const o = { ...t };
3858
- for (const [s, r] of Object.entries(e)) {
3859
- const i = t[s] ?? r;
3860
- o[s] = i + (r - i) * n;
3861
- }
3862
- return o;
3863
- }
3864
- function h0(t, e, n, o) {
3865
- const s = t.plan.id === "human" ? { ...at, ...e } : e;
3866
- let r;
3867
- if (Array.isArray(o))
3868
- r = o;
3869
- else {
3870
- const { skeleton: i } = ge(t, s), a = xn(t.plan, { ...s, roll: 0 }, { height: t.height, contact: "none" }), l = (s.roll ?? 0) * Math.PI / 180, c = o.x - i.hip.x, h = o.y - i.hip.y, f = a.hip.x + c * Math.cos(-l) - h * Math.sin(-l), y = a.hip.y + c * Math.sin(-l) + h * Math.cos(-l), u = Math.PI / 2 * (s.turn ?? 0), g = o.depth ?? i.chains[n].depths[i.chains[n].depths.length - 1], m = Math.cos(u), d = Math.sin(u);
3871
- r = [f * m - g * d, -y, f * d + g * m];
3872
- }
3873
- return si(t.plan, s, n, r, { height: t.height });
3874
- }
3875
- const ws = /* @__PURE__ */ new Set(["walk", "walking", "gait"]);
3876
- function xs(t, e = at, n) {
3877
- let o = { ...e };
3878
- for (const [r, i] of Object.entries(t))
3879
- typeof i == "number" && !ws.has(r) && (o[r] = i);
3880
- const s = Math.max(0, Math.min(1, typeof t.walking == "number" ? t.walking : 0));
3881
- if (s > 0) {
3882
- const r = typeof t.gait == "string" ? t.gait : void 0, i = r ? n?.[r] ?? r : void 0, a = ha(i, typeof t.walk == "number" ? t.walk : 0, o);
3883
- o = Object.fromEntries(Object.keys({ ...o, ...a }).map((l) => [l, (o[l] ?? 0) + ((a[l] ?? 0) - (o[l] ?? 0)) * s]));
3884
- }
3885
- return o;
3886
- }
3887
- function c0(t) {
3888
- const { character: e } = t, n = e.height * 0.8, o = e.height, s = e.plan.id === "human" ? at : {};
3889
- return {
3890
- type: "custom",
3891
- x: t.x - n / 2,
3892
- y: t.y - o,
3893
- width: n,
3894
- height: o,
3895
- props: { ...s, ...t.pose },
3896
- character: e,
3897
- ...t.gaits ? { gaits: t.gaits } : {},
3898
- draw(r, i, a) {
3899
- r.translate(n / 2, o), Ia(r, e, xs(i.props ?? {}, s, t.gaits), a);
3900
- }
3901
- };
3902
- }
3903
- function Oa(t, e, n) {
3904
- const o = (r) => ({ x: r.x + e, y: r.y + n }), s = (r) => Object.fromEntries(Object.entries(r).map(([i, a]) => [i, a.map(o)]));
3905
- return {
3906
- ...t,
3907
- ...t.bodyContours ? { bodyContours: Object.fromEntries(Object.entries(t.bodyContours).map(([r, i]) => [r, {
3908
- ...i,
3909
- outline: i.outline.map(o),
3910
- samples: i.samples.map((a) => ({ ...a, center: o(a.center), left: o(a.left), right: o(a.right) }))
3911
- }])) } : {},
3912
- points: Object.fromEntries(Object.entries(t.points).map(([r, i]) => [r, o(i)])),
3913
- chains: s(t.chains),
3914
- parts: Object.fromEntries(Object.entries(t.parts).map(([r, i]) => [r, { ...i, points: i.points.map(o) }])),
3915
- head: { ...t.head, center: o(t.head.center) },
3916
- groundY: t.groundY + n
3917
- };
3918
- }
3919
- function f0(t, e, n) {
3920
- const o = t.character;
3921
- if (!o) throw new Error("characterAt: the target was not made by characterTarget");
3922
- const s = { ...t.props };
3923
- let r = 0, i = 0;
3924
- for (const [c, h] of e.state?.values.get(n) ?? [])
3925
- c === "x" || c === "motionPathX" ? r = typeof h == "number" ? h : r : c === "y" || c === "motionPathY" ? i = typeof h == "number" ? h : i : (typeof h == "number" || ws.has(c)) && (s[c] = h);
3926
- const a = xs(s, o.plan.id === "human" ? at : {}, t.gaits), l = Pa(o, a);
3927
- return { pose: a, joints: Oa(l, t.x + r + t.width / 2, t.y + i + t.height) };
3928
- }
3929
- function Ta(t, e = at) {
3930
- const n = [];
3931
- return t.forEach((o, s) => {
3932
- const r = s === 0 ? e : n[s - 1], i = typeof o.pose == "string" ? Zr[o.pose] : void 0;
3933
- n.push(i ? { ...i, turn: r.turn ?? 0 } : { ...r, ...o.pose });
3934
- }), n;
3935
- }
3936
- function u0(t, e, n = at) {
3937
- const o = Ta(e, n);
3938
- return Object.keys(n).filter((r) => o.some((i) => (i[r] ?? n[r]) !== n[r])).map((r) => ({
3939
- id: `${t}-${r}`,
3940
- target: t,
3941
- property: r,
3942
- keyframes: e.map((i, a) => ({
3943
- time: i.time,
3944
- value: o[a][r] ?? n[r],
3945
- ...i.easing ? { easing: i.easing } : {}
3946
- }))
3947
- }));
3948
- }
3949
- function wo() {
3950
- return {
3951
- torso: [{ at: 0, width: 0.083 }, { at: 0.25, width: 0.08 }, { at: 0.5, width: 0.075 }, { at: 0.8, width: 0.085 }, { at: 1, width: 0.023 }],
3952
- arm: [{ at: 0, width: 0.026 }, { at: 0.3, width: 0.024 }, { at: 0.5, width: 0.018 }, { at: 0.7, width: 0.021 }, { at: 1, width: 0.012 }],
3953
- leg: [{ at: 0, width: 0.036 }, { at: 0.3, width: 0.037 }, { at: 0.5, width: 0.026 }, { at: 0.7, width: 0.029 }, { at: 1, width: 0.015 }]
3954
- };
3955
- }
3956
- const xo = {
3957
- youngMan: {
3958
- figure: "organic",
3959
- skin: "#edb98d",
3960
- ink: "#53372d",
3961
- headSize: 0.28,
3962
- shoulderWidth: 0.074,
3963
- hipWidth: 0.045,
3964
- handSize: 0.078,
3965
- hair: { style: "softSweep", color: "#38291f" },
3966
- ears: !0,
3967
- face: { style: "anime", shape: "angular", jawWidth: 0.83, chinWidth: 0.35, jawRoundness: 1, eyeScale: 0.95, eyeAspect: 1.1, nose: !0, iris: "#6a472d" },
3968
- outfit: { shirt: "#bc7050", trousers: "#495a67", sleeves: "short" }
3969
- },
3970
- youngWoman: {
3971
- figure: "organic",
3972
- skin: "#f1c299",
3973
- ink: "#53372d",
3974
- headSize: 0.28,
3975
- shoulderWidth: 0.065,
3976
- hipWidth: 0.054,
3977
- handSize: 0.075,
3978
- body: { torso: [{ at: 0, width: 0.098 }, { at: 0.18, width: 0.097 }, { at: 0.44, width: 0.061 }, { at: 0.7, width: 0.087 }, { at: 0.85, width: 0.09 }, { at: 1, width: 0.024 }] },
3979
- hair: { style: "flowingBob", color: "#38291f" },
3980
- ears: !0,
3981
- face: { style: "anime", shape: "angular", jawWidth: 0.78, chinWidth: 0.32, jawRoundness: 1, eyeScale: 0.95, eyeAspect: 1.1, nose: !0, iris: "#6a472d", lashes: !0 },
3982
- outfit: { shirt: "#72958b", trousers: "#6b6888", sleeves: "short", bottom: "skirt" }
3983
- },
3984
- childBoy: {
3985
- figure: "organic",
3986
- height: 230,
3987
- skin: "#edb98d",
3988
- ink: "#53372d",
3989
- headSize: 0.36,
3990
- shoulderWidth: 0.052,
3991
- hipWidth: 0.038,
3992
- legLength: 0.82,
3993
- armLength: 0.8,
3994
- handSize: 0.074,
3995
- body: wo(),
3996
- hair: { style: "softSweep", color: "#38291f" },
3997
- ears: !0,
3998
- face: { style: "anime", shape: "round", eyeScale: 1, eyeAspect: 1.1, nose: !0, iris: "#6a472d" },
3999
- outfit: { shirt: "#d99843", trousers: "#497b91", sleeves: "short", bottom: "shorts" }
4000
- },
4001
- childGirl: {
4002
- figure: "organic",
4003
- height: 225,
4004
- skin: "#f1c299",
4005
- ink: "#53372d",
4006
- headSize: 0.36,
4007
- shoulderWidth: 0.052,
4008
- hipWidth: 0.038,
4009
- legLength: 0.82,
4010
- armLength: 0.8,
4011
- handSize: 0.074,
4012
- body: wo(),
4013
- hair: { style: "flowingBob", color: "#38291f" },
4014
- ears: !0,
4015
- face: { style: "anime", shape: "round", eyeScale: 1, eyeAspect: 1.1, nose: !0, iris: "#6a472d", lashes: !0 },
4016
- outfit: { shirt: "#ae7396", trousers: "#648769", sleeves: "short", bottom: "skirt" }
4017
- }
4018
- };
4019
- function d0(t, e = {}) {
4020
- if (!Object.prototype.hasOwnProperty.call(xo, t)) throw new Error(`softCartoonCharacter: unknown actor '${t}'`);
4021
- const n = xo[t];
4022
- return va({ ...n, ...e, body: { ...n.body, ...e.body }, face: { ...n.face, ...e.face } });
4023
- }
4024
- const Mo = Object.freeze({
4025
- everyday: Object.freeze({ shirt: "#bc7050", trousers: "#495a67", sleeves: "short", bottom: "trousers", collar: !1, tie: null }),
4026
- formal: Object.freeze({ top: "shirt", shirt: "#f4ede2", trousers: "#394653", sleeves: "long", bottom: "trousers", trouserStyle: "plain", collar: !0, tie: "#804453" }),
4027
- casual: Object.freeze({ top: "tshirt", shirt: "#648a83", trousers: "#426683", sleeves: "short", bottom: "trousers", trouserStyle: "jeans", collar: !1, tie: null })
4028
- });
4029
- function g0(t, e = {}) {
4030
- if (!Object.prototype.hasOwnProperty.call(Mo, t)) throw new Error(`outfitPreset: unknown category '${t}'`);
4031
- const n = { ...Mo[t], ...e };
4032
- return e.top && e.top !== "shirt" && (n.collar = e.collar ?? !1, n.tie = e.tie ?? null), n.top === "dress" && (n.bottom = "skirt"), n;
4033
- }
4034
- const y0 = Object.freeze({
4035
- test: Object.freeze({ name: "Test", inningsPerSide: 2, oversPerInnings: null, ballsPerOver: 6, freeHitAfterNoBall: !1, summary: "Multi-day cricket. Each side can have two innings; there is no innings over limit." }),
4036
- odi: Object.freeze({ name: "ODI", inningsPerSide: 1, oversPerInnings: 50, ballsPerOver: 6, freeHitAfterNoBall: !0, summary: "One innings per side, up to 50 overs. A no-ball gives a free hit on the next legitimate delivery." }),
4037
- t20: Object.freeze({ name: "T20", inningsPerSide: 1, oversPerInnings: 20, ballsPerOver: 6, freeHitAfterNoBall: !0, summary: "One innings per side, up to 20 overs. A no-ball gives a free hit on the next legitimate delivery." })
4038
- }), m0 = Object.freeze({ adults: "Adults", men: "Men", children: "Children", mixed: "Mixed cast" }), ko = Object.freeze({
4039
- bowler: "Bowler",
4040
- keeper: "Wicketkeeper",
4041
- fielder: "Extra cover",
4042
- slip: "Slip",
4043
- point: "Point",
4044
- cover: "Cover",
4045
- "mid-off": "Mid-off",
4046
- "mid-on": "Mid-on",
4047
- "square-leg": "Square leg",
4048
- "fine-leg": "Fine leg",
4049
- "third-man": "Third man"
4050
- }), p0 = Object.freeze(Object.fromEntries(Object.entries({
4051
- bowling: { name: "Pace bowling", summary: "Run up, deliver with a straight arm, bounce and follow through." },
4052
- spin: { name: "Spin bowling", summary: "A shorter approach and a curved illustrative flight before the bounce." },
4053
- batting: { name: "Drive", summary: "Two hands on the bat, a backlift, contact and a follow-through." },
4054
- defend: { name: "Defensive block", summary: "Meet the ball with a controlled bat and keep it close." },
4055
- running: { name: "Running between wickets", summary: "Both batters make the opposite ground to complete one run." },
4056
- four: { name: "Boundary four", summary: "A struck ball reaches the boundary after touching the ground." },
4057
- six: { name: "Boundary six", summary: "A struck ball clears the boundary before touching the ground." },
4058
- catch: { name: "Catch", summary: "A fielder controls the struck ball before it touches the ground." },
4059
- fielding: { name: "Ground field", summary: "A fielder moves to the ball, bends and gathers it." },
4060
- throw: { name: "Field and throw", summary: "Gather, wind up, release and return the ball to the keeper." },
4061
- bowled: { name: "Bowled", summary: "A legal delivery hits the wicket and removes a bail." },
4062
- lbw: { name: "LBW illustration", summary: "Pad contact and a projected path to the stumps illustrate an authored LBW decision." },
4063
- stumping: { name: "Stumping", summary: "The keeper holds the ball and breaks the wicket while the striker is out of ground, not attempting a run." },
4064
- "run-out": { name: "Run-out", summary: "A direct throw breaks the wicket before the running batter makes that ground." },
4065
- "no-ball": { name: "Front-foot no-ball", summary: "The landing front foot oversteps the popping crease at release; one extra, no legal ball." },
4066
- wide: { name: "Wide ball", summary: "An untouched delivery passes beyond reach for a normal stroke; one extra, no legal ball." }
4067
- }).map(([t, e]) => [t, Object.freeze(e)])));
4068
- function Wa(t, e, n) {
4069
- if (!Object.prototype.hasOwnProperty.call(t, e)) throw new Error(`${n}: unknown choice '${e}'`);
4070
- return e;
4071
- }
4072
- const Ha = Object.freeze({ pitch: "Whole pitch", batter: "Batter close-up", bowler: "Bowler close-up", keeper: "Keeper close-up", field: "Whole ground", overhead: "Overhead ground", orbit: "360° ground orbit", "follow-ball": "Follow the ball" }), $a = Object.freeze({ pitch: 75, batter: 145, bowler: 35, keeper: 145, field: 75, overhead: 75, orbit: 75, "follow-ball": 75 });
4073
- function b0(t, e = {}) {
4074
- const n = Wa(Ha, e.view ?? "pitch", "cricketCamera.view"), o = e.yaw ?? $a[n];
4075
- if (!Number.isFinite(o)) throw new Error("cricketCamera: yaw must be finite");
4076
- const s = (o % 360 + 360) % 360, r = e.zoom ?? 1;
4077
- if (!Number.isFinite(r) || r < 0.25 || r > 4) throw new Error("cricketCamera: zoom must be between 0.25 and 4");
4078
- const i = (y) => r === 1 ? y : Math.atan(Math.tan(y * Math.PI / 360) / r) * 360 / Math.PI, a = e.every ?? 40;
4079
- if (!Number.isFinite(a) || a < 16 || a > 1e3) throw new Error("cricketCamera: every must be between 16 and 1000 ms");
4080
- if (n === "follow-ball") {
4081
- const y = ["x", "y", "z"].map((d) => {
4082
- const b = t.timeline.tracks.find((P) => P.target === `${t.scene.id}/ball` && P.property === d);
4083
- if (!b || !("keyframes" in b) || !b.keyframes.length) throw new Error(`cricketCamera: missing ball ${d} keyframes`);
4084
- const x = b.keyframes;
4085
- let M = 0, v = new An({ ...b, keyframes: x.slice(0, 2) });
4086
- return (P) => {
4087
- const C = M;
4088
- for (; M < x.length - 2 && P - (b.delay ?? 0) > x[M + 1].time; ) M++;
4089
- return M !== C && (v = new An({ ...b, keyframes: x.slice(M, M + 2) })), v.getValueAtTime(P);
4090
- };
4091
- }), u = Ps({ scene: t.scene.id, camera: "camera", start: 0, end: t.duration, every: a, offset: [5, 3, 6], subjectAt: (d) => y.map((b) => b(d)) }), g = t.scene.objects.find((d) => d.id === "camera" && d.kind === "camera"), m = i(g?.kind === "camera" && g.projection === "perspective" ? g.fov : 48);
4092
- return [...u, { id: `${t.scene.id}/camera-zoom-fov`, target: `${t.scene.id}/camera`, property: "fov", keyframes: [{ time: 0, value: m }, { time: t.duration, value: m }] }];
4093
- }
4094
- const l = n === "field" || n === "overhead" || n === "orbit", c = n === "batter" ? [0.1, 0.85, 9.3] : n === "bowler" ? [0.68, 1, -9.55] : n === "keeper" ? [0, 0.7, 10.1] : [0, 0.65, 0], h = l ? t.boundaryRadius * 2.8 : n === "pitch" ? 29 : 4.3, f = n === "overhead" ? 89 : l ? 52 : n === "pitch" ? 16 : 12;
4095
- return As({ scene: t.scene.id, camera: "camera", start: 0, end: t.duration, every: a, easing: "linear", from: { target: c, yaw: s, pitch: f, distance: h, fov: i(l ? 48 : n === "pitch" ? 50 : 46) }, to: { yaw: n === "orbit" ? s + 360 : s } });
4096
- }
4097
- function ce(t, e) {
4098
- if (!Array.isArray(t) || t.length !== 3 || !t.every(Number.isFinite)) throw new Error(`${e}: expected three finite coordinates`);
4099
- }
4100
- function _a(t, e, n = 40, o = []) {
4101
- if (!Number.isFinite(t) || !Number.isFinite(e) || t < 0 || e < t) throw new Error("sampleTimes: expected finite ordered nonnegative times");
4102
- if (!Number.isFinite(n) || n < 16 || n > 1e3) throw new Error("sampleTimes: every must be between 16 and 1000 ms");
4103
- if ((e - t) / n > 2e4) throw new Error("sampleTimes: too many samples");
4104
- const s = /* @__PURE__ */ new Set([t, e, ...o.filter((r) => r >= t && r <= e && Number.isFinite(r))]);
4105
- for (let r = t + n; r < e; r += n) s.add(r);
4106
- return [...s].sort((r, i) => r - i);
4107
- }
4108
- function Fa(t, e) {
4109
- if (Ms(t), !Number.isFinite(e)) throw new Error("ballFlightPoint: time must be finite");
4110
- const n = Math.max(0, Math.min(1, (e - t.start) / (t.end - t.start))), o = 4 * n * (1 - n), s = t.to[0] - t.from[0], r = t.to[2] - t.from[2], i = Math.hypot(s, r) || 1;
4111
- return [
4112
- t.from[0] + s * n - r / i * (t.curve ?? 0) * o,
4113
- t.from[1] + (t.to[1] - t.from[1]) * n + (t.arc ?? 0) * o,
4114
- t.from[2] + r * n + s / i * (t.curve ?? 0) * o
4115
- ];
4116
- }
4117
- function Ms(t) {
4118
- if (!t.target?.trim()) throw new Error("ballFlight: target is required");
4119
- if (ce(t.from, "ballFlight.from"), ce(t.to, "ballFlight.to"), !Number.isFinite(t.start) || !Number.isFinite(t.end) || t.start < 0 || t.end <= t.start) throw new Error("ballFlight: end must be greater than start, both finite and nonnegative");
4120
- if (!Number.isFinite(t.arc ?? 0) || (t.arc ?? 0) < 0 || !Number.isFinite(t.curve ?? 0)) throw new Error("ballFlight: arc must be finite and nonnegative; curve must be finite");
4121
- }
4122
- function w0(t) {
4123
- Ms(t);
4124
- const e = _a(t.start, t.end, t.every), n = e.map((o) => Fa(t, o));
4125
- return ["x", "y", "z"].map((o, s) => ({
4126
- id: `${t.id ?? "flight"}-${o}`,
4127
- target: t.target,
4128
- property: o,
4129
- keyframes: e.map((r, i) => ({ time: r, value: n[i][s] }))
4130
- }));
4131
- }
4132
- const x0 = Object.freeze({
4133
- mcc: Object.freeze({ name: "MCC", poppingCreaseHalfWidth: 1.83, fieldingRadius: null, summary: "MCC minimum crease markings. The base Laws do not prescribe a limited-over restriction area." }),
4134
- "icc-men": Object.freeze({ name: "ICC men", poppingCreaseHalfWidth: 7.5, fieldingRadius: 27.43, summary: "ICC men: extended crease markings; ODI/T20 restriction-area arcs have a 27.43 m radius." }),
4135
- "icc-women": Object.freeze({ name: "ICC women", poppingCreaseHalfWidth: 7.5, fieldingRadius: 23, summary: "ICC women: extended crease markings; ODI/T20 restriction-area arcs have a 23 m radius." })
4136
- });
4137
- function M0(t) {
4138
- const [e, n] = t.centres, o = Math.hypot(n[0] - e[0], n[2] - e[2]), s = (n[0] - e[0]) / o, r = (n[2] - e[2]) / o, i = [];
4139
- for (let a = 0; a < 2; a++) {
4140
- const l = a === 0 ? n : e;
4141
- for (let c = 0; c <= 64; c++) {
4142
- const h = (a + c / 64) * Math.PI, f = Math.cos(h) * t.radius, y = Math.sin(h) * t.radius;
4143
- i.push([l[0] + r * f + s * y, 0.018, l[2] - s * f + r * y]);
4144
- }
4145
- }
4146
- return i;
4147
- }
4148
- function La(t, e) {
4149
- ce(e, "cricketFieldingAreaContains.point");
4150
- const n = t.fieldingArea;
4151
- if (n == null) return null;
4152
- if (!Number.isFinite(n.radius) || n.radius <= 0) throw new Error("cricketFieldingAreaContains: radius must be positive and finite");
4153
- if (!Array.isArray(n.centres) || n.centres.length !== 2) throw new Error("cricketFieldingAreaContains: two centres are required");
4154
- const [o, s] = n.centres;
4155
- ce(o, "cricketFieldingAreaContains.centre"), ce(s, "cricketFieldingAreaContains.centre");
4156
- const r = s[0] - o[0], i = s[2] - o[2], a = r * r + i * i, l = a ? Math.max(0, Math.min(1, ((e[0] - o[0]) * r + (e[2] - o[2]) * i) / a)) : 0;
4157
- return Math.hypot(e[0] - o[0] - l * r, e[2] - o[2] - l * i) <= n.radius + 1e-9;
4158
- }
4159
- function Ca(t) {
4160
- return Object.keys(ko).flatMap((e) => {
4161
- const n = t.scene.objects.find((s) => s.id === e && s.kind === "character");
4162
- if (!n) return [];
4163
- if (n.parent) throw new Error(`cricketFieldingPositions: '${e}' must be unparented for setup markers`);
4164
- const o = [...n.position ?? [0, 0, 0]];
4165
- return [{ id: e, name: n.name ?? ko[e], position: o, inside: La(t, o) }];
4166
- });
4167
- }
4168
- function k0(t) {
4169
- return t.fieldingArea ? Ca(t).map((e) => ({
4170
- id: `fielding-review-${e.id}`,
4171
- name: `${e.name}: ${e.inside ? "inside" : "outside"} restriction area`,
4172
- kind: "line",
4173
- closed: !0,
4174
- width: 0.12,
4175
- color: e.inside ? "#d8eb8a" : "#ee9670",
4176
- points: Array.from({ length: 32 }, (n, o) => [e.position[0] + Math.cos(o * Math.PI / 16) * 0.7, 0.06, e.position[2] + Math.sin(o * Math.PI / 16) * 0.7])
4177
- })) : [];
4178
- }
4179
- export {
4180
- ir as $,
4181
- wt as A,
4182
- It as B,
4183
- y0 as C,
4184
- Ls as D,
4185
- Hn as E,
4186
- rr as F,
4187
- ln as G,
4188
- at as H,
4189
- jr as I,
4190
- l0 as J,
4191
- bn as K,
4192
- i0 as L,
4193
- Zr as M,
4194
- e0 as N,
4195
- le as O,
4196
- ca as P,
4197
- Ks as Q,
4198
- Gt as R,
4199
- xo as S,
4200
- Ao as T,
4201
- ja as U,
4202
- h0 as V,
4203
- Pa as W,
4204
- Qa as X,
4205
- xs as Y,
4206
- Ta as Z,
4207
- Yr as _,
4208
- wn as a,
4209
- xa as a$,
4210
- kt as a0,
4211
- Ga as a1,
4212
- Ya as a2,
4213
- Da as a3,
4214
- _r as a4,
4215
- Xa as a5,
4216
- ft as a6,
4217
- Va as a7,
4218
- tt as a8,
4219
- Do as a9,
4220
- yo as aA,
4221
- Lr as aB,
4222
- en as aC,
4223
- sr as aD,
4224
- Fe as aE,
4225
- Le as aF,
4226
- je as aG,
4227
- Vs as aH,
4228
- Ua as aI,
4229
- Ma as aJ,
4230
- n0 as aK,
4231
- Za as aL,
4232
- mo as aM,
4233
- Oa as aN,
4234
- Fr as aO,
4235
- ya as aP,
4236
- ms as aQ,
4237
- li as aR,
4238
- Ee as aS,
4239
- o0 as aT,
4240
- Ka as aU,
4241
- Di as aV,
4242
- Ce as aW,
4243
- Qi as aX,
4244
- Wi as aY,
4245
- na as aZ,
4246
- ia as a_,
4247
- Ja as aa,
4248
- Ts as ab,
4249
- Os as ac,
4250
- Is as ad,
4251
- wa as ae,
4252
- ls as af,
4253
- Zi as ag,
4254
- zi as ah,
4255
- Ti as ai,
4256
- zn as aj,
4257
- ni as ak,
4258
- Fs as al,
4259
- ue as am,
4260
- ao as an,
4261
- Mo as ao,
4262
- ba as ap,
4263
- ii as aq,
4264
- ua as ar,
4265
- f0 as as,
4266
- Aa as at,
4267
- s0 as au,
4268
- u0 as av,
4269
- c0 as aw,
4270
- Ia as ax,
4271
- a0 as ay,
4272
- r0 as az,
4273
- Pt as b,
4274
- ri as b0,
4275
- Yo as b1,
4276
- Cr as b2,
4277
- Dt as b3,
4278
- ne as b4,
4279
- qa as b5,
4280
- Mn as b6,
4281
- d0 as b7,
4282
- hr as b8,
4283
- fa as b9,
4284
- cr as ba,
4285
- pn as bb,
4286
- ut as bc,
4287
- lr as bd,
4288
- va as c,
4289
- si as d,
4290
- za as e,
4291
- Wa as f,
4292
- m0 as g,
4293
- x0 as h,
4294
- M0 as i,
4295
- ko as j,
4296
- ce as k,
4297
- p0 as l,
4298
- _a as m,
4299
- t0 as n,
4300
- g0 as o,
4301
- ha as p,
4302
- Fa as q,
4303
- Re as r,
4304
- oi as s,
4305
- $a as t,
4306
- Ha as u,
4307
- w0 as v,
4308
- b0 as w,
4309
- La as x,
4310
- k0 as y,
4311
- Ca as z
4312
- };