@wallarm-org/design-system 4.6.2 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AgentAvatar/AgentAvatar.d.ts +45 -0
- package/dist/components/AgentAvatar/AgentAvatar.js +544 -0
- package/dist/components/AgentAvatar/AgentAvatarGroup.d.ts +12 -0
- package/dist/components/AgentAvatar/AgentAvatarGroup.js +25 -0
- package/dist/components/AgentAvatar/index.d.ts +4 -0
- package/dist/components/AgentAvatar/index.js +3 -0
- package/dist/components/AgentAvatar/useBakedLayers.d.ts +9 -0
- package/dist/components/AgentAvatar/useBakedLayers.js +75 -0
- package/dist/components/AgentAvatar/useCharacter.d.ts +39 -0
- package/dist/components/AgentAvatar/useCharacter.js +251 -0
- package/dist/components/AgentGlyph/AgentGlyph.d.ts +30 -0
- package/dist/components/AgentGlyph/AgentGlyph.js +192 -0
- package/dist/components/AgentGlyph/index.d.ts +4 -0
- package/dist/components/AgentGlyph/index.js +2 -0
- package/dist/components/AgentLookBuilder/index.d.ts +3 -0
- package/dist/components/AgentLookBuilder/index.js +2 -0
- package/dist/components/AgentLookBuilder/kit.d.ts +36 -0
- package/dist/components/AgentLookBuilder/kit.js +30 -0
- package/dist/components/Chat/ChatGreeting.d.ts +1 -1
- package/dist/components/Chat/ChatGreeting.js +95 -44
- package/dist/components/Chat/ChatHeaderTitle.d.ts +1 -1
- package/dist/components/Chat/ChatHeaderTitle.js +32 -29
- package/dist/components/WallySkeleton/WallySkeleton.js +92 -71
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/lib/agent-characters/bake.d.ts +40 -0
- package/dist/lib/agent-characters/bake.js +220 -0
- package/dist/lib/agent-characters/canvas.d.ts +7 -0
- package/dist/lib/agent-characters/canvas.js +22 -0
- package/dist/lib/agent-characters/char.d.ts +32 -0
- package/dist/lib/agent-characters/char.js +375 -0
- package/dist/lib/agent-characters/color.d.ts +6 -0
- package/dist/lib/agent-characters/color.js +20 -0
- package/dist/lib/agent-characters/data.gen.d.ts +106 -0
- package/dist/lib/agent-characters/data.gen.js +3854 -0
- package/dist/lib/agent-characters/engine.d.ts +206 -0
- package/dist/lib/agent-characters/engine.js +1241 -0
- package/dist/lib/agent-characters/eyes.d.ts +18 -0
- package/dist/lib/agent-characters/eyes.js +132 -0
- package/dist/lib/agent-characters/geom.d.ts +23 -0
- package/dist/lib/agent-characters/geom.js +109 -0
- package/dist/lib/agent-characters/glyph.d.ts +21 -0
- package/dist/lib/agent-characters/glyph.js +126 -0
- package/dist/lib/agent-characters/look.d.ts +24 -0
- package/dist/lib/agent-characters/look.js +68 -0
- package/dist/lib/agent-characters/motion.d.ts +73 -0
- package/dist/lib/agent-characters/motion.js +1215 -0
- package/dist/lib/agent-characters/paths.d.ts +13 -0
- package/dist/lib/agent-characters/paths.js +118 -0
- package/dist/lib/agent-characters/places.d.ts +76 -0
- package/dist/lib/agent-characters/places.js +64 -0
- package/dist/lib/agent-characters/propOf.d.ts +7 -0
- package/dist/lib/agent-characters/propOf.js +20 -0
- package/dist/lib/agent-characters/props.d.ts +4 -0
- package/dist/lib/agent-characters/props.js +337 -0
- package/dist/lib/agent-characters/queue.d.ts +23 -0
- package/dist/lib/agent-characters/queue.js +73 -0
- package/dist/lib/agent-characters/runtime.d.ts +69 -0
- package/dist/lib/agent-characters/runtime.js +178 -0
- package/dist/lib/agent-characters/svg.d.ts +6 -0
- package/dist/lib/agent-characters/svg.js +6 -0
- package/dist/lib/agent-characters/worker.d.ts +6 -0
- package/dist/lib/agent-characters/worker.js +94 -0
- package/dist/metadata/components.json +689 -276
- package/dist/theme/components/agent-avatar.css +42 -0
- package/dist/theme/index.css +1 -0
- package/dist/utils/renderSvgNode.d.ts +4 -0
- package/dist/utils/renderSvgNode.js +12 -0
- package/package.json +2 -1
|
@@ -0,0 +1,1241 @@
|
|
|
1
|
+
import { hexOf } from "./color.js";
|
|
2
|
+
import { eyeTargets, eyesPath, helloPop } from "./eyes.js";
|
|
3
|
+
import { geom, shapeOf } from "./geom.js";
|
|
4
|
+
import { hash32, rng } from "./look.js";
|
|
5
|
+
import { ACTS, ACT_W, BEAT, E_FILL, E_GRAV, E_INOUT, E_OUT, E_RISE, FAST, FIDDLE, HELLO_PROP, HELLO_TILT, INVITE, NOX, P_BRIGHT, P_DART, P_LAND, P_POP, P_PURSUIT, P_SHAPE, P_SQ, P_W, blinkOpen, lerp, logn, propTr, spring, stepS } from "./motion.js";
|
|
6
|
+
import { clamp, r2 } from "./paths.js";
|
|
7
|
+
import { propOf } from "./propOf.js";
|
|
8
|
+
import { getRuntime } from "./runtime.js";
|
|
9
|
+
const EYE_KEYS = [
|
|
10
|
+
'w',
|
|
11
|
+
'ht',
|
|
12
|
+
'hb',
|
|
13
|
+
'kt',
|
|
14
|
+
'kb',
|
|
15
|
+
'lid',
|
|
16
|
+
'rot',
|
|
17
|
+
'bright'
|
|
18
|
+
];
|
|
19
|
+
const invOk = (o)=>!!(o?.svg.isConnected && 'invite' === o.st);
|
|
20
|
+
class Character {
|
|
21
|
+
svg;
|
|
22
|
+
c;
|
|
23
|
+
S;
|
|
24
|
+
o;
|
|
25
|
+
st;
|
|
26
|
+
visible = true;
|
|
27
|
+
rectDirty = false;
|
|
28
|
+
clips = [];
|
|
29
|
+
peers = null;
|
|
30
|
+
fid = null;
|
|
31
|
+
cover = false;
|
|
32
|
+
rt = getRuntime();
|
|
33
|
+
timers = new Set();
|
|
34
|
+
disposed = false;
|
|
35
|
+
fig;
|
|
36
|
+
ef;
|
|
37
|
+
eg;
|
|
38
|
+
eyes;
|
|
39
|
+
vglow;
|
|
40
|
+
sha;
|
|
41
|
+
shc;
|
|
42
|
+
props;
|
|
43
|
+
pa;
|
|
44
|
+
beam;
|
|
45
|
+
glint;
|
|
46
|
+
stitch;
|
|
47
|
+
veilr;
|
|
48
|
+
E;
|
|
49
|
+
gx;
|
|
50
|
+
gy;
|
|
51
|
+
sq;
|
|
52
|
+
wt;
|
|
53
|
+
blink = null;
|
|
54
|
+
flicker = null;
|
|
55
|
+
land = null;
|
|
56
|
+
r;
|
|
57
|
+
rate;
|
|
58
|
+
bias;
|
|
59
|
+
phase;
|
|
60
|
+
nextBlink;
|
|
61
|
+
nextGlance;
|
|
62
|
+
nextHop = 0;
|
|
63
|
+
read = null;
|
|
64
|
+
ghostT = 1;
|
|
65
|
+
figOp = 1;
|
|
66
|
+
propScale;
|
|
67
|
+
rect = null;
|
|
68
|
+
rectE = -1;
|
|
69
|
+
r2;
|
|
70
|
+
nextBeat = 0;
|
|
71
|
+
nextAct;
|
|
72
|
+
lastAct = '';
|
|
73
|
+
pv = null;
|
|
74
|
+
lastPg = '';
|
|
75
|
+
hl = null;
|
|
76
|
+
inv = null;
|
|
77
|
+
doneT;
|
|
78
|
+
covHT;
|
|
79
|
+
covT = 0;
|
|
80
|
+
covY = 0;
|
|
81
|
+
cov = null;
|
|
82
|
+
topping = false;
|
|
83
|
+
reachN = 0;
|
|
84
|
+
lastReach = 0;
|
|
85
|
+
cueK = null;
|
|
86
|
+
dbl = 0;
|
|
87
|
+
lt = 0;
|
|
88
|
+
lastD;
|
|
89
|
+
lastB;
|
|
90
|
+
lastT;
|
|
91
|
+
lastFo;
|
|
92
|
+
lastV;
|
|
93
|
+
lastSa;
|
|
94
|
+
lastSc;
|
|
95
|
+
lastPs;
|
|
96
|
+
lastPa;
|
|
97
|
+
lastBeam;
|
|
98
|
+
lastGl;
|
|
99
|
+
lastSo;
|
|
100
|
+
constructor(svg, c, o){
|
|
101
|
+
const st = o.state;
|
|
102
|
+
const e0 = eyeTargets(c.eyes, st);
|
|
103
|
+
const q = (part)=>svg.querySelector(`[data-part~="${part}"]`);
|
|
104
|
+
this.svg = svg;
|
|
105
|
+
this.c = c;
|
|
106
|
+
this.S = shapeOf(c.shape);
|
|
107
|
+
this.o = o;
|
|
108
|
+
this.st = st;
|
|
109
|
+
this.fig = q('fig');
|
|
110
|
+
this.ef = q('ef');
|
|
111
|
+
this.eg = q('eg');
|
|
112
|
+
this.eyes = q('eyes');
|
|
113
|
+
this.vglow = q('vglow');
|
|
114
|
+
this.sha = q('sha');
|
|
115
|
+
this.shc = q('shc');
|
|
116
|
+
this.props = q('props');
|
|
117
|
+
this.pa = q('pa');
|
|
118
|
+
this.beam = q('beam');
|
|
119
|
+
this.glint = q('glint');
|
|
120
|
+
this.stitch = q('stitch');
|
|
121
|
+
this.veilr = q('veilr');
|
|
122
|
+
this.E = Object.fromEntries(EYE_KEYS.map((k)=>[
|
|
123
|
+
k,
|
|
124
|
+
spring(e0[k], 'bright' === k ? P_BRIGHT : P_SHAPE)
|
|
125
|
+
]));
|
|
126
|
+
this.gx = spring(0, P_DART);
|
|
127
|
+
this.gy = spring(e0.gy, P_DART);
|
|
128
|
+
this.sq = spring(1, P_SQ);
|
|
129
|
+
this.wt = {
|
|
130
|
+
breathe: spring(1, P_W),
|
|
131
|
+
bob: spring(0, P_W),
|
|
132
|
+
float: spring(0, P_W),
|
|
133
|
+
work: spring(0, P_W)
|
|
134
|
+
};
|
|
135
|
+
const seed = hash32(`x${c.shape}${o.salt}`);
|
|
136
|
+
this.r = rng(seed);
|
|
137
|
+
this.rate = 0.8 + 0.45 * this.r();
|
|
138
|
+
this.bias = (this.r() - 0.5) * 0.2;
|
|
139
|
+
this.phase = 1000 * this.r();
|
|
140
|
+
const now = performance.now();
|
|
141
|
+
this.nextBlink = now + 400 + 2500 * this.r();
|
|
142
|
+
this.nextGlance = now + 600 + 1800 * this.r();
|
|
143
|
+
this.propScale = spring(1, P_POP);
|
|
144
|
+
this.r2 = rng(0x5bd1e995 ^ seed);
|
|
145
|
+
this.nextAct = now + this.actGap() * (0.3 + 0.7 * this.r2());
|
|
146
|
+
this.props?.removeAttribute('transform');
|
|
147
|
+
this.applyState(st, now, true);
|
|
148
|
+
}
|
|
149
|
+
later(fn, ms) {
|
|
150
|
+
const id = setTimeout(()=>{
|
|
151
|
+
this.timers.delete(id);
|
|
152
|
+
if (!this.disposed) fn();
|
|
153
|
+
}, ms);
|
|
154
|
+
this.timers.add(id);
|
|
155
|
+
return id;
|
|
156
|
+
}
|
|
157
|
+
clear(id) {
|
|
158
|
+
clearTimeout(id);
|
|
159
|
+
if (void 0 !== id) this.timers.delete(id);
|
|
160
|
+
}
|
|
161
|
+
isLive() {
|
|
162
|
+
return this.rt.live.has(this);
|
|
163
|
+
}
|
|
164
|
+
targets(st) {
|
|
165
|
+
return eyeTargets(this.c.eyes, st);
|
|
166
|
+
}
|
|
167
|
+
setTargets(t, pop) {
|
|
168
|
+
for (const k of EYE_KEYS){
|
|
169
|
+
this.E[k].t = t[k];
|
|
170
|
+
this.E[k].p = 'bright' === k ? P_BRIGHT : pop ? P_POP : P_SHAPE;
|
|
171
|
+
}
|
|
172
|
+
this.gy.t = t.gy;
|
|
173
|
+
this.gx.t = 0;
|
|
174
|
+
}
|
|
175
|
+
snap() {
|
|
176
|
+
for (const k of EYE_KEYS){
|
|
177
|
+
this.E[k].x = this.E[k].t;
|
|
178
|
+
this.E[k].v = 0;
|
|
179
|
+
}
|
|
180
|
+
this.gx.x = this.gx.t;
|
|
181
|
+
this.gy.x = this.gy.t;
|
|
182
|
+
this.gx.v = this.gy.v = 0;
|
|
183
|
+
}
|
|
184
|
+
startBlink(now, dur) {
|
|
185
|
+
this.blink = {
|
|
186
|
+
t0: now,
|
|
187
|
+
dur: dur || 170 + 90 * this.r()
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
returnTo() {
|
|
191
|
+
return this.o.returnTo ? this.o.returnTo() : 'idle';
|
|
192
|
+
}
|
|
193
|
+
emit(st, from) {
|
|
194
|
+
this.o.onState?.(st, from);
|
|
195
|
+
}
|
|
196
|
+
applyState(st, now, first = false) {
|
|
197
|
+
const prev = this.st;
|
|
198
|
+
this.st = st;
|
|
199
|
+
const svg = this.svg;
|
|
200
|
+
this.hl = null;
|
|
201
|
+
if ('power' !== st) {
|
|
202
|
+
this.land = null;
|
|
203
|
+
this.flicker = null;
|
|
204
|
+
}
|
|
205
|
+
svg.setAttribute('data-state', st);
|
|
206
|
+
this.ghostCls();
|
|
207
|
+
svg.toggleAttribute('data-veiled', 'box' === st || 'power' === st || 'invite' === st);
|
|
208
|
+
const t = this.targets('power' === st && 'invite' === prev ? 'invite' : st);
|
|
209
|
+
const live = this.isLive() || this.o.live && this.rt.motionOn();
|
|
210
|
+
const mask = !first && live && (('done' === prev || 'hello' === prev) && 'idle' === st || 'idle' === prev && ('failed' === st || 'working' === st) || 'working' === prev && 'idle' === st || 'needs' === prev && 'working' === st);
|
|
211
|
+
if (!live || first) {
|
|
212
|
+
this.setTargets(t);
|
|
213
|
+
this.snap();
|
|
214
|
+
} else if (mask) {
|
|
215
|
+
this.startBlink(now, 200);
|
|
216
|
+
this.later(()=>{
|
|
217
|
+
if (this.st === st) this.setTargets(t);
|
|
218
|
+
}, 80);
|
|
219
|
+
} else if ('off' === st) {
|
|
220
|
+
this.E.ht.t = t.ht;
|
|
221
|
+
this.E.hb.t = t.hb;
|
|
222
|
+
this.E.lid.t = 0;
|
|
223
|
+
this.E.rot.t = 0;
|
|
224
|
+
this.later(()=>{
|
|
225
|
+
if ('off' === this.st) this.E.w.t = t.w;
|
|
226
|
+
}, 120);
|
|
227
|
+
this.later(()=>{
|
|
228
|
+
if ('off' === this.st) this.E.bright.t = t.bright;
|
|
229
|
+
}, 150);
|
|
230
|
+
this.gx.t = 0;
|
|
231
|
+
this.gy.t = 0;
|
|
232
|
+
} else if ('hello' === st) {
|
|
233
|
+
this.setTargets(helloPop(this.targets('idle')), true);
|
|
234
|
+
this.hl = {
|
|
235
|
+
t0: now
|
|
236
|
+
};
|
|
237
|
+
} else this.setTargets(t, 'done' === st);
|
|
238
|
+
this.wt.bob.t = 'working' === st ? 1 : 0;
|
|
239
|
+
this.wt.work.t = 'working' === st ? 1 : 0;
|
|
240
|
+
this.wt.breathe.t = 'off' === st || 'box' === st || 'power' === st ? 0 : 1;
|
|
241
|
+
this.wt.float.t = 'box' === st ? 1 : 0;
|
|
242
|
+
if (first || !live) for(const k in this.wt)this.wt[k].x = this.wt[k].t;
|
|
243
|
+
this.read = null;
|
|
244
|
+
if ('box' === st) {
|
|
245
|
+
this.ghostT = 0;
|
|
246
|
+
this.figOp = 0.5;
|
|
247
|
+
this.propScale.x = this.propScale.t = 0;
|
|
248
|
+
if (first || !live) this.wt.float.x = 1;
|
|
249
|
+
this.requestVeil();
|
|
250
|
+
} else if ('invite' === st) {
|
|
251
|
+
this.ghostT = 0;
|
|
252
|
+
this.figOp = 1;
|
|
253
|
+
this.propScale.x = this.propScale.t = 0;
|
|
254
|
+
this.requestVeil();
|
|
255
|
+
this.inv = {
|
|
256
|
+
n: 0,
|
|
257
|
+
next: now + 2000 + 1000 * this.r2(),
|
|
258
|
+
done: false
|
|
259
|
+
};
|
|
260
|
+
if (live && !invOk(this.rt.inv.owner)) this.rt.inv.owner = this;
|
|
261
|
+
} else if ('power' !== st) {
|
|
262
|
+
this.ghostT = 1;
|
|
263
|
+
this.figOp = 1;
|
|
264
|
+
this.propScale.t = 1;
|
|
265
|
+
if ('box' === prev || 'invite' === prev || first || !live) this.propScale.x = 1;
|
|
266
|
+
}
|
|
267
|
+
if ('invite' !== st) this.inv = null;
|
|
268
|
+
if ('hello' === st && this.o.autoReturn) {
|
|
269
|
+
const ms = live ? 1900 + 400 * this.r2() : 1200;
|
|
270
|
+
this.clear(this.doneT);
|
|
271
|
+
this.doneT = this.later(()=>{
|
|
272
|
+
if ('hello' === this.st && this.svg.isConnected) {
|
|
273
|
+
const to = this.returnTo();
|
|
274
|
+
this.setState(to);
|
|
275
|
+
this.emit(to, 'hello');
|
|
276
|
+
}
|
|
277
|
+
}, ms);
|
|
278
|
+
}
|
|
279
|
+
if ('done' === st && this.o.autoReturn) {
|
|
280
|
+
const ms = 1600 + 600 * this.r();
|
|
281
|
+
this.clear(this.doneT);
|
|
282
|
+
this.doneT = this.later(()=>{
|
|
283
|
+
if ('done' === this.st && this.svg.isConnected) {
|
|
284
|
+
const to = this.returnTo();
|
|
285
|
+
this.setState(to);
|
|
286
|
+
this.emit(to, 'done');
|
|
287
|
+
}
|
|
288
|
+
}, ms);
|
|
289
|
+
}
|
|
290
|
+
if (!live) return;
|
|
291
|
+
this.releaseClips(now);
|
|
292
|
+
if ('hello' === st && !first) this.helloClips(now);
|
|
293
|
+
if ('failed' === st) this.nextBeat = now + 1700 + 1000 * this.r2();
|
|
294
|
+
if ('idle' === st) this.nextAct = Math.max(this.nextAct, now + 0.5 * this.actGap());
|
|
295
|
+
if ('done' === st) this.hop(now, 7);
|
|
296
|
+
if ('failed' === st && !this.clipBusy('wob', now)) this.clips.push({
|
|
297
|
+
wob: 1,
|
|
298
|
+
t0: now,
|
|
299
|
+
keys: [
|
|
300
|
+
[
|
|
301
|
+
0,
|
|
302
|
+
0,
|
|
303
|
+
1,
|
|
304
|
+
0
|
|
305
|
+
],
|
|
306
|
+
[
|
|
307
|
+
150,
|
|
308
|
+
0,
|
|
309
|
+
1,
|
|
310
|
+
-4
|
|
311
|
+
],
|
|
312
|
+
[
|
|
313
|
+
300,
|
|
314
|
+
0,
|
|
315
|
+
1,
|
|
316
|
+
2.5
|
|
317
|
+
],
|
|
318
|
+
[
|
|
319
|
+
450,
|
|
320
|
+
0,
|
|
321
|
+
1,
|
|
322
|
+
-1
|
|
323
|
+
],
|
|
324
|
+
[
|
|
325
|
+
600,
|
|
326
|
+
0,
|
|
327
|
+
1,
|
|
328
|
+
0
|
|
329
|
+
]
|
|
330
|
+
],
|
|
331
|
+
ease: E_INOUT
|
|
332
|
+
});
|
|
333
|
+
if ('needs' === st) this.nextHop = now + 500;
|
|
334
|
+
if ('power' === st) this.startLanding(now, prev);
|
|
335
|
+
}
|
|
336
|
+
requestVeil() {
|
|
337
|
+
this.o.requestVeil?.();
|
|
338
|
+
}
|
|
339
|
+
ghostCls() {
|
|
340
|
+
const st = this.st;
|
|
341
|
+
this.svg.toggleAttribute('data-ghosting', 'box' === st || 'power' === st || 'invite' === st || !!this.cover && 'off' !== st);
|
|
342
|
+
}
|
|
343
|
+
setCover(onIn) {
|
|
344
|
+
const on = !!onIn;
|
|
345
|
+
const now = performance.now();
|
|
346
|
+
if (on && this.topping) {
|
|
347
|
+
this.clips = this.clips.filter((c)=>!c.cvt);
|
|
348
|
+
this.topping = false;
|
|
349
|
+
const cov = this.cov;
|
|
350
|
+
cov.x = cov.t = cov.v = 0;
|
|
351
|
+
this.lastV = null;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (on === !!this.cover) return;
|
|
355
|
+
this.cover = on;
|
|
356
|
+
if (on) {
|
|
357
|
+
this.covT = geom(this.S).top[1];
|
|
358
|
+
this.covY = Math.min(this.covT + 0.3 * (108 - this.covT), this.S.v[1] - 4);
|
|
359
|
+
this.cov = spring(0, P_W);
|
|
360
|
+
this.reachN = 0;
|
|
361
|
+
this.lastReach = now - 35000;
|
|
362
|
+
this.requestVeil();
|
|
363
|
+
} else {
|
|
364
|
+
this.clear(this.covHT);
|
|
365
|
+
this.topping = false;
|
|
366
|
+
this.cov = null;
|
|
367
|
+
}
|
|
368
|
+
const veil = this.svg.querySelector('[data-part~="veil"]');
|
|
369
|
+
if (veil) this.fig.insertBefore(veil, on ? this.fig.querySelector(':scope > g[clip-path]:not([data-part~="veil"])') : this.fig.querySelector(':scope > [data-part~="visor"]'));
|
|
370
|
+
this.ghostCls();
|
|
371
|
+
this.lastV = null;
|
|
372
|
+
if (!this.isLive()) this.render(now);
|
|
373
|
+
}
|
|
374
|
+
get filling() {
|
|
375
|
+
return this.topping;
|
|
376
|
+
}
|
|
377
|
+
coverAll() {
|
|
378
|
+
if (!this.cover || this.topping) return;
|
|
379
|
+
const now = performance.now();
|
|
380
|
+
if (!this.isLive()) {
|
|
381
|
+
this.setCover(false);
|
|
382
|
+
if ('idle' === this.st) {
|
|
383
|
+
this.setState('done');
|
|
384
|
+
this.emit('done', 'idle');
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
this.topping = true;
|
|
389
|
+
this.clear(this.covHT);
|
|
390
|
+
const cov = this.cov;
|
|
391
|
+
const y0 = cov.x;
|
|
392
|
+
cov.x = cov.t = cov.v = 0;
|
|
393
|
+
for (const c of this.clips)if ('reach' === c.kind && !c.rel) c.rel = now;
|
|
394
|
+
this.clips.push({
|
|
395
|
+
cvt: 1,
|
|
396
|
+
t0: now,
|
|
397
|
+
keys: [
|
|
398
|
+
[
|
|
399
|
+
0,
|
|
400
|
+
0,
|
|
401
|
+
1,
|
|
402
|
+
0,
|
|
403
|
+
null,
|
|
404
|
+
{
|
|
405
|
+
cv: y0
|
|
406
|
+
}
|
|
407
|
+
],
|
|
408
|
+
[
|
|
409
|
+
480,
|
|
410
|
+
0,
|
|
411
|
+
1,
|
|
412
|
+
0,
|
|
413
|
+
E_INOUT,
|
|
414
|
+
{
|
|
415
|
+
cv: -(this.covY - this.covT + 3)
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
],
|
|
419
|
+
onEnd: ()=>{
|
|
420
|
+
this.setCover(false);
|
|
421
|
+
this.o.onCoverEnd?.();
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
this.later(()=>{
|
|
425
|
+
if (this.topping && this.svg.isConnected && 'idle' === this.st) {
|
|
426
|
+
this.setState('done');
|
|
427
|
+
this.emit('done', 'idle');
|
|
428
|
+
}
|
|
429
|
+
}, 360);
|
|
430
|
+
}
|
|
431
|
+
cueDir(now = performance.now()) {
|
|
432
|
+
const K = this.cueK;
|
|
433
|
+
if (K && K.e === this.rt.rectEpoch && now - K.t < 1000) return K.v;
|
|
434
|
+
let el = this.o.cue;
|
|
435
|
+
if ('function' == typeof el) el = el();
|
|
436
|
+
let v = null;
|
|
437
|
+
if (el?.isConnected) {
|
|
438
|
+
const r = el.getBoundingClientRect();
|
|
439
|
+
if (r.width && r.height) {
|
|
440
|
+
const me = this.box();
|
|
441
|
+
const dx = r.left + r.width / 2 - me.x;
|
|
442
|
+
const dy = r.top + r.height / 2 - me.y;
|
|
443
|
+
const d = Math.hypot(dx, dy) || 1;
|
|
444
|
+
v = {
|
|
445
|
+
gx: 0.8 * dx / d,
|
|
446
|
+
gy: clamp(0.7 * dy / d, -0.4, 0.6)
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
this.cueK = {
|
|
451
|
+
e: this.rt.rectEpoch,
|
|
452
|
+
t: now,
|
|
453
|
+
v
|
|
454
|
+
};
|
|
455
|
+
return v;
|
|
456
|
+
}
|
|
457
|
+
cueHover(on) {
|
|
458
|
+
if (!this.isLive()) return;
|
|
459
|
+
const now = performance.now();
|
|
460
|
+
if ('invite' === this.st) {
|
|
461
|
+
if (on && !this.clips.some((c)=>c.perk && !c.rel)) {
|
|
462
|
+
for (const c of this.clips)if (c.inv && !c.rel) c.rel = now;
|
|
463
|
+
if (this.inv) this.inv.done = true;
|
|
464
|
+
const c = this.cueDir(now) || {
|
|
465
|
+
gx: 0,
|
|
466
|
+
gy: 0
|
|
467
|
+
};
|
|
468
|
+
const s = Math.abs(c.gx) >= 0.15 ? Math.sign(c.gx) : 0;
|
|
469
|
+
const x = {
|
|
470
|
+
gx: c.gx,
|
|
471
|
+
gy: 1.25 * c.gy,
|
|
472
|
+
br: 0.18
|
|
473
|
+
};
|
|
474
|
+
this.clips.push({
|
|
475
|
+
perk: 1,
|
|
476
|
+
gaze: true,
|
|
477
|
+
slow: false,
|
|
478
|
+
relMs: 400,
|
|
479
|
+
t0: now,
|
|
480
|
+
keys: [
|
|
481
|
+
[
|
|
482
|
+
0,
|
|
483
|
+
0,
|
|
484
|
+
1,
|
|
485
|
+
0,
|
|
486
|
+
null,
|
|
487
|
+
{
|
|
488
|
+
gx: 0,
|
|
489
|
+
gy: 0,
|
|
490
|
+
br: 0
|
|
491
|
+
}
|
|
492
|
+
],
|
|
493
|
+
[
|
|
494
|
+
220,
|
|
495
|
+
0,
|
|
496
|
+
1.01,
|
|
497
|
+
2 * s,
|
|
498
|
+
E_OUT,
|
|
499
|
+
x
|
|
500
|
+
],
|
|
501
|
+
[
|
|
502
|
+
1e7,
|
|
503
|
+
0,
|
|
504
|
+
1.01,
|
|
505
|
+
2 * s,
|
|
506
|
+
null,
|
|
507
|
+
x
|
|
508
|
+
]
|
|
509
|
+
]
|
|
510
|
+
});
|
|
511
|
+
} else if (!on) {
|
|
512
|
+
for (const c of this.clips)if (c.perk && !c.rel) c.rel = now;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (this.cover && this.cov) {
|
|
516
|
+
this.clear(this.covHT);
|
|
517
|
+
if (on) this.covHT = this.later(()=>{
|
|
518
|
+
if (this.cover && !this.topping && this.cov) this.cov.t = -0.35 * (this.covY - this.covT);
|
|
519
|
+
}, 150);
|
|
520
|
+
else if (!this.topping) this.cov.t = 0;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
invTick(now) {
|
|
524
|
+
if (this.clips.some((c)=>(c.inv || c.perk) && !c.rel)) return true;
|
|
525
|
+
const I = this.inv;
|
|
526
|
+
if (!I || I.done || I.n >= 3 || now < I.next || !this.repOn() || this.blink) return false;
|
|
527
|
+
const c = this.cueDir(now);
|
|
528
|
+
if (!c || Math.abs(this.gx.x) > 0.05 || Math.abs(this.gy.x) > 0.05) return false;
|
|
529
|
+
const INV = this.rt.inv;
|
|
530
|
+
if (invOk(INV.owner)) {
|
|
531
|
+
if (INV.owner !== this) return false;
|
|
532
|
+
} else INV.owner = this;
|
|
533
|
+
let n = 0;
|
|
534
|
+
for (const k of this.rt.live)if (k !== this && k.visible && k.svg.isConnected) {
|
|
535
|
+
if ('needs' === k.st || 'failed' === k.st || 'hello' === k.st || 'done' === k.st) {
|
|
536
|
+
I.next = now + 1500;
|
|
537
|
+
return false;
|
|
538
|
+
}
|
|
539
|
+
if (k.clips.some((x)=>x.act && !x.rel)) n++;
|
|
540
|
+
}
|
|
541
|
+
const ACT = this.rt.act;
|
|
542
|
+
if (n >= ACT.cap || now - ACT.last < 700 || now - INV.last < 6000) {
|
|
543
|
+
I.next = now + 600 + 900 * this.r2();
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
this.clips.push({
|
|
547
|
+
act: 1,
|
|
548
|
+
inv: 1,
|
|
549
|
+
kind: 'invite',
|
|
550
|
+
gaze: true,
|
|
551
|
+
slow: false,
|
|
552
|
+
t0: now,
|
|
553
|
+
keys: INVITE(c)
|
|
554
|
+
});
|
|
555
|
+
I.n++;
|
|
556
|
+
I.next = now + 2300 + (1 === I.n ? 12000 : 24000) * (0.85 + 0.3 * this.r2());
|
|
557
|
+
INV.last = ACT.last = now;
|
|
558
|
+
this.nextBlink = Math.max(this.nextBlink, now + 3100);
|
|
559
|
+
return true;
|
|
560
|
+
}
|
|
561
|
+
clipBusy(tag, now) {
|
|
562
|
+
return this.clips.some((c)=>c[tag] && now - c.t0 < c.keys[c.keys.length - 1][0]);
|
|
563
|
+
}
|
|
564
|
+
hop(now, hgt = 10) {
|
|
565
|
+
if (this.clipBusy('hop', now)) return;
|
|
566
|
+
this.clips.push({
|
|
567
|
+
hop: 1,
|
|
568
|
+
t0: now,
|
|
569
|
+
keys: [
|
|
570
|
+
[
|
|
571
|
+
0,
|
|
572
|
+
0,
|
|
573
|
+
1
|
|
574
|
+
],
|
|
575
|
+
[
|
|
576
|
+
90,
|
|
577
|
+
0,
|
|
578
|
+
0.9,
|
|
579
|
+
0,
|
|
580
|
+
E_OUT
|
|
581
|
+
],
|
|
582
|
+
[
|
|
583
|
+
250,
|
|
584
|
+
-hgt,
|
|
585
|
+
1.08,
|
|
586
|
+
0,
|
|
587
|
+
E_RISE
|
|
588
|
+
],
|
|
589
|
+
[
|
|
590
|
+
290,
|
|
591
|
+
-hgt,
|
|
592
|
+
1,
|
|
593
|
+
0
|
|
594
|
+
],
|
|
595
|
+
[
|
|
596
|
+
430,
|
|
597
|
+
0,
|
|
598
|
+
1,
|
|
599
|
+
0,
|
|
600
|
+
E_GRAV
|
|
601
|
+
]
|
|
602
|
+
],
|
|
603
|
+
onEnd: (n)=>{
|
|
604
|
+
this.sq.x = 0.86;
|
|
605
|
+
this.sq.v = 0;
|
|
606
|
+
this.sq.p = P_SQ;
|
|
607
|
+
if ('needs' === this.st) this.startBlink(n);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
releaseClips(now, all = true) {
|
|
612
|
+
for (const c of this.clips)if ((c.act || c.perk || all && (c.beat || c.hw || c.tilt)) && !c.rel) c.rel = now;
|
|
613
|
+
}
|
|
614
|
+
helloClips(now) {
|
|
615
|
+
this.hop(now, 6);
|
|
616
|
+
if (!this.clips.some((c)=>c.tilt && !c.rel)) this.clips.push({
|
|
617
|
+
tilt: 1,
|
|
618
|
+
t0: now,
|
|
619
|
+
keys: HELLO_TILT
|
|
620
|
+
});
|
|
621
|
+
const k = this.fid ? this.fid.k : null;
|
|
622
|
+
const hp = k ? HELLO_PROP[k] : void 0;
|
|
623
|
+
if (hp && !this.clips.some((c)=>c.hw && !c.rel)) this.clips.push({
|
|
624
|
+
hw: 1,
|
|
625
|
+
t0: now,
|
|
626
|
+
keys: hp
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
greet() {
|
|
630
|
+
if ('idle' === this.st && !this.land && this.o.autoReturn) this.setState('hello');
|
|
631
|
+
}
|
|
632
|
+
beat(now) {
|
|
633
|
+
if (!this.clips.some((c)=>c.beat && !c.rel)) this.clips.push({
|
|
634
|
+
beat: 1,
|
|
635
|
+
t0: now,
|
|
636
|
+
keys: BEAT
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
actGap() {
|
|
640
|
+
const s = this.o.size || 120;
|
|
641
|
+
return logn(this.r2, 6000 * this.rate, 0.45, 3000, 15000) * (s <= 48 ? 1.6 : s <= 72 ? 1.25 : 1);
|
|
642
|
+
}
|
|
643
|
+
repOn() {
|
|
644
|
+
return false !== this.o.rep && (this.o.size || 120) > 32 && !this.land;
|
|
645
|
+
}
|
|
646
|
+
preview(k) {
|
|
647
|
+
const now = performance.now();
|
|
648
|
+
this.pv = k || null;
|
|
649
|
+
this.releaseClips(now, false);
|
|
650
|
+
this.nextAct = k ? now + 250 : now + 0.5 * this.actGap();
|
|
651
|
+
}
|
|
652
|
+
box() {
|
|
653
|
+
if (!this.rect || this.rectE !== this.rt.rectEpoch || this.rectDirty) {
|
|
654
|
+
this.rect = this.svg.getBoundingClientRect();
|
|
655
|
+
this.rectE = this.rt.rectEpoch;
|
|
656
|
+
this.rectDirty = false;
|
|
657
|
+
}
|
|
658
|
+
const r = this.rect;
|
|
659
|
+
return {
|
|
660
|
+
x: r.left + r.width / 2,
|
|
661
|
+
y: r.top + r.height / 2
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
lookDir() {
|
|
665
|
+
const ps = (this.peers || []).filter((p)=>p !== this && p.svg.isConnected);
|
|
666
|
+
if (ps.length) {
|
|
667
|
+
const me = this.box();
|
|
668
|
+
const near = ps.map((p)=>{
|
|
669
|
+
const b = p.box();
|
|
670
|
+
return {
|
|
671
|
+
dx: b.x - me.x,
|
|
672
|
+
dy: b.y - me.y
|
|
673
|
+
};
|
|
674
|
+
}).sort((a, b)=>Math.hypot(a.dx, a.dy) - Math.hypot(b.dx, b.dy)).slice(0, 2);
|
|
675
|
+
const q = near[this.r2() * near.length | 0];
|
|
676
|
+
const d = Math.hypot(q.dx, q.dy) || 1;
|
|
677
|
+
return {
|
|
678
|
+
gx: 0.78 * q.dx / d,
|
|
679
|
+
gy: 0.45 * q.dy / d
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
const s = this.r2() < 0.5 ? -1 : 1;
|
|
683
|
+
return {
|
|
684
|
+
gx: s * (0.6 + 0.2 * this.r2()),
|
|
685
|
+
gy: (this.r2() - 0.5) * 0.2
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
pick(now) {
|
|
689
|
+
const W = {
|
|
690
|
+
...ACT_W
|
|
691
|
+
};
|
|
692
|
+
if (!this.fid || !FIDDLE[this.fid.k]) W.prop = 0;
|
|
693
|
+
delete W[this.lastAct];
|
|
694
|
+
if (this.cover && 'stretch' in W && (this.reachN >= 3 || now - this.lastReach < 45000 || [
|
|
695
|
+
...this.rt.live
|
|
696
|
+
].some((c)=>c !== this && c.visible && c.clips.some((k)=>'reach' === k.kind && !k.rel)))) W.stretch = 0;
|
|
697
|
+
let sum = 0;
|
|
698
|
+
for(const k in W)sum += W[k];
|
|
699
|
+
let x = this.r2() * sum;
|
|
700
|
+
for(const k in W){
|
|
701
|
+
x -= W[k];
|
|
702
|
+
if (x <= 0) return k;
|
|
703
|
+
}
|
|
704
|
+
return 'look';
|
|
705
|
+
}
|
|
706
|
+
play(kind, now) {
|
|
707
|
+
let keys;
|
|
708
|
+
let gaze = false;
|
|
709
|
+
let fast = false;
|
|
710
|
+
const s = this.r2() < 0.5 ? -1 : 1;
|
|
711
|
+
if ('bored' === kind) keys = ACTS.bored();
|
|
712
|
+
else if ('fidget' === kind) {
|
|
713
|
+
fast = this.r2() >= 0.6;
|
|
714
|
+
keys = fast ? ACTS.shuffle(s) : ACTS.lean(s);
|
|
715
|
+
} else if ('stretch' === kind && this.cover) {
|
|
716
|
+
keys = ACTS.reach(0.7 * (this.covY - this.covT));
|
|
717
|
+
gaze = true;
|
|
718
|
+
fast = true;
|
|
719
|
+
if (!this.pv) {
|
|
720
|
+
this.reachN++;
|
|
721
|
+
this.lastReach = now;
|
|
722
|
+
}
|
|
723
|
+
} else if ('stretch' === kind) keys = ACTS.stretch();
|
|
724
|
+
else if ('prop' === kind) {
|
|
725
|
+
const f = this.fid && FIDDLE[this.fid.k];
|
|
726
|
+
if (!f || !this.fid) return 0;
|
|
727
|
+
keys = f;
|
|
728
|
+
gaze = keys.some((k)=>k[5] && ('gx' in k[5] || 'gy' in k[5]));
|
|
729
|
+
fast = FAST.has(this.fid.k);
|
|
730
|
+
} else {
|
|
731
|
+
const g = this.lookDir();
|
|
732
|
+
const L = 1.2 * g.gx;
|
|
733
|
+
keys = this.r2() < 0.35 ? ACTS.take(g, L) : ACTS.look(g, L);
|
|
734
|
+
gaze = true;
|
|
735
|
+
if (this.r2() < 0.5 && !this.blink) this.startBlink(now);
|
|
736
|
+
}
|
|
737
|
+
if (gaze) {
|
|
738
|
+
this.gx.p = this.gy.p = P_DART;
|
|
739
|
+
this.gx.t = 0;
|
|
740
|
+
this.gy.t = this.targets(this.st).gy;
|
|
741
|
+
}
|
|
742
|
+
const dur = keys[keys.length - 1][0];
|
|
743
|
+
this.clips.push({
|
|
744
|
+
act: 1,
|
|
745
|
+
kind: 'stretch' === kind && this.cover ? 'reach' : kind,
|
|
746
|
+
gaze,
|
|
747
|
+
slow: !fast,
|
|
748
|
+
t0: now,
|
|
749
|
+
keys
|
|
750
|
+
});
|
|
751
|
+
this.lastAct = kind;
|
|
752
|
+
this.rt.act.last = now;
|
|
753
|
+
this.nextGlance = Math.max(this.nextGlance, now + dur + 300);
|
|
754
|
+
return dur;
|
|
755
|
+
}
|
|
756
|
+
actTick(now) {
|
|
757
|
+
const cur = this.clips.find((c)=>c.act && !c.rel);
|
|
758
|
+
if (cur) return !!cur.gaze;
|
|
759
|
+
if (!this.repOn() || now < this.nextAct) return false;
|
|
760
|
+
if (!this.pv) {
|
|
761
|
+
let n = 0;
|
|
762
|
+
for (const c of this.rt.live)if (c !== this && c.visible && c.clips.some((k)=>k.act && !k.rel)) n++;
|
|
763
|
+
if (n >= this.rt.act.cap || now - this.rt.act.last < 700) {
|
|
764
|
+
this.nextAct = now + 500 + 900 * this.r2();
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const dur = this.play(this.pv || this.pick(now), now);
|
|
769
|
+
this.nextAct = now + dur + (this.pv ? 900 : this.actGap());
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
startLanding(now, prev) {
|
|
773
|
+
this.requestVeil();
|
|
774
|
+
const fy = 'invite' === prev ? 0 : this.floatY(now);
|
|
775
|
+
this.land = {
|
|
776
|
+
t0: now,
|
|
777
|
+
fy,
|
|
778
|
+
op0: this.figOp,
|
|
779
|
+
sk0: 'invite' === prev ? 1 : 0.35
|
|
780
|
+
};
|
|
781
|
+
this.wt.float.t = 0;
|
|
782
|
+
this.wt.float.x = 0;
|
|
783
|
+
}
|
|
784
|
+
floatY(now) {
|
|
785
|
+
return -8 + 4 * Math.sin((now + this.phase) / 3600 * 2 * Math.PI);
|
|
786
|
+
}
|
|
787
|
+
setState(st) {
|
|
788
|
+
if (this.land) {
|
|
789
|
+
this.land.next = 'power' === st ? null : st;
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
const now = performance.now();
|
|
793
|
+
if (st === this.st && 'power' !== st) return;
|
|
794
|
+
this.clear(this.doneT);
|
|
795
|
+
this.applyState(st, now);
|
|
796
|
+
if (!this.isLive()) this.render(now);
|
|
797
|
+
}
|
|
798
|
+
life(now) {
|
|
799
|
+
if (this.hl && !this.hl.arc && now - this.hl.t0 >= 260) {
|
|
800
|
+
this.hl.arc = true;
|
|
801
|
+
this.setTargets(this.targets('hello'), true);
|
|
802
|
+
}
|
|
803
|
+
if ('failed' === this.st && this.nextBeat && now >= this.nextBeat) {
|
|
804
|
+
this.beat(now);
|
|
805
|
+
this.nextBeat = now + 2500 + 1500 * this.r2();
|
|
806
|
+
}
|
|
807
|
+
const owns = 'idle' === this.st ? this.actTick(now) : 'invite' === this.st ? this.invTick(now) : false;
|
|
808
|
+
const st = this.st;
|
|
809
|
+
if ('off' === st || 'box' === st || 'power' === st) {
|
|
810
|
+
if ('off' === st) {
|
|
811
|
+
const b = 0.11 + 0.03 * Math.sin(now / 1000);
|
|
812
|
+
this.E.bright.t = b;
|
|
813
|
+
}
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
const med = 'working' === st ? 7000 : 'needs' === st ? 2400 : 'invite' === st ? 4000 : 3200;
|
|
817
|
+
const ip = 'invite' === st && this.clips.some((c)=>c.inv && !c.rel);
|
|
818
|
+
if (now >= this.nextBlink && !this.blink && !ip && 'working' !== st && 'hello' !== st) {
|
|
819
|
+
this.startBlink(now);
|
|
820
|
+
this.nextBlink = now + logn(this.r, med * this.rate, 0.5, 700, 10000);
|
|
821
|
+
if (this.r() < 0.12) this.dbl = now + 90 + 60 * this.r() + 250;
|
|
822
|
+
}
|
|
823
|
+
if (this.dbl && now >= this.dbl && !this.blink && !ip) {
|
|
824
|
+
this.startBlink(now);
|
|
825
|
+
this.dbl = 0;
|
|
826
|
+
}
|
|
827
|
+
if ('invite' === st) {
|
|
828
|
+
if (!owns) {
|
|
829
|
+
this.cueDir(now);
|
|
830
|
+
this.gx.p = this.gy.p = P_PURSUIT;
|
|
831
|
+
this.gx.t = 0;
|
|
832
|
+
this.gy.t = 0;
|
|
833
|
+
}
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
if ('working' === st) {
|
|
837
|
+
if (!this.read) this.read = {
|
|
838
|
+
step: 0,
|
|
839
|
+
steps: 3 + (3 * this.r() | 0),
|
|
840
|
+
line: 0,
|
|
841
|
+
next: now + 200
|
|
842
|
+
};
|
|
843
|
+
const R = this.read;
|
|
844
|
+
if (now >= R.next) if (R.step < R.steps) {
|
|
845
|
+
this.gx.p = this.gy.p = P_DART;
|
|
846
|
+
this.gx.t = -0.5 + 0.32 * R.step;
|
|
847
|
+
this.gy.t = -0.12 + 0.09 * R.line;
|
|
848
|
+
R.step++;
|
|
849
|
+
R.next = now + 180 + 140 * this.r();
|
|
850
|
+
} else {
|
|
851
|
+
this.gx.t = -0.5;
|
|
852
|
+
R.line = (R.line + 1) % 3;
|
|
853
|
+
this.gy.t = -0.12 + 0.09 * R.line;
|
|
854
|
+
R.step = 0;
|
|
855
|
+
R.steps = 3 + (3 * this.r() | 0);
|
|
856
|
+
R.next = now + 260;
|
|
857
|
+
this.startBlink(now, 170);
|
|
858
|
+
}
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
if ('needs' === st) {
|
|
862
|
+
this.gx.p = this.gy.p = P_PURSUIT;
|
|
863
|
+
this.gx.t = 0;
|
|
864
|
+
this.gy.t = 0;
|
|
865
|
+
if (this.nextHop && now >= this.nextHop) {
|
|
866
|
+
this.hop(now, 10);
|
|
867
|
+
this.nextHop = now + logn(this.r, 4500, 0.3, 2800, 8000);
|
|
868
|
+
}
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if ('idle' === st && now >= this.nextGlance) {
|
|
872
|
+
const p = this.r();
|
|
873
|
+
this.gx.p = this.gy.p = P_DART;
|
|
874
|
+
if (p < 0.55) {
|
|
875
|
+
this.gx.t = 0.5 * this.bias;
|
|
876
|
+
this.gy.t = 0;
|
|
877
|
+
this.nextGlance = now + logn(this.r, 1800, 0.6, 400, 6000);
|
|
878
|
+
} else {
|
|
879
|
+
const far = p > 0.85;
|
|
880
|
+
const A = far ? 0.5 + 0.4 * this.r() : 0.1 + 0.25 * this.r();
|
|
881
|
+
const ang = this.r() * Math.PI * 2;
|
|
882
|
+
this.gx.t = clamp(Math.cos(ang) * A + this.bias, -0.9, 0.9);
|
|
883
|
+
this.gy.t = clamp(Math.sin(ang) * A * 0.6, -0.5, 0.5);
|
|
884
|
+
if (A > 0.4 && this.r() < 0.25 && !this.blink) this.startBlink(now);
|
|
885
|
+
this.nextGlance = now + (far ? 600 + 800 * this.r() : logn(this.r, 1800, 0.6, 400, 6000));
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
tick(now, dt, beat = true) {
|
|
890
|
+
if (this.lt && now - this.lt > 500) {
|
|
891
|
+
this.nextAct = Math.max(this.nextAct, now + 1500 + 2500 * this.r2());
|
|
892
|
+
if (this.inv) this.inv.next = Math.max(this.inv.next, now + 1500 + 1000 * this.r2());
|
|
893
|
+
}
|
|
894
|
+
this.lt = now;
|
|
895
|
+
this.life(now);
|
|
896
|
+
for (const k of EYE_KEYS)stepS(this.E[k], dt);
|
|
897
|
+
stepS(this.gx, dt);
|
|
898
|
+
stepS(this.gy, dt);
|
|
899
|
+
stepS(this.sq, dt);
|
|
900
|
+
stepS(this.propScale, dt);
|
|
901
|
+
for(const k in this.wt)stepS(this.wt[k], dt);
|
|
902
|
+
if (this.cov) stepS(this.cov, dt);
|
|
903
|
+
if (beat || this.busy()) this.render(now);
|
|
904
|
+
}
|
|
905
|
+
busy() {
|
|
906
|
+
const st = this.st;
|
|
907
|
+
if (this.blink || this.land || this.flicker || this.clips.some((c)=>!c.slow)) return true;
|
|
908
|
+
if ('working' === st || 'box' === st || 'power' === st) return true;
|
|
909
|
+
if (this.pa && ('needs' === st || this.wt.work.x > 0.001)) return true;
|
|
910
|
+
const m = (s)=>Math.abs(s.v) > 1e-3 || Math.abs(s.x - s.t) > 1e-3;
|
|
911
|
+
for (const k of EYE_KEYS)if (m(this.E[k])) return true;
|
|
912
|
+
if (m(this.gx) || m(this.gy) || m(this.sq) || m(this.propScale)) return true;
|
|
913
|
+
for(const k in this.wt)if (m(this.wt[k])) return true;
|
|
914
|
+
if (this.cov && m(this.cov)) return true;
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
917
|
+
render(now) {
|
|
918
|
+
const live = this.isLive();
|
|
919
|
+
const E = {};
|
|
920
|
+
for (const k of EYE_KEYS)E[k] = this.E[k].x;
|
|
921
|
+
let open = 1;
|
|
922
|
+
if (this.blink) {
|
|
923
|
+
const u = (now - this.blink.t0) / this.blink.dur;
|
|
924
|
+
open = blinkOpen(u);
|
|
925
|
+
if (u > 1) this.blink = null;
|
|
926
|
+
}
|
|
927
|
+
let bright = E.bright;
|
|
928
|
+
let ty = 0;
|
|
929
|
+
let sy = 1;
|
|
930
|
+
let rot = 0;
|
|
931
|
+
let shadowK = 1;
|
|
932
|
+
let X = null;
|
|
933
|
+
if (live) {
|
|
934
|
+
const t = (now + this.phase) / 1000;
|
|
935
|
+
sy *= 1 + 0.012 * this.wt.breathe.x * Math.sin(2 * t * Math.PI / 3.2);
|
|
936
|
+
ty += -1.2 * this.wt.bob.x * (0.5 + 0.5 * Math.sin(2 * t * Math.PI / 2.4));
|
|
937
|
+
const fl = this.wt.float.x;
|
|
938
|
+
if (fl > 0.001) {
|
|
939
|
+
ty += fl * this.floatY(now);
|
|
940
|
+
rot += 1.5 * fl * Math.sin(2 * t * Math.PI / 5.1);
|
|
941
|
+
shadowK = lerp(1, 0.35, fl);
|
|
942
|
+
}
|
|
943
|
+
for(let i = this.clips.length - 1; i >= 0; i--){
|
|
944
|
+
const cl = this.clips[i];
|
|
945
|
+
const el = now - cl.t0;
|
|
946
|
+
const ks = cl.keys;
|
|
947
|
+
const last = ks[ks.length - 1][0];
|
|
948
|
+
if (el >= last) {
|
|
949
|
+
this.clips.splice(i, 1);
|
|
950
|
+
cl.onEnd?.(now);
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
let w = 1;
|
|
954
|
+
if (cl.rel) {
|
|
955
|
+
const u = (now - cl.rel) / (cl.relMs || 180);
|
|
956
|
+
if (u >= 1) {
|
|
957
|
+
this.clips.splice(i, 1);
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
w = 1 - E_INOUT(u);
|
|
961
|
+
}
|
|
962
|
+
let a = ks[0];
|
|
963
|
+
let b = ks[1];
|
|
964
|
+
for(let k = 1; k < ks.length; k++)if (el <= ks[k][0]) {
|
|
965
|
+
a = ks[k - 1];
|
|
966
|
+
b = ks[k];
|
|
967
|
+
break;
|
|
968
|
+
}
|
|
969
|
+
const e = (b[4] || cl.ease || E_INOUT)(clamp((el - a[0]) / Math.max(1, b[0] - a[0]), 0, 1));
|
|
970
|
+
if (1 === w) {
|
|
971
|
+
ty += lerp(a[1], b[1], e);
|
|
972
|
+
sy *= lerp(a[2], b[2], e);
|
|
973
|
+
rot += lerp(a[3] || 0, b[3] || 0, e);
|
|
974
|
+
} else {
|
|
975
|
+
ty += w * lerp(a[1], b[1], e);
|
|
976
|
+
sy *= 1 + w * (lerp(a[2], b[2], e) - 1);
|
|
977
|
+
rot += w * lerp(a[3] || 0, b[3] || 0, e);
|
|
978
|
+
}
|
|
979
|
+
if (a[5] || b[5]) {
|
|
980
|
+
X = X || {};
|
|
981
|
+
const xa = a[5] || NOX;
|
|
982
|
+
const xb = b[5] || NOX;
|
|
983
|
+
for(const k in b[5] || a[5]){
|
|
984
|
+
const key = k;
|
|
985
|
+
X[key] = (X[key] || 0) + w * lerp(xa[key] || 0, xb[key] || 0, e);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
if (this.land) {
|
|
990
|
+
const L = this.land;
|
|
991
|
+
const el = now - L.t0;
|
|
992
|
+
if (el < 180) ty += lerp(L.fy, L.fy - 6, E_INOUT(el / 180));
|
|
993
|
+
else if (el < 400) {
|
|
994
|
+
const u = E_GRAV((el - 180) / 220);
|
|
995
|
+
ty += lerp(L.fy - 6, 0, u);
|
|
996
|
+
sy *= lerp(1, 1.06, u);
|
|
997
|
+
}
|
|
998
|
+
if (el >= 400 && !L.hit) {
|
|
999
|
+
L.hit = true;
|
|
1000
|
+
this.sq.x = 0.82;
|
|
1001
|
+
this.sq.v = 0;
|
|
1002
|
+
this.sq.p = P_LAND;
|
|
1003
|
+
}
|
|
1004
|
+
shadowK = el < 400 ? L.sk0 : lerp(L.sk0, 1, clamp((el - 400) / 120, 0, 1));
|
|
1005
|
+
this.ghostT = E_FILL(clamp((el - 420) / 480, 0, 1));
|
|
1006
|
+
if (el >= 420 && !L.fill) {
|
|
1007
|
+
L.fill = true;
|
|
1008
|
+
this.svg.removeAttribute('data-veiled');
|
|
1009
|
+
}
|
|
1010
|
+
this.figOp = lerp(L.op0, 1, clamp((el - 400) / 300, 0, 1));
|
|
1011
|
+
if (el >= 800 && !L.eyes) {
|
|
1012
|
+
L.eyes = true;
|
|
1013
|
+
this.flicker = now;
|
|
1014
|
+
this.setTargets(this.targets('idle'), true);
|
|
1015
|
+
}
|
|
1016
|
+
if (el >= 950 && !L.props) {
|
|
1017
|
+
L.props = true;
|
|
1018
|
+
this.propScale.t = 1;
|
|
1019
|
+
this.propScale.p = P_POP;
|
|
1020
|
+
}
|
|
1021
|
+
if (el >= 1150) {
|
|
1022
|
+
const nx = L.next || 'idle';
|
|
1023
|
+
this.land = null;
|
|
1024
|
+
this.st = 'power';
|
|
1025
|
+
this.applyState(nx, now);
|
|
1026
|
+
this.startBlink(now);
|
|
1027
|
+
this.emit(nx, 'power');
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (this.flicker) {
|
|
1031
|
+
const el = now - this.flicker;
|
|
1032
|
+
const seq = [
|
|
1033
|
+
[
|
|
1034
|
+
0,
|
|
1035
|
+
0
|
|
1036
|
+
],
|
|
1037
|
+
[
|
|
1038
|
+
40,
|
|
1039
|
+
0.8
|
|
1040
|
+
],
|
|
1041
|
+
[
|
|
1042
|
+
100,
|
|
1043
|
+
0.1
|
|
1044
|
+
],
|
|
1045
|
+
[
|
|
1046
|
+
140,
|
|
1047
|
+
1
|
|
1048
|
+
],
|
|
1049
|
+
[
|
|
1050
|
+
190,
|
|
1051
|
+
0.3
|
|
1052
|
+
],
|
|
1053
|
+
[
|
|
1054
|
+
240,
|
|
1055
|
+
1
|
|
1056
|
+
]
|
|
1057
|
+
];
|
|
1058
|
+
if (el > 240) this.flicker = null;
|
|
1059
|
+
else {
|
|
1060
|
+
let v = 1;
|
|
1061
|
+
for(let k = 1; k < seq.length; k++){
|
|
1062
|
+
const [t1, v1] = seq[k];
|
|
1063
|
+
const [t0, v0] = seq[k - 1];
|
|
1064
|
+
if (el <= t1) {
|
|
1065
|
+
v = lerp(v0, v1, (el - t0) / (t1 - t0));
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
bright = v * E.bright;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
sy *= this.sq.x;
|
|
1073
|
+
} else if ('box' === this.st) {
|
|
1074
|
+
ty = -8;
|
|
1075
|
+
shadowK = 0.35;
|
|
1076
|
+
}
|
|
1077
|
+
const tt = (now + this.phase) / 1000;
|
|
1078
|
+
const dw = 'off' === this.st ? this.wt.breathe.x : 1;
|
|
1079
|
+
let gx = this.gx.x + (live ? dw * (0.02 * Math.sin(2.1 * tt) + 0.012 * Math.sin(3.7 * tt)) : 0);
|
|
1080
|
+
let gy = this.gy.x + (live ? 0.015 * dw * Math.sin(1.7 * tt) : 0);
|
|
1081
|
+
if (X) {
|
|
1082
|
+
gx = clamp(gx + (X.gx || 0), -0.95, 0.95);
|
|
1083
|
+
gy = clamp(gy + (X.gy || 0), -0.6, 0.7);
|
|
1084
|
+
if (X.lid) E.lid = clamp(E.lid + X.lid, 0, 0.85);
|
|
1085
|
+
if (X.op) open = clamp(open + X.op, 0.04, 1.04);
|
|
1086
|
+
if (X.br) bright += X.br;
|
|
1087
|
+
}
|
|
1088
|
+
const d = eyesPath(this.S, E, open, gx, gy);
|
|
1089
|
+
if (d !== this.lastD) {
|
|
1090
|
+
this.ef.setAttribute('d', d);
|
|
1091
|
+
this.eg.setAttribute('d', d);
|
|
1092
|
+
this.lastD = d;
|
|
1093
|
+
}
|
|
1094
|
+
const bo = r2(clamp(bright, 0, 1.2));
|
|
1095
|
+
if (bo !== this.lastB) {
|
|
1096
|
+
this.eyes.setAttribute('opacity', String(bo));
|
|
1097
|
+
this.vglow.setAttribute('opacity', String(r2(0.8 * bo)));
|
|
1098
|
+
this.lastB = bo;
|
|
1099
|
+
}
|
|
1100
|
+
const sx = 1 + (1 - sy) * 0.7;
|
|
1101
|
+
const tr = `translate(60 ${r2(108 + ty)}) rotate(${r2(rot)}) scale(${r2(1000 * sx) / 1000} ${r2(1000 * sy) / 1000}) translate(-60 -108)`;
|
|
1102
|
+
if (tr !== this.lastT) {
|
|
1103
|
+
this.fig.setAttribute('transform', tr);
|
|
1104
|
+
this.lastT = tr;
|
|
1105
|
+
}
|
|
1106
|
+
const fo = r2(this.figOp);
|
|
1107
|
+
if (fo !== this.lastFo) {
|
|
1108
|
+
this.fig.setAttribute('opacity', String(fo));
|
|
1109
|
+
this.lastFo = fo;
|
|
1110
|
+
}
|
|
1111
|
+
if (this.veilr) {
|
|
1112
|
+
let h;
|
|
1113
|
+
if (this.cover && !this.land && 'off' !== this.st) {
|
|
1114
|
+
let y = this.covY + this.cov.x + (X?.cv || 0);
|
|
1115
|
+
if (!this.topping) y = Math.max(y, this.covT + 0.2 * (this.covY - this.covT));
|
|
1116
|
+
h = r2(y + 30);
|
|
1117
|
+
} else h = r2(140 * (1 - this.ghostT));
|
|
1118
|
+
if (h !== this.lastV) {
|
|
1119
|
+
this.veilr.setAttribute('height', String(Math.max(0, h)));
|
|
1120
|
+
this.lastV = h;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
if (this.sha && this.shc) {
|
|
1124
|
+
const hgt = clamp(-ty / 12, 0, 1);
|
|
1125
|
+
const cx = this.sha.getAttribute('cx');
|
|
1126
|
+
const kA = (1 - 0.2 * hgt) * shadowK;
|
|
1127
|
+
const kC = (1 - 0.45 * hgt) * shadowK;
|
|
1128
|
+
const ta = `translate(${cx} 108) scale(${r2(kA)} ${r2(kA)}) translate(${-Number(cx)} -108)`;
|
|
1129
|
+
const tc = `translate(${cx} 108) scale(${r2(kC)} 1) translate(${-Number(cx)} -108)`;
|
|
1130
|
+
if (ta !== this.lastSa) {
|
|
1131
|
+
this.sha.setAttribute('transform', ta);
|
|
1132
|
+
this.sha.setAttribute('opacity', String(r2(0.16 * (1 - 0.4 * hgt) * shadowK)));
|
|
1133
|
+
this.lastSa = ta;
|
|
1134
|
+
}
|
|
1135
|
+
if (tc !== this.lastSc) {
|
|
1136
|
+
this.shc.setAttribute('transform', tc);
|
|
1137
|
+
this.shc.setAttribute('opacity', String(r2(0.36 * (1 - 0.8 * hgt) * shadowK)));
|
|
1138
|
+
this.lastSc = tc;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (this.props) {
|
|
1142
|
+
const ps = r2(this.propScale.x);
|
|
1143
|
+
if (ps !== this.lastPs) {
|
|
1144
|
+
this.props.setAttribute('opacity', String(clamp(ps, 0, 1)));
|
|
1145
|
+
this.lastPs = ps;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
if (this.pa && live) {
|
|
1149
|
+
const w = this.wt.work.x + ('needs' === this.st ? 0.3 : 0);
|
|
1150
|
+
const t = (now + this.phase) / 1000;
|
|
1151
|
+
const a = this.pa.dataset.a;
|
|
1152
|
+
const px = this.pa.dataset.px;
|
|
1153
|
+
const py = this.pa.dataset.py;
|
|
1154
|
+
let ang = 0;
|
|
1155
|
+
if ('dish' === a) ang = 14 * w * Math.sin(2 * t * Math.PI / 1.5);
|
|
1156
|
+
else if ('sway' === a) ang = 7 * w * Math.sin(2 * t * Math.PI / 1.2);
|
|
1157
|
+
else if ('twitch' === a) ang = 5 * w * Math.sin(2 * t * Math.PI / 0.45);
|
|
1158
|
+
else if ('wave' === a) ang = 9 * w * Math.sin(2 * t * Math.PI / 0.8);
|
|
1159
|
+
else if ('wind' === a) ang = 0;
|
|
1160
|
+
else if ('rock' === a) ang = 2.5 * w * Math.sin(2 * t * Math.PI / 2.4);
|
|
1161
|
+
let sxk = 1;
|
|
1162
|
+
let sk = 1;
|
|
1163
|
+
if ('wind' === a && w > 0.001) {
|
|
1164
|
+
const c = Math.cos(2 * t * Math.PI / 1.6);
|
|
1165
|
+
sxk = 1 + w * ((c < 0 ? -1 : 1) * Math.max(0.14, Math.abs(c)) - 1);
|
|
1166
|
+
} else if ('focus' === a && w > 0.001) sk = 1 + 0.06 * w * (0.5 - 0.5 * Math.cos(2 * t * Math.PI / 1.5));
|
|
1167
|
+
const k3 = (v)=>Math.round(1000 * v) / 1000;
|
|
1168
|
+
const tr2 = 1 !== sxk ? `translate(${px} 0) scale(${k3(sxk)} 1) translate(${-Number(px)} 0)` : 1 !== sk ? `translate(${px} ${py}) scale(${k3(sk)}) translate(${-Number(px)} ${-Number(py)})` : `rotate(${r2(ang)} ${px} ${py})`;
|
|
1169
|
+
if (tr2 !== this.lastPa) {
|
|
1170
|
+
this.pa.setAttribute('transform', tr2);
|
|
1171
|
+
this.lastPa = tr2;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
if (this.props) {
|
|
1175
|
+
const pg = X ? propTr(X, this.fid) : '';
|
|
1176
|
+
if (pg !== this.lastPg) {
|
|
1177
|
+
if (pg) this.props.setAttribute('transform', pg);
|
|
1178
|
+
else this.props.removeAttribute('transform');
|
|
1179
|
+
this.lastPg = pg;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (this.beam) {
|
|
1183
|
+
const b = r2(0.55 * this.wt.work.x + (X?.bm ? X.bm : 0));
|
|
1184
|
+
if (b !== this.lastBeam) {
|
|
1185
|
+
this.beam.setAttribute('opacity', String(b));
|
|
1186
|
+
this.lastBeam = b;
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (this.glint && live) {
|
|
1190
|
+
const g = r2(0.25 + 0.7 * this.wt.work.x * (0.5 + 0.5 * Math.sin(now / 1000 * 2 * Math.PI / 1.5)));
|
|
1191
|
+
if (g !== this.lastGl) {
|
|
1192
|
+
this.glint.setAttribute('opacity', String(g));
|
|
1193
|
+
this.lastGl = g;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
if (this.stitch && live) {
|
|
1197
|
+
const so = r2(-12 * this.wt.work.x * (now / 1000 / 1.6 % 1));
|
|
1198
|
+
if (so !== this.lastSo) {
|
|
1199
|
+
this.stitch.setAttribute('stroke-dashoffset', String(so));
|
|
1200
|
+
this.lastSo = so;
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
dispose() {
|
|
1205
|
+
this.disposed = true;
|
|
1206
|
+
for (const id of this.timers)clearTimeout(id);
|
|
1207
|
+
this.timers.clear();
|
|
1208
|
+
this.rt.unregister(this);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
function createCharacter(svg, c, o) {
|
|
1212
|
+
const ch = new Character(svg, c, o);
|
|
1213
|
+
const P = c.prop && 'none' !== c.prop ? propOf(c.prop, ch.S, hexOf(c.color)) : null;
|
|
1214
|
+
ch.fid = P ? P.fid : null;
|
|
1215
|
+
if (o.cover) ch.setCover(true);
|
|
1216
|
+
else {
|
|
1217
|
+
const veil = svg.querySelector('[data-part~="veil"]');
|
|
1218
|
+
const visor = svg.querySelector('[data-part~="visor"]');
|
|
1219
|
+
if (veil && visor && veil.nextElementSibling !== visor) visor.before(veil);
|
|
1220
|
+
}
|
|
1221
|
+
const rt = getRuntime();
|
|
1222
|
+
if (o.live && rt.motionOn()) rt.register(ch);
|
|
1223
|
+
ch.render(performance.now());
|
|
1224
|
+
return ch;
|
|
1225
|
+
}
|
|
1226
|
+
function joinPeers(row, ch) {
|
|
1227
|
+
const sync = ()=>{
|
|
1228
|
+
const all = [
|
|
1229
|
+
...row
|
|
1230
|
+
];
|
|
1231
|
+
for (const o of row)o.peers = all;
|
|
1232
|
+
};
|
|
1233
|
+
row.add(ch);
|
|
1234
|
+
sync();
|
|
1235
|
+
return ()=>{
|
|
1236
|
+
row.delete(ch);
|
|
1237
|
+
ch.peers = null;
|
|
1238
|
+
sync();
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
export { Character, createCharacter, joinPeers };
|