talking-head-studio 0.4.10 → 0.4.12

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 (178) hide show
  1. package/README.md +299 -337
  2. package/dist/TalkingHead.d.ts +44 -28
  3. package/dist/TalkingHead.js +21 -2
  4. package/dist/TalkingHead.web.d.ts +37 -4
  5. package/dist/TalkingHead.web.js +28 -8
  6. package/dist/TalkingHeadVisualization.d.ts +22 -0
  7. package/dist/TalkingHeadVisualization.js +30 -10
  8. package/dist/api/studioApi.d.ts +12 -1
  9. package/dist/api/studioApi.js +41 -28
  10. package/dist/appearance/apply.js +2 -3
  11. package/dist/appearance/matchers.js +1 -2
  12. package/dist/appearance/schema.js +1 -2
  13. package/dist/contract.d.ts +14 -0
  14. package/dist/contract.js +30 -0
  15. package/dist/core/avatar/avatarCapabilities.d.ts +60 -0
  16. package/dist/core/avatar/avatarCapabilities.js +100 -0
  17. package/dist/core/avatar/backend.d.ts +130 -0
  18. package/dist/core/avatar/backend.js +4 -0
  19. package/dist/core/avatar/backends/gaussian.d.ts +49 -0
  20. package/dist/core/avatar/backends/gaussian.js +293 -0
  21. package/dist/core/avatar/backends/index.d.ts +3 -0
  22. package/dist/core/avatar/backends/index.js +7 -0
  23. package/dist/core/avatar/backends/morphTarget.d.ts +39 -0
  24. package/dist/core/avatar/backends/morphTarget.js +179 -0
  25. package/dist/core/avatar/faceControls.d.ts +40 -0
  26. package/dist/core/avatar/faceControls.js +138 -0
  27. package/dist/core/avatar/motion.d.ts +1713 -0
  28. package/dist/core/avatar/motion.js +550 -0
  29. package/dist/core/avatar/motionRuntime.d.ts +46 -0
  30. package/dist/core/avatar/motionRuntime.js +84 -0
  31. package/dist/core/avatar/schema.d.ts +78 -0
  32. package/dist/core/avatar/schema.js +134 -0
  33. package/dist/core/avatar/visemes.d.ts +47 -1
  34. package/dist/core/avatar/visemes.js +114 -1
  35. package/dist/editor/AvatarCanvas.js +93 -3
  36. package/dist/editor/AvatarEditor.native.js +19 -9
  37. package/dist/editor/AvatarModel.js +2 -2
  38. package/dist/editor/FaceSqueezeEditor.d.ts +3 -1
  39. package/dist/editor/FaceSqueezeEditor.js +195 -121
  40. package/dist/editor/FaceSqueezeEditor.web.d.ts +3 -1
  41. package/dist/editor/FaceSqueezeEditor.web.js +32 -30
  42. package/dist/editor/RigidAccessory.js +18 -4
  43. package/dist/editor/SkinnedClothing.js +19 -9
  44. package/dist/editor/boneLockedDrag.d.ts +11 -0
  45. package/dist/editor/boneLockedDrag.js +68 -0
  46. package/dist/editor/boneSnap.js +22 -12
  47. package/dist/editor/boneSnap.web.d.ts +27 -0
  48. package/dist/editor/boneSnap.web.js +99 -0
  49. package/dist/editor/index.web.d.ts +10 -0
  50. package/dist/editor/index.web.js +26 -0
  51. package/dist/editor/sounds/haha.wav +0 -0
  52. package/dist/editor/sounds/owie.wav +0 -0
  53. package/dist/editor/sounds/stop.wav +0 -0
  54. package/dist/editor/studioTheme.d.ts +14 -14
  55. package/dist/editor/studioTheme.js +19 -16
  56. package/dist/editor/types.d.ts +1 -0
  57. package/dist/html/accessories.d.ts +7 -0
  58. package/dist/html/accessories.js +149 -0
  59. package/dist/html/motion.d.ts +1 -0
  60. package/dist/html/motion.js +189 -0
  61. package/dist/html/visemes.d.ts +7 -0
  62. package/dist/html/visemes.js +348 -0
  63. package/dist/html.d.ts +1 -1
  64. package/dist/html.js +56 -734
  65. package/dist/index.d.ts +19 -1
  66. package/dist/index.js +44 -5
  67. package/dist/index.web.d.ts +18 -1
  68. package/dist/index.web.js +36 -3
  69. package/dist/platform/api/types.d.ts +10 -0
  70. package/dist/platform/api/types.js +2 -0
  71. package/dist/platform/marketplace/types.d.ts +32 -0
  72. package/dist/platform/marketplace/types.js +2 -0
  73. package/dist/platform/sdk/unity.d.ts +27 -0
  74. package/dist/platform/sdk/unity.js +2 -0
  75. package/dist/platform/sdk/unreal.d.ts +23 -0
  76. package/dist/platform/sdk/unreal.js +2 -0
  77. package/dist/platform/sdk/web.d.ts +16 -0
  78. package/dist/platform/sdk/web.js +2 -0
  79. package/dist/sketchfab/api.js +5 -5
  80. package/dist/sketchfab/glbInspect.d.ts +22 -0
  81. package/dist/sketchfab/glbInspect.js +58 -0
  82. package/dist/sketchfab/index.d.ts +3 -0
  83. package/dist/sketchfab/index.js +8 -1
  84. package/dist/sketchfab/inspectRemote.d.ts +13 -0
  85. package/dist/sketchfab/inspectRemote.js +77 -0
  86. package/dist/sketchfab/types.d.ts +10 -0
  87. package/dist/sketchfab/useSketchfabSearch.js +1 -2
  88. package/dist/studio/AccessoryBrowserScreen.d.ts +6 -0
  89. package/dist/studio/AccessoryBrowserScreen.js +626 -0
  90. package/dist/studio/AccessoryPanel.d.ts +10 -0
  91. package/dist/studio/AccessoryPanel.js +396 -0
  92. package/dist/studio/AppearancePanel.d.ts +9 -0
  93. package/dist/studio/AppearancePanel.js +77 -0
  94. package/dist/studio/AvatarCreatorScreen.d.ts +5 -0
  95. package/dist/studio/AvatarCreatorScreen.js +806 -0
  96. package/dist/studio/AvatarEditorScreen.d.ts +14 -0
  97. package/dist/studio/AvatarEditorScreen.js +510 -0
  98. package/dist/studio/AvatarGrid.d.ts +23 -0
  99. package/dist/studio/AvatarGrid.js +257 -0
  100. package/dist/studio/ColorSwatch.d.ts +8 -0
  101. package/dist/studio/ColorSwatch.js +100 -0
  102. package/dist/studio/CreateVoiceProfileSheet.d.ts +8 -0
  103. package/dist/studio/CreateVoiceProfileSheet.js +242 -0
  104. package/dist/studio/DetailsPanel.d.ts +15 -0
  105. package/dist/studio/DetailsPanel.js +239 -0
  106. package/dist/studio/FilamentEditor.d.ts +2 -0
  107. package/dist/studio/FilamentEditor.js +6 -0
  108. package/dist/studio/PrecisionPanel.d.ts +2 -0
  109. package/dist/studio/PrecisionPanel.js +7 -0
  110. package/dist/studio/PublicGalleryScreen.d.ts +5 -0
  111. package/dist/studio/PublicGalleryScreen.js +358 -0
  112. package/dist/studio/SketchfabModelCard.d.ts +20 -0
  113. package/dist/studio/SketchfabModelCard.js +104 -0
  114. package/dist/studio/StudioBrowseHeader.d.ts +9 -0
  115. package/dist/studio/StudioBrowseHeader.js +28 -0
  116. package/dist/studio/StudioEmptyState.d.ts +8 -0
  117. package/dist/studio/StudioEmptyState.js +29 -0
  118. package/dist/studio/StudioFloatingAction.d.ts +13 -0
  119. package/dist/studio/StudioFloatingAction.js +42 -0
  120. package/dist/studio/StudioSectionHeader.d.ts +7 -0
  121. package/dist/studio/StudioSectionHeader.js +27 -0
  122. package/dist/studio/StudioSurfaceCard.d.ts +8 -0
  123. package/dist/studio/StudioSurfaceCard.js +20 -0
  124. package/dist/studio/VoicePanel.d.ts +15 -0
  125. package/dist/studio/VoicePanel.js +305 -0
  126. package/dist/studio/constants.d.ts +3 -0
  127. package/dist/studio/constants.js +6 -0
  128. package/dist/studio/index.d.ts +29 -0
  129. package/dist/studio/index.js +54 -0
  130. package/dist/studio/useSketchfabCapabilities.d.ts +31 -0
  131. package/dist/studio/useSketchfabCapabilities.js +82 -0
  132. package/dist/tts/useDirectVisemeStream.d.ts +2 -6
  133. package/dist/tts/useDirectVisemeStream.js +16 -12
  134. package/dist/tts/useMotionMarkers.d.ts +0 -1
  135. package/dist/tts/useMotionMarkers.js +1 -2
  136. package/dist/utils/avatarUtils.js +94 -8
  137. package/dist/utils/faceLandmarkerToShapeWeights.js +21 -14
  138. package/dist/voice/convertToWav.js +1 -2
  139. package/dist/voice/index.d.ts +3 -0
  140. package/dist/voice/index.js +6 -1
  141. package/dist/voice/useAudioPlayer.js +18 -6
  142. package/dist/voice/useAudioRecording.js +1 -2
  143. package/dist/voice/useFaceControls.d.ts +14 -0
  144. package/dist/voice/useFaceControls.js +81 -0
  145. package/dist/voice/useVoicePreview.d.ts +7 -0
  146. package/dist/voice/useVoicePreview.js +83 -0
  147. package/dist/wardrobe/index.d.ts +3 -0
  148. package/dist/wardrobe/index.js +8 -1
  149. package/dist/wardrobe/useAccessoryGestures.d.ts +20 -0
  150. package/dist/wardrobe/useAccessoryGestures.js +94 -0
  151. package/dist/wardrobe/useAvatarWardrobeHydration.js +9 -4
  152. package/dist/wardrobe/useStudioAvatar.d.ts +29 -0
  153. package/dist/wardrobe/useStudioAvatar.js +186 -0
  154. package/dist/wardrobe/wardrobeStore.d.ts +2 -0
  155. package/dist/wardrobe/wardrobeStore.js +12 -2
  156. package/dist/wgpu/R3FWebGpuCanvas.d.ts +15 -0
  157. package/dist/wgpu/R3FWebGpuCanvas.js +176 -0
  158. package/dist/wgpu/WgpuAvatar.d.ts +26 -2
  159. package/dist/wgpu/WgpuAvatar.js +313 -46
  160. package/dist/wgpu/accessoryDefaults.d.ts +12 -0
  161. package/dist/wgpu/accessoryDefaults.js +19 -0
  162. package/dist/wgpu/blobShim.d.ts +2 -0
  163. package/dist/wgpu/blobShim.js +191 -0
  164. package/dist/wgpu/index.d.ts +1 -0
  165. package/dist/wgpu/index.js +4 -1
  166. package/dist/wgpu/loadGLTFFromUri.d.ts +2 -0
  167. package/dist/wgpu/loadGLTFFromUri.js +75 -0
  168. package/dist/wgpu/morphTables.js +21 -10
  169. package/dist/wgpu/motionState.d.ts +20 -0
  170. package/dist/wgpu/motionState.js +31 -0
  171. package/dist/wgpu/patchThreeForRN.d.ts +28 -0
  172. package/dist/wgpu/patchThreeForRN.js +292 -0
  173. package/dist/wgpu/scenePlacement.d.ts +5 -0
  174. package/dist/wgpu/scenePlacement.js +50 -0
  175. package/dist/wgpu/useAuthedModelUri.js +22 -11
  176. package/dist/wgpu/useNativeGLTF.d.ts +7 -0
  177. package/dist/wgpu/useNativeGLTF.js +36 -0
  178. package/package.json +102 -32
