@oxy.so/bloom 19.10.2 → 19.11.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/docs/adoption-matrix.mdx +8 -8
- package/docs/agent-avatar.mdx +22 -0
- package/docs/empty-state.mdx +20 -1
- package/docs/task-catalog.json +1 -1
- package/docs/task-catalog.mdx +1 -1
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js +36 -17
- package/lib/commonjs/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/commonjs/agent-avatar/vector-mood.js +129 -0
- package/lib/commonjs/agent-avatar/vector-mood.js.map +1 -0
- package/lib/commonjs/empty-state/constants.js +2 -0
- package/lib/commonjs/empty-state/constants.js.map +1 -1
- package/lib/commonjs/tooltip/TextBubble.js +25 -14
- package/lib/commonjs/tooltip/TextBubble.js.map +1 -1
- package/lib/commonjs/tooltip/Tooltip.web.js +33 -25
- package/lib/commonjs/tooltip/Tooltip.web.js.map +1 -1
- package/lib/module/agent-avatar/VectorCharacterAvatar.js +36 -17
- package/lib/module/agent-avatar/VectorCharacterAvatar.js.map +1 -1
- package/lib/module/agent-avatar/vector-mood.js +117 -0
- package/lib/module/agent-avatar/vector-mood.js.map +1 -0
- package/lib/module/empty-state/constants.js +2 -0
- package/lib/module/empty-state/constants.js.map +1 -1
- package/lib/module/tooltip/TextBubble.js +25 -14
- package/lib/module/tooltip/TextBubble.js.map +1 -1
- package/lib/module/tooltip/Tooltip.web.js +33 -25
- package/lib/module/tooltip/Tooltip.web.js.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/index.d.ts +1 -1
- package/lib/typescript/commonjs/agent-avatar/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/types.d.ts +14 -0
- package/lib/typescript/commonjs/agent-avatar/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/agent-avatar/vector-mood.d.ts +61 -0
- package/lib/typescript/commonjs/agent-avatar/vector-mood.d.ts.map +1 -0
- package/lib/typescript/commonjs/empty-state/constants.d.ts +5 -0
- package/lib/typescript/commonjs/empty-state/constants.d.ts.map +1 -1
- package/lib/typescript/commonjs/tooltip/TextBubble.d.ts.map +1 -1
- package/lib/typescript/commonjs/tooltip/Tooltip.web.d.ts +4 -2
- package/lib/typescript/commonjs/tooltip/Tooltip.web.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/VectorCharacterAvatar.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/index.d.ts +1 -1
- package/lib/typescript/module/agent-avatar/index.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/types.d.ts +14 -0
- package/lib/typescript/module/agent-avatar/types.d.ts.map +1 -1
- package/lib/typescript/module/agent-avatar/vector-mood.d.ts +61 -0
- package/lib/typescript/module/agent-avatar/vector-mood.d.ts.map +1 -0
- package/lib/typescript/module/empty-state/constants.d.ts +5 -0
- package/lib/typescript/module/empty-state/constants.d.ts.map +1 -1
- package/lib/typescript/module/tooltip/TextBubble.d.ts.map +1 -1
- package/lib/typescript/module/tooltip/Tooltip.web.d.ts +4 -2
- package/lib/typescript/module/tooltip/Tooltip.web.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/agent-avatar/VectorCharacterAvatar.tsx +39 -10
- package/src/agent-avatar/index.ts +1 -1
- package/src/agent-avatar/types.ts +15 -0
- package/src/agent-avatar/vector-mood.ts +140 -0
- package/src/empty-state/constants.ts +7 -0
- package/src/tooltip/TextBubble.tsx +24 -11
- package/src/tooltip/Tooltip.web.tsx +37 -36
|
@@ -18,6 +18,14 @@ import { CHARACTER_COLORS } from './character-colors';
|
|
|
18
18
|
import { vectorWorkLook } from './vector-work-look';
|
|
19
19
|
import { sampleVectorPose, blendVectorPose, type VectorPose } from './vector-pose';
|
|
20
20
|
import { sampleVectorMotion, referenceWorkTime, type VectorMotionPose } from './vector-motion';
|
|
21
|
+
import {
|
|
22
|
+
advanceVectorMood,
|
|
23
|
+
initialVectorMood,
|
|
24
|
+
setVectorMood,
|
|
25
|
+
settleVectorMood,
|
|
26
|
+
vectorMoodActive,
|
|
27
|
+
vectorMoodFrame,
|
|
28
|
+
} from './vector-mood';
|
|
21
29
|
import {
|
|
22
30
|
useCallback,
|
|
23
31
|
useContext,
|
|
@@ -83,7 +91,7 @@ export function VectorCharacterAvatar(props: Props) {
|
|
|
83
91
|
return <AnimatedVectorCharacterAvatar {...props} />;
|
|
84
92
|
}
|
|
85
93
|
function AnimatedVectorCharacterAvatar(props: Props) {
|
|
86
|
-
const { character, size = 64, paused, portrait, interactive, previewPart } = props;
|
|
94
|
+
const { character, size = 64, paused, portrait, interactive, previewPart, mood } = props;
|
|
87
95
|
const { messages } = useMessages(AGENT_AVATAR_MESSAGES, props.locale);
|
|
88
96
|
const catalog = useVectorAssetLoader(props.catalog);
|
|
89
97
|
const reduced = usePrefersReducedMotion(),
|
|
@@ -166,13 +174,17 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
166
174
|
motionFrom: undefined as VectorMotionPose | undefined,
|
|
167
175
|
transitionStarted: 0,
|
|
168
176
|
transitionDuration: VECTOR_TRANSITION_SECONDS,
|
|
177
|
+
mood: initialVectorMood(mood),
|
|
169
178
|
});
|
|
170
179
|
const previous = useRef({
|
|
171
180
|
idle: props.idleKey,
|
|
172
181
|
reaction: props.reactionKey,
|
|
173
182
|
work: props.workingKey,
|
|
174
183
|
entrance: props.entranceKey,
|
|
184
|
+
mood,
|
|
175
185
|
});
|
|
186
|
+
const latestMood = useRef(mood);
|
|
187
|
+
latestMood.current = mood;
|
|
176
188
|
const cycles = useRef(props.workingCycles);
|
|
177
189
|
cycles.current = props.workingCycles;
|
|
178
190
|
const play = useCallback((action: VectorAction) => {
|
|
@@ -253,6 +265,13 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
253
265
|
play('idle');
|
|
254
266
|
}
|
|
255
267
|
}, [props.idleKey, props.reactionKey, props.workingKey, props.entranceKey, play]);
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (mood === previous.current.mood) return;
|
|
270
|
+
setVectorMood(state.current.mood, mood, previous.current.mood);
|
|
271
|
+
previous.current.mood = mood;
|
|
272
|
+
// A still character repaints into the new mood; a running one restarts its frame loop.
|
|
273
|
+
setRevision((value) => value + 1);
|
|
274
|
+
}, [mood]);
|
|
256
275
|
useEffect(() => {
|
|
257
276
|
if (Platform.OS !== 'web' || typeof IntersectionObserver === 'undefined' || !host.current)
|
|
258
277
|
return;
|
|
@@ -289,7 +308,8 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
289
308
|
motion.yaw += (motion.targetYaw - motion.yaw) * follow;
|
|
290
309
|
motion.pitch += (motion.targetPitch - motion.pitch) * follow;
|
|
291
310
|
motion.lookMix += ((motion.pointerActive ? 1 : 0) - motion.lookMix) * follow;
|
|
292
|
-
|
|
311
|
+
advanceVectorMood(motion.mood, latestMood.current, delta);
|
|
312
|
+
} else settleVectorMood(motion.mood, latestMood.current);
|
|
293
313
|
if (!painted || stopped || now - painted >= 1000 / 30) {
|
|
294
314
|
painted = painted ? now - ((now - painted) % (1000 / 30)) : now;
|
|
295
315
|
const action = portrait ? 'idle' : motion.action,
|
|
@@ -299,6 +319,7 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
299
319
|
Math.max(0, (motion.clock - motion.transitionStarted) / motion.transitionDuration),
|
|
300
320
|
);
|
|
301
321
|
const eased = transition * transition * (3 - 2 * transition);
|
|
322
|
+
const feeling = !portrait && vectorMoodActive(motion.mood) ? { ...motion.mood } : undefined;
|
|
302
323
|
const sharedKey = JSON.stringify([
|
|
303
324
|
latestFrameRecipe.current,
|
|
304
325
|
action,
|
|
@@ -312,10 +333,12 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
312
333
|
motion.transitionDuration,
|
|
313
334
|
vectorStateIdentity(motion.poseFrom),
|
|
314
335
|
vectorStateIdentity(motion.motionFrom),
|
|
336
|
+
feeling?.sadness,
|
|
337
|
+
feeling?.declineTime,
|
|
315
338
|
portrait,
|
|
316
339
|
previewPart,
|
|
317
340
|
]);
|
|
318
|
-
const { pose, procedural, drawing } = shareVectorFrame(sharedKey, () => {
|
|
341
|
+
const { pose, procedural, gaze, drawing } = shareVectorFrame(sharedKey, () => {
|
|
319
342
|
const poseTime =
|
|
320
343
|
asset.referenceFace && action === 'work' ? referenceWorkTime(time) : time;
|
|
321
344
|
const targetPose = sampleVectorPose(asset, action, poseTime);
|
|
@@ -346,17 +369,22 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
346
369
|
: undefined,
|
|
347
370
|
})
|
|
348
371
|
: undefined;
|
|
372
|
+
// The mood goes over the blended motion, never into it: a transition captures the
|
|
373
|
+
// motion without the mood, which carries on through the transition on its own clock.
|
|
374
|
+
const framed = vectorMoodFrame(
|
|
375
|
+
asset,
|
|
376
|
+
procedural,
|
|
377
|
+
{ yaw: portrait ? 0 : motion.yaw, pitch: portrait ? 0 : motion.pitch },
|
|
378
|
+
feeling,
|
|
379
|
+
);
|
|
349
380
|
const drawing = renderVectorFrame(asset, {
|
|
350
381
|
action,
|
|
351
382
|
time,
|
|
352
|
-
|
|
353
|
-
pitch: portrait ? 0 : motion.pitch,
|
|
383
|
+
...framed,
|
|
354
384
|
eyesOnly: previewPart === 'eyes',
|
|
355
385
|
pose,
|
|
356
|
-
motion: procedural,
|
|
357
|
-
look: procedural ? { yaw: procedural.yaw, pitch: procedural.pitch, mix: 1 } : undefined,
|
|
358
386
|
});
|
|
359
|
-
return { pose, procedural, drawing };
|
|
387
|
+
return { pose, procedural, gaze: framed.look ?? framed, drawing };
|
|
360
388
|
});
|
|
361
389
|
motion.lastPose = pose;
|
|
362
390
|
motion.lastMotion = procedural;
|
|
@@ -372,8 +400,8 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
372
400
|
time,
|
|
373
401
|
count: motion.count,
|
|
374
402
|
entrance: stopped ? 1 : motion.entrance,
|
|
375
|
-
gazeYaw:
|
|
376
|
-
gazePitch:
|
|
403
|
+
gazeYaw: gaze.yaw,
|
|
404
|
+
gazePitch: gaze.pitch,
|
|
377
405
|
tracking: motion.lookMix,
|
|
378
406
|
});
|
|
379
407
|
}
|
|
@@ -424,6 +452,7 @@ function AnimatedVectorCharacterAvatar(props: Props) {
|
|
|
424
452
|
gazeYaw: String(display?.gazeYaw ?? 0),
|
|
425
453
|
gazePitch: String(display?.gazePitch ?? 0),
|
|
426
454
|
tracking: String(display?.tracking ?? 0),
|
|
455
|
+
mood: mood ?? 'neutral',
|
|
427
456
|
},
|
|
428
457
|
}
|
|
429
458
|
: {})}
|
|
@@ -2,7 +2,7 @@ export { AgentAvatar } from './AgentAvatar';
|
|
|
2
2
|
export { AgentAvatarProvider } from './AgentAvatarProvider';
|
|
3
3
|
export { BLOOM_CHARACTER_RUNTIME_URL } from './context';
|
|
4
4
|
export { useAvatarRendererCapabilities } from './use-avatar-renderer-capabilities';
|
|
5
|
-
export type { AgentAvatarProps, AgentAvatarProviderProps } from './types';
|
|
5
|
+
export type { AgentAvatarMood, AgentAvatarProps, AgentAvatarProviderProps } from './types';
|
|
6
6
|
|
|
7
7
|
// One model: a character. `resolveAvatarCharacter` fills it in, `parseAvatarCharacter`
|
|
8
8
|
// checks saved JSON, `characterFromLegacy` migrates an avatar saved before 10.
|
|
@@ -4,6 +4,14 @@ import type { BloomThemeStorage } from '../theme/persistence';
|
|
|
4
4
|
import type { AvatarCharacter } from './character';
|
|
5
5
|
import type { VectorAssetLoader } from './vector-types';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* How the character feels, held for as long as it is set. `neutral` is its usual idle. `sad` is
|
|
9
|
+
* for an empty or not-found state, a refusal, something that could not be done: the character
|
|
10
|
+
* shakes its head "no" once as the mood starts, then stays dejected (looking down, drooping, lids
|
|
11
|
+
* heavy) on top of its idle until the mood changes.
|
|
12
|
+
*/
|
|
13
|
+
export type AgentAvatarMood = 'neutral' | 'sad';
|
|
14
|
+
|
|
7
15
|
export type AgentAvatarProps = {
|
|
8
16
|
/** @deprecated All characters use SVG. The legacy selector is accepted but has no effect. */
|
|
9
17
|
renderer?: 'svg' | 'webgl';
|
|
@@ -24,6 +32,13 @@ export type AgentAvatarProps = {
|
|
|
24
32
|
entranceKey?: number;
|
|
25
33
|
workingKey?: number;
|
|
26
34
|
workingCycles?: number;
|
|
35
|
+
/**
|
|
36
|
+
* Default `neutral`. Becoming `sad` (or mounting sad) shakes the head "no" once, then holds a
|
|
37
|
+
* dejected idle; back to `neutral` the droop eases out. Reactions, work and pointer gaze still
|
|
38
|
+
* play on top. Reduced motion and `paused` show the settled pose with no shake; a `portrait`
|
|
39
|
+
* still is always neutral.
|
|
40
|
+
*/
|
|
41
|
+
mood?: AgentAvatarMood;
|
|
27
42
|
/** The first picture of the character has been painted. Fires once per mounted renderer. */
|
|
28
43
|
onReady?: () => void;
|
|
29
44
|
/** Reports selected geometry preparation; paint-only changes do not reload. */
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { VectorLook } from './vector-face';
|
|
2
|
+
import type { VectorMotionPose } from './vector-motion';
|
|
3
|
+
import type { VectorData } from './vector-types';
|
|
4
|
+
import type { AgentAvatarMood } from './types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* How a mood is laid over whatever the character is doing. It is procedural, like gaze and
|
|
8
|
+
* blinking: every body, preset or edited, has its authored clips and none of them a "no", so the
|
|
9
|
+
* mood moves the pose those clips produce rather than adding a clip that only some bodies would
|
|
10
|
+
* have.
|
|
11
|
+
*/
|
|
12
|
+
export type VectorMoodState = {
|
|
13
|
+
/** How far into its mood the character is: 0 neutral, 1 fully sad. Eases, never jumps. */
|
|
14
|
+
sadness: number;
|
|
15
|
+
/** Seconds into the head shake that starts a sad mood. Past `VECTOR_DECLINE_SECONDS`, none. */
|
|
16
|
+
declineTime: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** The shake that says "no": three turns, the first the widest, coming to rest. */
|
|
20
|
+
export const VECTOR_DECLINE_SECONDS = 1.4;
|
|
21
|
+
/** How quickly the dejected pose sets in and lifts, per second. Settled in about a second. */
|
|
22
|
+
const SADNESS_RATE = 2.5;
|
|
23
|
+
const DECLINE_YAW = 0.6;
|
|
24
|
+
|
|
25
|
+
/** A neutral pose that a mood can be laid on: no turn, no droop, eyes open. */
|
|
26
|
+
export const VECTOR_REST_MOTION: Readonly<VectorMotionPose> = {
|
|
27
|
+
yaw: 0,
|
|
28
|
+
pitch: 0,
|
|
29
|
+
roll: 0,
|
|
30
|
+
bob: 0,
|
|
31
|
+
scale: 1,
|
|
32
|
+
lid: 1,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const unit = (value: number) => (Number.isFinite(value) ? Math.max(0, Math.min(1, value)) : 0);
|
|
36
|
+
const ease = (value: number) => {
|
|
37
|
+
const t = unit(value);
|
|
38
|
+
return t * t * (3 - 2 * t);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/** The state a character starts in, with or without the mood. Starting sad shakes the head. */
|
|
42
|
+
export function initialVectorMood(mood: AgentAvatarMood | undefined): VectorMoodState {
|
|
43
|
+
return { sadness: 0, declineTime: mood === 'sad' ? 0 : Number.POSITIVE_INFINITY };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The mood the character is now asked for. Becoming sad shakes the head once. */
|
|
47
|
+
export function setVectorMood(
|
|
48
|
+
state: VectorMoodState,
|
|
49
|
+
mood: AgentAvatarMood | undefined,
|
|
50
|
+
previous: AgentAvatarMood | undefined,
|
|
51
|
+
) {
|
|
52
|
+
if (mood === 'sad' && previous !== 'sad') state.declineTime = 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** One frame of a running character: the shake moves on and the droop eases towards the mood. */
|
|
56
|
+
export function advanceVectorMood(
|
|
57
|
+
state: VectorMoodState,
|
|
58
|
+
mood: AgentAvatarMood | undefined,
|
|
59
|
+
delta: number,
|
|
60
|
+
) {
|
|
61
|
+
const target = mood === 'sad' ? 1 : 0;
|
|
62
|
+
state.declineTime += delta;
|
|
63
|
+
state.sadness += (target - state.sadness) * (1 - Math.exp(-delta * SADNESS_RATE));
|
|
64
|
+
if (Math.abs(target - state.sadness) < 0.001) state.sadness = target;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A still character (paused, reduced motion) shows the mood's settled pose and never shakes. */
|
|
68
|
+
export function settleVectorMood(state: VectorMoodState, mood: AgentAvatarMood | undefined) {
|
|
69
|
+
state.sadness = mood === 'sad' ? 1 : 0;
|
|
70
|
+
state.declineTime = Number.POSITIVE_INFINITY;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Whether the mood moves the pose at all; a neutral character draws exactly as it did without one. */
|
|
74
|
+
export function vectorMoodActive(state: VectorMoodState): boolean {
|
|
75
|
+
return state.sadness > 0 || state.declineTime < VECTOR_DECLINE_SECONDS;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The head turn of the shake, in radians, at `time` seconds into it: zero before and after, and
|
|
80
|
+
* it starts and ends at rest with no jump in speed. The swings shrink as the head gives up.
|
|
81
|
+
*/
|
|
82
|
+
export function sampleVectorDecline(time: number): number {
|
|
83
|
+
if (!(time > 0 && time < VECTOR_DECLINE_SECONDS)) return 0;
|
|
84
|
+
const u = time / VECTOR_DECLINE_SECONDS;
|
|
85
|
+
return DECLINE_YAW * ease(u / 0.12) * (1 - u) ** 2 * Math.sin(Math.PI * 6 * u);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* `pose` with the mood laid over it. Sad looks down and a little aside, sinks and deflates
|
|
90
|
+
* slightly, tilts the head and lets the lids fall; the shake turns the head and rocks it a little
|
|
91
|
+
* with each turn. Blinks and breathing carry on underneath.
|
|
92
|
+
*/
|
|
93
|
+
export function applyVectorMood(pose: VectorMotionPose, state: VectorMoodState): VectorMotionPose {
|
|
94
|
+
const sad = unit(state.sadness),
|
|
95
|
+
shake = sampleVectorDecline(state.declineTime);
|
|
96
|
+
return {
|
|
97
|
+
yaw: pose.yaw + shake - sad * 0.1,
|
|
98
|
+
pitch: pose.pitch + sad * 0.3,
|
|
99
|
+
roll: pose.roll + shake * 0.12 + sad * 0.06,
|
|
100
|
+
bob: pose.bob - sad * 0.04,
|
|
101
|
+
scale: pose.scale * (1 - sad * 0.03),
|
|
102
|
+
lid: unit(pose.lid * (1 - sad * 0.4)),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type VectorMoodFrame = {
|
|
107
|
+
/** The turn of the whole drawing (and of a reference face without a rest basis). */
|
|
108
|
+
yaw: number;
|
|
109
|
+
pitch: number;
|
|
110
|
+
motion?: VectorMotionPose;
|
|
111
|
+
/** A reference face's head direction. */
|
|
112
|
+
look?: VectorLook;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* What `renderVectorFrame` draws a character with, the mood laid on. `procedural` is a reference
|
|
117
|
+
* face's sampled motion (undefined for other bodies) and `turn` the pointer's turn. The mood's
|
|
118
|
+
* turn goes everywhere a head can turn: a reference face's `look`, and the frame's own turn, which
|
|
119
|
+
* is how a body with no head of its own (and a face fitted without a rest basis) shakes. A neutral
|
|
120
|
+
* character draws exactly as it did without a mood.
|
|
121
|
+
*/
|
|
122
|
+
export function vectorMoodFrame(
|
|
123
|
+
asset: VectorData,
|
|
124
|
+
procedural: VectorMotionPose | undefined,
|
|
125
|
+
turn: { yaw: number; pitch: number },
|
|
126
|
+
mood: VectorMoodState | undefined,
|
|
127
|
+
): VectorMoodFrame {
|
|
128
|
+
const look = (motion: VectorMotionPose | undefined) =>
|
|
129
|
+
asset.referenceFace && motion ? { yaw: motion.yaw, pitch: motion.pitch, mix: 1 } : undefined;
|
|
130
|
+
if (!mood || !vectorMoodActive(mood))
|
|
131
|
+
return { ...turn, motion: procedural, look: look(procedural) };
|
|
132
|
+
const base = procedural ?? VECTOR_REST_MOTION,
|
|
133
|
+
motion = applyVectorMood(base, mood);
|
|
134
|
+
return {
|
|
135
|
+
yaw: turn.yaw + motion.yaw - base.yaw,
|
|
136
|
+
pitch: turn.pitch + motion.pitch - base.pitch,
|
|
137
|
+
motion,
|
|
138
|
+
look: look(motion),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -6,6 +6,11 @@ export interface EmptyStateGeometry {
|
|
|
6
6
|
glyph: number;
|
|
7
7
|
/** `IconCircle`'s rung. `lg` is 52, `xl` is 64. */
|
|
8
8
|
circle: 'lg' | 'xl';
|
|
9
|
+
/**
|
|
10
|
+
* The box for a figure passed as `illustration`: an agent's avatar, a picture. Larger than the
|
|
11
|
+
* disc because a character has to be read (its face, its gesture), not just recognised.
|
|
12
|
+
*/
|
|
13
|
+
illustration: number;
|
|
9
14
|
/** Above and below the block. */
|
|
10
15
|
paddingVertical: number;
|
|
11
16
|
/** Between the mark, the text block, the children, the actions and the footer. */
|
|
@@ -32,6 +37,7 @@ export const EMPTY_STATE_GEOMETRY: Record<EmptyStateVariant, EmptyStateGeometry>
|
|
|
32
37
|
comfortable: {
|
|
33
38
|
glyph: 32,
|
|
34
39
|
circle: 'xl',
|
|
40
|
+
illustration: 112,
|
|
35
41
|
paddingVertical: 48,
|
|
36
42
|
gap: 16,
|
|
37
43
|
textGap: 6,
|
|
@@ -42,6 +48,7 @@ export const EMPTY_STATE_GEOMETRY: Record<EmptyStateVariant, EmptyStateGeometry>
|
|
|
42
48
|
compact: {
|
|
43
49
|
glyph: 24,
|
|
44
50
|
circle: 'lg',
|
|
51
|
+
illustration: 72,
|
|
45
52
|
paddingVertical: 24,
|
|
46
53
|
gap: 12,
|
|
47
54
|
textGap: 4,
|
|
@@ -29,19 +29,32 @@ export function createTextBubble(Content: ContentComponent) {
|
|
|
29
29
|
size?: TooltipSize;
|
|
30
30
|
}) {
|
|
31
31
|
const size = useTooltipSize(sizeProp);
|
|
32
|
-
const
|
|
33
|
-
const type = TOOLTIP_SIZES[size];
|
|
34
|
-
const c = Children.toArray(children);
|
|
32
|
+
const lines = Children.toArray(children);
|
|
35
33
|
return (
|
|
36
|
-
<Content label={
|
|
37
|
-
<
|
|
38
|
-
{c.map((child, i) => (
|
|
39
|
-
<Text key={i} style={[TYPE_SCALE[type.type], { color: palette.text }]}>
|
|
40
|
-
{child}
|
|
41
|
-
</Text>
|
|
42
|
-
))}
|
|
43
|
-
</View>
|
|
34
|
+
<Content label={lines.join(' ')} size={size}>
|
|
35
|
+
<TextBubbleLines lines={lines} size={size} />
|
|
44
36
|
</Content>
|
|
45
37
|
);
|
|
46
38
|
};
|
|
47
39
|
}
|
|
40
|
+
|
|
41
|
+
/** The bubble's text, rendered only when `Content` shows it: a closed tooltip reads no palette. */
|
|
42
|
+
function TextBubbleLines({
|
|
43
|
+
lines,
|
|
44
|
+
size,
|
|
45
|
+
}: {
|
|
46
|
+
lines: ReturnType<typeof Children.toArray>;
|
|
47
|
+
size: TooltipSize;
|
|
48
|
+
}) {
|
|
49
|
+
const palette = useMenuPalette();
|
|
50
|
+
const type = TOOLTIP_SIZES[size];
|
|
51
|
+
return (
|
|
52
|
+
<View style={{ gap: 2 }}>
|
|
53
|
+
{lines.map((line, i) => (
|
|
54
|
+
<Text key={i} style={[TYPE_SCALE[type.type], { color: palette.text }]}>
|
|
55
|
+
{line}
|
|
56
|
+
</Text>
|
|
57
|
+
))}
|
|
58
|
+
</View>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -157,32 +157,8 @@ export function TooltipTrigger({ children }: { children: React.ReactNode }) {
|
|
|
157
157
|
* Non-interactive (`pointer-events-none select-none`), so a press on the bubble
|
|
158
158
|
* falls through to the dismiss layer.
|
|
159
159
|
*/
|
|
160
|
-
export function TooltipContent({
|
|
161
|
-
|
|
162
|
-
label,
|
|
163
|
-
size: sizeProp,
|
|
164
|
-
}: {
|
|
165
|
-
children: React.ReactNode;
|
|
166
|
-
label: string;
|
|
167
|
-
size?: TooltipSize;
|
|
168
|
-
}) {
|
|
169
|
-
const size = useTooltipSize(sizeProp);
|
|
170
|
-
const parentFill = useSurfaceFill();
|
|
171
|
-
const palette = useMenuPalette();
|
|
172
|
-
const publishedFill = resolveSurfaceMaterial({
|
|
173
|
-
fill: palette.surface,
|
|
174
|
-
parentFill: parentFill,
|
|
175
|
-
}).publishedFill;
|
|
176
|
-
const materialStyle = useSurfaceMaterial(
|
|
177
|
-
'[data-bloom-tooltip]',
|
|
178
|
-
'bloom-tooltip-surface-css',
|
|
179
|
-
palette.surface,
|
|
180
|
-
true,
|
|
181
|
-
undefined,
|
|
182
|
-
undefined,
|
|
183
|
-
TOOLTIP_SIZES[size].borderRadius,
|
|
184
|
-
);
|
|
185
|
-
const { position, visible, triggerRef } = useContext(TooltipContext);
|
|
160
|
+
export function TooltipContent(props: TooltipContentProps) {
|
|
161
|
+
const { visible } = useContext(TooltipContext);
|
|
186
162
|
|
|
187
163
|
// `visible` drives an `open` → `closing` → unmounted cycle, so the exit has
|
|
188
164
|
// the animation's length to play before the bubble leaves the tree. Adjusted
|
|
@@ -209,23 +185,52 @@ export function TooltipContent({
|
|
|
209
185
|
return () => clearTimeout(timer);
|
|
210
186
|
}, [visible, mounted]);
|
|
211
187
|
|
|
188
|
+
// A closed tooltip is nothing but this state. Every icon button in a list carries one, so its
|
|
189
|
+
// palette, material and anchor are resolved only while the bubble is up (`TooltipBubble`).
|
|
190
|
+
return mounted ? <TooltipBubble {...props} /> : null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface TooltipContentProps {
|
|
194
|
+
children: React.ReactNode;
|
|
195
|
+
label: string;
|
|
196
|
+
size?: TooltipSize;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function TooltipBubble({ children, label, size: sizeProp }: TooltipContentProps) {
|
|
200
|
+
const size = useTooltipSize(sizeProp);
|
|
201
|
+
const parentFill = useSurfaceFill();
|
|
202
|
+
const palette = useMenuPalette();
|
|
203
|
+
const publishedFill = resolveSurfaceMaterial({
|
|
204
|
+
fill: palette.surface,
|
|
205
|
+
parentFill: parentFill,
|
|
206
|
+
}).publishedFill;
|
|
207
|
+
const materialStyle = useSurfaceMaterial(
|
|
208
|
+
'[data-bloom-tooltip]',
|
|
209
|
+
'bloom-tooltip-surface-css',
|
|
210
|
+
palette.surface,
|
|
211
|
+
true,
|
|
212
|
+
undefined,
|
|
213
|
+
undefined,
|
|
214
|
+
TOOLTIP_SIZES[size].borderRadius,
|
|
215
|
+
);
|
|
216
|
+
const { position, visible, triggerRef } = useContext(TooltipContext);
|
|
217
|
+
|
|
212
218
|
// The TRIGGER's viewport box, re-measured on scroll and resize. The bubble is
|
|
213
219
|
// portaled and `position: fixed` against it. It used to be `position:
|
|
214
220
|
// absolute` inside the tree, which on react-native-web (every `View` is
|
|
215
221
|
// `position: relative`) anchored it to whatever box happened to contain the
|
|
216
222
|
// Tooltip — the column, the card — rather than to its trigger.
|
|
217
|
-
const anchor = useTrackedAnchor(triggerRef
|
|
223
|
+
const anchor = useTrackedAnchor(triggerRef);
|
|
218
224
|
const [bubbleWidth, setBubbleWidth] = useState(0);
|
|
219
225
|
const [bubble, setBubble] = useState<ComponentRef<typeof View> | null>(null);
|
|
220
226
|
const reducedMotion = usePrefersReducedMotion();
|
|
221
227
|
// Present once it has been measured (the frame before, it would show at the
|
|
222
228
|
// wrong place) and a frame has painted at zero for the fade to start from.
|
|
223
|
-
const presence =
|
|
224
|
-
useEnteredPresence(visible, mounted && anchor !== null) && bubbleWidth > 0 ? 1 : 0;
|
|
229
|
+
const presence = useEnteredPresence(visible, anchor !== null) && bubbleWidth > 0 ? 1 : 0;
|
|
225
230
|
const presenceMs = reducedMotion ? 0 : TOOLTIP_MOTION_DURATION;
|
|
226
231
|
useSurfacePresenceContent(bubble, { presence, duration: presenceMs, blur: 4 });
|
|
227
232
|
|
|
228
|
-
if (!
|
|
233
|
+
if (!anchor) return null;
|
|
229
234
|
|
|
230
235
|
const box = TOOLTIP_SIZES[size];
|
|
231
236
|
const bubbleStyle: WebCssStyle = {
|
|
@@ -324,14 +329,10 @@ export function TooltipContent({
|
|
|
324
329
|
*/
|
|
325
330
|
function useTrackedAnchor(
|
|
326
331
|
ref: React.RefObject<ComponentRef<typeof View> | null>,
|
|
327
|
-
active: boolean,
|
|
328
332
|
): FloatingAnchor | null {
|
|
329
333
|
const [anchor, setAnchor] = useState<FloatingAnchor | null>(null);
|
|
330
334
|
useEffect(() => {
|
|
331
|
-
if (
|
|
332
|
-
setAnchor(null);
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
+
if (typeof window === 'undefined') return;
|
|
335
336
|
let frame = 0;
|
|
336
337
|
let last: FloatingAnchor | null = null;
|
|
337
338
|
const tick = () => {
|
|
@@ -353,7 +354,7 @@ function useTrackedAnchor(
|
|
|
353
354
|
};
|
|
354
355
|
tick();
|
|
355
356
|
return () => window.cancelAnimationFrame(frame);
|
|
356
|
-
}, [ref
|
|
357
|
+
}, [ref]);
|
|
357
358
|
return anchor;
|
|
358
359
|
}
|
|
359
360
|
|