@peerbots/face 0.0.0-stage → 0.2.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-DEMuLMAb.d.ts +63 -0
  3. package/dist/chunk-EAYBAWGE.js +1487 -0
  4. package/dist/chunk-EAYBAWGE.js.map +1 -0
  5. package/dist/chunk-QGFC2GUD.js +211 -0
  6. package/dist/chunk-QGFC2GUD.js.map +1 -0
  7. package/dist/chunk-ZEXL2QPJ.js +68 -0
  8. package/dist/chunk-ZEXL2QPJ.js.map +1 -0
  9. package/dist/index.cjs +4639 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.ts +557 -0
  12. package/dist/index.js +1660 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/pixi.cjs +2421 -0
  15. package/dist/pixi.cjs.map +1 -0
  16. package/dist/pixi.d.ts +33 -0
  17. package/dist/pixi.js +889 -0
  18. package/dist/pixi.js.map +1 -0
  19. package/dist/vizij.cjs +1556 -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 +116 -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/pixi.js ADDED
@@ -0,0 +1,889 @@
1
+ import {
2
+ EMOTION_EMOJIS,
3
+ EMOTION_EMOTICONS,
4
+ useMessageVisualState
5
+ } from "./chunk-QGFC2GUD.js";
6
+ import {
7
+ FaceStoreContext,
8
+ color_mapping,
9
+ interpolateColor,
10
+ rgbaToHex,
11
+ useFaceStore,
12
+ useFaceStoreInstance
13
+ } from "./chunk-EAYBAWGE.js";
14
+
15
+ // src/components/PixiFaceView.tsx
16
+ import { useState as useState5 } from "react";
17
+ import { Application, useExtend as useExtend8 } from "@pixi/react";
18
+ import { Container as Container5, Graphics as Graphics5, Sprite as Sprite3, Text as Text2 } from "pixi.js";
19
+
20
+ // src/components/FaceContainer.tsx
21
+ import { useState as useState2, useEffect as useEffect3 } from "react";
22
+ import { Container as Container2 } from "pixi.js";
23
+ import { useApplication as useApplication2, useExtend as useExtend5, useTick as useTick4 } from "@pixi/react";
24
+
25
+ // src/components/FaceEyes.tsx
26
+ import {
27
+ Sprite,
28
+ Texture,
29
+ Graphics,
30
+ Container,
31
+ Assets
32
+ } from "pixi.js";
33
+ import { useTick, useExtend } from "@pixi/react";
34
+ import { useEffect, useState, useRef, useMemo, useCallback } from "react";
35
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
36
+ var EYEBROW_POINTS = [
37
+ { x: -5, y: 2.5 },
38
+ { x: -4, y: 1.6 },
39
+ { x: -3, y: 0.9 },
40
+ { x: -2, y: 0.4 },
41
+ { x: -1, y: 0.1 },
42
+ { x: 0, y: 0 },
43
+ { x: 1, y: 0.1 },
44
+ { x: 2, y: 0.4 },
45
+ { x: 3, y: 0.9 },
46
+ { x: 4, y: 1.6 },
47
+ { x: 5, y: 2.5 }
48
+ ];
49
+ function FaceEyes({
50
+ scale,
51
+ frozen = false
52
+ }) {
53
+ const message = useFaceStore((state) => state.lastMessage);
54
+ const face = useFaceStore((state) => state.selectedFace);
55
+ const gaze = useFaceStore((state) => state.gaze);
56
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
57
+ useExtend({ Container, Sprite, Graphics });
58
+ const [faceSheet, setFaceSheet] = useState(null);
59
+ const [cheekTexture, setCheekTexture] = useState(null);
60
+ const [eyeBrows, setEyeBrows] = useState("Hugo");
61
+ const leftEyeTexture = useMemo(() => {
62
+ if (!faceSheet) return Texture.EMPTY;
63
+ const emotion = message?.emotion || "Neutral";
64
+ return faceSheet.textures?.[`${emotion.toLowerCase()}_l.png`] || faceSheet.textures?.["neutral_l.png"] || Texture.EMPTY;
65
+ }, [message, faceSheet]);
66
+ const rightEyeTexture = useMemo(() => {
67
+ if (!faceSheet) return Texture.EMPTY;
68
+ const emotion = message?.emotion || "Neutral";
69
+ return faceSheet.textures?.[`${emotion.toLowerCase()}_r.png`] || faceSheet.textures?.["neutral_r.png"] || Texture.EMPTY;
70
+ }, [message, faceSheet]);
71
+ const breathingScaleRef = useRef(1);
72
+ const breathingTimeRef = useRef(0);
73
+ const blinkScaleRef = useRef(1);
74
+ const isBlinkingRef = useRef(false);
75
+ const blinkEveryRef = useRef(500);
76
+ const blinkTimerRef = useRef(0);
77
+ const blinkTargetScaleRef = useRef(1);
78
+ const currentGazeRef = useRef({ x: 0, y: 0 });
79
+ const leftEyeContainerRef = useRef(null);
80
+ const rightEyeContainerRef = useRef(null);
81
+ const leftEyebrowRef = useRef(null);
82
+ const rightEyebrowRef = useRef(null);
83
+ const leftEyeSpriteRef = useRef(null);
84
+ const rightEyeSpriteRef = useRef(null);
85
+ const leftCheekRef = useRef(null);
86
+ const rightCheekRef = useRef(null);
87
+ const positions = useMemo(() => {
88
+ return {
89
+ leftEyeX: -300 * scale,
90
+ rightEyeX: 300 * scale,
91
+ leftEyeY: 0,
92
+ rightEyeY: 0,
93
+ leftEyeToRightEyeScaleRatio: 1.1,
94
+ cheekYOffset: 150 * scale,
95
+ eyebrowMultiplier: 7.5 * scale,
96
+ eyebrowOffset: -180 * scale
97
+ };
98
+ }, [scale]);
99
+ useTick((ticker) => {
100
+ const deltaTime = frozen ? 0 : ticker.deltaTime;
101
+ const frequency = 785e-5;
102
+ breathingTimeRef.current += deltaTime;
103
+ breathingScaleRef.current = 1 + 0.1 * Math.sin(breathingTimeRef.current * frequency);
104
+ const blinkDuration = 20;
105
+ const blinkSpeed = 0.5;
106
+ blinkTimerRef.current += deltaTime;
107
+ if (isBlinkingRef.current) {
108
+ if (blinkTimerRef.current > blinkDuration) {
109
+ blinkEveryRef.current = 200 + Math.random() * 400;
110
+ blinkTargetScaleRef.current = 1;
111
+ isBlinkingRef.current = false;
112
+ blinkTimerRef.current = 0;
113
+ }
114
+ } else if (blinkTimerRef.current > blinkEveryRef.current) {
115
+ blinkTargetScaleRef.current = 0.05;
116
+ isBlinkingRef.current = true;
117
+ blinkTimerRef.current = 0;
118
+ }
119
+ blinkScaleRef.current += (blinkTargetScaleRef.current - blinkScaleRef.current) * blinkSpeed * deltaTime;
120
+ currentGazeRef.current.x += (gaze.x - currentGazeRef.current.x) * 0.15;
121
+ currentGazeRef.current.y += (gaze.y - currentGazeRef.current.y) * 0.15;
122
+ const gazeOffsetX = currentGazeRef.current.x * 40 * scale;
123
+ const gazeOffsetY = currentGazeRef.current.y * 30 * scale;
124
+ if (leftEyeContainerRef.current) {
125
+ leftEyeContainerRef.current.x = positions.leftEyeX + gazeOffsetX;
126
+ leftEyeContainerRef.current.y = positions.leftEyeY + gazeOffsetY;
127
+ }
128
+ if (rightEyeContainerRef.current) {
129
+ rightEyeContainerRef.current.x = positions.rightEyeX + gazeOffsetX;
130
+ rightEyeContainerRef.current.y = positions.rightEyeY + gazeOffsetY;
131
+ }
132
+ const breathe = breathingScaleRef.current;
133
+ const blink = blinkScaleRef.current;
134
+ if (leftEyeSpriteRef.current) {
135
+ leftEyeSpriteRef.current.scale.x = positions.leftEyeToRightEyeScaleRatio * breathe * scale;
136
+ leftEyeSpriteRef.current.scale.y = positions.leftEyeToRightEyeScaleRatio * breathe * blink * scale;
137
+ }
138
+ if (rightEyeSpriteRef.current) {
139
+ rightEyeSpriteRef.current.scale.x = 1 * breathe * scale;
140
+ rightEyeSpriteRef.current.scale.y = 1 * breathe * blink * scale;
141
+ }
142
+ if (leftCheekRef.current) {
143
+ leftCheekRef.current.scale.x = 0.08 * breathe * scale;
144
+ leftCheekRef.current.scale.y = 0.04 * breathe * scale;
145
+ }
146
+ if (rightCheekRef.current) {
147
+ rightCheekRef.current.scale.x = 0.08 * breathe * scale;
148
+ rightCheekRef.current.scale.y = 0.04 * breathe * scale;
149
+ }
150
+ const strokeWidth = Math.max(1.5, 3 * scale);
151
+ if (leftEyebrowRef.current) {
152
+ const g = leftEyebrowRef.current;
153
+ g.clear();
154
+ const mult = positions.eyebrowMultiplier * breathe;
155
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
156
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
157
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
158
+ }
159
+ g.stroke({
160
+ width: strokeWidth,
161
+ color: "black",
162
+ cap: "round",
163
+ join: "round"
164
+ });
165
+ }
166
+ if (rightEyebrowRef.current) {
167
+ const g = rightEyebrowRef.current;
168
+ g.clear();
169
+ const mult = positions.eyebrowMultiplier * breathe;
170
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
171
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
172
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
173
+ }
174
+ g.stroke({
175
+ width: strokeWidth,
176
+ color: "black",
177
+ cap: "round",
178
+ join: "round"
179
+ });
180
+ }
181
+ });
182
+ const drawEyebrow = useCallback(
183
+ (g) => {
184
+ g.clear();
185
+ const mult = positions.eyebrowMultiplier * breathingScaleRef.current;
186
+ const strokeWidth = Math.max(1.5, 3 * scale);
187
+ g.moveTo(EYEBROW_POINTS[0].x * mult, EYEBROW_POINTS[0].y * mult);
188
+ for (let i = 1; i < EYEBROW_POINTS.length; i++) {
189
+ g.lineTo(EYEBROW_POINTS[i].x * mult, EYEBROW_POINTS[i].y * mult);
190
+ }
191
+ g.stroke({
192
+ width: strokeWidth,
193
+ color: "black",
194
+ cap: "round",
195
+ join: "round"
196
+ });
197
+ },
198
+ [positions.eyebrowMultiplier, scale]
199
+ );
200
+ useEffect(() => {
201
+ let cancelled = false;
202
+ async function loadAvatarTextures(currentFace) {
203
+ if (currentFace?.kind !== "PixiFace" || currentFace.type !== "avatar") {
204
+ return;
205
+ }
206
+ try {
207
+ if (currentFace.eyes?.kind === "spritesheet") {
208
+ const sheet = await Assets.load(currentFace.eyes.path);
209
+ if (!cancelled) {
210
+ setFaceSheet(sheet);
211
+ }
212
+ }
213
+ if (currentFace.cheeks?.kind === "texture") {
214
+ const cheek = await Assets.load(currentFace.cheeks.path);
215
+ if (!cancelled) {
216
+ setCheekTexture(cheek);
217
+ }
218
+ } else if (!cancelled) {
219
+ setCheekTexture(null);
220
+ }
221
+ if (!cancelled) {
222
+ setEyeBrows(currentFace.eyebrows);
223
+ }
224
+ } catch (err) {
225
+ console.warn("Failed to load PixiFace textures:", err);
226
+ }
227
+ }
228
+ void loadAvatarTextures(face);
229
+ return () => {
230
+ cancelled = true;
231
+ };
232
+ }, [face]);
233
+ if (pixiSettings?.eyeDisplay === "none") {
234
+ return null;
235
+ }
236
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
237
+ /* @__PURE__ */ jsxs(
238
+ "pixiContainer",
239
+ {
240
+ ref: leftEyeContainerRef,
241
+ position: { x: positions.leftEyeX, y: positions.leftEyeY },
242
+ label: "LeftEyeContainer",
243
+ children: [
244
+ eyeBrows === "Hugo" && /* @__PURE__ */ jsx(
245
+ "pixiGraphics",
246
+ {
247
+ ref: leftEyebrowRef,
248
+ label: "LeftEyebrow",
249
+ position: { x: 0, y: positions.eyebrowOffset },
250
+ draw: drawEyebrow
251
+ }
252
+ ),
253
+ /* @__PURE__ */ jsx(
254
+ "pixiSprite",
255
+ {
256
+ ref: leftEyeSpriteRef,
257
+ label: "LeftEye",
258
+ anchor: { x: 0.5, y: 0.5 },
259
+ position: { x: 0, y: 0 },
260
+ texture: leftEyeTexture,
261
+ pivot: { x: 0.5, y: 0.5 }
262
+ }
263
+ ),
264
+ cheekTexture && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ jsx(
265
+ "pixiSprite",
266
+ {
267
+ ref: leftCheekRef,
268
+ label: "LeftCheek",
269
+ texture: cheekTexture,
270
+ pivot: { x: 0.5, y: 0.5 },
271
+ anchor: { x: 0.5, y: 0.5 },
272
+ position: { x: 0, y: positions.cheekYOffset }
273
+ }
274
+ )
275
+ ]
276
+ }
277
+ ),
278
+ /* @__PURE__ */ jsxs(
279
+ "pixiContainer",
280
+ {
281
+ ref: rightEyeContainerRef,
282
+ position: { x: positions.rightEyeX, y: positions.rightEyeY },
283
+ label: "RightEyeContainer",
284
+ children: [
285
+ eyeBrows === "Hugo" && /* @__PURE__ */ jsx(
286
+ "pixiGraphics",
287
+ {
288
+ ref: rightEyebrowRef,
289
+ label: "RightEyebrow",
290
+ position: { x: 0, y: positions.eyebrowOffset },
291
+ draw: drawEyebrow
292
+ }
293
+ ),
294
+ /* @__PURE__ */ jsx(
295
+ "pixiSprite",
296
+ {
297
+ ref: rightEyeSpriteRef,
298
+ label: "RightEye",
299
+ position: { x: 0, y: 0 },
300
+ pivot: { x: 0.5, y: 0.5 },
301
+ anchor: { x: 0.5, y: 0.5 },
302
+ texture: rightEyeTexture
303
+ }
304
+ ),
305
+ cheekTexture && pixiSettings?.cheekDisplay !== "none" && /* @__PURE__ */ jsx(
306
+ "pixiSprite",
307
+ {
308
+ ref: rightCheekRef,
309
+ label: "RightCheek",
310
+ texture: cheekTexture,
311
+ pivot: { x: 0.5, y: 0.5 },
312
+ anchor: { x: 0.5, y: 0.5 },
313
+ position: { x: 0, y: positions.cheekYOffset }
314
+ }
315
+ )
316
+ ]
317
+ }
318
+ )
319
+ ] });
320
+ }
321
+
322
+ // src/components/FaceMouth.tsx
323
+ import { useRef as useRef2, useMemo as useMemo2, useCallback as useCallback2 } from "react";
324
+ import { Graphics as Graphics2 } from "pixi.js";
325
+ import { useTick as useTick2, useExtend as useExtend2 } from "@pixi/react";
326
+ import { jsx as jsx2 } from "react/jsx-runtime";
327
+ var ZIG_ZAG_POINTS = [
328
+ { x: 0, y: -10 },
329
+ { x: 10, y: 10 },
330
+ { x: 20, y: -10 },
331
+ { x: 30, y: 10 },
332
+ { x: 40, y: -10 },
333
+ { x: 50, y: 10 },
334
+ { x: 60, y: -10 },
335
+ { x: 70, y: 10 },
336
+ { x: 80, y: -10 },
337
+ { x: 90, y: 10 },
338
+ { x: 100, y: -10 },
339
+ { x: 110, y: 10 }
340
+ ];
341
+ var SMILEY_POINTS = [
342
+ { x: -40, y: 40 },
343
+ { x: -30, y: 30 },
344
+ { x: -20, y: 20 },
345
+ { x: -10, y: 10 },
346
+ { x: 0, y: 0 },
347
+ { x: 10, y: 10 },
348
+ { x: 20, y: 20 },
349
+ { x: 30, y: 30 },
350
+ { x: 40, y: 40 }
351
+ ];
352
+ function FaceMouth({
353
+ scale,
354
+ frozen = false
355
+ }) {
356
+ useExtend2({ Graphics: Graphics2 });
357
+ const talking = useFaceStore((state) => state.isSpeaking);
358
+ const face = useFaceStore((state) => state.selectedFace);
359
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
360
+ const currentAmplitude = useFaceStore((state) => state.currentAmplitude);
361
+ const amplitudeData = useFaceStore((state) => state.amplitudeData);
362
+ const speechStartTime = useFaceStore((state) => state.speechStartTime);
363
+ const talkingScaleRef = useRef2(1);
364
+ const talkingTimeRef = useRef2(0);
365
+ const talkingShape = useMemo2(
366
+ () => face?.kind === "PixiFace" && face.type === "avatar" ? face.mouth : "Ellipse",
367
+ [face]
368
+ );
369
+ const graphicsRef = useRef2(null);
370
+ const getAmplitudeAtTime = useCallback2(
371
+ (timeMs) => {
372
+ if (!amplitudeData || amplitudeData.length === 0) return 0;
373
+ const point = amplitudeData.find((p, i) => {
374
+ const nextPoint = amplitudeData[i + 1];
375
+ return p.time <= timeMs && (!nextPoint || nextPoint.time > timeMs);
376
+ });
377
+ return point ? point.value : 0;
378
+ },
379
+ [amplitudeData]
380
+ );
381
+ const drawMouth = useCallback2(
382
+ (graphics) => {
383
+ graphics.clear();
384
+ const talkingScale = talkingScaleRef.current;
385
+ const talkingTime = talkingTimeRef.current;
386
+ switch (talkingShape) {
387
+ case "Hugo": {
388
+ const width = 40 * scale;
389
+ const smileDepth = 20 * scale;
390
+ const openHeight = talking ? talkingScale * 30 * scale : 0;
391
+ const topLipLift = talking ? talkingScale * 10 * scale : 0;
392
+ const centerY = scale * 240;
393
+ graphics.moveTo(-width, centerY);
394
+ graphics.quadraticCurveTo(
395
+ 0,
396
+ centerY + smileDepth * 0.5 - topLipLift,
397
+ width,
398
+ centerY
399
+ );
400
+ graphics.quadraticCurveTo(
401
+ 0,
402
+ centerY + smileDepth + openHeight * 1.5,
403
+ -width,
404
+ centerY
405
+ );
406
+ graphics.fill({ color: "black" });
407
+ break;
408
+ }
409
+ case "Beak": {
410
+ SMILEY_POINTS.forEach((eachPoint, index) => {
411
+ const y = talkingScale * (Math.pow(40, 1.1) - Math.pow(Math.abs(eachPoint.x), 1.1)) + scale * 240;
412
+ if (index === 0) {
413
+ graphics.moveTo(eachPoint.x, y);
414
+ }
415
+ graphics.lineTo(eachPoint.x, y);
416
+ });
417
+ graphics.moveTo(SMILEY_POINTS[0].x, -1 * SMILEY_POINTS[0].y);
418
+ SMILEY_POINTS.forEach((eachPoint, index) => {
419
+ const y = -1 * talkingScale * (Math.pow(40, 1.1) - Math.pow(Math.abs(eachPoint.x), 1.1)) + scale * 240;
420
+ if (index === 0) {
421
+ graphics.moveTo(eachPoint.x, y);
422
+ }
423
+ graphics.lineTo(eachPoint.x, y);
424
+ });
425
+ break;
426
+ }
427
+ case "ZigZag": {
428
+ ZIG_ZAG_POINTS.forEach((eachPoint, index) => {
429
+ const x = eachPoint.x - ZIG_ZAG_POINTS[ZIG_ZAG_POINTS.length - 1].x / 2;
430
+ const y = talking ? Math.sin(talkingTime * 0.3 + index * 5) * (10 * talkingScale) + scale * 240 : eachPoint.y + scale * 240;
431
+ if (index === 0) {
432
+ graphics.moveTo(x, y);
433
+ }
434
+ graphics.lineTo(x, y);
435
+ });
436
+ break;
437
+ }
438
+ case "Ellipse":
439
+ default: {
440
+ graphics.ellipse(
441
+ 0,
442
+ scale * 240,
443
+ scale * 60,
444
+ talking ? 2 + talkingScale * scale * 15 : 4
445
+ );
446
+ graphics.fill({ color: "black" });
447
+ break;
448
+ }
449
+ }
450
+ graphics.stroke({ color: "black", width: 2 });
451
+ },
452
+ [scale, talking, talkingShape]
453
+ );
454
+ useTick2((time) => {
455
+ if (frozen) return;
456
+ let targetScale;
457
+ if (talking) {
458
+ if (currentAmplitude > 0) {
459
+ targetScale = Math.min(currentAmplitude * 1.5, 1);
460
+ } else if (amplitudeData && speechStartTime) {
461
+ const elapsed = performance.now() - speechStartTime;
462
+ targetScale = Math.min(getAmplitudeAtTime(elapsed) * 1.5, 1);
463
+ } else {
464
+ targetScale = Math.abs(Math.sin(time.lastTime * 0.1));
465
+ }
466
+ talkingTimeRef.current = time.lastTime;
467
+ } else {
468
+ targetScale = 0;
469
+ }
470
+ const lerpAlpha = 0.2;
471
+ talkingScaleRef.current += (targetScale - talkingScaleRef.current) * lerpAlpha;
472
+ if (graphicsRef.current) {
473
+ drawMouth(graphicsRef.current);
474
+ }
475
+ });
476
+ if (pixiSettings?.mouthDisplay === "none") return null;
477
+ return /* @__PURE__ */ jsx2("pixiGraphics", { ref: graphicsRef, label: "Mouth", draw: drawMouth });
478
+ }
479
+
480
+ // src/components/FaceText.tsx
481
+ import { useEffect as useEffect2, useMemo as useMemo3 } from "react";
482
+ import { Text, TextStyle } from "pixi.js";
483
+ import { useExtend as useExtend3, useTick as useTick3 } from "@pixi/react";
484
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
485
+ var FONT_FAMILY = "Courier New, Courier, monospace";
486
+ var TEXT_PERSISTENCE_DURATION = 3e3;
487
+ var MS_PER_CHAR = 50;
488
+ var PAUSE_BEFORE_NEXT_MSG = 500;
489
+ function FaceText({ scale }) {
490
+ useExtend3({ Text });
491
+ const lastMessage = useFaceStore((state) => state.lastMessage);
492
+ const isSpeaking = useFaceStore((state) => state.isSpeaking);
493
+ const selectedFace = useFaceStore((state) => state.selectedFace);
494
+ const pixiSettings = useFaceStore((state) => state.faceSettings.pixiSettings);
495
+ const emotionType = useMemo3(() => {
496
+ if (pixiSettings?.emotionDisplay) {
497
+ return pixiSettings.emotionDisplay;
498
+ }
499
+ if (selectedFace?.kind === "PixiFace" && selectedFace.type === "text") {
500
+ return selectedFace.showEmotion;
501
+ }
502
+ return "emoticon";
503
+ }, [pixiSettings?.emotionDisplay, selectedFace]);
504
+ const { displayText, queueMessage, update } = useMessageVisualState(
505
+ isSpeaking,
506
+ {
507
+ msPerChar: MS_PER_CHAR,
508
+ persistenceDuration: TEXT_PERSISTENCE_DURATION,
509
+ pauseBeforeNextMsg: PAUSE_BEFORE_NEXT_MSG
510
+ }
511
+ );
512
+ useEffect2(() => {
513
+ queueMessage(lastMessage.speech);
514
+ }, [lastMessage.speech, queueMessage]);
515
+ useTick3((delta) => {
516
+ update(delta.deltaMS);
517
+ });
518
+ const emotionStyle = useMemo3(
519
+ () => new TextStyle({
520
+ fontFamily: FONT_FAMILY,
521
+ fontSize: Math.max(12, 48 * scale),
522
+ fill: "black",
523
+ align: "center"
524
+ }),
525
+ [scale]
526
+ );
527
+ const bodyStyle = useMemo3(
528
+ () => new TextStyle({
529
+ fontFamily: FONT_FAMILY,
530
+ fontSize: Math.max(12, 48 * scale),
531
+ fill: "black",
532
+ align: "center",
533
+ wordWrap: true,
534
+ wordWrapWidth: Math.max(200, 800 * scale)
535
+ }),
536
+ [scale]
537
+ );
538
+ const emotionSymbol = emotionType === "emoji" ? EMOTION_EMOJIS[lastMessage.emotion] : EMOTION_EMOTICONS[lastMessage.emotion];
539
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
540
+ emotionType !== "none" && /* @__PURE__ */ jsx3(
541
+ "pixiText",
542
+ {
543
+ anchor: 0.5,
544
+ x: 0,
545
+ y: -50 * scale,
546
+ text: emotionSymbol,
547
+ style: emotionStyle
548
+ }
549
+ ),
550
+ /* @__PURE__ */ jsx3(
551
+ "pixiText",
552
+ {
553
+ text: displayText,
554
+ anchor: 0.5,
555
+ x: 0,
556
+ y: 0,
557
+ style: bodyStyle
558
+ }
559
+ )
560
+ ] });
561
+ }
562
+
563
+ // src/components/FaceBackground.tsx
564
+ import { useMemo as useMemo4 } from "react";
565
+ import { Sprite as Sprite2, Texture as Texture2 } from "pixi.js";
566
+ import { useApplication, useExtend as useExtend4 } from "@pixi/react";
567
+ import { jsx as jsx4 } from "react/jsx-runtime";
568
+ function createRadialGradientTexture(size) {
569
+ if (typeof document === "undefined") {
570
+ return Texture2.EMPTY;
571
+ }
572
+ const canvas = document.createElement("canvas");
573
+ canvas.width = size;
574
+ canvas.height = size;
575
+ const ctx = canvas.getContext("2d");
576
+ if (!ctx) return Texture2.EMPTY;
577
+ const gradient = ctx.createRadialGradient(
578
+ size / 2,
579
+ size / 2,
580
+ 0,
581
+ size / 2,
582
+ size / 2,
583
+ size / 2
584
+ );
585
+ gradient.addColorStop(0, "rgba(255, 255, 255, 0.7)");
586
+ gradient.addColorStop(0.4, "rgba(255, 255, 255, 0.2)");
587
+ gradient.addColorStop(1, "rgba(255, 255, 255, 0)");
588
+ ctx.fillStyle = gradient;
589
+ ctx.fillRect(0, 0, size, size);
590
+ return Texture2.from(canvas);
591
+ }
592
+ function FaceBackground() {
593
+ useExtend4({ Sprite: Sprite2 });
594
+ const { app, isInitialised } = useApplication();
595
+ const texture = useMemo4(() => createRadialGradientTexture(1024), []);
596
+ if (!app || !isInitialised || !app.renderer) return null;
597
+ const screenWidth = app.renderer.screen && app.renderer.screen.width || app.renderer.width || 2e3;
598
+ const screenHeight = app.renderer.screen && app.renderer.screen.height || app.renderer.height || 2e3;
599
+ const size = Math.max(screenWidth, screenHeight) * 2;
600
+ return /* @__PURE__ */ jsx4(
601
+ "pixiSprite",
602
+ {
603
+ texture,
604
+ anchor: 0.5,
605
+ width: size,
606
+ height: size,
607
+ x: 0,
608
+ y: 0,
609
+ blendMode: "screen",
610
+ alpha: 0.5
611
+ }
612
+ );
613
+ }
614
+
615
+ // src/components/FaceContainer.tsx
616
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
617
+ function stepRendererBackgroundColor(renderer, targetHex) {
618
+ try {
619
+ const currentHex = renderer.background.color.toHex();
620
+ if (currentHex.toLowerCase() === targetHex.toLowerCase()) {
621
+ return;
622
+ }
623
+ const interpolated = interpolateColor(currentHex, targetHex, 0.1);
624
+ if (interpolated !== null) {
625
+ renderer.background.color = rgbaToHex(interpolated);
626
+ }
627
+ } catch (err) {
628
+ void err;
629
+ }
630
+ }
631
+ function FaceContainer({ frozen = false }) {
632
+ useExtend5({ Container: Container2 });
633
+ const settings = useFaceStore((state) => state.faceSettings);
634
+ const selectedFace = useFaceStore((state) => state.selectedFace);
635
+ const lastMessage = useFaceStore((state) => state.lastMessage);
636
+ const { app, isInitialised } = useApplication2();
637
+ const [layout, setLayout] = useState2({
638
+ landscape: true,
639
+ scale: 1,
640
+ x: 400,
641
+ y: 300
642
+ });
643
+ const isAvatar = selectedFace?.kind === "PixiFace" && selectedFace.type === "avatar";
644
+ useEffect3(() => {
645
+ if (!app || !isInitialised || !app.renderer) return;
646
+ const updateLayout = () => {
647
+ if (!app?.renderer) return;
648
+ const width = app.renderer.screen && app.renderer.screen.width || app.renderer.width || 800;
649
+ const height = app.renderer.screen && app.renderer.screen.height || app.renderer.height || 600;
650
+ const isLandscape = width > height;
651
+ const baseScale = isLandscape ? width / 1200 : height / 1200;
652
+ const effectiveLandscape = settings.autoRotate ? isLandscape : true;
653
+ setLayout({
654
+ landscape: effectiveLandscape,
655
+ scale: baseScale,
656
+ x: width / 2,
657
+ y: height / 2
658
+ });
659
+ };
660
+ updateLayout();
661
+ const onResize = () => {
662
+ if (app?.renderer) {
663
+ updateLayout();
664
+ }
665
+ };
666
+ window.addEventListener("resize", onResize);
667
+ window.addEventListener("orientationchange", onResize);
668
+ app.renderer.on("resize", onResize);
669
+ return () => {
670
+ window.removeEventListener("resize", onResize);
671
+ window.removeEventListener("orientationchange", onResize);
672
+ if (app?.renderer) {
673
+ app.renderer.off("resize", onResize);
674
+ }
675
+ };
676
+ }, [app, isInitialised, settings.autoRotate]);
677
+ useTick4(() => {
678
+ if (app?.renderer && lastMessage) {
679
+ const targetColor = color_mapping[lastMessage.color] ?? color_mapping["Light Blue"];
680
+ stepRendererBackgroundColor(app.renderer, targetColor);
681
+ }
682
+ });
683
+ return /* @__PURE__ */ jsxs3(
684
+ "pixiContainer",
685
+ {
686
+ label: "FaceContainer",
687
+ position: {
688
+ x: layout.x + (settings.offset?.x ?? 0),
689
+ y: layout.y + (settings.offset?.y ?? 0)
690
+ },
691
+ pivot: { x: 0.5, y: 0.5 },
692
+ angle: layout.landscape ? settings.rotation : 90 + settings.rotation,
693
+ children: [
694
+ isAvatar && /* @__PURE__ */ jsx5(FaceBackground, {}),
695
+ selectedFace?.kind === "PixiFace" && selectedFace.type === "text" ? /* @__PURE__ */ jsx5(FaceText, { scale: layout.scale * settings.zoom }) : /* @__PURE__ */ jsxs3(Fragment3, { children: [
696
+ /* @__PURE__ */ jsx5(FaceEyes, { scale: layout.scale * settings.zoom, frozen }),
697
+ /* @__PURE__ */ jsx5(FaceMouth, { scale: layout.scale * settings.zoom, frozen })
698
+ ] })
699
+ ]
700
+ }
701
+ );
702
+ }
703
+
704
+ // src/components/FaceFullScreenButton.tsx
705
+ import { useCallback as useCallback3, useEffect as useEffect4, useState as useState3 } from "react";
706
+ import { useApplication as useApplication3, useExtend as useExtend6 } from "@pixi/react";
707
+ import { Container as Container3, Graphics as Graphics3, Rectangle } from "pixi.js";
708
+ import { iconPaths } from "@peerbots/core";
709
+ import { jsx as jsx6 } from "react/jsx-runtime";
710
+ function FaceFullScreenButton() {
711
+ useExtend6({ Graphics: Graphics3, Container: Container3 });
712
+ const { app } = useApplication3();
713
+ const [fullScreen, setFullScreen] = useState3(false);
714
+ useEffect4(() => {
715
+ if (typeof document === "undefined") {
716
+ return;
717
+ }
718
+ const handleFullscreenChange = () => {
719
+ setFullScreen(Boolean(document.fullscreenElement));
720
+ };
721
+ document.addEventListener("fullscreenchange", handleFullscreenChange);
722
+ return () => {
723
+ document.removeEventListener("fullscreenchange", handleFullscreenChange);
724
+ };
725
+ }, []);
726
+ const toggleFullScreen = useCallback3(() => {
727
+ if (typeof document === "undefined") {
728
+ return;
729
+ }
730
+ if (fullScreen) {
731
+ void document.exitFullscreen().catch((err) => {
732
+ console.warn("Exit fullscreen error:", err);
733
+ });
734
+ } else {
735
+ const container = document.getElementById("face-view-container");
736
+ if (container) {
737
+ container.requestFullscreen().catch((err) => {
738
+ console.warn("Container fullscreen error:", err);
739
+ if (app?.canvas) {
740
+ void app.canvas.requestFullscreen().catch((canvasErr) => {
741
+ console.warn("Canvas fullscreen error:", canvasErr);
742
+ });
743
+ }
744
+ });
745
+ } else if (app?.canvas) {
746
+ void app.canvas.requestFullscreen().catch((err) => {
747
+ console.warn("Canvas fullscreen error:", err);
748
+ });
749
+ }
750
+ }
751
+ }, [app, fullScreen]);
752
+ const drawIcon = useCallback3(
753
+ (graphics) => {
754
+ graphics.clear();
755
+ const pathD = fullScreen ? iconPaths.arrowsPointingIn : iconPaths.arrowsPointingOut;
756
+ graphics.svg(`
757
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
758
+ <path strokeLinecap="round" strokeLinejoin="round" d="${pathD}" />
759
+ </svg>
760
+ `);
761
+ },
762
+ [fullScreen]
763
+ );
764
+ return /* @__PURE__ */ jsx6(
765
+ "pixiContainer",
766
+ {
767
+ label: "FullScreenToggle",
768
+ x: 20,
769
+ y: 20,
770
+ eventMode: "static",
771
+ onPointerDown: toggleFullScreen,
772
+ hitArea: new Rectangle(0, 0, 50, 50),
773
+ children: /* @__PURE__ */ jsx6(
774
+ "pixiGraphics",
775
+ {
776
+ onPointerDown: toggleFullScreen,
777
+ eventMode: "static",
778
+ draw: drawIcon
779
+ }
780
+ )
781
+ }
782
+ );
783
+ }
784
+
785
+ // src/components/FaceScrollToTopButton.tsx
786
+ import { useCallback as useCallback4, useLayoutEffect, useState as useState4 } from "react";
787
+ import { useExtend as useExtend7 } from "@pixi/react";
788
+ import { Container as Container4, Graphics as Graphics4, Rectangle as Rectangle2 } from "pixi.js";
789
+ import { iconPaths as iconPaths2 } from "@peerbots/core";
790
+ import { jsx as jsx7 } from "react/jsx-runtime";
791
+ function FaceScrollToTopButton() {
792
+ useExtend7({ Graphics: Graphics4, Container: Container4 });
793
+ const [xPos, setXPos] = useState4(
794
+ () => typeof window !== "undefined" ? window.innerWidth - 50 : 750
795
+ );
796
+ const scrollToTop = useCallback4(() => {
797
+ if (typeof window !== "undefined") {
798
+ window.scrollTo(0, 0);
799
+ }
800
+ }, []);
801
+ useLayoutEffect(() => {
802
+ if (typeof window === "undefined") {
803
+ return;
804
+ }
805
+ const calculatePositionBasedOnWindow = () => {
806
+ setXPos(window.innerWidth - 50);
807
+ };
808
+ const orientation = typeof screen !== "undefined" ? screen.orientation : void 0;
809
+ orientation?.addEventListener("change", calculatePositionBasedOnWindow);
810
+ window.addEventListener("resize", calculatePositionBasedOnWindow);
811
+ return () => {
812
+ orientation?.removeEventListener("change", calculatePositionBasedOnWindow);
813
+ window.removeEventListener("resize", calculatePositionBasedOnWindow);
814
+ };
815
+ }, []);
816
+ const drawChevron = useCallback4((graphics) => {
817
+ graphics.clear();
818
+ graphics.svg(`
819
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
820
+ <path strokeLinecap="round" strokeLinejoin="round" d="${iconPaths2.chevronUpSmall}" />
821
+ </svg>
822
+ `);
823
+ }, []);
824
+ return /* @__PURE__ */ jsx7(
825
+ "pixiContainer",
826
+ {
827
+ label: "ScrollToTopButton",
828
+ x: xPos,
829
+ y: 20,
830
+ eventMode: "static",
831
+ onPointerDown: scrollToTop,
832
+ hitArea: new Rectangle2(0, 0, 50, 50),
833
+ children: /* @__PURE__ */ jsx7(
834
+ "pixiGraphics",
835
+ {
836
+ onPointerDown: scrollToTop,
837
+ eventMode: "static",
838
+ draw: drawChevron
839
+ }
840
+ )
841
+ }
842
+ );
843
+ }
844
+
845
+ // src/components/PixiFaceView.tsx
846
+ import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
847
+ function PixiFaceView({
848
+ isPreview = false,
849
+ frozen = false
850
+ } = {}) {
851
+ useExtend8({ Container: Container5, Graphics: Graphics5, Sprite: Sprite3, Text: Text2 });
852
+ const settings = useFaceStore((state) => state.faceSettings);
853
+ const currentStore = useFaceStoreInstance();
854
+ const [containerEl, setContainerEl] = useState5(null);
855
+ return /* @__PURE__ */ jsx8(
856
+ "div",
857
+ {
858
+ ref: setContainerEl,
859
+ className: "pbf:w-full pbf:h-full pbf:relative pbf:overflow-hidden",
860
+ "data-testid": "pixi-face-view",
861
+ children: containerEl ? /* @__PURE__ */ jsx8(
862
+ Application,
863
+ {
864
+ resizeTo: containerEl,
865
+ backgroundColor: "#ABE3FA",
866
+ className: "pbf:w-full pbf:h-full pbf:block",
867
+ children: /* @__PURE__ */ jsxs4(FaceStoreContext.Provider, { value: currentStore, children: [
868
+ !isPreview && settings.showFullScreenButton && /* @__PURE__ */ jsx8(FaceFullScreenButton, {}),
869
+ !isPreview && settings.showScrollButton && /* @__PURE__ */ jsx8(FaceScrollToTopButton, {}),
870
+ /* @__PURE__ */ jsx8(FaceContainer, { frozen })
871
+ ] })
872
+ }
873
+ ) : null
874
+ }
875
+ );
876
+ }
877
+ var PixiFaceView_default = PixiFaceView;
878
+ export {
879
+ FaceBackground,
880
+ FaceContainer,
881
+ FaceEyes,
882
+ FaceFullScreenButton,
883
+ FaceMouth,
884
+ FaceScrollToTopButton,
885
+ FaceText,
886
+ PixiFaceView,
887
+ PixiFaceView_default as default
888
+ };
889
+ //# sourceMappingURL=pixi.js.map