@celljs/ta-web 4.27.0 → 4.28.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 (264) hide show
  1. package/esm/browser/assistant/assistant-role.d.ts +9 -4
  2. package/esm/browser/assistant/assistant-role.js +17 -5
  3. package/esm/browser/assistant/assistant-task-util.d.ts +6 -0
  4. package/esm/browser/assistant/assistant-task-util.js +12 -1
  5. package/esm/browser/assistant/assistant-view.js +4 -1
  6. package/esm/browser/assistant/assistant.d.ts +2 -1
  7. package/esm/browser/assistant/assistant.js +9 -7
  8. package/esm/browser/assistant/call-conversing.d.ts +45 -0
  9. package/esm/browser/assistant/call-conversing.js +91 -0
  10. package/esm/browser/assistant/call-face.d.ts +13 -0
  11. package/esm/browser/assistant/call-face.js +81 -0
  12. package/esm/browser/assistant/call-keeper.d.ts +8 -4
  13. package/esm/browser/assistant/call-keeper.js +32 -11
  14. package/esm/browser/assistant/call-partnering.d.ts +37 -0
  15. package/esm/browser/assistant/call-partnering.js +79 -0
  16. package/esm/browser/assistant/call-scenes.d.ts +25 -0
  17. package/esm/browser/assistant/call-scenes.js +82 -0
  18. package/esm/browser/assistant/call-screen.d.ts +3 -0
  19. package/esm/browser/assistant/call-screen.js +15 -0
  20. package/esm/browser/assistant/mic-sense.d.ts +31 -0
  21. package/esm/browser/assistant/mic-sense.js +119 -0
  22. package/esm/browser/assistant/noise-gate.d.ts +32 -0
  23. package/esm/browser/assistant/noise-gate.js +66 -0
  24. package/esm/browser/assistant/pcm-util.d.ts +10 -0
  25. package/esm/browser/assistant/pcm-util.js +55 -0
  26. package/esm/browser/assistant/read-aloud.d.ts +2 -1
  27. package/esm/browser/assistant/realtime-voice-protocol.d.ts +84 -0
  28. package/esm/browser/assistant/realtime-voice-protocol.js +40 -0
  29. package/esm/browser/assistant/realtime-voice.d.ts +50 -62
  30. package/esm/browser/assistant/realtime-voice.js +213 -134
  31. package/esm/browser/assistant/spoken-timeline.d.ts +27 -0
  32. package/esm/browser/assistant/spoken-timeline.js +49 -0
  33. package/esm/browser/assistant/voice-call-bar.d.ts +9 -2
  34. package/esm/browser/assistant/voice-call-bar.js +81 -31
  35. package/esm/browser/assistant/voice-call-protocol.d.ts +61 -4
  36. package/esm/browser/assistant/voice-call.d.ts +16 -23
  37. package/esm/browser/assistant/voice-call.js +134 -117
  38. package/esm/browser/assistant/voice-reading.d.ts +83 -0
  39. package/esm/browser/assistant/voice-reading.js +150 -0
  40. package/esm/browser/avatar/dino-talk.d.ts +15 -0
  41. package/esm/browser/avatar/dino-talk.js +34 -0
  42. package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
  43. package/esm/browser/components/conversation-scroll-util.d.ts +8 -1
  44. package/esm/browser/components/conversation-scroll-util.js +21 -0
  45. package/esm/browser/components/conversation-scroll.js +10 -11
  46. package/esm/browser/components/gallery.js +28 -7
  47. package/esm/browser/components/host-view.d.ts +1 -1
  48. package/esm/browser/components/image-pull.d.ts +64 -0
  49. package/esm/browser/components/image-pull.js +202 -0
  50. package/esm/browser/components/kept-call-bar.js +2 -1
  51. package/esm/browser/components/lightbox.d.ts +1 -1
  52. package/esm/browser/components/lightbox.js +57 -2
  53. package/esm/browser/components/markdown.d.ts +3 -1
  54. package/esm/browser/components/markdown.js +8 -4
  55. package/esm/browser/components/partner-row.js +2 -1
  56. package/esm/browser/components/relay-services.d.ts +9 -3
  57. package/esm/browser/components/relay-services.js +73 -35
  58. package/esm/browser/components/session-view.js +4 -2
  59. package/esm/browser/components/settings-parts.js +2 -0
  60. package/esm/browser/components/ta-avatar.d.ts +15 -1
  61. package/esm/browser/components/ta-avatar.js +38 -5
  62. package/esm/browser/components/voice-services.js +6 -1
  63. package/esm/browser/extension/web-api-call.d.ts +64 -2
  64. package/esm/browser/extension/web-api-contributions.d.ts +1 -0
  65. package/esm/browser/extension/web-api-partners.d.ts +2 -0
  66. package/esm/browser/extension/web-extension-api.d.ts +6 -6
  67. package/esm/browser/extension/web-extension-context.js +1 -0
  68. package/esm/browser/extension/web-extension-protocol.d.ts +3 -1
  69. package/esm/browser/extension/web-extension-run.d.ts +3 -2
  70. package/esm/browser/extension/web-extension-run.js +2 -0
  71. package/esm/browser/i18n/locales.d.ts +24 -5
  72. package/esm/browser/i18n/messages-ja.js +25 -6
  73. package/esm/browser/i18n/messages-zh-tw.js +25 -6
  74. package/esm/browser/i18n/messages.d.ts +23 -4
  75. package/esm/browser/i18n/messages.js +50 -12
  76. package/esm/browser/markdown/code-renderers.d.ts +2 -0
  77. package/esm/browser/markdown/code-renderers.js +2 -0
  78. package/esm/browser/screen/page-answers.d.ts +2 -1
  79. package/esm/browser/screen/page-answers.js +7 -4
  80. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  81. package/esm/browser/settings/settings-protocol.js +2 -0
  82. package/esm/browser/style/chat-list.d.ts +1 -1
  83. package/esm/browser/style/chat-list.js +1 -1
  84. package/esm/browser/style/conversation.d.ts +1 -1
  85. package/esm/browser/style/conversation.js +6 -1
  86. package/esm/browser/style/device.js +1 -0
  87. package/esm/browser/style/dialogs.d.ts +1 -1
  88. package/esm/browser/style/dialogs.js +1 -1
  89. package/esm/browser/style/layout.d.ts +1 -1
  90. package/esm/browser/style/layout.js +135 -57
  91. package/esm/browser/style/shell.d.ts +1 -1
  92. package/esm/browser/style/shell.js +8 -0
  93. package/esm/browser/style/video-call.d.ts +2 -0
  94. package/esm/browser/style/video-call.js +52 -0
  95. package/esm/browser/style.js +2 -0
  96. package/esm/browser/util/desktop.d.ts +10 -1
  97. package/esm/browser/util/desktop.js +10 -0
  98. package/esm/browser/util/image-pull.d.ts +61 -0
  99. package/esm/browser/util/image-pull.js +88 -0
  100. package/esm/browser/util/spoken.d.ts +3 -3
  101. package/esm/browser/util/spoken.js +4 -4
  102. package/esm/browser/video-call/call-camera.d.ts +59 -0
  103. package/esm/browser/video-call/call-camera.js +188 -0
  104. package/esm/browser/video-call/call-window.d.ts +19 -0
  105. package/esm/browser/video-call/call-window.js +80 -0
  106. package/esm/browser/video-call/clip-plan.d.ts +47 -0
  107. package/esm/browser/video-call/clip-plan.js +60 -0
  108. package/esm/browser/video-call/face-clips.d.ts +33 -0
  109. package/esm/browser/video-call/face-clips.js +93 -0
  110. package/esm/browser/video-call/face-files.d.ts +31 -0
  111. package/esm/browser/video-call/face-files.js +77 -0
  112. package/esm/browser/video-call/video-call-view.d.ts +19 -0
  113. package/esm/browser/video-call/video-call-view.js +214 -0
  114. package/esm/browser/video-call/video-face.d.ts +13 -0
  115. package/esm/browser/video-call/video-face.js +497 -0
  116. package/esm/browser/workbench-hosts.d.ts +1 -0
  117. package/esm/browser/workbench-protocol.d.ts +2 -0
  118. package/esm/browser/workbench-util.d.ts +5 -0
  119. package/esm/browser/workbench-util.js +18 -0
  120. package/esm/browser/workbench.d.ts +6 -0
  121. package/esm/browser/workbench.js +36 -5
  122. package/lib/browser/assistant/assistant-role.d.ts +9 -4
  123. package/lib/browser/assistant/assistant-role.js +17 -5
  124. package/lib/browser/assistant/assistant-task-util.d.ts +6 -0
  125. package/lib/browser/assistant/assistant-task-util.js +11 -0
  126. package/lib/browser/assistant/assistant-view.js +3 -0
  127. package/lib/browser/assistant/assistant.d.ts +2 -1
  128. package/lib/browser/assistant/assistant.js +9 -7
  129. package/lib/browser/assistant/call-conversing.d.ts +46 -0
  130. package/lib/browser/assistant/call-conversing.js +96 -0
  131. package/lib/browser/assistant/call-face.d.ts +14 -0
  132. package/lib/browser/assistant/call-face.js +117 -0
  133. package/lib/browser/assistant/call-keeper.d.ts +8 -4
  134. package/lib/browser/assistant/call-keeper.js +32 -11
  135. package/lib/browser/assistant/call-partnering.d.ts +38 -0
  136. package/lib/browser/assistant/call-partnering.js +83 -0
  137. package/lib/browser/assistant/call-scenes.d.ts +26 -0
  138. package/lib/browser/assistant/call-scenes.js +85 -0
  139. package/lib/browser/assistant/call-screen.d.ts +3 -0
  140. package/lib/browser/assistant/call-screen.js +15 -0
  141. package/lib/browser/assistant/mic-sense.d.ts +32 -0
  142. package/lib/browser/assistant/mic-sense.js +123 -0
  143. package/lib/browser/assistant/noise-gate.d.ts +33 -0
  144. package/lib/browser/assistant/noise-gate.js +71 -0
  145. package/lib/browser/assistant/pcm-util.d.ts +11 -0
  146. package/lib/browser/assistant/pcm-util.js +58 -0
  147. package/lib/browser/assistant/read-aloud.d.ts +2 -1
  148. package/lib/browser/assistant/realtime-voice-protocol.d.ts +85 -0
  149. package/lib/browser/assistant/realtime-voice-protocol.js +43 -0
  150. package/lib/browser/assistant/realtime-voice.d.ts +50 -62
  151. package/lib/browser/assistant/realtime-voice.js +217 -138
  152. package/lib/browser/assistant/spoken-timeline.d.ts +28 -0
  153. package/lib/browser/assistant/spoken-timeline.js +53 -0
  154. package/lib/browser/assistant/voice-call-bar.d.ts +9 -2
  155. package/lib/browser/assistant/voice-call-bar.js +81 -30
  156. package/lib/browser/assistant/voice-call-protocol.d.ts +61 -4
  157. package/lib/browser/assistant/voice-call.d.ts +16 -23
  158. package/lib/browser/assistant/voice-call.js +134 -117
  159. package/lib/browser/assistant/voice-reading.d.ts +84 -0
  160. package/lib/browser/assistant/voice-reading.js +156 -0
  161. package/lib/browser/avatar/dino-talk.d.ts +16 -0
  162. package/lib/browser/avatar/dino-talk.js +37 -0
  163. package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
  164. package/lib/browser/components/conversation-scroll-util.d.ts +8 -1
  165. package/lib/browser/components/conversation-scroll-util.js +21 -0
  166. package/lib/browser/components/conversation-scroll.js +10 -11
  167. package/lib/browser/components/gallery.js +28 -7
  168. package/lib/browser/components/host-view.d.ts +1 -1
  169. package/lib/browser/components/image-pull.d.ts +65 -0
  170. package/lib/browser/components/image-pull.js +206 -0
  171. package/lib/browser/components/kept-call-bar.js +2 -1
  172. package/lib/browser/components/lightbox.d.ts +1 -1
  173. package/lib/browser/components/lightbox.js +57 -2
  174. package/lib/browser/components/markdown.d.ts +3 -1
  175. package/lib/browser/components/markdown.js +7 -3
  176. package/lib/browser/components/partner-row.js +2 -1
  177. package/lib/browser/components/relay-services.d.ts +9 -3
  178. package/lib/browser/components/relay-services.js +71 -33
  179. package/lib/browser/components/session-view.js +3 -1
  180. package/lib/browser/components/settings-parts.js +2 -0
  181. package/lib/browser/components/ta-avatar.d.ts +15 -1
  182. package/lib/browser/components/ta-avatar.js +38 -5
  183. package/lib/browser/components/voice-services.js +5 -0
  184. package/lib/browser/extension/web-api-call.d.ts +64 -2
  185. package/lib/browser/extension/web-api-contributions.d.ts +1 -0
  186. package/lib/browser/extension/web-api-partners.d.ts +2 -0
  187. package/lib/browser/extension/web-extension-api.d.ts +6 -6
  188. package/lib/browser/extension/web-extension-context.js +1 -0
  189. package/lib/browser/extension/web-extension-protocol.d.ts +3 -1
  190. package/lib/browser/extension/web-extension-run.d.ts +3 -2
  191. package/lib/browser/extension/web-extension-run.js +2 -0
  192. package/lib/browser/i18n/locales.d.ts +24 -5
  193. package/lib/browser/i18n/messages-ja.js +25 -6
  194. package/lib/browser/i18n/messages-zh-tw.js +25 -6
  195. package/lib/browser/i18n/messages.d.ts +23 -4
  196. package/lib/browser/i18n/messages.js +50 -12
  197. package/lib/browser/markdown/code-renderers.d.ts +2 -0
  198. package/lib/browser/markdown/code-renderers.js +3 -1
  199. package/lib/browser/screen/page-answers.d.ts +2 -1
  200. package/lib/browser/screen/page-answers.js +7 -4
  201. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  202. package/lib/browser/settings/settings-protocol.js +2 -0
  203. package/lib/browser/style/chat-list.d.ts +1 -1
  204. package/lib/browser/style/chat-list.js +1 -1
  205. package/lib/browser/style/conversation.d.ts +1 -1
  206. package/lib/browser/style/conversation.js +6 -1
  207. package/lib/browser/style/device.js +1 -0
  208. package/lib/browser/style/dialogs.d.ts +1 -1
  209. package/lib/browser/style/dialogs.js +1 -1
  210. package/lib/browser/style/layout.d.ts +1 -1
  211. package/lib/browser/style/layout.js +135 -57
  212. package/lib/browser/style/shell.d.ts +1 -1
  213. package/lib/browser/style/shell.js +8 -0
  214. package/lib/browser/style/video-call.d.ts +3 -0
  215. package/lib/browser/style/video-call.js +55 -0
  216. package/lib/browser/style.js +2 -0
  217. package/lib/browser/util/desktop.d.ts +10 -1
  218. package/lib/browser/util/desktop.js +10 -0
  219. package/lib/browser/util/image-pull.d.ts +62 -0
  220. package/lib/browser/util/image-pull.js +91 -0
  221. package/lib/browser/util/spoken.d.ts +3 -3
  222. package/lib/browser/util/spoken.js +4 -4
  223. package/lib/browser/video-call/call-camera.d.ts +60 -0
  224. package/lib/browser/video-call/call-camera.js +192 -0
  225. package/lib/browser/video-call/call-window.d.ts +20 -0
  226. package/lib/browser/video-call/call-window.js +83 -0
  227. package/lib/browser/video-call/clip-plan.d.ts +48 -0
  228. package/lib/browser/video-call/clip-plan.js +64 -0
  229. package/lib/browser/video-call/face-clips.d.ts +34 -0
  230. package/lib/browser/video-call/face-clips.js +96 -0
  231. package/lib/browser/video-call/face-files.d.ts +32 -0
  232. package/lib/browser/video-call/face-files.js +82 -0
  233. package/lib/browser/video-call/video-call-view.d.ts +20 -0
  234. package/lib/browser/video-call/video-call-view.js +250 -0
  235. package/lib/browser/video-call/video-face.d.ts +14 -0
  236. package/lib/browser/video-call/video-face.js +533 -0
  237. package/lib/browser/workbench-hosts.d.ts +1 -0
  238. package/lib/browser/workbench-protocol.d.ts +2 -0
  239. package/lib/browser/workbench-util.d.ts +5 -0
  240. package/lib/browser/workbench-util.js +18 -0
  241. package/lib/browser/workbench.d.ts +6 -0
  242. package/lib/browser/workbench.js +35 -4
  243. package/package.json +7 -7
  244. package/public/faces/README.md +27 -0
  245. package/public/faces/clap.mp4 +0 -0
  246. package/public/faces/dance.mp4 +0 -0
  247. package/public/faces/happy.mp4 +0 -0
  248. package/public/faces/heart.mp4 +0 -0
  249. package/public/faces/idle-1.mp4 +0 -0
  250. package/public/faces/idle-2.mp4 +0 -0
  251. package/public/faces/idle-3.mp4 +0 -0
  252. package/public/faces/laugh.mp4 +0 -0
  253. package/public/faces/lips.json +1 -0
  254. package/public/faces/listening.mp4 +0 -0
  255. package/public/faces/poster.jpg +0 -0
  256. package/public/faces/shy.mp4 +0 -0
  257. package/public/faces/sorry.mp4 +0 -0
  258. package/public/faces/stretch.mp4 +0 -0
  259. package/public/faces/surprised.mp4 +0 -0
  260. package/public/faces/talk-1.mp4 +0 -0
  261. package/public/faces/talk-2.mp4 +0 -0
  262. package/public/faces/think-2.mp4 +0 -0
  263. package/public/faces/thinking.mp4 +0 -0
  264. package/public/faces/wave.mp4 +0 -0
