@klex/mascot 0.6.0 → 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 CHANGED
@@ -97,7 +97,7 @@ Emotes, including jumps and shaking, scale down with the avatar. The ground is t
97
97
 
98
98
  `idle` defaults to `true`. Resting characters breathe gently, sway their heads, blink and occasionally glance around without changing their expression or position. Every instance has its own breathing pace and independently randomized blink and glance pauses. Each glance also varies in direction and duration. The idle pose fades out for travel and emotes, then returns automatically. Flying characters keep their hover. Use `idle={false}` for static avatars or long lists that do not need continuous animation.
99
99
 
100
- `activity` selects a persistent animation and defaults to `'idle'`. `'sleeping'` closes the eyes, lowers and tilts the head, and breathes slowly. `'calling'` holds a bundled Twemoji 📞 SVG against the head, mirrored toward the face and held by a small hand in the body color. A fixed graphic avoids platform-dependent emoji font shapes and baselines. The earpiece follows the deformed silhouette slightly above the eyes, including custom shapes. Each avatar alternates attentive listening, irregular conversational emphasis, and a friendly double nod, with natural blinks and pauses. These are ambient gestures, not speech detection; reduced motion keeps a static listening pose. No laptop is shown. `'working'` places a laptop in front of the character, with its back facing the viewer. Each avatar independently alternates between reading across successive lines, typing in irregular bursts, and looking up to think with a question mark overhead. Phase order, durations, and pauses are randomized anew throughout the animation. `'recalling'` shows a thought bubble with pulsing dots above the head. The character alternates quiet pondering toward the bubble, quick searching glances, and a short happy nod; these are ambient gestures and never claim a memory was found. `'learning'` holds an open book and writes into it with a pencil. Ink fills the right-hand page line by line in uneven bursts, the pen lifts while returning to the start of a line, and the character pauses to reread or think. A full page turns over and writing starts on a fresh page. Travel and emotes take precedence, then the latest activity resumes. `idle={false}` disables only the default idle animation; an explicit sleeping, working, calling, recalling or learning activity still runs.
100
+ `activity` selects a persistent animation and defaults to `'idle'`. `'sleeping'` closes the eyes, lowers and tilts the head, and breathes slowly. `'calling'` holds a bundled Twemoji 📞 SVG against the head, mirrored toward the face and held by a small hand in the body color. A fixed graphic avoids platform-dependent emoji font shapes and baselines. The earpiece follows the deformed silhouette slightly above the eyes, including custom shapes. Each avatar alternates attentive listening, irregular conversational emphasis, and a friendly double nod, with natural blinks and pauses. These are ambient gestures, not speech detection; reduced motion keeps a static listening pose. No laptop is shown. `'working'` places a laptop in front of the character, with its back facing the viewer. Each avatar independently alternates between reading across successive lines, typing in irregular bursts, and looking up to think with a question mark overhead. Phase order, durations, and pauses are randomized anew throughout the animation. `'recalling'` shows a thought bubble with pulsing dots above the head. The character alternates quiet pondering toward the bubble, quick searching glances, and a short happy nod; these are ambient gestures and never claim a memory was found. `'learning'` holds an open book and writes into it with a pencil. Ink fills the right-hand page line by line in uneven bursts, the pen lifts while returning to the start of a line, and the character pauses to reread or think. A full page turns over and writing starts on a fresh page. Travel and emotes take precedence, then the latest activity resumes. A changed activity blends in, so an awake avatar closes its eyes as it falls asleep; a freshly mounted one starts in its activity's pose, and held props still spring in. Pass `activityPending` while `activity` is only a placeholder for a status that is still loading: the first real activity shows at once as well. Once one has shown, every change blends, including a return to a placeholder. `idle={false}` disables only the default idle animation; an explicit sleeping, working, calling, recalling or learning activity still runs.
101
101
 