@@ -0,0 +1,14 @@
1
+ export interface AvatarEditorScreenProps {
2
+ avatarId: string;
3
+ onDelete?: () => void;
4
+ onBrowseAccessories?: () => void;
5
+ /**
6
+ * Optional voice-preview override forwarded to VoicePanel. A host that mounts
7
+ * a live avatar (e.g. Sorti's docked studio panel) passes this to preview the
8
+ * voice on the real speaking face with lip-sync instead of an audio sample.
9
+ */
10
+ onPreviewVoice?: (voiceId: string) => Promise<void> | void;
11
+ /** Voice id currently previewing, when the host owns preview state. */
12
+ previewingVoiceId?: string | null;
13
+ }
14
+ export declare function AvatarEditorScreen({ avatarId, onDelete, onBrowseAccessories, onPreviewVoice, previewingVoiceId }: AvatarEditorScreenProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,510 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AvatarEditorScreen = AvatarEditorScreen;
40
+ const jsx_runtime_1 = require("react/jsx-runtime");
41
+ const vector_icons_1 = require("@expo/vector-icons");
42
+ const TalkingHead_1 = require("../TalkingHead");
43
+ const expo_blur_1 = require("expo-blur");
44
+ const Haptics = __importStar(require("expo-haptics"));
45
+ const react_1 = require("react");
46
+ const react_native_1 = require("react-native");
47
+ const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
48
+ const AccessoryPanel_1 = __importDefault(require("./AccessoryPanel"));
49
+ const AppearancePanel_1 = __importDefault(require("./AppearancePanel"));
50
+ const DetailsPanel_1 = require("./DetailsPanel");
51
+ const FilamentEditor_1 = require("./FilamentEditor");
52
+ const wardrobe_1 = require("../wardrobe");
53
+ const VoicePanel_1 = __importDefault(require("./VoicePanel"));
54
+ const api_1 = require("../api");
55
+ const editor_1 = require("../editor");
56
+ // ---------------------------------------------------------------------------
57
+ // Constants
58
+ // ---------------------------------------------------------------------------
59
+ const TAB_ITEMS = [
60
+ { name: 'Appearance', icon: 'color-palette-outline' },
61
+ { name: 'Voice', icon: 'mic-outline' },
62
+ { name: 'Details', icon: 'document-text-outline' },
63
+ { name: 'Accessories', icon: 'sparkles-outline' },
64
+ ];
65
+ const MOODS = [
66
+ 'neutral',
67
+ 'happy',
68
+ 'sad',
69
+ 'angry',
70
+ 'fear',
71
+ 'disgust',
72
+ 'love',
73
+ 'sleep',
74
+ 'excited',
75
+ 'thinking',
76
+ 'concerned',
77
+ 'surprised',
78
+ ];
79
+ const MOOD_INTERVAL_MIN = 4000;
80
+ const MOOD_INTERVAL_MAX = 8000;
81
+ const COLORS = {
82
+ bg: editor_1.studioTheme.colors.background,
83
+ surface: editor_1.studioTheme.colors.surface,
84
+ card: editor_1.studioTheme.colors.surfaceRaised,
85
+ border: editor_1.studioTheme.colors.border,
86
+ accent: editor_1.studioTheme.colors.accent,
87
+ textPrimary: editor_1.studioTheme.colors.textPrimary,
88
+ textSecondary: editor_1.studioTheme.colors.textSecondary,
89
+ error: editor_1.studioTheme.colors.danger,
90
+ };
91
+ // ---------------------------------------------------------------------------
92
+ // Helpers
93
+ // ---------------------------------------------------------------------------
94
+ function randomMood() {
95
+ return MOODS[Math.floor(Math.random() * MOODS.length)];
96
+ }
97
+ function randomInterval() {
98
+ return MOOD_INTERVAL_MIN + Math.random() * (MOOD_INTERVAL_MAX - MOOD_INTERVAL_MIN);
99
+ }
100
+ function SegmentedTabs({ active, onSelect }) {
101
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.tabBar, children: (0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { horizontal: true, showsHorizontalScrollIndicator: false, contentContainerStyle: styles.tabRow, children: TAB_ITEMS.map((tab) => {
102
+ const isActive = tab.name === active;
103
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.Pressable, { onPress: () => {
104
+ void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
105
+ onSelect(tab.name);
106
+ }, style: [styles.tabItem, isActive && styles.tabItemActive], children: [(0, jsx_runtime_1.jsx)(vector_icons_1.Ionicons, { name: tab.icon, size: 16, color: isActive ? COLORS.textPrimary : COLORS.textSecondary }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.tabLabel, isActive && styles.tabLabelActive], children: tab.name })] }, tab.name));
107
+ }) }) }));
108
+ }
109
+ // ---------------------------------------------------------------------------
110
+ // Main Screen
111
+ // ---------------------------------------------------------------------------
112
+ function AvatarEditorScreen({ avatarId, onDelete, onBrowseAccessories, onPreviewVoice, previewingVoiceId }) {
113
+ const { height: windowHeight } = (0, react_native_1.useWindowDimensions)();
114
+ const talkingHeadRef = (0, react_1.useRef)(null);
115
+ const [activeTab, setActiveTab] = (0, react_1.useState)('Appearance');
116
+ const [isPlacementMode, setIsPlacementMode] = (0, react_1.useState)(false);
117
+ const [authToken, setAuthToken] = (0, react_1.useState)(undefined);
118
+ (0, react_1.useEffect)(() => {
119
+ (0, api_1.getToken)()
120
+ .then((t) => { setAuthToken(t); })
121
+ .catch(() => setAuthToken(null));
122
+ }, []);
123
+ // Crossfade shared values
124
+ const talkingHeadOpacity = (0, react_native_reanimated_1.useSharedValue)(1);
125
+ const filamentOpacity = (0, react_native_reanimated_1.useSharedValue)(0);
126
+ const blurIntensity = (0, react_native_reanimated_1.useSharedValue)(0);
127
+ // ---- Placement mode transition -------------------------------------------
128
+ const autoSaveTimer = (0, react_1.useRef)(null);
129
+ const enterPlacementMode = (0, react_1.useCallback)(() => {
130
+ if (autoSaveTimer.current) {
131
+ clearTimeout(autoSaveTimer.current);
132
+ autoSaveTimer.current = null;
133
+ }
134
+ talkingHeadOpacity.value = (0, react_native_reanimated_1.withTiming)(0, { duration: 400 });
135
+ filamentOpacity.value = (0, react_native_reanimated_1.withTiming)(1, { duration: 400 });
136
+ blurIntensity.value = (0, react_native_reanimated_1.withSequence)((0, react_native_reanimated_1.withTiming)(1, { duration: 150 }), (0, react_native_reanimated_1.withDelay)(100, (0, react_native_reanimated_1.withTiming)(0, { duration: 150 })));
137
+ setIsPlacementMode(true);
138
+ }, [talkingHeadOpacity, filamentOpacity, blurIntensity]);
139
+ const saveRef = (0, react_1.useRef)(() => Promise.resolve());
140
+ const exitPlacementMode = (0, react_1.useCallback)(() => {
141
+ filamentOpacity.value = (0, react_native_reanimated_1.withTiming)(0, { duration: 400 });
142
+ talkingHeadOpacity.value = (0, react_native_reanimated_1.withTiming)(1, { duration: 400 });
143
+ setTimeout(() => setIsPlacementMode(false), 450);
144
+ saveRef
145
+ .current()
146
+ .catch((err) => console.error('[exitPlacementMode] save failed:', err));
147
+ }, [talkingHeadOpacity, filamentOpacity]);
148
+ const filamentAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
149
+ opacity: filamentOpacity.value,
150
+ pointerEvents: filamentOpacity.value > 0.5 ? 'auto' : 'none',
151
+ }));
152
+ const talkingHeadAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
153
+ opacity: talkingHeadOpacity.value,
154
+ pointerEvents: talkingHeadOpacity.value > 0.5 ? 'auto' : 'none',
155
+ }));
156
+ const blurAnimatedStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
157
+ opacity: blurIntensity.value,
158
+ }));
159
+ const { avatar, loading, error, name, setName, description, setDescription, isPublic, setIsPublic, hairColor, setHairColor, skinColor, setSkinColor, eyeColor, setEyeColor, voiceProfileId, setVoiceProfileId, isDirty, save, reload, saving, } = (0, wardrobe_1.useStudioAvatar)({ avatarId });
160
+ saveRef.current = save;
161
+ // ---- Wardrobe Hydration --------------------------------------------------
162
+ const setActiveAsset = (0, wardrobe_1.useWardrobeStore)((s) => s.setActiveAsset);
163
+ const setPlacement = (0, wardrobe_1.useWardrobeStore)((s) => s.setPlacement);
164
+ const equipped = (0, wardrobe_1.useWardrobeStore)((s) => s.equipped);
165
+ const placements = (0, wardrobe_1.useWardrobeStore)((s) => s.placements);
166
+ const activeAssetId = (0, wardrobe_1.useWardrobeStore)((s) => s.activeAssetId);
167
+ const editorEquipped = (0, react_1.useMemo)(() => Object.values(equipped).map((asset) => ({
168
+ id: asset.id,
169
+ url: (0, api_1.assetFileUrl)(asset),
170
+ type: 'rigid',
171
+ slot: asset.slot,
172
+ })), [equipped]);
173
+ const handlePlacementChange = (0, react_1.useCallback)((assetId, placement) => {
174
+ setPlacement(assetId, {
175
+ bone: placement.bone,
176
+ position: placement.position,
177
+ rotation: placement.rotation,
178
+ scale: placement.scale ?? 1,
179
+ });
180
+ }, [setPlacement]);
181
+ const mappedAccessories = (0, react_1.useMemo)(() => {
182
+ return Object.values(equipped).map((asset) => {
183
+ const p = placements[asset.id];
184
+ return {
185
+ id: asset.id,
186
+ url: (0, api_1.assetFileUrl)(asset),
187
+ bone: p?.bone ?? 'Head',
188
+ position: p?.position ?? [0, 0, 0],
189
+ rotation: p?.rotation ?? [0, 0, 0],
190
+ scale: p?.scale ?? 1,
191
+ };
192
+ });
193
+ }, [equipped, placements]);
194
+ (0, wardrobe_1.useAvatarWardrobeHydration)({
195
+ avatarId: avatar?.id,
196
+ accessories: avatar?.appearance?.equippedAccessories,
197
+ });
198
+ const previewHeight = (0, react_1.useMemo)(() => {
199
+ const ratio = isPlacementMode ? 0.5 : 0.4;
200
+ return Math.max(250, Math.min(windowHeight * ratio, 430));
201
+ }, [isPlacementMode, windowHeight]);
202
+ const statusLabel = saving
203
+ ? 'Saving changes'
204
+ : isDirty
205
+ ? 'Unsaved edits'
206
+ : 'All changes saved';
207
+ const accessoryCount = Object.keys(equipped).length;
208
+ // ---- Random mood cycling ------------------------------------------------
209
+ (0, react_1.useEffect)(() => {
210
+ if (!avatar)
211
+ return;
212
+ let timeout;
213
+ const cycleMood = () => {
214
+ talkingHeadRef.current?.setMood(randomMood());
215
+ timeout = setTimeout(cycleMood, randomInterval());
216
+ };
217
+ timeout = setTimeout(cycleMood, randomInterval());
218
+ return () => clearTimeout(timeout);
219
+ }, [avatar]);
220
+ // ---- Live color preview callbacks ----------------------------------------
221
+ const handleSetHairColor = (0, react_1.useCallback)((color) => {
222
+ setHairColor(color);
223
+ talkingHeadRef.current?.setHairColor(color);
224
+ }, [setHairColor]);
225
+ const handleSetSkinColor = (0, react_1.useCallback)((color) => {
226
+ setSkinColor(color);
227
+ talkingHeadRef.current?.setSkinColor(color);
228
+ }, [setSkinColor]);
229
+ const handleSetEyeColor = (0, react_1.useCallback)((color) => {
230
+ setEyeColor(color);
231
+ talkingHeadRef.current?.setEyeColor(color);
232
+ }, [setEyeColor]);
233
+ // ---- Delete handler ------------------------------------------------------
234
+ const handleDelete = (0, react_1.useCallback)(async () => {
235
+ try {
236
+ await (0, api_1.deleteAvatar)(avatarId);
237
+ onDelete?.();
238
+ }
239
+ catch {
240
+ // DetailsPanel shows its own Alert; error will propagate via the hook
241
+ }
242
+ }, [avatarId, onDelete]);
243
+ // ---- Derived values ------------------------------------------------------
244
+ const avatarUrl = (0, react_1.useMemo)(() => (avatar ? (0, api_1.avatarFileUrl)(avatar) : null), [avatar]);
245
+ const stableTalkingHeadUrl = (0, react_1.useMemo)(() => {
246
+ if (!avatarUrl)
247
+ return null;
248
+ try {
249
+ const u = new URL(avatarUrl);
250
+ u.search = '';
251
+ return u.toString();
252
+ }
253
+ catch {
254
+ return avatarUrl.split('?')[0];
255
+ }
256
+ // eslint-disable-next-line react-hooks/exhaustive-deps
257
+ }, [avatar?.id]);
258
+ // ---- Panel rendering -----------------------------------------------------
259
+ const renderPanel = (0, react_1.useCallback)(() => {
260
+ switch (activeTab) {
261
+ case 'Appearance':
262
+ return ((0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { style: styles.panelScroll, contentContainerStyle: styles.panelScrollContent, showsVerticalScrollIndicator: false, children: (0, jsx_runtime_1.jsx)(AppearancePanel_1.default, { hairColor: hairColor, setHairColor: handleSetHairColor, skinColor: skinColor, setSkinColor: handleSetSkinColor, eyeColor: eyeColor, setEyeColor: handleSetEyeColor }) }));
263
+ case 'Voice':
264
+ return (0, jsx_runtime_1.jsx)(VoicePanel_1.default, { activeVoiceId: voiceProfileId, onSelectVoice: setVoiceProfileId, onPreviewVoice: onPreviewVoice, previewingVoiceId: previewingVoiceId });
265
+ case 'Accessories':
266
+ return ((0, jsx_runtime_1.jsx)(AccessoryPanel_1.default, { avatarId: avatarId, onPositionAsset: (assetId) => {
267
+ setActiveAsset(assetId);
268
+ enterPlacementMode();
269
+ }, onBrowseAccessories: onBrowseAccessories }));
270
+ case 'Details':
271
+ return ((0, jsx_runtime_1.jsx)(DetailsPanel_1.DetailsPanel, { name: name, setName: setName, description: description, setDescription: setDescription, isPublic: isPublic, setIsPublic: setIsPublic, isDirty: isDirty, saving: saving, onSave: save, onDelete: handleDelete }));
272
+ }
273
+ }, [
274
+ activeTab,
275
+ hairColor,
276
+ handleSetHairColor,
277
+ skinColor,
278
+ handleSetSkinColor,
279
+ eyeColor,
280
+ handleSetEyeColor,
281
+ voiceProfileId,
282
+ setVoiceProfileId,
283
+ onPreviewVoice,
284
+ previewingVoiceId,
285
+ name,
286
+ setName,
287
+ description,
288
+ setDescription,
289
+ isPublic,
290
+ setIsPublic,
291
+ isDirty,
292
+ saving,
293
+ save,
294
+ handleDelete,
295
+ avatarId,
296
+ enterPlacementMode,
297
+ setActiveAsset,
298
+ onBrowseAccessories,
299
+ ]);
300
+ // ---- Auto-save appearance changes ----------------------------------------
301
+ (0, react_1.useEffect)(() => {
302
+ if (!isDirty || saving || isPlacementMode)
303
+ return;
304
+ if (autoSaveTimer.current)
305
+ clearTimeout(autoSaveTimer.current);
306
+ autoSaveTimer.current = setTimeout(() => {
307
+ save().catch((err) => console.error('[auto-save] failed:', err));
308
+ }, 1500);
309
+ return () => {
310
+ if (autoSaveTimer.current)
311
+ clearTimeout(autoSaveTimer.current);
312
+ };
313
+ }, [isDirty, saving, isPlacementMode, save]);
314
+ // ---- Loading state -------------------------------------------------------
315
+ if (loading && !avatar) {
316
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.centered, children: [(0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "large", color: COLORS.accent }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.loadingText, children: "Loading avatar..." })] }));
317
+ }
318
+ // ---- Error state ---------------------------------------------------------
319
+ if (error && !avatar) {
320
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.centered, children: [(0, jsx_runtime_1.jsx)(vector_icons_1.Ionicons, { name: "alert-circle-outline", size: 40, color: COLORS.error, style: { marginBottom: 12 } }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.errorText, children: error }), (0, jsx_runtime_1.jsx)(react_native_1.Pressable, { style: styles.retryButton, onPress: reload, children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.retryButtonText, children: "Retry" }) })] }));
321
+ }
322
+ // ---- Main layout ---------------------------------------------------------
323
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.container, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.previewContainer, { height: previewHeight }], children: [stableTalkingHeadUrl && authToken !== undefined && !isPlacementMode && ((0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.talkingHead, talkingHeadAnimatedStyle], children: (0, jsx_runtime_1.jsx)(TalkingHead_1.TalkingHead, { ref: talkingHeadRef, avatarUrl: stableTalkingHeadUrl, authToken: authToken, cameraView: "upper", cameraDistance: -0.5, skinColor: skinColor, hairColor: hairColor, eyeColor: eyeColor, accessories: mappedAccessories, style: react_native_1.StyleSheet.absoluteFillObject, onError: (msg) => console.error('[TalkingHead] Error:', msg) }) })), avatarUrl && isPlacementMode && ((0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.talkingHead, filamentAnimatedStyle], children: (0, jsx_runtime_1.jsx)(FilamentEditor_1.FilamentEditor, { avatarUrl: avatarUrl, equipped: editorEquipped, placements: placements, activeAssetId: activeAssetId, onActiveAssetChange: setActiveAsset, onPlacementChange: handlePlacementChange, onDone: exitPlacementMode, style: react_native_1.StyleSheet.absoluteFillObject, skinColor: skinColor }) })), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { style: [styles.talkingHead, blurAnimatedStyle], pointerEvents: "none", children: (0, jsx_runtime_1.jsx)(expo_blur_1.BlurView, { intensity: 20, tint: "dark", style: react_native_1.StyleSheet.absoluteFillObject }) }), !avatarUrl && ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.previewPlaceholder, children: (0, jsx_runtime_1.jsx)(vector_icons_1.Ionicons, { name: "cube-outline", size: 48, color: COLORS.textSecondary }) }))] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.editorMetaBar, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.editorMetaCopy, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.editorEyebrow, children: isPlacementMode ? 'Placement mode' : 'Avatar studio' }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.editorTitle, children: isPlacementMode ? 'Fine-tune your wearable placement.' : 'Refine the look, voice, and presence.' })] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [
324
+ styles.statusChip,
325
+ saving
326
+ ? styles.statusChipAccent
327
+ : isDirty
328
+ ? styles.statusChipPending
329
+ : styles.statusChipCalm,
330
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.statusChipText, children: statusLabel }) })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.metaPillRow, children: [(0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.metaPill, children: [(0, jsx_runtime_1.jsx)(vector_icons_1.Ionicons, { name: "sparkles-outline", size: 14, color: COLORS.textPrimary }), (0, jsx_runtime_1.jsxs)(react_native_1.Text, { style: styles.metaPillText, children: [accessoryCount, " ", accessoryCount === 1 ? 'accessory' : 'accessories'] })] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.metaPill, children: [(0, jsx_runtime_1.jsx)(vector_icons_1.Ionicons, { name: "albums-outline", size: 14, color: COLORS.textPrimary }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.metaPillText, children: activeTab })] })] }), (0, jsx_runtime_1.jsx)(SegmentedTabs, { active: activeTab, onSelect: setActiveTab }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.panelContainer, children: renderPanel() })] }));
331
+ }
332
+ // ---------------------------------------------------------------------------
333
+ // Styles
334
+ // ---------------------------------------------------------------------------
335
+ const styles = react_native_1.StyleSheet.create({
336
+ container: {
337
+ flex: 1,
338
+ backgroundColor: COLORS.bg,
339
+ },
340
+ centered: {
341
+ flex: 1,
342
+ backgroundColor: COLORS.bg,
343
+ justifyContent: 'center',
344
+ alignItems: 'center',
345
+ padding: 24,
346
+ },
347
+ previewContainer: {
348
+ backgroundColor: COLORS.surface,
349
+ overflow: 'hidden',
350
+ borderBottomLeftRadius: 28,
351
+ borderBottomRightRadius: 28,
352
+ },
353
+ talkingHead: {
354
+ position: 'absolute',
355
+ top: 0,
356
+ left: 0,
357
+ right: 0,
358
+ bottom: 0,
359
+ },
360
+ previewPlaceholder: {
361
+ ...react_native_1.StyleSheet.absoluteFillObject,
362
+ justifyContent: 'center',
363
+ alignItems: 'center',
364
+ },
365
+ tabBar: {
366
+ backgroundColor: COLORS.bg,
367
+ paddingTop: 8,
368
+ },
369
+ tabRow: {
370
+ flexDirection: 'row',
371
+ paddingHorizontal: 16,
372
+ gap: 10,
373
+ },
374
+ tabItem: {
375
+ flexDirection: 'row',
376
+ alignItems: 'center',
377
+ gap: 8,
378
+ paddingHorizontal: 14,
379
+ paddingVertical: 12,
380
+ borderRadius: 999,
381
+ backgroundColor: COLORS.surface,
382
+ borderWidth: 1,
383
+ borderColor: COLORS.border,
384
+ },
385
+ tabItemActive: {
386
+ backgroundColor: COLORS.card,
387
+ borderColor: COLORS.accent,
388
+ },
389
+ tabLabel: {
390
+ fontSize: 13,
391
+ fontWeight: '600',
392
+ color: COLORS.textSecondary,
393
+ letterSpacing: 0.3,
394
+ },
395
+ tabLabelActive: {
396
+ color: COLORS.textPrimary,
397
+ },
398
+ editorMetaBar: {
399
+ flexDirection: 'row',
400
+ justifyContent: 'space-between',
401
+ alignItems: 'flex-start',
402
+ gap: 12,
403
+ paddingHorizontal: 16,
404
+ paddingTop: 18,
405
+ paddingBottom: 10,
406
+ },
407
+ editorMetaCopy: {
408
+ flex: 1,
409
+ gap: 4,
410
+ },
411
+ editorEyebrow: {
412
+ color: COLORS.textSecondary,
413
+ fontSize: 11,
414
+ fontWeight: '700',
415
+ letterSpacing: 1.6,
416
+ textTransform: 'uppercase',
417
+ },
418
+ editorTitle: {
419
+ color: COLORS.textPrimary,
420
+ fontSize: 15,
421
+ lineHeight: 21,
422
+ fontWeight: '600',
423
+ },
424
+ statusChip: {
425
+ paddingHorizontal: 12,
426
+ paddingVertical: 8,
427
+ borderRadius: 999,
428
+ borderWidth: 1,
429
+ },
430
+ statusChipAccent: {
431
+ backgroundColor: `${COLORS.accent}20`,
432
+ borderColor: `${COLORS.accent}60`,
433
+ },
434
+ statusChipPending: {
435
+ backgroundColor: `${COLORS.textSecondary}16`,
436
+ borderColor: `${COLORS.textSecondary}44`,
437
+ },
438
+ statusChipCalm: {
439
+ backgroundColor: `${COLORS.textPrimary}12`,
440
+ borderColor: `${COLORS.textPrimary}24`,
441
+ },
442
+ statusChipText: {
443
+ color: COLORS.textPrimary,
444
+ fontSize: 12,
445
+ fontWeight: '700',
446
+ letterSpacing: 0.2,
447
+ },
448
+ metaPillRow: {
449
+ flexDirection: 'row',
450
+ flexWrap: 'wrap',
451
+ gap: 8,
452
+ paddingHorizontal: 16,
453
+ paddingBottom: 4,
454
+ },
455
+ metaPill: {
456
+ flexDirection: 'row',
457
+ alignItems: 'center',
458
+ gap: 6,
459
+ paddingHorizontal: 12,
460
+ paddingVertical: 8,
461
+ borderRadius: 999,
462
+ backgroundColor: COLORS.surface,
463
+ borderWidth: 1,
464
+ borderColor: COLORS.border,
465
+ },
466
+ metaPillText: {
467
+ color: COLORS.textPrimary,
468
+ fontSize: 12,
469
+ fontWeight: '600',
470
+ },
471
+ panelContainer: {
472
+ flex: 1,
473
+ backgroundColor: COLORS.surface,
474
+ marginTop: 14,
475
+ borderTopLeftRadius: 28,
476
+ borderTopRightRadius: 28,
477
+ overflow: 'hidden',
478
+ },
479
+ panelScroll: {
480
+ flex: 1,
481
+ },
482
+ panelScrollContent: {
483
+ paddingBottom: 108,
484
+ },
485
+ loadingText: {
486
+ marginTop: 16,
487
+ color: COLORS.textSecondary,
488
+ fontSize: 15,
489
+ fontWeight: '500',
490
+ letterSpacing: 0.3,
491
+ },
492
+ errorText: {
493
+ color: '#f87171',
494
+ fontSize: 15,
495
+ textAlign: 'center',
496
+ marginBottom: 20,
497
+ lineHeight: 22,
498
+ },
499
+ retryButton: {
500
+ backgroundColor: COLORS.card,
501
+ paddingHorizontal: 24,
502
+ paddingVertical: 12,
503
+ borderRadius: 999,
504
+ },
505
+ retryButtonText: {
506
+ color: '#ffffff',
507
+ fontWeight: '600',
508
+ fontSize: 14,
509
+ },
510
+ });
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ export interface AvatarGridItem {
3
+ id: string;
4
+ name: string;
5
+ thumbnailUrl: string | null;
6
+ subtitle?: string;
7
+ isActive?: boolean;
8
+ }
9
+ export interface AvatarGridProps {
10
+ items: AvatarGridItem[];
11
+ loading: boolean;
12
+ error: string | null;
13
+ onSelect: (id: string) => void;
14
+ onDelete?: (id: string) => void;
15
+ onRetry?: () => void;
16
+ emptyMessage?: string;
17
+ emptySubMessage?: string;
18
+ thumbnailHeaders?: Record<string, string>;
19
+ ListHeaderComponent?: React.ReactElement;
20
+ bottomClearance?: number;
21
+ }
22
+ export declare function AvatarGrid({ items, loading, error, onSelect, onDelete, onRetry, emptyMessage, emptySubMessage, thumbnailHeaders, ListHeaderComponent, bottomClearance, }: AvatarGridProps): import("react/jsx-runtime").JSX.Element;
23
+ export default AvatarGrid;