@memori.ai/memori-react 7.19.2 → 7.21.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.d.ts +3 -2
  3. package/dist/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.js +13 -6
  4. package/dist/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.js.map +1 -1
  5. package/dist/components/Avatar/AvatarView/AvatarComponent/avatarComponent.d.ts +14 -18
  6. package/dist/components/Avatar/AvatarView/AvatarComponent/avatarComponent.js +19 -77
  7. package/dist/components/Avatar/AvatarView/AvatarComponent/avatarComponent.js.map +1 -1
  8. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.d.ts +17 -2
  9. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +95 -70
  10. package/dist/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  11. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.d.ts +65 -0
  12. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.js +747 -0
  13. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.js.map +1 -0
  14. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.d.ts +9 -2
  15. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +60 -2
  16. package/dist/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
  17. package/dist/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.d.ts +3 -4
  18. package/dist/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.js +5 -11
  19. package/dist/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.js.map +1 -1
  20. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +13 -52
  21. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js +68 -70
  22. package/dist/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
  23. package/dist/components/Avatar/AvatarView/index.d.ts +1 -1
  24. package/dist/components/Avatar/AvatarView/index.js +2 -2
  25. package/dist/components/Avatar/AvatarView/index.js.map +1 -1
  26. package/dist/components/ChatBubble/ChatBubble.js +7 -1
  27. package/dist/components/ChatBubble/ChatBubble.js.map +1 -1
  28. package/dist/components/MemoriWidget/MemoriWidget.js +130 -62
  29. package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
  30. package/dist/components/UploadButton/UploadButton.js +2 -2
  31. package/dist/components/UploadButton/UploadButton.js.map +1 -1
  32. package/dist/components/WhyThisAnswer/WhyThisAnswer.css +43 -0
  33. package/dist/components/WhyThisAnswer/WhyThisAnswer.js +2 -1
  34. package/dist/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
  35. package/dist/context/visemeContext.js +0 -39
  36. package/dist/context/visemeContext.js.map +1 -1
  37. package/dist/locales/de.json +1 -0
  38. package/dist/locales/en.json +1 -0
  39. package/dist/locales/es.json +1 -0
  40. package/dist/locales/fr.json +1 -0
  41. package/dist/locales/it.json +1 -0
  42. package/esm/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.d.ts +3 -2
  43. package/esm/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.js +13 -6
  44. package/esm/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.js.map +1 -1
  45. package/esm/components/Avatar/AvatarView/AvatarComponent/avatarComponent.d.ts +14 -18
  46. package/esm/components/Avatar/AvatarView/AvatarComponent/avatarComponent.js +20 -78
  47. package/esm/components/Avatar/AvatarView/AvatarComponent/avatarComponent.js.map +1 -1
  48. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.d.ts +17 -2
  49. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js +99 -74
  50. package/esm/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.js.map +1 -1
  51. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.d.ts +65 -0
  52. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.js +743 -0
  53. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.js.map +1 -0
  54. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.d.ts +9 -2
  55. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js +61 -3
  56. package/esm/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.js.map +1 -1
  57. package/esm/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.d.ts +3 -4
  58. package/esm/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.js +5 -11
  59. package/esm/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.js.map +1 -1
  60. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.d.ts +13 -52
  61. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js +67 -69
  62. package/esm/components/Avatar/AvatarView/AvatarComponent/constants.js.map +1 -1
  63. package/esm/components/Avatar/AvatarView/index.d.ts +1 -1
  64. package/esm/components/Avatar/AvatarView/index.js +2 -2
  65. package/esm/components/Avatar/AvatarView/index.js.map +1 -1
  66. package/esm/components/ChatBubble/ChatBubble.js +7 -1
  67. package/esm/components/ChatBubble/ChatBubble.js.map +1 -1
  68. package/esm/components/MemoriWidget/MemoriWidget.js +130 -62
  69. package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
  70. package/esm/components/UploadButton/UploadButton.js +2 -2
  71. package/esm/components/UploadButton/UploadButton.js.map +1 -1
  72. package/esm/components/WhyThisAnswer/WhyThisAnswer.css +43 -0
  73. package/esm/components/WhyThisAnswer/WhyThisAnswer.js +2 -1
  74. package/esm/components/WhyThisAnswer/WhyThisAnswer.js.map +1 -1
  75. package/esm/context/visemeContext.js +0 -39
  76. package/esm/context/visemeContext.js.map +1 -1
  77. package/esm/locales/de.json +1 -0
  78. package/esm/locales/en.json +1 -0
  79. package/esm/locales/es.json +1 -0
  80. package/esm/locales/fr.json +1 -0
  81. package/esm/locales/it.json +1 -0
  82. package/package.json +2 -2
  83. package/src/components/Avatar/AvatarView/AvatarComponent/Shadow/DynamicShadow.tsx +15 -8
  84. package/src/components/Avatar/AvatarView/AvatarComponent/avatarComponent.tsx +64 -219
  85. package/src/components/Avatar/AvatarView/AvatarComponent/components/FullbodyAvatar/fullbodyAvatar.tsx +221 -124
  86. package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/AvatarAnimator.ts +1250 -0
  87. package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/MorphTargetController.ts +164 -8
  88. package/src/components/Avatar/AvatarView/AvatarComponent/components/halfbodyAvatar.tsx +19 -17
  89. package/src/components/Avatar/AvatarView/AvatarComponent/constants.ts +80 -79
  90. package/src/components/Avatar/AvatarView/index.tsx +1 -7
  91. package/src/components/ChatBubble/ChatBubble.tsx +14 -2
  92. package/src/components/MemoriWidget/MemoriWidget.tsx +168 -76
  93. package/src/components/UploadButton/UploadButton.tsx +4 -4
  94. package/src/components/UploadButton/__snapshots__/UploadButton.test.tsx.snap +1 -1
  95. package/src/components/WhyThisAnswer/WhyThisAnswer.css +43 -0
  96. package/src/components/WhyThisAnswer/WhyThisAnswer.stories.tsx +44 -3
  97. package/src/components/WhyThisAnswer/WhyThisAnswer.test.tsx +128 -8
  98. package/src/components/WhyThisAnswer/WhyThisAnswer.tsx +28 -3
  99. package/src/components/WhyThisAnswer/__snapshots__/WhyThisAnswer.test.tsx.snap +15 -1
  100. package/src/components/layouts/layouts.stories.tsx +0 -8
  101. package/src/context/visemeContext.tsx +40 -41
  102. package/src/index.stories.tsx +63 -65
  103. package/src/locales/de.json +1 -0
  104. package/src/locales/en.json +1 -0
  105. package/src/locales/es.json +1 -0
  106. package/src/locales/fr.json +1 -0
  107. package/src/locales/it.json +1 -0
  108. package/src/components/Avatar/AvatarView/AvatarComponent/components/controllers/AnimationController.ts +0 -308