102
102
  ```tsx
103
103
  <Klex activity="sleeping" size={40} />
@@ -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 extra embeds the Twemoji v17.0.3 telephone receiver (U+1F4DE), © Twitter, Inc. and other contributors, licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) and included unchanged apart from its placement. See `LICENSE-TWEMOJI.txt`.
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.6.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;
@@ -153,6 +159,14 @@ export function createActivity() {
153
159
  laptop.snap(activity === 'working');
154
160
  book.snap(activity === 'learning');
155
161
  },
162
+ /**
163
+ * Takes an activity's pose at once; held props still spring in. Idle
164
+ * breathing starts from rest anyway, so it keeps its soft fade.
165
+ */
166
+ snapPose(activity: KlexActivity | false) {
167
+ for (const { id } of ACTIVITIES)
168
+ weights[id] = Number(activity === id && id !== 'idle');
169
+ },
156
170
  get workingBob() {
157
171
  const { laptopFloat, laptopTap } = working.pose();
158
172
  return (
@@ -190,6 +204,7 @@ export function createActivity() {
190
204
  if (activity === 'recalling') recalling.advance(dt);
191
205
  if (activity === 'learning') learning.advance(dt);
192
206
  if (activity === 'calling') calling.advance(dt);
207
+ if (activity === 'watching') watching.advance(dt);
193
208
  laptop.advance(dt, activity === 'working');
194
209
  book.advance(dt, activity === 'learning');
195
210
  idle.advance(dt, activity === 'idle');
@@ -210,6 +225,7 @@ export function createActivity() {
210
225
  const recallingPose = recalling.pose();
211
226
  const learningPose = learning.pose();
212
227
  const callingPose = calling.pose();
228
+ const watchingPose = watching.pose();
213
229
  const flying = activityPose('flying', time);
214
230
  const pose = { ...REST_EMOTE };
215
231
  for (const key of [
@@ -229,6 +245,7 @@ export function createActivity() {
229
245
  recallingPose[key] * weights.recalling +
230
246
  learningPose[key] * weights.learning +
231
247
  callingPose[key] * weights.calling +
248
+ watchingPose[key] * weights.watching +
232
249
  flying[key] * weights.flying;
233
250
  }
234
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
- <text
282
- x="-15"
283
- y="8"
284
- transform="scale(-1 1)"
285
- fontSize="30"
286
- style={{
287
- fontFamily:
288
- 'Apple Color Emoji, Segoe UI Emoji, Noto Color Emoji, sans-serif',
289
- }}
290
- >
291
- 👋
292
- </text>
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/glide.ts CHANGED
@@ -393,6 +393,10 @@ export function createGlide(
393
393
  let disposed = false;
394
394
  let height = flyingInitially ? 64 : 0;
395
395
  let activity: KlexActivity | false = false;
396
+ // Until a real activity has shown, the rig takes each pose at once, so it
397
+ // never animates out of its mount or a loading placeholder. Afterwards every
398
+ // change blends, e.g. eyes closing to sleep, including back to a placeholder.
399
+ let activityShown = false;
396
400
  const activityMotion = createActivity();
397
401
  let emote: { action: Emote; time: number } | null = null;
398
402
  let lastLook: EmoteLook = {};
@@ -958,6 +962,7 @@ export function createGlide(
958
962
  nextScale = 1,
959
963
  nextIdle = false,
960
964
  nextActivity: KlexActivity = 'idle',
965
+ activityPending = false,
961
966
  ) {
962
967
  hand = eyes.querySelector('[data-wave-anchor]');
963
968
  phone = eyes.querySelector('[data-phone-anchor]');
@@ -966,7 +971,12 @@ export function createGlide(
966
971
  settings = next;
967
972
  reducedMotion = reduced;
968
973
  activity = nextActivity === 'idle' && !nextIdle ? false : nextActivity;
974
+ if (!activityShown)
975
+ activityMotion.snapPose(
976
+ !busy && !transitioning && !emote ? activity : false,
977
+ );
969
978
  if (reduced) activityMotion.snapProps(activity);
979
+ if (!activityPending) activityShown = true;
970
980
  if (reduced && emote) {
971
981
  emote = null;
972
982
  onEmoteComplete();
package/src/klex.tsx CHANGED
@@ -94,8 +94,17 @@ export type KlexProps = {
94
94
  size?: number;
95
95
  /** Disable the default idle animation. Sleeping and working still animate. */
96
96
  idle?: boolean;
97
- /** Persistent resting animation. Resumes after travel and emotes. */
97
+ /**
98
+ * Persistent resting animation. Resumes after travel and emotes. A change
99
+ * blends in, e.g. eyes close to sleep; on mount it shows at once.
100
+ */
98
101
  activity?: KlexActivity;
102
+ /**
103
+ * Marks `activity` as a placeholder while the real one loads on mount. The
104
+ * first real activity shows at once instead of blending in; once one has
105
+ * shown, every change blends, including back to a placeholder.
106
+ */
107
+ activityPending?: boolean;
99
108
  /** Total track width. Defaults to size for a stationary avatar. */
100
109
  width?: CSSProperties['width'];
101
110
  /** Initial track position. Y is a pixel offset from the ground line. */
@@ -143,6 +152,7 @@ export function Klex({
143
152
  size = 160,
144
153
  idle = true,
145
154
  activity = 'idle',
155
+ activityPending = false,
146
156
  width = size,
147
157
  initialPosition,
148
158
  layout = 'track',
@@ -235,6 +245,7 @@ export function Klex({
235
245
  scale,
236
246
  idle,
237
247
  activity,
248
+ activityPending,
238
249
  );
239
250
  });
240
251
 
@@ -307,6 +318,7 @@ export function Klex({
307
318
  scale,
308
319
  idle,
309
320
  activity,
321
+ activityPending,
310
322
  );
311
323
  }, [
312
324
  reducedMotion,
@@ -314,6 +326,7 @@ export function Klex({
314
326
  scale,
315
327
  idle,
316
328
  activity,
329
+ activityPending,
317
330
  reactionLook.extra,
318
331
  extra,
319
332
  extrasEnabled,
@@ -334,6 +347,7 @@ export function Klex({
334
347
  scale,
335
348
  idle,
336
349
  activity,
350
+ activityPending,
337
351
  );
338
352
  }
339
353
  motion.moveTo(target === 'left' ? -50 : target === 'right' ? 50 : target);
@@ -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
+ }