@openmaxai/mascot 0.0.0-stage → 0.1.0-beta.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.
@@ -0,0 +1,4704 @@
1
+ const TAU = Math.PI * 2;
2
+ const DEG = Math.PI / 180;
3
+ const RAYS = 192;
4
+ const SPRING_HZ = 120;
5
+ const SMALL_PX = 48;
6
+ function mulberry32(seed) {
7
+ let a = seed >>> 0;
8
+ return function() {
9
+ a = a + 1831565813 >>> 0;
10
+ let t = a;
11
+ t = Math.imul(t ^ t >>> 15, t | 1);
12
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
13
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
14
+ };
15
+ }
16
+ function seedOf(s) {
17
+ if (typeof s === "number") return s >>> 0;
18
+ let h = 2166136261;
19
+ for (const ch of String(s)) {
20
+ h ^= ch.codePointAt(0);
21
+ h = Math.imul(h, 16777619) >>> 0;
22
+ }
23
+ return h;
24
+ }
25
+ function seededShuffle(arr, rnd) {
26
+ const a = arr.slice();
27
+ for (let i = a.length - 1; i > 0; i--) {
28
+ const j = Math.floor(rnd() * (i + 1));
29
+ [a[i], a[j]] = [a[j], a[i]];
30
+ }
31
+ return a;
32
+ }
33
+ function shuffleBag(pool, rnd, last) {
34
+ const a = seededShuffle(pool, rnd);
35
+ const k = a.findIndex((x) => x !== last);
36
+ if (k > 0) [a[0], a[k]] = [a[k], a[0]];
37
+ return a;
38
+ }
39
+ function cubicBezier(x1, y1, x2, y2) {
40
+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;
41
+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
42
+ const X = (t) => ((ax * t + bx) * t + cx) * t;
43
+ const Y = (t) => ((ay * t + by) * t + cy) * t;
44
+ const DX = (t) => (3 * ax * t + 2 * bx) * t + cx;
45
+ return function(x) {
46
+ if (x <= 0) return 0;
47
+ if (x >= 1) return 1;
48
+ let t = x;
49
+ for (let i = 0; i < 8; i++) {
50
+ const e = X(t) - x;
51
+ if (Math.abs(e) < 1e-7) return Y(t);
52
+ const d = DX(t);
53
+ if (Math.abs(d) < 1e-6) break;
54
+ t -= e / d;
55
+ }
56
+ let lo = 0, hi = 1;
57
+ t = x;
58
+ for (let i = 0; i < 40; i++) {
59
+ const v = X(t);
60
+ if (Math.abs(v - x) < 1e-7) break;
61
+ if (v < x) lo = t;
62
+ else hi = t;
63
+ t = (lo + hi) / 2;
64
+ }
65
+ return Y(t);
66
+ };
67
+ }
68
+ const easeCache = /* @__PURE__ */ new Map();
69
+ const EASE_IN_OUT = [
70
+ .42,
71
+ 0,
72
+ .58,
73
+ 1
74
+ ];
75
+ const EASE_BRIDGE = [
76
+ .4,
77
+ 0,
78
+ .2,
79
+ 1
80
+ ];
81
+ const EASE_FACE = [
82
+ .4,
83
+ .06,
84
+ .18,
85
+ 1
86
+ ];
87
+ function ease(arr) {
88
+ const k = arr.join(",");
89
+ let f = easeCache.get(k);
90
+ if (!f) {
91
+ f = cubicBezier(arr[0], arr[1], arr[2], arr[3]);
92
+ easeCache.set(k, f);
93
+ }
94
+ return f;
95
+ }
96
+ const clamp01 = (v) => v < 0 ? 0 : v > 1 ? 1 : v;
97
+ const smoothstep = (v) => {
98
+ v = clamp01(v);
99
+ return v * v * (3 - 2 * v);
100
+ };
101
+ const easeOutCubic = (v) => 1 - (1 - clamp01(v)) ** 3;
102
+ const easeOutBack = (v) => {
103
+ v = clamp01(v);
104
+ return 1 + 2.70158 * (v - 1) ** 3 + 1.70158 * (v - 1) ** 2;
105
+ };
106
+ const easeInOutCubic = (v) => {
107
+ v = clamp01(v);
108
+ return v < .5 ? 4 * v * v * v : 1 - (-2 * v + 2) ** 3 / 2;
109
+ };
110
+ const frac = (v) => v - Math.floor(v);
111
+ function approach(cur, target, rate, dt) {
112
+ return target + (cur - target) * Math.exp(-rate * dt);
113
+ }
114
+ function createSpring(x, omega = 14, zeta = 1) {
115
+ return {
116
+ x,
117
+ v: 0,
118
+ target: x,
119
+ omega,
120
+ zeta
121
+ };
122
+ }
123
+ function stepSpring(s, dt) {
124
+ dt = Math.min(Math.max(dt, 0), .1);
125
+ if (dt <= 0) return s.x;
126
+ const n = Math.max(1, Math.ceil(dt * 120 - 1e-9)), h = dt / n;
127
+ for (let i = 0; i < n; i++) {
128
+ s.v += (-2 * s.zeta * s.omega * s.v - s.omega * s.omega * (s.x - s.target)) * h;
129
+ s.x += s.v * h;
130
+ }
131
+ if (!Number.isFinite(s.x) || !Number.isFinite(s.v)) {
132
+ s.x = s.target;
133
+ s.v = 0;
134
+ }
135
+ return s.x;
136
+ }
137
+ function springAtRest(s, eps = .001) {
138
+ return Math.abs(s.x - s.target) < eps && Math.abs(s.v) < eps * 10;
139
+ }
140
+ function snapSpring(s, v = s.target) {
141
+ s.x = s.target = v;
142
+ s.v = 0;
143
+ }
144
+ function evalTrack(keys, t) {
145
+ if (!keys || !keys.length) return null;
146
+ if (t <= keys[0].t) return keys[0].v;
147
+ const last = keys[keys.length - 1];
148
+ if (t >= last.t) return last.v;
149
+ let i = 0;
150
+ while (i < keys.length - 2 && keys[i + 1].t <= t) i++;
151
+ const a = keys[i], b = keys[i + 1];
152
+ const p = ease(a.ease || EASE_IN_OUT)((t - a.t) / Math.max(b.t - a.t, 1e-9));
153
+ return a.v.map((c, k) => c + (b.v[k] - c) * p);
154
+ }
155
+ const qMul = (a, b) => [
156
+ a[0] * b[0] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3],
157
+ a[0] * b[1] + a[1] * b[0] + a[2] * b[3] - a[3] * b[2],
158
+ a[0] * b[2] - a[1] * b[3] + a[2] * b[0] + a[3] * b[1],
159
+ a[0] * b[3] + a[1] * b[2] - a[2] * b[1] + a[3] * b[0]
160
+ ];
161
+ const qAxis = (ax, ay, az, ang) => {
162
+ const s = Math.sin(ang / 2);
163
+ return [
164
+ Math.cos(ang / 2),
165
+ ax * s,
166
+ ay * s,
167
+ az * s
168
+ ];
169
+ };
170
+ function quatFromEuler(pitch, yaw, roll) {
171
+ return qMul(qAxis(0, 0, 1, roll * DEG), qMul(qAxis(0, 1, 0, yaw * DEG), qAxis(1, 0, 0, -pitch * DEG)));
172
+ }
173
+ function quatPow(q, k) {
174
+ const w = Math.max(-1, Math.min(1, q[0])), ang = 2 * Math.acos(w), s = Math.sqrt(Math.max(0, 1 - w * w));
175
+ if (s < 1e-9) return [
176
+ 1,
177
+ 0,
178
+ 0,
179
+ 0
180
+ ];
181
+ return qAxis(q[1] / s, q[2] / s, q[3] / s, ang * k);
182
+ }
183
+ function quatRotate(q, v) {
184
+ const [w, x, y, z] = q, [vx, vy, vz] = v;
185
+ const tx = 2 * (y * vz - z * vy), ty = 2 * (z * vx - x * vz), tz = 2 * (x * vy - y * vx);
186
+ return [
187
+ vx + w * tx + (y * tz - z * ty),
188
+ vy + w * ty + (z * tx - x * tz),
189
+ vz + w * tz + (x * ty - y * tx)
190
+ ];
191
+ }
192
+ function expMapFront(u, v) {
193
+ const r = Math.hypot(u, v);
194
+ if (r < 1e-9) return [
195
+ 0,
196
+ 0,
197
+ 1
198
+ ];
199
+ if (r > 1) return [
200
+ u,
201
+ v,
202
+ 0
203
+ ];
204
+ const d = Math.asin(r), k = Math.sin(d) / r;
205
+ return [
206
+ u * k,
207
+ v * k,
208
+ Math.cos(d)
209
+ ];
210
+ }
211
+ function sphereMap(u, v, yaw, pitch) {
212
+ return quatRotate(quatFromEuler(-pitch / DEG, yaw / DEG, 0), expMapFront(u, v));
213
+ }
214
+ const visibleOnSphere = (p) => p[2] > 0 || p[0] * p[0] + p[1] * p[1] >= 1;
215
+ function polarShape(fn, n = 360) {
216
+ const pts = [];
217
+ for (let i = 0; i < n; i++) {
218
+ const t = i / n * TAU;
219
+ const r = fn(t);
220
+ pts.push([r * Math.cos(t), r * Math.sin(t)]);
221
+ }
222
+ return pts;
223
+ }
224
+ function superellipse(a, b, p, n = 360, pBottom = p) {
225
+ const pts = [];
226
+ for (let i = 0; i < n; i++) {
227
+ const t = i / n * TAU, c = Math.cos(t), s = Math.sin(t);
228
+ const e = 2 / (s > 0 ? pBottom : p);
229
+ pts.push([a * Math.sign(c) * Math.abs(c) ** e, b * Math.sign(s) * Math.abs(s) ** e]);
230
+ }
231
+ return pts;
232
+ }
233
+ function transformShape(pts, { rot = 0, sx = 1, sy = 1, dx = 0, dy = 0 } = {}) {
234
+ const c = Math.cos(rot), s = Math.sin(rot);
235
+ return pts.map(([x, y]) => {
236
+ x *= sx;
237
+ y *= sy;
238
+ return [x * c - y * s + dx, x * s + y * c + dy];
239
+ });
240
+ }
241
+ const uniformAngles = (n = 192) => Float64Array.from({ length: n }, (_, i) => i / n * TAU);
242
+ const angOf = (x, y) => {
243
+ const a = Math.atan2(y, x);
244
+ return a < 0 ? a + TAU : a;
245
+ };
246
+ function cornerAngles(pts, minTurnDeg = 25) {
247
+ const out = [], m = pts.length, lim = minTurnDeg * DEG;
248
+ for (let j = 0; j < m; j++) {
249
+ const p = pts[(j - 1 + m) % m], c = pts[j], q = pts[(j + 1) % m];
250
+ const a1 = Math.atan2(c[1] - p[1], c[0] - p[0]), a2 = Math.atan2(q[1] - c[1], q[0] - c[0]);
251
+ let d = Math.abs(a2 - a1);
252
+ if (d > Math.PI) d = TAU - d;
253
+ if (d > lim) out.push(angOf(c[0], c[1]));
254
+ }
255
+ return out;
256
+ }
257
+ function angleTable(extra = [], n = 192) {
258
+ const all = [...uniformAngles(n), ...extra].sort((a, b) => a - b);
259
+ return Float64Array.from(all.filter((v, i) => i === 0 || v - all[i - 1] > 1e-7));
260
+ }
261
+ function raySample(pts, angles = 192) {
262
+ if (typeof angles === "number") angles = uniformAngles(angles);
263
+ const n = angles.length, out = new Float32Array(n), m = pts.length;
264
+ for (let i = 0; i < n; i++) {
265
+ const th = angles[i], dx = Math.cos(th), dy = Math.sin(th);
266
+ let best = 0;
267
+ for (let j = 0; j < m; j++) {
268
+ const [ax, ay] = pts[j], [bx, by] = pts[(j + 1) % m];
269
+ const ex = bx - ax, ey = by - ay;
270
+ const det = ex * dy - dx * ey;
271
+ if (Math.abs(det) < 1e-12) continue;
272
+ const t = (ex * ay - ax * ey) / det;
273
+ const u = (dx * ay - dy * ax) / det;
274
+ if (t > 0 && u >= -1e-9 && u <= 1.000000001 && t > best) best = t;
275
+ }
276
+ out[i] = best;
277
+ }
278
+ return out;
279
+ }
280
+ function radiusAtAngle(angles, radii, th) {
281
+ th = (th % TAU + TAU) % TAU;
282
+ let lo = 0, hi = angles.length;
283
+ while (lo < hi) {
284
+ const mid = lo + hi >> 1;
285
+ if (angles[mid] < th) lo = mid + 1;
286
+ else hi = mid;
287
+ }
288
+ const n = angles.length, i1 = lo % n, i0 = (lo - 1 + n) % n;
289
+ const a0 = angles[i0], span = ((lo === n ? angles[0] + TAU : angles[i1]) - a0 + TAU) % TAU || TAU;
290
+ const f = (th - a0 + TAU) % TAU / span;
291
+ return radii[i0] + (radii[i1] - radii[i0]) * Math.min(1, Math.max(0, f));
292
+ }
293
+ function lerpRadii(a, b, w, out = new Float32Array(a.length)) {
294
+ for (let i = 0; i < a.length; i++) out[i] = a[i] + (b[i] - a[i]) * w;
295
+ return out;
296
+ }
297
+ function lerpPts(a, b, w) {
298
+ return a.map((p, i) => [p[0] + (b[i][0] - p[0]) * w, p[1] + (b[i][1] - p[1]) * w]);
299
+ }
300
+ function cubicPts(p0, p1, p2, p3, n) {
301
+ const out = [];
302
+ for (let i = 0; i < n; i++) {
303
+ const t = i / (n - 1), m = 1 - t;
304
+ const a = m * m * m, b = 3 * m * m * t, c = 3 * m * t * t, d = t * t * t;
305
+ out.push([a * p0[0] + b * p1[0] + c * p2[0] + d * p3[0], a * p0[1] + b * p1[1] + c * p2[1] + d * p3[1]]);
306
+ }
307
+ return out;
308
+ }
309
+ function resample(pts, n) {
310
+ const L = [0];
311
+ for (let i = 1; i < pts.length; i++) L.push(L[i - 1] + Math.hypot(pts[i][0] - pts[i - 1][0], pts[i][1] - pts[i - 1][1]));
312
+ const total = L[L.length - 1] || 1, out = [];
313
+ let j = 1;
314
+ for (let k = 0; k < n; k++) {
315
+ const s = k / (n - 1) * total;
316
+ while (j < L.length - 1 && L[j] < s) j++;
317
+ const a = pts[j - 1], b = pts[j], f = (s - L[j - 1]) / (L[j] - L[j - 1] || 1);
318
+ out.push([a[0] + (b[0] - a[0]) * f, a[1] + (b[1] - a[1]) * f]);
319
+ }
320
+ return out;
321
+ }
322
+ function speechEnvelope(t, seed = 0) {
323
+ const syll = Math.max(0, Math.sin(TAU * 4.1 * t + .8 * Math.sin(1.7 * t + seed)));
324
+ const phrase = .55 + .45 * Math.sin(TAU * .33 * t + seed);
325
+ const pause = Math.sin(TAU * .19 * t + seed * 2) < -.72 ? 0 : 1;
326
+ return Math.min(1, syll ** .7 * phrase * pause);
327
+ }
328
+ const BRAND = {
329
+ blue: "#3297D7",
330
+ productBlue: "#21B1FF",
331
+ charBlue: "#63B5E4",
332
+ ink: "#111111",
333
+ cyan: "#42DCFF",
334
+ red: "#FF513D"
335
+ };
336
+ const LU = (x, y) => [(x - 600) / 449, (y - 600) / 449];
337
+ const M_SEGMENTS = [
338
+ [
339
+ [214, 759],
340
+ [245, 759],
341
+ [275, 759],
342
+ [300, 759]
343
+ ],
344
+ [
345
+ [300, 759],
346
+ [355, 759],
347
+ [377, 742],
348
+ [377, 690]
349
+ ],
350
+ [
351
+ [377, 690],
352
+ [377, 650],
353
+ [377, 640],
354
+ [377, 620]
355
+ ],
356
+ [
357
+ [377, 620],
358
+ [377, 515],
359
+ [432, 456],
360
+ [500, 456]
361
+ ],
362
+ [
363
+ [500, 456],
364
+ [552, 456],
365
+ [588, 478],
366
+ [600, 506]
367
+ ],
368
+ [
369
+ [600, 506],
370
+ [572, 560],
371
+ [548, 630],
372
+ [549, 690]
373
+ ],
374
+ [
375
+ [549, 690],
376
+ [551, 742],
377
+ [576, 764],
378
+ [600, 764]
379
+ ],
380
+ [
381
+ [600, 764],
382
+ [624, 764],
383
+ [649, 742],
384
+ [651, 690]
385
+ ],
386
+ [
387
+ [651, 690],
388
+ [652, 630],
389
+ [628, 560],
390
+ [600, 506]
391
+ ],
392
+ [
393
+ [600, 506],
394
+ [612, 478],
395
+ [648, 456],
396
+ [700, 456]
397
+ ],
398
+ [
399
+ [700, 456],
400
+ [768, 456],
401
+ [823, 515],
402
+ [823, 620]
403
+ ],
404
+ [
405
+ [823, 620],
406
+ [823, 640],
407
+ [823, 650],
408
+ [823, 690]
409
+ ],
410
+ [
411
+ [823, 690],
412
+ [823, 742],
413
+ [845, 759],
414
+ [900, 759]
415
+ ],
416
+ [
417
+ [900, 759],
418
+ [925, 759],
419
+ [955, 759],
420
+ [986, 759]
421
+ ]
422
+ ];
423
+ function logoMLine(n = 120) {
424
+ const raw = [];
425
+ for (const seg of M_SEGMENTS) {
426
+ const p = cubicPts(...seg.map((q) => LU(...q)), 16);
427
+ raw.push(...raw.length ? p.slice(1) : p);
428
+ }
429
+ return resample(raw, n);
430
+ }
431
+ const LOGO_GEOM = {
432
+ ring: 410 / 449,
433
+ ringW: 78 / 449,
434
+ lineW: 76 / 449,
435
+ baseline: 159 / 449
436
+ };
437
+ const EYE_L = [-.1, -.135];
438
+ const EYE_R = [.56, -.15];
439
+ const BROW = [
440
+ [-.56, -.92],
441
+ [-.2, -.6],
442
+ [.45, -.62],
443
+ [.77, -.82]
444
+ ];
445
+ const FACES = {
446
+ grin: {
447
+ brow: {
448
+ dy: 0,
449
+ bend: 0,
450
+ tilt: 0
451
+ },
452
+ eyes: {
453
+ kind: "dot",
454
+ len: .02
455
+ },
456
+ mouth: {
457
+ L: -.43,
458
+ Rb: .33,
459
+ Rt: .68,
460
+ yL: .13,
461
+ yR: .27,
462
+ sag: .03,
463
+ depth: .42
464
+ }
465
+ },
466
+ listen: {
467
+ brow: {
468
+ dy: -.05,
469
+ bend: -.15,
470
+ tilt: 0
471
+ },
472
+ eyes: {
473
+ kind: "dot",
474
+ len: .042
475
+ },
476
+ mouth: {
477
+ L: -.1,
478
+ Rb: .24,
479
+ Rt: .3,
480
+ yL: .3,
481
+ yR: .33,
482
+ sag: 0,
483
+ depth: .17
484
+ }
485
+ },
486
+ think: {
487
+ brow: {
488
+ dy: -.02,
489
+ bend: .02,
490
+ tilt: .16
491
+ },
492
+ eyes: {
493
+ kind: "dot",
494
+ len: .014
495
+ },
496
+ mouth: {
497
+ L: -.12,
498
+ Rb: .42,
499
+ Rt: .42,
500
+ yL: .34,
501
+ yR: .28,
502
+ sag: -.015,
503
+ depth: 0
504
+ }
505
+ },
506
+ speak: {
507
+ brow: {
508
+ dy: -.02,
509
+ bend: -.05,
510
+ tilt: 0
511
+ },
512
+ eyes: {
513
+ kind: "dot",
514
+ len: .022
515
+ },
516
+ mouth: {
517
+ L: -.38,
518
+ Rb: .3,
519
+ Rt: .6,
520
+ yL: .15,
521
+ yR: .27,
522
+ sag: .03,
523
+ depth: .03,
524
+ speak: .4
525
+ }
526
+ },
527
+ laugh: {
528
+ brow: {
529
+ dy: -.1,
530
+ bend: -.18,
531
+ tilt: 0
532
+ },
533
+ eyes: {
534
+ kind: "happy",
535
+ len: .07
536
+ },
537
+ mouth: {
538
+ L: -.48,
539
+ Rb: .4,
540
+ Rt: .72,
541
+ yL: .1,
542
+ yR: .24,
543
+ sag: .04,
544
+ depth: .5
545
+ }
546
+ },
547
+ frown: {
548
+ brow: {
549
+ dy: .1,
550
+ bend: .1,
551
+ tilt: -.04
552
+ },
553
+ eyes: {
554
+ kind: "dot",
555
+ len: .014
556
+ },
557
+ mouth: {
558
+ L: -.24,
559
+ Rb: .46,
560
+ Rt: .46,
561
+ yL: .4,
562
+ yR: .38,
563
+ sag: -.09,
564
+ depth: 0
565
+ }
566
+ },
567
+ sleep: {
568
+ brow: {
569
+ dy: .07,
570
+ bend: -.04,
571
+ tilt: 0
572
+ },
573
+ eyes: {
574
+ kind: "closed",
575
+ len: .05
576
+ },
577
+ mouth: {
578
+ L: -.14,
579
+ Rb: .3,
580
+ Rt: .3,
581
+ yL: .34,
582
+ yR: .34,
583
+ sag: .05,
584
+ depth: 0
585
+ }
586
+ },
587
+ focus: {
588
+ brow: {
589
+ dy: .05,
590
+ bend: .06,
591
+ tilt: 0
592
+ },
593
+ eyes: {
594
+ kind: "dot",
595
+ len: .012
596
+ },
597
+ mouth: {
598
+ L: -.1,
599
+ Rb: .3,
600
+ Rt: .36,
601
+ yL: .32,
602
+ yR: .33,
603
+ sag: 0,
604
+ depth: 0
605
+ }
606
+ },
607
+ scan: {
608
+ brow: {
609
+ dy: -.03,
610
+ bend: -.05,
611
+ tilt: 0
612
+ },
613
+ eyes: {
614
+ kind: "dot",
615
+ len: .026
616
+ },
617
+ mouth: {
618
+ L: -.04,
619
+ Rb: .2,
620
+ Rt: .24,
621
+ yL: .31,
622
+ yR: .32,
623
+ sag: 0,
624
+ depth: .1
625
+ }
626
+ },
627
+ read: {
628
+ brow: {
629
+ dy: .02,
630
+ bend: 0,
631
+ tilt: 0
632
+ },
633
+ eyes: {
634
+ kind: "dot",
635
+ len: .01
636
+ },
637
+ mouth: {
638
+ L: -.05,
639
+ Rb: .28,
640
+ Rt: .3,
641
+ yL: .33,
642
+ yR: .33,
643
+ sag: .025,
644
+ depth: 0
645
+ }
646
+ },
647
+ loadf: {
648
+ brow: {
649
+ dy: 0,
650
+ bend: 0,
651
+ tilt: 0
652
+ },
653
+ eyes: {
654
+ kind: "dot",
655
+ len: .02
656
+ },
657
+ mouth: {
658
+ L: -.04,
659
+ Rb: .24,
660
+ Rt: .27,
661
+ yL: .33,
662
+ yR: .33,
663
+ sag: 0,
664
+ depth: .08
665
+ }
666
+ },
667
+ greet: {
668
+ brow: {
669
+ dy: -.08,
670
+ bend: -.12,
671
+ tilt: 0
672
+ },
673
+ eyes: {
674
+ kind: "happy",
675
+ len: .07
676
+ },
677
+ mouth: {
678
+ L: -.45,
679
+ Rb: .36,
680
+ Rt: .7,
681
+ yL: .12,
682
+ yR: .25,
683
+ sag: .03,
684
+ depth: .46
685
+ }
686
+ },
687
+ wait: {
688
+ brow: {
689
+ dy: -.06,
690
+ bend: -.1,
691
+ tilt: 0
692
+ },
693
+ eyes: {
694
+ kind: "dot",
695
+ len: .03
696
+ },
697
+ mouth: {
698
+ L: -.1,
699
+ Rb: .3,
700
+ Rt: .36,
701
+ yL: .3,
702
+ yR: .32,
703
+ sag: .05,
704
+ depth: 0
705
+ }
706
+ },
707
+ nope: {
708
+ brow: {
709
+ dy: .03,
710
+ bend: .04,
711
+ tilt: 0
712
+ },
713
+ eyes: {
714
+ kind: "dot",
715
+ len: .014
716
+ },
717
+ mouth: {
718
+ L: -.15,
719
+ Rb: .35,
720
+ Rt: .4,
721
+ yL: .34,
722
+ yR: .33,
723
+ sag: -.03,
724
+ depth: 0
725
+ }
726
+ },
727
+ thanks: {
728
+ brow: {
729
+ dy: -.06,
730
+ bend: -.1,
731
+ tilt: 0
732
+ },
733
+ eyes: {
734
+ kind: "happy",
735
+ len: .07
736
+ },
737
+ mouth: {
738
+ L: -.2,
739
+ Rb: .32,
740
+ Rt: .4,
741
+ yL: .27,
742
+ yR: .3,
743
+ sag: .07,
744
+ depth: .12
745
+ }
746
+ },
747
+ confused: {
748
+ brow: {
749
+ dy: -.02,
750
+ bend: 0,
751
+ tilt: .3
752
+ },
753
+ eyes: {
754
+ kind: "dot",
755
+ len: .02
756
+ },
757
+ mouth: {
758
+ L: -.15,
759
+ Rb: .4,
760
+ Rt: .4,
761
+ yL: .36,
762
+ yR: .28,
763
+ sag: 0,
764
+ depth: 0,
765
+ wave: .035
766
+ }
767
+ },
768
+ wow: {
769
+ brow: {
770
+ dy: -.15,
771
+ bend: -.22,
772
+ tilt: 0
773
+ },
774
+ eyes: {
775
+ kind: "dot",
776
+ len: .05
777
+ },
778
+ mouth: {
779
+ L: -.02,
780
+ Rb: .26,
781
+ Rt: .26,
782
+ yL: .3,
783
+ yR: .3,
784
+ sag: 0,
785
+ depth: .26
786
+ }
787
+ },
788
+ sad: {
789
+ brow: {
790
+ dy: .05,
791
+ bend: -.2,
792
+ tilt: -.12
793
+ },
794
+ eyes: {
795
+ kind: "dot",
796
+ len: .015
797
+ },
798
+ mouth: {
799
+ L: -.15,
800
+ Rb: .38,
801
+ Rt: .38,
802
+ yL: .42,
803
+ yR: .42,
804
+ sag: -.08,
805
+ depth: 0
806
+ }
807
+ },
808
+ shy: {
809
+ brow: {
810
+ dy: .02,
811
+ bend: -.08,
812
+ tilt: 0
813
+ },
814
+ eyes: {
815
+ kind: "closed",
816
+ len: .05
817
+ },
818
+ mouth: {
819
+ L: -.05,
820
+ Rb: .25,
821
+ Rt: .28,
822
+ yL: .32,
823
+ yR: .33,
824
+ sag: .05,
825
+ depth: 0
826
+ }
827
+ },
828
+ warn: {
829
+ brow: {
830
+ dy: -.1,
831
+ bend: -.15,
832
+ tilt: 0
833
+ },
834
+ eyes: {
835
+ kind: "dot",
836
+ len: .04
837
+ },
838
+ mouth: {
839
+ L: -.1,
840
+ Rb: .3,
841
+ Rt: .32,
842
+ yL: .34,
843
+ yR: .34,
844
+ sag: 0,
845
+ depth: 0,
846
+ wave: .02
847
+ }
848
+ },
849
+ off: {
850
+ brow: {
851
+ dy: .06,
852
+ bend: 0,
853
+ tilt: 0
854
+ },
855
+ eyes: {
856
+ kind: "flat",
857
+ len: .05
858
+ },
859
+ mouth: {
860
+ L: -.1,
861
+ Rb: .3,
862
+ Rt: .3,
863
+ yL: .35,
864
+ yR: .35,
865
+ sag: 0,
866
+ depth: 0
867
+ }
868
+ },
869
+ smug: {
870
+ brow: {
871
+ dy: -.06,
872
+ bend: -.04,
873
+ tilt: .12
874
+ },
875
+ eyes: {
876
+ kind: "closed",
877
+ len: .05
878
+ },
879
+ mouth: {
880
+ L: -.12,
881
+ Rb: .32,
882
+ Rt: .42,
883
+ yL: .28,
884
+ yR: .3,
885
+ sag: .07,
886
+ depth: 0
887
+ }
888
+ },
889
+ tired: {
890
+ brow: {
891
+ dy: .08,
892
+ bend: -.06,
893
+ tilt: -.06
894
+ },
895
+ eyes: {
896
+ kind: "flat",
897
+ len: .05
898
+ },
899
+ mouth: {
900
+ L: -.1,
901
+ Rb: .3,
902
+ Rt: .32,
903
+ yL: .36,
904
+ yR: .36,
905
+ sag: -.01,
906
+ depth: 0,
907
+ wave: .02
908
+ }
909
+ }
910
+ };
911
+ function mouthPts(m, amp = 0) {
912
+ const depth = m.depth + (m.speak || 0) * amp;
913
+ const topY = (x) => {
914
+ const s = (x - m.L) / (m.Rt - m.L || 1);
915
+ const c = Math.min(1, Math.max(0, s));
916
+ return m.yL + (m.yR - m.yL) * s + m.sag * Math.sin(Math.PI * c) + (m.wave || 0) * Math.sin(3 * Math.PI * c);
917
+ };
918
+ const top = [], bowl = [];
919
+ for (let i = 0; i <= 10; i++) {
920
+ const x = m.Rt + (m.L - m.Rt) * (i / 10);
921
+ top.push([x, topY(x)]);
922
+ }
923
+ const xc = (m.L + m.Rb) / 2, a = (m.Rb - m.L) / 2;
924
+ for (let i = 1; i <= 14; i++) {
925
+ const u = i / 14, x = xc - a * Math.cos(Math.PI * u);
926
+ bowl.push([x, topY(x) + depth * Math.sin(Math.PI * u) ** .85]);
927
+ }
928
+ return resample(top.concat(bowl), 26);
929
+ }
930
+ function eyePts(c, e, lid) {
931
+ const out = [];
932
+ for (let i = 0; i < 7; i++) {
933
+ const s = i / 6;
934
+ let x, y;
935
+ if (e.kind === "dot") {
936
+ x = 0;
937
+ y = (s - .5) * 2 * e.len;
938
+ } else if (e.kind === "happy") {
939
+ x = (s - .5) * .17;
940
+ y = .025 - .07 * Math.sin(Math.PI * s);
941
+ } else if (e.kind === "flat") {
942
+ x = (s - .5) * .13;
943
+ y = .01;
944
+ } else {
945
+ x = (s - .5) * .16;
946
+ y = .01 + .045 * Math.sin(Math.PI * s);
947
+ }
948
+ x += (s - .5) * .09 * (1 - lid);
949
+ out.push([c[0] + x, c[1] + y * lid]);
950
+ }
951
+ return out;
952
+ }
953
+ const ILL_LINE = [
954
+ [-.94, .76],
955
+ [-.66, .7],
956
+ [-.61, .46],
957
+ [-.75, .22],
958
+ [-.72, .03],
959
+ [-.45, -.11],
960
+ [-.31, -.3],
961
+ [-.42, -.49],
962
+ [-.56, -.59],
963
+ [-.5, -.73],
964
+ [-.31, -.78],
965
+ [.01, -.78],
966
+ [.17, -.89],
967
+ [.2, -1.05],
968
+ [.34, -1.19],
969
+ [.61, -1.19],
970
+ [.74, -1.03],
971
+ [.71, -.86],
972
+ [.63, -.76]
973
+ ];
974
+ const ILL_ANT = 12;
975
+ const ILL_NOSE = [
976
+ [.38, -.05],
977
+ [.46, .11],
978
+ [.43, .2],
979
+ [.34, .22]
980
+ ];
981
+ const ILL_EYE_L = [.15, -.14];
982
+ const ILL_EYE_R = [.66, -.16];
983
+ const ILL_FACES = {
984
+ grin: { sag: .12 },
985
+ listen: {
986
+ sag: .05,
987
+ open: .12,
988
+ w: .6,
989
+ curl: 1.15,
990
+ perk: -.06
991
+ },
992
+ think: {
993
+ sag: -.02,
994
+ w: .7,
995
+ dy: .02
996
+ },
997
+ speak: {
998
+ sag: .1,
999
+ open: .04,
1000
+ speak: .35
1001
+ },
1002
+ laugh: {
1003
+ sag: .1,
1004
+ open: .3,
1005
+ curl: 1.2,
1006
+ perk: -.08
1007
+ },
1008
+ frown: {
1009
+ sag: -.1,
1010
+ w: .8,
1011
+ dy: .05,
1012
+ curl: .9,
1013
+ perk: .08
1014
+ },
1015
+ sleep: {
1016
+ sag: .05,
1017
+ w: .6,
1018
+ dy: .03,
1019
+ curl: .85,
1020
+ perk: .1
1021
+ },
1022
+ focus: {
1023
+ sag: .02,
1024
+ w: .7
1025
+ },
1026
+ scan: {
1027
+ sag: .03,
1028
+ open: .1,
1029
+ w: .5
1030
+ },
1031
+ read: {
1032
+ sag: .05,
1033
+ w: .6
1034
+ },
1035
+ loadf: {
1036
+ sag: 0,
1037
+ open: .06,
1038
+ w: .5
1039
+ },
1040
+ greet: {
1041
+ sag: .1,
1042
+ open: .25,
1043
+ curl: 1.15,
1044
+ perk: -.05
1045
+ },
1046
+ wait: {
1047
+ sag: .08,
1048
+ w: .8
1049
+ },
1050
+ nope: {
1051
+ sag: -.04,
1052
+ w: .8
1053
+ },
1054
+ thanks: {
1055
+ sag: .14,
1056
+ open: .05,
1057
+ curl: 1.1
1058
+ },
1059
+ confused: {
1060
+ sag: -.02,
1061
+ w: .8,
1062
+ wave: .03,
1063
+ curl: 1.1,
1064
+ perk: -.04
1065
+ },
1066
+ wow: {
1067
+ open: .24,
1068
+ w: .45,
1069
+ curl: 1.25,
1070
+ perk: -.12
1071
+ },
1072
+ sad: {
1073
+ sag: -.1,
1074
+ w: .8,
1075
+ dy: .06,
1076
+ curl: .8,
1077
+ perk: .14
1078
+ },
1079
+ shy: {
1080
+ sag: .08,
1081
+ w: .55
1082
+ },
1083
+ warn: {
1084
+ sag: 0,
1085
+ w: .7,
1086
+ wave: .02,
1087
+ perk: -.05
1088
+ },
1089
+ off: {
1090
+ sag: 0,
1091
+ w: .6,
1092
+ curl: .8,
1093
+ perk: .12
1094
+ },
1095
+ smug: {
1096
+ sag: .1,
1097
+ w: .7,
1098
+ curl: 1.1,
1099
+ perk: -.06
1100
+ },
1101
+ tired: {
1102
+ sag: -.02,
1103
+ w: .6,
1104
+ dy: .04,
1105
+ curl: .85,
1106
+ perk: .12,
1107
+ wave: .015
1108
+ }
1109
+ };
1110
+ function catmullRom(pts, seg = 8) {
1111
+ const out = [], n = pts.length, P = (i) => pts[Math.max(0, Math.min(n - 1, i))];
1112
+ for (let i = 0; i < n - 1; i++) {
1113
+ const p0 = P(i - 1), p1 = P(i), p2 = P(i + 1), p3 = P(i + 2);
1114
+ for (let k = 0; k < seg; k++) {
1115
+ const t = k / seg, t2 = t * t, t3 = t2 * t;
1116
+ out.push([0, 1].map((d) => .5 * (2 * p1[d] + (-p0[d] + p2[d]) * t + (2 * p0[d] - 5 * p1[d] + 4 * p2[d] - p3[d]) * t2 + (-p0[d] + 3 * p1[d] - 3 * p2[d] + p3[d]) * t3)));
1117
+ }
1118
+ }
1119
+ out.push(pts[n - 1]);
1120
+ return out;
1121
+ }
1122
+ function illFeatures(name, amp, lid) {
1123
+ const e = FACES[name].eyes, f = {
1124
+ sag: 0,
1125
+ open: 0,
1126
+ w: 1,
1127
+ dy: 0,
1128
+ curl: 1,
1129
+ perk: 0,
1130
+ wave: 0,
1131
+ speak: 0,
1132
+ ...ILL_FACES[name]
1133
+ };
1134
+ const ac = [.47, -1];
1135
+ const line = ILL_LINE.map(([x, y], i) => {
1136
+ if (i < ILL_ANT) return [x, y];
1137
+ const k = (i - ILL_ANT + 1) / (ILL_LINE.length - ILL_ANT);
1138
+ return [ac[0] + (x - ac[0]) * f.curl, ac[1] + (y - ac[1]) * f.curl + f.perk * k * 1.4];
1139
+ });
1140
+ const c = .1, hw = .29 * f.w;
1141
+ const m = {
1142
+ L: c - hw,
1143
+ Rt: c + hw,
1144
+ Rb: c + hw,
1145
+ yL: .29 + f.dy + (1 - f.w) * .1,
1146
+ yR: .29 + f.dy + (1 - f.w) * .1 + (f.sag > 0 ? .16 * f.w : .03),
1147
+ sag: f.sag,
1148
+ depth: f.open,
1149
+ speak: f.speak,
1150
+ wave: f.wave
1151
+ };
1152
+ return {
1153
+ line: resample(catmullRom(line, 6), 48),
1154
+ eyeL: eyePts(ILL_EYE_L, e, lid),
1155
+ eyeR: eyePts(ILL_EYE_R, e, lid),
1156
+ nose: resample(catmullRom(ILL_NOSE, 5), 8),
1157
+ mouth: mouthPts(m, amp)
1158
+ };
1159
+ }
1160
+ function faceFeatures(name, amp = 0, lid = 1, charId = "ext") {
1161
+ const ch = CHARACTERS[charId];
1162
+ return ch.features ? ch.features(name, amp, lid) : {};
1163
+ }
1164
+ function extFeatures(name, amp, lid) {
1165
+ const f = FACES[name], b = f.brow;
1166
+ const P = BROW.map(([x, y], i) => [x, y + b.dy + (i === 1 || i === 2 ? b.bend : 0) - (i >= 2 ? b.tilt * (i === 3 ? 1 : .5) : 0)]);
1167
+ return {
1168
+ brow: resample(cubicPts(P[0], P[1], P[2], P[3], 24), 12),
1169
+ eyeL: eyePts(EYE_L, f.eyes, lid),
1170
+ eyeR: eyePts(EYE_R, f.eyes, lid),
1171
+ mouth: mouthPts(f.mouth, amp)
1172
+ };
1173
+ }
1174
+ const CHARACTERS = {};
1175
+ function registerCharacter(...defs) {
1176
+ for (const d of defs) CHARACTERS[d.id] = d;
1177
+ return CHARACTERS;
1178
+ }
1179
+ const FACE_SHAPES = {
1180
+ base: () => polarShape(() => 1),
1181
+ listen: () => superellipse(1.02, 1.04, 2.05),
1182
+ think: () => transformShape(polarShape((t) => 1 + .05 * Math.cos(t + 2.2)), { rot: .2 }),
1183
+ talk: () => superellipse(1.06, .95, 2.1),
1184
+ burst: () => superellipse(1.08, .94, 2.05),
1185
+ error: () => superellipse(1, .96, 2.15),
1186
+ sleep: () => superellipse(1.08, .9, 2, 360, 2.6),
1187
+ squash: () => superellipse(1.07, .92, 2.05, 360, 2.5),
1188
+ tall: () => superellipse(.95, 1.07, 2),
1189
+ spin: () => polarShape((t) => 1 + .02 * Math.cos(3 * t))
1190
+ };
1191
+ const logoCharacter = {
1192
+ id: "logo",
1193
+ label: "Logo",
1194
+ kind: "logo",
1195
+ color: "#3297D7",
1196
+ mLine: logoMLine,
1197
+ geom: LOGO_GEOM,
1198
+ shapes: {
1199
+ base: () => polarShape(() => 1),
1200
+ listen: () => polarShape(() => 1.05),
1201
+ think: () => transformShape(polarShape((t) => 1 + .06 * Math.cos(t + 2.2) - .025 * Math.cos(2 * t)), { rot: .25 }),
1202
+ talk: () => superellipse(1.06, .95, 2.1),
1203
+ burst: () => polarShape((t) => 1 + .045 * Math.cos(8 * t - Math.PI / 2)),
1204
+ error: () => polarShape((t) => .98 + .035 * Math.cos(6 * t - Math.PI / 2)),
1205
+ sleep: () => superellipse(1.06, .92, 2, 360, 3),
1206
+ squash: () => superellipse(1.06, .93, 2.05, 360, 2.4),
1207
+ tall: () => superellipse(.96, 1.06, 2),
1208
+ spin: () => polarShape((t) => 1 + .025 * Math.cos(3 * t))
1209
+ }
1210
+ };
1211
+ const extCharacter = {
1212
+ id: "ext",
1213
+ label: "扩展",
1214
+ kind: "face",
1215
+ color: "#63B5E4",
1216
+ ink: "#111111",
1217
+ features: extFeatures,
1218
+ eyes: [EYE_L, EYE_R],
1219
+ strokes: {
1220
+ brow: .042,
1221
+ mouth: .05,
1222
+ eyeDot: .09,
1223
+ eyeArc: .055
1224
+ },
1225
+ shapes: FACE_SHAPES
1226
+ };
1227
+ const illCharacter = {
1228
+ id: "ill",
1229
+ label: "插画",
1230
+ kind: "face",
1231
+ face: "ill",
1232
+ color: "#3297D7",
1233
+ palettes: {
1234
+ blue: "#3297D7",
1235
+ red: "#FF513D",
1236
+ green: "#65D73F",
1237
+ yellow: "#FFD646",
1238
+ purple: "#8B5CF6",
1239
+ cyan: "#42DCFF"
1240
+ },
1241
+ ink: "#111111",
1242
+ watercolor: true,
1243
+ features: illFeatures,
1244
+ eyes: [ILL_EYE_L, ILL_EYE_R],
1245
+ strokes: {
1246
+ line: .07,
1247
+ nose: .06,
1248
+ mouth: .065,
1249
+ eyeDot: .1,
1250
+ eyeArc: .06
1251
+ },
1252
+ shapes: FACE_SHAPES
1253
+ };
1254
+ const bankCache = /* @__PURE__ */ new Map();
1255
+ function shapeBank(charId) {
1256
+ let b = bankCache.get(charId);
1257
+ if (!b) {
1258
+ const polys = Object.entries(CHARACTERS[charId].shapes).map(([k, fn]) => [k, fn()]);
1259
+ const corners = polys.flatMap(([, pts]) => cornerAngles(pts));
1260
+ const angles = angleTable(corners), sharp = new Uint8Array(angles.length), compact = [];
1261
+ for (let i = 0; i < angles.length; i++) {
1262
+ const u = angles[i] / TAU * 192, isUniform = Math.abs(u - Math.round(u)) < 1e-6;
1263
+ sharp[i] = corners.some((c) => Math.abs(c - angles[i]) < 1e-7) ? 1 : 0;
1264
+ if (sharp[i] || isUniform && Math.round(u) % 4 === 0) compact.push(i);
1265
+ }
1266
+ b = {};
1267
+ for (const [k, pts] of polys) b[k] = raySample(pts, angles);
1268
+ Object.defineProperties(b, {
1269
+ angles: { value: angles },
1270
+ sharp: { value: sharp },
1271
+ compact: { value: Uint16Array.from(compact) }
1272
+ });
1273
+ bankCache.set(charId, b);
1274
+ }
1275
+ return b;
1276
+ }
1277
+ const OVER = [
1278
+ .3,
1279
+ 0,
1280
+ .2,
1281
+ 1.25
1282
+ ];
1283
+ const POP = [
1284
+ .2,
1285
+ .7,
1286
+ .3,
1287
+ 1
1288
+ ];
1289
+ const FALL = [
1290
+ .6,
1291
+ 0,
1292
+ .9,
1293
+ .5
1294
+ ];
1295
+ const SPIN = [
1296
+ .3,
1297
+ 0,
1298
+ .2,
1299
+ 1.08
1300
+ ];
1301
+ const k = (t, v, e) => e ? {
1302
+ t,
1303
+ v: Array.isArray(v) ? v : [v],
1304
+ ease: e
1305
+ } : {
1306
+ t,
1307
+ v: Array.isArray(v) ? v : [v]
1308
+ };
1309
+ const blink = (t) => ({
1310
+ t,
1311
+ v: "blink"
1312
+ });
1313
+ const R0 = [
1314
+ 0,
1315
+ 0,
1316
+ 0
1317
+ ];
1318
+ const CLIPS = {
1319
+ idleBreath: {
1320
+ duration: 4.8,
1321
+ squashAnchor: -1,
1322
+ tracks: {
1323
+ squash: [
1324
+ k(0, [1, 1]),
1325
+ k(2.4, [.99, 1.022]),
1326
+ k(4.8, [1, 1])
1327
+ ],
1328
+ position: [
1329
+ k(0, [0, 0]),
1330
+ k(2.4, [0, -.017]),
1331
+ k(4.8, [0, 0])
1332
+ ],
1333
+ expression: [{
1334
+ t: 0,
1335
+ v: "grin"
1336
+ }, blink(3.1)]
1337
+ }
1338
+ },
1339
+ idleLook: {
1340
+ duration: 5.6,
1341
+ tracks: {
1342
+ rotation: [
1343
+ k(0, R0, OVER),
1344
+ k(.7, [
1345
+ -4.5,
1346
+ 18,
1347
+ 3.5
1348
+ ]),
1349
+ k(2.1, [
1350
+ -4.5,
1351
+ 18,
1352
+ 3.5
1353
+ ], OVER),
1354
+ k(2.7, [
1355
+ 3,
1356
+ -16,
1357
+ -3.5
1358
+ ]),
1359
+ k(4.1, [
1360
+ 3,
1361
+ -16,
1362
+ -3.5
1363
+ ]),
1364
+ k(4.9, R0),
1365
+ k(5.6, R0)
1366
+ ],
1367
+ expression: [
1368
+ {
1369
+ t: 0,
1370
+ v: "grin"
1371
+ },
1372
+ {
1373
+ t: .75,
1374
+ v: "listen"
1375
+ },
1376
+ blink(2.45),
1377
+ {
1378
+ t: 4.85,
1379
+ v: "grin",
1380
+ cut: false
1381
+ },
1382
+ blink(5.25)
1383
+ ]
1384
+ }
1385
+ },
1386
+ idleHop: {
1387
+ duration: 3.8,
1388
+ squashAnchor: -1,
1389
+ tracks: {
1390
+ position: [
1391
+ k(0, [0, 0]),
1392
+ k(.35, [0, .05], POP),
1393
+ k(.75, [0, -.3], FALL),
1394
+ k(1.15, [0, 0]),
1395
+ k(3.8, [0, 0])
1396
+ ],
1397
+ squash: [
1398
+ k(0, [1, 1]),
1399
+ k(.35, [1.07, .9]),
1400
+ k(.6, [.94, 1.09]),
1401
+ k(1.1, [1, 1]),
1402
+ k(1.18, [1.1, .87], OVER),
1403
+ k(1.5, [1, 1]),
1404
+ k(3.8, [1, 1])
1405
+ ],
1406
+ hk: [
1407
+ k(0, 0),
1408
+ k(.35, -.12),
1409
+ k(.6, .15),
1410
+ k(1.1, 0),
1411
+ k(3.8, 0)
1412
+ ],
1413
+ expression: [
1414
+ {
1415
+ t: 0,
1416
+ v: "grin"
1417
+ },
1418
+ {
1419
+ t: .4,
1420
+ v: "laugh"
1421
+ },
1422
+ {
1423
+ t: 1.7,
1424
+ v: "grin"
1425
+ },
1426
+ blink(2.5),
1427
+ blink(2.8)
1428
+ ]
1429
+ }
1430
+ },
1431
+ idleTilt: {
1432
+ duration: 4.4,
1433
+ tracks: {
1434
+ rotation: [
1435
+ k(0, R0, OVER),
1436
+ k(.7, [
1437
+ -6,
1438
+ 7,
1439
+ -9
1440
+ ]),
1441
+ k(2.6, [
1442
+ -6,
1443
+ 7,
1444
+ -9
1445
+ ], OVER),
1446
+ k(3.3, R0),
1447
+ k(4.4, R0)
1448
+ ],
1449
+ expression: [
1450
+ {
1451
+ t: 0,
1452
+ v: "grin"
1453
+ },
1454
+ {
1455
+ t: .7,
1456
+ v: "smug"
1457
+ },
1458
+ blink(1.5),
1459
+ {
1460
+ t: 3.3,
1461
+ v: "grin"
1462
+ }
1463
+ ]
1464
+ }
1465
+ },
1466
+ listen: {
1467
+ duration: 2.6,
1468
+ tracks: {
1469
+ zoom: [
1470
+ k(0, 1),
1471
+ k(1.3, 1.025),
1472
+ k(2.6, 1)
1473
+ ],
1474
+ position: [
1475
+ k(0, [0, 0]),
1476
+ k(.5, [0, .04]),
1477
+ k(1, [0, 0]),
1478
+ k(2.6, [0, 0])
1479
+ ],
1480
+ rotation: [
1481
+ k(0, [
1482
+ 3,
1483
+ 0,
1484
+ -2
1485
+ ]),
1486
+ k(.5, [
1487
+ 7,
1488
+ 0,
1489
+ 0
1490
+ ]),
1491
+ k(1.3, [
1492
+ 3,
1493
+ 3,
1494
+ 2
1495
+ ]),
1496
+ k(2.6, [
1497
+ 3,
1498
+ 0,
1499
+ -2
1500
+ ])
1501
+ ],
1502
+ expression: [{
1503
+ t: 0,
1504
+ v: "listen"
1505
+ }, blink(2)]
1506
+ }
1507
+ },
1508
+ work: {
1509
+ duration: 2.4,
1510
+ tracks: {
1511
+ position: [
1512
+ k(0, [0, 0]),
1513
+ k(.15, [0, .023]),
1514
+ k(.3, [0, 0]),
1515
+ k(.45, [0, .023]),
1516
+ k(.6, [0, 0]),
1517
+ k(1.05, [0, .023]),
1518
+ k(1.2, [0, 0]),
1519
+ k(1.35, [0, .023]),
1520
+ k(1.5, [0, 0]),
1521
+ k(2.4, [0, 0])
1522
+ ],
1523
+ rotation: [
1524
+ k(0, [
1525
+ 10,
1526
+ -3,
1527
+ 0
1528
+ ]),
1529
+ k(.15, [
1530
+ 14,
1531
+ -2,
1532
+ 0
1533
+ ]),
1534
+ k(.3, [
1535
+ 10,
1536
+ -1,
1537
+ 0
1538
+ ]),
1539
+ k(.45, [
1540
+ 14,
1541
+ 0,
1542
+ 0
1543
+ ]),
1544
+ k(.6, [
1545
+ 10,
1546
+ 1,
1547
+ 0
1548
+ ]),
1549
+ k(1.2, [
1550
+ 10,
1551
+ 3,
1552
+ 0
1553
+ ]),
1554
+ k(1.35, [
1555
+ 14,
1556
+ 2,
1557
+ 0
1558
+ ]),
1559
+ k(1.5, [
1560
+ 10,
1561
+ 1,
1562
+ 0
1563
+ ]),
1564
+ k(2.4, [
1565
+ 10,
1566
+ -3,
1567
+ 0
1568
+ ])
1569
+ ],
1570
+ hk: [
1571
+ k(0, 0),
1572
+ k(.15, -.06),
1573
+ k(.3, 0),
1574
+ k(.45, -.06),
1575
+ k(.6, 0),
1576
+ k(1.05, -.06),
1577
+ k(1.2, 0),
1578
+ k(2.4, 0)
1579
+ ],
1580
+ wv: [
1581
+ k(0, .01),
1582
+ k(1.2, .025),
1583
+ k(2.4, .01)
1584
+ ],
1585
+ expression: [{
1586
+ t: 0,
1587
+ v: "focus"
1588
+ }, blink(2)]
1589
+ }
1590
+ },
1591
+ scan: {
1592
+ duration: 2.8,
1593
+ tracks: {
1594
+ rotation: [
1595
+ k(0, [
1596
+ 4,
1597
+ -20,
1598
+ -4
1599
+ ], OVER),
1600
+ k(1.2, [
1601
+ 4,
1602
+ 20,
1603
+ 4
1604
+ ]),
1605
+ k(1.4, [
1606
+ 4,
1607
+ 20,
1608
+ 4
1609
+ ], OVER),
1610
+ k(2.6, [
1611
+ 4,
1612
+ -20,
1613
+ -4
1614
+ ]),
1615
+ k(2.8, [
1616
+ 4,
1617
+ -20,
1618
+ -4
1619
+ ])
1620
+ ],
1621
+ position: [
1622
+ k(0, [-.033, 0]),
1623
+ k(1.2, [.033, 0]),
1624
+ k(1.4, [.033, 0]),
1625
+ k(2.6, [-.033, 0]),
1626
+ k(2.8, [-.033, 0])
1627
+ ],
1628
+ expression: [
1629
+ {
1630
+ t: 0,
1631
+ v: "scan"
1632
+ },
1633
+ blink(1.3),
1634
+ {
1635
+ t: 1.25,
1636
+ v: "read",
1637
+ cut: false
1638
+ },
1639
+ {
1640
+ t: 2.65,
1641
+ v: "scan",
1642
+ cut: false
1643
+ }
1644
+ ]
1645
+ }
1646
+ },
1647
+ ponder: {
1648
+ duration: 3.4,
1649
+ tracks: {
1650
+ rotation: [
1651
+ k(0, [
1652
+ -13,
1653
+ 12,
1654
+ 5
1655
+ ]),
1656
+ k(1.7, [
1657
+ -11,
1658
+ 15,
1659
+ 9
1660
+ ]),
1661
+ k(3.4, [
1662
+ -13,
1663
+ 12,
1664
+ 5
1665
+ ])
1666
+ ],
1667
+ position: [
1668
+ k(0, [0, 0]),
1669
+ k(1.7, [0, -.027]),
1670
+ k(3.4, [0, 0])
1671
+ ],
1672
+ hk: [
1673
+ k(0, .05),
1674
+ k(1.7, .1),
1675
+ k(3.4, .05)
1676
+ ],
1677
+ expression: [{
1678
+ t: 0,
1679
+ v: "think"
1680
+ }, blink(2.6)]
1681
+ }
1682
+ },
1683
+ hop: {
1684
+ duration: 1.7,
1685
+ squashAnchor: -1,
1686
+ tracks: {
1687
+ position: [
1688
+ k(0, [0, 0]),
1689
+ k(.25, [0, .06], POP),
1690
+ k(.65, [0, -.37], FALL),
1691
+ k(1.05, [0, 0]),
1692
+ k(1.7, [0, 0])
1693
+ ],
1694
+ squash: [
1695
+ k(0, [1, 1]),
1696
+ k(.25, [1.09, .88]),
1697
+ k(.5, [.93, 1.1]),
1698
+ k(1, [1, 1]),
1699
+ k(1.08, [1.12, .86], OVER),
1700
+ k(1.4, [1, 1])
1701
+ ],
1702
+ rotation: [
1703
+ k(0, R0),
1704
+ k(.3, R0, SPIN),
1705
+ k(1, [
1706
+ 0,
1707
+ 0,
1708
+ 360
1709
+ ])
1710
+ ],
1711
+ hk: [
1712
+ k(0, 0),
1713
+ k(.5, .18),
1714
+ k(1.1, 0)
1715
+ ],
1716
+ expression: [{
1717
+ t: 0,
1718
+ v: "laugh"
1719
+ }]
1720
+ }
1721
+ },
1722
+ bounce: {
1723
+ duration: 1.2,
1724
+ squashAnchor: -1,
1725
+ tracks: {
1726
+ position: [
1727
+ k(0, [0, 0]),
1728
+ k(.1, [0, .033], POP),
1729
+ k(.3, [0, -.2], FALL),
1730
+ k(.55, [0, 0]),
1731
+ k(.65, [0, .033], POP),
1732
+ k(.85, [0, -.2], FALL),
1733
+ k(1.1, [0, 0]),
1734
+ k(1.2, [0, 0])
1735
+ ],
1736
+ squash: [
1737
+ k(0, [1, 1]),
1738
+ k(.1, [1.08, .9]),
1739
+ k(.3, [.95, 1.08]),
1740
+ k(.55, [1.08, .9]),
1741
+ k(.65, [1.06, .92]),
1742
+ k(.85, [.95, 1.08]),
1743
+ k(1.1, [1.06, .92]),
1744
+ k(1.2, [1, 1])
1745
+ ],
1746
+ rotation: [
1747
+ k(0, [
1748
+ 0,
1749
+ 0,
1750
+ -6
1751
+ ]),
1752
+ k(.6, [
1753
+ 0,
1754
+ 0,
1755
+ 6
1756
+ ]),
1757
+ k(1.2, [
1758
+ 0,
1759
+ 0,
1760
+ -6
1761
+ ])
1762
+ ],
1763
+ hk: [
1764
+ k(0, 0),
1765
+ k(.3, .15),
1766
+ k(.55, 0),
1767
+ k(.85, .15),
1768
+ k(1.1, 0)
1769
+ ],
1770
+ expression: [{
1771
+ t: 0,
1772
+ v: "laugh"
1773
+ }]
1774
+ }
1775
+ },
1776
+ nod: {
1777
+ duration: 1.2,
1778
+ tracks: {
1779
+ rotation: [
1780
+ k(0, R0),
1781
+ k(.25, [
1782
+ 16,
1783
+ 0,
1784
+ 0
1785
+ ], OVER),
1786
+ k(.5, R0),
1787
+ k(.75, [
1788
+ 16,
1789
+ 0,
1790
+ 0
1791
+ ], OVER),
1792
+ k(1, R0),
1793
+ k(1.2, R0)
1794
+ ],
1795
+ position: [
1796
+ k(0, [0, 0]),
1797
+ k(.25, [0, .06], OVER),
1798
+ k(.5, [0, 0]),
1799
+ k(.75, [0, .06], OVER),
1800
+ k(1, [0, 0]),
1801
+ k(1.2, [0, 0])
1802
+ ],
1803
+ hk: [
1804
+ k(0, 0),
1805
+ k(.25, -.15),
1806
+ k(.5, 0),
1807
+ k(.75, -.15),
1808
+ k(1, 0)
1809
+ ],
1810
+ expression: [{
1811
+ t: 0,
1812
+ v: "grin"
1813
+ }]
1814
+ }
1815
+ },
1816
+ pop: {
1817
+ duration: 1.6,
1818
+ squashAnchor: -1,
1819
+ tracks: {
1820
+ zoom: [
1821
+ k(0, 1),
1822
+ k(.3, 1.08, OVER),
1823
+ k(.8, 1),
1824
+ k(1.6, 1)
1825
+ ],
1826
+ position: [
1827
+ k(0, [0, 0]),
1828
+ k(.15, [0, .027], POP),
1829
+ k(.35, [0, -.083], FALL),
1830
+ k(.7, [0, 0]),
1831
+ k(1.6, [0, 0])
1832
+ ],
1833
+ hk: [
1834
+ k(0, 0),
1835
+ k(.3, .2),
1836
+ k(1, 0)
1837
+ ],
1838
+ expression: [{
1839
+ t: 0,
1840
+ v: "greet"
1841
+ }, blink(1)]
1842
+ }
1843
+ },
1844
+ shake: {
1845
+ duration: 1,
1846
+ tracks: {
1847
+ rotation: [
1848
+ k(0, R0),
1849
+ k(.18, [
1850
+ 0,
1851
+ -20,
1852
+ -5
1853
+ ]),
1854
+ k(.45, [
1855
+ 0,
1856
+ 20,
1857
+ 5
1858
+ ]),
1859
+ k(.72, [
1860
+ 0,
1861
+ -20,
1862
+ -5
1863
+ ]),
1864
+ k(.9, R0),
1865
+ k(1, R0)
1866
+ ],
1867
+ position: [
1868
+ k(0, [0, 0]),
1869
+ k(.18, [-.067, 0]),
1870
+ k(.45, [.067, 0]),
1871
+ k(.72, [-.067, 0]),
1872
+ k(.9, [0, 0]),
1873
+ k(1, [0, 0])
1874
+ ],
1875
+ sk: [
1876
+ k(0, 0),
1877
+ k(.18, -.2),
1878
+ k(.45, .2),
1879
+ k(.72, -.2),
1880
+ k(.9, 0)
1881
+ ],
1882
+ expression: [{
1883
+ t: 0,
1884
+ v: "nope"
1885
+ }]
1886
+ }
1887
+ },
1888
+ droop: {
1889
+ duration: 4.4,
1890
+ squashAnchor: -1,
1891
+ tracks: {
1892
+ position: [
1893
+ k(0, [0, .073]),
1894
+ k(2.2, [0, .093]),
1895
+ k(4.4, [0, .073])
1896
+ ],
1897
+ squash: [
1898
+ k(0, [1.01, .97]),
1899
+ k(2.2, [1.015, .955]),
1900
+ k(4.4, [1.01, .97])
1901
+ ],
1902
+ rotation: [
1903
+ k(0, [
1904
+ 10,
1905
+ 0,
1906
+ -2
1907
+ ]),
1908
+ k(2.2, [
1909
+ 10,
1910
+ 0,
1911
+ 2
1912
+ ]),
1913
+ k(4.4, [
1914
+ 10,
1915
+ 0,
1916
+ -2
1917
+ ])
1918
+ ],
1919
+ lids: [
1920
+ k(0, .15),
1921
+ k(2.2, .3),
1922
+ k(4.4, .15)
1923
+ ],
1924
+ hk: [k(0, -.25), k(4.4, -.25)],
1925
+ expression: [{
1926
+ t: 0,
1927
+ v: "sad"
1928
+ }, blink(3)]
1929
+ }
1930
+ },
1931
+ slump: {
1932
+ duration: 1.5,
1933
+ squashAnchor: -1,
1934
+ tracks: {
1935
+ position: [
1936
+ k(0, [0, 0]),
1937
+ k(.6, [0, 0]),
1938
+ k(1.1, [0, .04]),
1939
+ k(1.5, [0, .04])
1940
+ ],
1941
+ squash: [
1942
+ k(0, [1, 1]),
1943
+ k(.6, [1, 1]),
1944
+ k(1.1, [1.01, .96]),
1945
+ k(1.5, [1.01, .96])
1946
+ ],
1947
+ rotation: [
1948
+ k(0, R0),
1949
+ k(.6, R0),
1950
+ k(1.1, [
1951
+ 8,
1952
+ 0,
1953
+ 0
1954
+ ]),
1955
+ k(1.5, [
1956
+ 8,
1957
+ 0,
1958
+ 0
1959
+ ])
1960
+ ],
1961
+ hk: [
1962
+ k(0, 0),
1963
+ k(1.1, -.3),
1964
+ k(1.5, -.3)
1965
+ ],
1966
+ expression: [{
1967
+ t: 0,
1968
+ v: "off"
1969
+ }]
1970
+ }
1971
+ },
1972
+ relay: {
1973
+ duration: 2.4,
1974
+ squashAnchor: -1,
1975
+ tracks: {
1976
+ zoom: [k(0, .8), k(2.4, .8)],
1977
+ position: [
1978
+ k(0, [-.58, 0]),
1979
+ k(.12, [-.64, .01]),
1980
+ k(.3, [-.47, -.05], OVER),
1981
+ k(.52, [-.6, 0]),
1982
+ k(.7, [-.58, 0]),
1983
+ k(1.15, [-.58, -.018]),
1984
+ k(1.62, [-.58, .004]),
1985
+ k(1.9, [-.58, -.035]),
1986
+ k(2.1, [-.57, .05], OVER),
1987
+ k(2.3, [-.58, 0]),
1988
+ k(2.4, [-.58, 0])
1989
+ ],
1990
+ squash: [
1991
+ k(0, [1, 1]),
1992
+ k(.12, [1.05, .95]),
1993
+ k(.3, [.95, 1.06], OVER),
1994
+ k(.5, [1.02, .98]),
1995
+ k(.7, [1, 1]),
1996
+ k(1.9, [.97, 1.04]),
1997
+ k(2.1, [1.05, .95], OVER),
1998
+ k(2.3, [1, 1]),
1999
+ k(2.4, [1, 1])
2000
+ ],
2001
+ rotation: [
2002
+ k(0, [
2003
+ 0,
2004
+ 16,
2005
+ 0
2006
+ ]),
2007
+ k(.12, [
2008
+ -5,
2009
+ 10,
2010
+ 5
2011
+ ]),
2012
+ k(.3, [
2013
+ 8,
2014
+ 28,
2015
+ -9
2016
+ ], OVER),
2017
+ k(.52, [
2018
+ -2,
2019
+ 14,
2020
+ 2
2021
+ ]),
2022
+ k(.7, [
2023
+ 0,
2024
+ 17,
2025
+ 0
2026
+ ]),
2027
+ k(1.15, [
2028
+ 2,
2029
+ 19,
2030
+ 2
2031
+ ]),
2032
+ k(1.62, [
2033
+ -1,
2034
+ 15,
2035
+ -1
2036
+ ]),
2037
+ k(1.9, [
2038
+ -4,
2039
+ 15,
2040
+ 0
2041
+ ]),
2042
+ k(2.1, [
2043
+ 15,
2044
+ 9,
2045
+ 0
2046
+ ], OVER),
2047
+ k(2.3, [
2048
+ 0,
2049
+ 16,
2050
+ 0
2051
+ ]),
2052
+ k(2.4, [
2053
+ 0,
2054
+ 16,
2055
+ 0
2056
+ ])
2057
+ ],
2058
+ hk: [
2059
+ k(0, 0),
2060
+ k(.12, -.05),
2061
+ k(.3, .14),
2062
+ k(.55, 0),
2063
+ k(2.1, -.12),
2064
+ k(2.3, 0),
2065
+ k(2.4, 0)
2066
+ ],
2067
+ expression: [
2068
+ {
2069
+ t: 0,
2070
+ v: "listen"
2071
+ },
2072
+ blink(1.05),
2073
+ {
2074
+ t: 2.05,
2075
+ v: "grin",
2076
+ cut: false
2077
+ },
2078
+ {
2079
+ t: 2.38,
2080
+ v: "listen",
2081
+ cut: false
2082
+ }
2083
+ ]
2084
+ }
2085
+ },
2086
+ reboot: {
2087
+ duration: 2.4,
2088
+ squashAnchor: -1,
2089
+ tracks: {
2090
+ zoom: [
2091
+ k(0, .84),
2092
+ k(1.15, .84, OVER),
2093
+ k(1.35, .92),
2094
+ k(1.65, .84),
2095
+ k(2.4, .84)
2096
+ ],
2097
+ squash: [
2098
+ k(0, [1, 1]),
2099
+ k(.25, [1.06, .92]),
2100
+ k(.4, [1, 1]),
2101
+ k(1.15, [1, 1]),
2102
+ k(1.3, [.95, 1.07]),
2103
+ k(1.55, [1, 1]),
2104
+ k(2.4, [1, 1])
2105
+ ],
2106
+ rotation: [
2107
+ k(0, R0),
2108
+ k(.12, [
2109
+ 0,
2110
+ 0,
2111
+ -7
2112
+ ]),
2113
+ k(.3, [
2114
+ 0,
2115
+ 0,
2116
+ -4
2117
+ ], SPIN),
2118
+ k(1.15, [
2119
+ 0,
2120
+ 0,
2121
+ 360
2122
+ ]),
2123
+ k(1.35, [
2124
+ 0,
2125
+ 0,
2126
+ 354
2127
+ ]),
2128
+ k(1.6, [
2129
+ 0,
2130
+ 0,
2131
+ 361.5
2132
+ ]),
2133
+ k(1.85, [
2134
+ 0,
2135
+ 0,
2136
+ 360
2137
+ ]),
2138
+ k(2.4, [
2139
+ 0,
2140
+ 0,
2141
+ 360
2142
+ ])
2143
+ ],
2144
+ position: [
2145
+ k(0, [0, 0]),
2146
+ k(1.15, [0, 0]),
2147
+ k(1.3, [0, -.06], OVER),
2148
+ k(1.55, [0, .01]),
2149
+ k(1.75, [0, 0]),
2150
+ k(2.05, [0, -.015]),
2151
+ k(2.4, [0, 0])
2152
+ ],
2153
+ lids: [
2154
+ k(0, 0),
2155
+ k(.25, 1),
2156
+ k(1.15, 1),
2157
+ k(1.3, 0),
2158
+ k(2.4, 0)
2159
+ ],
2160
+ hk: [
2161
+ k(0, 0),
2162
+ k(.25, -.2),
2163
+ k(1.15, -.2),
2164
+ k(1.3, .18),
2165
+ k(1.7, 0),
2166
+ k(2.4, 0)
2167
+ ],
2168
+ expression: [
2169
+ {
2170
+ t: 0,
2171
+ v: "focus"
2172
+ },
2173
+ {
2174
+ t: 1.2,
2175
+ v: "grin"
2176
+ },
2177
+ blink(2.05)
2178
+ ]
2179
+ }
2180
+ }
2181
+ };
2182
+ const MORPH = {
2183
+ dots: {
2184
+ baseR: 22,
2185
+ zoom: 2,
2186
+ zoomL: 1.2
2187
+ },
2188
+ orbit: {
2189
+ baseR: 19,
2190
+ zoom: 2.2,
2191
+ zoomL: 1.35
2192
+ },
2193
+ radar: {
2194
+ baseR: 19,
2195
+ zoom: 1.6,
2196
+ zoomL: 1.05
2197
+ },
2198
+ progress: {
2199
+ baseR: 19,
2200
+ zoom: 2.2,
2201
+ zoomL: 1.2,
2202
+ shot: 2.5
2203
+ },
2204
+ bang: {
2205
+ baseR: 13,
2206
+ zoom: 1.9,
2207
+ zoomL: 1.15
2208
+ },
2209
+ standby: {
2210
+ baseR: 13,
2211
+ zoom: 3,
2212
+ zoomL: 1.7
2213
+ }
2214
+ };
2215
+ const MORPH_KINDS = Object.keys(MORPH);
2216
+ const STATE_GROUPS = [
2217
+ ["basic", "基础"],
2218
+ ["work", "工作中"],
2219
+ ["social", "与人互动"],
2220
+ ["collab", "协作"],
2221
+ ["mood", "情绪"],
2222
+ ["page", "页面与模块"],
2223
+ ["lifecycle", "生命周期"],
2224
+ ["system", "系统"]
2225
+ ];
2226
+ const L = (hump = 1, wave = 0, o = {}) => ({
2227
+ hump,
2228
+ wave,
2229
+ ws: .9,
2230
+ skew: 0,
2231
+ ...o
2232
+ });
2233
+ const STATES = {
2234
+ idle: {
2235
+ group: "basic",
2236
+ label: "待机",
2237
+ logo: L(),
2238
+ clips: [
2239
+ "idleBreath",
2240
+ "idleBreath",
2241
+ "idleLook",
2242
+ "idleHop",
2243
+ "idleTilt"
2244
+ ],
2245
+ compactClips: ["idleBreath"]
2246
+ },
2247
+ listening: {
2248
+ group: "basic",
2249
+ label: "倾听",
2250
+ shape: "listen",
2251
+ face: "listen",
2252
+ logo: L(1.14),
2253
+ clips: ["listen"]
2254
+ },
2255
+ thinking: {
2256
+ group: "basic",
2257
+ label: "思考",
2258
+ shape: "think",
2259
+ face: "think",
2260
+ logo: L(1, .05),
2261
+ clips: ["ponder"],
2262
+ morph: "dots"
2263
+ },
2264
+ speaking: {
2265
+ group: "basic",
2266
+ label: "说话",
2267
+ shape: "talk",
2268
+ face: "speak",
2269
+ logo: L(),
2270
+ clips: ["listen"],
2271
+ speak: true
2272
+ },
2273
+ sleeping: {
2274
+ group: "basic",
2275
+ label: "睡眠",
2276
+ shape: "sleep",
2277
+ face: "sleep",
2278
+ logo: L(.5),
2279
+ clips: ["droop"],
2280
+ morph: "standby",
2281
+ fps: 30
2282
+ },
2283
+ "listening-voice": {
2284
+ group: "basic",
2285
+ label: "语音聆听",
2286
+ shape: "listen",
2287
+ face: "listen",
2288
+ logo: L(1.12),
2289
+ clips: ["listen"],
2290
+ voice: true
2291
+ },
2292
+ working: {
2293
+ group: "work",
2294
+ label: "专注工作",
2295
+ logo: L(.95, .025, { ws: 2.2 }),
2296
+ clips: ["work"]
2297
+ },
2298
+ "thinking-deep": {
2299
+ group: "work",
2300
+ label: "深度推理",
2301
+ shape: "think",
2302
+ face: "think",
2303
+ logo: L(1, .04, { ws: .4 }),
2304
+ clips: ["ponder"],
2305
+ morph: "dots"
2306
+ },
2307
+ planning: {
2308
+ group: "work",
2309
+ label: "规划清单",
2310
+ face: "read",
2311
+ logo: L(1),
2312
+ clips: ["work", "ponder"],
2313
+ morph: "dots"
2314
+ },
2315
+ searching: {
2316
+ group: "work",
2317
+ label: "搜索",
2318
+ shape: "listen",
2319
+ face: "scan",
2320
+ logo: L(1.05),
2321
+ clips: ["scan"],
2322
+ morph: "radar"
2323
+ },
2324
+ reading: {
2325
+ group: "work",
2326
+ label: "阅读",
2327
+ logo: L(1, .015, { ws: .5 }),
2328
+ clips: ["scan", "work"]
2329
+ },
2330
+ reviewing: {
2331
+ group: "work",
2332
+ label: "审阅",
2333
+ logo: L(1.05),
2334
+ clips: [
2335
+ "scan",
2336
+ "scan",
2337
+ "work"
2338
+ ]
2339
+ },
2340
+ coding: {
2341
+ group: "work",
2342
+ label: "写代码",
2343
+ logo: L(1, .02, { ws: 3 }),
2344
+ clips: ["work"]
2345
+ },
2346
+ testing: {
2347
+ group: "work",
2348
+ label: "测试",
2349
+ logo: L(1, 0, { skew: .15 }),
2350
+ clips: ["work", "ponder"]
2351
+ },
2352
+ deploying: {
2353
+ group: "work",
2354
+ label: "部署",
2355
+ shape: "tall",
2356
+ face: "greet",
2357
+ logo: L(1.15, .03, { ws: 2 }),
2358
+ clips: ["work"],
2359
+ morph: "progress"
2360
+ },
2361
+ syncing: {
2362
+ group: "work",
2363
+ label: "同步",
2364
+ shape: "spin",
2365
+ face: "loadf",
2366
+ logo: L(1, .03, { ws: -1.2 }),
2367
+ clips: ["work"],
2368
+ morph: "orbit"
2369
+ },
2370
+ downloading: {
2371
+ group: "work",
2372
+ label: "下载",
2373
+ face: "loadf",
2374
+ logo: L(.95, .03, { ws: 1.5 }),
2375
+ clips: ["work"],
2376
+ morph: "progress"
2377
+ },
2378
+ handoff: {
2379
+ group: "work",
2380
+ label: "交付/上传",
2381
+ face: "grin",
2382
+ logo: L(1.05),
2383
+ clips: ["work"],
2384
+ morph: "progress"
2385
+ },
2386
+ loading: {
2387
+ group: "work",
2388
+ label: "连接中",
2389
+ shape: "spin",
2390
+ face: "loadf",
2391
+ logo: L(.9, .04, { ws: 2.5 }),
2392
+ clips: ["idleBreath"],
2393
+ morph: "progress"
2394
+ },
2395
+ greeting: {
2396
+ group: "social",
2397
+ label: "打招呼",
2398
+ face: "greet",
2399
+ logo: L(1.08),
2400
+ clips: ["pop", "idleTilt"],
2401
+ next: "idle",
2402
+ holdSeconds: 2.4
2403
+ },
2404
+ "hello-enter": {
2405
+ group: "social",
2406
+ label: "入场",
2407
+ face: "greet",
2408
+ logo: L(1.05),
2409
+ clips: ["pop"],
2410
+ next: "idle"
2411
+ },
2412
+ goodbye: {
2413
+ group: "social",
2414
+ label: "挥手离场",
2415
+ face: "greet",
2416
+ logo: L(1),
2417
+ clips: ["shake", "slump"],
2418
+ once: true
2419
+ },
2420
+ notification: {
2421
+ group: "social",
2422
+ label: "新消息",
2423
+ face: "wait",
2424
+ logo: L(1.05),
2425
+ clips: ["pop"]
2426
+ },
2427
+ mentioned: {
2428
+ group: "social",
2429
+ label: "被 @",
2430
+ face: "listen",
2431
+ logo: L(1.1, 0, { skew: .25 }),
2432
+ clips: ["pop"],
2433
+ next: "idle",
2434
+ holdSeconds: 2.8
2435
+ },
2436
+ "typing-reply": {
2437
+ group: "social",
2438
+ label: "正在回复",
2439
+ face: "read",
2440
+ logo: L(1, .02, { ws: 2.5 }),
2441
+ clips: ["listen"],
2442
+ morph: "dots"
2443
+ },
2444
+ waiting: {
2445
+ group: "social",
2446
+ label: "等待确认",
2447
+ face: "wait",
2448
+ logo: L(1.05),
2449
+ clips: ["listen"],
2450
+ morph: "orbit"
2451
+ },
2452
+ approved: {
2453
+ group: "social",
2454
+ label: "已批准",
2455
+ shape: "burst",
2456
+ face: "laugh",
2457
+ logo: L(1.12),
2458
+ clips: ["nod", "pop"],
2459
+ next: "idle"
2460
+ },
2461
+ rejected: {
2462
+ group: "social",
2463
+ label: "已驳回",
2464
+ shape: "squash",
2465
+ face: "nope",
2466
+ logo: L(.85),
2467
+ clips: ["shake", "slump"],
2468
+ next: "idle"
2469
+ },
2470
+ nodding: {
2471
+ group: "social",
2472
+ label: "点头同意",
2473
+ face: "grin",
2474
+ logo: L(1.05),
2475
+ clips: ["nod"],
2476
+ next: "idle",
2477
+ holdSeconds: 2.4
2478
+ },
2479
+ shaking: {
2480
+ group: "social",
2481
+ label: "摇头否定",
2482
+ face: "nope",
2483
+ logo: L(.9),
2484
+ clips: ["shake"],
2485
+ next: "idle",
2486
+ holdSeconds: 2
2487
+ },
2488
+ thanks: {
2489
+ group: "social",
2490
+ label: "感谢",
2491
+ face: "thanks",
2492
+ logo: L(1.1),
2493
+ clips: ["pop"],
2494
+ next: "idle",
2495
+ holdSeconds: 3
2496
+ },
2497
+ success: {
2498
+ group: "social",
2499
+ label: "成功",
2500
+ shape: "burst",
2501
+ logo: L(1.1, .06),
2502
+ clips: ["hop"],
2503
+ next: "idle"
2504
+ },
2505
+ celebrating: {
2506
+ group: "social",
2507
+ label: "庆祝",
2508
+ shape: "burst",
2509
+ logo: L(1.18, .07, { ws: 1.6 }),
2510
+ clips: ["bounce", "hop"],
2511
+ next: "idle"
2512
+ },
2513
+ "handover-to-human": {
2514
+ group: "collab",
2515
+ label: "转人工",
2516
+ face: "grin",
2517
+ logo: L(1.05, 0, { skew: .2 }),
2518
+ clips: ["idleLook"]
2519
+ },
2520
+ "asking-question": {
2521
+ group: "collab",
2522
+ label: "向你提问",
2523
+ face: "listen",
2524
+ logo: L(1.08, 0, { skew: -.15 }),
2525
+ clips: ["ponder"]
2526
+ },
2527
+ collaborating: {
2528
+ group: "collab",
2529
+ label: "协同工作",
2530
+ logo: L(1.05, .02),
2531
+ clips: ["relay"],
2532
+ accent: "relay"
2533
+ },
2534
+ "celebrating-team": {
2535
+ group: "collab",
2536
+ label: "团队庆祝",
2537
+ shape: "burst",
2538
+ face: "laugh",
2539
+ logo: L(1.18, .06, { ws: 2 }),
2540
+ clips: ["bounce", "hop"],
2541
+ next: "idle"
2542
+ },
2543
+ confused: {
2544
+ group: "mood",
2545
+ label: "困惑",
2546
+ shape: "think",
2547
+ face: "confused",
2548
+ logo: L(1, 0, { skew: -.25 }),
2549
+ clips: ["ponder", "idleTilt"]
2550
+ },
2551
+ surprised: {
2552
+ group: "mood",
2553
+ label: "惊讶",
2554
+ shape: "tall",
2555
+ face: "wow",
2556
+ logo: L(1.25),
2557
+ clips: ["pop"],
2558
+ next: "idle",
2559
+ holdSeconds: 2.4
2560
+ },
2561
+ sad: {
2562
+ group: "mood",
2563
+ label: "难过",
2564
+ shape: "squash",
2565
+ face: "sad",
2566
+ logo: L(.68),
2567
+ clips: ["droop"]
2568
+ },
2569
+ shy: {
2570
+ group: "mood",
2571
+ label: "害羞",
2572
+ face: "shy",
2573
+ logo: L(.92, 0, { skew: .2 }),
2574
+ clips: ["idleTilt"]
2575
+ },
2576
+ excited: {
2577
+ group: "mood",
2578
+ label: "兴奋",
2579
+ shape: "burst",
2580
+ logo: L(1.2, .06, { ws: 2.5 }),
2581
+ clips: ["bounce"]
2582
+ },
2583
+ proud: {
2584
+ group: "mood",
2585
+ label: "得意",
2586
+ face: "smug",
2587
+ logo: L(1.1, 0, { skew: -.12 }),
2588
+ clips: ["idleTilt", "idleBreath"]
2589
+ },
2590
+ tired: {
2591
+ group: "mood",
2592
+ label: "疲惫",
2593
+ shape: "squash",
2594
+ face: "tired",
2595
+ logo: L(.7),
2596
+ clips: ["droop"]
2597
+ },
2598
+ "do-not-disturb": {
2599
+ group: "mood",
2600
+ label: "专注免打扰",
2601
+ face: "focus",
2602
+ logo: L(.85),
2603
+ clips: ["idleBreath"],
2604
+ fps: 24
2605
+ },
2606
+ "page-loading": {
2607
+ group: "page",
2608
+ label: "页面加载",
2609
+ shape: "spin",
2610
+ face: "loadf",
2611
+ logo: L(1, .04, { ws: 2 }),
2612
+ clips: ["idleBreath"],
2613
+ morph: "progress"
2614
+ },
2615
+ "module-loading": {
2616
+ group: "page",
2617
+ label: "模块加载",
2618
+ face: "loadf",
2619
+ logo: L(.95, .02, { ws: 1.5 }),
2620
+ clips: ["idleBreath"],
2621
+ morph: "dots",
2622
+ fps: 30
2623
+ },
2624
+ skeleton: {
2625
+ group: "page",
2626
+ label: "骨架占位",
2627
+ face: "off",
2628
+ logo: L(.9),
2629
+ clips: ["idleBreath"],
2630
+ morph: "standby",
2631
+ gray: .55,
2632
+ fps: 30
2633
+ },
2634
+ empty: {
2635
+ group: "page",
2636
+ label: "空状态",
2637
+ face: "nope",
2638
+ logo: L(.95, 0, { skew: .1 }),
2639
+ clips: ["idleLook"]
2640
+ },
2641
+ "no-results": {
2642
+ group: "page",
2643
+ label: "无搜索结果",
2644
+ face: "confused",
2645
+ logo: L(.95),
2646
+ clips: ["scan", "shake"]
2647
+ },
2648
+ "not-found-404": {
2649
+ group: "page",
2650
+ label: "404 迷路",
2651
+ shape: "think",
2652
+ face: "confused",
2653
+ logo: L(1, 0, { skew: -.2 }),
2654
+ clips: ["idleLook", "ponder"]
2655
+ },
2656
+ "no-permission": {
2657
+ group: "page",
2658
+ label: "无权限",
2659
+ face: "nope",
2660
+ logo: L(.85),
2661
+ clips: ["shake"],
2662
+ morph: "bang"
2663
+ },
2664
+ "network-offline": {
2665
+ group: "page",
2666
+ label: "断网",
2667
+ shape: "squash",
2668
+ face: "sad",
2669
+ logo: L(.75),
2670
+ clips: ["droop"],
2671
+ morph: "standby",
2672
+ gray: .35,
2673
+ fps: 30
2674
+ },
2675
+ reconnecting: {
2676
+ group: "page",
2677
+ label: "重连中",
2678
+ face: "scan",
2679
+ logo: L(1, .03, { ws: 1.5 }),
2680
+ clips: ["scan"],
2681
+ morph: "radar"
2682
+ },
2683
+ retrying: {
2684
+ group: "page",
2685
+ label: "重试中",
2686
+ face: "focus",
2687
+ logo: L(.95, .02, { ws: 2 }),
2688
+ clips: ["work"],
2689
+ morph: "orbit"
2690
+ },
2691
+ maintenance: {
2692
+ group: "page",
2693
+ label: "维护施工",
2694
+ logo: L(.95),
2695
+ clips: ["work"]
2696
+ },
2697
+ updating: {
2698
+ group: "page",
2699
+ label: "版本更新",
2700
+ shape: "tall",
2701
+ face: "loadf",
2702
+ logo: L(1.05, .03, { ws: 1.8 }),
2703
+ clips: ["idleBreath"],
2704
+ morph: "progress"
2705
+ },
2706
+ saving: {
2707
+ group: "page",
2708
+ label: "保存中",
2709
+ face: "focus",
2710
+ logo: L(1, .02, { ws: 2 }),
2711
+ clips: ["work"],
2712
+ morph: "progress"
2713
+ },
2714
+ saved: {
2715
+ group: "page",
2716
+ label: "已保存",
2717
+ face: "thanks",
2718
+ logo: L(1.08),
2719
+ clips: ["pop"],
2720
+ next: "idle"
2721
+ },
2722
+ "copying-done": {
2723
+ group: "page",
2724
+ label: "复制成功",
2725
+ face: "thanks",
2726
+ logo: L(1.08),
2727
+ clips: ["pop"],
2728
+ next: "idle"
2729
+ },
2730
+ starting: {
2731
+ group: "lifecycle",
2732
+ label: "启动中",
2733
+ shape: "squash",
2734
+ face: "tired",
2735
+ logo: L(.6, .03, { ws: 1.5 }),
2736
+ clips: ["idleBreath"],
2737
+ morph: "progress",
2738
+ next: "ready",
2739
+ holdSeconds: 2.4
2740
+ },
2741
+ ready: {
2742
+ group: "lifecycle",
2743
+ label: "启动完成",
2744
+ face: "greet",
2745
+ logo: L(1.12),
2746
+ clips: ["pop"],
2747
+ next: "idle"
2748
+ },
2749
+ paused: {
2750
+ group: "lifecycle",
2751
+ label: "已暂停",
2752
+ face: "wait",
2753
+ logo: L(1),
2754
+ clips: ["slump"],
2755
+ once: true,
2756
+ gray: .25
2757
+ },
2758
+ resuming: {
2759
+ group: "lifecycle",
2760
+ label: "继续",
2761
+ face: "grin",
2762
+ logo: L(1.05),
2763
+ clips: ["pop"],
2764
+ next: "idle"
2765
+ },
2766
+ stopping: {
2767
+ group: "lifecycle",
2768
+ label: "停止中",
2769
+ face: "nope",
2770
+ logo: L(.85),
2771
+ clips: ["slump"],
2772
+ next: "idle",
2773
+ holdSeconds: 1.8
2774
+ },
2775
+ "shutting-down": {
2776
+ group: "lifecycle",
2777
+ label: "关机",
2778
+ shape: "squash",
2779
+ face: "sleep",
2780
+ logo: L(.55),
2781
+ clips: ["slump"],
2782
+ morph: "standby",
2783
+ gray: .5,
2784
+ fps: 30
2785
+ },
2786
+ queued: {
2787
+ group: "lifecycle",
2788
+ label: "排队中",
2789
+ face: "wait",
2790
+ logo: L(.95),
2791
+ clips: ["listen"],
2792
+ morph: "orbit"
2793
+ },
2794
+ "waiting-for-input": {
2795
+ group: "lifecycle",
2796
+ label: "等你输入",
2797
+ face: "wait",
2798
+ logo: L(1),
2799
+ clips: ["listen"],
2800
+ morph: "orbit"
2801
+ },
2802
+ warning: {
2803
+ group: "system",
2804
+ label: "警告",
2805
+ face: "warn",
2806
+ logo: L(1.05),
2807
+ clips: ["listen"],
2808
+ morph: "bang"
2809
+ },
2810
+ error: {
2811
+ group: "system",
2812
+ label: "出错",
2813
+ shape: "error",
2814
+ face: "frown",
2815
+ logo: L(.72),
2816
+ clips: ["shake", "slump"],
2817
+ once: true
2818
+ },
2819
+ offline: {
2820
+ group: "system",
2821
+ label: "离线",
2822
+ face: "off",
2823
+ logo: L(.6),
2824
+ clips: ["slump"],
2825
+ once: true,
2826
+ gray: 1
2827
+ },
2828
+ scheduled: {
2829
+ group: "system",
2830
+ label: "已排程",
2831
+ face: "wait",
2832
+ logo: L(1),
2833
+ clips: ["listen"],
2834
+ morph: "orbit"
2835
+ },
2836
+ alarm: {
2837
+ group: "system",
2838
+ label: "定时触发",
2839
+ shape: "talk",
2840
+ face: "wow",
2841
+ logo: L(1.2),
2842
+ clips: ["shake"],
2843
+ morph: "bang"
2844
+ },
2845
+ "rate-limited": {
2846
+ group: "system",
2847
+ label: "限流中",
2848
+ shape: "squash",
2849
+ face: "nope",
2850
+ logo: L(.8),
2851
+ clips: ["droop"],
2852
+ morph: "orbit"
2853
+ },
2854
+ recovering: {
2855
+ group: "system",
2856
+ label: "修复中",
2857
+ logo: L(.95, .02),
2858
+ clips: ["reboot"],
2859
+ accent: "reboot"
2860
+ }
2861
+ };
2862
+ const STATE_ALIASES = {};
2863
+ const resolveState = (name) => STATES[name] ? name : STATE_ALIASES[name] && STATES[STATE_ALIASES[name]] ? STATE_ALIASES[name] : null;
2864
+ const META = {
2865
+ idle: ["常驻头像、无事发生", "SML"],
2866
+ listening: ["用户正在输入 / 说话", "LM"],
2867
+ "listening-voice": ["语音输入,随音量起伏", "LM"],
2868
+ thinking: ["开始推理", "LMS"],
2869
+ speaking: ["流式输出回复", "LM"],
2870
+ sleeping: ["长时间无交互", "MS"],
2871
+ working: ["调用工具、执行任务", "LMS"],
2872
+ "thinking-deep": ["长时间推理 / 复杂规划", "LMS"],
2873
+ planning: ["生成计划 / 待办", "LMS"],
2874
+ searching: ["检索 / 联网搜索", "LMS"],
2875
+ reading: ["读文档 / 网页", "LM"],
2876
+ reviewing: ["审阅代码或文档", "LM"],
2877
+ coding: ["写代码 / 生成内容", "LM"],
2878
+ testing: ["跑测试", "LM"],
2879
+ deploying: ["发布 / 部署", "LMS"],
2880
+ syncing: ["同步数据", "LMS"],
2881
+ downloading: ["下载文件", "LMS"],
2882
+ handoff: ["上传 / 交付产物", "LMS"],
2883
+ loading: ["建立连接", "LMS"],
2884
+ greeting: ["打开对话 / 欢迎语", "LM"],
2885
+ "hello-enter": ["Agent 入场(会话开始)", "LM"],
2886
+ goodbye: ["会话结束 / 离场", "LM"],
2887
+ notification: ["有新消息", "MS"],
2888
+ mentioned: ["被 @", "MS"],
2889
+ "typing-reply": ["正在组织回复", "MS"],
2890
+ waiting: ["等待人审批", "LMS"],
2891
+ approved: ["审批通过", "LM"],
2892
+ rejected: ["审批驳回", "LM"],
2893
+ nodding: ["确认 / 同意", "LM"],
2894
+ shaking: ["拒绝 / 不同意", "LM"],
2895
+ thanks: ["收到感谢", "LM"],
2896
+ success: ["任务完成", "LMS"],
2897
+ celebrating: ["里程碑达成", "L"],
2898
+ "handover-to-human": ["转人工客服", "LM"],
2899
+ "asking-question": ["需要用户补充信息", "LM"],
2900
+ collaborating: ["多 Agent / 人机协作", "L"],
2901
+ "celebrating-team": ["团队目标达成", "L"],
2902
+ confused: ["意图不明", "LM"],
2903
+ surprised: ["意外结果", "LM"],
2904
+ sad: ["任务失败后安抚", "LM"],
2905
+ shy: ["被夸奖", "LM"],
2906
+ excited: ["好消息", "LM"],
2907
+ proud: ["完成高难任务", "LM"],
2908
+ tired: ["长任务 / 高负载", "LM"],
2909
+ "do-not-disturb": ["专注模式", "MS"],
2910
+ "page-loading": ["整页加载(居中大图)", "L"],
2911
+ "module-loading": ["局部区块加载(低打扰)", "S"],
2912
+ skeleton: ["骨架屏占位", "MS"],
2913
+ empty: ["列表 / 页面为空", "LM"],
2914
+ "no-results": ["搜索无结果", "LM"],
2915
+ "not-found-404": ["404 页面", "L"],
2916
+ "no-permission": ["无权限访问", "LMS"],
2917
+ "network-offline": ["网络断开", "LMS"],
2918
+ reconnecting: ["断线重连", "MS"],
2919
+ retrying: ["请求重试", "MS"],
2920
+ maintenance: ["系统维护", "L"],
2921
+ updating: ["版本更新中", "LM"],
2922
+ saving: ["保存中", "S"],
2923
+ saved: ["已保存", "S"],
2924
+ "copying-done": ["复制成功", "S"],
2925
+ starting: ["Agent 启动中", "LM"],
2926
+ ready: ["启动完成", "LM"],
2927
+ paused: ["任务已暂停(引擎休眠)", "LMS"],
2928
+ resuming: ["继续任务", "LM"],
2929
+ stopping: ["正在停止", "LM"],
2930
+ "shutting-down": ["关闭 / 下线", "LM"],
2931
+ queued: ["排队等待资源", "MS"],
2932
+ "waiting-for-input": ["等待用户输入", "LM"],
2933
+ warning: ["需要注意", "LMS"],
2934
+ error: ["任务失败", "LMS"],
2935
+ offline: ["Agent 不在线", "MS"],
2936
+ scheduled: ["已创建定时任务", "MS"],
2937
+ alarm: ["定时触发", "LM"],
2938
+ "rate-limited": ["被限流", "MS"],
2939
+ recovering: ["自动修复 / 重试", "LM"]
2940
+ };
2941
+ const BLINK_DUR = .26;
2942
+ function compileClip(name, def) {
2943
+ const tr = def.tracks || {};
2944
+ const lids = (tr.lids || []).slice(), expression = [];
2945
+ for (const e of tr.expression || []) if (e.v === "blink") lids.push(k(e.t, 0), k(e.t + BLINK_DUR * .45, 1), k(e.t + BLINK_DUR, 0));
2946
+ else expression.push({
2947
+ t: e.t,
2948
+ name: e.v,
2949
+ cut: e.cut !== false
2950
+ });
2951
+ lids.sort((a, b) => a.t - b.t);
2952
+ return {
2953
+ name,
2954
+ duration: def.duration,
2955
+ restTime: def.restTime || 0,
2956
+ squashAnchor: def.squashAnchor || 0,
2957
+ tracks: {
2958
+ position: tr.position,
2959
+ rotation: tr.rotation,
2960
+ squash: tr.squash,
2961
+ zoom: tr.zoom,
2962
+ lids: lids.length ? lids : null,
2963
+ hk: tr.hk,
2964
+ sk: tr.sk,
2965
+ wv: tr.wv
2966
+ },
2967
+ expression
2968
+ };
2969
+ }
2970
+ const COMPILED = {};
2971
+ for (const [n, c] of Object.entries(CLIPS)) COMPILED[n] = compileClip(n, c);
2972
+ function samplePose(clip, t) {
2973
+ const T = clip.tracks, v = (key, d) => {
2974
+ const r = evalTrack(T[key], t);
2975
+ return r ? r : d;
2976
+ };
2977
+ return {
2978
+ rot: v("rotation", R0).slice(),
2979
+ pos: v("position", [0, 0]).slice(),
2980
+ scl: v("squash", [1, 1]).slice(),
2981
+ zoom: v("zoom", [1])[0],
2982
+ lids: clamp01(v("lids", [0])[0]),
2983
+ hk: v("hk", [0])[0],
2984
+ sk: v("sk", [0])[0],
2985
+ wv: v("wv", [0])[0]
2986
+ };
2987
+ }
2988
+ const restFrame = (clip) => samplePose(clip, clip.restTime);
2989
+ const angDiff = (a, b) => Math.abs(((a - b) % 360 + 540) % 360 - 180);
2990
+ function isSimilar(a, b) {
2991
+ for (let i = 0; i < 3; i++) if (angDiff(a.rot[i], b.rot[i]) >= 4) return false;
2992
+ return Math.abs(a.pos[0] - b.pos[0]) < .015 && Math.abs(a.pos[1] - b.pos[1]) < .015 && Math.abs(a.scl[0] - b.scl[0]) < .02 && Math.abs(a.scl[1] - b.scl[1]) < .02 && Math.abs(a.zoom - b.zoom) < .02 && Math.abs(a.lids - b.lids) < .05 && Math.abs(a.hk - b.hk) < .02 && Math.abs(a.sk - b.sk) < .02 && Math.abs(a.wv - b.wv) < .02;
2993
+ }
2994
+ const BRIDGE_SECONDS = .35;
2995
+ function bridgeClip(from, to, squashAnchor = 0) {
2996
+ const tr = (a, b) => [k(0, a, EASE_BRIDGE), k(BRIDGE_SECONDS, b)];
2997
+ const rot = to.rot.map((r, i) => r + 360 * Math.round((from.rot[i] - r) / 360));
2998
+ return {
2999
+ name: "bridge",
3000
+ duration: BRIDGE_SECONDS,
3001
+ restTime: 0,
3002
+ squashAnchor,
3003
+ expression: [],
3004
+ tracks: {
3005
+ position: tr(from.pos, to.pos),
3006
+ rotation: tr(from.rot, rot),
3007
+ squash: tr(from.scl, to.scl),
3008
+ zoom: tr([from.zoom], [to.zoom]),
3009
+ lids: from.lids === 0 && to.lids === 0 ? null : tr([from.lids], [to.lids]),
3010
+ hk: tr([from.hk], [to.hk]),
3011
+ sk: tr([from.sk], [to.sk]),
3012
+ wv: tr([from.wv], [to.wv])
3013
+ }
3014
+ };
3015
+ }
3016
+ for (const [key, st] of Object.entries(STATES)) {
3017
+ const m = META[key] || ["", "M"];
3018
+ st.scene = m[0];
3019
+ st.sizes = m[1].split("");
3020
+ st.id = key;
3021
+ st.shape = st.shape || "base";
3022
+ for (const c of [...st.clips, ...st.compactClips || []]) if (!CLIPS[c]) throw new Error(`state ${key}: unknown clip ${c}`);
3023
+ st.sequential = !!(st.next && st.holdSeconds == null) || !!st.once;
3024
+ st.hold = st.holdSeconds;
3025
+ st.once = !!(st.next || st.once);
3026
+ st.duration = st.once ? st.holdSeconds ?? st.clips.reduce((s, c) => s + CLIPS[c].duration + .35, 0) : null;
3027
+ }
3028
+ const MORPH_SHOT_OFF = 1.5;
3029
+ var MorphBehavior = class {
3030
+ constructor(rnd = Math.random) {
3031
+ this.rnd = rnd;
3032
+ this.amount = createSpring(0, 14, 1);
3033
+ this.swap = createSpring(1, 11, 1);
3034
+ this.spin = createSpring(0, 14, 1);
3035
+ this.target = null;
3036
+ this.seen = null;
3037
+ this.kind = null;
3038
+ this.outgoing = null;
3039
+ this.g = 0;
3040
+ this.kindT0 = 0;
3041
+ this.shotT0 = 0;
3042
+ this.outT0 = 0;
3043
+ this.outShotT0 = 0;
3044
+ this.shotOff = false;
3045
+ this.shotOffT = 0;
3046
+ this.active = false;
3047
+ this.dir = 1;
3048
+ this.spinAcc = 0;
3049
+ }
3050
+ set(kind) {
3051
+ this.target = kind && MORPH[kind] ? kind : null;
3052
+ }
3053
+ _rule(reduced) {
3054
+ const v = this.target, shotPrev = this.shotT0;
3055
+ if (v !== this.seen) {
3056
+ this.seen = v;
3057
+ if (v != null) {
3058
+ this.shotT0 = this.g;
3059
+ this.shotOff = false;
3060
+ }
3061
+ }
3062
+ let on = v != null;
3063
+ if (v != null && MORPH[v].shot) {
3064
+ if (!this.shotOff && this.g - this.shotT0 > MORPH[v].shot) {
3065
+ this.shotOff = true;
3066
+ this.shotOffT = this.g;
3067
+ } else if (this.shotOff && this.g - this.shotOffT > MORPH_SHOT_OFF) {
3068
+ this.shotOff = false;
3069
+ this.shotT0 = this.g;
3070
+ }
3071
+ on = !this.shotOff;
3072
+ }
3073
+ this.amount.target = on ? 1 : 0;
3074
+ if (v != null && v !== this.kind) {
3075
+ if (this.kind != null && this.amount.x > .02) {
3076
+ this.outgoing = this.kind;
3077
+ this.outT0 = this.kindT0;
3078
+ this.outShotT0 = shotPrev;
3079
+ this.swap.x = reduced ? 1 : 0;
3080
+ } else {
3081
+ this.outgoing = null;
3082
+ this.swap.x = 1;
3083
+ }
3084
+ this.swap.v = 0;
3085
+ this.swap.target = 1;
3086
+ this.kind = v;
3087
+ this.kindT0 = this.g;
3088
+ }
3089
+ if (v == null && this.amount.x < .004) {
3090
+ this.kind = null;
3091
+ this.outgoing = null;
3092
+ }
3093
+ if (this.swap.x > .996) this.outgoing = null;
3094
+ if (on !== this.active) {
3095
+ if (on && !reduced) this.dir = this.rnd() < .5 ? 1 : -1;
3096
+ if (!reduced) {
3097
+ this.spinAcc += Math.PI * this.dir;
3098
+ this.spin.target = this.spinAcc;
3099
+ }
3100
+ this.active = on;
3101
+ }
3102
+ }
3103
+ advance(dt, reduced = false) {
3104
+ dt = dt > 0 ? Math.min(dt, .1) : 0;
3105
+ this.g += dt;
3106
+ this._rule(reduced);
3107
+ stepSpring(this.amount, dt);
3108
+ stepSpring(this.swap, dt);
3109
+ stepSpring(this.spin, dt);
3110
+ if (reduced) {
3111
+ this.swap.x = 1;
3112
+ this.spin.x = this.spin.target;
3113
+ this.amount.x = this.amount.target;
3114
+ }
3115
+ }
3116
+ settle() {
3117
+ this._rule(false);
3118
+ for (const s of [
3119
+ this.amount,
3120
+ this.swap,
3121
+ this.spin
3122
+ ]) snapSpring(s);
3123
+ this._rule(false);
3124
+ }
3125
+ snapshot(clockOverride) {
3126
+ const g = clockOverride ?? this.g;
3127
+ return {
3128
+ amount: clamp01(this.amount.x),
3129
+ swap: clamp01(this.swap.x),
3130
+ spin: this.spin.x,
3131
+ kind: this.kind,
3132
+ outgoing: this.outgoing,
3133
+ clock: {
3134
+ stateTime: g - this.kindT0,
3135
+ shotTime: g - this.shotT0
3136
+ },
3137
+ outgoingClock: {
3138
+ stateTime: g - this.outT0,
3139
+ shotTime: g - this.outShotT0
3140
+ },
3141
+ isSettled: Math.abs(this.amount.x - this.amount.target) < .001 && Math.abs(this.spin.target - this.spin.x) < .01 && this.swap.x > .996
3142
+ };
3143
+ }
3144
+ };
3145
+ const DU = 114;
3146
+ function dotsWave(clock, idx, a, still) {
3147
+ if (still) return {
3148
+ lift: 0,
3149
+ pop: 1,
3150
+ tone: 1
3151
+ };
3152
+ const o = frac(clock.stateTime / 1.4 + .119), s = Math.abs(o - idx / 3), i = Math.min(s, 1 - s), A = Math.exp(-(i * i) / (2 * .15 * .15));
3153
+ return {
3154
+ lift: A * 9 * a,
3155
+ pop: .84 + .22 * A,
3156
+ tone: 1 - .5 * (1 - A)
3157
+ };
3158
+ }
3159
+ const disc = (key, cx, cy, r, opacity) => ({
3160
+ type: "disc",
3161
+ key,
3162
+ cx,
3163
+ cy,
3164
+ r,
3165
+ opacity
3166
+ });
3167
+ const ring = (key, r, width, opacity, arc) => ({
3168
+ type: "ring",
3169
+ key,
3170
+ cx: 0,
3171
+ cy: 0,
3172
+ r,
3173
+ width,
3174
+ opacity,
3175
+ arc
3176
+ });
3177
+ function bangBar() {
3178
+ const pts = [], bot = 48, rt = 15, rb = 8.5, n = 10;
3179
+ for (let i = 0; i <= n; i++) {
3180
+ const a = Math.PI + i / n * Math.PI;
3181
+ pts.push([rt * Math.cos(a), -33 + rt * Math.sin(a)]);
3182
+ }
3183
+ for (let i = 0; i <= n; i++) {
3184
+ const a = i / n * Math.PI;
3185
+ pts.push([rb * Math.cos(a), bot - rb + rb * Math.sin(a)]);
3186
+ }
3187
+ return pts;
3188
+ }
3189
+ const BANG_BAR = bangBar();
3190
+ const GEN = {
3191
+ dots(e, clock, baseR, still) {
3192
+ const out = [];
3193
+ for (let s = 0; s < 2; s++) {
3194
+ const i = clamp01((e - s * .12) / (1 - s * .12));
3195
+ if (i <= .004) continue;
3196
+ const u = dotsWave(clock, s === 0 ? 0 : 2, e, still);
3197
+ out.push(disc(`dots.${s}`, (s ? 62 : -62) * easeOutBack(i), -u.lift, 22 * easeOutCubic(i) * u.pop * 1.02, easeOutCubic(i) * u.tone));
3198
+ }
3199
+ return out;
3200
+ },
3201
+ orbit(e, clock, baseR, still, detail) {
3202
+ const n = easeOutCubic(e), r = 52 * easeOutBack(e), s = clock.stateTime * 1.7, N = detail ? 5 : 4;
3203
+ return Array.from({ length: N }, (_, i) => {
3204
+ const c = s + i * TAU / N, u = Math.cos(c), l = .5 + .5 * clamp01(u), rr = r * 1.1;
3205
+ return disc(`orbit.${i}`, rr * Math.sin(c), -rr * .5 * u, Math.max(12 * l * n, .3), Math.min(1, Math.max(.18, (u + .4) / .6)) * n);
3206
+ });
3207
+ },
3208
+ radar(e, clock, baseR, still, detail) {
3209
+ const r = easeOutCubic(e), N = detail ? 3 : 2;
3210
+ return Array.from({ length: N }, (_, i) => {
3211
+ const c = frac(clock.stateTime / 1.3 + i / N);
3212
+ return ring(`radar.${i}`, baseR + (104 - baseR) * c, 3.4 * (1 - c * .55), r * (1 - c) * .9);
3213
+ });
3214
+ },
3215
+ progress(e, clock) {
3216
+ const n = easeOutCubic(e), r = 62 * easeOutBack(e), s = clamp01(clamp01(clock.shotTime / 2.5) / .85);
3217
+ const out = [ring("progress.track", r, 5, n * .16)];
3218
+ if (s > 0) out.push(ring("progress.arc", r, 5, n, s));
3219
+ return out;
3220
+ },
3221
+ bang(e, clock, baseR, still) {
3222
+ const t = clock.stateTime, r = easeOutCubic(clamp01(e * 1.1)), o = still ? 0 : Math.exp(-(t % 2.2) * 5.5), sw = Math.sin(t * 42) * 2.2 * o * DEG;
3223
+ const sc = clamp01(e * 1.2), ty = -26 - (1 - r) * 70, pivot = -74, c = Math.cos(sw), s = Math.sin(sw);
3224
+ return [{
3225
+ type: "shape",
3226
+ key: "bang.bar",
3227
+ pts: BANG_BAR.map(([x, y]) => {
3228
+ x *= sc;
3229
+ y *= sc;
3230
+ const yy = y - pivot;
3231
+ return [x * c - yy * s, x * s + yy * c + pivot + ty];
3232
+ }),
3233
+ opacity: clamp01(e * 1.5 - .2)
3234
+ }];
3235
+ },
3236
+ standby(e, clock) {
3237
+ const n = .5 + .5 * Math.sin(clock.stateTime * 1.6);
3238
+ return [disc("standby.halo", 0, 0, 26 + 7 * n, easeOutCubic(e) * (.06 + .1 * n))];
3239
+ }
3240
+ };
3241
+ function composeMorph(m, sizePx = 200, { still = false } = {}) {
3242
+ const a = clamp01(m.amount), s = clamp01(m.swap), kind = m.kind, out = s < .999 ? m.outgoing : null;
3243
+ const w = (j) => j === kind ? a * s : j === out ? a * (1 - s) : 0;
3244
+ const clk = (j) => j === kind ? m.clock : m.outgoingClock;
3245
+ const baseR = kind ? MORPH[kind].baseR * s + (out ? MORPH[out].baseR : MORPH[kind].baseR) * (1 - s) : 19;
3246
+ const hDots = w("dots"), hasDots = kind === "dots" || out === "dots";
3247
+ const g = hasDots ? dotsWave(clk("dots"), 1, a, still) : {
3248
+ lift: 0,
3249
+ pop: 1,
3250
+ tone: 1
3251
+ };
3252
+ let pop = hasDots ? 1 + (g.pop - 1) * (hDots / Math.max(a, .001)) : 1;
3253
+ const wb = w("bang");
3254
+ if (wb > .004 && !still) pop *= 1 + .04 * Math.exp(-(clk("bang").stateTime % 2.2) * 5.5) * wb;
3255
+ const dy = -g.lift * hDots + 58 * wb * a;
3256
+ const ws = w("standby"), dim = ws > 0 ? (.28 + .2 * Math.sin(clk("standby").stateTime * 1.6)) * ws : 0;
3257
+ const I = 1 - smoothstep((sizePx - 44) / 90);
3258
+ const kz = (j) => MORPH[j].zoomL + (MORPH[j].zoom - MORPH[j].zoomL) * I;
3259
+ const zk = kind ? kz(kind) : 1, zo = out ? kz(out) : zk;
3260
+ const detail = sizePx >= SMALL_PX;
3261
+ const parts = [];
3262
+ for (const j of [out, kind]) {
3263
+ if (j == null) continue;
3264
+ const e = w(j);
3265
+ if (e > .004) parts.push(...GEN[j](e, clk(j), baseR, still, detail));
3266
+ }
3267
+ return {
3268
+ core: {
3269
+ scale: 1 - a + baseR / DU * pop * a,
3270
+ dy: dy / DU,
3271
+ opacity: (1 - (1 - g.tone) * hDots) * (1 - dim),
3272
+ round: easeInOutCubic(a / .62)
3273
+ },
3274
+ faceVisible: a < .5,
3275
+ faceAlpha: 1 - smoothstep((a - .35) / .15),
3276
+ zoom: 1 + (zk * s + zo * (1 - s) - 1) * a,
3277
+ parts: parts.filter((p) => p.opacity > 0)
3278
+ };
3279
+ }
3280
+ const RELAY_HELPER = {
3281
+ x: 162,
3282
+ y: 12,
3283
+ s: .6
3284
+ };
3285
+ const RELAY_FROM = [-26, -54];
3286
+ const RELAY_TO = [112, -34];
3287
+ const RELAY_CTRL = [52, -170];
3288
+ const qBez = (a, c, b, u) => [(1 - u) * (1 - u) * a[0] + 2 * u * (1 - u) * c[0] + u * u * b[0], (1 - u) * (1 - u) * a[1] + 2 * u * (1 - u) * c[1] + u * u * b[1]];
3289
+ const HELPER_TRACKS = {
3290
+ dy: [
3291
+ k(0, 0),
3292
+ k(.5, -.03),
3293
+ k(.85, .02),
3294
+ k(.95, .03),
3295
+ k(1.1, -.2, OVER),
3296
+ k(1.24, .01),
3297
+ k(1.36, -.03),
3298
+ k(1.5, 0),
3299
+ k(1.95, -.025),
3300
+ k(2.4, 0)
3301
+ ],
3302
+ sq: [
3303
+ k(0, [1, 1]),
3304
+ k(.85, [1, 1]),
3305
+ k(.95, [1.08, .9]),
3306
+ k(1.08, [.93, 1.09]),
3307
+ k(1.24, [1.1, .88], OVER),
3308
+ k(1.4, [1, 1]),
3309
+ k(2.4, [1, 1])
3310
+ ],
3311
+ rot: [
3312
+ k(0, [2]),
3313
+ k(.6, [-3]),
3314
+ k(1.3, [0]),
3315
+ k(1.4, [-8]),
3316
+ k(1.62, [13], OVER),
3317
+ k(1.9, [-2]),
3318
+ k(2.15, [2]),
3319
+ k(2.4, [2])
3320
+ ]
3321
+ };
3322
+ function relayHelperPose(c, still = false) {
3323
+ if (still) return {
3324
+ dy: 0,
3325
+ sx: 1,
3326
+ sy: 1,
3327
+ rot: 0
3328
+ };
3329
+ const [sx, sy] = evalTrack(HELPER_TRACKS.sq, c);
3330
+ return {
3331
+ dy: evalTrack(HELPER_TRACKS.dy, c)[0],
3332
+ sx,
3333
+ sy,
3334
+ rot: evalTrack(HELPER_TRACKS.rot, c)[0]
3335
+ };
3336
+ }
3337
+ const ACCENT = {
3338
+ relay(e, c, o) {
3339
+ const n = easeOutCubic(e), out = [];
3340
+ const leg = (key, t0, t1, a, b, col) => {
3341
+ const u = o.still ? key === "relay.task" ? .5 : -1 : (c - t0) / (t1 - t0);
3342
+ if (u < 0 || u > 1) return;
3343
+ const w = ease([
3344
+ .3,
3345
+ 0,
3346
+ .25,
3347
+ 1
3348
+ ])(u), p = qBez(a, RELAY_CTRL, b, w), f = Math.min(1, u / .12, (1 - u) / .12);
3349
+ out.push({
3350
+ ...disc(key, p[0], p[1], 19 * (.85 + .25 * Math.sin(Math.PI * u)), n * f),
3351
+ color: col
3352
+ });
3353
+ };
3354
+ leg("relay.task", .28, .98, RELAY_FROM, RELAY_TO, void 0);
3355
+ leg("relay.result", 1.42, 2.08, RELAY_TO, RELAY_FROM, o.peer);
3356
+ return out;
3357
+ },
3358
+ reboot(e, c, o) {
3359
+ const n = easeOutCubic(e), r = 146 * (.85 + .15 * easeOutBack(e)), arc = .72;
3360
+ const rot = o.still ? 30 : 360 * ease(SPIN)(clamp01((c - .3) / .85)) + 150 * c;
3361
+ const a = (-90 + rot + arc * 360) * DEG, tx = -Math.sin(a), ty = Math.cos(a), ex = r * Math.cos(a), ey = r * Math.sin(a);
3362
+ const L = 30, W = 21;
3363
+ return [{
3364
+ ...ring("reboot.arc", r, 10, n, arc),
3365
+ rot
3366
+ }, {
3367
+ type: "shape",
3368
+ key: "reboot.head",
3369
+ opacity: n,
3370
+ pts: [
3371
+ [ex + tx * L, ey + ty * L],
3372
+ [ex - ty * W - tx * 4, ey + tx * W - ty * 4],
3373
+ [ex + ty * W - tx * 4, ey - tx * W - ty * 4]
3374
+ ]
3375
+ }];
3376
+ }
3377
+ };
3378
+ const NS = "http://www.w3.org/2000/svg";
3379
+ function h(tag, attrs, children = [], text) {
3380
+ return {
3381
+ tag,
3382
+ attrs,
3383
+ children,
3384
+ text,
3385
+ el: null
3386
+ };
3387
+ }
3388
+ function createEl(v, stats) {
3389
+ const el = document.createElementNS(NS, v.tag);
3390
+ for (const k in v.attrs) if (k !== "key") el.setAttribute(k, v.attrs[k]);
3391
+ if (v.text !== void 0) el.textContent = v.text;
3392
+ for (const c of v.children) el.appendChild(createEl(c, stats));
3393
+ v.el = el;
3394
+ stats.writes++;
3395
+ return el;
3396
+ }
3397
+ const live = /* @__PURE__ */ new Set();
3398
+ let rafId = 0;
3399
+ function loop(now) {
3400
+ rafId = 0;
3401
+ let want = false;
3402
+ for (const a of live) {
3403
+ a._tick(now);
3404
+ want = want || a._wantsFrame();
3405
+ }
3406
+ if (want) rafId = requestAnimationFrame(loop);
3407
+ }
3408
+ function kick() {
3409
+ if (!rafId && typeof document !== "undefined" && !document.hidden) rafId = requestAnimationFrame(loop);
3410
+ }
3411
+ if (typeof document !== "undefined") document.addEventListener("visibilitychange", () => {
3412
+ if (document.hidden) {
3413
+ cancelAnimationFrame(rafId);
3414
+ rafId = 0;
3415
+ } else {
3416
+ for (const a of live) a._last = 0;
3417
+ kick();
3418
+ }
3419
+ });
3420
+ let uid = 0;
3421
+ const r2 = (v) => Math.round(v * 100) / 100;
3422
+ const fmt = (q) => `${r2(q[0])} ${r2(q[1])}`;
3423
+ function mixHex(a, b, t) {
3424
+ if (t <= .001) return a;
3425
+ const pa = parseInt(a.slice(1), 16), pb = parseInt(b.slice(1), 16);
3426
+ const c = (sh) => Math.round((pa >> sh & 255) + ((pb >> sh & 255) - (pa >> sh & 255)) * Math.min(1, t));
3427
+ return "#" + (1 << 24 | c(16) << 16 | c(8) << 8 | c(0)).toString(16).slice(1).toUpperCase();
3428
+ }
3429
+ function pathOpen(pts) {
3430
+ if (pts.length < 3) return `M${fmt(pts[0])}L${fmt(pts[pts.length - 1])}`;
3431
+ let d = `M${fmt(pts[0])}`;
3432
+ for (let i = 1; i < pts.length - 1; i++) {
3433
+ const q = pts[i], e = [(q[0] + pts[i + 1][0]) / 2, (q[1] + pts[i + 1][1]) / 2];
3434
+ d += `Q${fmt(q)} ${i === pts.length - 2 ? fmt(pts[i + 1]) : fmt(e)}`;
3435
+ }
3436
+ return d;
3437
+ }
3438
+ function pathClosed(pts, sharp) {
3439
+ const n = pts.length, mid = (a, b) => [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
3440
+ let d = `M${fmt(mid(pts[n - 1], pts[0]))}`;
3441
+ for (let i = 0; i < n; i++) {
3442
+ const m = fmt(mid(pts[i], pts[(i + 1) % n]));
3443
+ d += sharp && sharp[i] ? `L${fmt(pts[i])}L${m}` : `Q${fmt(pts[i])} ${m}`;
3444
+ }
3445
+ return d + "Z";
3446
+ }
3447
+ function visibleRuns(P) {
3448
+ const runs = [];
3449
+ let cur = null;
3450
+ for (let i = 0; i < P.length; i++) {
3451
+ const p = P[i];
3452
+ if (visibleOnSphere(p)) {
3453
+ if (!cur) {
3454
+ cur = [];
3455
+ if (i > 0) {
3456
+ const a = P[i - 1], t = clamp01(a[2] / (a[2] - p[2] || 1));
3457
+ cur.push([a[0] + (p[0] - a[0]) * t, a[1] + (p[1] - a[1]) * t]);
3458
+ }
3459
+ runs.push(cur);
3460
+ }
3461
+ cur.push([p[0], p[1]]);
3462
+ } else if (cur) {
3463
+ const a = P[i - 1], t = clamp01(a[2] / (a[2] - p[2] || 1));
3464
+ cur.push([a[0] + (p[0] - a[0]) * t, a[1] + (p[1] - a[1]) * t]);
3465
+ cur = null;
3466
+ }
3467
+ }
3468
+ return runs.filter((r) => r.length >= 2);
3469
+ }
3470
+ function waterColorFilter(id, seed) {
3471
+ return h("filter", {
3472
+ key: "wc",
3473
+ id,
3474
+ x: "-10%",
3475
+ y: "-10%",
3476
+ width: "120%",
3477
+ height: "120%",
3478
+ "color-interpolation-filters": "sRGB"
3479
+ }, [
3480
+ h("feTurbulence", {
3481
+ key: "t1",
3482
+ type: "fractalNoise",
3483
+ baseFrequency: .045,
3484
+ numOctaves: 2,
3485
+ seed: seed % 97,
3486
+ result: "edge"
3487
+ }),
3488
+ h("feDisplacementMap", {
3489
+ key: "d",
3490
+ in: "SourceGraphic",
3491
+ in2: "edge",
3492
+ scale: 2.4,
3493
+ xChannelSelector: "R",
3494
+ yChannelSelector: "G",
3495
+ result: "body"
3496
+ }),
3497
+ h("feTurbulence", {
3498
+ key: "t2",
3499
+ type: "fractalNoise",
3500
+ baseFrequency: .09,
3501
+ numOctaves: 3,
3502
+ seed: (seed + 5) % 97,
3503
+ result: "grain"
3504
+ }),
3505
+ h("feColorMatrix", {
3506
+ key: "cm",
3507
+ in: "grain",
3508
+ type: "matrix",
3509
+ values: "0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0.9 0 0 0 -0.36",
3510
+ result: "light"
3511
+ }),
3512
+ h("feComposite", {
3513
+ key: "c",
3514
+ in: "light",
3515
+ in2: "body",
3516
+ operator: "in",
3517
+ result: "spots"
3518
+ }),
3519
+ h("feMerge", { key: "m" }, [h("feMergeNode", {
3520
+ key: "a",
3521
+ in: "body"
3522
+ }), h("feMergeNode", {
3523
+ key: "b",
3524
+ in: "spots"
3525
+ })])
3526
+ ]);
3527
+ }
3528
+ const FACE_SECONDS = .28;
3529
+ const LIDMORPH_SECONDS = .35;
3530
+ const LOOK_SECONDS = .5;
3531
+ const POSE_REST = {
3532
+ rot: [
3533
+ 0,
3534
+ 0,
3535
+ 0
3536
+ ],
3537
+ pos: [0, 0],
3538
+ scl: [1, 1],
3539
+ zoom: 1,
3540
+ lids: 0,
3541
+ hk: 0,
3542
+ sk: 0,
3543
+ wv: 0
3544
+ };
3545
+ const sin2win = (a, lo, hi) => a <= lo || a >= hi ? 0 : Math.sin(Math.PI * (a - lo) / (hi - lo)) ** 2;
3546
+ const pokeDur = (p) => p.kind === "spin" ? .9 + .4 * (p.turns - 1) : p.kind === "nod" ? .5 : .62;
3547
+ function blinkCurve(t) {
3548
+ const u = t / BLINK_DUR, u1 = .306, u2 = .578;
3549
+ return u < u1 ? smoothstep(u / u1) : u < u2 ? 1 : 1 - smoothstep((u - u2) / (1 - u2));
3550
+ }
3551
+ function lidMorphOpen(u) {
3552
+ const u1 = .38, u2 = .475;
3553
+ if (u < u1) return 1 - smoothstep(u / u1);
3554
+ if (u < u2) return 0;
3555
+ const v = (u - u2) / (1 - u2);
3556
+ return v < .7 ? 1.06 * (1 - (1 - v / .7) ** 2) : 1.06 - .06 * smoothstep((v - .7) / .3);
3557
+ }
3558
+ const LOOKS = {
3559
+ left: {
3560
+ rot: [0, -20],
3561
+ pos: [-.1, 0]
3562
+ },
3563
+ right: {
3564
+ rot: [0, 20],
3565
+ pos: [.1, 0]
3566
+ },
3567
+ up: {
3568
+ rot: [-20, 0],
3569
+ pos: [0, -.1]
3570
+ },
3571
+ down: {
3572
+ rot: [20, 0],
3573
+ pos: [0, .1]
3574
+ },
3575
+ center: {
3576
+ rot: [0, 0],
3577
+ pos: [0, 0]
3578
+ }
3579
+ };
3580
+ const BLINK_BLOCKING = new Set(Object.keys(FACES).filter((k) => FACES[k].eyes.kind !== "dot"));
3581
+ const EMPHASIS_FACE = "wow";
3582
+ function expressionAt(clip, t) {
3583
+ let name = null;
3584
+ for (const e of clip.expression) {
3585
+ if (name == null) name = e.name;
3586
+ if (e.t <= t + 1e-9) name = e.name;
3587
+ }
3588
+ return name;
3589
+ }
3590
+ const attrCache = /* @__PURE__ */ new WeakMap();
3591
+ const mk = (tag) => document.createElementNS(NS, tag);
3592
+ var Avatar = class {
3593
+ constructor(host, opts = {}) {
3594
+ this.host = host;
3595
+ this.onEvent = opts.onEvent || null;
3596
+ if (!CHARACTERS[opts.character || "logo"]) throw new Error(`[openmax-avatar] 形象「${opts.character || "logo"}」未注册:请先 registerCharacter(...)`);
3597
+ this.id = `omav${++uid}`;
3598
+ this.character = opts.character || "logo";
3599
+ this.seed = seedOf(opts.seed ?? 7);
3600
+ this.rnd = mulberry32(this.seed);
3601
+ this.reducedOpt = opts.reducedMotion ?? "auto";
3602
+ this.frozen = opts.frozenAt != null;
3603
+ this.maxFps = opts.maxFps || 60;
3604
+ this.time = 0;
3605
+ this._last = 0;
3606
+ this.stats = {
3607
+ fps: 0,
3608
+ writes: 0,
3609
+ frames: 0,
3610
+ sleeping: false,
3611
+ clip: ""
3612
+ };
3613
+ this._fpsWin = [];
3614
+ this.inView = true;
3615
+ this.px = 0;
3616
+ this.speechLevel = null;
3617
+ this.pointer = null;
3618
+ this.gaze = [0, 0];
3619
+ this.lookOff = {
3620
+ rot: [0, 0],
3621
+ pos: [0, 0]
3622
+ };
3623
+ this.lookTw = null;
3624
+ this.bodyW = createSpring(1, 10, 1);
3625
+ this.morph = new MorphBehavior(this.rnd);
3626
+ this.spinBase = null;
3627
+ this.pokes = [];
3628
+ this.palette = opts.palette || "blue";
3629
+ this.facing = opts.facing === "left" ? "left" : "right";
3630
+ this.partnerColor = opts.partnerColor || null;
3631
+ this.faceName = "grin";
3632
+ this.faceFrom = null;
3633
+ this.faceCur = null;
3634
+ this.faceT = 9;
3635
+ this.drawT = 9;
3636
+ this.lidMorph = null;
3637
+ this.faceQueue = null;
3638
+ this.clipFace = null;
3639
+ this.emphasis = false;
3640
+ this.lidsSuppressed = false;
3641
+ this.logoP = {
3642
+ hump: 1,
3643
+ wave: 0,
3644
+ ws: .9,
3645
+ skew: 0
3646
+ };
3647
+ this.gray = 0;
3648
+ this.accentKind = null;
3649
+ this.accentW = 0;
3650
+ this.blinkT = -1;
3651
+ this.clip = null;
3652
+ this.clipT = 0;
3653
+ this.pending = null;
3654
+ this.playing = false;
3655
+ this.loopCount = 0;
3656
+ this.bags = /* @__PURE__ */ new Map();
3657
+ this.pose = { ...POSE_REST };
3658
+ this.jit = Array.from({ length: 64 }, () => [(this.rnd() - .5) * .014, (this.rnd() - .5) * .014]);
3659
+ this._useChar(this.character);
3660
+ this.svg = mk("svg");
3661
+ host.appendChild(this.svg);
3662
+ this.mql = typeof matchMedia === "function" ? matchMedia("(prefers-reduced-motion: reduce)") : null;
3663
+ this._onMql = () => this.wake();
3664
+ this.mql?.addEventListener?.("change", this._onMql);
3665
+ if (typeof ResizeObserver === "function") {
3666
+ this.ro = new ResizeObserver(() => {
3667
+ this._measure();
3668
+ this.wake();
3669
+ });
3670
+ this.ro.observe(host);
3671
+ }
3672
+ if (!this.frozen && typeof IntersectionObserver === "function") {
3673
+ this.io = new IntersectionObserver((es) => {
3674
+ this.inView = es[es.length - 1].isIntersecting;
3675
+ if (this.inView) this.wake();
3676
+ });
3677
+ this.io.observe(host);
3678
+ }
3679
+ this._measure();
3680
+ this.state = null;
3681
+ this.setState(opts.state || "idle", true);
3682
+ if (this.frozen) {
3683
+ this.step(Math.round(Math.max(0, opts.frozenAt) * 60));
3684
+ return;
3685
+ }
3686
+ live.add(this);
3687
+ this.wake();
3688
+ }
3689
+ get reduced() {
3690
+ return this.reducedOpt === "auto" ? !!this.mql?.matches : !!this.reducedOpt;
3691
+ }
3692
+ get small() {
3693
+ return this.px > 0 && this.px < SMALL_PX;
3694
+ }
3695
+ _measure() {
3696
+ const r = this.host.getBoundingClientRect();
3697
+ this.px = Math.min(r.width, r.height);
3698
+ }
3699
+ setState(name, instant = false) {
3700
+ name = resolveState(name);
3701
+ if (!name || name === this.state && !instant) return;
3702
+ const st = STATES[name], prev = this.state, prevHold = prev ? this._hold() : null;
3703
+ this.state = name;
3704
+ this.stateT = 0;
3705
+ this.seqIdx = 0;
3706
+ this._ended = false;
3707
+ if (prev) this._emit("statechange", {
3708
+ state: name,
3709
+ prev
3710
+ });
3711
+ this._applyLook(instant);
3712
+ this.morph.set(st.morph || null);
3713
+ if (instant) this.morph.settle();
3714
+ const pool = this._pool();
3715
+ const first = st.sequential ? pool[0] : this._draw(pool);
3716
+ this._load(first, {
3717
+ phase: instant && !st.sequential ? this.rnd() : 0,
3718
+ bridge: !instant
3719
+ });
3720
+ const hold = this._hold();
3721
+ if (instant) this._faceNow(this._wantFace());
3722
+ else {
3723
+ if (hold && hold !== prevHold) this.drawT = 0;
3724
+ this._playFace(this._wantFace(), false);
3725
+ }
3726
+ this.wake();
3727
+ }
3728
+ setCharacter(id) {
3729
+ if (!CHARACTERS[id] || id === this.character) return;
3730
+ this.character = id;
3731
+ this._useChar(id);
3732
+ this.faceCur = null;
3733
+ this.faceFrom = null;
3734
+ this.faceT = 9;
3735
+ this.drawT = 0;
3736
+ this._applyLook(true);
3737
+ this.wake();
3738
+ }
3739
+ setPalette(p) {
3740
+ this.palette = p;
3741
+ this.wake();
3742
+ }
3743
+ setFacing(f) {
3744
+ this.facing = f === "left" ? "left" : "right";
3745
+ this.wake();
3746
+ }
3747
+ setPartnerColor(p) {
3748
+ this.partnerColor = p || null;
3749
+ this.wake();
3750
+ }
3751
+ lookAt(x, y) {
3752
+ this.pointer = x == null ? null : [Math.max(-1, Math.min(1, x)), Math.max(-1, Math.min(1, y))];
3753
+ this.wake();
3754
+ }
3755
+ look(dir) {
3756
+ const to = LOOKS[dir];
3757
+ if (!to) return;
3758
+ if (this.reduced) {
3759
+ this.lookOff = {
3760
+ rot: to.rot.slice(),
3761
+ pos: to.pos.slice()
3762
+ };
3763
+ this.lookTw = null;
3764
+ } else this.lookTw = {
3765
+ t: 0,
3766
+ from: {
3767
+ rot: this.lookOff.rot.slice(),
3768
+ pos: this.lookOff.pos.slice()
3769
+ },
3770
+ to
3771
+ };
3772
+ this.wake();
3773
+ }
3774
+ setEmphasis(v) {
3775
+ v = !!v;
3776
+ if (v === this.emphasis) return;
3777
+ this.emphasis = v;
3778
+ this._playFace(this._wantFace(), false);
3779
+ this.wake();
3780
+ }
3781
+ setSpeechLevel(v) {
3782
+ this.speechLevel = v;
3783
+ this.wake();
3784
+ }
3785
+ setSpring({ omega, zeta }) {
3786
+ if (omega) this.bodyW.omega = omega;
3787
+ if (zeta) this.bodyW.zeta = zeta;
3788
+ this.wake();
3789
+ }
3790
+ blink() {
3791
+ if (this.blinkT < 0 && !this.lidMorph) this.blinkT = 0;
3792
+ this.wake();
3793
+ }
3794
+ poke(kind = "bounce", { turns = 1 } = {}) {
3795
+ if (this.reduced || ![
3796
+ "bounce",
3797
+ "nod",
3798
+ "spin"
3799
+ ].includes(kind)) return;
3800
+ this.pokes.push({
3801
+ kind,
3802
+ t: 0,
3803
+ turns: Math.max(1, Math.round(turns))
3804
+ });
3805
+ this.wake();
3806
+ }
3807
+ setReducedMotion(v) {
3808
+ this.reducedOpt = v;
3809
+ this.wake();
3810
+ }
3811
+ step(n = 1, dt = 1 / 60) {
3812
+ for (let i = 0; i < n; i++) this._update(dt);
3813
+ this._render();
3814
+ return this;
3815
+ }
3816
+ debugFrame() {
3817
+ return {
3818
+ state: this.state,
3819
+ clip: this.clip?.name,
3820
+ pending: this.pending?.clip.name || null,
3821
+ time: this.clipT,
3822
+ duration: this.clip?.duration,
3823
+ face: this.faceName,
3824
+ pose: this.pose,
3825
+ morph: this.morph.snapshot()
3826
+ };
3827
+ }
3828
+ destroy() {
3829
+ live.delete(this);
3830
+ this.ro?.disconnect();
3831
+ this.io?.disconnect();
3832
+ this.mql?.removeEventListener?.("change", this._onMql);
3833
+ this.svg.remove();
3834
+ }
3835
+ _useChar(id) {
3836
+ const ch = CHARACTERS[id];
3837
+ this.bank = shapeBank(id);
3838
+ const n = this.bank.angles.length;
3839
+ this.fromR = Float32Array.from(this.bank.base);
3840
+ this.toR = this.bank.base;
3841
+ this.curR = new Float32Array(n);
3842
+ if (ch.mLine && !this.mBase) {
3843
+ this.mBase = ch.mLine(120);
3844
+ this.mSmall = ch.mLine(44);
3845
+ }
3846
+ this.sk = null;
3847
+ }
3848
+ _emit(type, detail) {
3849
+ try {
3850
+ this.onEvent?.(type, detail);
3851
+ } catch (e) {
3852
+ setTimeout(() => {
3853
+ throw e;
3854
+ });
3855
+ }
3856
+ }
3857
+ _applyLook(instant) {
3858
+ const st = STATES[this.state];
3859
+ lerpRadii(this.fromR, this.toR, easeInOutCubic(this.bodyW.x), this.fromR);
3860
+ const to = this.bank[st.shape] || this.bank.base;
3861
+ if (to !== this.toR || instant) {
3862
+ this.toR = to;
3863
+ if (instant) {
3864
+ this.fromR.set(to);
3865
+ snapSpring(this.bodyW, 1);
3866
+ } else {
3867
+ this.bodyW.x = 0;
3868
+ this.bodyW.v = 0;
3869
+ this.bodyW.target = 1;
3870
+ }
3871
+ }
3872
+ if (instant) {
3873
+ Object.assign(this.logoP, st.logo);
3874
+ this.gray = st.gray || 0;
3875
+ }
3876
+ }
3877
+ _hold() {
3878
+ return STATES[this.state].face || (this.emphasis ? "wow" : null);
3879
+ }
3880
+ _wantFace() {
3881
+ return this._hold() || this.clipFace || "grin";
3882
+ }
3883
+ _faceNow(name) {
3884
+ this.faceName = name;
3885
+ this.faceFrom = null;
3886
+ this.faceT = 9;
3887
+ this.lidMorph = null;
3888
+ this.faceQueue = null;
3889
+ }
3890
+ _playFace(name, through) {
3891
+ if (!name || !FACES[name]) return;
3892
+ if (this.reduced) {
3893
+ this._faceNow(name);
3894
+ return;
3895
+ }
3896
+ if (this.blinkT >= 0 || this.lidMorph || this.pose.lids > 0 && !this.lidsSuppressed) {
3897
+ this.faceQueue = {
3898
+ name,
3899
+ through
3900
+ };
3901
+ return;
3902
+ }
3903
+ if (name === this.faceName) return;
3904
+ if (through && !BLINK_BLOCKING.has(name) && !BLINK_BLOCKING.has(this.faceName)) {
3905
+ this.lidMorph = {
3906
+ t: 0,
3907
+ to: name,
3908
+ switched: false
3909
+ };
3910
+ return;
3911
+ }
3912
+ this.faceFrom = this.faceCur;
3913
+ this.faceName = name;
3914
+ this.faceT = 0;
3915
+ }
3916
+ _clipFaceEvent(name, through) {
3917
+ this.clipFace = name;
3918
+ if (!this._hold()) this._playFace(name, through);
3919
+ }
3920
+ _pool() {
3921
+ const st = STATES[this.state];
3922
+ return this.small && st.compactClips ? st.compactClips : st.clips;
3923
+ }
3924
+ _draw(pool) {
3925
+ const key = pool.join("|");
3926
+ let bag = this.bags.get(key);
3927
+ if (!bag || !bag.length) {
3928
+ bag = shuffleBag(pool, this.rnd, this.clip?.name === "bridge" ? this.pending?.clip.name : this.clip?.name);
3929
+ this.bags.set(key, bag);
3930
+ }
3931
+ return bag.shift();
3932
+ }
3933
+ _load(name, { phase = 0, bridge = true } = {}) {
3934
+ const clip = COMPILED[name];
3935
+ const curName = this.pending ? this.pending.clip.name : this.clip?.name;
3936
+ if (bridge && this.clip && (curName !== name || this.pending)) {
3937
+ this.pending = {
3938
+ clip,
3939
+ t: clip.restTime
3940
+ };
3941
+ this.clip = bridgeClip(this.pose, restFrame(clip), clip.squashAnchor);
3942
+ this.clipT = 0;
3943
+ const f = expressionAt(clip, clip.restTime);
3944
+ if (f) this._clipFaceEvent(f, false);
3945
+ } else if (curName === name && this.clip && !this.pending && this.clipT < this.clip.duration) return;
3946
+ else {
3947
+ this.pending = null;
3948
+ this.clip = clip;
3949
+ this.clipT = clip.restTime + phase * (clip.duration - clip.restTime);
3950
+ const f = expressionAt(clip, this.clipT);
3951
+ if (f) this.clipFace = f;
3952
+ }
3953
+ this.playing = true;
3954
+ this._statsClip();
3955
+ }
3956
+ _statsClip() {
3957
+ this.stats.clip = this.pending ? `bridge→${this.pending.clip.name}` : this.clip.name;
3958
+ }
3959
+ _loopSeam(over) {
3960
+ const c = this.clip, end = samplePose(c, c.duration), rest = restFrame(c);
3961
+ if (isSimilar(end, rest)) {
3962
+ this.clipT = c.restTime + Math.min(over, c.duration - c.restTime - 1e-6);
3963
+ this._fire(c.restTime - 1e-9, this.clipT);
3964
+ } else {
3965
+ this.pending = {
3966
+ clip: c,
3967
+ t: c.restTime
3968
+ };
3969
+ this.clip = bridgeClip(end, rest, c.squashAnchor);
3970
+ this.clipT = Math.min(over, BRIDGE_SECONDS);
3971
+ }
3972
+ this._statsClip();
3973
+ }
3974
+ _clipEnded(over) {
3975
+ const st = STATES[this.state], pool = this._pool();
3976
+ this.loopCount++;
3977
+ if (st.sequential) {
3978
+ this.seqIdx++;
3979
+ if (this.seqIdx >= pool.length) {
3980
+ if (st.next) {
3981
+ this._emit("stateend", {
3982
+ state: this.state,
3983
+ next: st.next
3984
+ });
3985
+ this.setState(st.next);
3986
+ return;
3987
+ }
3988
+ this.clipT = this.clip.duration;
3989
+ this.playing = false;
3990
+ if (!this._ended) {
3991
+ this._ended = true;
3992
+ this._emit("stateend", {
3993
+ state: this.state,
3994
+ next: null
3995
+ });
3996
+ }
3997
+ return;
3998
+ }
3999
+ const n = pool[this.seqIdx];
4000
+ if (n === this.clip.name) this._loopSeam(over);
4001
+ else this._load(n);
4002
+ return;
4003
+ }
4004
+ const n = this._draw(pool);
4005
+ if (n === this.clip.name) this._loopSeam(over);
4006
+ else this._load(n);
4007
+ }
4008
+ _fire(a, b) {
4009
+ if (this.pending) return;
4010
+ for (const e of this.clip.expression) if (e.t > a && e.t <= b) this._clipFaceEvent(e.name, !e.cut);
4011
+ }
4012
+ _advanceClip(dt) {
4013
+ if (!this.playing || !this.clip) return;
4014
+ const prevT = this.clipT;
4015
+ this.clipT += dt;
4016
+ this._fire(prevT, Math.min(this.clipT, this.clip.duration));
4017
+ if (this.clipT >= this.clip.duration) {
4018
+ const over = this.clipT - this.clip.duration;
4019
+ if (this.pending) {
4020
+ const p = this.pending;
4021
+ this.pending = null;
4022
+ this.clip = p.clip;
4023
+ this.clipT = p.t;
4024
+ this._statsClip();
4025
+ } else this._clipEnded(over);
4026
+ }
4027
+ }
4028
+ wake() {
4029
+ if (this.frozen) {
4030
+ if (this.state) this._render();
4031
+ return;
4032
+ }
4033
+ this.stats.sleeping = false;
4034
+ this._awake = true;
4035
+ kick();
4036
+ }
4037
+ _wantsFrame() {
4038
+ return this._awake && this.inView;
4039
+ }
4040
+ _tick(now) {
4041
+ if (!this._awake || !this.inView) return;
4042
+ const fpsCap = Math.min(STATES[this.state].fps || 60, this.small ? 30 : 60, this.maxFps);
4043
+ if (this._last && now - this._last < 1e3 / fpsCap - 2) return;
4044
+ const dt = this._last ? Math.min((now - this._last) / 1e3, .1) : 1 / 60;
4045
+ this._last = now;
4046
+ this._fpsWin.push(now);
4047
+ while (this._fpsWin.length && now - this._fpsWin[0] > 1e3) this._fpsWin.shift();
4048
+ this.stats.fps = this._fpsWin.length;
4049
+ this._update(dt);
4050
+ this._render();
4051
+ if (this._settled()) {
4052
+ this._awake = false;
4053
+ this.stats.sleeping = true;
4054
+ this._last = 0;
4055
+ this._fpsWin = [];
4056
+ this.stats.fps = 0;
4057
+ }
4058
+ }
4059
+ _update(dt) {
4060
+ dt = Math.min(Math.max(dt, 0), .1);
4061
+ const st = STATES[this.state];
4062
+ if (this.reduced) {
4063
+ this.morph.settle();
4064
+ snapSpring(this.bodyW, 1);
4065
+ this.fromR.set(this.toR);
4066
+ this.blinkT = -1;
4067
+ this.drawT = 9;
4068
+ this.pokes = [];
4069
+ const c = COMPILED[st.clips[0]];
4070
+ this._faceNow(this._hold() || expressionAt(c, c.restTime) || "grin");
4071
+ Object.assign(this.logoP, st.logo);
4072
+ this.gray = st.gray || 0;
4073
+ this.accentKind = st.accent || null;
4074
+ this.accentW = st.accent ? 1 : 0;
4075
+ this.pose = restFrame(c);
4076
+ if (this.lookTw) {
4077
+ this.lookOff = {
4078
+ rot: this.lookTw.to.rot.slice(),
4079
+ pos: this.lookTw.to.pos.slice()
4080
+ };
4081
+ this.lookTw = null;
4082
+ }
4083
+ this.gaze = this.pointer ? this.pointer.slice() : [0, 0];
4084
+ return;
4085
+ }
4086
+ this.time += dt;
4087
+ this.stateT += dt;
4088
+ this.faceT += dt;
4089
+ this.drawT += dt;
4090
+ if (st.next && st.holdSeconds != null && this.stateT >= st.holdSeconds) {
4091
+ this._emit("stateend", {
4092
+ state: this.state,
4093
+ next: st.next
4094
+ });
4095
+ this.setState(st.next);
4096
+ }
4097
+ this._advanceClip(dt * (1 - this.morph.snapshot().amount));
4098
+ this.pose = samplePose(this.clip, this.clipT);
4099
+ this.morph.advance(dt);
4100
+ stepSpring(this.bodyW, dt);
4101
+ if (this.blinkT >= 0) {
4102
+ this.blinkT += dt;
4103
+ if (this.blinkT > BLINK_DUR) this.blinkT = -1;
4104
+ }
4105
+ if (this.lidMorph) {
4106
+ const L = this.lidMorph;
4107
+ L.t += dt;
4108
+ if (!L.switched && L.t / LIDMORPH_SECONDS >= .38) {
4109
+ L.switched = true;
4110
+ this.faceName = L.to;
4111
+ this.faceFrom = null;
4112
+ this.faceT = 9;
4113
+ }
4114
+ if (L.t >= LIDMORPH_SECONDS) this.lidMorph = null;
4115
+ }
4116
+ if (this.faceQueue && this.blinkT < 0 && !this.lidMorph && (this.pose.lids === 0 || this.lidsSuppressed)) {
4117
+ const q = this.faceQueue;
4118
+ this.faceQueue = null;
4119
+ this._playFace(q.name, q.through);
4120
+ }
4121
+ if (BLINK_BLOCKING.has(this.faceName) || this.faceT < FACE_SECONDS || this.lidMorph) this.lidsSuppressed = true;
4122
+ else if (this.lidsSuppressed && this.pose.lids === 0) this.lidsSuppressed = false;
4123
+ if (this.lookTw) {
4124
+ const T = this.lookTw;
4125
+ T.t += dt;
4126
+ const p = ease(EASE_IN_OUT)(Math.min(1, T.t / LOOK_SECONDS));
4127
+ this.lookOff = {
4128
+ rot: T.from.rot.map((v, i) => v + (T.to.rot[i] - v) * p),
4129
+ pos: T.from.pos.map((v, i) => v + (T.to.pos[i] - v) * p)
4130
+ };
4131
+ if (T.t >= LOOK_SECONDS) this.lookTw = null;
4132
+ }
4133
+ this.pokes = this.pokes.filter((p) => (p.t += dt) < pokeDur(p));
4134
+ const g = this.pointer || [0, 0];
4135
+ this.gaze = [approach(this.gaze[0], g[0], 8.4, dt), approach(this.gaze[1], g[1], 8.4, dt)];
4136
+ for (const key of [
4137
+ "hump",
4138
+ "wave",
4139
+ "skew"
4140
+ ]) this.logoP[key] = approach(this.logoP[key], st.logo[key], 7, dt);
4141
+ this.logoP.ws = st.logo.ws;
4142
+ this.gray = approach(this.gray, st.gray || 0, 5, dt);
4143
+ if (st.accent) this.accentKind = st.accent;
4144
+ this.accentW = approach(this.accentW, st.accent ? 1 : 0, 8, dt);
4145
+ if (!st.accent && this.accentW < .004) {
4146
+ this.accentKind = null;
4147
+ this.accentW = 0;
4148
+ }
4149
+ }
4150
+ _settled() {
4151
+ if (this.reduced) return true;
4152
+ if (this.playing || this.pending || this.pokes.length || this.blinkT >= 0 || this.lidMorph || this.faceQueue || this.lookTw || this.faceT < FACE_SECONDS) return false;
4153
+ if (CHARACTERS[this.character].face === "ill" && this.drawT < .9) return false;
4154
+ if (!springAtRest(this.bodyW)) return false;
4155
+ const m = this.morph.snapshot();
4156
+ if (!m.isSettled || m.kind) return false;
4157
+ const st = STATES[this.state], g = this.pointer || [0, 0];
4158
+ if (Math.abs(this.gaze[0] - g[0]) > .001 || Math.abs(this.gaze[1] - g[1]) > .001) return false;
4159
+ if (Math.abs(this.logoP.hump - st.logo.hump) > .001 || Math.abs(this.logoP.wave - st.logo.wave) > .001 || Math.abs(this.logoP.skew - st.logo.skew) > .001) return false;
4160
+ if (Math.abs(this.gray - (st.gray || 0)) > .001) return false;
4161
+ return !st.speak && !st.voice && !this.accentKind;
4162
+ }
4163
+ _frame(m) {
4164
+ const p = this.pose, logo = CHARACTERS[this.character].kind === "logo";
4165
+ let pitch = 0, yaw = 0, lift = 0, qx = 1, qy = 1;
4166
+ for (const k of this.pokes) {
4167
+ const a = Math.min(1, k.t / pokeDur(k));
4168
+ if (k.kind === "spin") yaw += 180 * k.turns * (1 - Math.cos(Math.PI * a));
4169
+ else if (k.kind === "nod") pitch += 16 * Math.sin(Math.PI * a) ** 2;
4170
+ else {
4171
+ const c = sin2win(a, 0, .18) + sin2win(a, .82, 1), u = sin2win(a, .18, .82);
4172
+ lift += .3 * Math.sin(Math.PI * clamp01((a - .14) / .72));
4173
+ qx *= 1 + .08 * c - .04 * u;
4174
+ qy *= 1 - .1 * c + .06 * u;
4175
+ }
4176
+ }
4177
+ const [gx, gy] = this.gaze, L = this.lookOff;
4178
+ const rot = [
4179
+ p.rot[0] + 14 * gy + L.rot[0] + pitch,
4180
+ p.rot[1] + 22 * gx + L.rot[1] + (logo ? 0 : yaw),
4181
+ p.rot[2] + (logo ? yaw : 0)
4182
+ ];
4183
+ let pos = [p.pos[0] + .03 * gx + L.pos[0], p.pos[1] + .024 * gy + L.pos[1] - lift], scl = [p.scl[0] * qx, p.scl[1] * qy];
4184
+ const X = 1 - m.amount;
4185
+ if (m.amount > 0 || !m.isSettled) this.spinBase ??= rot.map((r) => 360 * Math.round(r / 360));
4186
+ else this.spinBase = null;
4187
+ if (this.spinBase) for (let i = 0; i < 3; i++) rot[i] = this.spinBase[i] + (rot[i] - this.spinBase[i]) * X;
4188
+ rot[logo ? 2 : 1] += m.spin / DEG;
4189
+ if (X < 1) {
4190
+ pos = [pos[0] * X, pos[1] * X];
4191
+ scl = [1 + (scl[0] - 1) * X, 1 + (scl[1] - 1) * X];
4192
+ }
4193
+ let lidOpen = 1 - Math.max(this.lidsSuppressed ? 0 : p.lids, this.blinkT >= 0 ? blinkCurve(this.blinkT) : 0);
4194
+ if (this.lidMorph) lidOpen = lidMorphOpen(this.lidMorph.t / LIDMORPH_SECONDS);
4195
+ if (!logo && BLINK_BLOCKING.has(this.faceName) && !this.lidMorph) lidOpen = 1;
4196
+ return {
4197
+ rot,
4198
+ pos,
4199
+ scl,
4200
+ zoom: p.zoom,
4201
+ lidOpen,
4202
+ hk: p.hk,
4203
+ sk: p.sk,
4204
+ wv: p.wv,
4205
+ anchor: this.pending ? 0 : this.clip?.squashAnchor || 0
4206
+ };
4207
+ }
4208
+ _set(node, k, v) {
4209
+ let m = attrCache.get(node);
4210
+ if (!m) attrCache.set(node, m = /* @__PURE__ */ new Map());
4211
+ if (v == null) {
4212
+ if (m.has(k)) {
4213
+ m.delete(k);
4214
+ node.removeAttribute(k);
4215
+ this._w++;
4216
+ }
4217
+ return;
4218
+ }
4219
+ v = typeof v === "number" ? String(r2(v)) : v;
4220
+ if (m.get(k) === v) return;
4221
+ m.set(k, v);
4222
+ node.setAttribute(k, v);
4223
+ this._w++;
4224
+ }
4225
+ _skeleton() {
4226
+ const ch = CHARACTERS[this.character], svg = mk("svg"), S = {
4227
+ svg,
4228
+ pool: /* @__PURE__ */ new Map(),
4229
+ feat: {}
4230
+ };
4231
+ this._w++;
4232
+ for (const [k, v] of Object.entries({
4233
+ viewBox: "0 0 100 100",
4234
+ width: "100%",
4235
+ height: "100%",
4236
+ role: "img",
4237
+ style: "display:block;overflow:visible"
4238
+ })) this._set(svg, k, v);
4239
+ if (ch.watercolor) {
4240
+ const st = { writes: 0 };
4241
+ svg.appendChild(createEl(h("defs", {}, [waterColorFilter(`${this.id}wc`, this.seed)]), st));
4242
+ this._w += st.writes;
4243
+ }
4244
+ S.parts = svg.appendChild(mk("g"));
4245
+ S.head = svg.appendChild(mk("g"));
4246
+ S.body = S.head.appendChild(mk("path"));
4247
+ if (ch.kind === "logo") {
4248
+ S.m = S.head.appendChild(mk("path"));
4249
+ this._set(S.body, "fill", "none");
4250
+ for (const [k, v] of Object.entries({
4251
+ fill: "none",
4252
+ "stroke-linejoin": "round",
4253
+ "stroke-linecap": "butt"
4254
+ })) this._set(S.m, k, v);
4255
+ } else {
4256
+ S.face = S.head.appendChild(mk("g"));
4257
+ for (const key of Object.keys(faceFeatures("grin", 0, 1, this.character))) {
4258
+ const p = S.face.appendChild(mk("path"));
4259
+ S.feat[key] = p;
4260
+ for (const [k, v] of Object.entries({
4261
+ fill: "none",
4262
+ "stroke-linecap": "round",
4263
+ "stroke-linejoin": "round"
4264
+ })) this._set(p, k, v);
4265
+ if (ch.face === "ill" && key === "line") {
4266
+ this._set(p, "pathLength", 1);
4267
+ this._set(p, "stroke-dasharray", "1 1");
4268
+ }
4269
+ }
4270
+ }
4271
+ this._w += 4 + Object.keys(S.feat).length;
4272
+ this.svg.replaceWith(svg);
4273
+ this.svg = svg;
4274
+ this.sk = S;
4275
+ }
4276
+ _renderParts(parts, V, U, color, minW, minR) {
4277
+ const S = this.sk, seen = /* @__PURE__ */ new Set(), order = [];
4278
+ for (const p of parts) {
4279
+ const tag = p.type === "shape" ? "path" : "circle";
4280
+ let rec = S.pool.get(p.key);
4281
+ if (!rec || rec.tag !== tag) {
4282
+ if (rec) rec.el.remove();
4283
+ rec = {
4284
+ tag,
4285
+ el: mk(tag)
4286
+ };
4287
+ S.pool.set(p.key, rec);
4288
+ this._w++;
4289
+ }
4290
+ const e = rec.el;
4291
+ seen.add(p.key);
4292
+ order.push(e);
4293
+ if (p.type === "disc") {
4294
+ const [x, y] = V(p.cx / DU, p.cy / DU);
4295
+ this._set(e, "cx", x);
4296
+ this._set(e, "cy", y);
4297
+ this._set(e, "r", Math.max(minR * Math.min(1, p.r), p.r / DU * U));
4298
+ this._set(e, "fill", p.color || color);
4299
+ } else if (p.type === "ring") {
4300
+ const [x, y] = V((p.cx || 0) / DU, (p.cy || 0) / DU);
4301
+ this._set(e, "cx", x);
4302
+ this._set(e, "cy", y);
4303
+ this._set(e, "r", p.r / DU * U);
4304
+ this._set(e, "fill", "none");
4305
+ this._set(e, "stroke", p.color || color);
4306
+ this._set(e, "stroke-width", Math.max(minW, p.width / DU * U));
4307
+ const arc = p.arc != null;
4308
+ this._set(e, "pathLength", arc ? 1 : null);
4309
+ this._set(e, "stroke-dasharray", arc ? `${r2(p.arc)} 1` : null);
4310
+ this._set(e, "stroke-linecap", arc ? "round" : null);
4311
+ this._set(e, "transform", arc ? `rotate(${r2(-90 + (p.rot || 0))} ${r2(x)} ${r2(y)})` : null);
4312
+ } else {
4313
+ this._set(e, "d", "M" + p.pts.map((q) => fmt(V(q[0] / DU, q[1] / DU))).join("L") + "Z");
4314
+ this._set(e, "fill", p.color || color);
4315
+ }
4316
+ this._set(e, "opacity", p.opacity);
4317
+ }
4318
+ for (const [k, rec] of S.pool) if (!seen.has(k)) {
4319
+ rec.el.remove();
4320
+ S.pool.delete(k);
4321
+ this._w++;
4322
+ }
4323
+ const kids = S.parts.childNodes;
4324
+ if (kids.length !== order.length || order.some((e, i) => kids[i] !== e)) for (const e of order) {
4325
+ S.parts.appendChild(e);
4326
+ this._w++;
4327
+ }
4328
+ }
4329
+ _render() {
4330
+ this._w = 0;
4331
+ if (!this.sk) this._skeleton();
4332
+ const S = this.sk, ch = CHARACTERS[this.character], st = STATES[this.state];
4333
+ const small = this.small, px = this.px || 200, still = this.reduced;
4334
+ const m = this.morph.snapshot(still ? 1.2 : void 0);
4335
+ const M = composeMorph(m, px, { still });
4336
+ const F = this._frame(m);
4337
+ lerpRadii(this.fromR, this.toR, easeInOutCubic(this.bodyW.x), this.curR);
4338
+ let amp = 0;
4339
+ if (st.speak || st.voice) amp = this.speechLevel != null ? this.speechLevel : still ? .5 : speechEnvelope(this.time, this.seed);
4340
+ const sx = F.scl[0] * (1 + amp * .025), sy = F.scl[1] * (1 - amp * .03);
4341
+ const R = 30, CX = 50, CY = 52, U = R * (Math.max(.25, F.zoom) * M.zoom);
4342
+ const V = (x, y) => [CX + x * U, CY + y * U];
4343
+ const rad = M.core.scale;
4344
+ const cx0 = F.pos[0], cy0 = F.pos[1] + M.core.dy + (F.anchor === -1 ? rad * (1 - sy) : 0);
4345
+ const roll = F.rot[2] * DEG, cr = Math.cos(roll), sr = Math.sin(roll);
4346
+ const B = (lx, ly) => {
4347
+ const x = lx * sx * rad, y = ly * sy * rad;
4348
+ return V(cx0 + x * cr - y * sr, cy0 + x * sr + y * cr);
4349
+ };
4350
+ const round = M.core.round, A = this.bank.angles, curR = this.curR;
4351
+ const radiusAt = (th) => {
4352
+ const r = radiusAtAngle(A, curR, th);
4353
+ return r + (1 - r) * round;
4354
+ };
4355
+ const outline = (k) => {
4356
+ const idx = small ? this.bank.compact : null, n = idx ? idx.length : A.length, pts = [], sharp = [];
4357
+ for (let j = 0; j < n; j++) {
4358
+ const i = idx ? idx[j] : j, r = (curR[i] + (1 - curR[i]) * round) * k;
4359
+ pts.push(B(r * Math.cos(A[i]), r * Math.sin(A[i])));
4360
+ sharp.push(round < .5 && this.bank.sharp[i]);
4361
+ }
4362
+ return pathClosed(pts, sharp);
4363
+ };
4364
+ const qPY = quatFromEuler(F.rot[0], F.rot[1], 0);
4365
+ const color = mixHex(ch.palettes ? ch.palettes[this.palette] || ch.color : ch.color, "#9CA2A6", this.gray);
4366
+ const pxPerUnit = px / 100;
4367
+ this._set(S.svg, "aria-label", `OpenMax ${ch.label}:${st.label}`);
4368
+ let parts = M.parts;
4369
+ const mir = this.facing === "left" && ch.kind !== "logo";
4370
+ const relayOn = this.accentKind === "relay" && this.accentW > .004;
4371
+ const partner = this.partnerColor || (this.palette === "red" ? "blue" : "red");
4372
+ const peer = mixHex(ch.palettes ? ch.palettes[partner] || BRAND.red : color, "#9CA2A6", this.gray);
4373
+ const ac = this.clip?.name === this.accentKind ? this.clipT : 0;
4374
+ if (this.accentKind && this.accentW > .004) {
4375
+ let ap = ACCENT[this.accentKind](this.accentW, ac, {
4376
+ still,
4377
+ detail: !small,
4378
+ logo: ch.kind === "logo",
4379
+ peer,
4380
+ ink: mixHex(ch.ink || "#111111", "#6B7280", this.gray)
4381
+ });
4382
+ if (mir) ap = ap.map((q) => q.key.startsWith("relay.") ? {
4383
+ ...q,
4384
+ cx: -q.cx
4385
+ } : q);
4386
+ parts = parts.concat(ap);
4387
+ }
4388
+ this._renderParts(parts, V, U, color, 1.1 / pxPerUnit, .9 / pxPerUnit);
4389
+ this._set(S.head, "opacity", M.core.opacity >= .999 ? null : M.core.opacity);
4390
+ const showFace = M.faceVisible, fa = M.faceAlpha;
4391
+ if (ch.kind === "logo") {
4392
+ const G = ch.geom, rw = G.ringW * (small ? 1.15 : 1);
4393
+ const ringR = G.ring + (.5 - G.ring) * round, ringW = rw + (1 - rw) * round;
4394
+ this._set(S.body, "d", outline(ringR));
4395
+ this._set(S.body, "stroke", color);
4396
+ this._set(S.body, "stroke-width", rad * U * ringW);
4397
+ let d = "";
4398
+ if (showFace) {
4399
+ const base = small ? this.mSmall : this.mBase, n = base.length;
4400
+ const hump = this.logoP.hump * (1 + F.hk) * (1 - .16 * Math.min(1, 1 - F.lidOpen));
4401
+ const wave = small ? 0 : this.logoP.wave + F.wv, skew = this.logoP.skew + F.sk, ws = this.logoP.ws;
4402
+ const ampR = st.speak ? this.speechLevel != null ? this.speechLevel : speechEnvelope(this.time - .12, this.seed) : 0;
4403
+ d = visibleRuns(base.map(([u, v], i) => {
4404
+ const s = i / (n - 1), env = Math.sin(Math.PI * s);
4405
+ let hm = hump;
4406
+ if (st.speak) hm *= 1 + .22 * (u < 0 ? amp : ampR);
4407
+ if (st.voice) hm *= 1 + .3 * amp;
4408
+ hm *= 1 + skew * Math.sign(u);
4409
+ if (v < G.baseline) v = G.baseline + (v - G.baseline) * hm;
4410
+ v += wave * Math.sin(TAU * (2 * s - this.time * ws)) * env * env;
4411
+ return quatRotate(quatPow(qPY, .6 * env), expMapFront(u, v));
4412
+ })).map((run) => pathOpen(run.map(([x, y]) => {
4413
+ const k = radiusAt(Math.atan2(y, x));
4414
+ return B(x * k, y * k);
4415
+ }))).join("");
4416
+ }
4417
+ this._set(S.m, "display", d ? null : "none");
4418
+ if (d) {
4419
+ this._set(S.m, "d", d);
4420
+ this._set(S.m, "stroke", color);
4421
+ this._set(S.m, "stroke-width", rad * U * G.ringW * (small ? 1.15 : 1));
4422
+ this._set(S.m, "opacity", fa >= .999 ? null : fa);
4423
+ }
4424
+ } else {
4425
+ const wc = ch.watercolor && !small;
4426
+ this._set(S.body, "d", outline(1));
4427
+ this._set(S.body, "fill", color);
4428
+ this._set(S.body, "filter", wc ? `url(#${this.id}wc)` : null);
4429
+ this._set(S.face, "display", showFace ? null : "none");
4430
+ if (showFace) {
4431
+ const target = faceFeatures(this.faceName, amp, 1, this.character);
4432
+ const w = this.faceFrom ? ease(EASE_FACE)(Math.min(1, this.faceT / FACE_SECONDS)) : 1, cur = {};
4433
+ for (const key in target) cur[key] = this.faceFrom && this.faceFrom[key] && this.faceFrom[key].length === target[key].length ? lerpPts(this.faceFrom[key], target[key], w) : target[key];
4434
+ if (w >= 1) this.faceFrom = null;
4435
+ this.faceCur = cur;
4436
+ const lidOpen = F.lidOpen;
4437
+ const blinkEye = (pts) => {
4438
+ if (lidOpen === 1) return pts;
4439
+ const c = pts[3];
4440
+ return pts.map(([x, y], i) => [x + (i / 6 - .5) * .09 * Math.max(0, 1 - lidOpen), c[1] + (y - c[1]) * Math.max(.12, lidOpen)]);
4441
+ };
4442
+ let ji = 0;
4443
+ const proj = (pts) => visibleRuns(pts.map(([u, v]) => {
4444
+ const j = this.jit[ji++ % 64];
4445
+ return quatRotate(qPY, expMapFront(u + j[0], v + j[1]));
4446
+ })).map((run) => pathOpen(run.map(([x, y]) => B(x, y)))).join("");
4447
+ const kk = small ? 1.7 : 1, SW = ch.strokes;
4448
+ const eyeW = FACES[this.faceName].eyes.kind === "dot" ? SW.eyeDot : SW.eyeArc;
4449
+ if (ch.face === "ill" && !still && !small) {
4450
+ const Aw = .012 + .02 * this.logoP.wave / .05, n = cur.line.length;
4451
+ cur.line = cur.line.map(([x, y], i) => {
4452
+ const s = i / (n - 1);
4453
+ const env = s < .62 ? Math.sin(s / .62 * Math.PI) : 0;
4454
+ return [x + Aw * env * Math.sin(TAU * (1.5 * s - this.time * .5)), y];
4455
+ });
4456
+ }
4457
+ const ink = mixHex(ch.ink, "#6B7280", this.gray);
4458
+ const prog = still ? 1 : ease([
4459
+ .5,
4460
+ 0,
4461
+ .3,
4462
+ 1
4463
+ ])(Math.min(1, this.drawT / .7));
4464
+ this._set(S.face, "opacity", fa >= .999 ? null : fa);
4465
+ for (const key in cur) {
4466
+ const el = S.feat[key];
4467
+ if (!el) continue;
4468
+ const eye = key === "eyeL" || key === "eyeR", d = proj(eye ? blinkEye(cur[key]) : cur[key]);
4469
+ this._set(el, "display", d ? null : "none");
4470
+ if (!d) continue;
4471
+ this._set(el, "d", d);
4472
+ this._set(el, "stroke", ink);
4473
+ this._set(el, "stroke-width", rad * U * (eye ? eyeW : SW[key]) * kk);
4474
+ if (ch.face === "ill" && key === "line") this._set(el, "stroke-dashoffset", 1 - prog);
4475
+ }
4476
+ }
4477
+ }
4478
+ this._set(S.head, "transform", mir ? "matrix(-1 0 0 1 100 0)" : null);
4479
+ if (relayOn) {
4480
+ if (!S.helper) {
4481
+ S.helper = mk("g");
4482
+ S.svg.insertBefore(S.helper, S.head);
4483
+ this._w++;
4484
+ }
4485
+ const clone = S.head.cloneNode(true);
4486
+ clone.removeAttribute("transform");
4487
+ clone.removeAttribute("opacity");
4488
+ if (ch.kind !== "logo") clone.firstChild.setAttribute("fill", peer);
4489
+ S.helper.replaceChildren(clone);
4490
+ this._w++;
4491
+ const hp = relayHelperPose(ac, still), Rm = rad * U, [mcx, mcy] = V(cx0, cy0), hs = RELAY_HELPER.s;
4492
+ const [hx, hy] = V(RELAY_HELPER.x / DU, RELAY_HELPER.y / DU + hp.dy), ms = ch.kind === "logo" ? 1 : -1;
4493
+ this._set(S.helper, "transform", `${mir ? "matrix(-1 0 0 1 100 0) " : ""}translate(${r2(hx)} ${r2(hy + hs * Rm)}) rotate(${r2(-hp.rot)}) scale(${r2(ms * hs * hp.sx * 1e3) / 1e3} ${r2(hs * hp.sy * 1e3) / 1e3}) translate(${r2(-mcx)} ${r2(-(mcy + Rm))})`);
4494
+ this._set(S.helper, "opacity", easeOutCubic(this.accentW));
4495
+ } else if (S.helper) {
4496
+ S.helper.remove();
4497
+ S.helper = null;
4498
+ this._w++;
4499
+ }
4500
+ this.stats.writes = this._w;
4501
+ this.stats.frames++;
4502
+ }
4503
+ };
4504
+ function createAvatar(host, opts) {
4505
+ return new Avatar(host, opts);
4506
+ }
4507
+ function activeAvatarCount() {
4508
+ return live.size;
4509
+ }
4510
+ const AGENT_EVENT_MAP = {
4511
+ "session.started": "hello-enter",
4512
+ "session.ended": "goodbye",
4513
+ "message.received": "notification",
4514
+ "mention.received": "mentioned",
4515
+ "user.typing": "listening",
4516
+ "voice.input": "listening-voice",
4517
+ "user.thanks": "thanks",
4518
+ "run.started": "thinking",
4519
+ "reasoning.long": "thinking-deep",
4520
+ "plan.created": "planning",
4521
+ "tool.call": "working",
4522
+ "tool.search": "searching",
4523
+ "tool.read": "reading",
4524
+ "tool.code": "coding",
4525
+ "review.started": "reviewing",
4526
+ "test.running": "testing",
4527
+ "deploy.started": "deploying",
4528
+ "sync.started": "syncing",
4529
+ "file.downloading": "downloading",
4530
+ "file.uploading": "handoff",
4531
+ "connection.pending": "loading",
4532
+ "response.composing": "typing-reply",
4533
+ "response.streaming": "speaking",
4534
+ "approval.requested": "waiting",
4535
+ "approval.granted": "approved",
4536
+ "approval.denied": "rejected",
4537
+ "task.completed": "success",
4538
+ "milestone.reached": "celebrating",
4539
+ "task.failed": "error",
4540
+ "task.retrying": "recovering",
4541
+ "warning": "warning",
4542
+ "rate.limited": "rate-limited",
4543
+ "schedule.registered": "scheduled",
4544
+ "schedule.triggered": "alarm",
4545
+ "agent.idle": "idle",
4546
+ "agent.sleep": "sleeping",
4547
+ "agent.offline": "offline",
4548
+ "dnd.on": "do-not-disturb",
4549
+ "route.change": "page-loading",
4550
+ "request.pending": "module-loading",
4551
+ "skeleton.show": "skeleton",
4552
+ "data.empty": "empty",
4553
+ "search.empty": "no-results",
4554
+ "route.notfound": "not-found-404",
4555
+ "auth.forbidden": "no-permission",
4556
+ "network.offline": "network-offline",
4557
+ "network.reconnecting": "reconnecting",
4558
+ "request.retry": "retrying",
4559
+ "system.maintenance": "maintenance",
4560
+ "app.updating": "updating",
4561
+ "doc.saving": "saving",
4562
+ "doc.saved": "saved",
4563
+ "clipboard.copied": "copying-done",
4564
+ "agent.starting": "starting",
4565
+ "agent.ready": "ready",
4566
+ "agent.paused": "paused",
4567
+ "agent.resumed": "resuming",
4568
+ "agent.stopping": "stopping",
4569
+ "agent.shutdown": "shutting-down",
4570
+ "task.queued": "queued",
4571
+ "input.required": "waiting-for-input",
4572
+ "handover.human": "handover-to-human",
4573
+ "agent.question": "asking-question",
4574
+ "collab.started": "collaborating",
4575
+ "team.milestone": "celebrating-team"
4576
+ };
4577
+ function mapAgentEvent(evt, map = AGENT_EVENT_MAP) {
4578
+ const k = typeof evt === "string" ? evt : evt && evt.type;
4579
+ return k && map[k] || null;
4580
+ }
4581
+ function defineOpenMaxAvatar(tag = "openmax-avatar") {
4582
+ if (typeof customElements === "undefined") return null;
4583
+ if (customElements.get(tag)) return customElements.get(tag);
4584
+ class OpenMaxAvatarElement extends HTMLElement {
4585
+ static get observedAttributes() {
4586
+ return [
4587
+ "character",
4588
+ "color",
4589
+ "state",
4590
+ "size",
4591
+ "gaze",
4592
+ "reduced-motion",
4593
+ "seed",
4594
+ "facing",
4595
+ "partner-color"
4596
+ ];
4597
+ }
4598
+ connectedCallback() {
4599
+ if (!this.shadowRoot) this.attachShadow({ mode: "open" }).innerHTML = "<style>:host{display:inline-block;vertical-align:middle;line-height:0;width:64px;height:64px}div{width:100%;height:100%}</style><div part=\"stage\"></div>";
4600
+ this._applySize();
4601
+ if (!this._av) {
4602
+ const rm = this.getAttribute("reduced-motion");
4603
+ this._av = new Avatar(this.shadowRoot.lastChild, {
4604
+ character: this.getAttribute("character") || "logo",
4605
+ palette: this.getAttribute("color") || "blue",
4606
+ facing: this.getAttribute("facing") || "right",
4607
+ partnerColor: this.getAttribute("partner-color") || null,
4608
+ state: resolveState(this.getAttribute("state")) || "idle",
4609
+ seed: ((s) => s == null ? 7 : isNaN(+s) ? s : +s)(this.getAttribute("seed")),
4610
+ reducedMotion: rm === "true" ? true : rm === "false" ? false : "auto",
4611
+ onEvent: (type, detail) => {
4612
+ if (type === "statechange") {
4613
+ this._reflect = true;
4614
+ this.setAttribute("state", detail.state);
4615
+ this._reflect = false;
4616
+ }
4617
+ this.dispatchEvent(new CustomEvent(type, {
4618
+ detail,
4619
+ bubbles: true,
4620
+ composed: true
4621
+ }));
4622
+ }
4623
+ });
4624
+ }
4625
+ this._applyGaze();
4626
+ if (!this._onClick) {
4627
+ this._onClick = () => {
4628
+ if (this.getAttribute("poke") !== "off") this._av?.poke("bounce");
4629
+ };
4630
+ this.addEventListener("click", this._onClick);
4631
+ }
4632
+ }
4633
+ disconnectedCallback() {
4634
+ this._av?.destroy();
4635
+ this._av = null;
4636
+ this._gazeOff?.();
4637
+ }
4638
+ attributeChangedCallback(name, old, val) {
4639
+ if (!this._av || old === val || this._reflect) return;
4640
+ if (name === "state" && resolveState(val)) this._av.setState(val);
4641
+ else if (name === "character" && CHARACTERS[val]) this._av.setCharacter(val);
4642
+ else if (name === "color") this._av.setPalette(val || "blue");
4643
+ else if (name === "facing") this._av.setFacing(val);
4644
+ else if (name === "partner-color") this._av.setPartnerColor(val);
4645
+ else if (name === "size") this._applySize();
4646
+ else if (name === "gaze") this._applyGaze();
4647
+ else if (name === "reduced-motion") this._av.setReducedMotion(val === "true" ? true : val === "false" ? false : "auto");
4648
+ }
4649
+ _applySize() {
4650
+ const s = parseFloat(this.getAttribute("size"));
4651
+ if (s > 0) {
4652
+ this.style.width = s + "px";
4653
+ this.style.height = s + "px";
4654
+ }
4655
+ }
4656
+ _applyGaze() {
4657
+ this._gazeOff?.();
4658
+ this._gazeOff = null;
4659
+ if (this.getAttribute("gaze") !== "follow") {
4660
+ this._av?.lookAt(null);
4661
+ return;
4662
+ }
4663
+ const on = (e) => {
4664
+ const r = this.getBoundingClientRect(), k = Math.max(160, r.width * 1.2);
4665
+ this._av?.lookAt((e.clientX - r.left - r.width / 2) / k, (e.clientY - r.top - r.height / 2) / k);
4666
+ };
4667
+ window.addEventListener("pointermove", on, { passive: true });
4668
+ this._gazeOff = () => window.removeEventListener("pointermove", on);
4669
+ }
4670
+ get avatar() {
4671
+ return this._av;
4672
+ }
4673
+ get state() {
4674
+ return this._av ? this._av.state : this.getAttribute("state");
4675
+ }
4676
+ set state(v) {
4677
+ this.setAttribute("state", v);
4678
+ }
4679
+ setState(v) {
4680
+ this.setAttribute("state", v);
4681
+ }
4682
+ setSpeechLevel(v) {
4683
+ this._av?.setSpeechLevel(v);
4684
+ }
4685
+ lookAt(x, y) {
4686
+ this._av?.lookAt(x, y);
4687
+ }
4688
+ blink() {
4689
+ this._av?.blink();
4690
+ }
4691
+ poke(kind, o) {
4692
+ this._av?.poke(kind, o);
4693
+ }
4694
+ look(dir) {
4695
+ this._av?.look(dir);
4696
+ }
4697
+ setEmphasis(v) {
4698
+ this._av?.setEmphasis(v);
4699
+ }
4700
+ }
4701
+ customElements.define(tag, OpenMaxAvatarElement);
4702
+ return OpenMaxAvatarElement;
4703
+ }
4704
+ export { mulberry32 as $, catmullRom as A, evalTrack as B, STATES as C, transformShape as Ct, angleTable as D, activeAvatarCount as E, visibleRuns as Et, createSpring as F, illCharacter as G, expressionAt as H, cubicBezier as I, lerpRadii as J, isSimilar as K, cubicPts as L, composeMorph as M, cornerAngles as N, approach as O, createAvatar as P, mapAgentEvent as Q, defineOpenMaxAvatar as R, SPRING_HZ as S, superellipse as St, STATE_GROUPS as T, visibleOnSphere as Tt, extCharacter as U, expMapFront as V, faceFeatures as W, logoCharacter as X, lidMorphOpen as Y, logoMLine as Z, LOOKS as _, snapSpring as _t, BRAND as a, raySample as at, MorphBehavior as b, springAtRest as bt, CLIPS as c, resample as ct, EASE_FACE as d, samplePose as dt, polarShape as et, EASE_IN_OUT as f, seedOf as ft, LOGO_GEOM as g, smoothstep as gt, ILL_FACES as h, shuffleBag as ht, BLINK_BLOCKING as i, radiusAtAngle as it, compileClip as j, bridgeClip as k, COMPILED as l, resolveState as lt, FACES as m, shapeBank as mt, AGENT_EVENT_MAP as n, quatPow as nt, BRIDGE_SECONDS as o, registerCharacter as ot, EMPHASIS_FACE as p, seededShuffle as pt, lerpPts as q, Avatar as r, quatRotate as rt, CHARACTERS as s, relayHelperPose as st, ACCENT as t, quatFromEuler as tt, EASE_BRIDGE as u, restFrame as ut, MORPH as v, speechEnvelope as vt, STATE_ALIASES as w, uniformAngles as wt, RAYS as x, stepSpring as xt, MORPH_KINDS as y, sphereMap as yt, easeInOutCubic as z };