@sage-rsc/talking-head-react 1.0.27 → 1.0.28

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-COqTUp83.cjs");exports.CurriculumLearning=i.CurriculumLearning;exports.TalkingHeadAvatar=i.TalkingHeadAvatar;exports.TalkingHeadComponent=i.TalkingHeadComponent;exports.animations=i.animations;exports.getActiveTTSConfig=i.getActiveTTSConfig;exports.getAnimation=i.getAnimation;exports.getVoiceOptions=i.getVoiceOptions;exports.hasAnimation=i.hasAnimation;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./index-Dx7mDKJm.cjs");exports.CurriculumLearning=i.CurriculumLearning;exports.TalkingHeadAvatar=i.TalkingHeadAvatar;exports.TalkingHeadComponent=i.TalkingHeadComponent;exports.animations=i.animations;exports.getActiveTTSConfig=i.getActiveTTSConfig;exports.getAnimation=i.getAnimation;exports.getVoiceOptions=i.getVoiceOptions;exports.hasAnimation=i.hasAnimation;
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { C as n, T as s, a as t, d as e, b as o, g, c as m, h as r } from "./index-DPiBXfzj.js";
1
+ import { C as n, T as s, a as t, d as e, b as o, g, c as m, h as r } from "./index-zMY6cyU2.js";
2
2
  export {
3
3
  n as CurriculumLearning,
4
4
  s as TalkingHeadAvatar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sage-rsc/talking-head-react",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "A reusable React component for 3D talking avatars with lip-sync and text-to-speech",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -51,6 +51,11 @@ const CurriculumLearning = forwardRef(({
51
51
  onCustomAction
52
52
  });
53
53
 
54
+ // Refs for functions to avoid circular dependencies
55
+ const startTeachingRef = useRef(null);
56
+ const nextLessonRef = useRef(null);
57
+ const completeLessonRef = useRef(null);
58
+
54
59
  // Update callbacks ref when they change
55
60
  useEffect(() => {
56
61
  callbacksRef.current = {
@@ -111,13 +116,20 @@ const CurriculumLearning = forwardRef(({
111
116
  return false;
112
117
  }, []);
113
118
 
114
- // Complete current lesson
119
+ // Complete current lesson - defined before it's used to avoid circular dependency
115
120
  const completeLesson = useCallback(() => {
116
121
  stateRef.current.lessonCompleted = true;
117
122
  stateRef.current.isQuestionMode = false;
118
123
 
119
- const percentage = Math.round((stateRef.current.score / stateRef.current.totalQuestions) * 100);
120
- let feedbackMessage = `Congratulations! You've completed this lesson with a score of ${stateRef.current.score} out of ${stateRef.current.totalQuestions} (${percentage}%). `;
124
+ const percentage = stateRef.current.totalQuestions > 0
125
+ ? Math.round((stateRef.current.score / stateRef.current.totalQuestions) * 100)
126
+ : 100;
127
+ let feedbackMessage = `Congratulations! You've completed this lesson`;
128
+ if (stateRef.current.totalQuestions > 0) {
129
+ feedbackMessage += ` with a score of ${stateRef.current.score} out of ${stateRef.current.totalQuestions} (${percentage}%). `;
130
+ } else {
131
+ feedbackMessage += `! `;
132
+ }
121
133
 
122
134
  if (percentage >= 80) {
123
135
  feedbackMessage += "Excellent work! You have a great understanding of this topic.";
@@ -150,7 +162,7 @@ const CurriculumLearning = forwardRef(({
150
162
  if (animations.lessonComplete) {
151
163
  try {
152
164
  avatarRef.current.playAnimation(animations.lessonComplete, true);
153
- } catch (error) {
165
+ } catch (error) {
154
166
  avatarRef.current.playCelebration();
155
167
  }
156
168
  }
@@ -165,12 +177,15 @@ const CurriculumLearning = forwardRef(({
165
177
  lipsyncLang: defaultAvatarConfig.lipsyncLang,
166
178
  onSpeechEnd: () => {
167
179
  // Add a small delay after speech ends for natural flow
168
- setTimeout(() => {
169
- nextLesson();
180
+ setTimeout(() => {
181
+ // Use ref to avoid circular dependency
182
+ if (nextLessonRef.current) {
183
+ nextLessonRef.current();
184
+ }
170
185
  }, 1000);
171
186
  }
172
187
  });
173
- } else {
188
+ } else {
174
189
  // This is the last lesson, complete curriculum instead
175
190
  avatarRef.current.speakText(feedbackMessage, {
176
191
  lipsyncLang: defaultAvatarConfig.lipsyncLang,
@@ -183,7 +198,7 @@ const CurriculumLearning = forwardRef(({
183
198
  });
184
199
  }
185
200
  }
186
- }, [animations.lessonComplete, curriculum, nextLesson, completeCurriculum, defaultAvatarConfig]);
201
+ }, [animations.lessonComplete, curriculum, completeCurriculum, defaultAvatarConfig]);
187
202
 
188
203
  // Complete entire curriculum
189
204
  const completeCurriculum = useCallback(() => {
@@ -337,13 +352,15 @@ const CurriculumLearning = forwardRef(({
337
352
 
338
353
  // Automatically start teaching the next lesson after a brief pause
339
354
  setTimeout(() => {
340
- startTeaching();
355
+ if (startTeachingRef.current) {
356
+ startTeachingRef.current();
357
+ }
341
358
  }, 500);
342
359
  }
343
360
  } else {
344
361
  completeCurriculum();
345
362
  }
346
- }, [curriculum, completeCurriculum, startTeaching]);
363
+ }, [curriculum, completeCurriculum]);
347
364
 
348
365
  // Start teaching the lesson
349
366
  const startTeaching = useCallback(() => {
@@ -391,11 +408,14 @@ const CurriculumLearning = forwardRef(({
391
408
  if (currentLesson.questions && currentLesson.questions.length > 0) {
392
409
  startQuestions();
393
410
  } else {
394
- completeLesson();
411
+ // No questions, complete the lesson using ref to avoid circular dependency
412
+ if (completeLessonRef.current) {
413
+ completeLessonRef.current();
414
+ }
395
415
  }
396
416
  }, 8000);
397
417
  }
398
- }, [animations.teaching, getCurrentLesson, startQuestions, completeLesson, defaultAvatarConfig]);
418
+ }, [animations.teaching, getCurrentLesson, startQuestions, defaultAvatarConfig]);
399
419
 
400
420
  // Handle answer selection
401
421
  const handleAnswerSelect = useCallback((answer) => {
@@ -537,6 +557,13 @@ const CurriculumLearning = forwardRef(({
537
557
  }
538
558
  }, [autoStart, getCurrentLesson, startTeaching]);
539
559
 
560
+ // Update refs after all functions are defined to avoid circular dependency issues
561
+ useEffect(() => {
562
+ startTeachingRef.current = startTeaching;
563
+ nextLessonRef.current = nextLesson;
564
+ completeLessonRef.current = completeLesson;
565
+ }, [startTeaching, nextLesson, completeLesson]);
566
+
540
567
  // Expose methods via ref (for external control)
541
568
  useImperativeHandle(ref, () => ({
542
569
  // Curriculum control methods