@klex/mascot 0.6.1 → 0.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/README.md +1 -1
- package/package.json +2 -1
- package/src/activity.ts +9 -0
- package/src/extras.tsx +16 -12
- package/src/watching.ts +50 -0
package/README.md
CHANGED
|
@@ -173,4 +173,4 @@ The component respects the system's reduced-motion preference: idle and emotes a
|
|
|
173
173
|
|
|
174
174
|
## License
|
|
175
175
|
|
|
176
|
-
MIT. The phone
|
|
176
|
+
MIT. The phone and wave extras embed the Twemoji v17.0.3 telephone receiver (U+1F4DE) and waving hand (U+1F44B), © Twitter, Inc. and other contributors, licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) and included unchanged apart from their placement. See `LICENSE-TWEMOJI.txt`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klex/mascot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The animated Klex mascot: a React component, its GSAP motion engine, body presets, and SVG helpers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT AND CC-BY-4.0",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": "./src/index.ts",
|
|
22
22
|
"./glide": "./src/glide.ts",
|
|
23
|
+
"./presets": "./src/presets.ts",
|
|
23
24
|
"./svg": "./src/svg.ts"
|
|
24
25
|
},
|
|
25
26
|
"repository": {
|
package/src/activity.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { REST_EMOTE } from './emotes';
|
|
|
5
5
|
import { createIdle } from './idle';
|
|
6
6
|
import { createLearning } from './learning';
|
|
7
7
|
import { createRecalling } from './recalling';
|
|
8
|
+
import { createWatching } from './watching';
|
|
8
9
|
import { createWorking } from './working';
|
|
9
10
|
|
|
10
11
|
export const ACTIVITIES = [
|
|
@@ -14,6 +15,7 @@ export const ACTIVITIES = [
|
|
|
14
15
|
{ id: 'recalling', name: 'Recalling' },
|
|
15
16
|
{ id: 'learning', name: 'Learning' },
|
|
16
17
|
{ id: 'calling', name: 'On a call' },
|
|
18
|
+
{ id: 'watching', name: 'Watching' },
|
|
17
19
|
{ id: 'flying', name: 'Flying up' },
|
|
18
20
|
] as const;
|
|
19
21
|
export type KlexActivity = (typeof ACTIVITIES)[number]['id'];
|
|
@@ -66,6 +68,8 @@ function activityPose(activity: KlexActivity | false, time: number) {
|
|
|
66
68
|
headSway: 1.5 * Math.sin(phase * 3),
|
|
67
69
|
lookY: -7,
|
|
68
70
|
};
|
|
71
|
+
if (activity === 'watching')
|
|
72
|
+
return { ...REST_EMOTE, headTilt: 3, nod: 0.08, lookX: 9 };
|
|
69
73
|
if (activity === 'calling')
|
|
70
74
|
return {
|
|
71
75
|
...REST_EMOTE,
|
|
@@ -122,6 +126,7 @@ export function createActivity() {
|
|
|
122
126
|
const recalling = createRecalling();
|
|
123
127
|
const learning = createLearning();
|
|
124
128
|
const calling = createCalling();
|
|
129
|
+
const watching = createWatching();
|
|
125
130
|
const weights = {
|
|
126
131
|
idle: 0,
|
|
127
132
|
sleeping: 0,
|
|
@@ -129,6 +134,7 @@ export function createActivity() {
|
|
|
129
134
|
recalling: 0,
|
|
130
135
|
learning: 0,
|
|
131
136
|
calling: 0,
|
|
137
|
+
watching: 0,
|
|
132
138
|
flying: 0,
|
|
133
139
|
};
|
|
134
140
|
let time = Math.random() * 6;
|
|
@@ -198,6 +204,7 @@ export function createActivity() {
|
|
|
198
204
|
if (activity === 'recalling') recalling.advance(dt);
|
|
199
205
|
if (activity === 'learning') learning.advance(dt);
|
|
200
206
|
if (activity === 'calling') calling.advance(dt);
|
|
207
|
+
if (activity === 'watching') watching.advance(dt);
|
|
201
208
|
laptop.advance(dt, activity === 'working');
|
|
202
209
|
book.advance(dt, activity === 'learning');
|
|
203
210
|
idle.advance(dt, activity === 'idle');
|
|
@@ -218,6 +225,7 @@ export function createActivity() {
|
|
|
218
225
|
const recallingPose = recalling.pose();
|
|
219
226
|
const learningPose = learning.pose();
|
|
220
227
|
const callingPose = calling.pose();
|
|
228
|
+
const watchingPose = watching.pose();
|
|
221
229
|
const flying = activityPose('flying', time);
|
|
222
230
|
const pose = { ...REST_EMOTE };
|
|
223
231
|
for (const key of [
|
|
@@ -237,6 +245,7 @@ export function createActivity() {
|
|
|
237
245
|
recallingPose[key] * weights.recalling +
|
|
238
246
|
learningPose[key] * weights.learning +
|
|
239
247
|
callingPose[key] * weights.calling +
|
|
248
|
+
watchingPose[key] * weights.watching +
|
|
240
249
|
flying[key] * weights.flying;
|
|
241
250
|
}
|
|
242
251
|
return pose;
|
package/src/extras.tsx
CHANGED
|
@@ -278,18 +278,22 @@ function WaveHand({
|
|
|
278
278
|
}, [paused, reducedMotion, transient]);
|
|
279
279
|
return (
|
|
280
280
|
<g ref={scope} style={{ transformOrigin: '0px 8px' }}>
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
281
|
+
{/* Twemoji v17.0.3 waving hand (U+1F44B), © Twitter, Inc. and other contributors, CC BY 4.0. Source: https://github.com/jdecked/twemoji/blob/v17.0.3/assets/svg/1f44b.svg. See LICENSE-TWEMOJI.txt. */}
|
|
282
|
+
<g transform="scale(-1 1) translate(-15 -21) scale(0.8333)">
|
|
283
|
+
<path
|
|
284
|
+
fill="#EF9645"
|
|
285
|
+
d="M4.861 9.147c.94-.657 2.357-.531 3.201.166l-.968-1.407c-.779-1.111-.5-2.313.612-3.093 1.112-.777 4.263 1.312 4.263 1.312-.786-1.122-.639-2.544.483-3.331 1.122-.784 2.67-.513 3.456.611l10.42 14.72L25 31l-11.083-4.042L4.25 12.625c-.793-1.129-.519-2.686.611-3.478z"
|
|
286
|
+
/>
|
|
287
|
+
<path
|
|
288
|
+
fill="#FFDC5D"
|
|
289
|
+
d="M2.695 17.336s-1.132-1.65.519-2.781c1.649-1.131 2.78.518 2.78.518l5.251 7.658c.181-.302.379-.6.6-.894L4.557 11.21s-1.131-1.649.519-2.78c1.649-1.131 2.78.518 2.78.518l6.855 9.997c.255-.208.516-.417.785-.622L7.549 6.732s-1.131-1.649.519-2.78c1.649-1.131 2.78.518 2.78.518l7.947 11.589c.292-.179.581-.334.871-.498L12.238 4.729s-1.131-1.649.518-2.78c1.649-1.131 2.78.518 2.78.518l7.854 11.454 1.194 1.742c-4.948 3.394-5.419 9.779-2.592 13.902.565.825 1.39.26 1.39.26-3.393-4.949-2.357-10.51 2.592-13.903L24.515 8.62s-.545-1.924 1.378-2.47c1.924-.545 2.47 1.379 2.47 1.379l1.685 5.004c.668 1.984 1.379 3.961 2.32 5.831 2.657 5.28 1.07 11.842-3.94 15.279-5.465 3.747-12.936 2.354-16.684-3.11L2.695 17.336z"
|
|
290
|
+
/>
|
|
291
|
+
<g fill="#5DADEC">
|
|
292
|
+
<path d="M12 32.042C8 32.042 3.958 28 3.958 24c0-.553-.405-1-.958-1s-1.042.447-1.042 1C1.958 30 6 34.042 12 34.042c.553 0 1-.489 1-1.042s-.447-.958-1-.958z" />
|
|
293
|
+
<path d="M7 34c-3 0-5-2-5-5 0-.553-.447-1-1-1s-1 .447-1 1c0 4 3 7 7 7 .553 0 1-.447 1-1s-.447-1-1-1zM24 2c-.552 0-1 .448-1 1s.448 1 1 1c4 0 8 3.589 8 8 0 .552.448 1 1 1s1-.448 1-1c0-5.514-4-10-10-10z" />
|
|
294
|
+
<path d="M29 .042c-.552 0-1 .406-1 .958s.448 1.042 1 1.042c3 0 4.958 2.225 4.958 4.958 0 .552.489 1 1.042 1s.958-.448.958-1C35.958 3.163 33 .042 29 .042z" />
|
|
295
|
+
</g>
|
|
296
|
+
</g>
|
|
293
297
|
</g>
|
|
294
298
|
);
|
|
295
299
|
}
|
package/src/watching.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { emotePose } from './emotes';
|
|
2
|
+
|
|
3
|
+
const between = (min: number, max: number) => min + Math.random() * (max - min);
|
|
4
|
+
|
|
5
|
+
// Hosts place what Klex watches to its right. The gaze holds on one spot,
|
|
6
|
+
// then jumps to the next like a reader's eyes, often blinking after the jump.
|
|
7
|
+
export function createWatching() {
|
|
8
|
+
let holdIn = between(1.2, 3.2);
|
|
9
|
+
let blinkIn = between(2.5, 5);
|
|
10
|
+
let blinkTime = Infinity;
|
|
11
|
+
let target = { lookX: 9, lookY: 0 };
|
|
12
|
+
const pose = {
|
|
13
|
+
compression: 0.012,
|
|
14
|
+
headTilt: 3,
|
|
15
|
+
headSway: 0.6,
|
|
16
|
+
nod: 0.08,
|
|
17
|
+
lookX: 9,
|
|
18
|
+
lookY: 0,
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
advance(dt: number) {
|
|
22
|
+
holdIn -= dt;
|
|
23
|
+
blinkIn -= dt;
|
|
24
|
+
blinkTime += dt;
|
|
25
|
+
if (holdIn <= 0) {
|
|
26
|
+
holdIn = between(1.2, 3.4);
|
|
27
|
+
target = {
|
|
28
|
+
lookX: between(8, 11),
|
|
29
|
+
lookY: target.lookY > 0 ? between(-3.2, 0.5) : between(-0.5, 3.2),
|
|
30
|
+
};
|
|
31
|
+
if (Math.random() < 0.45) blinkIn = between(0.05, 0.15);
|
|
32
|
+
}
|
|
33
|
+
if (blinkIn <= 0) {
|
|
34
|
+
blinkTime = 0;
|
|
35
|
+
blinkIn = between(2.5, 5.5);
|
|
36
|
+
}
|
|
37
|
+
const glance = 1 - Math.exp(-18 * dt);
|
|
38
|
+
pose.lookX += (target.lookX - pose.lookX) * glance;
|
|
39
|
+
pose.lookY += (target.lookY - pose.lookY) * glance;
|
|
40
|
+
// The head trails the eyes, so a jump reads as attention, not a twitch.
|
|
41
|
+
const head = 1 - Math.exp(-3 * dt);
|
|
42
|
+
pose.headTilt += (2 + target.lookY * 0.6 - pose.headTilt) * head;
|
|
43
|
+
pose.nod += (0.08 + target.lookY * 0.04 - pose.nod) * head;
|
|
44
|
+
},
|
|
45
|
+
pose() {
|
|
46
|
+
const blink = emotePose('blink', blinkTime / 0.3).blinkLeft;
|
|
47
|
+
return { ...pose, blinkLeft: blink, blinkRight: blink };
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}
|