@peerbots/face 0.0.0-stage → 0.1.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 (50) hide show
  1. package/README.md +30 -2
  2. package/dist/VizijFaceView-3fvAa51G.d.ts +57 -0
  3. package/dist/chunk-AT25NYX2.js +211 -0
  4. package/dist/chunk-AT25NYX2.js.map +1 -0
  5. package/dist/chunk-T7QJ6B66.js +1475 -0
  6. package/dist/chunk-T7QJ6B66.js.map +1 -0
  7. package/dist/chunk-XHICGN32.js +62 -0
  8. package/dist/chunk-XHICGN32.js.map +1 -0
  9. package/dist/index.cjs +4353 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.ts +525 -0
  12. package/dist/index.js +1408 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/pixi.cjs +2403 -0
  15. package/dist/pixi.cjs.map +1 -0
  16. package/dist/pixi.d.ts +9 -0
  17. package/dist/pixi.js +882 -0
  18. package/dist/pixi.js.map +1 -0
  19. package/dist/vizij.cjs +1546 -0
  20. package/dist/vizij.cjs.map +1 -0
  21. package/dist/vizij.d.ts +2 -0
  22. package/dist/vizij.js +193 -0
  23. package/dist/vizij.js.map +1 -0
  24. package/package.json +114 -4
  25. package/public/FaceAssets/Hugo/cheek.png +0 -0
  26. package/public/FaceAssets/Hugo/concerned_l.png +0 -0
  27. package/public/FaceAssets/Hugo/concerned_r.png +0 -0
  28. package/public/FaceAssets/Hugo/happy_l.png +0 -0
  29. package/public/FaceAssets/Hugo/happy_r.png +0 -0
  30. package/public/FaceAssets/Hugo/hugo_spritesheet.json +97 -0
  31. package/public/FaceAssets/Hugo/hugo_spritesheet.png +0 -0
  32. package/public/FaceAssets/Hugo/neutral_l.png +0 -0
  33. package/public/FaceAssets/Hugo/neutral_r.png +0 -0
  34. package/public/FaceAssets/Hugo/sad_l.png +0 -0
  35. package/public/FaceAssets/Hugo/sad_r.png +0 -0
  36. package/public/FaceAssets/Hugo/sleepy_l.png +0 -0
  37. package/public/FaceAssets/Hugo/sleepy_r.png +0 -0
  38. package/public/FaceAssets/Hugo/surprised_l.png +0 -0
  39. package/public/FaceAssets/Hugo/surprised_r.png +0 -0
  40. package/public/FaceAssets/Icons/Concerned.png +0 -0
  41. package/public/FaceAssets/Icons/Neutral.png +0 -0
  42. package/public/FaceAssets/Icons/Sad.png +0 -0
  43. package/public/FaceAssets/Icons/Sleep.png +0 -0
  44. package/public/FaceAssets/Icons/Surprised.png +0 -0
  45. package/public/FaceAssets/Misty/misty_spritesheet.json +97 -0
  46. package/public/FaceAssets/Misty/misty_spritesheet.png +0 -0
  47. package/public/FaceAssets/Robotic/robotic_spritesheet.json +97 -0
  48. package/public/FaceAssets/Robotic/robotic_spritesheet.png +0 -0
  49. package/public/FaceAssets/Vizij/Hugo.glb +0 -0
  50. package/public/FaceAssets/Vizij/brand.svg +15 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,4353 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __esm = (fn, res) => function __init() {
7
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
+ };
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
22
+
23
+ // src/types/face.ts
24
+ function normalizeAssetBaseUrl(assetBaseUrl = "/FaceAssets") {
25
+ const trimmed = assetBaseUrl.trim();
26
+ if (!trimmed) {
27
+ return "/FaceAssets";
28
+ }
29
+ return trimmed.endsWith("/") ? trimmed.slice(0, -1) : trimmed;
30
+ }
31
+ function createBuiltInPixiFaces(assetBaseUrl) {
32
+ const base = normalizeAssetBaseUrl(assetBaseUrl);
33
+ return [
34
+ {
35
+ kind: "PixiFace",
36
+ type: "avatar",
37
+ name: "Hugo",
38
+ mouth: "Hugo",
39
+ eyes: {
40
+ kind: "spritesheet",
41
+ path: `${base}/Hugo/hugo_spritesheet.json`
42
+ },
43
+ cheeks: {
44
+ kind: "texture",
45
+ path: `${base}/Hugo/cheek.png`
46
+ },
47
+ eyebrows: "Hugo"
48
+ },
49
+ {
50
+ kind: "PixiFace",
51
+ type: "avatar",
52
+ name: "Simple",
53
+ mouth: "Ellipse",
54
+ eyes: {
55
+ kind: "spritesheet",
56
+ path: `${base}/Hugo/hugo_spritesheet.json`
57
+ },
58
+ cheeks: null,
59
+ eyebrows: null
60
+ },
61
+ {
62
+ kind: "PixiFace",
63
+ type: "avatar",
64
+ name: "Robotic",
65
+ mouth: "ZigZag",
66
+ eyes: {
67
+ kind: "spritesheet",
68
+ path: `${base}/Robotic/robotic_spritesheet.json`
69
+ },
70
+ cheeks: null,
71
+ eyebrows: null
72
+ },
73
+ {
74
+ kind: "PixiFace",
75
+ type: "text",
76
+ name: "Display",
77
+ showEmotion: "emoticon",
78
+ showText: true
79
+ }
80
+ ];
81
+ }
82
+ function createCustomVizijFace(glbUrl = "") {
83
+ return {
84
+ kind: "Vizij",
85
+ name: "Custom Face",
86
+ assetBundle: {
87
+ namespace: "custom",
88
+ glb: {
89
+ kind: "url",
90
+ src: glbUrl,
91
+ aggressiveImport: true
92
+ }
93
+ }
94
+ };
95
+ }
96
+ function createIncludedVizijFaces(assetBaseUrl) {
97
+ const base = normalizeAssetBaseUrl(assetBaseUrl);
98
+ return [
99
+ {
100
+ kind: "Vizij",
101
+ name: "Hugo - Expressive",
102
+ assetBundle: {
103
+ namespace: "hugo",
104
+ glb: {
105
+ kind: "url",
106
+ src: `${base}/Vizij/Hugo.glb`,
107
+ aggressiveImport: true
108
+ }
109
+ }
110
+ },
111
+ createCustomVizijFace("")
112
+ ];
113
+ }
114
+ function createBuiltInFaces(assetBaseUrl) {
115
+ return [
116
+ ...createBuiltInPixiFaces(assetBaseUrl),
117
+ ...createIncludedVizijFaces(assetBaseUrl)
118
+ ];
119
+ }
120
+ var PEERBOTS_COLORS, PEERBOTS_EMOTIONS, DEFAULT_FACE_MESSAGE, CONNECTION_FACE_MESSAGE, defaultFaceSettings, builtInFaces, customFace, includedVizijFaces, availableFaces, defaultFace, getFaceCapabilities;
121
+ var init_face = __esm({
122
+ "src/types/face.ts"() {
123
+ "use strict";
124
+ PEERBOTS_COLORS = [
125
+ "Light Blue",
126
+ "Blue",
127
+ "Green",
128
+ "Red",
129
+ "Purple",
130
+ "Pink",
131
+ "Yellow",
132
+ "Orange",
133
+ "Grey",
134
+ "Black",
135
+ "White"
136
+ ];
137
+ PEERBOTS_EMOTIONS = [
138
+ "Neutral",
139
+ "Surprised",
140
+ "Happy",
141
+ "Sad",
142
+ "Concerned",
143
+ "Sleepy"
144
+ ];
145
+ DEFAULT_FACE_MESSAGE = {
146
+ title: "Ready",
147
+ speech: "",
148
+ color: "Light Blue",
149
+ emotion: "Neutral"
150
+ };
151
+ CONNECTION_FACE_MESSAGE = {
152
+ title: "Connecting",
153
+ speech: "Connecting",
154
+ color: "Light Blue",
155
+ emotion: "Neutral"
156
+ };
157
+ defaultFaceSettings = {
158
+ zoom: 1,
159
+ offset: { x: 0, y: 0 },
160
+ rotation: 0,
161
+ autoRotate: true,
162
+ showFullScreenButton: true,
163
+ showScrollButton: true,
164
+ amplitudeGain: 1,
165
+ vizijSettings: {
166
+ faceExpressivity: 1
167
+ },
168
+ pixiSettings: {
169
+ eyeDisplay: "default",
170
+ mouthDisplay: "default",
171
+ cheekDisplay: "default",
172
+ emotionDisplay: "emoticon"
173
+ },
174
+ selectedLanguage: "English",
175
+ speechQueueMode: "interrupt",
176
+ captions: {
177
+ enabled: false,
178
+ fontSize: 32,
179
+ offset: { x: 0, y: 0 }
180
+ }
181
+ };
182
+ builtInFaces = createBuiltInPixiFaces();
183
+ customFace = createCustomVizijFace();
184
+ includedVizijFaces = createIncludedVizijFaces();
185
+ availableFaces = [...builtInFaces, ...includedVizijFaces];
186
+ defaultFace = builtInFaces[0];
187
+ getFaceCapabilities = (face) => {
188
+ if (!face) {
189
+ return {
190
+ canExpressColor: false,
191
+ canExpressEmotion: false,
192
+ canLipSync: false
193
+ };
194
+ }
195
+ if (face.kind === "PixiFace" && "type" in face) {
196
+ const pixiFace = face;
197
+ if (pixiFace.type === "avatar") {
198
+ return {
199
+ canExpressColor: "Background Color Change",
200
+ canExpressEmotion: "Image Swap",
201
+ canLipSync: pixiFace.mouth === "ZigZag" ? "Random mouth motions" : "Timed mouth motions"
202
+ };
203
+ }
204
+ if (pixiFace.type === "text") {
205
+ return {
206
+ canExpressColor: "Background Color Change",
207
+ canExpressEmotion: pixiFace.showEmotion === "none" ? false : pixiFace.showEmotion,
208
+ canLipSync: "Cursor movement"
209
+ };
210
+ }
211
+ }
212
+ if (face.kind === "Vizij") {
213
+ return {
214
+ canExpressColor: "Background Color Change",
215
+ canExpressEmotion: "Animated Expression",
216
+ canLipSync: "Lip-sync or random mouth motions"
217
+ };
218
+ }
219
+ return {
220
+ canExpressColor: false,
221
+ canExpressEmotion: false,
222
+ canLipSync: false
223
+ };
224
+ };
225
+ }
226
+ });
227
+
228
+ // src/types/labels.ts
229
+ function resolveFaceUiLabels(overrides) {
230
+ if (!overrides) {
231
+ return DEFAULT_FACE_UI_LABELS;
232
+ }
233
+ return {
234
+ ...DEFAULT_FACE_UI_LABELS,
235
+ ...overrides
236
+ };
237
+ }
238
+ var DEFAULT_FACE_UI_LABELS;
239
+ var init_labels = __esm({
240
+ "src/types/labels.ts"() {
241
+ "use strict";
242
+ DEFAULT_FACE_UI_LABELS = {
243
+ loading: "Loading...",
244
+ poweredBy: "Powered by",
245
+ tapToEnableSound: "Tap to enable sound",
246
+ allowSpeech: "Allow Speech",
247
+ characterSelection: "Character & Voice",
248
+ face: "Character",
249
+ uploadGlb: "Upload .GLB Rig",
250
+ vizijUploadGlb: "Upload a .glb file in Face Settings to preview Custom Face",
251
+ vizijErrorPrefix: "3D Face Error:",
252
+ faceCapabilities: "Face Capabilities",
253
+ color: "Color",
254
+ emotion: "Emotion",
255
+ speech: "Speech",
256
+ faceSpecificSettings: "Face-Specific Settings",
257
+ faceExpressivity: "Face Expressivity",
258
+ eyes: "Eyes",
259
+ mouth: "Mouth",
260
+ cheeks: "Cheeks",
261
+ emotionDisplay: "Emotion Display",
262
+ defaultOption: "Default",
263
+ noneOption: "None",
264
+ emoticon: "Emoticon",
265
+ emoji: "Emoji",
266
+ positioning: "Face Positioning",
267
+ autoRotate: "Auto-Rotate",
268
+ rotate: "Rotate 90\xB0",
269
+ reset: "Reset",
270
+ zoom: "Zoom",
271
+ horizontalOffset: "Horizontal Offset",
272
+ verticalOffset: "Vertical Offset",
273
+ faceSettings: "Face Settings",
274
+ onFaceButtons: "On-Face Controls",
275
+ showFullScreenButton: "Show Fullscreen Button",
276
+ showScrollButton: "Show Scroll-to-Top Button",
277
+ speechBehavior: "Speech Playback Behavior",
278
+ newButtonSpeech: "When new speech arrives",
279
+ interruptSpeech: "Interrupt current speech",
280
+ queueSpeech: "Queue after current speech",
281
+ captions: "Captions",
282
+ fontSize: "Caption Font Size",
283
+ verticalPosition: "Vertical Position",
284
+ voiceSelectorLanguage: "Language",
285
+ voiceSelectorVoice: "Voice",
286
+ unknownFaceType: "Unknown Face Type"
287
+ };
288
+ }
289
+ });
290
+
291
+ // src/helpers/viseme_mapper.ts
292
+ function mapVisemeToVizijTarget(viseme) {
293
+ if (Object.prototype.hasOwnProperty.call(pollyVisemeToVizijPath, viseme)) {
294
+ return pollyVisemeToVizijPath[viseme];
295
+ }
296
+ return "";
297
+ }
298
+ function estimateVisemesFromText(text, msPerChar = 65) {
299
+ const cleaned = text.trim();
300
+ if (!cleaned) {
301
+ return [];
302
+ }
303
+ const visemes = [];
304
+ const durationSec = Math.max(0.03, msPerChar / 1e3);
305
+ for (const ch of cleaned.toLowerCase()) {
306
+ const mapped = CHAR_TO_POLLY_VISEME[ch] ?? "sil";
307
+ const prev = visemes[visemes.length - 1];
308
+ if (prev && prev.value === mapped) {
309
+ prev.time = Number((prev.time + durationSec).toFixed(4));
310
+ } else {
311
+ visemes.push({
312
+ time: Number(durationSec.toFixed(4)),
313
+ type: "viseme",
314
+ value: mapped
315
+ });
316
+ }
317
+ }
318
+ if (visemes[visemes.length - 1]?.value !== "sil") {
319
+ visemes.push({
320
+ time: 0.1,
321
+ type: "viseme",
322
+ value: "sil"
323
+ });
324
+ }
325
+ return visemes;
326
+ }
327
+ var pollyVisemeToVizijPath, possiblePollyVisemes, CHAR_TO_POLLY_VISEME;
328
+ var init_viseme_mapper = __esm({
329
+ "src/helpers/viseme_mapper.ts"() {
330
+ "use strict";
331
+ pollyVisemeToVizijPath = {
332
+ "@": "pose_pzzzfnvy",
333
+ a: "a",
334
+ e: "e_2",
335
+ E: "e",
336
+ f: "f",
337
+ i: "i",
338
+ k: "k",
339
+ l: "r",
340
+ o: "o",
341
+ O: "o_2",
342
+ p: "p",
343
+ r: "r",
344
+ s: "s",
345
+ S: "s",
346
+ t: "t",
347
+ T: "t_2",
348
+ u: "u",
349
+ sil: ""
350
+ };
351
+ possiblePollyVisemes = Array.from(
352
+ new Set(Object.values(pollyVisemeToVizijPath).filter((v) => v.length > 0))
353
+ );
354
+ CHAR_TO_POLLY_VISEME = {
355
+ a: "a",
356
+ b: "p",
357
+ c: "k",
358
+ d: "t",
359
+ e: "e",
360
+ f: "f",
361
+ g: "k",
362
+ h: "@",
363
+ i: "i",
364
+ j: "S",
365
+ k: "k",
366
+ l: "l",
367
+ m: "p",
368
+ n: "t",
369
+ o: "o",
370
+ p: "p",
371
+ q: "k",
372
+ r: "r",
373
+ s: "s",
374
+ t: "t",
375
+ u: "u",
376
+ v: "f",
377
+ w: "u",
378
+ x: "s",
379
+ y: "i",
380
+ z: "s"
381
+ };
382
+ }
383
+ });
384
+
385
+ // src/helpers/emotion_mapper.ts
386
+ function getEmotionIconPath(emotion, assetBaseUrl) {
387
+ const base = normalizeAssetBaseUrl(assetBaseUrl);
388
+ const file = EMOTION_ICON_FILES[emotion] ?? EMOTION_ICON_FILES.Neutral;
389
+ return `${base}/Icons/${file}`;
390
+ }
391
+ function getEmotionEyeSpritePaths(emotion, character = "Hugo", assetBaseUrl) {
392
+ const base = normalizeAssetBaseUrl(assetBaseUrl);
393
+ const key = emotion.toLowerCase();
394
+ return {
395
+ left: `${base}/${character}/${key}_l.png`,
396
+ right: `${base}/${character}/${key}_r.png`
397
+ };
398
+ }
399
+ var EMOTION_EMOTICONS, EMOTION_EMOJIS, EMOTION_ICON_FILES, emotion_mapping;
400
+ var init_emotion_mapper = __esm({
401
+ "src/helpers/emotion_mapper.ts"() {
402
+ "use strict";
403
+ init_face();
404
+ EMOTION_EMOTICONS = {
405
+ Happy: ":D",
406
+ Sad: ":(",
407
+ Surprised: ":o",
408
+ Neutral: ":)",
409
+ Sleepy: ":z",
410
+ Concerned: ":/"
411
+ };
412
+ EMOTION_EMOJIS = {
413
+ Happy: "\u{1F600}",
414
+ Sad: "\u{1F622}",
415
+ Surprised: "\u{1F62E}",
416
+ Neutral: "\u{1F610}",
417
+ Sleepy: "\u{1F634}",
418
+ Concerned: "\u{1F61F}"
419
+ };
420
+ EMOTION_ICON_FILES = {
421
+ Neutral: "Neutral.png",
422
+ Surprised: "Surprised.png",
423
+ Happy: "Neutral.png",
424
+ Sad: "Sad.png",
425
+ Concerned: "Concerned.png",
426
+ Sleepy: "Sleep.png"
427
+ };
428
+ emotion_mapping = {
429
+ Neutral: getEmotionIconPath("Neutral"),
430
+ Surprised: getEmotionIconPath("Surprised"),
431
+ Happy: getEmotionIconPath("Happy"),
432
+ Sad: getEmotionIconPath("Sad"),
433
+ Concerned: getEmotionIconPath("Concerned"),
434
+ Sleepy: getEmotionIconPath("Sleepy")
435
+ };
436
+ }
437
+ });
438
+
439
+ // src/helpers/color_mappers.ts
440
+ function hexToRgb(hex) {
441
+ const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
442
+ const expanded = hex.replace(shorthandRegex, (_m, r, g, b) => {
443
+ return r + r + g + g + b + b;
444
+ });
445
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(expanded);
446
+ return result ? {
447
+ r: parseInt(result[1], 16),
448
+ g: parseInt(result[2], 16),
449
+ b: parseInt(result[3], 16)
450
+ } : null;
451
+ }
452
+ function rgbaToHex(orig) {
453
+ const rgb = orig.replace(/\s/g, "").match(/^rgba?\((\d+),(\d+),(\d+),?([^,\s)]+)?/i);
454
+ if (!rgb) {
455
+ return orig;
456
+ }
457
+ const alphaStr = (rgb[4] || "").trim();
458
+ const hexRgb = (Number(rgb[1]) | 1 << 8).toString(16).slice(1) + (Number(rgb[2]) | 1 << 8).toString(16).slice(1) + (Number(rgb[3]) | 1 << 8).toString(16).slice(1);
459
+ const numericAlpha = alphaStr !== "" ? Number(alphaStr) : 1;
460
+ const clampedAlpha = Math.max(0, Math.min(1, Number.isNaN(numericAlpha) ? 1 : numericAlpha));
461
+ const hexAlpha = (Math.round(clampedAlpha * 255) | 1 << 8).toString(16).slice(1);
462
+ return hexRgb + hexAlpha;
463
+ }
464
+ var color_mapping, font_color_mapping, hexToRgba, rgbToRgba, rbgToRgba, deconstructRgba, formatRgba, formatRbga, interpolateColor;
465
+ var init_color_mappers = __esm({
466
+ "src/helpers/color_mappers.ts"() {
467
+ "use strict";
468
+ color_mapping = {
469
+ "Light Blue": "#ABE3FA",
470
+ Blue: "#5F94D6",
471
+ Green: "#65C77D",
472
+ Red: "#E6817E",
473
+ Purple: "#9B86F3",
474
+ Pink: "#EBA4E4",
475
+ Yellow: "#F8EDB1",
476
+ Orange: "#E6A575",
477
+ Grey: "#CECECE",
478
+ Black: "#4D4D4D",
479
+ White: "#FDFEFE"
480
+ };
481
+ font_color_mapping = {
482
+ "Light Blue": "#020307",
483
+ Blue: "#020307",
484
+ Green: "#020307",
485
+ Red: "#020307",
486
+ Purple: "#020307",
487
+ Pink: "#020307",
488
+ Yellow: "#020307",
489
+ Orange: "#020307",
490
+ Grey: "#020307",
491
+ Black: "#FDFEFE",
492
+ White: "#020307"
493
+ };
494
+ hexToRgba = (color, alpha = 1) => {
495
+ const rgb = hexToRgb(color);
496
+ if (rgb !== null) {
497
+ return `rgba(${rgb.r},${rgb.g},${rgb.b},${alpha})`;
498
+ }
499
+ return null;
500
+ };
501
+ rgbToRgba = (color, alpha = 1) => {
502
+ const [r = "0", g = "0", b = "0"] = color.replace(/[^\d,]/g, "").split(",");
503
+ return `rgba(${r},${g},${b},${alpha})`;
504
+ };
505
+ rbgToRgba = rgbToRgba;
506
+ deconstructRgba = (rgba) => {
507
+ return rgba.replace(/[^\d.,]/g, "").split(",").map((x) => Number(x));
508
+ };
509
+ formatRgba = (color) => {
510
+ return `rgba(${color.r},${color.g},${color.b},${color.a})`;
511
+ };
512
+ formatRbga = formatRgba;
513
+ interpolateColor = (colorA, colorB, progress) => {
514
+ const rgbaColorA = hexToRgba(colorA);
515
+ const rgbaColorB = hexToRgba(colorB);
516
+ if (rgbaColorA && rgbaColorB) {
517
+ const [r1, g1, b1, a1] = deconstructRgba(rgbaColorA);
518
+ const [r2, g2, b2, a2] = deconstructRgba(rgbaColorB);
519
+ const clampedProgress = Math.max(0, Math.min(1, progress));
520
+ return formatRgba({
521
+ r: Math.round(r1 + (r2 - r1) * clampedProgress),
522
+ g: Math.round(g1 + (g2 - g1) * clampedProgress),
523
+ b: Math.round(b1 + (b2 - b1) * clampedProgress),
524
+ a: Number((a1 + (a2 - a1) * clampedProgress).toFixed(3))
525
+ });
526
+ }
527
+ return null;
528
+ };
529
+ }
530
+ });
531
+
532
+ // src/helpers/voice_helpers.ts
533
+ function getLanguageName(code) {
534
+ if (!code) {
535
+ return "";
536
+ }
537
+ try {
538
+ const baseCode = code.split("-")[0];
539
+ if (!baseCode || !languageDisplayNames) {
540
+ return code;
541
+ }
542
+ return languageDisplayNames.of(baseCode) || code;
543
+ } catch (err) {
544
+ void err;
545
+ return code;
546
+ }
547
+ }
548
+ function formatVoiceDisplayName(rawName) {
549
+ if (!rawName) return "";
550
+ let name = rawName.replace(/^AWS - /, "").trim();
551
+ if (name.startsWith("aws:")) {
552
+ const parts = name.split(":");
553
+ name = parts[1] || name.slice(4);
554
+ }
555
+ if (!name.includes("com.apple.") && !name.includes("com.google.")) {
556
+ return name;
557
+ }
558
+ if (name.includes("com.google.")) {
559
+ const afterColon = name.split(":").pop() || name;
560
+ return afterColon.replace(/[-_]/g, " ").trim();
561
+ }
562
+ const siriMatch = name.match(
563
+ /siri_([a-zA-Z]+)_[a-zA-Z0-9-_]+?(?:_(compact|premium|enhanced))?$/i
564
+ );
565
+ if (siriMatch) {
566
+ const gender = siriMatch[1].charAt(0).toUpperCase() + siriMatch[1].slice(1).toLowerCase();
567
+ const quality = siriMatch[2] && siriMatch[2].toLowerCase() !== "compact" ? ` (${siriMatch[2].charAt(0).toUpperCase() + siriMatch[2].slice(1).toLowerCase()})` : "";
568
+ return `Siri ${gender}${quality}`;
569
+ }
570
+ const ttsMatch = name.match(
571
+ /com\.apple\.ttsbundle\.([a-zA-Z0-9]+)(?:-(compact|premium|enhanced))?/i
572
+ );
573
+ if (ttsMatch) {
574
+ const base = ttsMatch[1].replace(/([a-z])([A-Z])/g, "$1 $2");
575
+ const quality = ttsMatch[2] && ttsMatch[2].toLowerCase() !== "compact" ? ` (${ttsMatch[2].charAt(0).toUpperCase() + ttsMatch[2].slice(1).toLowerCase()})` : "";
576
+ return `${base}${quality}`;
577
+ }
578
+ const speechMatch = name.match(
579
+ /com\.apple\.speech\.synthesis\.voice\.([a-zA-Z0-9_-]+)/i
580
+ );
581
+ if (speechMatch) {
582
+ return speechMatch[1].replace(/([a-z])([A-Z])/g, "$1 $2");
583
+ }
584
+ const tierMatch = name.match(
585
+ /com\.apple\.voice\.(compact|enhanced|premium)\.[^.]+\.([a-zA-Z0-9_-]+)/i
586
+ );
587
+ if (tierMatch) {
588
+ const base = tierMatch[2].replace(/([a-z])([A-Z])/g, "$1 $2");
589
+ const quality = tierMatch[1].toLowerCase() !== "compact" ? ` (${tierMatch[1].charAt(0).toUpperCase() + tierMatch[1].slice(1).toLowerCase()})` : "";
590
+ return `${base}${quality}`;
591
+ }
592
+ const eloquenceMatch = name.match(
593
+ /com\.apple\.eloquence\.[^.]+\.([a-zA-Z0-9_-]+)/i
594
+ );
595
+ if (eloquenceMatch) {
596
+ return eloquenceMatch[1].replace(/([a-z])([A-Z])/g, "$1 $2");
597
+ }
598
+ const segments = name.split(".");
599
+ let last = segments[segments.length - 1] || name;
600
+ last = last.replace(/[-_](compact|premium|enhanced)$/i, "");
601
+ last = last.replace(/([a-z])([A-Z])/g, "$1 $2");
602
+ last = last.replace(/[-_]/g, " ").trim();
603
+ return last || name;
604
+ }
605
+ function findMatchingVoice(voices, target) {
606
+ if (!target) return void 0;
607
+ const directUri = voices.find((v) => v.voiceURI === target);
608
+ if (directUri) return directUri;
609
+ const directName = voices.find((v) => v.name === target);
610
+ if (directName) return directName;
611
+ const targetClean = formatVoiceDisplayName(target).toLowerCase();
612
+ const cleanMatch = voices.find(
613
+ (v) => formatVoiceDisplayName(v.name).toLowerCase() === targetClean || formatVoiceDisplayName(v.voiceURI).toLowerCase() === targetClean
614
+ );
615
+ if (cleanMatch) return cleanMatch;
616
+ const lowerTarget = target.toLowerCase();
617
+ return voices.find(
618
+ (v) => v.voiceURI.toLowerCase() === lowerTarget || v.name.toLowerCase() === lowerTarget
619
+ );
620
+ }
621
+ var languageDisplayNames;
622
+ var init_voice_helpers = __esm({
623
+ "src/helpers/voice_helpers.ts"() {
624
+ "use strict";
625
+ languageDisplayNames = typeof Intl !== "undefined" && typeof Intl.DisplayNames === "function" ? new Intl.DisplayNames(["en"], { type: "language" }) : null;
626
+ }
627
+ });
628
+
629
+ // src/services/AudioAnalyzer.ts
630
+ var AudioAnalyzer, audioAnalyzer;
631
+ var init_AudioAnalyzer = __esm({
632
+ "src/services/AudioAnalyzer.ts"() {
633
+ "use strict";
634
+ AudioAnalyzer = class {
635
+ ctx = null;
636
+ analyzer = null;
637
+ data = null;
638
+ connectedElements = /* @__PURE__ */ new WeakSet();
639
+ connect(audio) {
640
+ if (typeof window === "undefined") {
641
+ return;
642
+ }
643
+ const AudioContextCtor = window.AudioContext || window.webkitAudioContext;
644
+ if (!AudioContextCtor) {
645
+ return;
646
+ }
647
+ try {
648
+ if (!this.ctx) {
649
+ this.ctx = new AudioContextCtor();
650
+ this.analyzer = this.ctx.createAnalyser();
651
+ this.analyzer.fftSize = 256;
652
+ this.data = new Uint8Array(new ArrayBuffer(this.analyzer.frequencyBinCount));
653
+ }
654
+ if (!this.connectedElements.has(audio) && this.analyzer) {
655
+ const source = this.ctx.createMediaElementSource(audio);
656
+ source.connect(this.analyzer);
657
+ this.analyzer.connect(this.ctx.destination);
658
+ this.connectedElements.add(audio);
659
+ }
660
+ } catch (error) {
661
+ console.warn("AudioAnalyzer connect error:", error);
662
+ }
663
+ }
664
+ getAmplitude() {
665
+ if (!this.analyzer || !this.data) {
666
+ return 0;
667
+ }
668
+ this.analyzer.getByteTimeDomainData(this.data);
669
+ let sum = 0;
670
+ for (const v of this.data) {
671
+ const normalized = (v - 128) / 128;
672
+ sum += normalized * normalized;
673
+ }
674
+ return Math.sqrt(sum / this.data.length);
675
+ }
676
+ };
677
+ audioAnalyzer = new AudioAnalyzer();
678
+ }
679
+ });
680
+
681
+ // src/services/ttsAudioCache.ts
682
+ function buildTtsCacheKey(params) {
683
+ const voice = params.voiceId.trim();
684
+ const engine = (params.engine ?? "default").trim() || "default";
685
+ const normalizedText = params.text.trim();
686
+ if (params.rate === void 0 && params.pitch === void 0) {
687
+ return `${voice}:${engine}:${normalizedText}`;
688
+ }
689
+ const rate = params.rate ?? 1;
690
+ const pitch = params.pitch ?? 1;
691
+ return `${voice}:${engine}:${rate}:${pitch}:${normalizedText}`;
692
+ }
693
+ async function blobToArrayBuffer(blob) {
694
+ if (typeof blob.arrayBuffer === "function") {
695
+ return blob.arrayBuffer();
696
+ }
697
+ return new Promise((resolve, reject) => {
698
+ const reader = new FileReader();
699
+ reader.onload = () => {
700
+ if (reader.result instanceof ArrayBuffer) {
701
+ resolve(reader.result);
702
+ } else {
703
+ reject(new Error("Failed to read Blob as ArrayBuffer"));
704
+ }
705
+ };
706
+ reader.onerror = () => {
707
+ reject(reader.error ?? new Error("FileReader error"));
708
+ };
709
+ reader.readAsArrayBuffer(blob);
710
+ });
711
+ }
712
+ var TtsAudioCache, defaultTtsAudioCache;
713
+ var init_ttsAudioCache = __esm({
714
+ "src/services/ttsAudioCache.ts"() {
715
+ "use strict";
716
+ TtsAudioCache = class {
717
+ maxEntries;
718
+ enableIndexedDb;
719
+ dbName;
720
+ storeName;
721
+ memory = /* @__PURE__ */ new Map();
722
+ dbPromise = null;
723
+ constructor(options = {}) {
724
+ this.maxEntries = Math.max(1, options.maxEntries ?? 100);
725
+ this.enableIndexedDb = options.enableIndexedDb ?? true;
726
+ this.dbName = options.dbName ?? "peerbots-tts-cache";
727
+ this.storeName = options.storeName ?? "entries";
728
+ }
729
+ get size() {
730
+ return this.memory.size;
731
+ }
732
+ hasInMemory(key) {
733
+ return this.memory.has(key);
734
+ }
735
+ async get(key) {
736
+ const existing = this.memory.get(key);
737
+ if (existing) {
738
+ this.memory.delete(key);
739
+ this.memory.set(key, existing);
740
+ return existing;
741
+ }
742
+ const fromIdb = await this.readFromIndexedDb(key);
743
+ if (fromIdb) {
744
+ this.putInMemory(key, fromIdb);
745
+ return fromIdb;
746
+ }
747
+ return void 0;
748
+ }
749
+ async set(key, entry) {
750
+ const fullEntry = {
751
+ ...entry,
752
+ createdAt: entry.createdAt ?? Date.now()
753
+ };
754
+ this.putInMemory(key, fullEntry);
755
+ await this.writeToIndexedDb(key, fullEntry);
756
+ }
757
+ async delete(key) {
758
+ const removedMem = this.memory.delete(key);
759
+ const removedIdb = await this.deleteFromIndexedDb(key);
760
+ return removedMem || removedIdb;
761
+ }
762
+ async clear() {
763
+ this.memory.clear();
764
+ await this.clearIndexedDb();
765
+ }
766
+ createObjectUrl(entry) {
767
+ return URL.createObjectURL(entry.audioBlob);
768
+ }
769
+ putInMemory(key, entry) {
770
+ if (this.memory.has(key)) {
771
+ this.memory.delete(key);
772
+ }
773
+ this.memory.set(key, entry);
774
+ while (this.memory.size > this.maxEntries) {
775
+ const oldestKey = this.memory.keys().next().value;
776
+ if (oldestKey !== void 0) {
777
+ this.memory.delete(oldestKey);
778
+ } else {
779
+ break;
780
+ }
781
+ }
782
+ }
783
+ openDatabase() {
784
+ if (!this.enableIndexedDb || typeof indexedDB === "undefined") {
785
+ return Promise.resolve(null);
786
+ }
787
+ if (this.dbPromise) {
788
+ return this.dbPromise;
789
+ }
790
+ this.dbPromise = new Promise((resolve) => {
791
+ try {
792
+ const request = indexedDB.open(this.dbName, 1);
793
+ request.onupgradeneeded = () => {
794
+ const db = request.result;
795
+ if (!db.objectStoreNames.contains(this.storeName)) {
796
+ db.createObjectStore(this.storeName, { keyPath: "key" });
797
+ }
798
+ };
799
+ request.onsuccess = () => resolve(request.result);
800
+ request.onerror = () => resolve(null);
801
+ } catch (err) {
802
+ void err;
803
+ resolve(null);
804
+ }
805
+ });
806
+ return this.dbPromise;
807
+ }
808
+ async readFromIndexedDb(key) {
809
+ const db = await this.openDatabase();
810
+ if (!db) {
811
+ return void 0;
812
+ }
813
+ return new Promise((resolve) => {
814
+ try {
815
+ const tx = db.transaction(this.storeName, "readonly");
816
+ const store = tx.objectStore(this.storeName);
817
+ const req = store.get(key);
818
+ req.onsuccess = () => {
819
+ const record = req.result;
820
+ if (!record || !record.audioBuffer) {
821
+ resolve(void 0);
822
+ return;
823
+ }
824
+ resolve({
825
+ audioBlob: new Blob([record.audioBuffer], {
826
+ type: record.mimeType || "audio/mpeg"
827
+ }),
828
+ mimeType: record.mimeType || "audio/mpeg",
829
+ visemes: record.visemes,
830
+ amplitudeData: record.amplitudeData,
831
+ extrema: record.extrema,
832
+ createdAt: record.createdAt
833
+ });
834
+ };
835
+ req.onerror = () => resolve(void 0);
836
+ } catch (err) {
837
+ void err;
838
+ resolve(void 0);
839
+ }
840
+ });
841
+ }
842
+ async writeToIndexedDb(key, entry) {
843
+ const db = await this.openDatabase();
844
+ if (!db) {
845
+ return;
846
+ }
847
+ try {
848
+ const audioBuffer = await blobToArrayBuffer(entry.audioBlob);
849
+ await new Promise((resolve) => {
850
+ const tx = db.transaction(this.storeName, "readwrite");
851
+ const store = tx.objectStore(this.storeName);
852
+ const record = {
853
+ key,
854
+ audioBuffer,
855
+ mimeType: entry.mimeType,
856
+ visemes: entry.visemes,
857
+ amplitudeData: entry.amplitudeData,
858
+ extrema: entry.extrema,
859
+ createdAt: entry.createdAt
860
+ };
861
+ const req = store.put(record);
862
+ req.onsuccess = () => resolve();
863
+ req.onerror = () => resolve();
864
+ });
865
+ } catch (err) {
866
+ void err;
867
+ }
868
+ }
869
+ async deleteFromIndexedDb(key) {
870
+ const db = await this.openDatabase();
871
+ if (!db) {
872
+ return false;
873
+ }
874
+ return new Promise((resolve) => {
875
+ try {
876
+ const tx = db.transaction(this.storeName, "readwrite");
877
+ const store = tx.objectStore(this.storeName);
878
+ const req = store.delete(key);
879
+ req.onsuccess = () => resolve(true);
880
+ req.onerror = () => resolve(false);
881
+ } catch (err) {
882
+ void err;
883
+ resolve(false);
884
+ }
885
+ });
886
+ }
887
+ async clearIndexedDb() {
888
+ const db = await this.openDatabase();
889
+ if (!db) {
890
+ return;
891
+ }
892
+ await new Promise((resolve) => {
893
+ try {
894
+ const tx = db.transaction(this.storeName, "readwrite");
895
+ const store = tx.objectStore(this.storeName);
896
+ const req = store.clear();
897
+ req.onsuccess = () => resolve();
898
+ req.onerror = () => resolve();
899
+ } catch (err) {
900
+ void err;
901
+ resolve();
902
+ }
903
+ });
904
+ }
905
+ };
906
+ defaultTtsAudioCache = new TtsAudioCache();
907
+ }
908
+ });
909
+
910
+ // src/hooks/useMessageVisualState.ts
911
+ function useMessageVisualState(isSpeaking, config = {}) {
912
+ const {
913
+ msPerChar = 50,
914
+ persistenceDuration = 3e3,
915
+ pauseBeforeNextMsg = 500
916
+ } = config;
917
+ const [displayText, setDisplayText] = (0, import_react.useState)("");
918
+ const [visualState, setVisualState] = (0, import_react.useState)("IDLE");
919
+ const stateRef = (0, import_react.useRef)("IDLE");
920
+ const displayTextRef = (0, import_react.useRef)("");
921
+ const currentMsgRef = (0, import_react.useRef)(null);
922
+ const nextMsgRef = (0, import_react.useRef)(null);
923
+ const timerRef = (0, import_react.useRef)(0);
924
+ const charTimerRef = (0, import_react.useRef)(0);
925
+ const typingIndexRef = (0, import_react.useRef)(0);
926
+ const startShowing = (0, import_react.useCallback)(
927
+ (speech) => {
928
+ currentMsgRef.current = speech;
929
+ nextMsgRef.current = null;
930
+ stateRef.current = "SHOWING";
931
+ setVisualState("SHOWING");
932
+ typingIndexRef.current = 0;
933
+ charTimerRef.current = 0;
934
+ if (msPerChar <= 0) {
935
+ setDisplayText(speech);
936
+ displayTextRef.current = speech;
937
+ typingIndexRef.current = speech.length;
938
+ } else {
939
+ setDisplayText("");
940
+ displayTextRef.current = "";
941
+ }
942
+ },
943
+ [msPerChar]
944
+ );
945
+ const queueMessage = (0, import_react.useCallback)(
946
+ (speech) => {
947
+ if (stateRef.current === "IDLE" || stateRef.current === "PERSISTING") {
948
+ startShowing(speech);
949
+ return;
950
+ }
951
+ nextMsgRef.current = speech;
952
+ },
953
+ [startShowing]
954
+ );
955
+ const update = (0, import_react.useCallback)(
956
+ (ms) => {
957
+ const prevState = stateRef.current;
958
+ switch (stateRef.current) {
959
+ case "IDLE":
960
+ if (displayTextRef.current !== "") {
961
+ setDisplayText("");
962
+ displayTextRef.current = "";
963
+ }
964
+ if (nextMsgRef.current) {
965
+ startShowing(nextMsgRef.current);
966
+ }
967
+ break;
968
+ case "SHOWING":
969
+ if (!currentMsgRef.current) {
970
+ stateRef.current = "IDLE";
971
+ break;
972
+ }
973
+ if (msPerChar <= 0) {
974
+ if (nextMsgRef.current) {
975
+ stateRef.current = "PAUSED";
976
+ timerRef.current = 0;
977
+ } else {
978
+ stateRef.current = "WAITING_FOR_AUDIO";
979
+ }
980
+ break;
981
+ }
982
+ charTimerRef.current += ms;
983
+ if (charTimerRef.current > msPerChar) {
984
+ const fullText = currentMsgRef.current;
985
+ const charCountToAdd = Math.floor(charTimerRef.current / msPerChar);
986
+ charTimerRef.current %= msPerChar;
987
+ const nextIndex = typingIndexRef.current + charCountToAdd;
988
+ if (nextIndex >= fullText.length) {
989
+ setDisplayText(fullText);
990
+ displayTextRef.current = fullText;
991
+ typingIndexRef.current = fullText.length;
992
+ if (nextMsgRef.current) {
993
+ stateRef.current = "PAUSED";
994
+ timerRef.current = 0;
995
+ } else {
996
+ stateRef.current = "WAITING_FOR_AUDIO";
997
+ }
998
+ } else {
999
+ typingIndexRef.current = nextIndex;
1000
+ const partial = fullText.substring(0, nextIndex);
1001
+ setDisplayText(partial);
1002
+ displayTextRef.current = partial;
1003
+ }
1004
+ }
1005
+ break;
1006
+ case "WAITING_FOR_AUDIO":
1007
+ if (nextMsgRef.current) {
1008
+ stateRef.current = "PAUSED";
1009
+ timerRef.current = 0;
1010
+ break;
1011
+ }
1012
+ if (!isSpeaking) {
1013
+ stateRef.current = "PERSISTING";
1014
+ timerRef.current = 0;
1015
+ }
1016
+ break;
1017
+ case "PERSISTING":
1018
+ if (nextMsgRef.current) {
1019
+ stateRef.current = "PAUSED";
1020
+ timerRef.current = 0;
1021
+ break;
1022
+ }
1023
+ timerRef.current += ms;
1024
+ if (timerRef.current > persistenceDuration) {
1025
+ stateRef.current = "IDLE";
1026
+ }
1027
+ break;
1028
+ case "PAUSED":
1029
+ timerRef.current += ms;
1030
+ if (timerRef.current > pauseBeforeNextMsg) {
1031
+ if (nextMsgRef.current) {
1032
+ startShowing(nextMsgRef.current);
1033
+ } else {
1034
+ stateRef.current = "WAITING_FOR_AUDIO";
1035
+ }
1036
+ }
1037
+ break;
1038
+ }
1039
+ if (stateRef.current !== prevState) {
1040
+ setVisualState(stateRef.current);
1041
+ }
1042
+ },
1043
+ [
1044
+ isSpeaking,
1045
+ msPerChar,
1046
+ persistenceDuration,
1047
+ pauseBeforeNextMsg,
1048
+ startShowing
1049
+ ]
1050
+ );
1051
+ return {
1052
+ displayText,
1053
+ visualState,
1054
+ queueMessage,
1055
+ update
1056
+ };
1057
+ }
1058
+ var import_react;
1059
+ var init_useMessageVisualState = __esm({
1060
+ "src/hooks/useMessageVisualState.ts"() {
1061
+ "use strict";
1062
+ import_react = require("react");
1063
+ }
1064
+ });
1065
+
1066
+ // src/store/faceRenderingSlice.ts
1067
+ function clampUnit(value) {
1068
+ if (Number.isNaN(value)) {
1069
+ return 0;
1070
+ }
1071
+ return Math.max(-1, Math.min(1, value));
1072
+ }
1073
+ function mergeFaceSettings(base, patch) {
1074
+ if (!patch) {
1075
+ return {
1076
+ ...base,
1077
+ offset: { ...base.offset },
1078
+ captions: {
1079
+ ...base.captions,
1080
+ offset: { ...base.captions.offset }
1081
+ },
1082
+ pixiSettings: base.pixiSettings ? { ...base.pixiSettings } : void 0,
1083
+ vizijSettings: base.vizijSettings ? { ...base.vizijSettings } : void 0
1084
+ };
1085
+ }
1086
+ return {
1087
+ ...defaultFaceSettings,
1088
+ ...base,
1089
+ ...patch,
1090
+ offset: {
1091
+ ...defaultFaceSettings.offset,
1092
+ ...base.offset || {},
1093
+ ...patch.offset || {}
1094
+ },
1095
+ captions: {
1096
+ ...defaultFaceSettings.captions,
1097
+ ...base.captions || {},
1098
+ ...patch.captions || {},
1099
+ offset: {
1100
+ ...defaultFaceSettings.captions.offset,
1101
+ ...base.captions?.offset || {},
1102
+ ...patch.captions?.offset || {}
1103
+ }
1104
+ },
1105
+ pixiSettings: {
1106
+ ...defaultFaceSettings.pixiSettings,
1107
+ ...base.pixiSettings || {},
1108
+ ...patch.pixiSettings || {}
1109
+ },
1110
+ vizijSettings: {
1111
+ ...defaultFaceSettings.vizijSettings,
1112
+ ...base.vizijSettings || {},
1113
+ ...patch.vizijSettings || {}
1114
+ }
1115
+ };
1116
+ }
1117
+ function createFaceRenderingSlice(options = {}) {
1118
+ const initialBaseUrl = normalizeAssetBaseUrl(options.assetBaseUrl);
1119
+ const initialFaces = createBuiltInFaces(initialBaseUrl);
1120
+ const initialSelectedFace = options.initialFace ?? initialFaces[0];
1121
+ const initialMergedSettings = mergeFaceSettings(
1122
+ defaultFaceSettings,
1123
+ options.initialSettings
1124
+ );
1125
+ return (set, get) => ({
1126
+ assetBaseUrl: initialBaseUrl,
1127
+ availableFaces: initialFaces,
1128
+ selectedFace: initialSelectedFace,
1129
+ faceSettings: initialMergedSettings,
1130
+ gaze: { x: 0, y: 0 },
1131
+ setFace: (face) => {
1132
+ set({ selectedFace: face });
1133
+ },
1134
+ setFaceByName: (name) => {
1135
+ const found = get().availableFaces.find((f) => f.name === name);
1136
+ if (found) {
1137
+ set({ selectedFace: found });
1138
+ }
1139
+ },
1140
+ setFaceSettings: (settings) => {
1141
+ set((state) => ({
1142
+ faceSettings: mergeFaceSettings(state.faceSettings, settings)
1143
+ }));
1144
+ },
1145
+ resetPositioning: () => {
1146
+ set((state) => ({
1147
+ faceSettings: mergeFaceSettings(state.faceSettings, {
1148
+ zoom: 1,
1149
+ offset: { x: 0, y: 0 },
1150
+ rotation: 0
1151
+ })
1152
+ }));
1153
+ },
1154
+ setGaze: (gaze) => {
1155
+ set({
1156
+ gaze: {
1157
+ x: clampUnit(gaze.x),
1158
+ y: clampUnit(gaze.y)
1159
+ }
1160
+ });
1161
+ },
1162
+ setLanguage: (lang) => {
1163
+ set((state) => ({
1164
+ faceSettings: mergeFaceSettings(state.faceSettings, {
1165
+ selectedLanguage: lang
1166
+ })
1167
+ }));
1168
+ },
1169
+ setAssetBaseUrl: (assetBaseUrl) => {
1170
+ const normalized = normalizeAssetBaseUrl(assetBaseUrl);
1171
+ const updatedFaces = createBuiltInFaces(normalized);
1172
+ const currentName = get().selectedFace?.name;
1173
+ const matchingUpdated = updatedFaces.find((f) => f.name === currentName);
1174
+ set({
1175
+ assetBaseUrl: normalized,
1176
+ availableFaces: updatedFaces,
1177
+ selectedFace: matchingUpdated ?? get().selectedFace
1178
+ });
1179
+ }
1180
+ });
1181
+ }
1182
+ var init_faceRenderingSlice = __esm({
1183
+ "src/store/faceRenderingSlice.ts"() {
1184
+ "use strict";
1185
+ init_face();
1186
+ }
1187
+ });
1188
+
1189
+ // src/store/faceSpeechSlice.ts
1190
+ function isNativeSpeechSynthesisVoice(voice) {
1191
+ if (!voice || typeof voice !== "object") {
1192
+ return false;
1193
+ }
1194
+ if (typeof SpeechSynthesisVoice !== "undefined" && voice instanceof SpeechSynthesisVoice) {
1195
+ return true;
1196
+ }
1197
+ return Object.prototype.toString.call(voice) === "[object SpeechSynthesisVoice]";
1198
+ }
1199
+ function matchesLanguage(voiceLang, selectedLang) {
1200
+ if (!voiceLang || !selectedLang) {
1201
+ return false;
1202
+ }
1203
+ return getLanguageName(voiceLang) === selectedLang || voiceLang === selectedLang || voiceLang.toLowerCase() === selectedLang.toLowerCase() || voiceLang.toLowerCase().startsWith(selectedLang.toLowerCase()) || selectedLang.toLowerCase().startsWith(voiceLang.toLowerCase());
1204
+ }
1205
+ function stopNativeSpeechSynthesis() {
1206
+ if (typeof window !== "undefined" && "speechSynthesis" in window) {
1207
+ try {
1208
+ if (window.speechSynthesis.speaking || window.speechSynthesis.pending) {
1209
+ window.speechSynthesis.cancel();
1210
+ }
1211
+ } catch (err) {
1212
+ void err;
1213
+ }
1214
+ }
1215
+ }
1216
+ function createFaceSpeechSlice(sliceOptions = {}) {
1217
+ let adapter = sliceOptions.speechAdapter ?? null;
1218
+ const cache = sliceOptions.ttsCache === false ? null : sliceOptions.ttsCache ?? defaultTtsAudioCache;
1219
+ const analyzer = sliceOptions.audioAnalyzer ?? audioAnalyzer;
1220
+ const utteranceDeferMs = sliceOptions.utteranceDeferMs ?? 10;
1221
+ let activeAudio = null;
1222
+ let activeObjectUrl = null;
1223
+ let activeUtterance = null;
1224
+ let activeTimer = null;
1225
+ let activeBoundaryTimer = null;
1226
+ let activeGeneration = 0;
1227
+ const revokeActiveObjectUrl = () => {
1228
+ if (activeObjectUrl) {
1229
+ try {
1230
+ URL.revokeObjectURL(activeObjectUrl);
1231
+ } catch (err) {
1232
+ void err;
1233
+ }
1234
+ activeObjectUrl = null;
1235
+ }
1236
+ };
1237
+ const cleanupActivePlayback = () => {
1238
+ activeGeneration += 1;
1239
+ if (activeTimer !== null) {
1240
+ clearTimeout(activeTimer);
1241
+ activeTimer = null;
1242
+ }
1243
+ if (activeBoundaryTimer !== null) {
1244
+ clearTimeout(activeBoundaryTimer);
1245
+ activeBoundaryTimer = null;
1246
+ }
1247
+ if (activeAudio) {
1248
+ activeAudio.onplay = null;
1249
+ activeAudio.onended = null;
1250
+ activeAudio.onerror = null;
1251
+ try {
1252
+ activeAudio.pause();
1253
+ activeAudio.currentTime = 0;
1254
+ } catch (err) {
1255
+ void err;
1256
+ }
1257
+ activeAudio = null;
1258
+ }
1259
+ revokeActiveObjectUrl();
1260
+ if (activeUtterance) {
1261
+ activeUtterance.onstart = null;
1262
+ activeUtterance.onend = null;
1263
+ activeUtterance.onerror = null;
1264
+ activeUtterance.onboundary = null;
1265
+ activeUtterance = null;
1266
+ }
1267
+ stopNativeSpeechSynthesis();
1268
+ };
1269
+ return (set, get) => {
1270
+ const playNextFromQueue = () => {
1271
+ const queue = get().speechQueue;
1272
+ if (queue.length > 0) {
1273
+ const [next, ...rest] = queue;
1274
+ set({ speechQueue: rest });
1275
+ void get().express(next.message, next.options);
1276
+ }
1277
+ };
1278
+ const finishGeneration = (gen) => {
1279
+ if (gen !== activeGeneration) {
1280
+ return;
1281
+ }
1282
+ if (activeBoundaryTimer !== null) {
1283
+ clearTimeout(activeBoundaryTimer);
1284
+ activeBoundaryTimer = null;
1285
+ }
1286
+ activeAudio = null;
1287
+ activeUtterance = null;
1288
+ revokeActiveObjectUrl();
1289
+ set({
1290
+ isSpeaking: false,
1291
+ speechStartTime: null,
1292
+ currentAmplitude: 0
1293
+ });
1294
+ playNextFromQueue();
1295
+ };
1296
+ const expressImpl = async (message, options) => {
1297
+ const speechText = (message.speech ?? "").trim();
1298
+ const hasWords = speechText.length > 0;
1299
+ if (sliceOptions.isSilent || options?.silent || !hasWords) {
1300
+ set({
1301
+ lastMessage: message,
1302
+ isSpeaking: false
1303
+ });
1304
+ return;
1305
+ }
1306
+ const effectiveQueueMode = options?.queueMode ?? get().faceSettings?.speechQueueMode ?? "interrupt";
1307
+ const currentlyPlaying = get().isSpeaking || activeAudio !== null || activeUtterance !== null || activeTimer !== null;
1308
+ if (effectiveQueueMode === "queue" && currentlyPlaying) {
1309
+ set((state) => ({
1310
+ speechQueue: [...state.speechQueue, { message, options }]
1311
+ }));
1312
+ return;
1313
+ }
1314
+ cleanupActivePlayback();
1315
+ const myGeneration = activeGeneration;
1316
+ set({
1317
+ lastMessage: message,
1318
+ isSpeaking: true
1319
+ });
1320
+ const selectedVoice = get().getSelectedVoice();
1321
+ const shouldUseAdapter = adapter !== null && typeof adapter.synthesizeSpeech === "function" && (adapter.canHandleVoice ? adapter.canHandleVoice(selectedVoice.voiceURI, selectedVoice) : true);
1322
+ if (shouldUseAdapter && adapter?.synthesizeSpeech) {
1323
+ try {
1324
+ const cacheKey = buildTtsCacheKey({
1325
+ voiceId: selectedVoice.voiceURI,
1326
+ engine: selectedVoice.engine,
1327
+ text: speechText
1328
+ });
1329
+ const cached = cache ? await cache.get(cacheKey) : void 0;
1330
+ if (myGeneration !== activeGeneration) {
1331
+ return;
1332
+ }
1333
+ let playbackUrl;
1334
+ let shouldRevokeUrl = false;
1335
+ let visemes = null;
1336
+ let ampData = null;
1337
+ let extrema = null;
1338
+ if (cached && cache) {
1339
+ playbackUrl = cache.createObjectUrl(cached);
1340
+ shouldRevokeUrl = true;
1341
+ visemes = cached.visemes ?? null;
1342
+ ampData = cached.amplitudeData ?? null;
1343
+ extrema = cached.extrema ?? null;
1344
+ } else {
1345
+ const synthesized = await adapter.synthesizeSpeech(
1346
+ speechText,
1347
+ selectedVoice.voiceURI,
1348
+ {
1349
+ engine: selectedVoice.engine,
1350
+ language: get().faceSettings?.selectedLanguage
1351
+ }
1352
+ );
1353
+ if (myGeneration !== activeGeneration) {
1354
+ return;
1355
+ }
1356
+ visemes = synthesized.visemes ?? null;
1357
+ ampData = synthesized.amplitudeData ?? null;
1358
+ extrema = synthesized.extrema ?? null;
1359
+ const mimeType = synthesized.mimeType || "audio/mpeg";
1360
+ let blobToCache = null;
1361
+ if (synthesized.audioBlob) {
1362
+ blobToCache = synthesized.audioBlob;
1363
+ } else if (synthesized.audioBuffer) {
1364
+ blobToCache = new Blob([synthesized.audioBuffer], { type: mimeType });
1365
+ }
1366
+ if (blobToCache) {
1367
+ if (cache) {
1368
+ await cache.set(cacheKey, {
1369
+ audioBlob: blobToCache,
1370
+ mimeType,
1371
+ visemes: synthesized.visemes,
1372
+ amplitudeData: synthesized.amplitudeData,
1373
+ extrema: synthesized.extrema
1374
+ });
1375
+ }
1376
+ playbackUrl = URL.createObjectURL(blobToCache);
1377
+ shouldRevokeUrl = true;
1378
+ } else if (synthesized.audioUrl) {
1379
+ playbackUrl = synthesized.audioUrl;
1380
+ }
1381
+ }
1382
+ if (playbackUrl && typeof Audio !== "undefined") {
1383
+ get().setSpokenVisemes(visemes);
1384
+ get().setAmplitudeData(ampData, extrema);
1385
+ const audio = new Audio(playbackUrl);
1386
+ audio.crossOrigin = "anonymous";
1387
+ activeAudio = audio;
1388
+ if (shouldRevokeUrl) {
1389
+ activeObjectUrl = playbackUrl;
1390
+ }
1391
+ analyzer.connect(audio);
1392
+ audio.onplay = () => {
1393
+ if (myGeneration !== activeGeneration) {
1394
+ return;
1395
+ }
1396
+ set({
1397
+ isSpeaking: true,
1398
+ speechStartTime: performance.now()
1399
+ });
1400
+ const pollAmplitude = () => {
1401
+ if (myGeneration === activeGeneration && activeAudio === audio && !audio.paused && !audio.ended) {
1402
+ get().setCurrentAmplitude(analyzer.getAmplitude());
1403
+ if (typeof requestAnimationFrame === "function") {
1404
+ requestAnimationFrame(pollAmplitude);
1405
+ }
1406
+ } else if (myGeneration === activeGeneration) {
1407
+ get().setCurrentAmplitude(0);
1408
+ }
1409
+ };
1410
+ pollAmplitude();
1411
+ };
1412
+ audio.onended = () => {
1413
+ finishGeneration(myGeneration);
1414
+ };
1415
+ audio.onerror = () => {
1416
+ finishGeneration(myGeneration);
1417
+ };
1418
+ await audio.play();
1419
+ return;
1420
+ }
1421
+ } catch (adapterError) {
1422
+ console.warn(
1423
+ "SpeechSynthesizerAdapter failed; falling back to Web Speech API:",
1424
+ adapterError
1425
+ );
1426
+ if (myGeneration !== activeGeneration) {
1427
+ return;
1428
+ }
1429
+ }
1430
+ }
1431
+ if (typeof window === "undefined" || typeof SpeechSynthesisUtterance === "undefined" || typeof window.speechSynthesis === "undefined") {
1432
+ finishGeneration(myGeneration);
1433
+ return;
1434
+ }
1435
+ const utterance = new SpeechSynthesisUtterance(speechText);
1436
+ activeUtterance = utterance;
1437
+ if (isNativeSpeechSynthesisVoice(selectedVoice)) {
1438
+ utterance.voice = selectedVoice;
1439
+ } else {
1440
+ const nativeVoices = window.speechSynthesis.getVoices();
1441
+ const matched = findMatchingVoice(nativeVoices, selectedVoice.voiceURI) || findMatchingVoice(nativeVoices, selectedVoice.name);
1442
+ if (matched) {
1443
+ utterance.voice = matched;
1444
+ }
1445
+ }
1446
+ utterance.lang = selectedVoice.lang || get().faceSettings?.selectedLanguage || "en-US";
1447
+ const estimatedVisemes = estimateVisemesFromText(speechText);
1448
+ set({
1449
+ spokenVisemes: estimatedVisemes,
1450
+ amplitudeData: null,
1451
+ amplitudeExtrema: null,
1452
+ currentAmplitude: 0
1453
+ });
1454
+ utterance.onstart = () => {
1455
+ if (myGeneration !== activeGeneration) {
1456
+ return;
1457
+ }
1458
+ set({
1459
+ isSpeaking: true,
1460
+ speechStartTime: performance.now()
1461
+ });
1462
+ };
1463
+ utterance.onboundary = (event) => {
1464
+ if (myGeneration !== activeGeneration) {
1465
+ return;
1466
+ }
1467
+ if (event.name === "word") {
1468
+ get().setCurrentAmplitude(1);
1469
+ if (activeBoundaryTimer !== null) {
1470
+ clearTimeout(activeBoundaryTimer);
1471
+ }
1472
+ activeBoundaryTimer = setTimeout(() => {
1473
+ if (myGeneration === activeGeneration) {
1474
+ get().setCurrentAmplitude(0);
1475
+ }
1476
+ }, 100);
1477
+ }
1478
+ };
1479
+ utterance.onend = () => {
1480
+ finishGeneration(myGeneration);
1481
+ };
1482
+ utterance.onerror = (event) => {
1483
+ if (event.error === "not-allowed") {
1484
+ get().setSpeechAllowed(false);
1485
+ }
1486
+ finishGeneration(myGeneration);
1487
+ };
1488
+ const invokeSpeak = () => {
1489
+ activeTimer = null;
1490
+ if (myGeneration !== activeGeneration) {
1491
+ return;
1492
+ }
1493
+ try {
1494
+ if (window.speechSynthesis.paused) {
1495
+ window.speechSynthesis.resume();
1496
+ }
1497
+ window.speechSynthesis.speak(utterance);
1498
+ } catch (speakErr) {
1499
+ console.warn("SpeechSynthesis speak invocation error:", speakErr);
1500
+ finishGeneration(myGeneration);
1501
+ }
1502
+ };
1503
+ if (utteranceDeferMs <= 0) {
1504
+ invokeSpeak();
1505
+ } else {
1506
+ activeTimer = setTimeout(invokeSpeak, utteranceDeferMs);
1507
+ }
1508
+ };
1509
+ return {
1510
+ lastMessage: sliceOptions.initialMessage ?? DEFAULT_FACE_MESSAGE,
1511
+ isSpeaking: false,
1512
+ speechAllowed: false,
1513
+ selectedVoiceUri: null,
1514
+ availableVoices: [],
1515
+ spokenVisemes: null,
1516
+ amplitudeData: null,
1517
+ amplitudeExtrema: null,
1518
+ currentAmplitude: 0,
1519
+ speechStartTime: null,
1520
+ speechQueue: [],
1521
+ setSpeechAllowed: (allowed) => {
1522
+ set({ speechAllowed: allowed });
1523
+ },
1524
+ setAvailableVoices: (voices) => {
1525
+ set({ availableVoices: voices });
1526
+ },
1527
+ refreshVoices: async () => {
1528
+ const collected = [];
1529
+ const seen = /* @__PURE__ */ new Set();
1530
+ if (typeof window !== "undefined" && "speechSynthesis" in window) {
1531
+ const browserVoices = window.speechSynthesis.getVoices();
1532
+ for (const v of browserVoices) {
1533
+ if (!seen.has(v.voiceURI)) {
1534
+ seen.add(v.voiceURI);
1535
+ collected.push(v);
1536
+ }
1537
+ }
1538
+ }
1539
+ if (adapter?.fetchVoices) {
1540
+ try {
1541
+ const remoteVoices = await adapter.fetchVoices();
1542
+ for (const v of remoteVoices) {
1543
+ if (!seen.has(v.voiceURI)) {
1544
+ seen.add(v.voiceURI);
1545
+ collected.push(v);
1546
+ }
1547
+ }
1548
+ } catch (err) {
1549
+ console.warn("Failed to fetch adapter voices:", err);
1550
+ }
1551
+ }
1552
+ set({ availableVoices: collected });
1553
+ return collected;
1554
+ },
1555
+ getDefaultVoice: () => {
1556
+ const voices = get().availableVoices;
1557
+ const selectedLang = get().faceSettings?.selectedLanguage;
1558
+ if (selectedLang) {
1559
+ const langVoice = voices.find(
1560
+ (v) => matchesLanguage(v.lang, selectedLang)
1561
+ );
1562
+ if (langVoice) {
1563
+ return langVoice;
1564
+ }
1565
+ }
1566
+ const defaultFlagged = voices.find((v) => v.default === true);
1567
+ if (defaultFlagged) {
1568
+ return defaultFlagged;
1569
+ }
1570
+ if (voices.length > 0) {
1571
+ return voices[0];
1572
+ }
1573
+ return {
1574
+ ...FALLBACK_DEFAULT_VOICE,
1575
+ lang: selectedLang || "en-US"
1576
+ };
1577
+ },
1578
+ getSelectedVoice: () => {
1579
+ const uri = get().selectedVoiceUri;
1580
+ const voices = get().availableVoices;
1581
+ if (uri !== null) {
1582
+ const matched = findMatchingVoice(voices, uri);
1583
+ if (matched) {
1584
+ return matched;
1585
+ }
1586
+ }
1587
+ return get().getDefaultVoice();
1588
+ },
1589
+ setVoice: (voiceUri, voiceOptions) => {
1590
+ const prevVoice = get().selectedVoiceUri || get().getSelectedVoice()?.voiceURI;
1591
+ set({ selectedVoiceUri: voiceUri });
1592
+ if (!sliceOptions.isSilent && !voiceOptions?.silent && prevVoice && prevVoice !== voiceUri) {
1593
+ void get().express({
1594
+ title: "Switching voice",
1595
+ speech: "Switching voice",
1596
+ color: "Light Blue",
1597
+ emotion: "Neutral"
1598
+ });
1599
+ }
1600
+ },
1601
+ setSpokenVisemes: (visemes) => {
1602
+ set({ spokenVisemes: visemes });
1603
+ },
1604
+ setAmplitudeData: (data, extrema) => {
1605
+ set({
1606
+ amplitudeData: data,
1607
+ amplitudeExtrema: extrema
1608
+ });
1609
+ },
1610
+ setIsSpeaking: (isSpeaking) => {
1611
+ set({ isSpeaking });
1612
+ },
1613
+ setCurrentAmplitude: (amplitude) => {
1614
+ const gain = get().faceSettings?.amplitudeGain ?? 1;
1615
+ const scaled = amplitude * gain;
1616
+ const clamped = Number.isNaN(scaled) ? 0 : Math.min(1, Math.max(0, scaled));
1617
+ set({ currentAmplitude: clamped });
1618
+ },
1619
+ setSpeechAdapter: (nextAdapter) => {
1620
+ adapter = nextAdapter;
1621
+ },
1622
+ express: expressImpl,
1623
+ _express: expressImpl,
1624
+ stopSpeech: () => {
1625
+ cleanupActivePlayback();
1626
+ set({
1627
+ isSpeaking: false,
1628
+ speechStartTime: null,
1629
+ currentAmplitude: 0,
1630
+ spokenVisemes: null,
1631
+ amplitudeData: null,
1632
+ amplitudeExtrema: null,
1633
+ speechQueue: []
1634
+ });
1635
+ }
1636
+ };
1637
+ };
1638
+ }
1639
+ var FALLBACK_DEFAULT_VOICE;
1640
+ var init_faceSpeechSlice = __esm({
1641
+ "src/store/faceSpeechSlice.ts"() {
1642
+ "use strict";
1643
+ init_face();
1644
+ init_voice_helpers();
1645
+ init_viseme_mapper();
1646
+ init_AudioAnalyzer();
1647
+ init_ttsAudioCache();
1648
+ FALLBACK_DEFAULT_VOICE = {
1649
+ default: false,
1650
+ lang: "en-US",
1651
+ localService: false,
1652
+ name: "en-US-Standard-B",
1653
+ voiceURI: "en-US-Standard-B"
1654
+ };
1655
+ }
1656
+ });
1657
+
1658
+ // src/store/createPeerbotsFaceStore.ts
1659
+ function restorePersistedFace(persistedSelection, builtIns, fallback) {
1660
+ if (typeof persistedSelection === "string") {
1661
+ return builtIns.find((f) => f.name === persistedSelection) ?? fallback;
1662
+ }
1663
+ if (persistedSelection && typeof persistedSelection === "object") {
1664
+ const selectionObj = persistedSelection;
1665
+ if (typeof selectionObj.name === "string") {
1666
+ const found = builtIns.find((f) => f.name === selectionObj.name);
1667
+ if (found) {
1668
+ if (found.kind === "Vizij" && selectionObj.assetBundle && typeof selectionObj.assetBundle === "object") {
1669
+ const persistedBundle = selectionObj.assetBundle;
1670
+ const persistedGlb = persistedBundle.glb && typeof persistedBundle.glb === "object" ? persistedBundle.glb : {};
1671
+ return {
1672
+ ...found,
1673
+ assetBundle: {
1674
+ ...found.assetBundle,
1675
+ ...persistedBundle,
1676
+ glb: {
1677
+ ...found.assetBundle.glb,
1678
+ ...persistedGlb
1679
+ }
1680
+ }
1681
+ };
1682
+ }
1683
+ return found;
1684
+ }
1685
+ if (typeof selectionObj.kind === "string") {
1686
+ return persistedSelection;
1687
+ }
1688
+ }
1689
+ }
1690
+ return fallback;
1691
+ }
1692
+ function createPeerbotsFaceStore(options = {}) {
1693
+ const stateInitializer = (...args) => ({
1694
+ ...createFaceRenderingSlice(options)(...args),
1695
+ ...createFaceSpeechSlice(options)(...args)
1696
+ });
1697
+ if (!options.persistName) {
1698
+ return (0, import_zustand.createStore)()(stateInitializer);
1699
+ }
1700
+ const builtIns = createBuiltInFaces(options.assetBaseUrl);
1701
+ const fallbackFace = options.initialFace ?? builtIns[0];
1702
+ return (0, import_zustand.createStore)()(
1703
+ (0, import_middleware.persist)(stateInitializer, {
1704
+ name: options.persistName,
1705
+ version: 1,
1706
+ partialize: (state) => ({
1707
+ selectedFace: state.selectedFace,
1708
+ faceSettings: state.faceSettings,
1709
+ selectedVoiceUri: state.selectedVoiceUri,
1710
+ lastMessage: state.lastMessage
1711
+ }),
1712
+ merge: (persistedState, currentState) => {
1713
+ const persisted = persistedState ?? {};
1714
+ const restoredFace = restorePersistedFace(
1715
+ persisted.selectedFace,
1716
+ currentState.availableFaces,
1717
+ fallbackFace
1718
+ );
1719
+ const restoredSettings = persisted.faceSettings ? mergeFaceSettings(
1720
+ defaultFaceSettings,
1721
+ persisted.faceSettings
1722
+ ) : currentState.faceSettings;
1723
+ return {
1724
+ ...currentState,
1725
+ selectedFace: restoredFace,
1726
+ selectedVoiceUri: persisted.selectedVoiceUri ?? null,
1727
+ faceSettings: restoredSettings,
1728
+ lastMessage: persisted.lastMessage ?? options.initialMessage ?? DEFAULT_FACE_MESSAGE,
1729
+ isSpeaking: false
1730
+ };
1731
+ }
1732
+ })
1733
+ );
1734
+ }
1735
+ var import_zustand, import_middleware, globalFaceStore;
1736
+ var init_createPeerbotsFaceStore = __esm({
1737
+ "src/store/createPeerbotsFaceStore.ts"() {
1738
+ "use strict";
1739
+ import_zustand = require("zustand");
1740
+ import_middleware = require("zustand/middleware");
1741
+ init_face();
1742
+ init_faceRenderingSlice();
1743
+ init_faceSpeechSlice();
1744
+ globalFaceStore = createPeerbotsFaceStore({
1745
+ persistName: "faceSettings"
1746
+ });
1747
+ }
1748
+ });
1749
+
1750
+ // src/store/FaceStoreContext.tsx
1751
+ function FaceStoreProvider({
1752
+ children,
1753
+ store,
1754
+ options
1755
+ }) {
1756
+ const [internalStore] = (0, import_react2.useState)(
1757
+ () => store ?? createPeerbotsFaceStore(options)
1758
+ );
1759
+ const resolvedStore = store ?? internalStore;
1760
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FaceStoreContext.Provider, { value: resolvedStore, children });
1761
+ }
1762
+ function useFaceStoreInstance() {
1763
+ const context = (0, import_react2.useContext)(FaceStoreContext);
1764
+ return context ?? globalFaceStore;
1765
+ }
1766
+ function useFaceStoreBase(selector) {
1767
+ const store = useFaceStoreInstance();
1768
+ return (0, import_zustand2.useStore)(store, selector);
1769
+ }
1770
+ var import_react2, import_zustand2, import_jsx_runtime, FaceStoreContext, useFaceStore;
1771
+ var init_FaceStoreContext = __esm({
1772
+ "src/store/FaceStoreContext.tsx"() {
1773
+ "use strict";
1774
+ import_react2 = require("react");
1775
+ import_zustand2 = require("zustand");
1776
+ init_createPeerbotsFaceStore();
1777
+ import_jsx_runtime = require("react/jsx-runtime");
1778
+ FaceStoreContext = (0, import_react2.createContext)(null);
1779
+ useFaceStore = Object.assign(useFaceStoreBase, {
1780
+ getState: () => globalFaceStore.getState(),
1781
+ setState: ((...args) => globalFaceStore.setState(...args)),
1782
+ subscribe: ((...args) => globalFaceStore.subscribe(...args))
1783
+ });
1784
+ }
1785
+ });
1786
+
1787
+ // src/components/FaceEyes.tsx
1788
+ function FaceEyes({
1789
+ scale,
1790
+ frozen = false
1791
+ }) {
1792
+ const message = useFaceStore((state) => state.lastMessage);
1793
+ const face = useFaceStore((state) => state.selectedFace);
1794
+ const gaze = useFaceStore((state) => state.gaze);
1795
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
1796
+ (0, import_react4.useExtend)({ Container: import_pixi.Container, Sprite: import_pixi.Sprite, Graphics: import_pixi.Graphics });
1797
+ const [faceSheet, setFaceSheet] = (0, import_react5.useState)(null);
1798
+ const [cheekTexture, setCheekTexture] = (0, import_react5.useState)(null);
1799
+ const [eyeBrows, setEyeBrows] = (0, import_react5.useState)("Hugo");
1800
+ const leftEyeTexture = (0, import_react5.useMemo)(() => {
1801
+ if (!faceSheet) return import_pixi.Texture.EMPTY;
1802
+ const emotion = message?.emotion || "Neutral";
1803
+ return faceSheet.textures?.[`${emotion.toLowerCase()}_l.png`] || faceSheet.textures?.["neutral_l.png"] || import_pixi.Texture.EMPTY;
1804
+ }, [message, faceSheet]);
1805
+ const rightEyeTexture = (0, import_react5.useMemo)(() => {
1806
+ if (!faceSheet) return import_pixi.Texture.EMPTY;
1807
+ const emotion = message?.emotion || "Neutral";
1808
+ return faceSheet.textures?.[`${emotion.toLowerCase()}_r.png`] || faceSheet.textures?.["neutral_r.png"] || import_pixi.Texture.EMPTY;
1809
+ }, [message, faceSheet]);
1810
+ const breathingScaleRef = (0, import_react5.useRef)(1);
1811
+ const breathingTimeRef = (0, import_react5.useRef)(0);
1812
+ const blinkScaleRef = (0, import_react5.useRef)(1);
1813
+ const isBlinkingRef = (0, import_react5.useRef)(false);
1814
+ const blinkEveryRef = (0, import_react5.useRef)(500);
1815
+ const blinkTimerRef = (0, import_react5.useRef)(0);
1816
+ const blinkTargetScaleRef = (0, import_react5.useRef)(1);
1817
+ const currentGazeRef = (0, import_react5.useRef)({ x: 0, y: 0 });
1818
+ const leftEyeContainerRef = (0, import_react5.useRef)(null);
1819
+ const rightEyeContainerRef = (0, import_react5.useRef)(null);
1820
+ const leftEyebrowRef = (0, import_react5.useRef)(null);
1821
+ const rightEyebrowRef = (0, import_react5.useRef)(null);
1822
+ const leftEyeSpriteRef = (0, import_react5.useRef)(null);
1823
+ const rightEyeSpriteRef = (0, import_react5.useRef)(null);
1824
+ const leftCheekRef = (0, import_react5.useRef)(null);
1825
+ const rightCheekRef = (0, import_react5.useRef)(null);
1826
+ const positions = (0, import_react5.useMemo)(() => {
1827
+ return {
1828
+ leftEyeX: -300 * scale,
1829
+ rightEyeX: 300 * scale,
1830
+ leftEyeY: 0,
1831
+ rightEyeY: 0,
1832
+ leftEyeToRightEyeScaleRatio: 1.1,
1833
+ cheekYOffset: 150 * scale,
1834
+ eyebrowMultiplier: 7.5 * scale,
1835
+ eyebrowOffset: -180 * scale
1836
+ };
1837
+ }, [scale]);
1838
+ (0, import_react4.useTick)((ticker) => {
1839
+ const deltaTime = frozen ? 0 : ticker.deltaTime;
1840
+ const frequency = 785e-5;
1841
+ breathingTimeRef.current += deltaTime;
1842
+ breathingScaleRef.current = 1 + 0.1 * Math.sin(breathingTimeRef.current * frequency);
1843
+ const blinkDuration = 20;
1844
+ const blinkSpeed = 0.5;
1845
+ blinkTimerRef.current += deltaTime;
1846
+ if (isBlinkingRef.current) {
1847
+ if (blinkTimerRef.current > blinkDuration) {
1848
+ blinkEveryRef.current = 200 + Math.random() * 400;
1849
+ blinkTargetScaleRef.current = 1;
1850
+ isBlinkingRef.current = false;
1851
+ blinkTimerRef.current = 0;
1852
+ }
1853
+ } else if (blinkTimerRef.current > blinkEveryRef.current) {
1854
+ blinkTargetScaleRef.current = 0.05;
1855
+ isBlinkingRef.current = true;
1856
+ blinkTimerRef.current = 0;
1857
+ }
1858
+ blinkScaleRef.current += (blinkTargetScaleRef.current - blinkScaleRef.current) * blinkSpeed * deltaTime;
1859
+ currentGazeRef.current.x += (gaze.x - currentGazeRef.current.x) * 0.15;
1860
+ currentGazeRef.current.y += (gaze.y - currentGazeRef.current.y) * 0.15;
1861
+ const gazeOffsetX = currentGazeRef.current.x * 40 * scale;
1862
+ const gazeOffsetY = currentGazeRef.current.y * 30 * scale;
1863
+ if (leftEyeContainerRef.current) {
1864
+ leftEyeContainerRef.current.x = positions.leftEyeX + gazeOffsetX;
1865
+ leftEyeContainerRef.current.y = positions.leftEyeY + gazeOffsetY;
1866
+ }
1867
+ if (rightEyeContainerRef.current) {
1868
+ rightEyeContainerRef.current.x = positions.rightEyeX + gazeOffsetX;
1869
+ rightEyeContainerRef.current.y = positions.rightEyeY + gazeOffsetY;
1870
+ }
1871
+ const breathe = breathingScaleRef.current;
1872
+ const blink = blinkScaleRef.current;
1873
+ if (leftEyeSpriteRef.current) {
1874
+ leftEyeSpriteRef.current.scale.x = positions.leftEyeToRightEyeScaleRatio * breathe * scale;
1875
+ leftEyeSpriteRef.current.scale.y = positions.leftEyeToRightEyeScaleRatio * breathe * blink * scale;
1876
+ }
1877
+ if (rightEyeSpriteRef.current) {
1878
+ rightEyeSpriteRef.current.scale.x = 1 * breathe * scale;
1879
+ rightEyeSpriteRef.current.scale.y = 1 * breathe * blink * scale;
1880
+ }
1881
+ if (leftCheekRef.current) {
1882
+ leftCheekRef.current.scale.x = 0.08 * breathe * scale;
1883
+ leftCheekRef.current.scale.y = 0.04 * breathe * scale;
1884
+ }
1885
+ if (rightCheekRef.current) {
1886
+ rightCheekRef.current.scale.x = 0.08 * breathe * scale;
1887
+ rightCheekRef.current.scale.y = 0.04 * breathe * scale;
1888
+ }
1889
+ const strokeWidth = Math.max(1.5, 3 * scale);
1890
+ if (leftEyebrowRef.current) {
1891
+ const g = leftEyebrowRef.current;
1892
+ g.clear();
1893
+ const mult = positions.eyebrowMultiplier * breathe;
1894
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
1895
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
1896
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
1897
+ }
1898
+ g.stroke({
1899
+ width: strokeWidth,
1900
+ color: "black",
1901
+ cap: "round",
1902
+ join: "round"
1903
+ });
1904
+ }
1905
+ if (rightEyebrowRef.current) {
1906
+ const g = rightEyebrowRef.current;
1907
+ g.clear();
1908
+ const mult = positions.eyebrowMultiplier * breathe;
1909
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
1910
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
1911
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
1912
+ }
1913
+ g.stroke({
1914
+ width: strokeWidth,
1915
+ color: "black",
1916
+ cap: "round",
1917
+ join: "round"
1918
+ });
1919
+ }
1920
+ });
1921
+ const drawEyebrow = (0, import_react5.useCallback)(
1922
+ (g) => {
1923
+ g.clear();
1924
+ const mult = positions.eyebrowMultiplier * breathingScaleRef.current;
1925
+ const strokeWidth = Math.max(1.5, 3 * scale);
1926
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
1927
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
1928
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
1929
+ }
1930
+ g.stroke({
1931
+ width: strokeWidth,
1932
+ color: "black",
1933
+ cap: "round",
1934
+ join: "round"
1935
+ });
1936
+ },
1937
+ [positions.eyebrowMultiplier, scale]
1938
+ );
1939
+ (0, import_react5.useEffect)(() => {
1940
+ let cancelled = false;
1941
+ async function loadAvatarTextures(currentFace) {
1942
+ if (currentFace?.kind !== "PixiFace" || currentFace.type !== "avatar") {
1943
+ return;
1944
+ }
1945
+ try {
1946
+ if (currentFace.eyes?.kind === "spritesheet") {
1947
+ const sheet = await import_pixi.Assets.load(currentFace.eyes.path);
1948
+ if (!cancelled) {
1949
+ setFaceSheet(sheet);
1950
+ }
1951
+ }
1952
+ if (currentFace.cheeks?.kind === "texture") {
1953
+ const cheek = await import_pixi.Assets.load(currentFace.cheeks.path);
1954
+ if (!cancelled) {
1955
+ setCheekTexture(cheek);
1956
+ }
1957
+ } else if (!cancelled) {
1958
+ setCheekTexture(null);
1959
+ }
1960
+ if (!cancelled) {
1961
+ setEyeBrows(currentFace.eyebrows);
1962
+ }
1963
+ } catch (err) {
1964
+ console.warn("Failed to load PixiFace textures:", err);
1965
+ }
1966
+ }
1967
+ void loadAvatarTextures(face);
1968
+ return () => {
1969
+ cancelled = true;
1970
+ };
1971
+ }, [face]);
1972
+ if (pixiSettings?.eyeDisplay === "none") {
1973
+ return null;
1974
+ }
1975
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1976
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1977
+ "pixiContainer",
1978
+ {
1979
+ ref: leftEyeContainerRef,
1980
+ position: { x: positions.leftEyeX, y: positions.leftEyeY },
1981
+ label: "LeftEyeContainer",
1982
+ children: [
1983
+ eyeBrows === "Hugo" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1984
+ "pixiGraphics",
1985
+ {
1986
+ ref: leftEyebrowRef,
1987
+ label: "LeftEyebrow",
1988
+ position: { x: 0, y: positions.eyebrowOffset },
1989
+ draw: drawEyebrow
1990
+ }
1991
+ ),
1992
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1993
+ "pixiSprite",
1994
+ {
1995
+ ref: leftEyeSpriteRef,
1996
+ label: "LeftEye",
1997
+ anchor: { x: 0.5, y: 0.5 },
1998
+ position: { x: 0, y: 0 },
1999
+ texture: leftEyeTexture,
2000
+ pivot: { x: 0.5, y: 0.5 }
2001
+ }
2002
+ ),
2003
+ cheekTexture && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2004
+ "pixiSprite",
2005
+ {
2006
+ ref: leftCheekRef,
2007
+ label: "LeftCheek",
2008
+ texture: cheekTexture,
2009
+ pivot: { x: 0.5, y: 0.5 },
2010
+ anchor: { x: 0.5, y: 0.5 },
2011
+ position: { x: 0, y: positions.cheekYOffset }
2012
+ }
2013
+ )
2014
+ ]
2015
+ }
2016
+ ),
2017
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2018
+ "pixiContainer",
2019
+ {
2020
+ ref: rightEyeContainerRef,
2021
+ position: { x: positions.rightEyeX, y: positions.rightEyeY },
2022
+ label: "RightEyeContainer",
2023
+ children: [
2024
+ eyeBrows === "Hugo" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2025
+ "pixiGraphics",
2026
+ {
2027
+ ref: rightEyebrowRef,
2028
+ label: "RightEyebrow",
2029
+ position: { x: 0, y: positions.eyebrowOffset },
2030
+ draw: drawEyebrow
2031
+ }
2032
+ ),
2033
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2034
+ "pixiSprite",
2035
+ {
2036
+ ref: rightEyeSpriteRef,
2037
+ label: "RightEye",
2038
+ position: { x: 0, y: 0 },
2039
+ pivot: { x: 0.5, y: 0.5 },
2040
+ anchor: { x: 0.5, y: 0.5 },
2041
+ texture: rightEyeTexture
2042
+ }
2043
+ ),
2044
+ cheekTexture && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2045
+ "pixiSprite",
2046
+ {
2047
+ ref: rightCheekRef,
2048
+ label: "RightCheek",
2049
+ texture: cheekTexture,
2050
+ pivot: { x: 0.5, y: 0.5 },
2051
+ anchor: { x: 0.5, y: 0.5 },
2052
+ position: { x: 0, y: positions.cheekYOffset }
2053
+ }
2054
+ )
2055
+ ]
2056
+ }
2057
+ )
2058
+ ] });
2059
+ }
2060
+ var import_pixi, import_react4, import_react5, import_jsx_runtime5, EYEBROW_POINTS;
2061
+ var init_FaceEyes = __esm({
2062
+ "src/components/FaceEyes.tsx"() {
2063
+ "use strict";
2064
+ import_pixi = require("pixi.js");
2065
+ import_react4 = require("@pixi/react");
2066
+ import_react5 = require("react");
2067
+ init_FaceStoreContext();
2068
+ import_jsx_runtime5 = require("react/jsx-runtime");
2069
+ EYEBROW_POINTS = [
2070
+ { x: -5, y: 2.5 },
2071
+ { x: -4, y: 1.6 },
2072
+ { x: -3, y: 0.9 },
2073
+ { x: -2, y: 0.4 },
2074
+ { x: -1, y: 0.1 },
2075
+ { x: 0, y: 0 },
2076
+ { x: 1, y: 0.1 },
2077
+ { x: 2, y: 0.4 },
2078
+ { x: 3, y: 0.9 },
2079
+ { x: 4, y: 1.6 },
2080
+ { x: 5, y: 2.5 }
2081
+ ];
2082
+ }
2083
+ });
2084
+
2085
+ // src/components/FaceMouth.tsx
2086
+ function FaceMouth({
2087
+ scale,
2088
+ frozen = false
2089
+ }) {
2090
+ (0, import_react7.useExtend)({ Graphics: import_pixi2.Graphics });
2091
+ const talking = useFaceStore((state) => state.isSpeaking);
2092
+ const face = useFaceStore((state) => state.selectedFace);
2093
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
2094
+ const currentAmplitude = useFaceStore((state) => state.currentAmplitude);
2095
+ const amplitudeData = useFaceStore((state) => state.amplitudeData);
2096
+ const speechStartTime = useFaceStore((state) => state.speechStartTime);
2097
+ const talkingScaleRef = (0, import_react6.useRef)(1);
2098
+ const talkingTimeRef = (0, import_react6.useRef)(0);
2099
+ const talkingShape = (0, import_react6.useMemo)(
2100
+ () => face?.kind === "PixiFace" && face.type === "avatar" ? face.mouth : "Ellipse",
2101
+ [face]
2102
+ );
2103
+ const graphicsRef = (0, import_react6.useRef)(null);
2104
+ const getAmplitudeAtTime = (0, import_react6.useCallback)(
2105
+ (timeMs) => {
2106
+ if (!amplitudeData || amplitudeData.length === 0) return 0;
2107
+ const point = amplitudeData.find((p, i) => {
2108
+ const nextPoint = amplitudeData[i + 1];
2109
+ return p.time <= timeMs && (!nextPoint || nextPoint.time > timeMs);
2110
+ });
2111
+ return point ? point.value : 0;
2112
+ },
2113
+ [amplitudeData]
2114
+ );
2115
+ const drawMouth = (0, import_react6.useCallback)(
2116
+ (graphics) => {
2117
+ graphics.clear();
2118
+ const talkingScale = talkingScaleRef.current;
2119
+ const talkingTime = talkingTimeRef.current;
2120
+ switch (talkingShape) {
2121
+ case "Hugo": {
2122
+ const width = 40 * scale;
2123
+ const smileDepth = 20 * scale;
2124
+ const openHeight = talking ? talkingScale * 30 * scale : 0;
2125
+ const topLipLift = talking ? talkingScale * 10 * scale : 0;
2126
+ const centerY = scale * 240;
2127
+ graphics.moveTo(-width, centerY);
2128
+ graphics.quadraticCurveTo(
2129
+ 0,
2130
+ centerY + smileDepth * 0.5 - topLipLift,
2131
+ width,
2132
+ centerY
2133
+ );
2134
+ graphics.quadraticCurveTo(
2135
+ 0,
2136
+ centerY + smileDepth + openHeight * 1.5,
2137
+ -width,
2138
+ centerY
2139
+ );
2140
+ graphics.fill({ color: "black" });
2141
+ break;
2142
+ }
2143
+ case "Beak": {
2144
+ SMILEY_POINTS.forEach((eachPoint, index) => {
2145
+ const y = talkingScale * (Math.pow(40, 1.1) - Math.pow(Math.abs(eachPoint.x), 1.1)) + scale * 240;
2146
+ if (index === 0) {
2147
+ graphics.moveTo(eachPoint.x, y);
2148
+ }
2149
+ graphics.lineTo(eachPoint.x, y);
2150
+ });
2151
+ graphics.moveTo(SMILEY_POINTS[0].x, -1 * SMILEY_POINTS[0].y);
2152
+ SMILEY_POINTS.forEach((eachPoint, index) => {
2153
+ const y = -1 * talkingScale * (Math.pow(40, 1.1) - Math.pow(Math.abs(eachPoint.x), 1.1)) + scale * 240;
2154
+ if (index === 0) {
2155
+ graphics.moveTo(eachPoint.x, y);
2156
+ }
2157
+ graphics.lineTo(eachPoint.x, y);
2158
+ });
2159
+ break;
2160
+ }
2161
+ case "ZigZag": {
2162
+ ZIG_ZAG_POINTS.forEach((eachPoint, index) => {
2163
+ const x = eachPoint.x - ZIG_ZAG_POINTS[ZIG_ZAG_POINTS.length - 1].x / 2;
2164
+ const y = talking ? Math.sin(talkingTime * 0.3 + index * 5) * (10 * talkingScale) + scale * 240 : eachPoint.y + scale * 240;
2165
+ if (index === 0) {
2166
+ graphics.moveTo(x, y);
2167
+ }
2168
+ graphics.lineTo(x, y);
2169
+ });
2170
+ break;
2171
+ }
2172
+ case "Ellipse":
2173
+ default: {
2174
+ graphics.ellipse(
2175
+ 0,
2176
+ scale * 240,
2177
+ scale * 60,
2178
+ talking ? 2 + talkingScale * scale * 15 : 4
2179
+ );
2180
+ graphics.fill({ color: "black" });
2181
+ break;
2182
+ }
2183
+ }
2184
+ graphics.stroke({ color: "black", width: 2 });
2185
+ },
2186
+ [scale, talking, talkingShape]
2187
+ );
2188
+ (0, import_react7.useTick)((time) => {
2189
+ if (frozen) return;
2190
+ let targetScale;
2191
+ if (talking) {
2192
+ if (currentAmplitude > 0) {
2193
+ targetScale = Math.min(currentAmplitude * 1.5, 1);
2194
+ } else if (amplitudeData && speechStartTime) {
2195
+ const elapsed = performance.now() - speechStartTime;
2196
+ targetScale = Math.min(getAmplitudeAtTime(elapsed) * 1.5, 1);
2197
+ } else {
2198
+ targetScale = Math.abs(Math.sin(time.lastTime * 0.1));
2199
+ }
2200
+ talkingTimeRef.current = time.lastTime;
2201
+ } else {
2202
+ targetScale = 0;
2203
+ }
2204
+ const lerpAlpha = 0.2;
2205
+ talkingScaleRef.current += (targetScale - talkingScaleRef.current) * lerpAlpha;
2206
+ if (graphicsRef.current) {
2207
+ drawMouth(graphicsRef.current);
2208
+ }
2209
+ });
2210
+ if (pixiSettings?.mouthDisplay === "none") return null;
2211
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("pixiGraphics", { ref: graphicsRef, label: "Mouth", draw: drawMouth });
2212
+ }
2213
+ var import_react6, import_pixi2, import_react7, import_jsx_runtime6, ZIG_ZAG_POINTS, SMILEY_POINTS;
2214
+ var init_FaceMouth = __esm({
2215
+ "src/components/FaceMouth.tsx"() {
2216
+ "use strict";
2217
+ import_react6 = require("react");
2218
+ import_pixi2 = require("pixi.js");
2219
+ import_react7 = require("@pixi/react");
2220
+ init_FaceStoreContext();
2221
+ import_jsx_runtime6 = require("react/jsx-runtime");
2222
+ ZIG_ZAG_POINTS = [
2223
+ { x: 0, y: -10 },
2224
+ { x: 10, y: 10 },
2225
+ { x: 20, y: -10 },
2226
+ { x: 30, y: 10 },
2227
+ { x: 40, y: -10 },
2228
+ { x: 50, y: 10 },
2229
+ { x: 60, y: -10 },
2230
+ { x: 70, y: 10 },
2231
+ { x: 80, y: -10 },
2232
+ { x: 90, y: 10 },
2233
+ { x: 100, y: -10 },
2234
+ { x: 110, y: 10 }
2235
+ ];
2236
+ SMILEY_POINTS = [
2237
+ { x: -40, y: 40 },
2238
+ { x: -30, y: 30 },
2239
+ { x: -20, y: 20 },
2240
+ { x: -10, y: 10 },
2241
+ { x: 0, y: 0 },
2242
+ { x: 10, y: 10 },
2243
+ { x: 20, y: 20 },
2244
+ { x: 30, y: 30 },
2245
+ { x: 40, y: 40 }
2246
+ ];
2247
+ }
2248
+ });
2249
+
2250
+ // src/components/FaceText.tsx
2251
+ function FaceText({ scale }) {
2252
+ (0, import_react9.useExtend)({ Text: import_pixi3.Text });
2253
+ const lastMessage = useFaceStore((state) => state.lastMessage);
2254
+ const isSpeaking = useFaceStore((state) => state.isSpeaking);
2255
+ const selectedFace = useFaceStore((state) => state.selectedFace);
2256
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
2257
+ const emotionType = (0, import_react8.useMemo)(() => {
2258
+ if (pixiSettings?.emotionDisplay) {
2259
+ return pixiSettings.emotionDisplay;
2260
+ }
2261
+ if (selectedFace?.kind === "PixiFace" && selectedFace.type === "text") {
2262
+ return selectedFace.showEmotion;
2263
+ }
2264
+ return "emoticon";
2265
+ }, [pixiSettings?.emotionDisplay, selectedFace]);
2266
+ const { displayText, queueMessage, update } = useMessageVisualState(
2267
+ isSpeaking,
2268
+ {
2269
+ msPerChar: MS_PER_CHAR,
2270
+ persistenceDuration: TEXT_PERSISTENCE_DURATION,
2271
+ pauseBeforeNextMsg: PAUSE_BEFORE_NEXT_MSG
2272
+ }
2273
+ );
2274
+ (0, import_react8.useEffect)(() => {
2275
+ queueMessage(lastMessage.speech);
2276
+ }, [lastMessage.speech, queueMessage]);
2277
+ (0, import_react9.useTick)((delta) => {
2278
+ update(delta.deltaMS);
2279
+ });
2280
+ const emotionStyle = (0, import_react8.useMemo)(
2281
+ () => new import_pixi3.TextStyle({
2282
+ fontFamily: FONT_FAMILY,
2283
+ fontSize: Math.max(12, 48 * scale),
2284
+ fill: "black",
2285
+ align: "center"
2286
+ }),
2287
+ [scale]
2288
+ );
2289
+ const bodyStyle = (0, import_react8.useMemo)(
2290
+ () => new import_pixi3.TextStyle({
2291
+ fontFamily: FONT_FAMILY,
2292
+ fontSize: Math.max(12, 48 * scale),
2293
+ fill: "black",
2294
+ align: "center",
2295
+ wordWrap: true,
2296
+ wordWrapWidth: Math.max(200, 800 * scale)
2297
+ }),
2298
+ [scale]
2299
+ );
2300
+ const emotionSymbol = emotionType === "emoji" ? EMOTION_EMOJIS[lastMessage.emotion] : EMOTION_EMOTICONS[lastMessage.emotion];
2301
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2302
+ emotionType !== "none" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2303
+ "pixiText",
2304
+ {
2305
+ anchor: 0.5,
2306
+ x: 0,
2307
+ y: -50 * scale,
2308
+ text: emotionSymbol,
2309
+ style: emotionStyle
2310
+ }
2311
+ ),
2312
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2313
+ "pixiText",
2314
+ {
2315
+ text: displayText,
2316
+ anchor: 0.5,
2317
+ x: 0,
2318
+ y: 0,
2319
+ style: bodyStyle
2320
+ }
2321
+ )
2322
+ ] });
2323
+ }
2324
+ var import_react8, import_pixi3, import_react9, import_jsx_runtime7, FONT_FAMILY, TEXT_PERSISTENCE_DURATION, MS_PER_CHAR, PAUSE_BEFORE_NEXT_MSG;
2325
+ var init_FaceText = __esm({
2326
+ "src/components/FaceText.tsx"() {
2327
+ "use strict";
2328
+ import_react8 = require("react");
2329
+ import_pixi3 = require("pixi.js");
2330
+ import_react9 = require("@pixi/react");
2331
+ init_FaceStoreContext();
2332
+ init_emotion_mapper();
2333
+ init_useMessageVisualState();
2334
+ import_jsx_runtime7 = require("react/jsx-runtime");
2335
+ FONT_FAMILY = "Courier New, Courier, monospace";
2336
+ TEXT_PERSISTENCE_DURATION = 3e3;
2337
+ MS_PER_CHAR = 50;
2338
+ PAUSE_BEFORE_NEXT_MSG = 500;
2339
+ }
2340
+ });
2341
+
2342
+ // src/components/FaceBackground.tsx
2343
+ function createRadialGradientTexture(size) {
2344
+ if (typeof document === "undefined") {
2345
+ return import_pixi4.Texture.EMPTY;
2346
+ }
2347
+ const canvas = document.createElement("canvas");
2348
+ canvas.width = size;
2349
+ canvas.height = size;
2350
+ const ctx = canvas.getContext("2d");
2351
+ if (!ctx) return import_pixi4.Texture.EMPTY;
2352
+ const gradient = ctx.createRadialGradient(
2353
+ size / 2,
2354
+ size / 2,
2355
+ 0,
2356
+ size / 2,
2357
+ size / 2,
2358
+ size / 2
2359
+ );
2360
+ gradient.addColorStop(0, "rgba(255, 255, 255, 0.7)");
2361
+ gradient.addColorStop(0.4, "rgba(255, 255, 255, 0.2)");
2362
+ gradient.addColorStop(1, "rgba(255, 255, 255, 0)");
2363
+ ctx.fillStyle = gradient;
2364
+ ctx.fillRect(0, 0, size, size);
2365
+ return import_pixi4.Texture.from(canvas);
2366
+ }
2367
+ function FaceBackground() {
2368
+ (0, import_react11.useExtend)({ Sprite: import_pixi4.Sprite });
2369
+ const { app, isInitialised } = (0, import_react11.useApplication)();
2370
+ const texture = (0, import_react10.useMemo)(() => createRadialGradientTexture(1024), []);
2371
+ if (!app || !isInitialised || !app.renderer) return null;
2372
+ const screenWidth = app.renderer.screen && app.renderer.screen.width || app.renderer.width || 2e3;
2373
+ const screenHeight = app.renderer.screen && app.renderer.screen.height || app.renderer.height || 2e3;
2374
+ const size = Math.max(screenWidth, screenHeight) * 2;
2375
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2376
+ "pixiSprite",
2377
+ {
2378
+ texture,
2379
+ anchor: 0.5,
2380
+ width: size,
2381
+ height: size,
2382
+ x: 0,
2383
+ y: 0,
2384
+ blendMode: "screen",
2385
+ alpha: 0.5
2386
+ }
2387
+ );
2388
+ }
2389
+ var import_react10, import_pixi4, import_react11, import_jsx_runtime8;
2390
+ var init_FaceBackground = __esm({
2391
+ "src/components/FaceBackground.tsx"() {
2392
+ "use strict";
2393
+ import_react10 = require("react");
2394
+ import_pixi4 = require("pixi.js");
2395
+ import_react11 = require("@pixi/react");
2396
+ import_jsx_runtime8 = require("react/jsx-runtime");
2397
+ }
2398
+ });
2399
+
2400
+ // src/components/FaceContainer.tsx
2401
+ function stepRendererBackgroundColor(renderer, targetHex) {
2402
+ try {
2403
+ const currentHex = renderer.background.color.toHex();
2404
+ if (currentHex.toLowerCase() === targetHex.toLowerCase()) {
2405
+ return;
2406
+ }
2407
+ const interpolated = interpolateColor(currentHex, targetHex, 0.1);
2408
+ if (interpolated !== null) {
2409
+ renderer.background.color = rgbaToHex(interpolated);
2410
+ }
2411
+ } catch (err) {
2412
+ void err;
2413
+ }
2414
+ }
2415
+ function FaceContainer({ frozen = false }) {
2416
+ (0, import_react13.useExtend)({ Container: import_pixi5.Container });
2417
+ const settings = useFaceStore((state) => state.faceSettings);
2418
+ const selectedFace = useFaceStore((state) => state.selectedFace);
2419
+ const lastMessage = useFaceStore((state) => state.lastMessage);
2420
+ const { app, isInitialised } = (0, import_react13.useApplication)();
2421
+ const [layout, setLayout] = (0, import_react12.useState)({
2422
+ landscape: true,
2423
+ scale: 1,
2424
+ x: 400,
2425
+ y: 300
2426
+ });
2427
+ const isAvatar = selectedFace?.kind === "PixiFace" && selectedFace.type === "avatar";
2428
+ (0, import_react12.useEffect)(() => {
2429
+ if (!app || !isInitialised || !app.renderer) return;
2430
+ const updateLayout = () => {
2431
+ if (!app?.renderer) return;
2432
+ const width = app.renderer.screen && app.renderer.screen.width || app.renderer.width || 800;
2433
+ const height = app.renderer.screen && app.renderer.screen.height || app.renderer.height || 600;
2434
+ const isLandscape = width > height;
2435
+ const baseScale = isLandscape ? width / 1200 : height / 1200;
2436
+ const effectiveLandscape = settings.autoRotate ? isLandscape : true;
2437
+ setLayout({
2438
+ landscape: effectiveLandscape,
2439
+ scale: baseScale,
2440
+ x: width / 2,
2441
+ y: height / 2
2442
+ });
2443
+ };
2444
+ updateLayout();
2445
+ const onResize = () => {
2446
+ if (app?.renderer) {
2447
+ updateLayout();
2448
+ }
2449
+ };
2450
+ window.addEventListener("resize", onResize);
2451
+ window.addEventListener("orientationchange", onResize);
2452
+ app.renderer.on("resize", onResize);
2453
+ return () => {
2454
+ window.removeEventListener("resize", onResize);
2455
+ window.removeEventListener("orientationchange", onResize);
2456
+ if (app?.renderer) {
2457
+ app.renderer.off("resize", onResize);
2458
+ }
2459
+ };
2460
+ }, [app, isInitialised, settings.autoRotate]);
2461
+ (0, import_react13.useTick)(() => {
2462
+ if (app?.renderer && lastMessage) {
2463
+ const targetColor = color_mapping[lastMessage.color] ?? color_mapping["Light Blue"];
2464
+ stepRendererBackgroundColor(app.renderer, targetColor);
2465
+ }
2466
+ });
2467
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
2468
+ "pixiContainer",
2469
+ {
2470
+ label: "FaceContainer",
2471
+ position: {
2472
+ x: layout.x + (settings.offset?.x ?? 0),
2473
+ y: layout.y + (settings.offset?.y ?? 0)
2474
+ },
2475
+ pivot: { x: 0.5, y: 0.5 },
2476
+ angle: layout.landscape ? settings.rotation : 90 + settings.rotation,
2477
+ children: [
2478
+ isAvatar && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FaceBackground, {}),
2479
+ selectedFace?.kind === "PixiFace" && selectedFace.type === "text" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FaceText, { scale: layout.scale * settings.zoom }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
2480
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FaceEyes, { scale: layout.scale * settings.zoom, frozen }),
2481
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(FaceMouth, { scale: layout.scale * settings.zoom, frozen })
2482
+ ] })
2483
+ ]
2484
+ }
2485
+ );
2486
+ }
2487
+ var import_react12, import_pixi5, import_react13, import_jsx_runtime9;
2488
+ var init_FaceContainer = __esm({
2489
+ "src/components/FaceContainer.tsx"() {
2490
+ "use strict";
2491
+ import_react12 = require("react");
2492
+ import_pixi5 = require("pixi.js");
2493
+ import_react13 = require("@pixi/react");
2494
+ init_FaceStoreContext();
2495
+ init_color_mappers();
2496
+ init_FaceEyes();
2497
+ init_FaceMouth();
2498
+ init_FaceText();
2499
+ init_FaceBackground();
2500
+ import_jsx_runtime9 = require("react/jsx-runtime");
2501
+ }
2502
+ });
2503
+
2504
+ // src/components/FaceFullScreenButton.tsx
2505
+ function FaceFullScreenButton() {
2506
+ (0, import_react15.useExtend)({ Graphics: import_pixi6.Graphics, Container: import_pixi6.Container });
2507
+ const { app } = (0, import_react15.useApplication)();
2508
+ const [fullScreen, setFullScreen] = (0, import_react14.useState)(false);
2509
+ (0, import_react14.useEffect)(() => {
2510
+ if (typeof document === "undefined") {
2511
+ return;
2512
+ }
2513
+ const handleFullscreenChange = () => {
2514
+ setFullScreen(Boolean(document.fullscreenElement));
2515
+ };
2516
+ document.addEventListener("fullscreenchange", handleFullscreenChange);
2517
+ return () => {
2518
+ document.removeEventListener("fullscreenchange", handleFullscreenChange);
2519
+ };
2520
+ }, []);
2521
+ const toggleFullScreen = (0, import_react14.useCallback)(() => {
2522
+ if (typeof document === "undefined") {
2523
+ return;
2524
+ }
2525
+ if (fullScreen) {
2526
+ void document.exitFullscreen().catch((err) => {
2527
+ console.warn("Exit fullscreen error:", err);
2528
+ });
2529
+ } else {
2530
+ const container = document.getElementById("face-view-container");
2531
+ if (container) {
2532
+ container.requestFullscreen().catch((err) => {
2533
+ console.warn("Container fullscreen error:", err);
2534
+ if (app?.canvas) {
2535
+ void app.canvas.requestFullscreen().catch((canvasErr) => {
2536
+ console.warn("Canvas fullscreen error:", canvasErr);
2537
+ });
2538
+ }
2539
+ });
2540
+ } else if (app?.canvas) {
2541
+ void app.canvas.requestFullscreen().catch((err) => {
2542
+ console.warn("Canvas fullscreen error:", err);
2543
+ });
2544
+ }
2545
+ }
2546
+ }, [app, fullScreen]);
2547
+ const drawIcon = (0, import_react14.useCallback)(
2548
+ (graphics) => {
2549
+ graphics.clear();
2550
+ const pathD = fullScreen ? import_core3.iconPaths.arrowsPointingIn : import_core3.iconPaths.arrowsPointingOut;
2551
+ graphics.svg(`
2552
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
2553
+ <path strokeLinecap="round" strokeLinejoin="round" d="${pathD}" />
2554
+ </svg>
2555
+ `);
2556
+ },
2557
+ [fullScreen]
2558
+ );
2559
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2560
+ "pixiContainer",
2561
+ {
2562
+ label: "FullScreenToggle",
2563
+ x: 20,
2564
+ y: 20,
2565
+ eventMode: "static",
2566
+ onPointerDown: toggleFullScreen,
2567
+ hitArea: new import_pixi6.Rectangle(0, 0, 50, 50),
2568
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2569
+ "pixiGraphics",
2570
+ {
2571
+ onPointerDown: toggleFullScreen,
2572
+ eventMode: "static",
2573
+ draw: drawIcon
2574
+ }
2575
+ )
2576
+ }
2577
+ );
2578
+ }
2579
+ var import_react14, import_react15, import_pixi6, import_core3, import_jsx_runtime10;
2580
+ var init_FaceFullScreenButton = __esm({
2581
+ "src/components/FaceFullScreenButton.tsx"() {
2582
+ "use strict";
2583
+ import_react14 = require("react");
2584
+ import_react15 = require("@pixi/react");
2585
+ import_pixi6 = require("pixi.js");
2586
+ import_core3 = require("@peerbots/core");
2587
+ import_jsx_runtime10 = require("react/jsx-runtime");
2588
+ }
2589
+ });
2590
+
2591
+ // src/components/FaceScrollToTopButton.tsx
2592
+ function FaceScrollToTopButton() {
2593
+ (0, import_react17.useExtend)({ Graphics: import_pixi7.Graphics, Container: import_pixi7.Container });
2594
+ const [xPos, setXPos] = (0, import_react16.useState)(
2595
+ () => typeof window !== "undefined" ? window.innerWidth - 50 : 750
2596
+ );
2597
+ const scrollToTop = (0, import_react16.useCallback)(() => {
2598
+ if (typeof window !== "undefined") {
2599
+ window.scrollTo(0, 0);
2600
+ }
2601
+ }, []);
2602
+ (0, import_react16.useLayoutEffect)(() => {
2603
+ if (typeof window === "undefined") {
2604
+ return;
2605
+ }
2606
+ const calculatePositionBasedOnWindow = () => {
2607
+ setXPos(window.innerWidth - 50);
2608
+ };
2609
+ const orientation = typeof screen !== "undefined" ? screen.orientation : void 0;
2610
+ orientation?.addEventListener("change", calculatePositionBasedOnWindow);
2611
+ window.addEventListener("resize", calculatePositionBasedOnWindow);
2612
+ return () => {
2613
+ orientation?.removeEventListener("change", calculatePositionBasedOnWindow);
2614
+ window.removeEventListener("resize", calculatePositionBasedOnWindow);
2615
+ };
2616
+ }, []);
2617
+ const drawChevron = (0, import_react16.useCallback)((graphics) => {
2618
+ graphics.clear();
2619
+ graphics.svg(`
2620
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
2621
+ <path strokeLinecap="round" strokeLinejoin="round" d="${import_core4.iconPaths.chevronUpSmall}" />
2622
+ </svg>
2623
+ `);
2624
+ }, []);
2625
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2626
+ "pixiContainer",
2627
+ {
2628
+ label: "ScrollToTopButton",
2629
+ x: xPos,
2630
+ y: 20,
2631
+ eventMode: "static",
2632
+ onPointerDown: scrollToTop,
2633
+ hitArea: new import_pixi7.Rectangle(0, 0, 50, 50),
2634
+ children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2635
+ "pixiGraphics",
2636
+ {
2637
+ onPointerDown: scrollToTop,
2638
+ eventMode: "static",
2639
+ draw: drawChevron
2640
+ }
2641
+ )
2642
+ }
2643
+ );
2644
+ }
2645
+ var import_react16, import_react17, import_pixi7, import_core4, import_jsx_runtime11;
2646
+ var init_FaceScrollToTopButton = __esm({
2647
+ "src/components/FaceScrollToTopButton.tsx"() {
2648
+ "use strict";
2649
+ import_react16 = require("react");
2650
+ import_react17 = require("@pixi/react");
2651
+ import_pixi7 = require("pixi.js");
2652
+ import_core4 = require("@peerbots/core");
2653
+ import_jsx_runtime11 = require("react/jsx-runtime");
2654
+ }
2655
+ });
2656
+
2657
+ // src/components/PixiFaceView.tsx
2658
+ var PixiFaceView_exports = {};
2659
+ __export(PixiFaceView_exports, {
2660
+ PixiFaceView: () => PixiFaceView,
2661
+ default: () => PixiFaceView_default
2662
+ });
2663
+ function PixiFaceView({
2664
+ isPreview = false,
2665
+ frozen = false
2666
+ } = {}) {
2667
+ (0, import_react19.useExtend)({ Container: import_pixi8.Container, Graphics: import_pixi8.Graphics, Sprite: import_pixi8.Sprite, Text: import_pixi8.Text });
2668
+ const settings = useFaceStore((state) => state.faceSettings);
2669
+ const currentStore = useFaceStoreInstance();
2670
+ const [containerEl, setContainerEl] = (0, import_react18.useState)(null);
2671
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2672
+ "div",
2673
+ {
2674
+ ref: setContainerEl,
2675
+ className: "w-full h-full relative overflow-hidden",
2676
+ "data-testid": "pixi-face-view",
2677
+ children: containerEl ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2678
+ import_react19.Application,
2679
+ {
2680
+ resizeTo: containerEl,
2681
+ backgroundColor: "#ABE3FA",
2682
+ className: "w-full h-full block",
2683
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(FaceStoreContext.Provider, { value: currentStore, children: [
2684
+ !isPreview && settings.showFullScreenButton && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FaceFullScreenButton, {}),
2685
+ !isPreview && settings.showScrollButton && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FaceScrollToTopButton, {}),
2686
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(FaceContainer, { frozen })
2687
+ ] })
2688
+ }
2689
+ ) : null
2690
+ }
2691
+ );
2692
+ }
2693
+ var import_react18, import_react19, import_pixi8, import_jsx_runtime12, PixiFaceView_default;
2694
+ var init_PixiFaceView = __esm({
2695
+ "src/components/PixiFaceView.tsx"() {
2696
+ "use strict";
2697
+ import_react18 = require("react");
2698
+ import_react19 = require("@pixi/react");
2699
+ import_pixi8 = require("pixi.js");
2700
+ init_FaceStoreContext();
2701
+ init_FaceContainer();
2702
+ init_FaceFullScreenButton();
2703
+ init_FaceScrollToTopButton();
2704
+ import_jsx_runtime12 = require("react/jsx-runtime");
2705
+ PixiFaceView_default = PixiFaceView;
2706
+ }
2707
+ });
2708
+
2709
+ // src/components/VizijFaceView.tsx
2710
+ var VizijFaceView_exports = {};
2711
+ __export(VizijFaceView_exports, {
2712
+ VizijFaceView: () => VizijFaceView,
2713
+ default: () => VizijFaceView_default
2714
+ });
2715
+ function VizijFallback({ labels }) {
2716
+ const { loading, error, ready } = (0, import_runtime_react.useVizijRuntime)();
2717
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "flex items-center justify-center w-full h-full text-white bg-slate-900 p-4 text-sm", children: [
2718
+ (loading || !ready) && !error && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: labels.loading }),
2719
+ error && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { children: [
2720
+ labels.vizijErrorPrefix,
2721
+ " ",
2722
+ error.message
2723
+ ] })
2724
+ ] });
2725
+ }
2726
+ function VizijPoseSetter() {
2727
+ const { ready, animateValue, faceId, setInput } = (0, import_runtime_react.useVizijRuntime)();
2728
+ const settings = useFaceStore((state) => state.faceSettings);
2729
+ const lastMessage = useFaceStore((state) => state.lastMessage);
2730
+ const selectedFace = useFaceStore((state) => state.selectedFace);
2731
+ const spokenVisemes = useFaceStore((state) => state.spokenVisemes);
2732
+ const expressEmotion = (0, import_react20.useCallback)(
2733
+ (emotion) => {
2734
+ const expressivity = settings.vizijSettings?.faceExpressivity ?? 1;
2735
+ void animateValue(
2736
+ `rig/${faceId}/emotions/surprise.weight`,
2737
+ (emotion === "Surprised" ? 1 : 0) * expressivity,
2738
+ { duration: 0.2 }
2739
+ );
2740
+ void animateValue(
2741
+ `rig/${faceId}/emotions/happy.weight`,
2742
+ (emotion === "Happy" ? 1 : 0) * expressivity,
2743
+ { duration: 0.2 }
2744
+ );
2745
+ void animateValue(
2746
+ `rig/${faceId}/emotions/sad.weight`,
2747
+ (emotion === "Sad" ? 1 : 0) * expressivity,
2748
+ { duration: 0.2 }
2749
+ );
2750
+ void animateValue(
2751
+ `rig/${faceId}/emotions/concerned.weight`,
2752
+ (emotion === "Concerned" ? 1 : 0) * expressivity,
2753
+ { duration: 0.2 }
2754
+ );
2755
+ void animateValue(
2756
+ `rig/${faceId}/emotions/sleepy.weight`,
2757
+ (emotion === "Sleepy" ? 1 : 0) * expressivity,
2758
+ { duration: 0.2 }
2759
+ );
2760
+ },
2761
+ [animateValue, faceId, settings.vizijSettings?.faceExpressivity]
2762
+ );
2763
+ const expressColor = (0, import_react20.useCallback)(
2764
+ (color) => {
2765
+ const rgbColor = hexToRgb(color_mapping[color]) ?? {
2766
+ r: 0,
2767
+ g: 0,
2768
+ b: 0
2769
+ };
2770
+ void animateValue(`rig/${faceId}/background/color/r`, rgbColor.r / 255, {
2771
+ duration: 0.2
2772
+ });
2773
+ void animateValue(`rig/${faceId}/background/color/g`, rgbColor.g / 255, {
2774
+ duration: 0.2
2775
+ });
2776
+ void animateValue(`rig/${faceId}/background/color/b`, rgbColor.b / 255, {
2777
+ duration: 0.2
2778
+ });
2779
+ },
2780
+ [faceId, animateValue]
2781
+ );
2782
+ const expressViseme = (0, import_react20.useCallback)(
2783
+ (viseme, durationSec, prevViseme) => {
2784
+ const visemeVizijPath = pollyVisemeToVizijPath[viseme];
2785
+ const promises = [];
2786
+ if (viseme === "sil") {
2787
+ possiblePollyVisemes.forEach((target) => {
2788
+ promises.push(
2789
+ animateValue(`rig/${faceId}/visemes/${target}.weight`, 0, {
2790
+ duration: durationSec
2791
+ })
2792
+ );
2793
+ });
2794
+ } else if (visemeVizijPath) {
2795
+ promises.push(
2796
+ animateValue(`rig/${faceId}/visemes/${visemeVizijPath}.weight`, 1, {
2797
+ duration: durationSec
2798
+ })
2799
+ );
2800
+ if (prevViseme) {
2801
+ const prevMappedViseme = pollyVisemeToVizijPath[prevViseme];
2802
+ if (prevMappedViseme && prevMappedViseme !== visemeVizijPath) {
2803
+ promises.push(
2804
+ animateValue(
2805
+ `rig/${faceId}/visemes/${prevMappedViseme}.weight`,
2806
+ 0,
2807
+ { duration: durationSec }
2808
+ )
2809
+ );
2810
+ }
2811
+ }
2812
+ }
2813
+ return Promise.all(promises);
2814
+ },
2815
+ [animateValue, faceId]
2816
+ );
2817
+ const expressTimedVisemes = (0, import_react20.useCallback)(
2818
+ async (visemes) => {
2819
+ let prevViseme;
2820
+ for (const viseme of visemes) {
2821
+ const visemeValue = viseme.value;
2822
+ await expressViseme(visemeValue, viseme.time, prevViseme);
2823
+ prevViseme = visemeValue;
2824
+ }
2825
+ },
2826
+ [expressViseme]
2827
+ );
2828
+ (0, import_react20.useEffect)(() => {
2829
+ if (ready) {
2830
+ expressColor(lastMessage.color);
2831
+ expressEmotion(lastMessage.emotion);
2832
+ }
2833
+ }, [
2834
+ ready,
2835
+ lastMessage.color,
2836
+ lastMessage.emotion,
2837
+ expressColor,
2838
+ expressEmotion
2839
+ ]);
2840
+ (0, import_react20.useEffect)(() => {
2841
+ if (ready && selectedFace?.kind === "Vizij") {
2842
+ setInput(`rig/${faceId}/scene/scale/x`, settings.zoom);
2843
+ setInput(`rig/${faceId}/scene/scale/y`, settings.zoom);
2844
+ setInput(
2845
+ `rig/${faceId}/scene/translation/x`,
2846
+ (settings.offset?.x ?? 0) / 620 - 1
2847
+ );
2848
+ setInput(
2849
+ `rig/${faceId}/scene/translation/y`,
2850
+ (settings.offset?.y ?? 0) / 144 + 1
2851
+ );
2852
+ }
2853
+ }, [ready, selectedFace?.kind, faceId, setInput, settings]);
2854
+ (0, import_react20.useEffect)(() => {
2855
+ if (spokenVisemes !== null && ready) {
2856
+ void expressTimedVisemes(spokenVisemes);
2857
+ }
2858
+ }, [spokenVisemes, ready, expressTimedVisemes]);
2859
+ return null;
2860
+ }
2861
+ function VizijFaceView({ labels } = {}) {
2862
+ const uiLabels = resolveFaceUiLabels(labels);
2863
+ const selectedFace = useFaceStore((state) => state.selectedFace);
2864
+ const settings = useFaceStore((state) => state.faceSettings);
2865
+ if (selectedFace?.kind !== "Vizij") {
2866
+ return null;
2867
+ }
2868
+ const normalizedRot = (settings.rotation % 360 + 360) % 360;
2869
+ const rotClass = ROTATION_CLASS[normalizedRot] ?? ROTATION_CLASS[0];
2870
+ const glb = selectedFace.assetBundle?.glb;
2871
+ const hasGlbUrl = Boolean(glb) && "kind" in glb && glb.kind === "url" && Boolean(glb.src);
2872
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: rotClass, "data-testid": "vizij-face-view", children: hasGlbUrl ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_runtime_react.VizijRuntimeProvider, { assetBundle: selectedFace.assetBundle, autostart: true, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_react20.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(VizijFallback, { labels: uiLabels }), children: [
2873
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_runtime_react.VizijRuntimeFace, { className: "bg-black w-full h-full" }),
2874
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(VizijPoseSetter, {})
2875
+ ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "flex items-center justify-center h-full text-white bg-slate-900 p-4 text-sm", children: uiLabels.vizijUploadGlb }) });
2876
+ }
2877
+ var import_react20, import_runtime_react, import_jsx_runtime13, ROTATION_CLASS, VizijFaceView_default;
2878
+ var init_VizijFaceView = __esm({
2879
+ "src/components/VizijFaceView.tsx"() {
2880
+ "use strict";
2881
+ import_react20 = require("react");
2882
+ import_runtime_react = require("@vizij/runtime-react");
2883
+ init_FaceStoreContext();
2884
+ init_viseme_mapper();
2885
+ init_color_mappers();
2886
+ init_labels();
2887
+ import_jsx_runtime13 = require("react/jsx-runtime");
2888
+ ROTATION_CLASS = {
2889
+ 0: "rotate-0 w-full h-full",
2890
+ 90: "rotate-90 w-full h-full",
2891
+ 180: "rotate-180 w-full h-full",
2892
+ 270: "rotate-270 w-full h-full"
2893
+ };
2894
+ VizijFaceView_default = VizijFaceView;
2895
+ }
2896
+ });
2897
+
2898
+ // src/index.ts
2899
+ var src_exports = {};
2900
+ __export(src_exports, {
2901
+ AudioAnalyzer: () => AudioAnalyzer,
2902
+ CONNECTION_FACE_MESSAGE: () => CONNECTION_FACE_MESSAGE,
2903
+ CharacterSelectionControls: () => CharacterSelectionControls,
2904
+ CharacterSelectionSection: () => CharacterSelectionSection,
2905
+ ControlSettingsSection: () => ControlSettingsSection,
2906
+ DEFAULT_FACE_MESSAGE: () => DEFAULT_FACE_MESSAGE,
2907
+ DEFAULT_FACE_UI_LABELS: () => DEFAULT_FACE_UI_LABELS,
2908
+ EMOTION_EMOJIS: () => EMOTION_EMOJIS,
2909
+ EMOTION_EMOTICONS: () => EMOTION_EMOTICONS,
2910
+ EMOTION_ICON_FILES: () => EMOTION_ICON_FILES,
2911
+ FaceAudioPrompt: () => FaceAudioPrompt,
2912
+ FaceBehaviorControls: () => FaceBehaviorControls,
2913
+ FaceCaption: () => FaceCaption,
2914
+ FacePositioningControls: () => FacePositioningControls,
2915
+ FacePositioningSection: () => FacePositioningSection,
2916
+ FaceRendererRegistry: () => FaceRendererRegistry,
2917
+ FaceSettingsControl: () => FaceSettingsControl,
2918
+ FaceSettingsPanel: () => FaceSettingsPanel,
2919
+ FaceStoreContext: () => FaceStoreContext,
2920
+ FaceStoreProvider: () => FaceStoreProvider,
2921
+ FaceView: () => FaceView,
2922
+ FaceViewSkeleton: () => FaceViewSkeleton,
2923
+ FieldGroup: () => FieldGroup,
2924
+ PEERBOTS_COLORS: () => PEERBOTS_COLORS,
2925
+ PEERBOTS_EMOTIONS: () => PEERBOTS_EMOTIONS,
2926
+ PoweredByVizij: () => PoweredByVizij,
2927
+ StaticFaceFallback: () => StaticFaceFallback,
2928
+ TtsAudioCache: () => TtsAudioCache,
2929
+ VoiceSelector: () => VoiceSelector,
2930
+ audioAnalyzer: () => audioAnalyzer,
2931
+ availableFaces: () => availableFaces,
2932
+ blobToArrayBuffer: () => blobToArrayBuffer,
2933
+ buildTtsCacheKey: () => buildTtsCacheKey,
2934
+ builtInFaces: () => builtInFaces,
2935
+ color_mapping: () => color_mapping,
2936
+ createBuiltInFaces: () => createBuiltInFaces,
2937
+ createBuiltInPixiFaces: () => createBuiltInPixiFaces,
2938
+ createCustomVizijFace: () => createCustomVizijFace,
2939
+ createDefaultFaceRendererRegistry: () => createDefaultFaceRendererRegistry,
2940
+ createFaceRenderingSlice: () => createFaceRenderingSlice,
2941
+ createFaceSpeechSlice: () => createFaceSpeechSlice,
2942
+ createIncludedVizijFaces: () => createIncludedVizijFaces,
2943
+ createPeerbotsFaceStore: () => createPeerbotsFaceStore,
2944
+ customFace: () => customFace,
2945
+ deconstructRgba: () => deconstructRgba,
2946
+ defaultFace: () => defaultFace,
2947
+ defaultFaceRendererRegistry: () => defaultFaceRendererRegistry,
2948
+ defaultFaceSettings: () => defaultFaceSettings,
2949
+ defaultTtsAudioCache: () => defaultTtsAudioCache,
2950
+ emotion_mapping: () => emotion_mapping,
2951
+ estimateVisemesFromText: () => estimateVisemesFromText,
2952
+ findMatchingVoice: () => findMatchingVoice,
2953
+ font_color_mapping: () => font_color_mapping,
2954
+ formatRbga: () => formatRbga,
2955
+ formatRgba: () => formatRgba,
2956
+ formatVoiceDisplayName: () => formatVoiceDisplayName,
2957
+ getEmotionEyeSpritePaths: () => getEmotionEyeSpritePaths,
2958
+ getEmotionIconPath: () => getEmotionIconPath,
2959
+ getFaceCapabilities: () => getFaceCapabilities,
2960
+ getLanguageName: () => getLanguageName,
2961
+ globalFaceStore: () => globalFaceStore,
2962
+ hexToRgb: () => hexToRgb,
2963
+ hexToRgba: () => hexToRgba,
2964
+ includedVizijFaces: () => includedVizijFaces,
2965
+ interpolateColor: () => interpolateColor,
2966
+ isHeadlessOrTestEnvironment: () => isHeadlessOrTestEnvironment,
2967
+ isWebGLAvailable: () => isWebGLAvailable,
2968
+ mapVisemeToVizijTarget: () => mapVisemeToVizijTarget,
2969
+ mergeFaceSettings: () => mergeFaceSettings,
2970
+ normalizeAssetBaseUrl: () => normalizeAssetBaseUrl,
2971
+ pixiFaceRendererStrategy: () => pixiFaceRendererStrategy,
2972
+ pollyVisemeToVizijPath: () => pollyVisemeToVizijPath,
2973
+ possiblePollyVisemes: () => possiblePollyVisemes,
2974
+ rbgToRgba: () => rbgToRgba,
2975
+ resolveFaceUiLabels: () => resolveFaceUiLabels,
2976
+ rgbToRgba: () => rgbToRgba,
2977
+ rgbaToHex: () => rgbaToHex,
2978
+ stopNativeSpeechSynthesis: () => stopNativeSpeechSynthesis,
2979
+ useFaceStore: () => useFaceStore,
2980
+ useFaceStoreInstance: () => useFaceStoreInstance,
2981
+ useMessageVisualState: () => useMessageVisualState,
2982
+ vizijFaceRendererStrategy: () => vizijFaceRendererStrategy
2983
+ });
2984
+ module.exports = __toCommonJS(src_exports);
2985
+
2986
+ // src/types/index.ts
2987
+ init_face();
2988
+
2989
+ // src/types/renderer.ts
2990
+ init_face();
2991
+ var FaceRendererRegistry = class {
2992
+ strategies = /* @__PURE__ */ new Map();
2993
+ constructor(initialStrategies = []) {
2994
+ for (const strategy of initialStrategies) {
2995
+ this.register(strategy);
2996
+ }
2997
+ }
2998
+ register(strategy) {
2999
+ this.strategies.set(strategy.kind, strategy);
3000
+ }
3001
+ unregister(kind) {
3002
+ return this.strategies.delete(kind);
3003
+ }
3004
+ get(kind) {
3005
+ return this.strategies.get(kind);
3006
+ }
3007
+ has(kind) {
3008
+ return this.strategies.has(kind);
3009
+ }
3010
+ list() {
3011
+ return Array.from(this.strategies.values());
3012
+ }
3013
+ getCapabilities(face) {
3014
+ if (!face) {
3015
+ return getFaceCapabilities(void 0);
3016
+ }
3017
+ const strategy = this.strategies.get(face.kind);
3018
+ if (strategy?.getCapabilities) {
3019
+ return strategy.getCapabilities(face);
3020
+ }
3021
+ return getFaceCapabilities(face);
3022
+ }
3023
+ };
3024
+
3025
+ // src/types/index.ts
3026
+ init_labels();
3027
+
3028
+ // src/helpers/index.ts
3029
+ init_viseme_mapper();
3030
+ init_emotion_mapper();
3031
+ init_color_mappers();
3032
+ init_voice_helpers();
3033
+
3034
+ // src/helpers/environment.ts
3035
+ function isWebGLAvailable() {
3036
+ if (typeof window === "undefined" || typeof document === "undefined") {
3037
+ return false;
3038
+ }
3039
+ try {
3040
+ const canvas = document.createElement("canvas");
3041
+ const gl = canvas.getContext("webgl2") || canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
3042
+ return Boolean(gl);
3043
+ } catch (err) {
3044
+ void err;
3045
+ return false;
3046
+ }
3047
+ }
3048
+ function isHeadlessOrTestEnvironment() {
3049
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
3050
+ return true;
3051
+ }
3052
+ const ua = navigator.userAgent || "";
3053
+ if (ua.includes("peerbots-pa11y-ci") || ua.toLowerCase().includes("jsdom") || Boolean(navigator.webdriver) || Boolean(window.__VITEST_BROWSER__)) {
3054
+ return true;
3055
+ }
3056
+ return !isWebGLAvailable();
3057
+ }
3058
+
3059
+ // src/services/index.ts
3060
+ init_AudioAnalyzer();
3061
+ init_ttsAudioCache();
3062
+
3063
+ // src/hooks/index.ts
3064
+ init_useMessageVisualState();
3065
+
3066
+ // src/store/index.ts
3067
+ init_faceRenderingSlice();
3068
+ init_faceSpeechSlice();
3069
+ init_createPeerbotsFaceStore();
3070
+ init_FaceStoreContext();
3071
+
3072
+ // src/components/FaceView.tsx
3073
+ var import_react21 = require("react");
3074
+ var import_core5 = require("@peerbots/core");
3075
+ init_FaceStoreContext();
3076
+ init_face();
3077
+ init_labels();
3078
+
3079
+ // src/components/FaceCaption.tsx
3080
+ var import_react3 = require("react");
3081
+ init_FaceStoreContext();
3082
+ init_useMessageVisualState();
3083
+ var import_jsx_runtime2 = require("react/jsx-runtime");
3084
+ function FaceCaption() {
3085
+ const lastMessage = useFaceStore((state) => state.lastMessage);
3086
+ const settings = useFaceStore((state) => state.faceSettings);
3087
+ const isSpeaking = useFaceStore((state) => state.isSpeaking);
3088
+ const { displayText, queueMessage, update } = useMessageVisualState(
3089
+ isSpeaking,
3090
+ {
3091
+ msPerChar: 0,
3092
+ persistenceDuration: 1e3
3093
+ }
3094
+ );
3095
+ (0, import_react3.useEffect)(() => {
3096
+ queueMessage(lastMessage.speech);
3097
+ }, [lastMessage.speech, queueMessage]);
3098
+ (0, import_react3.useEffect)(() => {
3099
+ if (typeof requestAnimationFrame === "undefined") {
3100
+ return;
3101
+ }
3102
+ let lastTime = performance.now();
3103
+ let frameId;
3104
+ const tick = (now) => {
3105
+ const delta = now - lastTime;
3106
+ lastTime = now;
3107
+ update(delta);
3108
+ frameId = requestAnimationFrame(tick);
3109
+ };
3110
+ frameId = requestAnimationFrame(tick);
3111
+ return () => cancelAnimationFrame(frameId);
3112
+ }, [update]);
3113
+ if (!settings.captions || !settings.captions.enabled) {
3114
+ return null;
3115
+ }
3116
+ if (!displayText || displayText.trim() === "") {
3117
+ return null;
3118
+ }
3119
+ const offsetX = settings.captions.offset?.x ?? 0;
3120
+ const offsetY = settings.captions.offset?.y ?? 0;
3121
+ const fontSize = settings.captions.fontSize ?? 32;
3122
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3123
+ "div",
3124
+ {
3125
+ role: "status",
3126
+ "aria-live": "polite",
3127
+ "data-testid": "face-caption",
3128
+ className: "absolute text-center w-[80%] pointer-events-none z-50 font-sans",
3129
+ style: {
3130
+ top: `calc(${offsetY}% + 80%)`,
3131
+ left: `calc(50% + ${offsetX}px)`,
3132
+ transform: "translate(-50%, -50%)",
3133
+ fontSize: `${fontSize}px`,
3134
+ color: "#ffffff",
3135
+ backgroundColor: "rgba(15, 23, 42, 0.75)",
3136
+ padding: "0.25rem 0.75rem",
3137
+ borderRadius: "0.75rem"
3138
+ },
3139
+ children: displayText
3140
+ }
3141
+ );
3142
+ }
3143
+
3144
+ // src/components/FaceViewSkeleton.tsx
3145
+ var import_core = require("@peerbots/core");
3146
+ var import_jsx_runtime3 = require("react/jsx-runtime");
3147
+ function FaceViewSkeleton({
3148
+ label = "Loading robot face"
3149
+ } = {}) {
3150
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3151
+ "div",
3152
+ {
3153
+ role: "status",
3154
+ "aria-label": label,
3155
+ "data-testid": "face-view-skeleton",
3156
+ className: "flex flex-col items-center justify-center w-full h-full bg-sky-50 p-8 relative",
3157
+ children: [
3158
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex w-[80%] max-w-lg min-w-[260px] justify-around absolute top-1/3 px-12", children: [
3159
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core.Skeleton, { className: "w-16 h-16 md:w-24 md:h-24 rounded-full bg-slate-300" }),
3160
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core.Skeleton, { className: "w-16 h-16 md:w-24 md:h-24 rounded-full bg-slate-300" })
3161
+ ] }),
3162
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mt-48", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core.Skeleton, { className: "w-24 h-6 md:w-32 md:h-12 rounded-full bg-slate-300" }) })
3163
+ ]
3164
+ }
3165
+ );
3166
+ }
3167
+
3168
+ // src/components/StaticFaceFallback.tsx
3169
+ var import_core2 = require("@peerbots/core");
3170
+ init_FaceStoreContext();
3171
+ init_color_mappers();
3172
+ init_emotion_mapper();
3173
+ var import_jsx_runtime4 = require("react/jsx-runtime");
3174
+ function StaticFaceFallback({
3175
+ showSprites = true,
3176
+ className
3177
+ }) {
3178
+ const selectedFace = useFaceStore((state) => state.selectedFace);
3179
+ const lastMessage = useFaceStore((state) => state.lastMessage);
3180
+ const isSpeaking = useFaceStore((state) => state.isSpeaking);
3181
+ const assetBaseUrl = useFaceStore((state) => state.assetBaseUrl);
3182
+ const faceSettings = useFaceStore((state) => state.faceSettings);
3183
+ const bgColor = color_mapping[lastMessage.color] ?? color_mapping["Light Blue"];
3184
+ const fgColor = font_color_mapping[lastMessage.color] ?? font_color_mapping["Light Blue"];
3185
+ const accessibleLabel = `${selectedFace.name} robot face, emotion ${lastMessage.emotion}, color ${lastMessage.color}${isSpeaking ? ", speaking" : ""}`;
3186
+ const pixiSettings = faceSettings.pixiSettings;
3187
+ const isTextDisplay = selectedFace.kind === "PixiFace" && selectedFace.type === "text";
3188
+ const isHugoStyleAvatar = selectedFace.kind === "PixiFace" && selectedFace.type === "avatar" && (selectedFace.name === "Hugo" || selectedFace.name === "Simple");
3189
+ const eyePaths = getEmotionEyeSpritePaths(
3190
+ lastMessage.emotion,
3191
+ "Hugo",
3192
+ assetBaseUrl
3193
+ );
3194
+ const emotionIconPath = getEmotionIconPath(lastMessage.emotion, assetBaseUrl);
3195
+ const textEmotionMode = pixiSettings?.emotionDisplay ?? (isTextDisplay ? selectedFace.showEmotion : "emoticon");
3196
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3197
+ "div",
3198
+ {
3199
+ role: "img",
3200
+ "aria-label": accessibleLabel,
3201
+ "data-testid": "static-face-fallback",
3202
+ "data-face-name": selectedFace.name,
3203
+ "data-face-kind": selectedFace.kind,
3204
+ "data-emotion": lastMessage.emotion,
3205
+ "data-color": lastMessage.color,
3206
+ "data-speaking": String(isSpeaking),
3207
+ className: (0, import_core2.cn)(
3208
+ "flex flex-col items-center justify-center w-full h-full p-6 select-none transition-colors duration-200",
3209
+ className
3210
+ ),
3211
+ style: {
3212
+ backgroundColor: bgColor,
3213
+ color: fgColor
3214
+ },
3215
+ children: isTextDisplay ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col items-center gap-3 font-mono text-center max-w-xl", children: [
3216
+ textEmotionMode !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-4xl font-bold", "aria-hidden": "true", children: textEmotionMode === "emoji" ? EMOTION_EMOJIS[lastMessage.emotion] : EMOTION_EMOTICONS[lastMessage.emotion] }),
3217
+ lastMessage.speech && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-2xl font-semibold break-words", children: lastMessage.speech })
3218
+ ] }) : showSprites && isHugoStyleAvatar ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
3219
+ "div",
3220
+ {
3221
+ className: "flex flex-col items-center justify-center gap-8",
3222
+ "aria-hidden": "true",
3223
+ children: [
3224
+ pixiSettings?.eyeDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex items-center justify-center gap-16 md:gap-24", children: [
3225
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col items-center", children: [
3226
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3227
+ "img",
3228
+ {
3229
+ src: eyePaths.left,
3230
+ alt: "",
3231
+ className: "w-20 h-20 md:w-28 md:h-28 object-contain"
3232
+ }
3233
+ ),
3234
+ selectedFace.cheeks && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3235
+ "img",
3236
+ {
3237
+ src: selectedFace.cheeks.path,
3238
+ alt: "",
3239
+ className: "w-8 h-4 object-contain mt-1"
3240
+ }
3241
+ )
3242
+ ] }),
3243
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-col items-center", children: [
3244
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3245
+ "img",
3246
+ {
3247
+ src: eyePaths.right,
3248
+ alt: "",
3249
+ className: "w-20 h-20 md:w-28 md:h-28 object-contain"
3250
+ }
3251
+ ),
3252
+ selectedFace.cheeks && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3253
+ "img",
3254
+ {
3255
+ src: selectedFace.cheeks.path,
3256
+ alt: "",
3257
+ className: "w-8 h-4 object-contain mt-1"
3258
+ }
3259
+ )
3260
+ ] })
3261
+ ] }),
3262
+ pixiSettings?.mouthDisplay !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3263
+ "div",
3264
+ {
3265
+ className: (0, import_core2.cn)(
3266
+ "rounded-b-full bg-black transition-all duration-150",
3267
+ isSpeaking ? "w-16 h-8" : "w-14 h-3"
3268
+ )
3269
+ }
3270
+ )
3271
+ ]
3272
+ }
3273
+ ) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
3274
+ "div",
3275
+ {
3276
+ className: "flex flex-col items-center justify-center gap-3",
3277
+ "aria-hidden": "true",
3278
+ children: [
3279
+ showSprites && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3280
+ "img",
3281
+ {
3282
+ src: emotionIconPath,
3283
+ alt: "",
3284
+ className: "w-20 h-20 object-contain"
3285
+ }
3286
+ ),
3287
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "text-sm font-semibold tracking-wide", children: [
3288
+ selectedFace.name,
3289
+ " \u2022 ",
3290
+ lastMessage.emotion
3291
+ ] })
3292
+ ]
3293
+ }
3294
+ )
3295
+ }
3296
+ );
3297
+ }
3298
+
3299
+ // src/components/FaceView.tsx
3300
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3301
+ var LazyPixiFaceView = (0, import_react21.lazy)(
3302
+ () => Promise.resolve().then(() => (init_PixiFaceView(), PixiFaceView_exports)).then((module2) => ({
3303
+ default: module2.PixiFaceView
3304
+ }))
3305
+ );
3306
+ var LazyVizijFaceView = (0, import_react21.lazy)(
3307
+ () => Promise.resolve().then(() => (init_VizijFaceView(), VizijFaceView_exports)).then((module2) => ({
3308
+ default: module2.VizijFaceView
3309
+ }))
3310
+ );
3311
+ var pixiFaceRendererStrategy = {
3312
+ kind: "PixiFace",
3313
+ displayName: "PixiJS 2D Face Renderer",
3314
+ requiresWebGL: true,
3315
+ getCapabilities: (face) => getFaceCapabilities(face),
3316
+ render: ({ isPreview, frozen }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LazyPixiFaceView, { isPreview, frozen })
3317
+ };
3318
+ var vizijFaceRendererStrategy = {
3319
+ kind: "Vizij",
3320
+ displayName: "Vizij 3D WebAssembly Face Renderer",
3321
+ requiresWebGL: true,
3322
+ getCapabilities: (face) => getFaceCapabilities(face),
3323
+ render: () => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(LazyVizijFaceView, {})
3324
+ };
3325
+ function createDefaultFaceRendererRegistry() {
3326
+ const registry = new FaceRendererRegistry();
3327
+ registry.register(pixiFaceRendererStrategy);
3328
+ registry.register(vizijFaceRendererStrategy);
3329
+ return registry;
3330
+ }
3331
+ var defaultFaceRendererRegistry = createDefaultFaceRendererRegistry();
3332
+ function FaceView({
3333
+ isPreview = false,
3334
+ frozen = false,
3335
+ renderMode = "auto",
3336
+ showStaticSprites = true,
3337
+ registry = defaultFaceRendererRegistry,
3338
+ labels,
3339
+ className
3340
+ } = {}) {
3341
+ const uiLabels = resolveFaceUiLabels(labels);
3342
+ const selectedFace = useFaceStore((state) => state.selectedFace);
3343
+ const strategy = selectedFace ? registry.get(selectedFace.kind) : void 0;
3344
+ const renderContent = () => {
3345
+ if (!selectedFace || !strategy) {
3346
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3347
+ "div",
3348
+ {
3349
+ role: "alert",
3350
+ className: "flex items-center justify-center w-full h-full bg-slate-100 text-slate-800 text-sm p-4",
3351
+ children: uiLabels.unknownFaceType
3352
+ }
3353
+ );
3354
+ }
3355
+ const useStaticFallback = renderMode === "static" || renderMode === "auto" && strategy.requiresWebGL && isHeadlessOrTestEnvironment();
3356
+ if (useStaticFallback) {
3357
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(StaticFaceFallback, { showSprites: showStaticSprites });
3358
+ }
3359
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react21.Suspense, { fallback: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FaceViewSkeleton, { label: uiLabels.loading }), children: strategy.render({ face: selectedFace, isPreview, frozen }) });
3360
+ };
3361
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
3362
+ "div",
3363
+ {
3364
+ id: "face-view-container",
3365
+ className: (0, import_core5.cn)(
3366
+ "relative w-full h-full text-center overflow-hidden",
3367
+ className
3368
+ ),
3369
+ children: [
3370
+ renderContent(),
3371
+ !isPreview && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(FaceCaption, {})
3372
+ ]
3373
+ }
3374
+ );
3375
+ }
3376
+
3377
+ // src/components/FaceAudioPrompt.tsx
3378
+ var import_react22 = require("react");
3379
+ var import_core6 = require("@peerbots/core");
3380
+ init_FaceStoreContext();
3381
+ init_labels();
3382
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3383
+ function FaceAudioPrompt({
3384
+ className = "",
3385
+ position = "absolute",
3386
+ labels,
3387
+ onEnable
3388
+ }) {
3389
+ const uiLabels = resolveFaceUiLabels(labels);
3390
+ const speechAllowed = useFaceStore((state) => state.speechAllowed);
3391
+ const setSpeechAllowed = useFaceStore((state) => state.setSpeechAllowed);
3392
+ const refreshVoices = useFaceStore((state) => state.refreshVoices);
3393
+ const handleEnableAudio = (0, import_react22.useCallback)(() => {
3394
+ try {
3395
+ if (typeof window !== "undefined" && "speechSynthesis" in window && typeof SpeechSynthesisUtterance !== "undefined") {
3396
+ const utterance = new SpeechSynthesisUtterance(" ");
3397
+ window.speechSynthesis.speak(utterance);
3398
+ }
3399
+ } catch (err) {
3400
+ console.warn("Could not prime speechSynthesis:", err);
3401
+ }
3402
+ setSpeechAllowed(true);
3403
+ void refreshVoices();
3404
+ onEnable?.();
3405
+ }, [setSpeechAllowed, refreshVoices, onEnable]);
3406
+ if (speechAllowed) {
3407
+ return null;
3408
+ }
3409
+ const positionClasses = position === "fixed" ? "fixed top-4 left-1/2 -translate-x-1/2 z-50" : position === "absolute" ? "absolute top-4 left-1/2 -translate-x-1/2 z-50" : "inline-flex";
3410
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3411
+ "div",
3412
+ {
3413
+ className: (0, import_core6.cn)(positionClasses, className),
3414
+ "data-testid": "face-audio-prompt",
3415
+ children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
3416
+ import_core6.Button,
3417
+ {
3418
+ variant: "solid",
3419
+ color: "darkblue",
3420
+ size: "sm",
3421
+ onClick: handleEnableAudio,
3422
+ className: "shadow-lg px-4 py-2 flex items-center gap-2 rounded-full cursor-pointer",
3423
+ "aria-label": uiLabels.tapToEnableSound,
3424
+ children: [
3425
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_core6.Icon, { name: "play", size: "sm", className: "w-3.5 h-3.5" }),
3426
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "font-semibold text-xs tracking-wide", children: uiLabels.tapToEnableSound })
3427
+ ]
3428
+ }
3429
+ )
3430
+ }
3431
+ );
3432
+ }
3433
+
3434
+ // src/components/PoweredByVizij.tsx
3435
+ var import_core7 = require("@peerbots/core");
3436
+ init_FaceStoreContext();
3437
+ init_labels();
3438
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3439
+ function PoweredByVizij({
3440
+ className,
3441
+ poweredByLabel = DEFAULT_FACE_UI_LABELS.poweredBy
3442
+ }) {
3443
+ const assetBaseUrl = useFaceStore((state) => state.assetBaseUrl);
3444
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
3445
+ "a",
3446
+ {
3447
+ href: "https://vizij.ai",
3448
+ target: "_blank",
3449
+ rel: "noopener noreferrer",
3450
+ className: (0, import_core7.cn)(
3451
+ "inline-flex flex-col items-center gap-0.5 group transition-all hover:opacity-100 opacity-90",
3452
+ className
3453
+ ),
3454
+ children: [
3455
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "text-[9px] font-bold text-slate-600 uppercase tracking-[0.2em] leading-tight select-none", children: poweredByLabel }),
3456
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex items-center gap-1.5 focus-visible:outline-none", children: [
3457
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "relative w-5 h-5 group-hover:scale-110 transition-transform duration-300 ease-out", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3458
+ "img",
3459
+ {
3460
+ src: `${assetBaseUrl}/Vizij/brand.svg`,
3461
+ alt: "Vizij Logo",
3462
+ className: "w-full h-full object-contain"
3463
+ }
3464
+ ) }),
3465
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
3466
+ "span",
3467
+ {
3468
+ style: {
3469
+ fontFamily: "Gilroy, SFProRounded, ui-sans-serif, system-ui, sans-serif"
3470
+ },
3471
+ className: "text-lg font-bold tracking-tight text-teal-700",
3472
+ children: "vizij"
3473
+ }
3474
+ )
3475
+ ] })
3476
+ ]
3477
+ }
3478
+ );
3479
+ }
3480
+
3481
+ // src/components/FieldGroup.tsx
3482
+ var import_react23 = require("react");
3483
+ var import_core8 = require("@peerbots/core");
3484
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3485
+ function FieldGroup({
3486
+ label,
3487
+ icon,
3488
+ description,
3489
+ children,
3490
+ className,
3491
+ id: customId
3492
+ }) {
3493
+ const generatedId = (0, import_react23.useId)();
3494
+ const labelId = customId || `field-group-${generatedId}`;
3495
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3496
+ "div",
3497
+ {
3498
+ role: "group",
3499
+ "aria-labelledby": label ? labelId : void 0,
3500
+ className: (0, import_core8.cn)("flex flex-col gap-1.5 w-full", className),
3501
+ children: [
3502
+ label && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3503
+ "span",
3504
+ {
3505
+ id: labelId,
3506
+ className: "text-sm font-bold leading-6 text-slate-700 flex items-center gap-1",
3507
+ children: [
3508
+ icon && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "shrink-0", children: icon }),
3509
+ label
3510
+ ]
3511
+ }
3512
+ ),
3513
+ children,
3514
+ description && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "text-xs text-slate-600", children: description })
3515
+ ]
3516
+ }
3517
+ );
3518
+ }
3519
+
3520
+ // src/components/VoiceSelector.tsx
3521
+ var import_react24 = require("react");
3522
+ var import_core9 = require("@peerbots/core");
3523
+ init_voice_helpers();
3524
+ init_labels();
3525
+ var import_jsx_runtime18 = require("react/jsx-runtime");
3526
+ function VoiceSelector({
3527
+ voices,
3528
+ selectedVoiceUri,
3529
+ selectedLanguage,
3530
+ onVoiceChange,
3531
+ onLanguageChange,
3532
+ labels,
3533
+ className
3534
+ }) {
3535
+ const uiLabels = resolveFaceUiLabels(labels);
3536
+ const languages = (0, import_react24.useMemo)(() => {
3537
+ const unique = new Set(
3538
+ voices.map((v) => getLanguageName(v.lang)).filter(Boolean)
3539
+ );
3540
+ if (selectedLanguage && !unique.has(selectedLanguage)) {
3541
+ unique.add(selectedLanguage);
3542
+ }
3543
+ if (unique.size === 0) {
3544
+ unique.add("English");
3545
+ }
3546
+ return Array.from(unique).sort().map((langName) => ({
3547
+ label: langName,
3548
+ value: langName
3549
+ }));
3550
+ }, [voices, selectedLanguage]);
3551
+ const filteredVoices = (0, import_react24.useMemo)(() => {
3552
+ const list = voices.filter(
3553
+ (v) => !selectedLanguage || getLanguageName(v.lang) === selectedLanguage
3554
+ ).map((v) => ({
3555
+ displayName: formatVoiceDisplayName(v.name || v.voiceURI),
3556
+ voiceURI: v.voiceURI
3557
+ })).sort((a, b) => a.displayName.localeCompare(b.displayName)).map((voice) => ({
3558
+ label: voice.displayName,
3559
+ value: voice.voiceURI
3560
+ }));
3561
+ if (list.length === 0) {
3562
+ return [
3563
+ {
3564
+ label: "System Default Voice",
3565
+ value: selectedVoiceUri || "default"
3566
+ }
3567
+ ];
3568
+ }
3569
+ return list;
3570
+ }, [voices, selectedLanguage, selectedVoiceUri]);
3571
+ const activeVoiceValue = (0, import_react24.useMemo)(() => {
3572
+ if (!selectedVoiceUri) {
3573
+ return filteredVoices[0]?.value ?? "";
3574
+ }
3575
+ const matched = findMatchingVoice(
3576
+ filteredVoices.map((v) => ({ name: v.label, voiceURI: v.value })),
3577
+ selectedVoiceUri
3578
+ );
3579
+ return matched ? matched.voiceURI : selectedVoiceUri;
3580
+ }, [selectedVoiceUri, filteredVoices]);
3581
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("div", { className: (0, import_core9.cn)("flex flex-col gap-3", className), children: [
3582
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_core9.Field, { label: uiLabels.voiceSelectorLanguage, className: "flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3583
+ import_core9.Select,
3584
+ {
3585
+ "aria-label": uiLabels.voiceSelectorLanguage,
3586
+ className: "w-full",
3587
+ value: selectedLanguage || languages[0]?.value || "English",
3588
+ onChange: (val) => {
3589
+ if (val && onLanguageChange) {
3590
+ onLanguageChange(String(val));
3591
+ }
3592
+ },
3593
+ options: languages
3594
+ }
3595
+ ) }),
3596
+ /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_core9.Field, { label: uiLabels.voiceSelectorVoice, className: "flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3597
+ import_core9.Select,
3598
+ {
3599
+ "aria-label": uiLabels.voiceSelectorVoice,
3600
+ className: "w-full",
3601
+ value: activeVoiceValue,
3602
+ onChange: (val) => {
3603
+ if (val) {
3604
+ onVoiceChange(String(val));
3605
+ }
3606
+ },
3607
+ options: filteredVoices
3608
+ }
3609
+ ) })
3610
+ ] });
3611
+ }
3612
+
3613
+ // src/components/CharacterSelectionControls.tsx
3614
+ var import_core10 = require("@peerbots/core");
3615
+ init_face();
3616
+ init_labels();
3617
+ init_FaceStoreContext();
3618
+ init_voice_helpers();
3619
+ var import_jsx_runtime19 = require("react/jsx-runtime");
3620
+ function CharacterSelectionControls({
3621
+ enableVizij = true,
3622
+ labels
3623
+ } = {}) {
3624
+ const uiLabels = resolveFaceUiLabels(labels);
3625
+ const faceSettings = useFaceStore((state) => state.faceSettings);
3626
+ const availableFaces2 = useFaceStore((state) => state.availableFaces);
3627
+ const availableVoices = useFaceStore((state) => state.availableVoices);
3628
+ const refreshVoices = useFaceStore((state) => state.refreshVoices);
3629
+ const selectedFace = useFaceStore((state) => state.selectedFace);
3630
+ const getSelectedVoice = useFaceStore((state) => state.getSelectedVoice);
3631
+ const selectedVoiceUri = useFaceStore((state) => state.selectedVoiceUri);
3632
+ const setLanguage = useFaceStore((state) => state.setLanguage);
3633
+ const setVoice = useFaceStore((state) => state.setVoice);
3634
+ const setFace = useFaceStore((state) => state.setFace);
3635
+ const setFaceSettings = useFaceStore((state) => state.setFaceSettings);
3636
+ const speechAllowed = useFaceStore((state) => state.speechAllowed);
3637
+ const setSpeechAllowed = useFaceStore((state) => state.setSpeechAllowed);
3638
+ const currentVoiceUri = selectedVoiceUri || getSelectedVoice()?.voiceURI || "";
3639
+ const selectableFaces = enableVizij ? availableFaces2 : availableFaces2.filter((f) => f.kind !== "Vizij");
3640
+ const caps = getFaceCapabilities(selectedFace);
3641
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.SettingsPanel, { title: uiLabels.characterSelection, headingLevel: 4, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-4", children: [
3642
+ !speechAllowed && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
3643
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: "flex", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3644
+ import_core10.Button,
3645
+ {
3646
+ variant: "solid",
3647
+ color: "darkblue",
3648
+ size: "sm",
3649
+ onClick: () => {
3650
+ try {
3651
+ if (typeof window !== "undefined" && "speechSynthesis" in window && typeof SpeechSynthesisUtterance !== "undefined") {
3652
+ const utterance = new SpeechSynthesisUtterance(" ");
3653
+ window.speechSynthesis.speak(utterance);
3654
+ }
3655
+ } catch (err) {
3656
+ console.warn("SpeechSynthesis prime warning:", err);
3657
+ }
3658
+ setSpeechAllowed(true);
3659
+ void refreshVoices();
3660
+ },
3661
+ children: uiLabels.allowSpeech
3662
+ }
3663
+ ) }),
3664
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.Separator, {})
3665
+ ] }),
3666
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3667
+ VoiceSelector,
3668
+ {
3669
+ voices: availableVoices,
3670
+ selectedVoiceUri: currentVoiceUri,
3671
+ selectedLanguage: faceSettings.selectedLanguage,
3672
+ labels: uiLabels,
3673
+ onLanguageChange: (newLang) => {
3674
+ setLanguage(newLang);
3675
+ const firstVoice = availableVoices.find(
3676
+ (v) => getLanguageName(v.lang) === newLang
3677
+ );
3678
+ if (firstVoice) {
3679
+ setVoice(firstVoice.voiceURI);
3680
+ }
3681
+ },
3682
+ onVoiceChange: (newVoiceUri) => {
3683
+ setVoice(newVoiceUri);
3684
+ }
3685
+ }
3686
+ ),
3687
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.Field, { label: uiLabels.face, className: "flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3688
+ import_core10.Select,
3689
+ {
3690
+ "aria-label": uiLabels.face,
3691
+ className: "w-full",
3692
+ value: selectedFace ? selectedFace.name : "Hugo",
3693
+ onChange: (selectedName) => {
3694
+ const found = selectableFaces.find(
3695
+ (f) => f.name === String(selectedName)
3696
+ );
3697
+ if (found) {
3698
+ setFace(found);
3699
+ }
3700
+ },
3701
+ options: selectableFaces.map((face) => ({
3702
+ label: face.name,
3703
+ value: face.name
3704
+ }))
3705
+ }
3706
+ ) }),
3707
+ selectedFace?.name === "Custom Face" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.Field, { label: uiLabels.uploadGlb, className: "flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3708
+ import_core10.Input,
3709
+ {
3710
+ "aria-label": uiLabels.uploadGlb,
3711
+ type: "file",
3712
+ accept: ".glb",
3713
+ className: "w-full text-sm text-slate-900",
3714
+ onChange: (e) => {
3715
+ const file = e.target.files?.[0];
3716
+ if (file && selectedFace?.kind === "Vizij") {
3717
+ const url = URL.createObjectURL(file);
3718
+ const updatedFace = {
3719
+ ...selectedFace,
3720
+ assetBundle: {
3721
+ ...selectedFace.assetBundle,
3722
+ glb: {
3723
+ kind: "url",
3724
+ src: url,
3725
+ aggressiveImport: true
3726
+ }
3727
+ }
3728
+ };
3729
+ setFace(updatedFace);
3730
+ }
3731
+ }
3732
+ }
3733
+ ) }),
3734
+ selectedFace && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "py-1.5 px-3 border-l-2 rtl:border-l-0 rtl:border-r-2 border-teal-700/30 bg-slate-50 rounded-r-md", children: [
3735
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[11px] font-bold text-slate-700 uppercase tracking-wider mb-1.5 block", children: uiLabels.faceCapabilities }),
3736
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-row flex-wrap gap-x-4 gap-y-2", children: [
3737
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-start gap-1.5 min-w-fit", children: [
3738
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3739
+ "span",
3740
+ {
3741
+ "aria-hidden": "true",
3742
+ className: `mt-1 w-2 h-2 rounded-full ${caps.canExpressColor ? "bg-emerald-600" : "bg-slate-400"}`
3743
+ }
3744
+ ),
3745
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-col", children: [
3746
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-xs font-semibold text-slate-800", children: uiLabels.color }),
3747
+ typeof caps.canExpressColor === "string" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[11px] text-slate-600", children: caps.canExpressColor })
3748
+ ] })
3749
+ ] }),
3750
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-start gap-1.5 min-w-fit", children: [
3751
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3752
+ "span",
3753
+ {
3754
+ "aria-hidden": "true",
3755
+ className: `mt-1 w-2 h-2 rounded-full ${caps.canExpressEmotion ? "bg-emerald-600" : "bg-slate-400"}`
3756
+ }
3757
+ ),
3758
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-col", children: [
3759
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-xs font-semibold text-slate-800", children: uiLabels.emotion }),
3760
+ typeof caps.canExpressEmotion === "string" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[11px] text-slate-600", children: caps.canExpressEmotion })
3761
+ ] })
3762
+ ] }),
3763
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-start gap-1.5 min-w-fit", children: [
3764
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3765
+ "span",
3766
+ {
3767
+ "aria-hidden": "true",
3768
+ className: `mt-1 w-2 h-2 rounded-full ${caps.canLipSync ? "bg-emerald-600" : "bg-slate-400"}`
3769
+ }
3770
+ ),
3771
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-col", children: [
3772
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-xs font-semibold text-slate-800", children: uiLabels.speech }),
3773
+ typeof caps.canLipSync === "string" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "text-[11px] text-slate-600", children: caps.canLipSync })
3774
+ ] })
3775
+ ] })
3776
+ ] })
3777
+ ] }),
3778
+ enableVizij && selectedFace?.kind === "Vizij" && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
3779
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.Separator, {}),
3780
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-3", children: [
3781
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex items-center justify-between", children: [
3782
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "font-bold text-sm text-slate-800", children: uiLabels.faceSpecificSettings }),
3783
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(PoweredByVizij, { poweredByLabel: uiLabels.poweredBy })
3784
+ ] }),
3785
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(FieldGroup, { label: uiLabels.faceExpressivity, children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3786
+ import_core10.SliderWithNumberField,
3787
+ {
3788
+ "aria-label": uiLabels.faceExpressivity,
3789
+ min: 0,
3790
+ max: 1,
3791
+ step: 0.05,
3792
+ value: faceSettings.vizijSettings?.faceExpressivity ?? 1,
3793
+ onChange: (val) => {
3794
+ const vizijSettings = faceSettings.vizijSettings ?? defaultFaceSettings.vizijSettings;
3795
+ setFaceSettings({
3796
+ vizijSettings: {
3797
+ ...vizijSettings,
3798
+ faceExpressivity: val
3799
+ }
3800
+ });
3801
+ }
3802
+ }
3803
+ ) })
3804
+ ] })
3805
+ ] }),
3806
+ selectedFace?.kind === "PixiFace" && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)(import_jsx_runtime19.Fragment, { children: [
3807
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_core10.Separator, {}),
3808
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "space-y-3", children: [
3809
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("span", { className: "font-bold text-sm text-slate-800 block", children: uiLabels.faceSpecificSettings }),
3810
+ selectedFace.type === "avatar" && /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: "flex flex-col gap-3", children: [
3811
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3812
+ import_core10.Field,
3813
+ {
3814
+ label: uiLabels.eyes,
3815
+ labelPlacement: "left",
3816
+ className: "flex-row items-center justify-between",
3817
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3818
+ import_core10.TabRadio,
3819
+ {
3820
+ "aria-label": uiLabels.eyes,
3821
+ options: [
3822
+ { value: "default", label: uiLabels.defaultOption },
3823
+ { value: "none", label: uiLabels.noneOption }
3824
+ ],
3825
+ value: faceSettings.pixiSettings?.eyeDisplay ?? "default",
3826
+ onChange: (val) => {
3827
+ const pixiSettings = faceSettings.pixiSettings ?? defaultFaceSettings.pixiSettings;
3828
+ setFaceSettings({
3829
+ pixiSettings: {
3830
+ ...pixiSettings,
3831
+ eyeDisplay: val || "default"
3832
+ }
3833
+ });
3834
+ }
3835
+ }
3836
+ )
3837
+ }
3838
+ ),
3839
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3840
+ import_core10.Field,
3841
+ {
3842
+ label: uiLabels.mouth,
3843
+ labelPlacement: "left",
3844
+ className: "flex-row items-center justify-between",
3845
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3846
+ import_core10.TabRadio,
3847
+ {
3848
+ "aria-label": uiLabels.mouth,
3849
+ options: [
3850
+ { value: "default", label: uiLabels.defaultOption },
3851
+ { value: "none", label: uiLabels.noneOption }
3852
+ ],
3853
+ value: faceSettings.pixiSettings?.mouthDisplay ?? "default",
3854
+ onChange: (val) => {
3855
+ const pixiSettings = faceSettings.pixiSettings ?? defaultFaceSettings.pixiSettings;
3856
+ setFaceSettings({
3857
+ pixiSettings: {
3858
+ ...pixiSettings,
3859
+ mouthDisplay: val || "default"
3860
+ }
3861
+ });
3862
+ }
3863
+ }
3864
+ )
3865
+ }
3866
+ ),
3867
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3868
+ import_core10.Field,
3869
+ {
3870
+ label: uiLabels.cheeks,
3871
+ labelPlacement: "left",
3872
+ className: "flex-row items-center justify-between",
3873
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3874
+ import_core10.TabRadio,
3875
+ {
3876
+ "aria-label": uiLabels.cheeks,
3877
+ options: [
3878
+ { value: "default", label: uiLabels.defaultOption },
3879
+ { value: "none", label: uiLabels.noneOption }
3880
+ ],
3881
+ value: faceSettings.pixiSettings?.cheekDisplay ?? "default",
3882
+ onChange: (val) => {
3883
+ const pixiSettings = faceSettings.pixiSettings ?? defaultFaceSettings.pixiSettings;
3884
+ setFaceSettings({
3885
+ pixiSettings: {
3886
+ ...pixiSettings,
3887
+ cheekDisplay: val || "default"
3888
+ }
3889
+ });
3890
+ }
3891
+ }
3892
+ )
3893
+ }
3894
+ )
3895
+ ] }),
3896
+ selectedFace.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3897
+ import_core10.Field,
3898
+ {
3899
+ label: uiLabels.emotionDisplay,
3900
+ labelPlacement: "left",
3901
+ className: "flex-row items-center justify-between",
3902
+ children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3903
+ import_core10.TabRadio,
3904
+ {
3905
+ "aria-label": uiLabels.emotionDisplay,
3906
+ options: [
3907
+ { value: "emoticon", label: uiLabels.emoticon },
3908
+ { value: "emoji", label: uiLabels.emoji },
3909
+ { value: "none", label: uiLabels.noneOption }
3910
+ ],
3911
+ value: faceSettings.pixiSettings?.emotionDisplay ?? "emoticon",
3912
+ onChange: (val) => {
3913
+ const pixiSettings = faceSettings.pixiSettings ?? defaultFaceSettings.pixiSettings;
3914
+ setFaceSettings({
3915
+ pixiSettings: {
3916
+ ...pixiSettings,
3917
+ emotionDisplay: val || "emoticon"
3918
+ }
3919
+ });
3920
+ }
3921
+ }
3922
+ )
3923
+ }
3924
+ )
3925
+ ] })
3926
+ ] })
3927
+ ] }) });
3928
+ }
3929
+ var CharacterSelectionSection = CharacterSelectionControls;
3930
+
3931
+ // src/components/FacePositioningControls.tsx
3932
+ var import_core11 = require("@peerbots/core");
3933
+ init_FaceStoreContext();
3934
+ init_labels();
3935
+ var import_jsx_runtime20 = require("react/jsx-runtime");
3936
+ function FacePositioningControls({
3937
+ labels
3938
+ } = {}) {
3939
+ const uiLabels = resolveFaceUiLabels(labels);
3940
+ const faceSettings = useFaceStore((state) => state.faceSettings);
3941
+ const setFaceSettings = useFaceStore((state) => state.setFaceSettings);
3942
+ const resetPositioning = useFaceStore((state) => state.resetPositioning);
3943
+ const isModified = faceSettings.zoom !== 1 || (faceSettings.offset?.x ?? 0) !== 0 || (faceSettings.offset?.y ?? 0) !== 0 || faceSettings.rotation !== 0;
3944
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.SettingsPanel, { title: uiLabels.positioning, headingLevel: 4, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "space-y-4", children: [
3945
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex w-full flex-wrap items-center justify-between gap-2", children: [
3946
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3947
+ import_core11.Field,
3948
+ {
3949
+ label: uiLabels.autoRotate,
3950
+ labelPlacement: "left",
3951
+ labelWeight: "normal",
3952
+ className: "flex-row items-center gap-2 mb-0 !w-auto",
3953
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3954
+ import_core11.Switch,
3955
+ {
3956
+ "aria-label": uiLabels.autoRotate,
3957
+ checked: faceSettings.autoRotate,
3958
+ onChange: (checked) => {
3959
+ setFaceSettings({ autoRotate: checked });
3960
+ }
3961
+ }
3962
+ )
3963
+ }
3964
+ ),
3965
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex items-center gap-1.5 shrink-0", children: [
3966
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3967
+ import_core11.Button,
3968
+ {
3969
+ variant: "ghost",
3970
+ size: "sm",
3971
+ className: "p-1.5 text-xs whitespace-nowrap",
3972
+ onClick: () => {
3973
+ setFaceSettings({
3974
+ rotation: (faceSettings.rotation + 90) % 360
3975
+ });
3976
+ },
3977
+ leftIcon: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Icon, { name: "arrowPath", className: "h-3.5 w-3.5" }),
3978
+ children: uiLabels.rotate
3979
+ }
3980
+ ),
3981
+ isModified && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3982
+ import_core11.Button,
3983
+ {
3984
+ variant: "ghost",
3985
+ size: "sm",
3986
+ className: "p-1.5 text-xs whitespace-nowrap",
3987
+ onClick: resetPositioning,
3988
+ leftIcon: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Icon, { name: "arrowUturnLeft", className: "h-3.5 w-3.5" }),
3989
+ children: uiLabels.reset
3990
+ }
3991
+ )
3992
+ ] })
3993
+ ] }),
3994
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Separator, {}),
3995
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: "flex flex-col gap-4", children: [
3996
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
3997
+ FieldGroup,
3998
+ {
3999
+ label: uiLabels.zoom,
4000
+ icon: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Icon, { name: "magnifyingGlassPlus" }),
4001
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4002
+ import_core11.SliderWithNumberField,
4003
+ {
4004
+ "aria-label": uiLabels.zoom,
4005
+ min: 0.1,
4006
+ max: 3,
4007
+ step: 0.05,
4008
+ value: faceSettings.zoom,
4009
+ onChange: (val) => {
4010
+ setFaceSettings({ zoom: val });
4011
+ }
4012
+ }
4013
+ )
4014
+ }
4015
+ ),
4016
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4017
+ FieldGroup,
4018
+ {
4019
+ label: uiLabels.horizontalOffset,
4020
+ icon: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Icon, { name: "arrowsRightLeft" }),
4021
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4022
+ import_core11.SliderWithNumberField,
4023
+ {
4024
+ "aria-label": uiLabels.horizontalOffset,
4025
+ min: -1e3,
4026
+ max: 1e3,
4027
+ value: faceSettings.offset?.x ?? 0,
4028
+ onChange: (val) => {
4029
+ setFaceSettings({
4030
+ offset: {
4031
+ x: val,
4032
+ y: faceSettings.offset?.y ?? 0
4033
+ }
4034
+ });
4035
+ }
4036
+ }
4037
+ )
4038
+ }
4039
+ ),
4040
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4041
+ FieldGroup,
4042
+ {
4043
+ label: uiLabels.verticalOffset,
4044
+ icon: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_core11.Icon, { name: "arrowsUpDown" }),
4045
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4046
+ import_core11.SliderWithNumberField,
4047
+ {
4048
+ "aria-label": uiLabels.verticalOffset,
4049
+ min: -1e3,
4050
+ max: 1e3,
4051
+ value: faceSettings.offset?.y ?? 0,
4052
+ onChange: (val) => {
4053
+ setFaceSettings({
4054
+ offset: {
4055
+ x: faceSettings.offset?.x ?? 0,
4056
+ y: val
4057
+ }
4058
+ });
4059
+ }
4060
+ }
4061
+ )
4062
+ }
4063
+ )
4064
+ ] })
4065
+ ] }) });
4066
+ }
4067
+ var FacePositioningSection = FacePositioningControls;
4068
+
4069
+ // src/components/FaceBehaviorControls.tsx
4070
+ var import_core12 = require("@peerbots/core");
4071
+ init_labels();
4072
+ init_FaceStoreContext();
4073
+ var import_jsx_runtime21 = require("react/jsx-runtime");
4074
+ function FaceBehaviorControls({
4075
+ labels
4076
+ } = {}) {
4077
+ const uiLabels = resolveFaceUiLabels(labels);
4078
+ const faceSettings = useFaceStore((state) => state.faceSettings);
4079
+ const setFaceSettings = useFaceStore((state) => state.setFaceSettings);
4080
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core12.SettingsPanel, { title: uiLabels.faceSettings, headingLevel: 4, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-4", children: [
4081
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-2", children: [
4082
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "font-bold text-sm text-slate-800", children: uiLabels.onFaceButtons }),
4083
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4084
+ import_core12.Field,
4085
+ {
4086
+ label: uiLabels.showFullScreenButton,
4087
+ labelPlacement: "left",
4088
+ labelWeight: "normal",
4089
+ className: "flex-row items-center justify-between",
4090
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4091
+ import_core12.Switch,
4092
+ {
4093
+ "aria-label": uiLabels.showFullScreenButton,
4094
+ checked: faceSettings.showFullScreenButton,
4095
+ onChange: (checked) => {
4096
+ setFaceSettings({ showFullScreenButton: checked });
4097
+ }
4098
+ }
4099
+ )
4100
+ }
4101
+ ),
4102
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4103
+ import_core12.Field,
4104
+ {
4105
+ label: uiLabels.showScrollButton,
4106
+ labelPlacement: "left",
4107
+ labelWeight: "normal",
4108
+ className: "flex-row items-center justify-between",
4109
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4110
+ import_core12.Switch,
4111
+ {
4112
+ "aria-label": uiLabels.showScrollButton,
4113
+ checked: faceSettings.showScrollButton,
4114
+ onChange: (checked) => {
4115
+ setFaceSettings({ showScrollButton: checked });
4116
+ }
4117
+ }
4118
+ )
4119
+ }
4120
+ )
4121
+ ] }),
4122
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core12.Separator, {}),
4123
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-2", children: [
4124
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { className: "font-bold text-sm text-slate-800", children: uiLabels.speechBehavior }),
4125
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core12.Field, { label: uiLabels.newButtonSpeech, className: "flex-col gap-1", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4126
+ import_core12.Select,
4127
+ {
4128
+ "aria-label": uiLabels.newButtonSpeech,
4129
+ className: "w-full",
4130
+ value: faceSettings.speechQueueMode || "interrupt",
4131
+ onChange: (val) => {
4132
+ if (val) {
4133
+ setFaceSettings({
4134
+ speechQueueMode: val
4135
+ });
4136
+ }
4137
+ },
4138
+ options: [
4139
+ {
4140
+ label: uiLabels.interruptSpeech,
4141
+ value: "interrupt"
4142
+ },
4143
+ {
4144
+ label: uiLabels.queueSpeech,
4145
+ value: "queue"
4146
+ }
4147
+ ]
4148
+ }
4149
+ ) })
4150
+ ] }),
4151
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_core12.Separator, {}),
4152
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-3", children: [
4153
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4154
+ import_core12.Field,
4155
+ {
4156
+ label: uiLabels.captions,
4157
+ labelPlacement: "left",
4158
+ labelWeight: "bold",
4159
+ className: "flex-row items-center justify-between",
4160
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4161
+ import_core12.Switch,
4162
+ {
4163
+ "aria-label": uiLabels.captions,
4164
+ checked: faceSettings.captions?.enabled ?? false,
4165
+ onChange: (checked) => {
4166
+ setFaceSettings({
4167
+ captions: {
4168
+ ...faceSettings.captions,
4169
+ enabled: checked
4170
+ }
4171
+ });
4172
+ }
4173
+ }
4174
+ )
4175
+ }
4176
+ ),
4177
+ faceSettings.captions?.enabled && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: "flex flex-col gap-4 mt-1", children: [
4178
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldGroup, { label: uiLabels.fontSize, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4179
+ import_core12.SliderWithNumberField,
4180
+ {
4181
+ "aria-label": uiLabels.fontSize,
4182
+ min: 10,
4183
+ max: 100,
4184
+ step: 1,
4185
+ value: faceSettings.captions?.fontSize ?? 32,
4186
+ onChange: (val) => {
4187
+ setFaceSettings({
4188
+ captions: {
4189
+ ...faceSettings.captions,
4190
+ fontSize: val
4191
+ }
4192
+ });
4193
+ }
4194
+ }
4195
+ ) }),
4196
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldGroup, { label: uiLabels.horizontalOffset, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4197
+ import_core12.SliderWithNumberField,
4198
+ {
4199
+ "aria-label": uiLabels.horizontalOffset,
4200
+ min: -400,
4201
+ max: 400,
4202
+ step: 1,
4203
+ value: faceSettings.captions?.offset?.x ?? 0,
4204
+ onChange: (val) => {
4205
+ setFaceSettings({
4206
+ captions: {
4207
+ ...faceSettings.captions,
4208
+ offset: {
4209
+ x: val,
4210
+ y: faceSettings.captions?.offset?.y ?? 0
4211
+ }
4212
+ }
4213
+ });
4214
+ }
4215
+ }
4216
+ ) }),
4217
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldGroup, { label: uiLabels.verticalPosition, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4218
+ import_core12.SliderWithNumberField,
4219
+ {
4220
+ "aria-label": uiLabels.verticalPosition,
4221
+ min: -50,
4222
+ max: 50,
4223
+ step: 1,
4224
+ value: faceSettings.captions?.offset?.y ?? 0,
4225
+ onChange: (val) => {
4226
+ setFaceSettings({
4227
+ captions: {
4228
+ ...faceSettings.captions,
4229
+ offset: {
4230
+ x: faceSettings.captions?.offset?.x ?? 0,
4231
+ y: val
4232
+ }
4233
+ }
4234
+ });
4235
+ }
4236
+ }
4237
+ ) })
4238
+ ] })
4239
+ ] })
4240
+ ] }) });
4241
+ }
4242
+ var ControlSettingsSection = FaceBehaviorControls;
4243
+
4244
+ // src/components/FaceSettingsPanel.tsx
4245
+ var import_core13 = require("@peerbots/core");
4246
+ init_labels();
4247
+ var import_jsx_runtime22 = require("react/jsx-runtime");
4248
+ function FaceSettingsPanel({
4249
+ inline = false,
4250
+ enableVizij = true,
4251
+ columns = 3,
4252
+ labels,
4253
+ className
4254
+ } = {}) {
4255
+ const uiLabels = resolveFaceUiLabels(labels);
4256
+ const gridClass = columns === 1 ? "grid items-start gap-4 grid-cols-1" : "grid items-start gap-4 lg:gap-6 grid-cols-1 md:grid-cols-2 lg:grid-cols-3";
4257
+ const content = /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: (0, import_core13.cn)(gridClass, className), children: [
4258
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "min-w-0 h-full", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(CharacterSelectionControls, { enableVizij, labels: uiLabels }) }),
4259
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "min-w-0 h-full", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FacePositioningControls, { labels: uiLabels }) }),
4260
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: "min-w-0 h-full", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FaceBehaviorControls, { labels: uiLabels }) })
4261
+ ] });
4262
+ if (inline) {
4263
+ return content;
4264
+ }
4265
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_core13.SettingsPanel, { title: uiLabels.faceSettings, children: content });
4266
+ }
4267
+ var FaceSettingsControl = FaceSettingsPanel;
4268
+ // Annotate the CommonJS export names for ESM import in node:
4269
+ 0 && (module.exports = {
4270
+ AudioAnalyzer,
4271
+ CONNECTION_FACE_MESSAGE,
4272
+ CharacterSelectionControls,
4273
+ CharacterSelectionSection,
4274
+ ControlSettingsSection,
4275
+ DEFAULT_FACE_MESSAGE,
4276
+ DEFAULT_FACE_UI_LABELS,
4277
+ EMOTION_EMOJIS,
4278
+ EMOTION_EMOTICONS,
4279
+ EMOTION_ICON_FILES,
4280
+ FaceAudioPrompt,
4281
+ FaceBehaviorControls,
4282
+ FaceCaption,
4283
+ FacePositioningControls,
4284
+ FacePositioningSection,
4285
+ FaceRendererRegistry,
4286
+ FaceSettingsControl,
4287
+ FaceSettingsPanel,
4288
+ FaceStoreContext,
4289
+ FaceStoreProvider,
4290
+ FaceView,
4291
+ FaceViewSkeleton,
4292
+ FieldGroup,
4293
+ PEERBOTS_COLORS,
4294
+ PEERBOTS_EMOTIONS,
4295
+ PoweredByVizij,
4296
+ StaticFaceFallback,
4297
+ TtsAudioCache,
4298
+ VoiceSelector,
4299
+ audioAnalyzer,
4300
+ availableFaces,
4301
+ blobToArrayBuffer,
4302
+ buildTtsCacheKey,
4303
+ builtInFaces,
4304
+ color_mapping,
4305
+ createBuiltInFaces,
4306
+ createBuiltInPixiFaces,
4307
+ createCustomVizijFace,
4308
+ createDefaultFaceRendererRegistry,
4309
+ createFaceRenderingSlice,
4310
+ createFaceSpeechSlice,
4311
+ createIncludedVizijFaces,
4312
+ createPeerbotsFaceStore,
4313
+ customFace,
4314
+ deconstructRgba,
4315
+ defaultFace,
4316
+ defaultFaceRendererRegistry,
4317
+ defaultFaceSettings,
4318
+ defaultTtsAudioCache,
4319
+ emotion_mapping,
4320
+ estimateVisemesFromText,
4321
+ findMatchingVoice,
4322
+ font_color_mapping,
4323
+ formatRbga,
4324
+ formatRgba,
4325
+ formatVoiceDisplayName,
4326
+ getEmotionEyeSpritePaths,
4327
+ getEmotionIconPath,
4328
+ getFaceCapabilities,
4329
+ getLanguageName,
4330
+ globalFaceStore,
4331
+ hexToRgb,
4332
+ hexToRgba,
4333
+ includedVizijFaces,
4334
+ interpolateColor,
4335
+ isHeadlessOrTestEnvironment,
4336
+ isWebGLAvailable,
4337
+ mapVisemeToVizijTarget,
4338
+ mergeFaceSettings,
4339
+ normalizeAssetBaseUrl,
4340
+ pixiFaceRendererStrategy,
4341
+ pollyVisemeToVizijPath,
4342
+ possiblePollyVisemes,
4343
+ rbgToRgba,
4344
+ resolveFaceUiLabels,
4345
+ rgbToRgba,
4346
+ rgbaToHex,
4347
+ stopNativeSpeechSynthesis,
4348
+ useFaceStore,
4349
+ useFaceStoreInstance,
4350
+ useMessageVisualState,
4351
+ vizijFaceRendererStrategy
4352
+ });
4353
+ //# sourceMappingURL=index.cjs.map