@algorisys/tinyfly 0.75.0 → 0.77.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,6 +1,37 @@
1
- import { s as A, p as O, a as C } from "./sketch-CB6VNfnR.js";
2
- import { b as be, c as pe } from "./sketch-CB6VNfnR.js";
3
- const B = {
1
+ import { s as xt, p as Dt, c as jt, b as ye } from "./sketch-CA8ZXhxI.js";
2
+ import { a as jn } from "./sketch-CA8ZXhxI.js";
3
+ import { createRandom as me, hashSeed as pe } from "@algorisys/tinyfly";
4
+ function ht(t, e, n) {
5
+ const o = t.length;
6
+ if (o < 2) return [];
7
+ const r = [], s = [], h = (i) => e + (n - e) * i / (o - 1);
8
+ return t.forEach((i, l) => {
9
+ const a = t[Math.max(0, l - 1)], c = t[Math.min(o - 1, l + 1)], g = Math.hypot(c.x - a.x, c.y - a.y) || 1, y = h(l) / 2, f = -(c.y - a.y) / g * y, d = (c.x - a.x) / g * y;
10
+ r.push({ x: i.x + f, y: i.y + d }), s.push({ x: i.x - f, y: i.y - d });
11
+ }), [...r, ...s.reverse()];
12
+ }
13
+ function Jt(t, e, n, o) {
14
+ const r = e.length;
15
+ if (r < 2) return;
16
+ const s = ht(e, n, o), h = (i) => n + (o - n) * i / (r - 1);
17
+ t.beginPath(), t.moveTo(s[0].x, s[0].y);
18
+ for (const i of s.slice(1)) t.lineTo(i.x, i.y);
19
+ t.closePath(), t.fill(), e.forEach((i, l) => {
20
+ l !== 0 && l !== r - 1 && r > 3 || (t.beginPath(), t.arc(i.x, i.y, h(l) / 2, 0, Math.PI * 2), t.fill());
21
+ });
22
+ }
23
+ function z(t, e, n, o, r = 16) {
24
+ const s = { x: 2 * e.x - (t.x + n.x) / 2, y: 2 * e.y - (t.y + n.y) / 2 }, h = [];
25
+ for (let i = 0; i <= r; i++) {
26
+ const l = i / r, a = l < 0.5 ? { x: t.x + (e.x - t.x) * 2 * l, y: t.y + (e.y - t.y) * 2 * l } : { x: e.x + (n.x - e.x) * (2 * l - 1), y: e.y + (n.y - e.y) * (2 * l - 1) }, c = 1 - l, g = {
27
+ x: c * c * t.x + 2 * c * l * s.x + l * l * n.x,
28
+ y: c * c * t.y + 2 * c * l * s.y + l * l * n.y
29
+ };
30
+ h.push({ x: a.x + (g.x - a.x) * o, y: a.y + (g.y - a.y) * o });
31
+ }
32
+ return h;
33
+ }
34
+ const G = {
4
35
  lean: 0,
5
36
  headTilt: 0,
6
37
  leftShoulder: 18,
@@ -22,12 +53,14 @@ const B = {
22
53
  browTilt: 0,
23
54
  lookX: 0,
24
55
  lookY: 0,
25
- stretch: 1
56
+ stretch: 1,
57
+ turn: 0,
58
+ sit: 0
26
59
  };
27
- function k(e) {
28
- return { ...B, ...e };
60
+ function B(t) {
61
+ return { ...G, ...t };
29
62
  }
30
- const F = {
63
+ const zt = {
31
64
  mouth: 0,
32
65
  smile: 0,
33
66
  mouthWidth: 1,
@@ -38,346 +71,1290 @@ const F = {
38
71
  browTilt: 0,
39
72
  lookX: 0,
40
73
  lookY: 0
41
- }, m = (e) => ({ ...F, ...e }), T = {
42
- neutral: F,
43
- happy: m({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
44
- joyful: m({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
45
- sad: m({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
46
- crying: m({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
47
- surprised: m({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
48
- shocked: m({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
49
- angry: m({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
50
- furious: m({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
51
- worried: m({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
52
- scared: m({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
53
- confused: m({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
54
- skeptical: m({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
55
- thinking: m({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
56
- sleepy: m({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
57
- disgusted: m({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
58
- smug: m({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
59
- wink: m({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
74
+ }, _ = (t) => ({ ...zt, ...t }), N = {
75
+ neutral: zt,
76
+ happy: _({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
77
+ joyful: _({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
78
+ sad: _({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
79
+ crying: _({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
80
+ surprised: _({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
81
+ shocked: _({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
82
+ angry: _({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
83
+ furious: _({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
84
+ worried: _({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
85
+ scared: _({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
86
+ confused: _({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
87
+ skeptical: _({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
88
+ thinking: _({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
89
+ sleepy: _({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
90
+ disgusted: _({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
91
+ smug: _({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
92
+ wink: _({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
60
93
  };
61
- function D(e, t) {
62
- return { ...e, ...typeof t == "string" ? T[t] : t };
63
- }
64
- const U = {
65
- rest: B,
66
- wave: k({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...T.happy }),
67
- cheer: k({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...T.joyful }),
68
- shrug: k({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...T.confused, lookX: 0, lookY: 0 }),
69
- point: k({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
94
+ function we(t, e) {
95
+ return { ...t, ...typeof e == "string" ? N[e] : e };
96
+ }
97
+ const be = {
98
+ rest: G,
99
+ wave: B({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...N.happy }),
100
+ cheer: B({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...N.joyful }),
101
+ shrug: B({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...N.confused, lookX: 0, lookY: 0 }),
102
+ point: B({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
70
103
  // The forearm passes 180° to fold back in, so the hand reaches the chin.
71
- think: k({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...T.thinking }),
72
- handsOnHips: k({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
73
- sad: k({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...T.sad }),
74
- surprised: k({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...T.surprised }),
104
+ think: B({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...N.thinking }),
105
+ handsOnHips: B({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
106
+ sad: B({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...N.sad }),
107
+ surprised: B({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...N.surprised }),
75
108
  // Squash and stretch: the wind-up before a jump (or the landing), and the jump itself.
76
- crouch: k({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
77
- jump: k({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...T.joyful })
78
- }, _ = Object.keys(B);
79
- function $(e, t, o) {
80
- const r = { ...e };
81
- for (const n of _) r[n] = e[n] + (t[n] - e[n]) * o;
82
- return r;
83
- }
84
- const X = 24, V = 40;
85
- function z(e, t = B, o = 1) {
86
- const r = Math.sin(e * Math.PI * 2) * o, n = Math.cos(e * Math.PI * 2) * o, i = (h) => h <= V ? 22 * r : h;
109
+ crouch: B({ stretch: 0.72, leftShoulder: 35, rightShoulder: 35, leftElbow: -50, rightElbow: -50, leftHip: 22, rightHip: 22, headTilt: -4 }),
110
+ // Seated, hands resting on the knees. Arm angles spread outward per side, so
111
+ // reaching forward (+x, the way the figure faces) is negative for the left arm.
112
+ sit: B({ sit: 1, turn: 0.5, leftShoulder: -25, rightShoulder: 25, leftElbow: -55, rightElbow: 55 }),
113
+ jump: B({ stretch: 1.22, leftShoulder: 140, rightShoulder: 140, leftElbow: 20, rightElbow: 20, leftHip: 4, rightHip: 4, ...N.joyful })
114
+ }, Gt = Object.keys(G);
115
+ function Me(t, e, n) {
116
+ const o = { ...t };
117
+ for (const r of Gt) o[r] = t[r] + (e[r] - t[r]) * n;
118
+ return o;
119
+ }
120
+ const St = 24, _t = 4, Yt = 28, ke = 40;
121
+ function Ee(t, e = G, n = 1) {
122
+ const o = Math.sin(t * Math.PI * 2) * n, r = Math.cos(t * Math.PI * 2) * n, s = (a) => a <= ke, h = (a) => s(a) ? 22 * o : a, i = s(e.leftShoulder) ? e.leftElbow - Yt * Math.max(0, -o) : e.leftElbow, l = s(e.rightShoulder) ? e.rightElbow + Yt * Math.max(0, o) : e.rightElbow;
87
123
  return {
88
- ...t,
124
+ ...e,
125
+ // Lean into the walk, and keep the head a little more level than the body.
126
+ lean: e.lean + _t * n,
127
+ headTilt: e.headTilt - _t * 0.5 * n,
128
+ leftElbow: i,
129
+ rightElbow: l,
89
130
  // Left foot forward while swing > 0, right foot back; then the other way.
90
- leftHip: -X * r,
91
- rightHip: -X * r,
131
+ leftHip: -St * o,
132
+ rightHip: -St * o,
92
133
  // The leg swinging forward lifts, its shin trailing backward (-x). A positive
93
134
  // knee folds toward the centre, which is backward only for the right leg.
94
- leftKnee: -30 * Math.max(0, n),
95
- rightKnee: 30 * Math.max(0, -n),
135
+ leftKnee: -30 * Math.max(0, r),
136
+ rightKnee: 30 * Math.max(0, -r),
96
137
  // Arms swing against the legs: left arm back while the left foot is forward.
97
- leftShoulder: i(t.leftShoulder),
98
- rightShoulder: i(t.rightShoulder)
138
+ leftShoulder: h(e.leftShoulder),
139
+ rightShoulder: h(e.rightShoulder)
99
140
  };
100
141
  }
101
- function se(e, t = 1) {
102
- return 4 * ((K + L) * e) * Math.sin(X * t * Math.PI / 180);
142
+ function Sn(t, e = 1) {
143
+ return 4 * ((Pt + ct) * t) * Math.sin(St * e * Math.PI / 180);
144
+ }
145
+ function xe(t) {
146
+ const e = Math.abs(Math.sin(t / 65)), n = 0.55 + 0.45 * Math.sin(t / 310);
147
+ return e * n;
103
148
  }
104
- function Q(e) {
105
- const t = Math.abs(Math.sin(e / 65)), o = 0.55 + 0.45 * Math.sin(e / 310);
106
- return t * o;
149
+ const Zt = 0.12, $t = 0.46, Se = 1 - 2 * Zt, Pe = 0.1, Te = 0.21, ve = 0.19, Pt = 0.24, ct = 0.22, Qt = 0.12, We = 0.14, Vt = 0.33, Bt = 0.7, Rt = 0.3, Oe = 0.35, Ie = [1.7, 1.05], Ae = [1.3, 0.75], Lt = [1.45, 0.85], He = [1.15, 0.75], Ft = 0.06, _e = 0.7, Ye = 0.65, $e = 0.3, Be = 0.02, Re = 0.012, Le = 12, Fe = 0.25, ot = 90, Ne = 0.25, Ce = 0.01, J = (t) => Math.min(1, Math.max(0, t ?? 0));
150
+ function Pn(t, e = 1) {
151
+ return ct * t * e;
107
152
  }
108
- const Z = 0.12, j = 0.1, x = 0.21, ee = 0.19, K = 0.24, L = 0.22, Y = (e) => e * Math.PI / 180, oe = (e, t) => ({ x: t * Math.sin(Y(e)), y: Math.cos(Y(e)) });
109
- function te(e, t, o, r, n, i) {
110
- const h = Math.max(1, i * 0.6), l = 0.12 * o, s = r - 0.12 * o, a = l + t.lookX * 0.08 * o, f = t.lookY * 0.07 * o, y = [
111
- { x: -0.34 * o, open: t.leftEye, brow: t.leftBrow, side: -1 },
112
- { x: 0.34 * o, open: t.rightEye, brow: t.rightBrow, side: 1 }
153
+ const Tt = -0.12, te = 0.4, C = (t) => t * Math.PI / 180, Xe = (t, e) => ({ x: e * Math.sin(C(t)), y: Math.cos(C(t)) }), ee = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), ne = (t, e, n, o) => t - 0.3 * e - n * 0.14 * e - Math.max(0, o - 1) * 0.12 * e;
154
+ function qe(t, e, n, o, r, s) {
155
+ const h = Math.max(1, Math.min(s * 0.6, We * n)), i = J(e.turn), l = (Qt + Vt * i) * n, a = o + Tt * n, c = l + e.lookX * 0.08 * n, g = e.lookY * 0.07 * n, y = [
156
+ // The left eye is on the far side; turning closes it up more than the near one.
157
+ { x: -0.34 * n * (1 - Bt * i), squeeze: 1 - Bt * i, open: e.leftEye, brow: e.leftBrow, side: -1 },
158
+ { x: 0.34 * n * (1 - Rt * i), squeeze: 1 - Rt * i, open: e.rightEye, brow: e.rightBrow, side: 1 }
113
159
  ];
114
- e.fillStyle = n, e.strokeStyle = n, e.lineWidth = h;
115
- for (const b of y) {
116
- const E = Math.max(0, b.open) * (1 - Math.min(1, Math.max(0, t.blink)));
117
- if (E < 0.2) {
118
- const d = t.smile > 0.5 ? -0.12 * o : 0.06 * o;
119
- e.beginPath(), e.moveTo(b.x + l - 0.12 * o, s), e.quadraticCurveTo(b.x + l, s + d, b.x + l + 0.12 * o, s), e.stroke();
160
+ t.fillStyle = r, t.strokeStyle = r, t.lineWidth = h;
161
+ for (const u of y) {
162
+ const k = ee(u.open, e.blink);
163
+ if (k < 0.2) {
164
+ const P = e.smile > 0.5 ? -0.12 * n : 0.06 * n;
165
+ t.beginPath(), t.moveTo(u.x + l - 0.12 * n, a), t.quadraticCurveTo(u.x + l, a + P, u.x + l + 0.12 * n, a), t.stroke();
120
166
  } else {
121
- if (E > 1.2) {
122
- const p = 0.13 * o * E;
123
- e.beginPath(), e.ellipse(b.x + l, s, p * 0.85, p, 0, 0, Math.PI * 2), e.fillStyle = "#ffffff", e.fill(), e.stroke(), e.fillStyle = n;
167
+ if (k > 1.2) {
168
+ const S = 0.13 * n * k;
169
+ t.beginPath(), t.ellipse(u.x + l, a, S * 0.85, S, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = r;
124
170
  }
125
- const d = E > 1.2 ? 0.075 * o : 0.1 * o;
126
- e.beginPath(), e.ellipse(b.x + a, s + f, d, d * 1.1 * Math.min(E, 1), 0, 0, Math.PI * 2), e.fill();
171
+ const P = k > 1.2 ? 0.075 * n : 0.1 * n;
172
+ t.beginPath(), t.ellipse(u.x + c, a + g, P, P * 1.1 * Math.min(k, 1), 0, 0, Math.PI * 2), t.fill();
127
173
  }
128
- const P = s - 0.3 * o - b.brow * 0.14 * o - Math.max(0, E - 1) * 0.12 * o, W = b.x + l - b.side * 0.13 * o, H = b.x + l + b.side * 0.13 * o;
129
- e.beginPath(), e.moveTo(H, P), e.lineTo(W, P - t.browTilt * 0.1 * o), e.stroke();
174
+ const E = ne(a, n, u.brow, k), b = u.x + l - u.side * 0.13 * n * u.squeeze, M = u.x + l + u.side * 0.13 * n * u.squeeze;
175
+ t.beginPath(), t.moveTo(M, E), t.lineTo(b, E - e.browTilt * 0.1 * n), t.stroke();
130
176
  }
131
- const u = r + 0.4 * o, g = 0.25 * o * Math.max(0.3, t.mouthWidth), S = Math.min(1, Math.max(0, t.mouth));
132
- if (e.beginPath(), S <= 0.05) {
133
- e.moveTo(l - g, u), e.quadraticCurveTo(l, u + t.smile * 0.25 * o, l + g, u), e.stroke();
177
+ const f = o + te * n, d = 0.25 * n * Math.max(0.3, e.mouthWidth) * (1 - Oe * i), w = Math.min(1, Math.max(0, e.mouth));
178
+ if (t.beginPath(), w <= 0.05) {
179
+ t.moveTo(l - d, f), t.quadraticCurveTo(l, f + e.smile * 0.25 * n, l + d, f), t.stroke();
134
180
  return;
135
181
  }
136
- const w = 0.3 * o * S;
137
- t.smile > 0.3 ? (e.moveTo(l - g, u - 0.05 * o), e.lineTo(l + g, u - 0.05 * o), e.quadraticCurveTo(l, u + w * 2, l - g, u - 0.05 * o)) : t.smile < -0.3 ? (e.moveTo(l - g, u + w * 0.6), e.lineTo(l + g, u + w * 0.6), e.quadraticCurveTo(l, u - w * 1.4, l - g, u + w * 0.6)) : e.ellipse(l, u, g * 0.8, w, 0, 0, Math.PI * 2), e.fill();
138
- }
139
- function le(e, t, o, r, n = 16) {
140
- const i = { x: 2 * t.x - (e.x + o.x) / 2, y: 2 * t.y - (e.y + o.y) / 2 }, h = [];
141
- for (let l = 0; l <= n; l++) {
142
- const s = l / n, a = s < 0.5 ? { x: e.x + (t.x - e.x) * 2 * s, y: e.y + (t.y - e.y) * 2 * s } : { x: t.x + (o.x - t.x) * (2 * s - 1), y: t.y + (o.y - t.y) * (2 * s - 1) }, f = 1 - s, y = {
143
- x: f * f * e.x + 2 * f * s * i.x + s * s * o.x,
144
- y: f * f * e.y + 2 * f * s * i.y + s * s * o.y
145
- };
146
- h.push({ x: a.x + (y.x - a.x) * r, y: a.y + (y.y - a.y) * r });
147
- }
148
- return h;
182
+ const m = 0.3 * n * w;
183
+ e.smile > 0.3 ? (t.moveTo(l - d, f - 0.05 * n), t.lineTo(l + d, f - 0.05 * n), t.quadraticCurveTo(l, f + m * 2, l - d, f - 0.05 * n)) : e.smile < -0.3 ? (t.moveTo(l - d, f + m * 0.6), t.lineTo(l + d, f + m * 0.6), t.quadraticCurveTo(l, f - m * 1.4, l - d, f + m * 0.6)) : t.ellipse(l, f, d * 0.8, m, 0, 0, Math.PI * 2), t.fill();
149
184
  }
150
- function ne(e, t, o = {}, r = 0) {
151
- const n = o.height ?? 300, i = o.color ?? "#1e293b", h = (o.facing ?? 1) < 0 ? -1 : 1, l = Math.min(3, Math.max(0.3, t.stretch ?? 1)), s = Math.sqrt(l), a = Z * n, f = a / Math.sqrt(l), y = a * Math.sqrt(l), u = -0.46 * n * l, g = -0.76 * n * l;
152
- e.save(), e.scale(h, 1), e.strokeStyle = i, e.lineWidth = o.lineWidth ?? n * 0.025, e.lineCap = "round", e.lineJoin = "round";
153
- const S = (d, p, M, c, v) => {
154
- const I = oe(M, c);
155
- return { x: d + I.x * v * n, y: p + I.y * v * n };
156
- }, w = o.sketch ? A(e, o.sketch, r) : void 0, b = (...d) => {
157
- if (w) return w.line(d);
158
- e.beginPath(), e.moveTo(d[0].x, d[0].y);
159
- for (const p of d.slice(1)) e.lineTo(p.x, p.y);
160
- e.stroke();
161
- }, E = (d, p, M) => {
162
- const c = Math.min(1, Math.max(0, o.rubber ?? 0));
163
- if (c === 0) return b(d, p, M);
164
- const v = le(d, p, M, c);
165
- if (w) return w.curve(v);
166
- e.beginPath(), e.moveTo(v[0].x, v[0].y);
167
- for (const I of v.slice(1)) e.lineTo(I.x, I.y);
168
- e.stroke();
185
+ function oe(t, e) {
186
+ const n = e.height ?? 300, o = Math.min(3, Math.max(0.3, t.stretch ?? 1)), r = Math.sqrt(o), s = (e.headSize ?? 2 * Zt) / 2, h = e.headSize === void 0 ? Se : 1 - 2 * s, i = s * n, l = J(t.sit), a = t.leftHip + (-ot - t.leftHip) * l, c = t.leftKnee + (-ot - t.leftKnee) * l, g = t.rightHip + (ot - t.rightHip) * l, y = t.rightKnee + (ot - t.rightKnee) * l, f = e.classic === !0, d = J(t.turn), w = (x, p, T) => {
187
+ const v = C(p - T) / 2, O = d + (1 - d) * x * _e;
188
+ return f ? { x: 0, y: 0 } : { x: Math.cos(v) * Ft * O, y: Math.abs(Math.sin(v)) * Ft };
169
189
  };
170
- for (const [d, p, M] of [
171
- [-1, t.leftHip, t.leftKnee],
172
- [1, t.rightHip, t.rightKnee]
173
- ]) {
174
- const c = S(0, u, p, d, K * l);
175
- E({ x: 0, y: u }, c, S(c.x, c.y, p - M, d, L * l));
190
+ let m = 0;
191
+ if (l > 0 || !f) {
192
+ const x = (v, O, A) => Pt * Math.cos(C(O)) + ct * Math.cos(C(O - A)) + w(v, O, A).y, p = Math.max(x(-1, a, c), x(1, g, y)), T = f ? Math.min(1, l / Ne) : 1;
193
+ m = ($t - p) * T * n * o;
176
194
  }
177
- e.translate(0, u), e.rotate(Y(t.lean)), e.translate(0, -u), b({ x: 0, y: u }, { x: 0, y: g });
178
- const P = g + j * n * l;
179
- for (const [d, p, M] of [
180
- [-1, t.leftShoulder, t.leftElbow],
181
- [1, t.rightShoulder, t.rightElbow]
195
+ const u = -$t * n * o + m, k = -h * n * o + m, E = f ? 0 : (Be * J(t.turn) + Re * l) * n * o, b = E === 0 ? [{ x: 0, y: u }, { x: 0, y: k }] : z({ x: 0, y: u }, { x: -E, y: (u + k) / 2 }, { x: 0, y: k }, 1, 8), M = k + Pe * n * o, P = (e.shoulderWidth ?? 0) * n * Math.cos(d * Math.PI / 2), S = (x, p, T, v, O) => {
196
+ const A = Xe(T, v);
197
+ return { x: x + A.x * O * n, y: p + A.y * O * n };
198
+ }, W = (x, p, T) => {
199
+ const v = S(0, u, p, x, Pt * o);
200
+ return { root: { x: 0, y: u }, joint: v, end: S(v.x, v.y, p - T, x, ct * o) };
201
+ }, H = (x, p, T) => {
202
+ const v = { x: x * P, y: M }, O = S(v.x, v.y, p, x, Te * r);
203
+ return { root: v, joint: O, end: S(O.x, O.y, p + T, x, ve * r) };
204
+ }, Y = { left: W(-1, a, c), right: W(1, g, y) }, I = (x, p, T, v) => {
205
+ const O = w(x, T, v);
206
+ return { x: p.end.x + O.x * n * o, y: p.end.y + O.y * n * o };
207
+ };
208
+ return {
209
+ height: n,
210
+ facing: (e.facing ?? 1) < 0 ? -1 : 1,
211
+ stretch: o,
212
+ lineWidth: e.lineWidth ?? n * 0.025,
213
+ rubber: Math.min(1, Math.max(f ? 0 : $e, e.rubber ?? 0)),
214
+ r: i,
215
+ // The head keeps its area: taller and narrower when stretched.
216
+ headRx: i / Math.sqrt(o),
217
+ headRy: i * Math.sqrt(o),
218
+ hipY: u,
219
+ neckY: k,
220
+ drop: m,
221
+ lean: f ? t.lean : t.lean + Le * Math.sin(Math.PI * l),
222
+ classic: f,
223
+ legs: Y,
224
+ toes: { left: I(-1, Y.left, a, c), right: I(1, Y.right, g, y) },
225
+ spine: b,
226
+ arms: {
227
+ left: H(-1, t.leftShoulder, t.leftElbow),
228
+ right: H(1, t.rightShoulder, t.rightElbow)
229
+ }
230
+ };
231
+ }
232
+ const V = (t, e) => e === 0 ? [t.root, t.joint, t.end] : z(t.root, t.joint, t.end, e);
233
+ function vt(t, e, n) {
234
+ const o = Math.cos(n), r = Math.sin(n), s = t.x - e.x, h = t.y - e.y;
235
+ return { x: e.x + s * o - h * r, y: e.y + s * r + h * o };
236
+ }
237
+ function se(t, e) {
238
+ const n = C(t.lean), o = C(e.headTilt), r = { x: 0, y: t.hipY }, s = (u) => ({ x: t.facing * u.x, y: u.y }), h = (u) => s(vt(u, r, n)), i = (u) => h(vt({ x: u.x, y: u.y + t.neckY }, { x: 0, y: t.neckY }, o)), l = V(t.arms.left, t.rubber).map(h), a = V(t.arms.right, t.rubber).map(h), c = (u) => {
239
+ const [k, E] = u.slice(-2);
240
+ return Math.atan2(E.y - k.y, E.x - k.x);
241
+ };
242
+ let g = 1 / 0;
243
+ for (const [u, k] of [
244
+ [e.leftBrow, e.leftEye],
245
+ [e.rightBrow, e.rightEye]
182
246
  ]) {
183
- const c = S(0, P, p, d, x * s);
184
- E(
185
- { x: 0, y: P },
186
- c,
187
- S(c.x, c.y, p + M, d, ee * s)
188
- );
247
+ const E = ne(Tt, 1, u, ee(k, e.blink));
248
+ g = Math.min(g, E, E - e.browTilt * 0.1);
189
249
  }
190
- e.translate(0, g), e.rotate(Y(t.headTilt));
191
- const W = -y;
192
- e.beginPath(), e.ellipse(0, W, f, y, 0, 0, Math.PI * 2);
193
- const H = o.headFill ?? "#ffffff";
194
- if (H !== "none" && (e.fillStyle = H, e.fill()), w) {
195
- w.ellipse(0, W, f, y);
196
- const d = w.nudge();
197
- e.translate(d.x, d.y);
198
- } else
199
- e.stroke();
200
- e.translate(0, W), e.scale(f / a, y / a), te(e, t, a, 0, i, o.lineWidth ?? n * 0.025), e.restore(), o.label && (e.save(), e.fillStyle = i, e.font = o.labelFont ?? `700 ${Math.round(n * 0.11)}px sans-serif`, e.textAlign = "center", e.textBaseline = "bottom", e.fillText(o.label, 0, -n * l - 0.04 * n), e.restore());
250
+ const y = { left: s(t.legs.left.end), right: s(t.legs.right.end) }, f = { left: s(t.toes.left), right: s(t.toes.right) }, d = { left: Math.max(y.left.y, f.left.y), right: Math.max(y.right.y, f.right.y) }, w = Math.max(d.left, d.right), m = Ce * t.height;
251
+ return {
252
+ facing: t.facing,
253
+ height: t.height,
254
+ stretch: t.stretch,
255
+ lineWidth: t.lineWidth,
256
+ hip: r,
257
+ neck: h({ x: 0, y: t.neckY }),
258
+ shoulders: { left: h(t.arms.left.root), right: h(t.arms.right.root) },
259
+ elbows: { left: h(t.arms.left.joint), right: h(t.arms.right.joint) },
260
+ hands: { left: h(t.arms.left.end), right: h(t.arms.right.end) },
261
+ knees: { left: s(t.legs.left.joint), right: s(t.legs.right.joint) },
262
+ feet: y,
263
+ toes: f,
264
+ feetY: w,
265
+ grounded: { left: d.left >= w - m, right: d.right >= w - m },
266
+ handAngle: { left: c(l), right: c(a) },
267
+ limbs: {
268
+ leftArm: l,
269
+ rightArm: a,
270
+ leftLeg: V(t.legs.left, t.rubber).map(s),
271
+ rightLeg: V(t.legs.right, t.rubber).map(s),
272
+ spine: t.spine.map(h)
273
+ },
274
+ head: {
275
+ center: i({ x: 0, y: -t.headRy }),
276
+ rx: t.headRx,
277
+ ry: t.headRy,
278
+ // Mirroring a turn reverses it.
279
+ angle: t.facing * (n + o),
280
+ eyeY: Tt,
281
+ browTopY: g,
282
+ mouthY: te,
283
+ faceX: t.facing * (Qt + Vt * J(e.turn))
284
+ }
285
+ };
286
+ }
287
+ function Ue(t, e = {}) {
288
+ return se(oe(t, e), t);
289
+ }
290
+ function Tn(t, e, n) {
291
+ return vt({ x: t.center.x + e * t.rx, y: t.center.y + n * t.ry }, t.center, t.angle);
292
+ }
293
+ function Ke(t, e, n) {
294
+ const o = (s) => ({ x: s.x + e, y: s.y + n }), r = (s) => ({ left: o(s.left), right: o(s.right) });
295
+ return {
296
+ ...t,
297
+ hip: o(t.hip),
298
+ neck: o(t.neck),
299
+ shoulders: r(t.shoulders),
300
+ elbows: r(t.elbows),
301
+ hands: r(t.hands),
302
+ knees: r(t.knees),
303
+ feet: r(t.feet),
304
+ toes: r(t.toes),
305
+ feetY: t.feetY + n,
306
+ grounded: { ...t.grounded },
307
+ handAngle: { ...t.handAngle },
308
+ limbs: {
309
+ leftArm: t.limbs.leftArm.map(o),
310
+ rightArm: t.limbs.rightArm.map(o),
311
+ leftLeg: t.limbs.leftLeg.map(o),
312
+ rightLeg: t.limbs.rightLeg.map(o),
313
+ spine: t.limbs.spine.map(o)
314
+ },
315
+ head: { ...t.head, center: o(t.head.center) }
316
+ };
317
+ }
318
+ function De(t, e, n = {}, o = 0) {
319
+ const r = oe(e, n), s = n.color ?? "#1e293b", h = n.layers ?? {}, i = n.layers ? se(r, e) : void 0, l = n.sketch ? xt(t, n.sketch, o) : void 0, a = n.sketch && n.layers ? xt(t, n.sketch, o) : void 0, c = (b) => {
320
+ t.save(), b(), t.restore();
321
+ }, g = (b) => {
322
+ b && i && c(() => b(t, i, o, a));
323
+ }, y = () => t.scale(r.facing, 1), f = () => {
324
+ y(), t.translate(0, r.hipY), t.rotate(C(r.lean)), t.translate(0, -r.hipY);
325
+ }, d = (b, M, P) => {
326
+ if (l) return M ? l.curve(b) : l.line(b);
327
+ if (r.classic) {
328
+ t.beginPath(), t.moveTo(b[0].x, b[0].y);
329
+ for (const S of b.slice(1)) t.lineTo(S.x, S.y);
330
+ t.stroke();
331
+ return;
332
+ }
333
+ Jt(t, b, P[0] * r.lineWidth, P[1] * r.lineWidth);
334
+ }, w = (b, M) => d(V(b, r.rubber), r.rubber > 0, M), m = (b) => {
335
+ r.classic || d([r.legs[b].end, r.toes[b]], !1, He);
336
+ }, u = (b) => {
337
+ if (r.classic || l) return;
338
+ const M = r.arms[b].end;
339
+ t.beginPath(), t.arc(M.x, M.y, Ye * r.lineWidth, 0, Math.PI * 2), t.fill();
340
+ };
341
+ t.save(), t.strokeStyle = s, t.fillStyle = s, t.lineWidth = r.lineWidth, t.lineCap = "round", t.lineJoin = "round";
342
+ const k = (b) => {
343
+ c(() => {
344
+ f(), w(r.arms[b], Ae), u(b);
345
+ });
346
+ const M = h.sleeve;
347
+ M && i && c(() => M(t, i, b, o, a));
348
+ }, E = J(e.turn) > Fe;
349
+ g(h.behind), c(() => {
350
+ y(), w(r.legs.left, Lt), m("left"), w(r.legs.right, Lt), m("right");
351
+ }), E && k("left"), c(() => {
352
+ f(), d(r.spine, r.spine.length > 2, Ie);
353
+ const { left: b, right: M } = { left: r.arms.left.root, right: r.arms.right.root };
354
+ if (b.x !== M.x)
355
+ if (r.classic) d([b, M], !1, [1, 1]);
356
+ else {
357
+ const P = { x: (b.x + M.x) / 2, y: b.y - 0.3 * Math.abs(M.x - b.x) };
358
+ d(z(b, P, M, 1, 8), !0, [1.1, 1.1]);
359
+ }
360
+ }), g(h.body), E || k("left"), k("right"), g(h.behindHead), c(() => {
361
+ f(), t.translate(0, r.neckY), t.rotate(C(e.headTilt));
362
+ const b = -r.headRy;
363
+ t.beginPath(), t.ellipse(0, b, r.headRx, r.headRy, 0, 0, Math.PI * 2);
364
+ const M = n.headFill ?? "#ffffff";
365
+ if (M !== "none" && (t.fillStyle = M, t.fill()), l) {
366
+ l.ellipse(0, b, r.headRx, r.headRy);
367
+ const P = l.nudge();
368
+ t.translate(P.x, P.y);
369
+ } else
370
+ t.stroke();
371
+ t.translate(0, b), t.scale(r.headRx / r.r, r.headRy / r.r), qe(t, e, r.r, 0, s, r.lineWidth);
372
+ }), g(h.overHead), g(h.front), t.restore(), n.label && (t.save(), t.fillStyle = s, t.font = n.labelFont ?? `700 ${Math.round(r.height * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(n.label, 0, -r.height * r.stretch - 0.04 * r.height + r.drop), t.restore());
373
+ }
374
+ function re(t, e) {
375
+ const n = { ...t };
376
+ let o = t.walking > 0 ? Me(n, Ee(t.walk, n), t.walking) : n;
377
+ return t.talk > 0 && (o = { ...o, mouth: Math.max(o.mouth, t.talk * xe(e)) }), o;
201
378
  }
202
- function he(e) {
203
- const t = e.style ?? {}, o = t.height ?? 300, r = o * 0.8, n = { ...k(e.pose ?? {}), walk: 0, walking: 0, talk: 0, rubber: t.rubber ?? 0 };
379
+ function vn(t) {
380
+ const e = t.style ?? {}, n = e.height ?? 300, o = n * 0.8, r = { ...B(t.pose ?? {}), walk: 0, walking: 0, talk: 0, rubber: e.rubber ?? 0 };
204
381
  return {
205
382
  type: "custom",
206
- x: e.x - r / 2,
207
- y: e.y - o,
208
- width: r,
209
- height: o,
210
- props: { ...n },
211
- draw(i, h, l) {
212
- const s = h.props, a = { ...s };
213
- let f = s.walking > 0 ? $(a, z(s.walk, a), s.walking) : a;
214
- s.talk > 0 && (f = { ...f, mouth: Math.max(f.mouth, s.talk * Q(l)) }), i.translate(r / 2, o), ne(i, f, { ...t, rubber: s.rubber }, l);
383
+ x: t.x - o / 2,
384
+ y: t.y - n,
385
+ width: o,
386
+ height: n,
387
+ props: { ...r },
388
+ figureStyle: e,
389
+ draw(s, h, i) {
390
+ const l = h.props;
391
+ s.translate(o / 2, n), De(s, re(l, i), { ...e, rubber: l.rubber }, i);
215
392
  }
216
393
  };
217
394
  }
218
- function ae(e, t) {
219
- const o = [];
220
- return t.forEach((r, n) => {
221
- const i = n === 0 ? B : o[n - 1], h = typeof r.pose == "string" ? U[r.pose] : { ...i, ...r.pose };
222
- o.push(r.expression ? D(h, r.expression) : h);
223
- }), _.filter((r) => o.some((n) => n[r] !== B[r])).map((r) => ({
224
- id: `${e}-${r}`,
225
- target: e,
226
- property: r,
227
- keyframes: t.map((n, i) => ({
228
- time: n.time,
229
- value: o[i][r],
230
- ...n.easing ? { easing: n.easing } : {}
395
+ function Wn(t, e, n) {
396
+ const o = t.figureStyle;
397
+ if (!o) throw new Error("stickFigureAt: the target was not made by stickFigureTarget");
398
+ const r = { ...t.props };
399
+ let s = 0, h = 0;
400
+ for (const [a, c] of e.state?.values.get(n) ?? [])
401
+ typeof c == "number" && (a === "x" || a === "motionPathX" ? s = c : a === "y" || a === "motionPathY" ? h = c : a in r && (r[a] = c));
402
+ const i = re(r, e.time), l = Ue(i, { ...o, rubber: r.rubber });
403
+ return { pose: i, joints: Ke(l, t.x + s + t.width / 2, t.y + h + t.height) };
404
+ }
405
+ function On(t, e) {
406
+ const n = [];
407
+ return e.forEach((o, r) => {
408
+ const s = r === 0 ? G : n[r - 1], h = typeof o.pose == "string" ? be[o.pose] : { ...s, ...o.pose };
409
+ n.push(o.expression ? we(h, o.expression) : h);
410
+ }), Gt.filter((o) => n.some((r) => r[o] !== G[o])).map((o) => ({
411
+ id: `${t}-${o}`,
412
+ target: t,
413
+ property: o,
414
+ keyframes: e.map((r, s) => ({
415
+ time: r.time,
416
+ value: n[s][o],
417
+ ...r.easing ? { easing: r.easing } : {}
231
418
  }))
232
419
  }));
233
420
  }
234
- function ie(e, t, o = {}, r) {
235
- const n = o.length ?? 240, i = 9, h = 28, l = n - 22;
236
- e.save(), e.translate(t.x, t.y), e.rotate((o.angle ?? -30) * Math.PI / 180), e.fillStyle = o.color ?? "#f4c542", e.fillRect(h, -i, l - h, 2 * i), e.fillStyle = "#e8b4a0", e.fillRect(l, -i, n - l, 2 * i), e.fillStyle = "#f1dcbf", e.beginPath(), e.moveTo(0, 0), e.lineTo(h, -i), e.lineTo(h, i), e.closePath(), e.fill(), e.fillStyle = o.outline ?? "#2f2f33", e.beginPath(), e.moveTo(0, 0), e.lineTo(h * 0.35, -i * 0.35), e.lineTo(h * 0.35, i * 0.35), e.closePath(), e.fill(), e.strokeStyle = o.outline ?? "#2f2f33", e.lineWidth = 3, e.lineJoin = "round", e.lineCap = "round";
237
- const s = [
238
- [{ x: 0, y: 0 }, { x: h, y: -i }, { x: n, y: -i }, { x: n, y: i }, { x: h, y: i }, { x: 0, y: 0 }],
239
- [{ x: h, y: -i }, { x: h, y: i }],
240
- [{ x: l, y: -i }, { x: l, y: i }]
241
- ];
242
- for (const a of s) J(e, a, r);
243
- e.restore();
244
- }
245
- function N(e, t, o = {}, r) {
246
- const n = o.length ?? 90, i = o.thickness ?? 34;
247
- e.save(), e.translate(t.x, t.y), e.rotate((o.angle ?? -35) * Math.PI / 180);
248
- const h = -i / 2;
249
- e.fillStyle = o.color ?? "#f4a7b9", e.fillRect(0, h, n, i), e.fillStyle = "#e9edf2", e.fillRect(n * 0.45, h, n * 0.55, i), e.strokeStyle = o.outline ?? "#2f2f33", e.lineWidth = 3, e.lineJoin = "round";
421
+ function je(t, e, n = {}, o) {
422
+ const r = n.length ?? 240, s = 9, h = 28, i = r - 22;
423
+ t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -30) * Math.PI / 180), t.fillStyle = n.color ?? "#f4c542", t.fillRect(h, -s, i - h, 2 * s), t.fillStyle = "#e8b4a0", t.fillRect(i, -s, r - i, 2 * s), t.fillStyle = "#f1dcbf", t.beginPath(), t.moveTo(0, 0), t.lineTo(h, -s), t.lineTo(h, s), t.closePath(), t.fill(), t.fillStyle = n.outline ?? "#2f2f33", t.beginPath(), t.moveTo(0, 0), t.lineTo(h * 0.35, -s * 0.35), t.lineTo(h * 0.35, s * 0.35), t.closePath(), t.fill(), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round", t.lineCap = "round";
250
424
  const l = [
425
+ [{ x: 0, y: 0 }, { x: h, y: -s }, { x: r, y: -s }, { x: r, y: s }, { x: h, y: s }, { x: 0, y: 0 }],
426
+ [{ x: h, y: -s }, { x: h, y: s }],
427
+ [{ x: i, y: -s }, { x: i, y: s }]
428
+ ];
429
+ for (const a of l) he(t, a, o);
430
+ t.restore();
431
+ }
432
+ function ie(t, e, n = {}, o) {
433
+ const r = n.length ?? 90, s = n.thickness ?? 34;
434
+ t.save(), t.translate(e.x, e.y), t.rotate((n.angle ?? -35) * Math.PI / 180);
435
+ const h = -s / 2;
436
+ t.fillStyle = n.color ?? "#f4a7b9", t.fillRect(0, h, r, s), t.fillStyle = "#e9edf2", t.fillRect(r * 0.45, h, r * 0.55, s), t.strokeStyle = n.outline ?? "#2f2f33", t.lineWidth = 3, t.lineJoin = "round";
437
+ const i = [
251
438
  { x: 0, y: h },
252
- { x: n, y: h },
253
- { x: n, y: -h },
439
+ { x: r, y: h },
440
+ { x: r, y: -h },
254
441
  { x: 0, y: -h },
255
442
  { x: 0, y: h }
256
- ], s = [{ x: n * 0.45, y: h }, { x: n * 0.45, y: -h }];
257
- if (r)
258
- r.line(l), r.line(s);
443
+ ], l = [{ x: r * 0.45, y: h }, { x: r * 0.45, y: -h }];
444
+ if (o)
445
+ o.line(i), o.line(l);
259
446
  else
260
- for (const a of [l, s]) {
261
- e.beginPath(), e.moveTo(a[0].x, a[0].y);
262
- for (const f of a.slice(1)) e.lineTo(f.x, f.y);
263
- e.stroke();
447
+ for (const a of [i, l]) {
448
+ t.beginPath(), t.moveTo(a[0].x, a[0].y);
449
+ for (const c of a.slice(1)) t.lineTo(c.x, c.y);
450
+ t.stroke();
264
451
  }
265
- e.restore();
452
+ t.restore();
266
453
  }
267
- function q(e, t, o = {}, r) {
268
- const n = o.tool ?? "pencil", i = o.skin ?? "#f1c9a5", h = o.outline ?? "#2f2f33", l = n === "eraser" ? 17 : 9, s = n === "eraser" ? -40 : 0, a = r ? r.nudge(0.6) : { x: 0, y: 0 };
269
- e.save(), e.translate(t.x + a.x, t.y + a.y), e.rotate((o.angle ?? -30) * Math.PI / 180), e.scale(o.scale ?? 1, o.scale ?? 1), e.lineCap = "round", e.lineJoin = "round";
270
- const f = (g, S, w, b) => {
271
- for (const [E, P] of [
454
+ function le(t, e, n = {}, o) {
455
+ const r = n.tool ?? "pencil", s = n.skin ?? "#f1c9a5", h = n.outline ?? "#2f2f33", i = r === "eraser" ? 17 : 9, l = r === "eraser" ? -40 : 0, a = o ? o.nudge(0.6) : { x: 0, y: 0 };
456
+ t.save(), t.translate(e.x + a.x, e.y + a.y), t.rotate((n.angle ?? -30) * Math.PI / 180), t.scale(n.scale ?? 1, n.scale ?? 1), t.lineCap = "round", t.lineJoin = "round";
457
+ const c = (f, d, w, m) => {
458
+ for (const [u, k] of [
272
459
  [h, w + 6],
273
- [b, w]
460
+ [m, w]
274
461
  ])
275
- e.strokeStyle = E, e.lineWidth = P, e.beginPath(), e.moveTo(g.x, g.y), e.lineTo(S.x, S.y), e.stroke();
462
+ t.strokeStyle = u, t.lineWidth = k, t.beginPath(), t.moveTo(f.x, f.y), t.lineTo(d.x, d.y), t.stroke();
276
463
  };
277
- e.save(), e.translate(s, 0);
278
- const y = { x: 165, y: -l - 26 }, u = (g) => ({ x: y.x + g * 0.8, y: y.y + g * 0.6 });
279
- f(y, u(2e3), 64, i), f(u(110), u(2e3), 92, o.sleeve ?? "#5b7db1"), e.fillStyle = i, e.strokeStyle = h, e.lineWidth = 3, e.beginPath(), e.ellipse(y.x, y.y, 54, 40, 0.25, 0, Math.PI * 2), e.fill(), e.stroke(), e.restore(), n === "eraser" ? N(e, { x: 0, y: 0 }, { angle: 0, outline: h }, r) : ie(e, { x: 0, y: 0 }, { angle: 0, outline: h }, r), e.translate(s, 0), f({ x: 150, y: l + 8 }, { x: 92, y: l + 12 }, 22, i), f({ x: 140, y: -l - 18 }, { x: 58, y: -l - 6 }, 20, i), f({ x: 150, y: -l - 30 }, { x: 112, y: -l + 2 }, 20, i), f({ x: 172, y: -l - 30 }, { x: 140, y: -l + 4 }, 20, i), e.restore();
280
- }
281
- function fe(e, t, o, r = 0.08, n = 32) {
282
- const i = Math.PI * 2 * (1 + r), h = [];
283
- for (let l = 0; l <= n; l++) {
284
- const s = -Math.PI / 2 + i * l / n;
285
- h.push({ x: e + Math.cos(s) * o, y: t + Math.sin(s) * o });
464
+ t.save(), t.translate(l, 0);
465
+ const g = { x: 165, y: -i - 26 }, y = (f) => ({ x: g.x + f * 0.8, y: g.y + f * 0.6 });
466
+ c(g, y(2e3), 64, s), c(y(110), y(2e3), 92, n.sleeve ?? "#5b7db1"), t.fillStyle = s, t.strokeStyle = h, t.lineWidth = 3, t.beginPath(), t.ellipse(g.x, g.y, 54, 40, 0.25, 0, Math.PI * 2), t.fill(), t.stroke(), t.restore(), r === "eraser" ? ie(t, { x: 0, y: 0 }, { angle: 0, outline: h }, o) : je(t, { x: 0, y: 0 }, { angle: 0, outline: h }, o), t.translate(l, 0), c({ x: 150, y: i + 8 }, { x: 92, y: i + 12 }, 22, s), c({ x: 140, y: -i - 18 }, { x: 58, y: -i - 6 }, 20, s), c({ x: 150, y: -i - 30 }, { x: 112, y: -i + 2 }, 20, s), c({ x: 172, y: -i - 30 }, { x: 140, y: -i + 4 }, 20, s), t.restore();
467
+ }
468
+ function In(t, e, n, o = 0.08, r = 32) {
469
+ const s = Math.PI * 2 * (1 + o), h = [];
470
+ for (let i = 0; i <= r; i++) {
471
+ const l = -Math.PI / 2 + s * i / r;
472
+ h.push({ x: t + Math.cos(l) * n, y: e + Math.sin(l) * n });
286
473
  }
287
474
  return h;
288
475
  }
289
- function ue(e) {
290
- const { path: t } = e, o = t.map((l) => l.x), r = t.map((l) => l.y), n = Math.min(...o), i = Math.min(...r), h = e.hand === !1 ? void 0 : e.hand === !0 || e.hand === void 0 ? {} : e.hand;
476
+ function An(t) {
477
+ const { path: e } = t, n = e.map((i) => i.x), o = e.map((i) => i.y), r = Math.min(...n), s = Math.min(...o), h = t.hand === !1 ? void 0 : t.hand === !0 || t.hand === void 0 ? {} : t.hand;
291
478
  return {
292
479
  type: "custom",
293
- x: n,
294
- y: i,
295
- width: Math.max(1, Math.max(...o) - n),
296
- height: Math.max(1, Math.max(...r) - i),
480
+ x: r,
481
+ y: s,
482
+ width: Math.max(1, Math.max(...n) - r),
483
+ height: Math.max(1, Math.max(...o) - s),
297
484
  props: { draw: 0 },
298
- draw(l, s, a) {
299
- const f = Math.min(1, Math.max(0, Number(s.props?.draw ?? 0)));
300
- l.translate(-n, -i), l.strokeStyle = e.color ?? "#2f2f33", l.lineWidth = e.lineWidth ?? 5, l.lineCap = "round", l.lineJoin = "round";
301
- const y = e.sketch ? A(l, e.sketch, a) : void 0;
302
- f > 0 && (y ? e.smooth ? y.curve(t, f) : y.line(t, f) : J(l, O(t, f))), h && f > 0 && f < 1 && q(l, C(t, f), h, y);
485
+ draw(i, l, a) {
486
+ const c = Math.min(1, Math.max(0, Number(l.props?.draw ?? 0)));
487
+ i.translate(-r, -s), i.strokeStyle = t.color ?? "#2f2f33", i.lineWidth = t.lineWidth ?? 5, i.lineCap = "round", i.lineJoin = "round";
488
+ const g = t.sketch ? xt(i, t.sketch, a) : void 0;
489
+ c > 0 && (g ? t.smooth ? g.curve(e, c) : g.line(e, c) : he(i, Dt(e, c))), h && c > 0 && c < 1 && le(i, jt(e, c), h, g);
303
490
  }
304
491
  };
305
492
  }
306
- function J(e, t, o) {
307
- if (!(t.length < 2)) {
308
- if (o) return o.line(t);
309
- e.beginPath(), e.moveTo(t[0].x, t[0].y);
310
- for (const r of t.slice(1)) e.lineTo(r.x, r.y);
311
- e.stroke();
493
+ function he(t, e, n) {
494
+ if (!(e.length < 2)) {
495
+ if (n) return n.line(e);
496
+ t.beginPath(), t.moveTo(e[0].x, e[0].y);
497
+ for (const o of e.slice(1)) t.lineTo(o.x, o.y);
498
+ t.stroke();
312
499
  }
313
500
  }
314
- const R = 1e5;
315
- function ye(e, t, o, r, n = 6) {
316
- const i = [], h = Math.max(1, Math.round(n));
317
- for (let l = 0; l <= h; l++)
318
- i.push({ x: l % 2 === 0 ? e : e + o, y: t + r * l / h });
319
- return i;
320
- }
321
- function G(e, t, o, r) {
322
- if (r <= 0 || t.length === 0) return;
323
- const n = O(t, r), i = o / 2, h = (l) => {
324
- e.beginPath(), e.rect(-R, -R, 2 * R, 2 * R), l(), e.clip("evenodd");
501
+ const st = 1e5;
502
+ function Hn(t, e, n, o, r = 6) {
503
+ const s = [], h = Math.max(1, Math.round(r));
504
+ for (let i = 0; i <= h; i++)
505
+ s.push({ x: i % 2 === 0 ? t : t + n, y: e + o * i / h });
506
+ return s;
507
+ }
508
+ function ae(t, e, n, o) {
509
+ if (o <= 0 || e.length === 0) return;
510
+ const r = Dt(e, o), s = n / 2, h = (i) => {
511
+ t.beginPath(), t.rect(-st, -st, 2 * st, 2 * st), i(), t.clip("evenodd");
325
512
  };
326
- for (const l of n)
513
+ for (const i of r)
327
514
  h(() => {
328
- e.moveTo(l.x + i, l.y), e.arc(l.x, l.y, i, 0, Math.PI * 2);
515
+ t.moveTo(i.x + s, i.y), t.arc(i.x, i.y, s, 0, Math.PI * 2);
329
516
  });
330
- for (let l = 1; l < n.length; l++) {
331
- const s = n[l - 1], a = n[l], f = Math.hypot(a.x - s.x, a.y - s.y);
332
- if (f === 0) continue;
333
- const y = -(a.y - s.y) / f * i, u = (a.x - s.x) / f * i;
517
+ for (let i = 1; i < r.length; i++) {
518
+ const l = r[i - 1], a = r[i], c = Math.hypot(a.x - l.x, a.y - l.y);
519
+ if (c === 0) continue;
520
+ const g = -(a.y - l.y) / c * s, y = (a.x - l.x) / c * s;
334
521
  h(() => {
335
- e.moveTo(s.x + y, s.y + u), e.lineTo(a.x + y, a.y + u), e.lineTo(a.x - y, a.y - u), e.lineTo(s.x - y, s.y - u), e.closePath();
522
+ t.moveTo(l.x + g, l.y + y), t.lineTo(a.x + g, a.y + y), t.lineTo(a.x - g, a.y - y), t.lineTo(l.x - g, l.y - y), t.closePath();
336
523
  });
337
524
  }
338
525
  }
339
- function de(e, t, o, r, n) {
340
- e.save(), G(e, t, o, r), n(), e.restore();
526
+ function _n(t, e, n, o, r) {
527
+ t.save(), ae(t, e, n, o), r(), t.restore();
341
528
  }
342
- function ge(e, t) {
343
- const o = t.width ?? 40, r = t.hand === !0 ? {} : t.hand || void 0, n = t.eraser === !1 ? void 0 : t.eraser === !0 || t.eraser === void 0 ? {} : t.eraser;
529
+ function Yn(t, e) {
530
+ const n = e.width ?? 40, o = e.hand === !0 ? {} : e.hand || void 0, r = e.eraser === !1 ? void 0 : e.eraser === !0 || e.eraser === void 0 ? {} : e.eraser;
344
531
  return {
345
- ...e,
346
- props: { ...e.props, erase: 0 },
347
- draw(i, h, l) {
348
- const s = Number(h.props?.erase ?? 0);
349
- if (i.save(), G(i, t.path, o, s), e.draw(i, h, l), i.restore(), !n || s <= 0 || s >= 1) return;
350
- const a = C(t.path, s);
351
- r ? q(i, a, { ...r, tool: "eraser" }) : N(i, a, n);
532
+ ...t,
533
+ props: { ...t.props, erase: 0 },
534
+ draw(s, h, i) {
535
+ const l = Number(h.props?.erase ?? 0);
536
+ if (s.save(), ae(s, e.path, n, l), t.draw(s, h, i), s.restore(), !r || l <= 0 || l >= 1) return;
537
+ const a = jt(e.path, l);
538
+ o ? le(s, a, { ...o, tool: "eraser" }) : ie(s, a, r);
539
+ }
540
+ };
541
+ }
542
+ const q = (t) => t * Math.PI / 180;
543
+ function ce([t, e, n], o) {
544
+ const r = Math.cos(o), s = Math.sin(o);
545
+ return [t, e * r + n * s, -e * s + n * r];
546
+ }
547
+ function fe([t, e, n], o) {
548
+ const r = Math.cos(o), s = Math.sin(o);
549
+ return [t * r - e * s, t * s + e * r, n];
550
+ }
551
+ function et([t, e, n], o) {
552
+ const r = Math.cos(o), s = Math.sin(o);
553
+ return [t * r + n * s, e, -t * s + n * r];
554
+ }
555
+ const pt = (t, e) => [t[0] + e[0], t[1] + e[1], t[2] + e[2]], Nt = (t, e) => [t[0] * e, t[1] * e, t[2] * e], at = (t, e) => fe(ce(t, e.swing), e.spread);
556
+ function wt(t, e) {
557
+ const n = et(t, e);
558
+ return { point: { x: n[0], y: -n[1] }, depth: n[2] };
559
+ }
560
+ function It(t, e, n) {
561
+ const o = n.height, r = q(90 * (e.turn ?? 0)), h = [0, t.hipHeight * o * (t.boneScale?.(e, null) ?? 1), 0], i = {};
562
+ for (const p of t.chains) {
563
+ const T = p.parent ? i[p.parent] : void 0;
564
+ if (p.parent && !T) throw new Error(`body plan ${t.id}: chain ${p.id} comes before its parent ${p.parent}`);
565
+ const v = p.at ?? (T ? T.joints3.length - 1 : 0), O = T ? T.joints3[v] : h, A = T ? T.frames[Math.max(0, v - 1)] : { swing: 0, spread: 0 }, Z = p.offset ? pt(O, at(Nt(p.offset, o), A)) : O, nt = p.side ?? 1, ut = t.boneScale?.(e, p) ?? 1, gt = t.angles(e, p), X = [Z], Q = [];
566
+ let D = A.swing, yt = A.spread;
567
+ p.bones.forEach((ue, Ht) => {
568
+ const mt = gt[Ht] ?? { swing: 0, spread: 0 };
569
+ D += q(mt.swing), yt += q(mt.spread) * nt, Q.push({ swing: D, spread: yt });
570
+ const ge = et(at(p.rest, { swing: D, spread: yt }), q(mt.yaw ?? 0));
571
+ X.push(pt(X[Ht], Nt(ge, ue.length * o * ut)));
572
+ }), i[p.id] = { joints3: X, frames: Q };
573
+ }
574
+ const l = i[t.head.on], a = t.headPose?.(e) ?? { yaw: 0, nod: 0, tilt: 0, sx: 1, sy: 1 }, c = l.frames[l.frames.length - 1], g = t.head.size / 2 * o, y = g * a.sx, f = g * a.sy, d = (p) => at(et(ce(fe(p, -q(a.tilt)), -q(a.nod)), q(a.yaw)), c), w = pt(l.joints3[l.joints3.length - 1], d([0, f, 0])), m = {};
575
+ for (const p of t.chains) {
576
+ const { joints3: T, frames: v } = i[p.id], O = T.map((A) => wt(A, r));
577
+ m[p.id] = {
578
+ id: p.id,
579
+ joints3: T,
580
+ frames: v,
581
+ points: O.map((A) => A.point),
582
+ depths: O.map((A) => A.depth)
583
+ };
584
+ }
585
+ const u = wt(w, r), k = [[1, 0, 0], [0, 1, 0], [0, 0, 1]].map((p) => et(d(p), r)), E = wt(h, r).point, b = q(e.roll ?? 0), M = (p) => {
586
+ const T = p.x - E.x, v = p.y - E.y;
587
+ return { x: E.x + T * Math.cos(b) - v * Math.sin(b), y: E.y + T * Math.sin(b) + v * Math.cos(b) };
588
+ }, P = ([p, T, v]) => [p * Math.cos(b) + T * Math.sin(b), -p * Math.sin(b) + T * Math.cos(b), v];
589
+ for (const p of Object.values(m)) p.points = p.points.map(M);
590
+ const S = {
591
+ center: M(u.point),
592
+ depth: u.depth,
593
+ rx: y,
594
+ ry: f,
595
+ angle: 0,
596
+ axes: k.map(P)
597
+ }, W = S.axes[1];
598
+ S.angle = Math.atan2(W[0], W[1]);
599
+ const H = (p) => {
600
+ if ("head" in p) return { x: S.center.x + W[0] * f, y: S.center.y - W[1] * f };
601
+ const T = m[p.chain];
602
+ return T.points[Math.min(p.joint, T.points.length - 1)];
603
+ };
604
+ let Y = 0;
605
+ (n.contact ?? "ground") === "ground" && (Y = -Math.max(...t.contacts.map((p) => H(p).y))), Y -= (e.lift ?? 0) * o;
606
+ const I = (p) => ({ x: p.x, y: p.y + Y });
607
+ for (const p of Object.values(m)) p.points = p.points.map(I);
608
+ S.center = I(S.center);
609
+ const x = t.contacts.map((p) => ({ spec: p, point: H(p) }));
610
+ return {
611
+ height: o,
612
+ view: r,
613
+ chains: m,
614
+ head: S,
615
+ hip: I(M(E)),
616
+ contacts: x,
617
+ groundY: Math.max(...x.map((p) => p.point.y))
618
+ };
619
+ }
620
+ function de(t, [e, n, o]) {
621
+ const [r, s, h] = t.axes, i = [
622
+ r[0] * e * t.rx + s[0] * n * t.ry + h[0] * o * t.rx,
623
+ r[1] * e * t.rx + s[1] * n * t.ry + h[1] * o * t.rx,
624
+ r[2] * e * t.rx + s[2] * n * t.ry + h[2] * o * t.rx
625
+ ], l = Math.hypot(e, n, o) || 1, a = (r[2] * e + s[2] * n + h[2] * o) / l;
626
+ return { point: { x: t.center.x + i[0], y: t.center.y - i[1] }, depth: t.depth + i[2], facing: a };
627
+ }
628
+ const rt = (t) => t * 180 / Math.PI, j = (t, e) => [t[0] - e[0], t[1] - e[1], t[2] - e[2]], bt = (t, e) => t[0] * e[0] + t[1] * e[1] + t[2] * e[2], tt = (t) => Math.hypot(t[0], t[1], t[2]), Wt = (t) => {
629
+ const e = tt(t) || 1;
630
+ return [t[0] / e, t[1] / e, t[2] / e];
631
+ }, it = (t) => Math.atan2(Math.sin(t), Math.cos(t));
632
+ function Ct(t) {
633
+ const [e, n, o] = Wt(t);
634
+ return { swing: Math.asin(Math.max(-1, Math.min(1, o))), spread: Math.atan2(e, -n) };
635
+ }
636
+ function Je(t, e, n, o, r) {
637
+ const s = t.chains.find((Y) => Y.id === n);
638
+ if (!s) throw new Error(`reach: no chain ${n} in ${t.id}`);
639
+ if (s.bones.length < 2 || s.rest[1] > -0.99) throw new Error(`reach: ${n} is not a hanging limb of two bones or more`);
640
+ if (!t.withAngles) throw new Error(`reach: the ${t.id} plan cannot set angles`);
641
+ const h = It(t, { ...e, turn: 0, roll: 0, lift: 0 }, { height: r.height, contact: "none" }), i = h.chains[n], l = i.joints3[0], a = tt(j(i.joints3[1], i.joints3[0])), c = tt(j(i.joints3[2], i.joints3[1])), g = s.parent ? h.chains[s.parent].frames[Math.max(0, (s.at ?? h.chains[s.parent].joints3.length - 1) - 1)] : { swing: 0, spread: 0 }, y = j(o, l), f = Math.min(a + c - 1e-6, Math.max(Math.abs(a - c) + 1e-6, tt(y))), d = Wt(y), w = s.parent !== null, m = at(s.pole ?? (w ? [0, -0.35, -1] : [0, 0, 1]), g);
642
+ let u = j(m, [d[0] * bt(m, d), d[1] * bt(m, d), d[2] * bt(m, d)]);
643
+ tt(u) < 1e-6 && (u = et([1, 0, 0], 0)), u = Wt(u);
644
+ const k = (a * a + f * f - c * c) / (2 * a * f), E = Math.sqrt(Math.max(0, 1 - k * k)), b = [
645
+ l[0] + a * (k * d[0] + E * u[0]),
646
+ l[1] + a * (k * d[1] + E * u[1]),
647
+ l[2] + a * (k * d[2] + E * u[2])
648
+ ], M = [l[0] + d[0] * f, l[1] + d[1] * f, l[2] + d[2] * f], P = s.side ?? 1, S = Ct(j(b, l)), W = Ct(j(M, b)), H = [
649
+ { swing: rt(it(S.swing - g.swing)), spread: rt(it(S.spread - g.spread)) * P },
650
+ { swing: rt(it(W.swing - S.swing)), spread: rt(it(W.spread - S.spread)) * P }
651
+ ];
652
+ return t.withAngles(e, s, H);
653
+ }
654
+ function Xt(t, e, n, o, r, s = 0, h = 1, i = 40) {
655
+ const l = Math.cos(r), a = Math.sin(r);
656
+ return Array.from({ length: i + 1 }, (c, g) => {
657
+ const y = s + Math.PI * 2 * h * g / i, f = Math.cos(y) * n, d = Math.sin(y) * o;
658
+ return { x: t + f * l - d * a, y: e + f * a + d * l };
659
+ });
660
+ }
661
+ function ze(t, e) {
662
+ return e.look === "pencil" ? Ve(t, e) : Ge(t, e.ink, e.look);
663
+ }
664
+ function ft(t, e, n = !1) {
665
+ t.beginPath(), t.moveTo(e[0].x, e[0].y);
666
+ for (const o of e.slice(1)) t.lineTo(o.x, o.y);
667
+ n && t.closePath();
668
+ }
669
+ function Ge(t, e, n) {
670
+ const o = n === "silhouette", r = o ? 1.25 : 1;
671
+ return {
672
+ look: n,
673
+ ink: e,
674
+ limb(s, h, i) {
675
+ t.fillStyle = e, Jt(t, s, h * r, i * r);
676
+ },
677
+ line(s, h) {
678
+ s.length < 2 || (t.strokeStyle = e, t.lineWidth = h * r, t.lineCap = "round", t.lineJoin = "round", ft(t, s), t.stroke());
679
+ },
680
+ shape(s, h, i) {
681
+ ft(t, s, !0), (h !== null || o) && (t.fillStyle = o ? e : h, t.fill()), !(i <= 0) && (t.strokeStyle = e, t.lineWidth = i * r, t.lineJoin = "round", t.stroke());
682
+ },
683
+ ellipse(s, h, i, l, a, c, g) {
684
+ t.beginPath(), t.ellipse(s, h, i, l, a, 0, Math.PI * 2), (c !== null || o) && (t.fillStyle = o ? e : c, t.fill()), !(g <= 0) && (t.strokeStyle = e, t.lineWidth = g * r, t.stroke());
685
+ },
686
+ dot(s, h, i) {
687
+ t.fillStyle = e, t.beginPath(), t.arc(s, h, i * r, 0, Math.PI * 2), t.fill();
688
+ },
689
+ guide() {
690
+ },
691
+ guideEllipse() {
692
+ }
693
+ };
694
+ }
695
+ function Ze(t, e) {
696
+ const n = [t[0]];
697
+ let o = 0;
698
+ for (let h = 1; h < t.length; h++) {
699
+ const i = t[h - 1], l = t[h], a = Math.hypot(l.x - i.x, l.y - i.y);
700
+ let c = e - o;
701
+ for (; c < a; ) {
702
+ const g = c / a;
703
+ n.push({ x: i.x + (l.x - i.x) * g, y: i.y + (l.y - i.y) * g }), c += e;
704
+ }
705
+ o = a - (c - e);
706
+ }
707
+ const r = t[t.length - 1], s = n[n.length - 1];
708
+ return Math.hypot(r.x - s.x, r.y - s.y) > e * 0.25 ? n.push(r) : n[n.length - 1] = r, n;
709
+ }
710
+ function Qe(t, e) {
711
+ const n = t.length;
712
+ return t.map((o, r) => {
713
+ const s = t[Math.max(0, r - 1)], h = t[Math.min(n - 1, r + 1)], i = Math.hypot(h.x - s.x, h.y - s.y) || 1, l = e(n === 1 ? 0 : r / (n - 1));
714
+ return { x: o.x - (h.y - s.y) / i * l, y: o.y + (h.x - s.x) / i * l };
715
+ });
716
+ }
717
+ function qt(t) {
718
+ const e = [0.6, 1.4, 2.9].map((o) => ({
719
+ frequency: o * (0.8 + t.next() * 0.4),
720
+ phase: t.next() * Math.PI * 2,
721
+ amount: 0.5 + t.next() * 0.5
722
+ })), n = e.reduce((o, r) => o + r.amount, 0);
723
+ return (o) => e.reduce((r, s) => r + s.amount * Math.sin(Math.PI * 2 * s.frequency * o + s.phase), 0) / n;
724
+ }
725
+ function Ve(t, e) {
726
+ const n = e.pencil ?? {}, o = e.ink, r = n.roughness ?? Math.max(1, e.lineWidth * 0.12), s = Math.max(1, Math.round(n.passes ?? 2)), h = Math.min(1, Math.max(0, n.pressure ?? 0.25)), i = Math.min(1, Math.max(0, n.rubbedOut ?? 0.15)), l = ye(e.time, n.boil ?? 8);
727
+ let a = 0;
728
+ const c = (d, w, m = !1) => me(pe(`${e.seed}:${m ? "paper" : l}:${d}:${w}`)), g = (d, w, m, u, k, E = 0) => {
729
+ if (d.length < 2) return;
730
+ const b = d.slice(1).reduce((I, x, p) => I + Math.hypot(x.x - d[p].x, x.y - d[p].y), 0);
731
+ let M = Ze(d, Math.max(1.5, Math.min(e.lineWidth * 0.8, b / 24)));
732
+ if (E > 0 && M.length >= 2) {
733
+ const [I, x] = [M[M.length - 2], M[M.length - 1]], p = Math.hypot(x.x - I.x, x.y - I.y) || 1;
734
+ M = [...M, { x: x.x + (x.x - I.x) / p * E, y: x.y + (x.y - I.y) / p * E }];
735
+ }
736
+ const P = qt(m), S = qt(m), W = M.length, H = [], Y = [];
737
+ M.forEach((I, x) => {
738
+ const p = W === 1 ? 0 : x / (W - 1), T = M[Math.max(0, x - 1)], v = M[Math.min(W - 1, x + 1)], O = Math.hypot(v.x - T.x, v.y - T.y) || 1, A = -(v.y - T.y) / O, Z = (v.x - T.x) / O, nt = P(p) * k, ut = Math.min(1, p / 0.08, (1 - p) / 0.08), gt = (0.55 + 0.45 * Math.sqrt(Math.max(0, ut))) * (1 + h * S(p)), X = Math.max(0.3, w(p) * gt / 2), Q = I.x + A * nt, D = I.y + Z * nt;
739
+ H.push({ x: Q + A * X, y: D + Z * X }), Y.push({ x: Q - A * X, y: D - Z * X });
740
+ }), t.save(), t.globalAlpha *= u, t.fillStyle = o, ft(t, [...H, ...Y.reverse()], !0), t.fill(), t.restore();
741
+ }, y = (d, w) => {
742
+ const m = a++, u = c(m, 99, !0);
743
+ if (u.next() < i) {
744
+ const M = (u.next() * 2 - 1) * e.lineWidth * 1.4, P = (u.next() * 2 - 1) * e.lineWidth * 1.4, S = d.map((W) => ({ x: W.x + M, y: W.y + P }));
745
+ g(S, (W) => w(W) * 1.8, c(m, 98, !0), 0.035, r), g(S, (W) => w(W) * 0.45, c(m, 97, !0), 0.12, r * 1.5);
746
+ }
747
+ const k = d.slice(1).reduce((M, P, S) => M + Math.hypot(P.x - d[S].x, P.y - d[S].y), 0), E = w(0.5) > 4 && k > w(0.5) * 6, b = E ? [-0.3, 0.3, 0] : [0];
748
+ for (let M = 0; M < s; M++) {
749
+ const P = M === 0;
750
+ b.forEach((S, W) => {
751
+ const H = c(m, M * 10 + W), Y = S === 0 ? d : Qe(d, (x) => w(x) * S * Math.sqrt(Math.sin(Math.PI * x))), I = !P && S === 0 ? e.lineWidth * (0.3 + H.next() * 0.8) : 0;
752
+ g(Y, (x) => w(x) * (E ? 0.5 : 1) * (P ? 1 : 0.6), H, P ? 0.85 : 0.45, r * (P ? 0.6 : 1), I);
753
+ });
754
+ }
755
+ }, f = (d, w, m, u, k, E) => {
756
+ const M = c(a, 50).next() * Math.PI * 2;
757
+ y(Xt(d, w, m, u, k, M, 1.08, 48), () => E);
758
+ };
759
+ return {
760
+ look: "pencil",
761
+ ink: o,
762
+ limb(d, w, m) {
763
+ y(d, (u) => w + (m - w) * u);
764
+ },
765
+ line(d, w) {
766
+ y(d, () => w);
767
+ },
768
+ shape(d, w, m) {
769
+ w !== null && (t.save(), t.globalAlpha *= 0.88, t.fillStyle = w, ft(t, d, !0), t.fill(), t.restore()), m > 0 && y([...d, d[0]], () => m);
770
+ },
771
+ ellipse(d, w, m, u, k, E, b) {
772
+ E !== null && (t.save(), t.globalAlpha *= 0.9, t.fillStyle = E, t.beginPath(), t.ellipse(d, w, m, u, k, 0, Math.PI * 2), t.fill(), t.restore()), f(d, w, m, u, k, b);
773
+ },
774
+ dot(d, w, m) {
775
+ t.save(), t.globalAlpha *= 0.9, t.fillStyle = o, t.beginPath(), t.arc(d, w, m, 0, Math.PI * 2), t.fill(), t.restore();
776
+ },
777
+ guide(d) {
778
+ if (n.construction === !1 || d.length < 2) return;
779
+ const w = a++;
780
+ g(d, () => Math.max(0.6, e.lineWidth * 0.18), c(w, 0), 0.28, r * 1.2, e.lineWidth);
781
+ },
782
+ guideEllipse(d, w, m, u, k) {
783
+ if (n.construction === !1) return;
784
+ const E = a++, b = c(E, 0), M = Xt(d, w, m, u, k, b.next() * Math.PI * 2, 1.12, 48);
785
+ g(M, () => Math.max(0.6, e.lineWidth * 0.18), b, 0.28, r * 1.5);
786
+ }
787
+ };
788
+ }
789
+ const tn = 0.34, U = 0.12, L = -0.4, F = (t, e, n) => t[e] ?? n, en = (t, e) => Math.max(0, t) * (1 - Math.min(1, Math.max(0, e))), nn = 0.45, on = 0.35, sn = 0.7;
790
+ function dt(t, e, n) {
791
+ const o = (f) => Math.sqrt(Math.max(0, 1 - f.x * f.x - f.y * f.y)), r = de(t, [n.x, n.y, o(n)]).facing, s = t.axes[2], h = Math.atan2(s[0], s[2]), i = Math.cos(h), l = i >= 0 ? 1 : -1, a = l * Math.max(on, Math.abs(i)), c = l * Math.max(sn, Math.abs(i)), g = Math.cos(t.angle), y = Math.sin(t.angle);
792
+ return {
793
+ facing: r,
794
+ points: e.map((f) => {
795
+ const d = nn * Math.sin(h) + n.x * a + (f.x - n.x) * c, w = f.y + s[1] * o(f), m = d * t.rx, u = w * t.ry;
796
+ return { x: t.center.x + m * g + u * y, y: t.center.y + m * y - u * g };
797
+ })
798
+ };
799
+ }
800
+ const lt = (t, e, n, o = 12) => Array.from({ length: o + 1 }, (r, s) => {
801
+ const h = s / o, i = 1 - h;
802
+ return { x: i * i * t.x + 2 * i * h * e.x + h * h * n.x, y: i * i * t.y + 2 * i * h * e.y + h * h * n.y };
803
+ }), Mt = (t, e, n, o, r = 16) => Array.from({ length: r }, (s, h) => {
804
+ const i = Math.PI * 2 * h / r;
805
+ return { x: t + Math.cos(i) * n, y: e + Math.sin(i) * o };
806
+ }), Ut = 0.05;
807
+ function rn(t, e, n, o) {
808
+ const r = Math.max(1, Math.min(o * 0.6, 0.14 * e.rx)), s = (u, k) => dt(e, u, k).points, h = (u, k) => dt(e, [], { x: u, y: k }).facing, i = F(n, "smile", 0), l = F(n, "blink", 0), a = F(n, "lookX", 0), c = F(n, "lookY", 0), g = F(n, "browTilt", 0);
809
+ for (const u of [1, -1]) {
810
+ const k = u === 1 ? "left" : "right", E = tn * u;
811
+ if (h(E, U) < Ut) continue;
812
+ const b = { x: E, y: U }, M = en(F(n, `eye.${k}`, 1), l);
813
+ if (M < 0.2) {
814
+ const H = i > 0.5 ? 0.12 : -0.06;
815
+ t.line(s(lt({ x: E - 0.12, y: U }, { x: E, y: U + H }, { x: E + 0.12, y: U }), b), r);
816
+ } else {
817
+ if (M > 1.2) {
818
+ const x = 0.13 * M;
819
+ t.shape(s(Mt(E, U, x * 0.85, x), b), "#ffffff", r);
820
+ }
821
+ const H = M > 1.2 ? 0.075 : 0.1, Y = E + a * 0.08, I = U - c * 0.07;
822
+ t.shape(s(Mt(Y, I, H, H * 1.1 * Math.min(M, 1)), b), t.ink, 0);
823
+ }
824
+ const P = U + 0.3 + F(n, `brow.${k}`, 0) * 0.14 + Math.max(0, M - 1) * 0.12, S = { x: E + u * 0.13, y: P }, W = { x: E - u * 0.13, y: P + g * 0.1 };
825
+ t.line(s([S, { x: (S.x + W.x) / 2, y: (S.y + W.y) / 2 }, W], { x: E, y: P }), r);
826
+ }
827
+ const y = { x: 0, y: L };
828
+ if (h(0, L) < -Ut) return;
829
+ const f = 0.25 * Math.max(0.3, F(n, "mouthWidth", 1)), d = Math.min(1, Math.max(0, F(n, "mouth", 0)));
830
+ if (d <= 0.05) {
831
+ t.line(s(lt({ x: -f, y: L }, { x: 0, y: L - i * 0.25 }, { x: f, y: L }), y), r);
832
+ return;
833
+ }
834
+ const w = 0.3 * d;
835
+ let m;
836
+ if (i > 0.3) {
837
+ const u = L + 0.05;
838
+ m = [...lt({ x: f, y: u }, { x: 0, y: L - w * 2 }, { x: -f, y: u })];
839
+ } else if (i < -0.3) {
840
+ const u = L - w * 0.6;
841
+ m = [...lt({ x: f, y: u }, { x: 0, y: L + w * 1.4 }, { x: -f, y: u })];
842
+ } else
843
+ m = Mt(0, L, f * 0.8, w);
844
+ t.shape(s(m, y), t.ink, 0);
845
+ }
846
+ const kt = 0.215, Et = 0.205, ln = 0.065, Kt = 0.035, hn = 0.165, an = 0.155, cn = 12, K = {
847
+ turn: 0,
848
+ lean: 0,
849
+ side: 0,
850
+ "head.turn": 0,
851
+ "head.nod": 0,
852
+ "head.tilt": 0,
853
+ "arm.left.swing": 0,
854
+ "arm.left.spread": 12,
855
+ "arm.left.elbow": 8,
856
+ "arm.left.bend": 0,
857
+ "arm.right.swing": 0,
858
+ "arm.right.spread": 12,
859
+ "arm.right.elbow": 8,
860
+ "arm.right.bend": 0,
861
+ "leg.left.swing": 0,
862
+ "leg.left.spread": 3,
863
+ "leg.left.knee": 0,
864
+ "leg.left.ankle": 0,
865
+ "leg.right.swing": 0,
866
+ "leg.right.spread": 3,
867
+ "leg.right.knee": 0,
868
+ "leg.right.ankle": 0,
869
+ stretch: 1,
870
+ lift: 0,
871
+ roll: 0,
872
+ mouth: 0,
873
+ smile: 0.5,
874
+ mouthWidth: 1,
875
+ blink: 0,
876
+ "eye.left": 1,
877
+ "eye.right": 1,
878
+ "brow.left": 0,
879
+ "brow.right": 0,
880
+ browTilt: 0,
881
+ lookX: 0,
882
+ lookY: 0
883
+ };
884
+ function R(t = {}) {
885
+ return { ...K, ...t };
886
+ }
887
+ function $(t, e) {
888
+ const n = {};
889
+ for (const o of ["left", "right"]) for (const [r, s] of Object.entries(e)) n[`${t}.${o}.${r}`] = s;
890
+ return n;
891
+ }
892
+ const fn = {
893
+ rest: K,
894
+ wave: R({ "arm.right.spread": 115, "arm.right.bend": 55, "arm.right.elbow": 0, "head.tilt": -6, smile: 0.9 }),
895
+ cheer: R({ ...$("arm", { spread: 140, bend: 20, elbow: 0 }), mouth: 0.6, smile: 1, "eye.left": 0, "eye.right": 0 }),
896
+ point: R({ "arm.right.spread": 88, "arm.right.elbow": 0, "arm.right.bend": 0, "head.turn": -20, smile: 0.4 }),
897
+ handsOnHips: R({ ...$("arm", { spread: 50, bend: -105, elbow: 0 }), ...$("leg", { spread: 9 }), smile: 0.8 }),
898
+ think: R({ "arm.right.spread": 22, "arm.right.bend": -150, "arm.right.elbow": 0, "head.tilt": 10, lookX: -0.5, lookY: -0.8, smile: 0 }),
899
+ shrug: R({ ...$("arm", { spread: 35, bend: 75, elbow: 0 }), "head.tilt": -10, smile: -0.2 }),
900
+ sit: R({ ...$("leg", { swing: 90, knee: 90, spread: 4 }), ...$("arm", { swing: 25, elbow: 45, spread: 8 }) }),
901
+ kneel: R({
902
+ "leg.left.swing": 90,
903
+ "leg.left.knee": 90,
904
+ // The back thigh leans back a little so its knee meets the ground beside the
905
+ // front foot; the shin slopes up from it and the foot points down to tucked toes.
906
+ "leg.right.swing": -18,
907
+ "leg.right.knee": 108,
908
+ "leg.right.ankle": 16,
909
+ ...$("arm", { swing: 20, elbow: 30 })
910
+ }),
911
+ crouch: R({ ...$("leg", { swing: 75, knee: 140, spread: 6 }), lean: 25, ...$("arm", { swing: 50, elbow: 40 }), "head.nod": -15 }),
912
+ // On hands and knees: the back nearly level, arms straight down, the toes
913
+ // pointed back along the ground.
914
+ crawl: R({ lean: 82, "head.nod": -35, ...$("arm", { swing: 80, elbow: 0, spread: 4 }), ...$("leg", { knee: 92, ankle: -88 }) }),
915
+ lieDown: R({ roll: 90, ...$("arm", { spread: 8 }), "head.nod": 0 })
916
+ };
917
+ function dn(t = {}) {
918
+ const e = t.headSize ?? 0.3, n = t.shoulderWidth ?? 0.06, o = t.hipWidth ?? 0.022, r = Math.max(0.12, 1 - e - Kt - (kt + Et)), s = (l) => ({
919
+ id: `arm.${l}`,
920
+ parent: "spine",
921
+ offset: [(l === "left" ? 1 : -1) * n, -0.035, 0],
922
+ rest: [0, -1, 0],
923
+ side: l === "left" ? 1 : -1,
924
+ bones: [
925
+ { length: hn, width: [1.25, 0.9] },
926
+ { length: an, width: [0.9, 0.75] }
927
+ ]
928
+ }), h = (l) => ({
929
+ id: `leg.${l}`,
930
+ parent: null,
931
+ offset: [(l === "left" ? 1 : -1) * o, 0, 0],
932
+ rest: [0, -1, 0],
933
+ side: l === "left" ? 1 : -1,
934
+ bones: [
935
+ { length: kt, width: [1.45, 1.05] },
936
+ { length: Et, width: [1.05, 0.85] },
937
+ { length: ln, width: [0.95, 0.7] }
938
+ ]
939
+ }), i = (l, a) => l[a] ?? K[a] ?? 0;
940
+ return {
941
+ id: "human",
942
+ hipHeight: kt + Et,
943
+ // Tie order: legs, then the body, then the arms (in front of the chest unless turned away), then the head.
944
+ chains: [
945
+ h("left"),
946
+ h("right"),
947
+ {
948
+ id: "spine",
949
+ parent: null,
950
+ rest: [0, 1, 0],
951
+ bones: [
952
+ { length: r / 2, width: [1.7, 1.4] },
953
+ { length: r / 2, width: [1.4, 1.1] }
954
+ ]
955
+ },
956
+ { id: "neck", parent: "spine", rest: [0, 1, 0], bones: [{ length: Kt, width: [1, 0.9] }] },
957
+ s("left"),
958
+ s("right")
959
+ ],
960
+ head: { on: "neck", size: e },
961
+ contacts: [
962
+ ...["left", "right"].flatMap((l) => [
963
+ { chain: `leg.${l}`, joint: 1 },
964
+ { chain: `leg.${l}`, joint: 2 },
965
+ { chain: `leg.${l}`, joint: 3 },
966
+ { chain: `arm.${l}`, joint: 1 },
967
+ { chain: `arm.${l}`, joint: 2 }
968
+ ]),
969
+ { chain: "spine", joint: 0 },
970
+ { chain: "spine", joint: 1 },
971
+ { chain: "spine", joint: 2 },
972
+ { head: "top" }
973
+ ],
974
+ angles(l, a) {
975
+ if (a.id === "spine") {
976
+ const f = -i(l, "lean") / 2, d = i(l, "side") / 2;
977
+ return [
978
+ { swing: f, spread: d },
979
+ { swing: f, spread: d }
980
+ ];
981
+ }
982
+ if (a.id === "neck") return [{ swing: 0, spread: 0 }];
983
+ const [c, g] = a.id.split("."), y = (f) => i(l, `${c}.${g}.${f}`);
984
+ return c === "arm" ? [
985
+ { swing: y("swing"), spread: y("spread") },
986
+ { swing: y("elbow"), spread: y("bend") }
987
+ ] : [
988
+ { swing: y("swing"), spread: y("spread") },
989
+ { swing: -y("knee"), spread: 0 },
990
+ // The foot points forward, square to the shin, turned out a little.
991
+ { swing: 90 + y("ankle"), spread: 0, yaw: cn * (a.side ?? 1) }
992
+ ];
993
+ },
994
+ withAngles(l, a, c) {
995
+ const [g, y] = a.id.split("."), f = (d) => `${g}.${y}.${d}`;
996
+ return g === "arm" ? {
997
+ ...l,
998
+ [f("swing")]: c[0].swing,
999
+ [f("spread")]: c[0].spread,
1000
+ [f("elbow")]: c[1].swing,
1001
+ [f("bend")]: c[1].spread
1002
+ } : g === "leg" ? { ...l, [f("swing")]: c[0].swing, [f("spread")]: c[0].spread, [f("knee")]: -c[1].swing } : l;
1003
+ },
1004
+ boneScale(l, a) {
1005
+ const c = Math.min(3, Math.max(0.3, i(l, "stretch")));
1006
+ return a?.id.startsWith("arm.") ? Math.sqrt(c) : c;
1007
+ },
1008
+ headPose(l) {
1009
+ const a = Math.min(3, Math.max(0.3, i(l, "stretch")));
1010
+ return {
1011
+ yaw: i(l, "head.turn"),
1012
+ nod: i(l, "head.nod"),
1013
+ tilt: i(l, "head.tilt"),
1014
+ // The head keeps its area: taller and narrower when stretched.
1015
+ sx: 1 / Math.sqrt(a),
1016
+ sy: Math.sqrt(a)
1017
+ };
1018
+ },
1019
+ landmarks: {
1020
+ neck: ["neck", 0],
1021
+ "shoulder.left": ["arm.left", 0],
1022
+ "elbow.left": ["arm.left", 1],
1023
+ "hand.left": ["arm.left", 2],
1024
+ "shoulder.right": ["arm.right", 0],
1025
+ "elbow.right": ["arm.right", 1],
1026
+ "hand.right": ["arm.right", 2],
1027
+ "hip.left": ["leg.left", 0],
1028
+ "knee.left": ["leg.left", 1],
1029
+ "ankle.left": ["leg.left", 2],
1030
+ "toe.left": ["leg.left", 3],
1031
+ "hip.right": ["leg.right", 0],
1032
+ "knee.right": ["leg.right", 1],
1033
+ "ankle.right": ["leg.right", 2],
1034
+ "toe.right": ["leg.right", 3]
1035
+ }
1036
+ };
1037
+ }
1038
+ function $n(t) {
1039
+ const e = t.split(".");
1040
+ if (e.length === 3) {
1041
+ const [o, r, s] = e;
1042
+ return `${`${r === "left" ? "Left" : "Right"} ${o}`} · ${{
1043
+ swing: "forward / back",
1044
+ spread: "out / in",
1045
+ elbow: "elbow bend",
1046
+ bend: "forearm out / in",
1047
+ knee: "knee bend",
1048
+ ankle: "foot tilt"
1049
+ }[s] ?? s}`;
1050
+ }
1051
+ return {
1052
+ turn: "View (front → side → back)",
1053
+ lean: "Lean forward / back",
1054
+ side: "Lean sideways",
1055
+ "head.turn": "Head · turn",
1056
+ "head.nod": "Head · nod",
1057
+ "head.tilt": "Head · tilt",
1058
+ stretch: "Squash / stretch",
1059
+ lift: "Lift off the ground",
1060
+ roll: "Roll (whole figure)",
1061
+ mouth: "Mouth open",
1062
+ smile: "Smile",
1063
+ mouthWidth: "Mouth width",
1064
+ blink: "Blink",
1065
+ "eye.left": "Left eye open",
1066
+ "eye.right": "Right eye open",
1067
+ "brow.left": "Left brow",
1068
+ "brow.right": "Right brow",
1069
+ browTilt: "Brow slant",
1070
+ lookX: "Look left / right",
1071
+ lookY: "Look up / down"
1072
+ }[t] ?? t;
1073
+ }
1074
+ const un = {
1075
+ leftEye: "eye.left",
1076
+ rightEye: "eye.right",
1077
+ leftBrow: "brow.left",
1078
+ rightBrow: "brow.right"
1079
+ }, Bn = Object.fromEntries(
1080
+ Object.entries(N).map(([t, e]) => [
1081
+ t,
1082
+ Object.fromEntries(Object.entries(e).map(([n, o]) => [un[n] ?? n, o]))
1083
+ ])
1084
+ );
1085
+ function Rn(t = {}) {
1086
+ const e = (t.proportions ?? "bold") === "bold", n = t.figure ?? "fluid", o = t.look ?? "clean", r = t.height ?? 300, s = n === "stick";
1087
+ return {
1088
+ plan: t.plan ?? dn({
1089
+ headSize: t.headSize ?? (e ? 0.3 : 0.24),
1090
+ shoulderWidth: s ? 0 : t.shoulderWidth ?? 0.06,
1091
+ hipWidth: s ? 0 : t.hipWidth ?? 0.022
1092
+ }),
1093
+ figure: n,
1094
+ look: o,
1095
+ height: r,
1096
+ lineWidth: t.lineWidth ?? r * (e ? 0.045 : 0.022),
1097
+ ink: t.ink ?? (o === "pencil" ? "#2f2f33" : "#1e293b"),
1098
+ skin: t.skin ?? (o === "pencil" ? "none" : "#ffffff"),
1099
+ seed: t.seed ?? 1,
1100
+ pencil: t.pencil ?? {},
1101
+ layers: t.layers ?? {},
1102
+ contact: t.contact ?? "ground"
1103
+ };
1104
+ }
1105
+ function Ln(t, e, n, o) {
1106
+ const { point: r, facing: s } = de(t, [e, n, o]);
1107
+ return { point: r, facing: s };
1108
+ }
1109
+ const Ot = (t) => t.rest[1] < -0.5, gn = 0.3;
1110
+ function yn(t, e, n) {
1111
+ return t.figure === "stick" ? Ot(e) ? n.slice(0, 3) : n : Ot(e) && n.length >= 3 ? z(n[0], n[1], n[2], gn) : n.length === 3 ? z(n[0], n[1], n[2], 1) : n;
1112
+ }
1113
+ function At(t, e) {
1114
+ const n = t.plan.id === "human" ? { ...K, ...e } : e, o = It(t.plan, n, { height: t.height, contact: t.contact }), r = {}, s = {}, h = {}, i = 0.01 * t.height;
1115
+ t.plan.chains.forEach((f) => {
1116
+ const d = o.chains[f.id];
1117
+ r[f.id] = d.points;
1118
+ const w = d.depths.reduce((E, b) => E + b, 0) / d.depths.length, m = f.parent ? o.chains[f.parent] : void 0, u = m ? m.depths[f.at ?? m.depths.length - 1] : 0, k = w - u;
1119
+ h[f.id] = Math.abs(k) < i ? 0 : k, s[f.id] = { points: yn(t, f, d.points), depth: w };
1120
+ }), s.head = { points: [o.head.center], depth: o.head.depth }, h.head = 0;
1121
+ const l = [...t.plan.chains.map((f) => f.id), "head"], a = [...l].sort((f, d) => h[f] - h[d] || l.indexOf(f) - l.indexOf(d)), c = { hip: o.hip };
1122
+ for (const [f, [d, w]] of Object.entries(t.plan.landmarks ?? {})) {
1123
+ const m = o.chains[d]?.points;
1124
+ m && (c[f] = m[Math.min(w, m.length - 1)]);
1125
+ }
1126
+ const g = {};
1127
+ for (const [f, d] of Object.entries(c)) g[f] = d.y >= o.groundY - 0.01 * t.height;
1128
+ const y = {
1129
+ height: t.height,
1130
+ lineWidth: t.lineWidth,
1131
+ turn: n.turn ?? 0,
1132
+ points: c,
1133
+ chains: r,
1134
+ parts: s,
1135
+ head: o.head,
1136
+ groundY: o.groundY,
1137
+ grounded: g
1138
+ };
1139
+ return { skeleton: o, joints: y, order: a };
1140
+ }
1141
+ function mn(t, e) {
1142
+ return At(t, e).joints;
1143
+ }
1144
+ function pn(t, e, n) {
1145
+ const { head: o } = n;
1146
+ t.guideEllipse(o.center.x, o.center.y, o.rx * 1.03, o.ry * 1.03, o.angle);
1147
+ const r = Array.from({ length: 13 }, (l, a) => ({ x: 0, y: -0.95 + 1.9 * a / 12 })), s = Array.from({ length: 13 }, (l, a) => ({ x: -0.95 + 1.9 * a / 12, y: 0.12 })), h = dt(o, r, { x: 0, y: 0 });
1148
+ h.facing > 0 && t.guide(h.points), t.guide(dt(o, s, { x: 0, y: 0.12 }).points), t.guide(n.chains.spine ?? []);
1149
+ const i = e.lineWidth * 0.9;
1150
+ for (const l of ["shoulder.left", "shoulder.right", "elbow.left", "elbow.right", "hip.left", "hip.right", "knee.left", "knee.right"]) {
1151
+ const a = n.points[l];
1152
+ a && t.guideEllipse(a.x, a.y, i, i, 0);
1153
+ }
1154
+ }
1155
+ function wn(t, e, n, o, r) {
1156
+ const s = e.lineWidth;
1157
+ if (o === "head") {
1158
+ const { head: y } = n, f = e.skin === "none" ? null : e.skin;
1159
+ t.ellipse(y.center.x, y.center.y, y.rx, y.ry, y.angle, f, s), t.look !== "silhouette" && rn(t, y, r, s);
1160
+ return;
1161
+ }
1162
+ const h = e.plan.chains.find((y) => y.id === o), i = n.chains[o], l = n.parts[o].points;
1163
+ if (e.figure === "stick") {
1164
+ if (o === "neck") return;
1165
+ const y = o === "spine" ? [...i, ...n.chains.neck?.slice(1) ?? []] : l;
1166
+ t.line(y, s);
1167
+ return;
1168
+ }
1169
+ const a = (y, f) => [h.bones[y].width[0] * s, h.bones[f].width[1] * s];
1170
+ if (Ot(h)) {
1171
+ const [y, f] = a(0, 1);
1172
+ if (t.limb(l, y, f), h.bones.length >= 3)
1173
+ t.limb([i[2], i[3]], h.bones[2].width[0] * s, h.bones[2].width[1] * s);
1174
+ else {
1175
+ const d = i[i.length - 1];
1176
+ t.dot(d.x, d.y, s * 0.62);
1177
+ }
1178
+ return;
1179
+ }
1180
+ if (o === "spine") {
1181
+ const y = n.points["hip.left"], f = n.points["hip.right"];
1182
+ y && f && Math.hypot(y.x - f.x, y.y - f.y) > 0.5 && t.limb([y, f], s * 1.3, s * 1.3);
1183
+ const [d, w] = a(0, h.bones.length - 1);
1184
+ t.limb(l, d, w);
1185
+ const m = n.points["shoulder.left"], u = n.points["shoulder.right"];
1186
+ m && u && Math.hypot(m.x - u.x, m.y - u.y) > 0.5 && t.limb(z(m, i[i.length - 1], u, 1, 10), s * 1.15, s * 1.15);
1187
+ return;
1188
+ }
1189
+ const [c, g] = a(0, h.bones.length - 1);
1190
+ t.limb(l, c, g);
1191
+ }
1192
+ function bn(t, e, n, o = 0) {
1193
+ const r = e.plan.id === "human" ? { ...K, ...n } : n, { joints: s, order: h } = At(e, r), i = ze(t, {
1194
+ look: e.look,
1195
+ ink: e.ink,
1196
+ lineWidth: e.lineWidth,
1197
+ seed: e.seed,
1198
+ time: o,
1199
+ pencil: e.pencil
1200
+ }), l = (a) => {
1201
+ a && (t.save(), a(t, s, i, o), t.restore());
1202
+ };
1203
+ t.save(), t.lineCap = "round", t.lineJoin = "round", e.look === "pencil" && e.pencil.construction !== !1 && pn(i, e, s), l(e.layers.behind);
1204
+ for (const a of h) {
1205
+ const c = e.layers.parts?.[a];
1206
+ l(c?.under), wn(i, e, s, a, r), l(c?.over);
1207
+ }
1208
+ l(e.layers.front), t.restore();
1209
+ }
1210
+ function Fn(t, e, n) {
1211
+ const o = { ...t };
1212
+ for (const [r, s] of Object.entries(e)) {
1213
+ const h = t[r] ?? s;
1214
+ o[r] = h + (s - h) * n;
1215
+ }
1216
+ return o;
1217
+ }
1218
+ function Nn(t, e, n, o) {
1219
+ const r = t.plan.id === "human" ? { ...K, ...e } : e;
1220
+ let s;
1221
+ if (Array.isArray(o))
1222
+ s = o;
1223
+ else {
1224
+ const { skeleton: h } = At(t, r), i = It(t.plan, { ...r, roll: 0 }, { height: t.height, contact: "none" }), l = (r.roll ?? 0) * Math.PI / 180, a = o.x - h.hip.x, c = o.y - h.hip.y, g = i.hip.x + a * Math.cos(-l) - c * Math.sin(-l), y = i.hip.y + a * Math.sin(-l) + c * Math.cos(-l), f = Math.PI / 2 * (r.turn ?? 0), d = o.depth ?? h.chains[n].depths[h.chains[n].depths.length - 1], w = Math.cos(f), m = Math.sin(f);
1225
+ s = [g * w - d * m, -y, g * m + d * w];
1226
+ }
1227
+ return Je(t.plan, r, n, s, { height: t.height });
1228
+ }
1229
+ function Cn(t) {
1230
+ const { character: e } = t, n = e.height * 0.8, o = e.height, r = e.plan.id === "human" ? K : {};
1231
+ return {
1232
+ type: "custom",
1233
+ x: t.x - n / 2,
1234
+ y: t.y - o,
1235
+ width: n,
1236
+ height: o,
1237
+ props: { ...r, ...t.pose },
1238
+ character: e,
1239
+ draw(s, h, i) {
1240
+ s.translate(n / 2, o), bn(s, e, h.props, i);
1241
+ }
1242
+ };
1243
+ }
1244
+ function Mn(t, e, n) {
1245
+ const o = (s) => ({ x: s.x + e, y: s.y + n }), r = (s) => Object.fromEntries(Object.entries(s).map(([h, i]) => [h, i.map(o)]));
1246
+ return {
1247
+ ...t,
1248
+ points: Object.fromEntries(Object.entries(t.points).map(([s, h]) => [s, o(h)])),
1249
+ chains: r(t.chains),
1250
+ parts: Object.fromEntries(Object.entries(t.parts).map(([s, h]) => [s, { ...h, points: h.points.map(o) }])),
1251
+ head: { ...t.head, center: o(t.head.center) },
1252
+ groundY: t.groundY + n
1253
+ };
1254
+ }
1255
+ function Xn(t, e, n) {
1256
+ const o = t.character;
1257
+ if (!o) throw new Error("characterAt: the target was not made by characterTarget");
1258
+ const r = { ...t.props };
1259
+ let s = 0, h = 0;
1260
+ for (const [l, a] of e.state?.values.get(n) ?? [])
1261
+ typeof a == "number" && (l === "x" || l === "motionPathX" ? s = a : l === "y" || l === "motionPathY" ? h = a : l in r && (r[l] = a));
1262
+ const i = mn(o, r);
1263
+ return { pose: r, joints: Mn(i, t.x + s + t.width / 2, t.y + h + t.height) };
1264
+ }
1265
+ function qn(t, e, n = K) {
1266
+ const o = [];
1267
+ return e.forEach((s, h) => {
1268
+ const i = h === 0 ? n : o[h - 1], l = typeof s.pose == "string" ? fn[s.pose] : void 0;
1269
+ o.push(l ? { ...l, turn: i.turn ?? 0 } : { ...i, ...s.pose });
1270
+ }), Object.keys(n).filter((s) => o.some((h) => (h[s] ?? n[s]) !== n[s])).map((s) => ({
1271
+ id: `${t}-${s}`,
1272
+ target: t,
1273
+ property: s,
1274
+ keyframes: e.map((h, i) => ({
1275
+ time: h.time,
1276
+ value: o[i][s] ?? n[s],
1277
+ ...h.easing ? { easing: h.easing } : {}
1278
+ }))
1279
+ }));
1280
+ }
1281
+ const kn = (t, e, n) => t.slice(Math.floor((t.length - 1) * e), Math.ceil((t.length - 1) * n) + 1);
1282
+ function Un(t = {}) {
1283
+ const e = t.shirt ?? "#e2493b", n = t.trousers ?? "#24476b", o = (i) => i.lineWidth * 0.45, r = (i, l, a) => {
1284
+ const c = i.parts[`leg.${a}`].points;
1285
+ l.shape(ht(c, i.height * 0.08, i.height * 0.05), n, o(i));
1286
+ }, s = (i, l) => {
1287
+ const a = i.chains.spine, c = a[0], g = a[a.length - 1], y = { x: c.x - (g.x - c.x) * 0.25, y: c.y - (g.y - c.y) * 0.25 };
1288
+ l.shape(ht([y, ...i.parts.spine.points], i.height * 0.15, i.height * 0.14), e, o(i));
1289
+ }, h = (i, l, a) => {
1290
+ const c = i.parts[`arm.${a}`].points, g = c[0], y = i.chains.spine[i.chains.spine.length - 1], d = [{ x: g.x + (y.x - g.x) * 0.45, y: g.y + (y.y - g.y) * 0.45 }, ...kn(c, 0, 0.45)], w = ht(d, i.height * 0.085, i.height * 0.06), m = d.length, u = w.slice(0, m), k = w.slice(m).reverse();
1291
+ l.shape(w, e, 0);
1292
+ const E = (P) => Math.hypot(P[1].x - y.x, P[1].y - y.y), [b, M] = E(u) > E(k) ? [u, k] : [k, u];
1293
+ l.line(b.slice(1), o(i)), l.line(M.slice(Math.ceil(m * 0.45)), o(i)), l.line([u[m - 1], k[m - 1]], o(i));
1294
+ };
1295
+ return {
1296
+ parts: {
1297
+ "leg.left": { over: (i, l, a) => r(l, a, "left") },
1298
+ "leg.right": { over: (i, l, a) => r(l, a, "right") },
1299
+ spine: { over: (i, l, a) => s(l, a) },
1300
+ "arm.left": { over: (i, l, a) => h(l, a, "left") },
1301
+ "arm.right": { over: (i, l, a) => h(l, a, "right") }
352
1302
  }
353
1303
  };
354
1304
  }
355
1305
  export {
356
- T as EXPRESSIONS,
357
- U as POSES,
358
- B as REST_POSE,
359
- $ as blendPose,
360
- be as boilFrame,
361
- fe as circlePath,
362
- G as clipErased,
363
- N as drawEraser,
364
- q as drawHand,
365
- ie as drawPencil,
366
- ne as drawStickFigure,
367
- ue as drawnPathTarget,
368
- ge as erasable,
369
- O as partialPath,
370
- pe as pathLength,
371
- C as pointAlong,
372
- k as pose,
373
- ae as poseTracks,
374
- le as rubberLimb,
375
- ye as scrubPath,
376
- A as sketchPen,
377
- he as stickFigureTarget,
378
- se as strideLength,
379
- Q as talkingMouth,
380
- z as walkPose,
381
- de as withErased,
382
- D as withExpression
1306
+ N as EXPRESSIONS,
1307
+ Bn as HUMAN_EXPRESSIONS,
1308
+ fn as HUMAN_POSES,
1309
+ K as HUMAN_REST,
1310
+ be as POSES,
1311
+ G as REST_POSE,
1312
+ Un as basicOutfit,
1313
+ Me as blendPose,
1314
+ ye as boilFrame,
1315
+ Rn as character,
1316
+ Xn as characterAt,
1317
+ mn as characterJoints,
1318
+ qn as characterPoseTracks,
1319
+ Cn as characterTarget,
1320
+ In as circlePath,
1321
+ ae as clipErased,
1322
+ ze as createPen,
1323
+ bn as drawCharacter,
1324
+ ie as drawEraser,
1325
+ le as drawHand,
1326
+ je as drawPencil,
1327
+ De as drawStickFigure,
1328
+ An as drawnPathTarget,
1329
+ Xt as ellipsePoints,
1330
+ Yn as erasable,
1331
+ Tn as headPoint,
1332
+ $n as humanFieldLabel,
1333
+ dn as humanPlan,
1334
+ R as humanPose,
1335
+ Mn as jointsInScene,
1336
+ Ke as jointsToScene,
1337
+ Fn as mixPoses,
1338
+ Dt as partialPath,
1339
+ jn as pathLength,
1340
+ jt as pointAlong,
1341
+ Ln as pointOnHead,
1342
+ B as pose,
1343
+ On as poseTracks,
1344
+ Nn as reachCharacter,
1345
+ re as resolveStickPose,
1346
+ z as rubberLimb,
1347
+ Hn as scrubPath,
1348
+ Pn as seatHeight,
1349
+ xt as sketchPen,
1350
+ Wn as stickFigureAt,
1351
+ Ue as stickFigureJoints,
1352
+ vn as stickFigureTarget,
1353
+ Sn as strideLength,
1354
+ xe as talkingMouth,
1355
+ Jt as taperedLine,
1356
+ ht as taperedOutline,
1357
+ Ee as walkPose,
1358
+ _n as withErased,
1359
+ we as withExpression
383
1360
  };