@@ -0,0 +1,48 @@
1
+ /** The frame rate of the clips of the person (faces/*.mp4). */
2
+ export declare const CLIP_FPS = 24;
3
+ /** A clip as it plays in a reading, from `from` seconds of it. */
4
+ interface Segment {
5
+ clip: string;
6
+ from: number;
7
+ frames: number;
8
+ }
9
+ /**
10
+ * Which clip of the person shows at each moment of what Ta reads, chosen ahead as its sound comes (docs/design/ta-call.md
11
+ * 12): the mouth of each frame is drawn from the sound of that moment for that frame of that clip, so the clips must be
12
+ * known before they play. A clip plays whole, then the next is picked for the moment it begins (the look of the sentence
13
+ * heard then, or another gesture); all begin and end on the same frame, so that one follows another without a seam.
14
+ */
15
+ export declare class ClipPlan {
16
+ /** The frames of a clip. */
17
+ protected readonly frames: (clip: string) => number;
18
+ /** The clip that begins at that second of the reading, after `last`. */
19
+ protected readonly pick: (seconds: number, last: string | undefined) => string;
20
+ protected readonly segments: Segment[];
21
+ constructor(
22
+ /** The frames of a clip. */
23
+ frames: (clip: string) => number,
24
+ /** The clip that begins at that second of the reading, after `last`. */
25
+ pick: (seconds: number, last: string | undefined) => string);
26
+ /** The clip and its frame at that second of the reading. */
27
+ at(seconds: number): {
28
+ clip: string;
29
+ frame: number;
30
+ };
31
+ /** Picks the clips up to that second, once each. */
32
+ protected cover(seconds: number): void;
33
+ }
34
+ /**
35
+ * Keeps the clip on the clock of the sound, as players keep a video on its sound: a little apart, it plays a little
36
+ * faster or slower until they meet (each frame of it then has the mouth drawn for it, or the next one); far apart, it
37
+ * goes there at once.
38
+ */
39
+ export declare namespace ClipSync {
40
+ /** Apart by more than this, in seconds, the clip goes where the sound is. */
41
+ const SEEK_S = 0.3;
42
+ function step(want: number, now: number): {
43
+ seek?: number;
44
+ rate: number;
45
+ };
46
+ }
47
+ export {};
48
+ //# sourceMappingURL=clip-plan.d.ts.map
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClipSync = exports.ClipPlan = exports.CLIP_FPS = void 0;
4
+ /** The frame rate of the clips of the person (faces/*.mp4). */
5
+ exports.CLIP_FPS = 24;
6
+ /**
7
+ * Which clip of the person shows at each moment of what Ta reads, chosen ahead as its sound comes (docs/design/ta-call.md
8
+ * 12): the mouth of each frame is drawn from the sound of that moment for that frame of that clip, so the clips must be
9
+ * known before they play. A clip plays whole, then the next is picked for the moment it begins (the look of the sentence
10
+ * heard then, or another gesture); all begin and end on the same frame, so that one follows another without a seam.
11
+ */
12
+ class ClipPlan {
13
+ constructor(
14
+ /** The frames of a clip. */
15
+ frames,
16
+ /** The clip that begins at that second of the reading, after `last`. */
17
+ pick) {
18
+ this.frames = frames;
19
+ this.pick = pick;
20
+ this.segments = [];
21
+ }
22
+ /** The clip and its frame at that second of the reading. */
23
+ at(seconds) {
24
+ const time = Math.max(0, seconds);
25
+ this.cover(time);
26
+ let segment = this.segments[this.segments.length - 1];
27
+ for (let i = this.segments.length - 1; i >= 0 && this.segments[i].from > time; i--) {
28
+ segment = this.segments[Math.max(0, i - 1)];
29
+ }
30
+ return { clip: segment.clip, frame: Math.min(segment.frames - 1, Math.floor((time - segment.from) * exports.CLIP_FPS)) };
31
+ }
32
+ /** Picks the clips up to that second, once each. */
33
+ cover(seconds) {
34
+ let last = this.segments[this.segments.length - 1];
35
+ while (!last || last.from + last.frames / exports.CLIP_FPS <= seconds) {
36
+ const from = last ? last.from + last.frames / exports.CLIP_FPS : 0;
37
+ const clip = this.pick(from, last === null || last === void 0 ? void 0 : last.clip);
38
+ last = { clip, from, frames: Math.max(1, this.frames(clip)) };
39
+ this.segments.push(last);
40
+ }
41
+ }
42
+ }
43
+ exports.ClipPlan = ClipPlan;
44
+ /**
45
+ * Keeps the clip on the clock of the sound, as players keep a video on its sound: a little apart, it plays a little
46
+ * faster or slower until they meet (each frame of it then has the mouth drawn for it, or the next one); far apart, it
47
+ * goes there at once.
48
+ */
49
+ var ClipSync;
50
+ (function (ClipSync) {
51
+ /** Apart by more than this, in seconds, the clip goes where the sound is. */
52
+ ClipSync.SEEK_S = 0.3;
53
+ /** How much faster it plays, a second it is behind. */
54
+ const CATCH_UP = 3;
55
+ function step(want, now) {
56
+ const behind = want - now;
57
+ if (Math.abs(behind) > ClipSync.SEEK_S) {
58
+ return { seek: want, rate: 1 };
59
+ }
60
+ return { rate: Math.min(1.25, Math.max(0.8, 1 + behind * CATCH_UP)) };
61
+ }
62
+ ClipSync.step = step;
63
+ })(ClipSync || (exports.ClipSync = ClipSync = {}));
64
+ //# sourceMappingURL=clip-plan.js.map
@@ -0,0 +1,34 @@
1
+ import type { CallPhase, CallReading } from '../assistant/voice-call-protocol';
2
+ /**
3
+ * The clips of the person, under public/faces (README.md there): each begins and ends on the same frame. As Ta speaks
4
+ * with a voice service, what the clip shows, the captions and the mouth all follow the clock of its sound (ClipPlan,
5
+ * SpokenTimeline), and an extension may draw her mouth again for that sound (registerCallMouth).
6
+ */
7
+ /** A look she has as she says a sentence: its clip plays once, at the moment it is heard, her mouth drawn on it. */
8
+ export type Mood = 'happy' | 'surprised' | 'sorry' | 'laugh' | 'wave' | 'heart' | 'clap' | 'shy';
9
+ /** What she does once she has said a sentence of it (she stands up from the sofa): it plays as she listens after. */
10
+ export type Show = 'dance' | 'stretch';
11
+ export type ClipKind = 'listening' | 'thinking' | 'speaking' | Mood | Show;
12
+ /**
13
+ * Which clip the person of a video call plays (docs/design/ta-call.md 12), as the products of AI companions do: clips
14
+ * made beforehand of one person, each for a state, all beginning and ending on the same frame, so that one follows
15
+ * another without a seam at its end, and crosses into another at once as the state changes.
16
+ */
17
+ export declare namespace FaceClips {
18
+ /** The clip for the call as it is. */
19
+ function kind(phase: CallPhase, paused: boolean): ClipKind;
20
+ /** The look of a sentence Ta says (its clip plays once as she says it); undefined for none in particular. */
21
+ function mood(words: string | undefined): Mood | undefined;
22
+ function isMood(kind: ClipKind | undefined): kind is Mood;
23
+ function isShow(kind: ClipKind | undefined): kind is Show;
24
+ /** What she does once she said a sentence (she dances when she says she will); undefined for nothing. */
25
+ function show(words: string | undefined): Show | undefined;
26
+ /** The next clip of `kind`, at random but never the one just played: the same gestures do not come back in a row. */
27
+ function next(kind: ClipKind, last: string | undefined, random?: () => number): string;
28
+ /**
29
+ * The clip that begins at a second of a reading, after `last`: the look of the sentence heard then, once a sentence
30
+ * (`used`), else another gesture of speaking.
31
+ */
32
+ function at(reading: Pick<CallReading, 'pieces' | 'pieceAt'> | undefined, seconds: number, last: string | undefined, used: Set<number>): string;
33
+ }
34
+ //# sourceMappingURL=face-clips.d.ts.map
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FaceClips = void 0;
4
+ const CLIPS = {
5
+ listening: ['listening', 'idle-1', 'idle-2', 'idle-3'],
6
+ thinking: ['thinking', 'think-2'],
7
+ speaking: ['talk-1', 'talk-2', 'idle-1', 'listening'],
8
+ happy: ['happy'],
9
+ surprised: ['surprised'],
10
+ sorry: ['sorry'],
11
+ laugh: ['laugh'],
12
+ wave: ['wave'],
13
+ heart: ['heart'],
14
+ clap: ['clap'],
15
+ shy: ['shy'],
16
+ dance: ['dance'],
17
+ stretch: ['stretch'],
18
+ };
19
+ /** What of a sentence shows on her face as she says it, in the languages of Ta; the first that fits, sorrow first. */
20
+ const MOODS = [
21
+ ['sorry', /抱歉|对不起|不好意思|遗憾|可惜|失败了|出错|没做成|糟糕|對不起|ごめん|すみません|残念|\b(?:sorry|unfortunately|afraid|failed)\b/i],
22
+ ['laugh', /哈哈|嘿嘿|笑死|好好笑|太好笑|逗死|ハハ|笑える|\b(?:haha\w*|lol|hilarious|funny)\b/i],
23
+ ['surprised', /哇|天哪|天啊|真的吗|竟然|居然|没想到|わあ|まさか|\b(?:wow|really\?|no way|amazing|incredible)\b/i],
24
+ ['clap', /恭喜|太棒了|真棒|好厉害|太厉害|干得漂亮|好样的|太強|おめでとう|すごい|\b(?:congrat\w*|bravo|well done|awesome)\b/i],
25
+ ['heart', /爱你|喜欢你|比心|么么|谢谢你|感谢你|謝謝你|大好き|ありがとう|\b(?:love you|thank you|thanks)\b/i],
26
+ ['shy', /过奖|過獎|哪里哪里|害羞|不好意思啦|夸得|照れ|\b(?:flattered|you're too kind|blush\w*)\b/i],
27
+ [
28
+ 'wave',
29
+ /你好|您好|嗨|哈喽|早上好|下午好|晚上好|再见|拜拜|回头见|こんにちは|おはよう|こんばんは|またね|さようなら|\b(?:hello|hi|hey|bye|goodbye|see you)\b/i,
30
+ ],
31
+ ['happy', /太好了|好开心|开心|高兴|很棒|成功了|搞定|嬉しい|やった|\b(?:great|glad|yay|done!)\b/i],
32
+ ];
33
+ /** What she does once she has said a sentence of it. */
34
+ const SHOWS = [
35
+ ['dance', /跳舞|跳个舞|跳支舞|跳一段|跳给你看|跳一个|ダンス|踊|\bdanc(?:e|ing)\b/i],
36
+ ['stretch', /伸个懒腰|伸懒腰|活动一下|起来走走|ストレッチ|\bstretch\w*\b/i],
37
+ ];
38
+ const MOOD_KINDS = new Set(MOODS.map(([mood]) => mood));
39
+ /**
40
+ * Which clip the person of a video call plays (docs/design/ta-call.md 12), as the products of AI companions do: clips
41
+ * made beforehand of one person, each for a state, all beginning and ending on the same frame, so that one follows
42
+ * another without a seam at its end, and crosses into another at once as the state changes.
43
+ */
44
+ var FaceClips;
45
+ (function (FaceClips) {
46
+ /** The clip for the call as it is. */
47
+ function kind(phase, paused) {
48
+ if (paused) {
49
+ return 'listening';
50
+ }
51
+ return phase === 'thinking' ? 'thinking' : phase === 'speaking' ? 'speaking' : 'listening';
52
+ }
53
+ FaceClips.kind = kind;
54
+ /** The look of a sentence Ta says (its clip plays once as she says it); undefined for none in particular. */
55
+ function mood(words) {
56
+ var _a;
57
+ return words ? (_a = MOODS.find(([, test]) => test.test(words))) === null || _a === void 0 ? void 0 : _a[0] : undefined;
58
+ }
59
+ FaceClips.mood = mood;
60
+ function isMood(kind) {
61
+ return !!kind && MOOD_KINDS.has(kind);
62
+ }
63
+ FaceClips.isMood = isMood;
64
+ function isShow(kind) {
65
+ return kind === 'dance' || kind === 'stretch';
66
+ }
67
+ FaceClips.isShow = isShow;
68
+ /** What she does once she said a sentence (she dances when she says she will); undefined for nothing. */
69
+ function show(words) {
70
+ var _a;
71
+ return words ? (_a = SHOWS.find(([, test]) => test.test(words))) === null || _a === void 0 ? void 0 : _a[0] : undefined;
72
+ }
73
+ FaceClips.show = show;
74
+ /** The next clip of `kind`, at random but never the one just played: the same gestures do not come back in a row. */
75
+ function next(kind, last, random = Math.random) {
76
+ const clips = CLIPS[kind].filter(clip => clip !== last);
77
+ const from = clips.length ? clips : CLIPS[kind];
78
+ return from[Math.floor(random() * from.length) % from.length];
79
+ }
80
+ FaceClips.next = next;
81
+ /**
82
+ * The clip that begins at a second of a reading, after `last`: the look of the sentence heard then, once a sentence
83
+ * (`used`), else another gesture of speaking.
84
+ */
85
+ function at(reading, seconds, last, used) {
86
+ const piece = reading === null || reading === void 0 ? void 0 : reading.pieceAt(seconds);
87
+ const mood = piece === undefined ? undefined : FaceClips.mood(reading === null || reading === void 0 ? void 0 : reading.pieces[piece]);
88
+ if (mood && piece !== undefined && !used.has(piece)) {
89
+ used.add(piece);
90
+ return CLIPS[mood][0];
91
+ }
92
+ return next('speaking', last);
93
+ }
94
+ FaceClips.at = at;
95
+ })(FaceClips || (exports.FaceClips = FaceClips = {}));
96
+ //# sourceMappingURL=face-clips.js.map
@@ -0,0 +1,32 @@
1
+ /** A URL of the page's own, from the document a video call draws in (its window is about:blank). */
2
+ export declare function faceUrl(path: string, doc: Document): string;
3
+ /**
4
+ * The files of the person of a video call (faces/README.md), as they are now: their names stay the same from one Ta to
5
+ * the next while the files of the server are kept a year, so each is asked again once a page (a 304 when unchanged)
6
+ * and played from its copy in memory. A clip a cache kept from a Ta before would show another person than the one the
7
+ * mouth is drawn for. With where her face is in each frame (lips.json), and the frames of the clips without a mouth.
8
+ */
9
+ export declare class FaceFiles {
10
+ protected readonly base: string;
11
+ protected static current?: FaceFiles;
12
+ /** The URL each file plays from: its copy in memory, else its own. */
13
+ protected readonly urls: Map<string, string>;
14
+ protected faceBoxes: Record<string, number[][]>;
15
+ /** The frames of the clips no mouth is drawn on (lips.json `plain`). */
16
+ protected plainFrames: Record<string, number>;
17
+ loaded: boolean;
18
+ readonly ready: Promise<void>;
19
+ protected constructor(base: string);
20
+ /** The files of the page, loaded once. */
21
+ static of(doc: Document): FaceFiles;
22
+ static poster(doc: Document): string;
23
+ /** Where her face is (x1, y1, x2, y2) in each frame of a clip; undefined for a clip lips.json does not have. */
24
+ boxes(clip: string): readonly number[][] | undefined;
25
+ /** The frames of a clip; undefined for one lips.json does not have. */
26
+ frames(clip: string): number | undefined;
27
+ clip(name: string): string;
28
+ protected load(): Promise<void>;
29
+ /** The file as the server has it now. */
30
+ protected fresh(file: string): Promise<Response>;
31
+ }
32
+ //# sourceMappingURL=face-files.d.ts.map
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FaceFiles = void 0;
4
+ exports.faceUrl = faceUrl;
5
+ /** The picture shown until a clip plays (faces/README.md). */
6
+ const POSTER = 'faces/poster.jpg';
7
+ /** A URL of the page's own, from the document a video call draws in (its window is about:blank). */
8
+ function faceUrl(path, doc) {
9
+ return new URL(path, doc.baseURI === 'about:blank' ? document.baseURI : doc.baseURI).href;
10
+ }
11
+ /**
12
+ * The files of the person of a video call (faces/README.md), as they are now: their names stay the same from one Ta to
13
+ * the next while the files of the server are kept a year, so each is asked again once a page (a 304 when unchanged)
14
+ * and played from its copy in memory. A clip a cache kept from a Ta before would show another person than the one the
15
+ * mouth is drawn for. With where her face is in each frame (lips.json), and the frames of the clips without a mouth.
16
+ */
17
+ class FaceFiles {
18
+ constructor(base) {
19
+ this.base = base;
20
+ /** The URL each file plays from: its copy in memory, else its own. */
21
+ this.urls = new Map();
22
+ this.faceBoxes = {};
23
+ /** The frames of the clips no mouth is drawn on (lips.json `plain`). */
24
+ this.plainFrames = {};
25
+ this.loaded = false;
26
+ this.ready = this.load().finally(() => {
27
+ this.loaded = true;
28
+ });
29
+ }
30
+ /** The files of the page, loaded once. */
31
+ static of(doc) {
32
+ var _a;
33
+ const base = faceUrl('faces/', doc);
34
+ if (((_a = FaceFiles.current) === null || _a === void 0 ? void 0 : _a.base) !== base) {
35
+ FaceFiles.current = new FaceFiles(base);
36
+ }
37
+ return FaceFiles.current;
38
+ }
39
+ static poster(doc) {
40
+ var _a;
41
+ var _b;
42
+ return (_b = (_a = FaceFiles.current) === null || _a === void 0 ? void 0 : _a.urls.get('poster.jpg')) !== null && _b !== void 0 ? _b : faceUrl(POSTER, doc);
43
+ }
44
+ /** Where her face is (x1, y1, x2, y2) in each frame of a clip; undefined for a clip lips.json does not have. */
45
+ boxes(clip) {
46
+ return this.faceBoxes[clip];
47
+ }
48
+ /** The frames of a clip; undefined for one lips.json does not have. */
49
+ frames(clip) {
50
+ var _a;
51
+ var _b;
52
+ return (_b = (_a = this.faceBoxes[clip]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : this.plainFrames[clip];
53
+ }
54
+ clip(name) {
55
+ var _a;
56
+ const file = `${name}.mp4`;
57
+ return (_a = this.urls.get(file)) !== null && _a !== void 0 ? _a : new URL(file, this.base).href;
58
+ }
59
+ async load() {
60
+ var _a, _b;
61
+ const lips = await this.fresh('lips.json')
62
+ .then(response => response.json())
63
+ .catch(() => undefined);
64
+ this.faceBoxes = (_a = lips === null || lips === void 0 ? void 0 : lips.clips) !== null && _a !== void 0 ? _a : {};
65
+ this.plainFrames = (_b = lips === null || lips === void 0 ? void 0 : lips.plain) !== null && _b !== void 0 ? _b : {};
66
+ const files = ['poster.jpg', ...[...Object.keys(this.faceBoxes), ...Object.keys(this.plainFrames)].map(clip => `${clip}.mp4`)];
67
+ await Promise.all(files.map(file => this.fresh(file)
68
+ .then(response => response.blob())
69
+ .then(blob => this.urls.set(file, URL.createObjectURL(blob)))
70
+ .catch(() => undefined)));
71
+ }
72
+ /** The file as the server has it now. */
73
+ async fresh(file) {
74
+ const response = await fetch(new URL(file, this.base).href, { cache: 'no-cache' });
75
+ if (!response.ok) {
76
+ throw new Error(`${file}: ${response.status}`);
77
+ }
78
+ return response;
79
+ }
80
+ }
81
+ exports.FaceFiles = FaceFiles;
82
+ //# sourceMappingURL=face-files.js.map
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import type { VoiceCall } from '../assistant/voice-call';
3
+ import type { CallState } from '../assistant/voice-call-protocol';
4
+ /**
5
+ * A video call (docs/design/ta-call.md 12), as a messenger's: Ta as a person who speaks with the voice of the call,
6
+ * its mouth, face and hands moving with what it says, and the user's own camera in a corner once they turn it on
7
+ * (it begins off), which Ta then sees. On a phone it takes the whole screen while the user is on the call's
8
+ * conversation, and floats small elsewhere (or when minimized; a tap brings it back); in Ta Desktop it is a window of
9
+ * its own; in a browser on a computer, a panel.
10
+ */
11
+ export declare function VideoCallView({ call, state, title, here, onBack, onHangUp, }: {
12
+ call: VoiceCall;
13
+ state: CallState;
14
+ title: string;
15
+ /** The call's conversation is the one in front. */
16
+ here: boolean;
17
+ onBack(): void;
18
+ onHangUp(): void;
19
+ }): React.JSX.Element | null;
20
+ //# sourceMappingURL=video-call-view.d.ts.map
@@ -0,0 +1,250 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.VideoCallView = VideoCallView;
37
+ const lucide_react_1 = require("lucide-react");
38
+ const React = __importStar(require("react"));
39
+ const react_dom_1 = require("react-dom");
40
+ const call_scenes_1 = require("../assistant/call-scenes");
41
+ const call_screen_1 = require("../assistant/call-screen");
42
+ const icon_1 = require("../components/icon");
43
+ const loading_1 = require("../components/loading");
44
+ const ta_avatar_1 = require("../components/ta-avatar");
45
+ const device_1 = require("../device/device");
46
+ const use_t_1 = require("../i18n/use-t");
47
+ const desktop_1 = require("../util/desktop");
48
+ const call_camera_1 = require("./call-camera");
49
+ const call_window_1 = require("./call-window");
50
+ const video_face_1 = require("./video-face");
51
+ /** How far a finger or the mouse moves before the small window is dragged rather than tapped, in pixels. */
52
+ const DRAG_PX = 6;
53
+ /**
54
+ * A video call (docs/design/ta-call.md 12), as a messenger's: Ta as a person who speaks with the voice of the call,
55
+ * its mouth, face and hands moving with what it says, and the user's own camera in a corner once they turn it on
56
+ * (it begins off), which Ta then sees. On a phone it takes the whole screen while the user is on the call's
57
+ * conversation, and floats small elsewhere (or when minimized; a tap brings it back); in Ta Desktop it is a window of
58
+ * its own; in a browser on a computer, a panel.
59
+ */
60
+ function VideoCallView({ call, state, title, here, onBack, onHangUp, }) {
61
+ const handheld = (0, device_1.useDevice)(device => device.handheld);
62
+ const [minimized, setMinimized] = React.useState(false);
63
+ const [windowHost, setWindowHost] = React.useState(undefined);
64
+ const windowed = !handheld && call_window_1.CallWindow.can();
65
+ const camera = call_camera_1.CallCameras.of(call);
66
+ // Coming back to the call's conversation brings it back whole.
67
+ React.useEffect(() => {
68
+ if (here) {
69
+ setMinimized(false);
70
+ }
71
+ }, [here]);
72
+ // The camera stays off until the user turns it on; the call ending lets go of it.
73
+ React.useEffect(() => () => call_camera_1.CallCameras.end(call), [call]);
74
+ // Opened once a call, closed as it ends: what it is told as it opens is of its start.
75
+ const latest = React.useRef({ title, onHangUp });
76
+ latest.current = { title, onHangUp };
77
+ React.useEffect(() => {
78
+ var _a;
79
+ if (!windowed) {
80
+ return;
81
+ }
82
+ setWindowHost((_a = call_window_1.CallWindow.open(latest.current.title, () => latest.current.onHangUp())) !== null && _a !== void 0 ? _a : null);
83
+ return () => call_window_1.CallWindow.close();
84
+ }, [windowed]);
85
+ const shape = windowed && windowHost ? 'window' : minimized || (handheld && !here) ? 'mini' : handheld ? 'full' : 'panel';
86
+ const stage = (React.createElement(VideoStage, { call: call, state: state, camera: camera, shape: shape, title: title, handheld: handheld, onMinimize: () => setMinimized(true), onExpand: () => {
87
+ setMinimized(false);
88
+ if (!here) {
89
+ onBack();
90
+ }
91
+ }, onHangUp: onHangUp }));
92
+ if (windowed && windowHost === undefined) {
93
+ return null;
94
+ }
95
+ return shape === 'window' && windowHost ? (0, react_dom_1.createPortal)(stage, windowHost) : stage;
96
+ }
97
+ function useCamera(camera) {
98
+ React.useSyncExternalStore(listener => camera.subscribe(listener), () => { var _a; var _b; return `${camera.off}:${camera.denied}:${camera.facing}:${(_b = (_a = camera.stream) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : ''}`; });
99
+ return camera;
100
+ }
101
+ function VideoStage({ call, state, camera, shape, title, handheld, onMinimize, onExpand, onHangUp, }) {
102
+ var _a;
103
+ const t = (0, use_t_1.useT)();
104
+ useCamera(camera);
105
+ // Whoever answers knows whether the user's camera is on and how the call shows (CallScenes).
106
+ React.useEffect(() => call_scenes_1.CallScenes.show(call, { camera: !camera.off, view: shape }), [call, camera.off, shape]);
107
+ const mini = shape === 'mini';
108
+ const drag = useDrag(mini, onExpand);
109
+ const pin = useWindowPin(shape === 'window');
110
+ const phase = call_screen_1.CallScreen.phase(t, { phase: state.phase, paused: state.paused, heard: !!state.heard.trim() });
111
+ const words = state.phase === 'speaking' ? (_a = state.reading) === null || _a === void 0 ? void 0 : _a.pieces[state.reading.at] : state.phase === 'listening' ? state.heard.trim() || undefined : undefined;
112
+ const cut = !state.paused && state.phase === 'speaking';
113
+ return (React.createElement("div", { className: `ta-video-call ta-video-${shape} ta-video-${state.paused ? 'paused' : state.phase}`, role: "dialog", "aria-label": title, ...drag.props },
114
+ React.createElement(Person, { call: call, state: state, onTap: cut && !mini ? () => call.interrupt() : undefined }),
115
+ mini ? (React.createElement("span", { className: "ta-video-mini-phase" }, phase)) : (React.createElement(React.Fragment, null,
116
+ React.createElement("div", { className: "ta-video-top" },
117
+ shape !== 'window' && (React.createElement("button", { type: "button", className: "ta-video-round ta-video-minimize", "aria-label": t('ta.call.minimize'), title: t('ta.call.minimize'), onClick: onMinimize },
118
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.Minimize2, size: 18 }))),
119
+ React.createElement("div", { className: "ta-video-title" },
120
+ React.createElement("span", null, title),
121
+ React.createElement("small", null,
122
+ phase,
123
+ " \u00B7 ",
124
+ t('ta.call.aiMade'))),
125
+ pin && (React.createElement("button", { type: "button", className: `ta-video-round ta-video-pin${pin.pinned ? ' ta-on' : ''}`, "aria-pressed": pin.pinned, "aria-label": t(pin.pinned ? 'ta.call.unpin' : 'ta.call.pin'), title: t(pin.pinned ? 'ta.call.unpin' : 'ta.call.pin'), onClick: pin.toggle },
126
+ React.createElement(icon_1.Icon, { icon: pin.pinned ? lucide_react_1.Pin : lucide_react_1.PinOff, size: 18 })))),
127
+ React.createElement(SelfView, { camera: camera }),
128
+ words && React.createElement("div", { className: `ta-video-caption${state.phase === 'listening' ? ' ta-mine' : ''}` }, words),
129
+ React.createElement("div", { className: "ta-video-controls" },
130
+ React.createElement("button", { type: "button", className: `ta-video-round${camera.off ? ' ta-off' : ''}`, "aria-pressed": !camera.off, "aria-label": t(camera.denied ? 'ta.call.cameraDenied' : camera.off ? 'ta.call.cameraOn' : 'ta.call.cameraOff'), title: t(camera.denied ? 'ta.call.cameraDenied' : camera.off ? 'ta.call.cameraOn' : 'ta.call.cameraOff'), onClick: () => camera.toggle() },
131
+ React.createElement(icon_1.Icon, { icon: camera.off ? lucide_react_1.CameraOff : lucide_react_1.Camera, size: 22 })),
132
+ React.createElement("button", { type: "button", className: "ta-video-round ta-video-end", "aria-label": t('ta.call.hangUp'), title: t('ta.call.hangUp'), onClick: onHangUp },
133
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.PhoneOff, size: 26 })),
134
+ handheld ? (React.createElement("button", { type: "button", className: "ta-video-round", "aria-label": t('ta.call.flip'), title: t('ta.call.flip'), disabled: camera.off, onClick: () => camera.flip() },
135
+ React.createElement(icon_1.Icon, { icon: lucide_react_1.SwitchCamera, size: 22 }))) : (React.createElement("span", { className: "ta-video-round ta-video-spacer" })))))));
136
+ }
137
+ /**
138
+ * The pin of the window of a video call in Ta Desktop: whether it floats above every window, as the user chose the last
139
+ * time (the app keeps it), and the switch. None elsewhere, nor in an older Ta Desktop.
140
+ */
141
+ function useWindowPin(on) {
142
+ const pin = React.useMemo(() => (on ? desktop_1.DesktopUtil.callWindowPin() : undefined), [on]);
143
+ const [pinned, setPinned] = React.useState(undefined);
144
+ React.useEffect(() => {
145
+ let live = true;
146
+ pin === null || pin === void 0 ? void 0 : pin().then(now => live && setPinned(now)).catch(() => undefined);
147
+ return () => {
148
+ live = false;
149
+ };
150
+ }, [pin]);
151
+ if (!pin || pinned === undefined) {
152
+ return undefined;
153
+ }
154
+ return {
155
+ pinned,
156
+ toggle: () => {
157
+ const next = !pinned;
158
+ setPinned(next);
159
+ pin(next).then(setPinned, () => setPinned(!next));
160
+ },
161
+ };
162
+ }
163
+ /** What the user's camera shows, small in a corner, as one sees oneself in a video call; mirrored for the front camera. */
164
+ function SelfView({ camera }) {
165
+ const video = React.useRef(null);
166
+ const stream = camera.stream;
167
+ React.useEffect(() => {
168
+ var _a;
169
+ const element = video.current;
170
+ if (element && element.srcObject !== (stream !== null && stream !== void 0 ? stream : null)) {
171
+ element.srcObject = stream !== null && stream !== void 0 ? stream : null;
172
+ void ((_a = element.play) === null || _a === void 0 ? void 0 : _a.call(element).catch(() => undefined));
173
+ }
174
+ }, [stream]);
175
+ if (camera.off || !stream) {
176
+ return null;
177
+ }
178
+ return React.createElement("video", { ref: video, className: `ta-video-self${camera.facing === 'user' ? ' ta-mirror' : ''}`, autoPlay: true, muted: true, playsInline: true });
179
+ }
180
+ /** Ta as a person (VideoFace), its clips loaded as the call shows; the dinosaur in its place where they cannot play. */
181
+ function Person({ call, state, onTap }) {
182
+ const t = (0, use_t_1.useT)();
183
+ const [failed, setFailed] = React.useState(false);
184
+ const [ready, setReady] = React.useState(false);
185
+ return (React.createElement("div", { className: `ta-video-person${ready ? ' ta-ready' : ''}` },
186
+ !failed && React.createElement(video_face_1.VideoFace, { call: call, onReady: () => setReady(true), onFailed: () => setFailed(true) }),
187
+ onTap && React.createElement("button", { type: "button", className: "ta-video-tap", "aria-label": t('ta.call.interrupt'), title: t('ta.call.interrupt'), onClick: onTap }),
188
+ failed && React.createElement(ta_avatar_1.DinoFace, { mood: call_screen_1.CallScreen.mood(state), size: 200, talk: { level: () => call.level() }, fill: true, className: "ta-video-dino" }),
189
+ failed && React.createElement("span", { className: "ta-video-failed" }, t('ta.call.faceFailed')),
190
+ !ready && !failed && React.createElement(loading_1.Loading, { compact: true })));
191
+ }
192
+ /** The small window dragged about, keeping to the nearer side; a tap that does not drag brings the call back. */
193
+ function useDrag(on, tap) {
194
+ const [offset, setOffset] = React.useState(undefined);
195
+ const [side, setSide] = React.useState('right');
196
+ const [top, setTop] = React.useState(undefined);
197
+ const start = React.useRef(undefined);
198
+ if (!on) {
199
+ return { props: {} };
200
+ }
201
+ const props = {
202
+ style: {
203
+ ...(top === undefined ? {} : { top }),
204
+ ...(offset ? { transform: `translate3d(${offset.x}px, ${offset.y}px, 0)`, transition: 'none' } : {}),
205
+ },
206
+ 'data-side': side,
207
+ onPointerDown: (event) => {
208
+ var _a, _b;
209
+ start.current = { x: event.clientX, y: event.clientY, id: event.pointerId, moved: false };
210
+ (_b = (_a = event.currentTarget).setPointerCapture) === null || _b === void 0 ? void 0 : _b.call(_a, event.pointerId);
211
+ },
212
+ onPointerMove: (event) => {
213
+ const begun = start.current;
214
+ if (!begun || begun.id !== event.pointerId) {
215
+ return;
216
+ }
217
+ const x = event.clientX - begun.x;
218
+ const y = event.clientY - begun.y;
219
+ if (!begun.moved && Math.hypot(x, y) < DRAG_PX) {
220
+ return;
221
+ }
222
+ begun.moved = true;
223
+ setOffset({ x, y });
224
+ },
225
+ onPointerUp: (event) => {
226
+ var _a;
227
+ const begun = start.current;
228
+ start.current = undefined;
229
+ if (!begun || begun.id !== event.pointerId) {
230
+ return;
231
+ }
232
+ if (!begun.moved) {
233
+ tap();
234
+ return;
235
+ }
236
+ const element = event.currentTarget;
237
+ const rect = element.getBoundingClientRect();
238
+ const view = (_a = element.ownerDocument.defaultView) !== null && _a !== void 0 ? _a : window;
239
+ setSide(rect.left + rect.width / 2 < view.innerWidth / 2 ? 'left' : 'right');
240
+ setTop(Math.max(12, Math.min(view.innerHeight - rect.height - 12, rect.top)));
241
+ setOffset(undefined);
242
+ },
243
+ onPointerCancel: () => {
244
+ start.current = undefined;
245
+ setOffset(undefined);
246
+ },
247
+ };
248
+ return { props };
249
+ }
250
+ //# sourceMappingURL=video-call-view.js.map
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import type { VoiceCall } from '../assistant/voice-call';
3
+ /**
4
+ * The person of a video call: two layers of video, the one in front playing, the other taking over with a short fade
5
+ * when the clip changes. As Ta reads with a voice service, the clip is the one its ClipPlan has for that moment of the
6
+ * sound, and the mouth an extension draws for that moment is laid over it (MouthLayer); otherwise clips play by the
7
+ * state of the call.
8
+ */
9
+ export declare function VideoFace({ call, onReady, onFailed }: {
10
+ call: VoiceCall;
11
+ onReady(): void;
12
+ onFailed(): void;
13
+ }): React.JSX.Element;
14
+ //# sourceMappingURL=video-face.d.ts.map