@@ -1,308 +0,0 @@
1
- import { AnimationState, AnimationConfig } from '../FullbodyAvatar/types';
2
- import { AnimationAction, AnimationMixer, LoopOnce } from 'three';
3
- import { DEFAULT_CONFIG, MAX_IDLE_LOOPS_DEFAULT } from '../../constants';
4
-
5
- /**
6
- * Controller class for managing avatar animations and transitions between states
7
- */
8
- export class AnimationController {
9
- // Current animation state (LOADING, EMOTION, IDLE)
10
- private currentState: AnimationState = AnimationState.LOADING;
11
- // Currently playing animation action
12
- private currentAction: AnimationAction | null = null;
13
- // Three.js animation mixer
14
- private mixer: AnimationMixer;
15
- // Map of available animation actions
16
- private actions: Record<string, AnimationAction>;
17
- // Animation configuration settings
18
- private config: AnimationConfig;
19
- // Index of last played idle animation
20
- private lastIdleIndex: number = -1;
21
- // Flag to prevent overlapping transitions
22
- private isTransitioning: boolean = false;
23
- // Counter for number of times current idle has looped
24
- private currentIdleLoopCount: number = 0;
25
- // Maximum number of idle loops before forcing change
26
- private readonly MAX_IDLE_LOOPS = MAX_IDLE_LOOPS_DEFAULT;
27
- // Timestamp of last animation frame
28
- private lastAnimationTime: number = 0;
29
- // Flag to check if chat has already started
30
- private isChatAlreadyStarted: boolean = false;
31
- // Sequence of animations
32
- private sequence: string[] | null = null;
33
- // Index of current animation in sequence
34
- private sequenceIndex: number = 0;
35
-
36
- constructor(
37
- mixer: AnimationMixer,
38
- actions: Record<string, AnimationAction>,
39
- config: AnimationConfig = DEFAULT_CONFIG
40
- ) {
41
- // console.log('Initializing AnimationController');
42
- this.mixer = mixer;
43
- this.actions = actions;
44
- this.config = config;
45
- }
46
-
47
- /**
48
- * Checks if current idle animation has completed a loop
49
- */
50
- private checkForLoop() {
51
- if (!this.currentAction || this.currentState !== AnimationState.IDLE)
52
- return;
53
-
54
- const clip = this.currentAction.getClip();
55
- const currentTime = this.currentAction.time;
56
-
57
- // If the current time is less than the last time we recorded,
58
- // it means the animation has looped
59
- if (currentTime < this.lastAnimationTime) {
60
- this.currentIdleLoopCount++;
61
- // console.log(
62
- // `[AnimationController] Loop detected! Count: ${this.currentIdleLoopCount}`
63
- // );
64
-
65
- // Force idle change after MAX_IDLE_LOOPS
66
- if (this.currentIdleLoopCount >= this.MAX_IDLE_LOOPS) {
67
- this.forceIdleChange();
68
- }
69
- }
70
-
71
- this.lastAnimationTime = currentTime;
72
- }
73
-
74
- /**
75
- * Forces transition to a new idle animation
76
- */
77
- private forceIdleChange() {
78
- this.currentIdleLoopCount = 0;
79
- this.lastAnimationTime = 0;
80
- this.transitionTo(AnimationState.IDLE);
81
- }
82
-
83
- /**
84
- * Selects next random idle animation that differs from last played
85
- */
86
- private getNextIdleAnimation(): AnimationAction {
87
- let nextIndex;
88
- do {
89
- nextIndex = Math.floor(Math.random() * this.config.idleCount) + 1;
90
- } while (nextIndex === this.lastIdleIndex);
91
-
92
- // console.log(
93
- // '[AnimationController] isChatAlreadyStarted',
94
- // this.isChatAlreadyStarted
95
- // );
96
-
97
- if (this.isChatAlreadyStarted && nextIndex === 3) {
98
- // If chat has already started and the last idle was Idle4, use Idle3 instead
99
- nextIndex = this.lastIdleIndex !== 4 ? 4 : 2;
100
- }
101
-
102
- // console.log(
103
- // `[AnimationController] Selected idle animation: Idle${nextIndex}`
104
- // );
105
- this.lastIdleIndex = nextIndex;
106
- const idleAction = this.actions[`Idle${nextIndex}`];
107
-
108
- if (!idleAction) {
109
- throw new Error(`Idle animation ${nextIndex} not found`);
110
- }
111
-
112
- return idleAction;
113
- }
114
-
115
- /**
116
- * Plays a sequence of animations
117
- */
118
- playSequence(sequenceString: string) {
119
- const animations = sequenceString.split('->').map(anim => anim.trim());
120
- console.log('[AnimationController] playSequence:', animations);
121
-
122
- this.sequence = animations;
123
- this.sequenceIndex = 0;
124
-
125
- const firstAnim = this.parseAnimationName(animations[0]);
126
- this.transitionTo(AnimationState.EMOTION, firstAnim);
127
- }
128
-
129
- // Animation Name Parsing
130
- private parseAnimationName(animation: string): string {
131
- const randomMatch = animation.match(/(\w+)\[(\d+),(\d+)\]/);
132
- if (randomMatch) {
133
- const [_, base, min, max] = randomMatch;
134
- const random =
135
- Math.floor(Math.random() * (Number(max) - Number(min) + 1)) +
136
- Number(min);
137
- return `${base}${random}`;
138
- }
139
- return animation;
140
- }
141
-
142
- /**
143
- * Transitions to a new animation state
144
- */
145
- transitionTo(state: AnimationState, emotionName?: string) {
146
- if (this.isTransitioning) {
147
- // console.log(
148
- // '[AnimationController] Transition already in progress, skipping'
149
- // );
150
- return;
151
- }
152
-
153
- // console.log(
154
- // `[AnimationController] Transitioning to ${state}${
155
- // emotionName ? ` (${emotionName})` : ''
156
- // }`
157
- // );
158
- this.isTransitioning = true;
159
-
160
- try {
161
- let nextAction: AnimationAction | null = null;
162
-
163
- // Select the next action based on the current state
164
- switch (state) {
165
- case AnimationState.LOADING:
166
- nextAction = this.actions[emotionName || 'Loading1'];
167
- this.currentIdleLoopCount = 0;
168
- this.lastAnimationTime = 0;
169
- break;
170
- case AnimationState.EMOTION:
171
- nextAction = this.actions[emotionName || 'Timore1'];
172
- this.currentIdleLoopCount = 0;
173
- this.lastAnimationTime = 0;
174
- break;
175
- case AnimationState.IDLE:
176
- nextAction = this.getNextIdleAnimation();
177
- // Only reset loop count if we're coming from a different idle animation
178
- if (this.currentState !== AnimationState.IDLE) {
179
- this.currentIdleLoopCount = 0;
180
- this.lastAnimationTime = 0;
181
- }
182
- break;
183
- }
184
-
185
- if (!nextAction) {
186
- throw new Error(`No animation found for state: ${state}`);
187
- }
188
-
189
- // Fade out current animation
190
- if (this.currentAction) {
191
- this.currentAction.fadeOut(this.config.fadeOutDuration);
192
- }
193
-
194
- // Setup next animation
195
- nextAction.reset().fadeIn(this.config.fadeInDuration).play();
196
-
197
- // Configure animation properties
198
- nextAction.timeScale = this.config.timeScale;
199
- if (state !== AnimationState.IDLE) {
200
- nextAction.setLoop(LoopOnce, 1);
201
- nextAction.clampWhenFinished = true;
202
- } else {
203
- nextAction.setLoop(Infinity, Infinity);
204
- }
205
-
206
- this.currentAction = nextAction;
207
- this.currentState = state;
208
- // console.log('[AnimationController] Transition completed successfully');
209
- } catch (error) {
210
- console.error(
211
- '[AnimationController] Error during animation transition:',
212
- error
213
- );
214
- if (state !== AnimationState.IDLE) {
215
- this.transitionTo(AnimationState.IDLE);
216
- }
217
- } finally {
218
- this.isTransitioning = false;
219
- }
220
- }
221
-
222
- /**
223
- * Updates animation state on each frame
224
- */
225
- update(delta: number) {
226
- if (!this.currentAction) return;
227
-
228
- // Check for loop completion in idle animations
229
- this.checkForLoop();
230
-
231
- // Sequence progression,
232
- // If sequence is playing, transition to the next animation in the sequence
233
- // If sequence is finished, transition to idle
234
- if (
235
- this.sequence &&
236
- this.currentState === AnimationState.EMOTION &&
237
- this.currentAction.time >= this.currentAction.getClip().duration * 0.9
238
- ) {
239
- this.sequenceIndex++;
240
-
241
- if (this.sequenceIndex < this.sequence.length) {
242
- const nextAnim = this.parseAnimationName(this.sequence[this.sequenceIndex]);
243
- this.transitionTo(AnimationState.EMOTION, nextAnim);
244
- } else {
245
- this.sequence = null;
246
- this.sequenceIndex = 0;
247
- this.transitionTo(AnimationState.IDLE);
248
- }
249
- }
250
-
251
- // Check if emotion/loading animation is finished
252
- if (
253
- this.currentState !== AnimationState.IDLE &&
254
- this.currentAction.time >= this.currentAction.getClip().duration * 0.9
255
- ) {
256
- // console.log(
257
- // '[AnimationController] Non-idle animation completed, transitioning to idle'
258
- // );
259
- this.transitionTo(AnimationState.IDLE);
260
- }
261
-
262
- this.mixer.update(delta);
263
- }
264
-
265
- /**
266
- * Returns current animation state
267
- */
268
- getCurrentState(): AnimationState {
269
- return this.currentState;
270
- }
271
-
272
- /**
273
- * Returns number of times current idle has looped
274
- */
275
- getLoopCount(): number {
276
- return this.currentIdleLoopCount;
277
- }
278
-
279
- /**
280
- * Updates animation playback speed
281
- */
282
- setTimeScale(timeScale: number) {
283
- // console.log(`[AnimationController] Setting time scale to ${timeScale}`);
284
- this.config.timeScale = timeScale;
285
- if (this.currentAction) {
286
- this.currentAction.timeScale = timeScale;
287
- }
288
- }
289
-
290
- updateIsChatAlreadyStarted(isChatAlreadyStarted: boolean) {
291
- this.isChatAlreadyStarted = isChatAlreadyStarted;
292
- }
293
-
294
- /**
295
- * Returns debug information about current animation state
296
- */
297
- getDebugInfo() {
298
- return {
299
- currentState: this.currentState,
300
- currentIdleIndex: this.lastIdleIndex,
301
- loopCount: this.currentIdleLoopCount,
302
- currentTime: this.currentAction?.time || 0,
303
- lastTime: this.lastAnimationTime,
304
- isTransitioning: this.isTransitioning,
305
- isChatAlreadyStarted: this.isChatAlreadyStarted,
306
- };
307
- }
308
- }