@peerbots/face 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pixi.cjs CHANGED
@@ -31,8 +31,8 @@ __export(PixiFaceView_exports, {
31
31
  default: () => PixiFaceView_default
32
32
  });
33
33
  module.exports = __toCommonJS(PixiFaceView_exports);
34
- var import_react17 = require("react");
35
- var import_react18 = require("@pixi/react");
34
+ var import_react18 = require("react");
35
+ var import_react19 = require("@pixi/react");
36
36
  var import_pixi8 = require("pixi.js");
37
37
 
38
38
  // src/store/FaceStoreContext.tsx
@@ -72,7 +72,8 @@ var defaultFaceSettings = {
72
72
  captions: {
73
73
  enabled: false,
74
74
  fontSize: 32,
75
- offset: { x: 0, y: 0 }
75
+ offset: { x: 0, y: 0 },
76
+ style: "pill"
76
77
  }
77
78
  };
78
79
  function normalizeAssetBaseUrl(assetBaseUrl = "/FaceAssets") {
@@ -467,26 +468,214 @@ function estimateVisemesFromText(text, msPerChar = 65) {
467
468
  return visemes;
468
469
  }
469
470
 
471
+ // src/services/AudioManager.ts
472
+ var SILENT_WAV_DATA_URI = "data:audio/wav;base64,UklGRigAAABXQVZFZm10IBIAAAABAAEARKwAAIhYAQACABAAAABkYXRhAgAAAAEA";
473
+ function isIOSDevice(nav) {
474
+ const target = nav ?? (typeof navigator !== "undefined" ? navigator : void 0);
475
+ if (!target) {
476
+ return false;
477
+ }
478
+ const ua = target.userAgent ?? "";
479
+ if (/iPad|iPhone|iPod/.test(ua)) {
480
+ return true;
481
+ }
482
+ return target.platform === "MacIntel" && typeof target.maxTouchPoints === "number" && target.maxTouchPoints > 1;
483
+ }
484
+ var AudioManager = class {
485
+ audioElement = null;
486
+ registeredContexts = /* @__PURE__ */ new Set();
487
+ unlocked = false;
488
+ isUnlocked() {
489
+ return this.unlocked;
490
+ }
491
+ /**
492
+ * Registers an AudioContext so `unlock()` automatically resumes it during a
493
+ * user gesture.
494
+ */
495
+ registerAudioContext(ctx) {
496
+ this.registeredContexts.add(ctx);
497
+ }
498
+ /**
499
+ * Returns the single persistent HTMLAudioElement configured for inline
500
+ * cross-origin playback on iOS / Mobile Safari.
501
+ */
502
+ getAudioElement() {
503
+ if (this.audioElement) {
504
+ return this.audioElement;
505
+ }
506
+ if (typeof Audio === "undefined") {
507
+ return null;
508
+ }
509
+ const audio = new Audio();
510
+ audio.crossOrigin = "anonymous";
511
+ audio.preload = "auto";
512
+ audio.playsInline = true;
513
+ if (typeof audio.setAttribute === "function") {
514
+ audio.setAttribute("playsinline", "true");
515
+ }
516
+ this.audioElement = audio;
517
+ return this.audioElement;
518
+ }
519
+ /**
520
+ * Unlocks audio playback on iOS / Mobile Safari. MUST be called synchronously
521
+ * inside a user-gesture event handler (e.g. click or touchstart).
522
+ */
523
+ async unlock(options = {}) {
524
+ let anySucceeded = false;
525
+ const audio = this.getAudioElement();
526
+ let audioPlayPromise = null;
527
+ if (audio) {
528
+ try {
529
+ if (audio.paused || !audio.src) {
530
+ audio.src = SILENT_WAV_DATA_URI;
531
+ }
532
+ const playResult = audio.play();
533
+ if (playResult && typeof playResult.then === "function") {
534
+ audioPlayPromise = playResult.then(
535
+ () => {
536
+ if (audio.src === SILENT_WAV_DATA_URI) {
537
+ try {
538
+ audio.pause();
539
+ audio.currentTime = 0;
540
+ } catch (pauseErr) {
541
+ void pauseErr;
542
+ }
543
+ }
544
+ anySucceeded = true;
545
+ },
546
+ (err) => {
547
+ console.warn("AudioManager silent WAV unlock warning:", err);
548
+ }
549
+ );
550
+ } else {
551
+ if (audio.src === SILENT_WAV_DATA_URI) {
552
+ try {
553
+ audio.pause();
554
+ audio.currentTime = 0;
555
+ } catch (pauseErr) {
556
+ void pauseErr;
557
+ }
558
+ }
559
+ anySucceeded = true;
560
+ }
561
+ } catch (err) {
562
+ console.warn("AudioManager audio element unlock warning:", err);
563
+ }
564
+ }
565
+ const contextsToResume = new Set(this.registeredContexts);
566
+ if (options.audioContext) {
567
+ contextsToResume.add(options.audioContext);
568
+ }
569
+ const resumePromises = [];
570
+ for (const ctx of contextsToResume) {
571
+ if (ctx.state === "suspended" && typeof ctx.resume === "function") {
572
+ resumePromises.push(
573
+ ctx.resume().then(
574
+ () => {
575
+ anySucceeded = true;
576
+ },
577
+ (err) => {
578
+ console.warn("AudioManager AudioContext resume warning:", err);
579
+ }
580
+ )
581
+ );
582
+ }
583
+ }
584
+ if (typeof window !== "undefined" && "speechSynthesis" in window && typeof SpeechSynthesisUtterance !== "undefined") {
585
+ try {
586
+ if (window.speechSynthesis.paused) {
587
+ window.speechSynthesis.resume();
588
+ }
589
+ const utterance = new SpeechSynthesisUtterance("");
590
+ utterance.volume = 0;
591
+ window.speechSynthesis.speak(utterance);
592
+ anySucceeded = true;
593
+ } catch (err) {
594
+ console.warn("AudioManager speechSynthesis prime warning:", err);
595
+ }
596
+ }
597
+ if (audioPlayPromise) {
598
+ await audioPlayPromise;
599
+ }
600
+ if (resumePromises.length > 0) {
601
+ await Promise.all(resumePromises);
602
+ }
603
+ if (anySucceeded) {
604
+ this.unlocked = true;
605
+ }
606
+ return this.unlocked;
607
+ }
608
+ /**
609
+ * Resets internal state (primarily for unit testing).
610
+ */
611
+ reset() {
612
+ if (this.audioElement) {
613
+ try {
614
+ this.audioElement.pause();
615
+ } catch (err) {
616
+ void err;
617
+ }
618
+ }
619
+ this.audioElement = null;
620
+ this.registeredContexts.clear();
621
+ this.unlocked = false;
622
+ }
623
+ };
624
+ var audioManager = new AudioManager();
625
+
470
626
  // src/services/AudioAnalyzer.ts
471
627
  var AudioAnalyzer = class {
472
628
  ctx = null;
473
629
  analyzer = null;
474
630
  data = null;
475
631
  connectedElements = /* @__PURE__ */ new WeakSet();
476
- connect(audio) {
632
+ getContext() {
633
+ return this.ctx;
634
+ }
635
+ async resumeContext() {
636
+ if (!this.ctx) {
637
+ return false;
638
+ }
639
+ if (this.ctx.state === "suspended" && typeof this.ctx.resume === "function") {
640
+ try {
641
+ await this.ctx.resume();
642
+ } catch (error) {
643
+ console.warn("AudioAnalyzer resumeContext error:", error);
644
+ return false;
645
+ }
646
+ }
647
+ return this.ctx.state !== "suspended";
648
+ }
649
+ connect(audio, options = {}) {
477
650
  if (typeof window === "undefined") {
478
- return;
651
+ return false;
652
+ }
653
+ if (!options.force && isIOSDevice()) {
654
+ return false;
479
655
  }
480
656
  const AudioContextCtor = window.AudioContext || window.webkitAudioContext;
481
657
  if (!AudioContextCtor) {
482
- return;
658
+ return false;
483
659
  }
484
660
  try {
485
661
  if (!this.ctx) {
486
662
  this.ctx = new AudioContextCtor();
663
+ audioManager.registerAudioContext(this.ctx);
664
+ }
665
+ if (this.ctx.state === "suspended") {
666
+ if (typeof this.ctx.resume === "function") {
667
+ void this.ctx.resume().catch((err) => {
668
+ console.warn("AudioAnalyzer AudioContext resume warning:", err);
669
+ });
670
+ }
671
+ return false;
672
+ }
673
+ if (!this.analyzer) {
487
674
  this.analyzer = this.ctx.createAnalyser();
488
675
  this.analyzer.fftSize = 256;
489
- this.data = new Uint8Array(new ArrayBuffer(this.analyzer.frequencyBinCount));
676
+ this.data = new Uint8Array(
677
+ new ArrayBuffer(this.analyzer.frequencyBinCount)
678
+ );
490
679
  }
491
680
  if (!this.connectedElements.has(audio) && this.analyzer) {
492
681
  const source = this.ctx.createMediaElementSource(audio);
@@ -494,12 +683,14 @@ var AudioAnalyzer = class {
494
683
  this.analyzer.connect(this.ctx.destination);
495
684
  this.connectedElements.add(audio);
496
685
  }
686
+ return true;
497
687
  } catch (error) {
498
688
  console.warn("AudioAnalyzer connect error:", error);
689
+ return false;
499
690
  }
500
691
  }
501
692
  getAmplitude() {
502
- if (!this.analyzer || !this.data) {
693
+ if (!this.analyzer || !this.data || this.ctx?.state === "suspended") {
503
694
  return 0;
504
695
  }
505
696
  this.analyzer.getByteTimeDomainData(this.data);
@@ -744,6 +935,12 @@ var FALLBACK_DEFAULT_VOICE = {
744
935
  name: "en-US-Standard-B",
745
936
  voiceURI: "en-US-Standard-B"
746
937
  };
938
+ function isNotAllowedError(err) {
939
+ if (!err || typeof err !== "object") {
940
+ return false;
941
+ }
942
+ return err.name === "NotAllowedError";
943
+ }
747
944
  function isNativeSpeechSynthesisVoice(voice) {
748
945
  if (!voice || typeof voice !== "object") {
749
946
  return false;
@@ -774,6 +971,7 @@ function createFaceSpeechSlice(sliceOptions = {}) {
774
971
  let adapter = sliceOptions.speechAdapter ?? null;
775
972
  const cache = sliceOptions.ttsCache === false ? null : sliceOptions.ttsCache ?? defaultTtsAudioCache;
776
973
  const analyzer = sliceOptions.audioAnalyzer ?? audioAnalyzer;
974
+ const speechAudioManager = sliceOptions.audioManager ?? audioManager;
777
975
  const utteranceDeferMs = sliceOptions.utteranceDeferMs ?? 10;
778
976
  let activeAudio = null;
779
977
  let activeObjectUrl = null;
@@ -936,11 +1134,20 @@ function createFaceSpeechSlice(sliceOptions = {}) {
936
1134
  playbackUrl = synthesized.audioUrl;
937
1135
  }
938
1136
  }
939
- if (playbackUrl && typeof Audio !== "undefined") {
1137
+ const audio = playbackUrl ? speechAudioManager.getAudioElement() : null;
1138
+ if (playbackUrl && audio) {
940
1139
  get().setSpokenVisemes(visemes);
941
1140
  get().setAmplitudeData(ampData, extrema);
942
- const audio = new Audio(playbackUrl);
943
- audio.crossOrigin = "anonymous";
1141
+ audio.onplay = null;
1142
+ audio.onended = null;
1143
+ audio.onerror = null;
1144
+ try {
1145
+ audio.pause();
1146
+ audio.currentTime = 0;
1147
+ } catch (resetErr) {
1148
+ void resetErr;
1149
+ }
1150
+ audio.src = playbackUrl;
944
1151
  activeAudio = audio;
945
1152
  if (shouldRevokeUrl) {
946
1153
  activeObjectUrl = playbackUrl;
@@ -972,7 +1179,19 @@ function createFaceSpeechSlice(sliceOptions = {}) {
972
1179
  audio.onerror = () => {
973
1180
  finishGeneration(myGeneration);
974
1181
  };
975
- await audio.play();
1182
+ try {
1183
+ await audio.play();
1184
+ } catch (playError) {
1185
+ if (isNotAllowedError(playError)) {
1186
+ console.warn(
1187
+ "Audio playback blocked by browser autoplay policy (NotAllowedError); prompting user to re-enable sound."
1188
+ );
1189
+ get().setSpeechAllowed(false);
1190
+ finishGeneration(myGeneration);
1191
+ return;
1192
+ }
1193
+ throw playError;
1194
+ }
976
1195
  return;
977
1196
  }
978
1197
  } catch (adapterError) {
@@ -1078,6 +1297,16 @@ function createFaceSpeechSlice(sliceOptions = {}) {
1078
1297
  setSpeechAllowed: (allowed) => {
1079
1298
  set({ speechAllowed: allowed });
1080
1299
  },
1300
+ unlockAudio: async () => {
1301
+ const unlockPromise = speechAudioManager.unlock({
1302
+ audioContext: analyzer.getContext()
1303
+ });
1304
+ set({ speechAllowed: true });
1305
+ void get().refreshVoices();
1306
+ const unlocked = await unlockPromise;
1307
+ await analyzer.resumeContext();
1308
+ return unlocked;
1309
+ },
1081
1310
  setAvailableVoices: (voices) => {
1082
1311
  set({ availableVoices: voices });
1083
1312
  },
@@ -2234,64 +2463,231 @@ function FaceContainer({ frozen = false }) {
2234
2463
  }
2235
2464
 
2236
2465
  // src/components/FaceFullScreenButton.tsx
2237
- var import_react13 = require("react");
2238
- var import_react14 = require("@pixi/react");
2466
+ var import_react14 = require("react");
2467
+ var import_react15 = require("@pixi/react");
2239
2468
  var import_pixi6 = require("pixi.js");
2240
2469
  var import_core = require("@peerbots/core");
2241
- var import_jsx_runtime7 = require("react/jsx-runtime");
2242
- function FaceFullScreenButton() {
2243
- (0, import_react14.useExtend)({ Graphics: import_pixi6.Graphics, Container: import_pixi6.Container });
2244
- const { app } = (0, import_react14.useApplication)();
2245
- const [fullScreen, setFullScreen] = (0, import_react13.useState)(false);
2470
+
2471
+ // src/hooks/useFullscreen.ts
2472
+ var import_react13 = require("react");
2473
+
2474
+ // src/helpers/fullscreen.ts
2475
+ var FULLSCREEN_CHANGE_EVENTS = [
2476
+ "fullscreenchange",
2477
+ "webkitfullscreenchange",
2478
+ "mozfullscreenchange",
2479
+ "MSFullscreenChange"
2480
+ ];
2481
+ function getFullscreenElement(doc = typeof document !== "undefined" ? document : void 0) {
2482
+ if (!doc) return null;
2483
+ const vendorDoc = doc;
2484
+ return vendorDoc.fullscreenElement ?? vendorDoc.webkitFullscreenElement ?? vendorDoc.mozFullScreenElement ?? vendorDoc.msFullscreenElement ?? null;
2485
+ }
2486
+ function isNativeFullscreenSupported(element, doc = typeof document !== "undefined" ? document : void 0) {
2487
+ if (!doc) return false;
2488
+ const vendorDoc = doc;
2489
+ const enabledFlag = vendorDoc.fullscreenEnabled ?? vendorDoc.webkitFullscreenEnabled ?? vendorDoc.mozFullScreenEnabled ?? vendorDoc.msFullscreenEnabled;
2490
+ if (enabledFlag === false) {
2491
+ return false;
2492
+ }
2493
+ const target = element ?? doc.documentElement;
2494
+ if (!target) return false;
2495
+ return Boolean(
2496
+ typeof target.requestFullscreen === "function" || typeof target.webkitRequestFullscreen === "function" || typeof target.mozRequestFullScreen === "function" || typeof target.msRequestFullscreen === "function"
2497
+ );
2498
+ }
2499
+ async function requestNativeFullscreen(element) {
2500
+ const vendorEl = element;
2501
+ if (typeof vendorEl.requestFullscreen === "function") {
2502
+ await vendorEl.requestFullscreen();
2503
+ return;
2504
+ }
2505
+ if (typeof vendorEl.webkitRequestFullscreen === "function") {
2506
+ await vendorEl.webkitRequestFullscreen();
2507
+ return;
2508
+ }
2509
+ if (typeof vendorEl.mozRequestFullScreen === "function") {
2510
+ await vendorEl.mozRequestFullScreen();
2511
+ return;
2512
+ }
2513
+ if (typeof vendorEl.msRequestFullscreen === "function") {
2514
+ await vendorEl.msRequestFullscreen();
2515
+ return;
2516
+ }
2517
+ throw new Error("Native Fullscreen API is not supported on this element");
2518
+ }
2519
+ async function exitNativeFullscreen(doc = typeof document !== "undefined" ? document : void 0) {
2520
+ if (!doc) return;
2521
+ const vendorDoc = doc;
2522
+ if (typeof vendorDoc.exitFullscreen === "function") {
2523
+ await vendorDoc.exitFullscreen();
2524
+ return;
2525
+ }
2526
+ if (typeof vendorDoc.webkitExitFullscreen === "function") {
2527
+ await vendorDoc.webkitExitFullscreen();
2528
+ return;
2529
+ }
2530
+ if (typeof vendorDoc.mozCancelFullScreen === "function") {
2531
+ await vendorDoc.mozCancelFullScreen();
2532
+ return;
2533
+ }
2534
+ if (typeof vendorDoc.msExitFullscreen === "function") {
2535
+ await vendorDoc.msExitFullscreen();
2536
+ }
2537
+ }
2538
+ function addFullscreenChangeListener(listener, doc = typeof document !== "undefined" ? document : void 0) {
2539
+ if (!doc) {
2540
+ return () => void 0;
2541
+ }
2542
+ for (const eventName of FULLSCREEN_CHANGE_EVENTS) {
2543
+ doc.addEventListener(eventName, listener);
2544
+ }
2545
+ return () => {
2546
+ for (const eventName of FULLSCREEN_CHANGE_EVENTS) {
2547
+ doc.removeEventListener(eventName, listener);
2548
+ }
2549
+ };
2550
+ }
2551
+
2552
+ // src/hooks/useFullscreen.ts
2553
+ var FaceFullscreenContext = (0, import_react13.createContext)(null);
2554
+ function useFaceFullscreenContext() {
2555
+ return (0, import_react13.useContext)(FaceFullscreenContext);
2556
+ }
2557
+ function useFullscreen(targetRef, options = {}) {
2558
+ const { onFullscreenChange } = options;
2559
+ const [isNativeFullscreen, setIsNativeFullscreen] = (0, import_react13.useState)(false);
2560
+ const [isPseudoFullscreen, setIsPseudoFullscreen] = (0, import_react13.useState)(false);
2561
+ const previousBodyOverflowRef = (0, import_react13.useRef)(null);
2562
+ const onChangeRef = (0, import_react13.useRef)(onFullscreenChange);
2563
+ onChangeRef.current = onFullscreenChange;
2564
+ const isFullscreen = isNativeFullscreen || isPseudoFullscreen;
2565
+ const prevReportedRef = (0, import_react13.useRef)(false);
2246
2566
  (0, import_react13.useEffect)(() => {
2247
- if (typeof document === "undefined") {
2567
+ if (prevReportedRef.current !== isFullscreen) {
2568
+ prevReportedRef.current = isFullscreen;
2569
+ onChangeRef.current?.(isFullscreen);
2570
+ }
2571
+ }, [isFullscreen]);
2572
+ (0, import_react13.useEffect)(() => {
2573
+ const syncNative = () => {
2574
+ const fsEl = getFullscreenElement();
2575
+ const target = targetRef.current;
2576
+ const active = Boolean(
2577
+ fsEl && (!target || fsEl === target || target.contains(fsEl))
2578
+ );
2579
+ setIsNativeFullscreen(active);
2580
+ };
2581
+ syncNative();
2582
+ return addFullscreenChangeListener(syncNative);
2583
+ }, [targetRef]);
2584
+ (0, import_react13.useEffect)(() => {
2585
+ if (!isPseudoFullscreen || typeof document === "undefined") {
2248
2586
  return;
2249
2587
  }
2250
- const handleFullscreenChange = () => {
2251
- setFullScreen(Boolean(document.fullscreenElement));
2588
+ previousBodyOverflowRef.current = document.body.style.overflow;
2589
+ document.body.style.overflow = "hidden";
2590
+ const handleKeyDown = (event) => {
2591
+ if (event.key === "Escape") {
2592
+ setIsPseudoFullscreen(false);
2593
+ }
2252
2594
  };
2253
- document.addEventListener("fullscreenchange", handleFullscreenChange);
2595
+ window.addEventListener("keydown", handleKeyDown);
2254
2596
  return () => {
2255
- document.removeEventListener("fullscreenchange", handleFullscreenChange);
2597
+ window.removeEventListener("keydown", handleKeyDown);
2598
+ if (previousBodyOverflowRef.current !== null) {
2599
+ document.body.style.overflow = previousBodyOverflowRef.current;
2600
+ previousBodyOverflowRef.current = null;
2601
+ }
2256
2602
  };
2257
- }, []);
2258
- const toggleFullScreen = (0, import_react13.useCallback)(() => {
2259
- if (typeof document === "undefined") {
2603
+ }, [isPseudoFullscreen]);
2604
+ const enterFullscreen = (0, import_react13.useCallback)(async () => {
2605
+ const target = targetRef.current;
2606
+ if (!target) {
2260
2607
  return;
2261
2608
  }
2262
- if (fullScreen) {
2263
- void document.exitFullscreen().catch((err) => {
2609
+ if (isNativeFullscreenSupported(target)) {
2610
+ try {
2611
+ await requestNativeFullscreen(target);
2612
+ setIsNativeFullscreen(true);
2613
+ return;
2614
+ } catch (err) {
2615
+ console.warn(
2616
+ "Native fullscreen request failed; falling back to CSS pseudo-fullscreen:",
2617
+ err
2618
+ );
2619
+ }
2620
+ }
2621
+ setIsPseudoFullscreen(true);
2622
+ }, [targetRef]);
2623
+ const exitFullscreen = (0, import_react13.useCallback)(async () => {
2624
+ if (isPseudoFullscreen) {
2625
+ setIsPseudoFullscreen(false);
2626
+ }
2627
+ if (getFullscreenElement()) {
2628
+ try {
2629
+ await exitNativeFullscreen();
2630
+ } catch (err) {
2264
2631
  console.warn("Exit fullscreen error:", err);
2265
- });
2266
- } else {
2267
- const container = document.getElementById("face-view-container");
2268
- if (container) {
2269
- container.requestFullscreen().catch((err) => {
2270
- console.warn("Container fullscreen error:", err);
2271
- if (app?.canvas) {
2272
- void app.canvas.requestFullscreen().catch((canvasErr) => {
2273
- console.warn("Canvas fullscreen error:", canvasErr);
2274
- });
2275
- }
2276
- });
2277
- } else if (app?.canvas) {
2278
- void app.canvas.requestFullscreen().catch((err) => {
2279
- console.warn("Canvas fullscreen error:", err);
2280
- });
2281
2632
  }
2282
2633
  }
2283
- }, [app, fullScreen]);
2284
- const drawIcon = (0, import_react13.useCallback)(
2634
+ setIsNativeFullscreen(false);
2635
+ }, [isPseudoFullscreen]);
2636
+ const toggleFullscreen = (0, import_react13.useCallback)(async () => {
2637
+ if (isFullscreen) {
2638
+ await exitFullscreen();
2639
+ } else {
2640
+ await enterFullscreen();
2641
+ }
2642
+ }, [isFullscreen, exitFullscreen, enterFullscreen]);
2643
+ return (0, import_react13.useMemo)(
2644
+ () => ({
2645
+ isFullscreen,
2646
+ isPseudoFullscreen,
2647
+ enterFullscreen,
2648
+ exitFullscreen,
2649
+ toggleFullscreen
2650
+ }),
2651
+ [
2652
+ isFullscreen,
2653
+ isPseudoFullscreen,
2654
+ enterFullscreen,
2655
+ exitFullscreen,
2656
+ toggleFullscreen
2657
+ ]
2658
+ );
2659
+ }
2660
+
2661
+ // src/components/FaceFullScreenButton.tsx
2662
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2663
+ function FaceFullScreenButton() {
2664
+ (0, import_react15.useExtend)({ Graphics: import_pixi6.Graphics, Container: import_pixi6.Container });
2665
+ const { app } = (0, import_react15.useApplication)();
2666
+ const contextFullscreen = useFaceFullscreenContext();
2667
+ const fallbackRef = (0, import_react14.useRef)(null);
2668
+ const fallbackFullscreen = useFullscreen(fallbackRef);
2669
+ const isFullscreen = contextFullscreen ? contextFullscreen.isFullscreen : fallbackFullscreen.isFullscreen;
2670
+ const toggleFullScreen = (0, import_react14.useCallback)(() => {
2671
+ if (contextFullscreen) {
2672
+ void contextFullscreen.toggleFullscreen();
2673
+ return;
2674
+ }
2675
+ if (typeof document !== "undefined") {
2676
+ fallbackRef.current = document.getElementById("face-view-container") ?? (app?.canvas instanceof HTMLElement ? app.canvas : null);
2677
+ }
2678
+ void fallbackFullscreen.toggleFullscreen();
2679
+ }, [app, contextFullscreen, fallbackFullscreen]);
2680
+ const drawIcon = (0, import_react14.useCallback)(
2285
2681
  (graphics) => {
2286
2682
  graphics.clear();
2287
- const pathD = fullScreen ? import_core.iconPaths.arrowsPointingIn : import_core.iconPaths.arrowsPointingOut;
2683
+ const pathD = isFullscreen ? import_core.iconPaths.arrowsPointingIn : import_core.iconPaths.arrowsPointingOut;
2288
2684
  graphics.svg(`
2289
2685
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
2290
2686
  <path strokeLinecap="round" strokeLinejoin="round" d="${pathD}" />
2291
2687
  </svg>
2292
2688
  `);
2293
2689
  },
2294
- [fullScreen]
2690
+ [isFullscreen]
2295
2691
  );
2296
2692
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2297
2693
  "pixiContainer",
@@ -2315,22 +2711,22 @@ function FaceFullScreenButton() {
2315
2711
  }
2316
2712
 
2317
2713
  // src/components/FaceScrollToTopButton.tsx
2318
- var import_react15 = require("react");
2319
- var import_react16 = require("@pixi/react");
2714
+ var import_react16 = require("react");
2715
+ var import_react17 = require("@pixi/react");
2320
2716
  var import_pixi7 = require("pixi.js");
2321
2717
  var import_core2 = require("@peerbots/core");
2322
2718
  var import_jsx_runtime8 = require("react/jsx-runtime");
2323
2719
  function FaceScrollToTopButton() {
2324
- (0, import_react16.useExtend)({ Graphics: import_pixi7.Graphics, Container: import_pixi7.Container });
2325
- const [xPos, setXPos] = (0, import_react15.useState)(
2720
+ (0, import_react17.useExtend)({ Graphics: import_pixi7.Graphics, Container: import_pixi7.Container });
2721
+ const [xPos, setXPos] = (0, import_react16.useState)(
2326
2722
  () => typeof window !== "undefined" ? window.innerWidth - 50 : 750
2327
2723
  );
2328
- const scrollToTop = (0, import_react15.useCallback)(() => {
2724
+ const scrollToTop = (0, import_react16.useCallback)(() => {
2329
2725
  if (typeof window !== "undefined") {
2330
2726
  window.scrollTo(0, 0);
2331
2727
  }
2332
2728
  }, []);
2333
- (0, import_react15.useLayoutEffect)(() => {
2729
+ (0, import_react16.useLayoutEffect)(() => {
2334
2730
  if (typeof window === "undefined") {
2335
2731
  return;
2336
2732
  }
@@ -2345,7 +2741,7 @@ function FaceScrollToTopButton() {
2345
2741
  window.removeEventListener("resize", calculatePositionBasedOnWindow);
2346
2742
  };
2347
2743
  }, []);
2348
- const drawChevron = (0, import_react15.useCallback)((graphics) => {
2744
+ const drawChevron = (0, import_react16.useCallback)((graphics) => {
2349
2745
  graphics.clear();
2350
2746
  graphics.svg(`
2351
2747
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke="black">
@@ -2380,10 +2776,10 @@ function PixiFaceView({
2380
2776
  isPreview = false,
2381
2777
  frozen = false
2382
2778
  } = {}) {
2383
- (0, import_react18.useExtend)({ Container: import_pixi8.Container, Graphics: import_pixi8.Graphics, Sprite: import_pixi8.Sprite, Text: import_pixi8.Text });
2779
+ (0, import_react19.useExtend)({ Container: import_pixi8.Container, Graphics: import_pixi8.Graphics, Sprite: import_pixi8.Sprite, Text: import_pixi8.Text });
2384
2780
  const settings = useFaceStore((state) => state.faceSettings);
2385
2781
  const currentStore = useFaceStoreInstance();
2386
- const [containerEl, setContainerEl] = (0, import_react17.useState)(null);
2782
+ const [containerEl, setContainerEl] = (0, import_react18.useState)(null);
2387
2783
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2388
2784
  "div",
2389
2785
  {
@@ -2391,7 +2787,7 @@ function PixiFaceView({
2391
2787
  className: "pbf:w-full pbf:h-full pbf:relative pbf:overflow-hidden",
2392
2788
  "data-testid": "pixi-face-view",
2393
2789
  children: containerEl ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2394
- import_react18.Application,
2790
+ import_react19.Application,
2395
2791
  {
2396
2792
  resizeTo: containerEl,
2397
2793
  backgroundColor: "#ABE3FA",