@abraca/nuxt 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/README.md +84 -0
  2. package/dist/module.d.mts +201 -0
  3. package/dist/module.json +12 -0
  4. package/dist/module.mjs +170 -0
  5. package/dist/runtime/components/ACollaborationUsers.d.vue.ts +11 -0
  6. package/dist/runtime/components/ACollaborationUsers.vue +48 -0
  7. package/dist/runtime/components/ACollaborationUsers.vue.d.ts +11 -0
  8. package/dist/runtime/components/AColorPicker.d.vue.ts +13 -0
  9. package/dist/runtime/components/AColorPicker.vue +71 -0
  10. package/dist/runtime/components/AColorPicker.vue.d.ts +13 -0
  11. package/dist/runtime/components/ACommandPalette.d.vue.ts +13 -0
  12. package/dist/runtime/components/ACommandPalette.vue +31 -0
  13. package/dist/runtime/components/ACommandPalette.vue.d.ts +13 -0
  14. package/dist/runtime/components/AConnectionStatus.d.vue.ts +13 -0
  15. package/dist/runtime/components/AConnectionStatus.vue +50 -0
  16. package/dist/runtime/components/AConnectionStatus.vue.d.ts +13 -0
  17. package/dist/runtime/components/ADocTypeSelect.d.vue.ts +10 -0
  18. package/dist/runtime/components/ADocTypeSelect.vue +34 -0
  19. package/dist/runtime/components/ADocTypeSelect.vue.d.ts +10 -0
  20. package/dist/runtime/components/ADocumentTree.d.vue.ts +53 -0
  21. package/dist/runtime/components/ADocumentTree.vue +350 -0
  22. package/dist/runtime/components/ADocumentTree.vue.d.ts +53 -0
  23. package/dist/runtime/components/AEditor.d.vue.ts +60 -0
  24. package/dist/runtime/components/AEditor.vue +174 -0
  25. package/dist/runtime/components/AEditor.vue.d.ts +60 -0
  26. package/dist/runtime/components/AFloatingWindow.d.vue.ts +24 -0
  27. package/dist/runtime/components/AFloatingWindow.vue +232 -0
  28. package/dist/runtime/components/AFloatingWindow.vue.d.ts +24 -0
  29. package/dist/runtime/components/AIconPicker.d.vue.ts +13 -0
  30. package/dist/runtime/components/AIconPicker.vue +257 -0
  31. package/dist/runtime/components/AIconPicker.vue.d.ts +13 -0
  32. package/dist/runtime/components/ANodePanel.d.vue.ts +15 -0
  33. package/dist/runtime/components/ANodePanel.vue +541 -0
  34. package/dist/runtime/components/ANodePanel.vue.d.ts +15 -0
  35. package/dist/runtime/components/ANotifications.d.vue.ts +7 -0
  36. package/dist/runtime/components/ANotifications.vue +75 -0
  37. package/dist/runtime/components/ANotifications.vue.d.ts +7 -0
  38. package/dist/runtime/components/APermissionGuard.d.vue.ts +21 -0
  39. package/dist/runtime/components/APermissionGuard.vue +22 -0
  40. package/dist/runtime/components/APermissionGuard.vue.d.ts +21 -0
  41. package/dist/runtime/components/APresence.d.vue.ts +43 -0
  42. package/dist/runtime/components/APresence.vue +36 -0
  43. package/dist/runtime/components/APresence.vue.d.ts +43 -0
  44. package/dist/runtime/components/AProvider.d.vue.ts +27 -0
  45. package/dist/runtime/components/AProvider.vue +42 -0
  46. package/dist/runtime/components/AProvider.vue.d.ts +27 -0
  47. package/dist/runtime/components/ARoleBadge.d.vue.ts +11 -0
  48. package/dist/runtime/components/ARoleBadge.vue +29 -0
  49. package/dist/runtime/components/ARoleBadge.vue.d.ts +11 -0
  50. package/dist/runtime/components/AVoiceBar.d.vue.ts +13 -0
  51. package/dist/runtime/components/AVoiceBar.vue +379 -0
  52. package/dist/runtime/components/AVoiceBar.vue.d.ts +13 -0
  53. package/dist/runtime/components/AVoiceTile.d.vue.ts +10 -0
  54. package/dist/runtime/components/AVoiceTile.vue +48 -0
  55. package/dist/runtime/components/AVoiceTile.vue.d.ts +10 -0
  56. package/dist/runtime/components/AWindowLayer.d.vue.ts +3 -0
  57. package/dist/runtime/components/AWindowLayer.vue +17 -0
  58. package/dist/runtime/components/AWindowLayer.vue.d.ts +3 -0
  59. package/dist/runtime/components/aware/AArea.d.vue.ts +42 -0
  60. package/dist/runtime/components/aware/AArea.vue +45 -0
  61. package/dist/runtime/components/aware/AArea.vue.d.ts +42 -0
  62. package/dist/runtime/components/aware/AAvatar.d.vue.ts +25 -0
  63. package/dist/runtime/components/aware/AAvatar.vue +86 -0
  64. package/dist/runtime/components/aware/AAvatar.vue.d.ts +25 -0
  65. package/dist/runtime/components/aware/AButton.d.vue.ts +7 -0
  66. package/dist/runtime/components/aware/AButton.vue +39 -0
  67. package/dist/runtime/components/aware/AButton.vue.d.ts +7 -0
  68. package/dist/runtime/components/aware/ACursorLabel.d.vue.ts +12 -0
  69. package/dist/runtime/components/aware/ACursorLabel.vue +44 -0
  70. package/dist/runtime/components/aware/ACursorLabel.vue.d.ts +12 -0
  71. package/dist/runtime/components/aware/ADocBadge.d.vue.ts +11 -0
  72. package/dist/runtime/components/aware/ADocBadge.vue +27 -0
  73. package/dist/runtime/components/aware/ADocBadge.vue.d.ts +11 -0
  74. package/dist/runtime/components/aware/AFacepile.d.vue.ts +20 -0
  75. package/dist/runtime/components/aware/AFacepile.vue +92 -0
  76. package/dist/runtime/components/aware/AFacepile.vue.d.ts +20 -0
  77. package/dist/runtime/components/aware/AInput.d.vue.ts +7 -0
  78. package/dist/runtime/components/aware/AInput.vue +44 -0
  79. package/dist/runtime/components/aware/AInput.vue.d.ts +7 -0
  80. package/dist/runtime/components/aware/ASelect.d.vue.ts +7 -0
  81. package/dist/runtime/components/aware/ASelect.vue +51 -0
  82. package/dist/runtime/components/aware/ASelect.vue.d.ts +7 -0
  83. package/dist/runtime/components/aware/ATextarea.d.vue.ts +7 -0
  84. package/dist/runtime/components/aware/ATextarea.vue +44 -0
  85. package/dist/runtime/components/aware/ATextarea.vue.d.ts +7 -0
  86. package/dist/runtime/components/aware/AUserList.d.vue.ts +17 -0
  87. package/dist/runtime/components/aware/AUserList.vue +72 -0
  88. package/dist/runtime/components/aware/AUserList.vue.d.ts +17 -0
  89. package/dist/runtime/components/renderers/ACalendarRenderer.d.vue.ts +8 -0
  90. package/dist/runtime/components/renderers/ACalendarRenderer.vue +154 -0
  91. package/dist/runtime/components/renderers/ACalendarRenderer.vue.d.ts +8 -0
  92. package/dist/runtime/components/renderers/AGalleryRenderer.d.vue.ts +8 -0
  93. package/dist/runtime/components/renderers/AGalleryRenderer.vue +88 -0
  94. package/dist/runtime/components/renderers/AGalleryRenderer.vue.d.ts +8 -0
  95. package/dist/runtime/components/renderers/AKanbanRenderer.d.vue.ts +8 -0
  96. package/dist/runtime/components/renderers/AKanbanRenderer.vue +179 -0
  97. package/dist/runtime/components/renderers/AKanbanRenderer.vue.d.ts +8 -0
  98. package/dist/runtime/components/renderers/AOutlineRenderer.d.vue.ts +8 -0
  99. package/dist/runtime/components/renderers/AOutlineRenderer.vue +180 -0
  100. package/dist/runtime/components/renderers/AOutlineRenderer.vue.d.ts +8 -0
  101. package/dist/runtime/components/renderers/ATableRenderer.d.vue.ts +8 -0
  102. package/dist/runtime/components/renderers/ATableRenderer.vue +191 -0
  103. package/dist/runtime/components/renderers/ATableRenderer.vue.d.ts +8 -0
  104. package/dist/runtime/composables/useAAField.d.ts +42 -0
  105. package/dist/runtime/composables/useAAField.js +62 -0
  106. package/dist/runtime/composables/useAbraLocale.d.ts +14 -0
  107. package/dist/runtime/composables/useAbraLocale.js +11 -0
  108. package/dist/runtime/composables/useAbracadabra.d.ts +11 -0
  109. package/dist/runtime/composables/useAbracadabra.js +3 -0
  110. package/dist/runtime/composables/useAbracadabraAuth.d.ts +23 -0
  111. package/dist/runtime/composables/useAbracadabraAuth.js +22 -0
  112. package/dist/runtime/composables/useAwareness.d.ts +22 -0
  113. package/dist/runtime/composables/useAwareness.js +48 -0
  114. package/dist/runtime/composables/useAwarenessPeers.d.ts +34 -0
  115. package/dist/runtime/composables/useAwarenessPeers.js +33 -0
  116. package/dist/runtime/composables/useBackgroundSync.d.ts +37 -0
  117. package/dist/runtime/composables/useBackgroundSync.js +73 -0
  118. package/dist/runtime/composables/useChat.d.ts +65 -0
  119. package/dist/runtime/composables/useChat.js +210 -0
  120. package/dist/runtime/composables/useChatUsers.d.ts +21 -0
  121. package/dist/runtime/composables/useChatUsers.js +39 -0
  122. package/dist/runtime/composables/useChildTree.d.ts +119 -0
  123. package/dist/runtime/composables/useChildTree.js +100 -0
  124. package/dist/runtime/composables/useCommandPalette.d.ts +58 -0
  125. package/dist/runtime/composables/useCommandPalette.js +94 -0
  126. package/dist/runtime/composables/useConnectionStatus.d.ts +17 -0
  127. package/dist/runtime/composables/useConnectionStatus.js +37 -0
  128. package/dist/runtime/composables/useDashboard.d.ts +3 -0
  129. package/dist/runtime/composables/useDashboard.js +23 -0
  130. package/dist/runtime/composables/useDocExport.d.ts +5 -0
  131. package/dist/runtime/composables/useDocExport.js +256 -0
  132. package/dist/runtime/composables/useDocImport.d.ts +10 -0
  133. package/dist/runtime/composables/useDocImport.js +227 -0
  134. package/dist/runtime/composables/useDocJump.d.ts +29 -0
  135. package/dist/runtime/composables/useDocJump.js +17 -0
  136. package/dist/runtime/composables/useDocumentPermissions.d.ts +20 -0
  137. package/dist/runtime/composables/useDocumentPermissions.js +33 -0
  138. package/dist/runtime/composables/useEditor.d.ts +45 -0
  139. package/dist/runtime/composables/useEditor.js +121 -0
  140. package/dist/runtime/composables/useEditorDragHandle.d.ts +26 -0
  141. package/dist/runtime/composables/useEditorDragHandle.js +219 -0
  142. package/dist/runtime/composables/useEditorMentions.d.ts +28 -0
  143. package/dist/runtime/composables/useEditorMentions.js +40 -0
  144. package/dist/runtime/composables/useEditorSuggestions.d.ts +18 -0
  145. package/dist/runtime/composables/useEditorSuggestions.js +45 -0
  146. package/dist/runtime/composables/useEditorToolbar.d.ts +22 -0
  147. package/dist/runtime/composables/useEditorToolbar.js +60 -0
  148. package/dist/runtime/composables/useFileBlobStore.d.ts +15 -0
  149. package/dist/runtime/composables/useFileBlobStore.js +22 -0
  150. package/dist/runtime/composables/useFileIndex.d.ts +20 -0
  151. package/dist/runtime/composables/useFileIndex.js +69 -0
  152. package/dist/runtime/composables/useFollowUser.d.ts +5 -0
  153. package/dist/runtime/composables/useFollowUser.js +40 -0
  154. package/dist/runtime/composables/useNotifications.d.ts +82 -0
  155. package/dist/runtime/composables/useNotifications.js +171 -0
  156. package/dist/runtime/composables/useOfflineUploadQueue.d.ts +90 -0
  157. package/dist/runtime/composables/useOfflineUploadQueue.js +33 -0
  158. package/dist/runtime/composables/usePasskeyAccounts.d.ts +32 -0
  159. package/dist/runtime/composables/usePasskeyAccounts.js +46 -0
  160. package/dist/runtime/composables/usePluginRegistry.d.ts +6 -0
  161. package/dist/runtime/composables/usePluginRegistry.js +3 -0
  162. package/dist/runtime/composables/useRendererBase.d.ts +186 -0
  163. package/dist/runtime/composables/useRendererBase.js +46 -0
  164. package/dist/runtime/composables/useSearchIndex.d.ts +20 -0
  165. package/dist/runtime/composables/useSearchIndex.js +104 -0
  166. package/dist/runtime/composables/useTrash.d.ts +50 -0
  167. package/dist/runtime/composables/useTrash.js +127 -0
  168. package/dist/runtime/composables/useVoice.d.ts +51 -0
  169. package/dist/runtime/composables/useVoice.js +220 -0
  170. package/dist/runtime/composables/useWindowManager.d.ts +122 -0
  171. package/dist/runtime/composables/useWindowManager.js +141 -0
  172. package/dist/runtime/composables/useYDoc.d.ts +142 -0
  173. package/dist/runtime/composables/useYDoc.js +172 -0
  174. package/dist/runtime/extensions/accordion.d.ts +3 -0
  175. package/dist/runtime/extensions/accordion.js +49 -0
  176. package/dist/runtime/extensions/badge.d.ts +2 -0
  177. package/dist/runtime/extensions/badge.js +39 -0
  178. package/dist/runtime/extensions/callout.d.ts +2 -0
  179. package/dist/runtime/extensions/callout.js +28 -0
  180. package/dist/runtime/extensions/card.d.ts +3 -0
  181. package/dist/runtime/extensions/card.js +53 -0
  182. package/dist/runtime/extensions/code-collapse.d.ts +2 -0
  183. package/dist/runtime/extensions/code-collapse.js +32 -0
  184. package/dist/runtime/extensions/code-group.d.ts +2 -0
  185. package/dist/runtime/extensions/code-group.js +17 -0
  186. package/dist/runtime/extensions/collapsible.d.ts +2 -0
  187. package/dist/runtime/extensions/collapsible.js +35 -0
  188. package/dist/runtime/extensions/document-header.d.ts +11 -0
  189. package/dist/runtime/extensions/document-header.js +82 -0
  190. package/dist/runtime/extensions/document-meta.d.ts +20 -0
  191. package/dist/runtime/extensions/document-meta.js +121 -0
  192. package/dist/runtime/extensions/document.d.ts +6 -0
  193. package/dist/runtime/extensions/document.js +6 -0
  194. package/dist/runtime/extensions/file-block.d.ts +15 -0
  195. package/dist/runtime/extensions/file-block.js +34 -0
  196. package/dist/runtime/extensions/file-drop.d.ts +6 -0
  197. package/dist/runtime/extensions/file-drop.js +65 -0
  198. package/dist/runtime/extensions/kbd.d.ts +2 -0
  199. package/dist/runtime/extensions/kbd.js +33 -0
  200. package/dist/runtime/extensions/prose-icon.d.ts +2 -0
  201. package/dist/runtime/extensions/prose-icon.js +33 -0
  202. package/dist/runtime/extensions/search-highlight.d.ts +10 -0
  203. package/dist/runtime/extensions/search-highlight.js +129 -0
  204. package/dist/runtime/extensions/steps.d.ts +2 -0
  205. package/dist/runtime/extensions/steps.js +32 -0
  206. package/dist/runtime/extensions/tabs.d.ts +3 -0
  207. package/dist/runtime/extensions/tabs.js +49 -0
  208. package/dist/runtime/extensions/views/AccordionItemView.d.vue.ts +4 -0
  209. package/dist/runtime/extensions/views/AccordionItemView.vue +41 -0
  210. package/dist/runtime/extensions/views/AccordionItemView.vue.d.ts +4 -0
  211. package/dist/runtime/extensions/views/AccordionView.d.vue.ts +4 -0
  212. package/dist/runtime/extensions/views/AccordionView.vue +22 -0
  213. package/dist/runtime/extensions/views/AccordionView.vue.d.ts +4 -0
  214. package/dist/runtime/extensions/views/BadgeView.d.vue.ts +4 -0
  215. package/dist/runtime/extensions/views/BadgeView.vue +23 -0
  216. package/dist/runtime/extensions/views/BadgeView.vue.d.ts +4 -0
  217. package/dist/runtime/extensions/views/CalloutView.d.vue.ts +4 -0
  218. package/dist/runtime/extensions/views/CalloutView.vue +43 -0
  219. package/dist/runtime/extensions/views/CalloutView.vue.d.ts +4 -0
  220. package/dist/runtime/extensions/views/CardGroupView.d.vue.ts +4 -0
  221. package/dist/runtime/extensions/views/CardGroupView.vue +22 -0
  222. package/dist/runtime/extensions/views/CardGroupView.vue.d.ts +4 -0
  223. package/dist/runtime/extensions/views/CardView.d.vue.ts +4 -0
  224. package/dist/runtime/extensions/views/CardView.vue +28 -0
  225. package/dist/runtime/extensions/views/CardView.vue.d.ts +4 -0
  226. package/dist/runtime/extensions/views/CodeCollapseView.d.vue.ts +4 -0
  227. package/dist/runtime/extensions/views/CodeCollapseView.vue +45 -0
  228. package/dist/runtime/extensions/views/CodeCollapseView.vue.d.ts +4 -0
  229. package/dist/runtime/extensions/views/CodeGroupView.d.vue.ts +4 -0
  230. package/dist/runtime/extensions/views/CodeGroupView.vue +53 -0
  231. package/dist/runtime/extensions/views/CodeGroupView.vue.d.ts +4 -0
  232. package/dist/runtime/extensions/views/CollapsibleView.d.vue.ts +4 -0
  233. package/dist/runtime/extensions/views/CollapsibleView.vue +42 -0
  234. package/dist/runtime/extensions/views/CollapsibleView.vue.d.ts +4 -0
  235. package/dist/runtime/extensions/views/FileNodeView.d.vue.ts +4 -0
  236. package/dist/runtime/extensions/views/FileNodeView.vue +140 -0
  237. package/dist/runtime/extensions/views/FileNodeView.vue.d.ts +4 -0
  238. package/dist/runtime/extensions/views/KbdView.d.vue.ts +4 -0
  239. package/dist/runtime/extensions/views/KbdView.vue +23 -0
  240. package/dist/runtime/extensions/views/KbdView.vue.d.ts +4 -0
  241. package/dist/runtime/extensions/views/ProseIconView.d.vue.ts +4 -0
  242. package/dist/runtime/extensions/views/ProseIconView.vue +23 -0
  243. package/dist/runtime/extensions/views/ProseIconView.vue.d.ts +4 -0
  244. package/dist/runtime/extensions/views/StepsView.d.vue.ts +4 -0
  245. package/dist/runtime/extensions/views/StepsView.vue +32 -0
  246. package/dist/runtime/extensions/views/StepsView.vue.d.ts +4 -0
  247. package/dist/runtime/extensions/views/TabsItemView.d.vue.ts +4 -0
  248. package/dist/runtime/extensions/views/TabsItemView.vue +22 -0
  249. package/dist/runtime/extensions/views/TabsItemView.vue.d.ts +4 -0
  250. package/dist/runtime/extensions/views/TabsView.d.vue.ts +4 -0
  251. package/dist/runtime/extensions/views/TabsView.vue +56 -0
  252. package/dist/runtime/extensions/views/TabsView.vue.d.ts +4 -0
  253. package/dist/runtime/locale.d.ts +134 -0
  254. package/dist/runtime/locale.js +119 -0
  255. package/dist/runtime/middleware/abracadabra-auth.d.ts +11 -0
  256. package/dist/runtime/middleware/abracadabra-auth.js +9 -0
  257. package/dist/runtime/plugin-abracadabra.client.d.ts +7 -0
  258. package/dist/runtime/plugin-abracadabra.client.js +898 -0
  259. package/dist/runtime/plugin-abracadabra.server.d.ts +2 -0
  260. package/dist/runtime/plugin-abracadabra.server.js +71 -0
  261. package/dist/runtime/plugin-registry.d.ts +34 -0
  262. package/dist/runtime/plugin-registry.js +83 -0
  263. package/dist/runtime/plugin-shared-globals.client.d.ts +2 -0
  264. package/dist/runtime/plugin-shared-globals.client.js +20 -0
  265. package/dist/runtime/plugins/core.plugin.d.ts +12 -0
  266. package/dist/runtime/plugins/core.plugin.js +179 -0
  267. package/dist/runtime/server/api/_abracadabra/render/[docId].get.d.ts +18 -0
  268. package/dist/runtime/server/api/_abracadabra/render/[docId].get.js +51 -0
  269. package/dist/runtime/server/api/_abracadabra/spaces.get.d.ts +11 -0
  270. package/dist/runtime/server/api/_abracadabra/spaces.get.js +16 -0
  271. package/dist/runtime/server/plugins/abracadabra-service.d.ts +2 -0
  272. package/dist/runtime/server/plugins/abracadabra-service.js +116 -0
  273. package/dist/runtime/server/runners/doc-tree-cache.d.ts +11 -0
  274. package/dist/runtime/server/runners/doc-tree-cache.js +65 -0
  275. package/dist/runtime/server/tsconfig.json +3 -0
  276. package/dist/runtime/server/utils/docCache.d.ts +25 -0
  277. package/dist/runtime/server/utils/docCache.js +131 -0
  278. package/dist/runtime/server/utils/serverRunner.d.ts +28 -0
  279. package/dist/runtime/server/utils/serverRunner.js +58 -0
  280. package/dist/runtime/types.d.ts +444 -0
  281. package/dist/runtime/types.js +93 -0
  282. package/dist/runtime/utils/VoiceClient.d.ts +94 -0
  283. package/dist/runtime/utils/VoiceClient.js +599 -0
  284. package/dist/runtime/utils/avatarStyle.d.ts +15 -0
  285. package/dist/runtime/utils/avatarStyle.js +20 -0
  286. package/dist/runtime/utils/colorPalettes.d.ts +13 -0
  287. package/dist/runtime/utils/colorPalettes.js +49 -0
  288. package/dist/runtime/utils/docTypes.d.ts +129 -0
  289. package/dist/runtime/utils/docTypes.js +116 -0
  290. package/dist/runtime/utils/markdownToYjs.d.ts +23 -0
  291. package/dist/runtime/utils/markdownToYjs.js +440 -0
  292. package/dist/runtime/utils/metaFieldDefinitions.d.ts +7 -0
  293. package/dist/runtime/utils/metaFieldDefinitions.js +182 -0
  294. package/dist/runtime/utils/voiceErrors.d.ts +33 -0
  295. package/dist/runtime/utils/voiceErrors.js +54 -0
  296. package/dist/runtime/utils/yjsConvert.d.ts +14 -0
  297. package/dist/runtime/utils/yjsConvert.js +331 -0
  298. package/dist/types.d.mts +13 -0
  299. package/package.json +100 -0
@@ -0,0 +1,599 @@
1
+ import { createNanoEvents } from "nanoevents";
2
+ import { VoiceErrorCode, createVoiceError } from "./voiceErrors.js";
3
+ const ICE_SERVERS = [
4
+ { urls: "stun:stun.l.google.com:19302" },
5
+ { urls: "stun:stun1.l.google.com:19302" }
6
+ ];
7
+ function computeRms(buf) {
8
+ let sum = 0;
9
+ for (let i = 0; i < buf.length; i++) sum += buf[i] * buf[i];
10
+ return Math.sqrt(sum / buf.length) / 255;
11
+ }
12
+ export class VoiceClient {
13
+ constructor(url) {
14
+ this.url = url;
15
+ }
16
+ ws = null;
17
+ audioCtx = null;
18
+ _masterVolume = 1;
19
+ localStream = null;
20
+ _localVideoStream = null;
21
+ _localScreenStream = null;
22
+ localAudioTimer = null;
23
+ peerConnections = /* @__PURE__ */ new Map();
24
+ peerAudio = /* @__PURE__ */ new Map();
25
+ peers = /* @__PURE__ */ new Map();
26
+ emitter = createNanoEvents();
27
+ myPeerId = null;
28
+ _muted = false;
29
+ _videoEnabled = false;
30
+ _screenEnabled = false;
31
+ _profile = null;
32
+ _status = "idle";
33
+ /** Serialises async message handling so messages never run concurrently. */
34
+ _msgQueue = Promise.resolve();
35
+ on(event, handler) {
36
+ return this.emitter.on(event, handler);
37
+ }
38
+ get status() {
39
+ return this._status;
40
+ }
41
+ get isMuted() {
42
+ return this._muted;
43
+ }
44
+ get videoEnabled() {
45
+ return this._videoEnabled;
46
+ }
47
+ get screenEnabled() {
48
+ return this._screenEnabled;
49
+ }
50
+ get localVideoStream() {
51
+ return this._localVideoStream;
52
+ }
53
+ get localScreenStream() {
54
+ return this._localScreenStream;
55
+ }
56
+ setStatus(s) {
57
+ this._status = s;
58
+ this.emitter.emit("statusChange", s);
59
+ }
60
+ send(msg) {
61
+ if (this.ws?.readyState === WebSocket.OPEN) {
62
+ this.ws.send(JSON.stringify(msg));
63
+ }
64
+ }
65
+ async connect() {
66
+ if (this._status === "connecting" || this._status === "connected") return;
67
+ if (typeof window !== "undefined" && !window.isSecureContext) {
68
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.INSECURE_CONTEXT));
69
+ return;
70
+ }
71
+ this.setStatus("connecting");
72
+ try {
73
+ this.localStream = await navigator.mediaDevices.getUserMedia({
74
+ audio: true,
75
+ video: false
76
+ });
77
+ } catch (e) {
78
+ const name = e?.name ?? "";
79
+ const code = name === "NotAllowedError" || name === "PermissionDeniedError" ? VoiceErrorCode.MICROPHONE_PERMISSION_DENIED : name === "NotFoundError" ? VoiceErrorCode.MICROPHONE_NOT_FOUND : VoiceErrorCode.MEDIA_GENERIC;
80
+ this.emitter.emit("error", createVoiceError(code, e?.message));
81
+ this.setStatus("disconnected");
82
+ return;
83
+ }
84
+ this.audioCtx = new AudioContext();
85
+ if (this.audioCtx.state === "suspended") {
86
+ await this.audioCtx.resume();
87
+ }
88
+ const localSource = this.audioCtx.createMediaStreamSource(this.localStream);
89
+ const localAnalyser = this.audioCtx.createAnalyser();
90
+ localAnalyser.fftSize = 256;
91
+ localSource.connect(localAnalyser);
92
+ const localBuf = new Uint8Array(localAnalyser.frequencyBinCount);
93
+ this.localAudioTimer = setInterval(() => {
94
+ localAnalyser.getByteFrequencyData(localBuf);
95
+ this.emitter.emit("localAudioLevel", computeRms(localBuf));
96
+ }, 100);
97
+ try {
98
+ this.ws = new WebSocket(this.url);
99
+ } catch (e) {
100
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.CONNECT_FAILED, e?.message));
101
+ this.setStatus("disconnected");
102
+ return;
103
+ }
104
+ this.ws.addEventListener("message", (ev) => {
105
+ let msg;
106
+ try {
107
+ msg = JSON.parse(ev.data);
108
+ } catch {
109
+ return;
110
+ }
111
+ this._msgQueue = this._msgQueue.then(() => this.handleMessage(msg)).catch((err) => {
112
+ this.emitter.emit(
113
+ "error",
114
+ createVoiceError(VoiceErrorCode.UNKNOWN, String(err?.message ?? err))
115
+ );
116
+ });
117
+ });
118
+ this.ws.addEventListener("error", () => {
119
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.WEBSOCKET_ERROR));
120
+ });
121
+ this.ws.addEventListener("close", () => {
122
+ if (this._status === "connected" || this._status === "connecting") {
123
+ this.setStatus("disconnected");
124
+ }
125
+ });
126
+ }
127
+ async handleMessage(msg) {
128
+ switch (msg.type) {
129
+ case "welcome": {
130
+ this.myPeerId = msg.peer_id;
131
+ this.setStatus("connected");
132
+ if (this._profile) {
133
+ this.send({ type: "profile", name: this._profile.name, color: this._profile.color });
134
+ }
135
+ for (const info of msg.peers ?? []) {
136
+ const peer = this.addPeer(info.peer_id, info.user_id, info.muted);
137
+ if (info.video) peer.remoteVideo = true;
138
+ if (info.screen) peer.remoteScreen = true;
139
+ if (info.name) peer.displayName = info.name;
140
+ if (info.color) peer.color = info.color;
141
+ this.emitter.emit("peerJoined", peer);
142
+ await this.initiateOffer(info.peer_id);
143
+ }
144
+ break;
145
+ }
146
+ case "joined": {
147
+ const peer = this.addPeer(msg.peer_id, msg.user_id, msg.muted ?? false);
148
+ if (msg.video) peer.remoteVideo = true;
149
+ if (msg.screen) peer.remoteScreen = true;
150
+ if (msg.name) peer.displayName = msg.name;
151
+ if (msg.color) peer.color = msg.color;
152
+ this.emitter.emit("peerJoined", peer);
153
+ break;
154
+ }
155
+ case "left": {
156
+ const peerId = msg.peer_id;
157
+ this.emitter.emit("peerVideoStream", peerId, null, "camera");
158
+ this.emitter.emit("peerVideoStream", peerId, null, "screen");
159
+ this.removePeer(peerId);
160
+ this.emitter.emit("peerLeft", peerId);
161
+ break;
162
+ }
163
+ case "offer": {
164
+ await this.handleOffer(msg.from, msg.sdp);
165
+ break;
166
+ }
167
+ case "answer": {
168
+ const pc = this.peerConnections.get(msg.from);
169
+ if (pc) {
170
+ try {
171
+ await pc.setRemoteDescription(
172
+ new RTCSessionDescription({ type: "answer", sdp: msg.sdp })
173
+ );
174
+ } catch (e) {
175
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.ANSWER_FAILED, e?.message));
176
+ }
177
+ }
178
+ break;
179
+ }
180
+ case "ice": {
181
+ const pc = this.peerConnections.get(msg.from);
182
+ if (pc && msg.candidate) {
183
+ try {
184
+ await pc.addIceCandidate(new RTCIceCandidate(JSON.parse(msg.candidate)));
185
+ } catch (e) {
186
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.ICE_FAILED, e?.message));
187
+ }
188
+ }
189
+ break;
190
+ }
191
+ case "mute": {
192
+ const peer = this.peers.get(msg.peer_id);
193
+ if (peer) {
194
+ peer.remoteMuted = msg.muted;
195
+ this.emitter.emit("remoteMute", msg.peer_id, msg.muted);
196
+ }
197
+ break;
198
+ }
199
+ case "media-state": {
200
+ const peer = this.peers.get(msg.peer_id);
201
+ if (peer) {
202
+ peer.remoteVideo = msg.video;
203
+ peer.remoteScreen = msg.screen;
204
+ this.emitter.emit("peerMediaState", msg.peer_id, msg.video, msg.screen);
205
+ }
206
+ break;
207
+ }
208
+ case "profile": {
209
+ const peer = this.peers.get(msg.peer_id);
210
+ if (peer) {
211
+ peer.displayName = msg.name;
212
+ peer.color = msg.color;
213
+ this.emitter.emit("peerProfile", msg.peer_id, msg.name, msg.color);
214
+ }
215
+ break;
216
+ }
217
+ case "ping": {
218
+ this.send({ type: "pong" });
219
+ break;
220
+ }
221
+ case "error": {
222
+ const code = msg.code === "room_full" ? VoiceErrorCode.ROOM_FULL : msg.code === "forbidden" ? VoiceErrorCode.ROOM_FORBIDDEN : VoiceErrorCode.UNKNOWN;
223
+ this.emitter.emit("error", createVoiceError(code, msg.message));
224
+ break;
225
+ }
226
+ }
227
+ }
228
+ addPeer(peerId, userId, remoteMuted) {
229
+ const peer = {
230
+ id: peerId,
231
+ userId,
232
+ stream: null,
233
+ videoStream: null,
234
+ screenStream: null,
235
+ remoteMuted,
236
+ localMuted: false,
237
+ audioLevel: 0,
238
+ remoteVideo: false,
239
+ remoteScreen: false,
240
+ displayName: null,
241
+ color: null
242
+ };
243
+ this.peers.set(peerId, peer);
244
+ return peer;
245
+ }
246
+ removePeer(peerId) {
247
+ this.closePeerConnection(peerId);
248
+ const pa = this.peerAudio.get(peerId);
249
+ if (pa) {
250
+ clearInterval(pa.timer);
251
+ pa.audio.pause();
252
+ pa.audio.srcObject = null;
253
+ pa.source?.disconnect();
254
+ pa.analyser?.disconnect();
255
+ this.peerAudio.delete(peerId);
256
+ }
257
+ this.peers.delete(peerId);
258
+ }
259
+ wirePcEvents(pc, peerId) {
260
+ pc.onicecandidate = (e) => {
261
+ if (e.candidate) {
262
+ this.send({ type: "ice", to: peerId, candidate: JSON.stringify(e.candidate) });
263
+ }
264
+ };
265
+ pc.onconnectionstatechange = () => {
266
+ if (pc.connectionState === "failed") {
267
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.PEER_CONNECTION_FAILED, peerId));
268
+ }
269
+ };
270
+ pc.oniceconnectionstatechange = () => {
271
+ if (pc.iceConnectionState === "failed") {
272
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.ICE_FAILED, `ICE negotiation failed for peer ${peerId}`));
273
+ }
274
+ };
275
+ pc.ontrack = (e) => {
276
+ const peer = this.peers.get(peerId);
277
+ if (!peer) return;
278
+ const transceiver = e.transceiver;
279
+ const transceivers = pc.getTransceivers();
280
+ const idx = transceivers.indexOf(transceiver);
281
+ if (idx === 0) {
282
+ const audioStream = e.streams[0] ?? new MediaStream([e.track]);
283
+ peer.stream = audioStream;
284
+ this.emitter.emit("peerStream", peer);
285
+ this.setupPeerAudio(peerId, audioStream);
286
+ } else if (idx === 1) {
287
+ const videoStream = new MediaStream([e.track]);
288
+ peer.videoStream = videoStream;
289
+ this.emitter.emit("peerVideoStream", peerId, videoStream, "camera");
290
+ } else if (idx === 2) {
291
+ const screenStream = new MediaStream([e.track]);
292
+ peer.screenStream = screenStream;
293
+ this.emitter.emit("peerVideoStream", peerId, screenStream, "screen");
294
+ }
295
+ };
296
+ }
297
+ closePeerConnection(peerId) {
298
+ const existing = this.peerConnections.get(peerId);
299
+ if (existing) {
300
+ existing.ontrack = null;
301
+ existing.onicecandidate = null;
302
+ existing.onconnectionstatechange = null;
303
+ existing.oniceconnectionstatechange = null;
304
+ existing.close();
305
+ this.peerConnections.delete(peerId);
306
+ }
307
+ }
308
+ /**
309
+ * Create a new PC as the offerer — pre-creates the 3-transceiver layout
310
+ * (audio, camera video, screen video) so the offer SDP defines the m-line order.
311
+ */
312
+ createPeerConnectionForOffer(peerId) {
313
+ this.closePeerConnection(peerId);
314
+ const pc = new RTCPeerConnection({ iceServers: ICE_SERVERS });
315
+ this.peerConnections.set(peerId, pc);
316
+ const audioTrack = this.localStream?.getAudioTracks()[0] ?? null;
317
+ if (audioTrack) {
318
+ pc.addTransceiver(audioTrack, { direction: "sendrecv", streams: [this.localStream] });
319
+ } else {
320
+ pc.addTransceiver("audio", { direction: "recvonly" });
321
+ }
322
+ const cameraTrack = this._localVideoStream?.getVideoTracks()[0] ?? null;
323
+ if (cameraTrack) {
324
+ pc.addTransceiver(cameraTrack, { direction: "sendrecv", streams: [this._localVideoStream] });
325
+ } else {
326
+ pc.addTransceiver("video", { direction: "recvonly" });
327
+ }
328
+ const screenTrack = this._localScreenStream?.getVideoTracks()[0] ?? null;
329
+ if (screenTrack) {
330
+ pc.addTransceiver(screenTrack, { direction: "sendrecv", streams: [this._localScreenStream] });
331
+ } else {
332
+ pc.addTransceiver("video", { direction: "recvonly" });
333
+ }
334
+ this.wirePcEvents(pc, peerId);
335
+ return pc;
336
+ }
337
+ /**
338
+ * Create a new PC as the answerer — does NOT pre-create transceivers.
339
+ * `setRemoteDescription(offer)` will create them to match the offer's m-lines.
340
+ */
341
+ createPeerConnectionForAnswer(peerId) {
342
+ this.closePeerConnection(peerId);
343
+ const pc = new RTCPeerConnection({ iceServers: ICE_SERVERS });
344
+ this.peerConnections.set(peerId, pc);
345
+ this.wirePcEvents(pc, peerId);
346
+ return pc;
347
+ }
348
+ attachLocalTracksToAnswer(pc) {
349
+ const transceivers = pc.getTransceivers();
350
+ const audioTrack = this.localStream?.getAudioTracks()[0] ?? null;
351
+ if (transceivers[0] && audioTrack) {
352
+ transceivers[0].sender.replaceTrack(audioTrack);
353
+ transceivers[0].direction = "sendrecv";
354
+ }
355
+ const cameraTrack = this._localVideoStream?.getVideoTracks()[0] ?? null;
356
+ if (transceivers[1] && cameraTrack) {
357
+ transceivers[1].sender.replaceTrack(cameraTrack);
358
+ transceivers[1].direction = "sendrecv";
359
+ }
360
+ const screenTrack = this._localScreenStream?.getVideoTracks()[0] ?? null;
361
+ if (transceivers[2] && screenTrack) {
362
+ transceivers[2].sender.replaceTrack(screenTrack);
363
+ transceivers[2].direction = "sendrecv";
364
+ }
365
+ }
366
+ setupPeerAudio(peerId, stream) {
367
+ const old = this.peerAudio.get(peerId);
368
+ if (old) {
369
+ clearInterval(old.timer);
370
+ old.audio.pause();
371
+ old.audio.srcObject = null;
372
+ old.source?.disconnect();
373
+ old.analyser?.disconnect();
374
+ }
375
+ const audio = new Audio();
376
+ audio.srcObject = stream;
377
+ audio.autoplay = true;
378
+ const peer = this.peers.get(peerId);
379
+ audio.volume = peer?.localMuted ? 0 : this._masterVolume;
380
+ audio.play().catch((err) => {
381
+ this.emitter.emit(
382
+ "error",
383
+ createVoiceError(VoiceErrorCode.UNKNOWN, `Audio playback blocked: ${err?.message}`)
384
+ );
385
+ });
386
+ let source = null;
387
+ let analyser = null;
388
+ let timer;
389
+ if (this.audioCtx) {
390
+ if (this.audioCtx.state === "suspended") {
391
+ this.audioCtx.resume();
392
+ }
393
+ source = this.audioCtx.createMediaStreamSource(stream);
394
+ analyser = this.audioCtx.createAnalyser();
395
+ analyser.fftSize = 256;
396
+ source.connect(analyser);
397
+ const buf = new Uint8Array(analyser.frequencyBinCount);
398
+ const a = analyser;
399
+ timer = setInterval(() => {
400
+ if (!this.peers.has(peerId)) return;
401
+ a.getByteFrequencyData(buf);
402
+ const level = computeRms(buf);
403
+ const p = this.peers.get(peerId);
404
+ if (p) p.audioLevel = level;
405
+ this.emitter.emit("audioLevel", peerId, level);
406
+ }, 100);
407
+ } else {
408
+ timer = setInterval(() => {
409
+ }, 6e4);
410
+ }
411
+ this.peerAudio.set(peerId, { audio, source, analyser, timer });
412
+ }
413
+ async initiateOffer(peerId) {
414
+ const pc = this.createPeerConnectionForOffer(peerId);
415
+ try {
416
+ const offer = await pc.createOffer();
417
+ await pc.setLocalDescription(offer);
418
+ this.send({ type: "offer", to: peerId, sdp: offer.sdp });
419
+ } catch (e) {
420
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.OFFER_FAILED, e?.message));
421
+ }
422
+ }
423
+ async handleOffer(fromPeerId, sdp) {
424
+ let pc = this.peerConnections.get(fromPeerId);
425
+ const isNew = !pc;
426
+ if (!pc) {
427
+ pc = this.createPeerConnectionForAnswer(fromPeerId);
428
+ }
429
+ try {
430
+ await pc.setRemoteDescription(new RTCSessionDescription({ type: "offer", sdp }));
431
+ if (isNew) {
432
+ this.attachLocalTracksToAnswer(pc);
433
+ }
434
+ const answer = await pc.createAnswer();
435
+ await pc.setLocalDescription(answer);
436
+ this.send({ type: "answer", to: fromPeerId, sdp: answer.sdp });
437
+ } catch (e) {
438
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.ANSWER_FAILED, e?.message));
439
+ }
440
+ }
441
+ async renegotiateAll() {
442
+ for (const [peerId, pc] of this.peerConnections) {
443
+ if (pc.signalingState !== "stable") continue;
444
+ try {
445
+ const offer = await pc.createOffer();
446
+ await pc.setLocalDescription(offer);
447
+ this.send({ type: "offer", to: peerId, sdp: offer.sdp });
448
+ } catch (e) {
449
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.OFFER_FAILED, e?.message));
450
+ }
451
+ }
452
+ }
453
+ async toggleMute() {
454
+ this._muted = !this._muted;
455
+ if (this.localStream) {
456
+ for (const track of this.localStream.getAudioTracks()) {
457
+ track.enabled = !this._muted;
458
+ }
459
+ }
460
+ this.send({ type: "mute", muted: this._muted });
461
+ this.emitter.emit("mute", this._muted);
462
+ }
463
+ async toggleVideo() {
464
+ if (this._videoEnabled) {
465
+ this._localVideoStream?.getTracks().forEach((t) => t.stop());
466
+ this._localVideoStream = null;
467
+ this._videoEnabled = false;
468
+ for (const pc of this.peerConnections.values()) {
469
+ const transceivers = pc.getTransceivers();
470
+ if (transceivers[1]) {
471
+ await transceivers[1].sender.replaceTrack(null);
472
+ transceivers[1].direction = "recvonly";
473
+ }
474
+ }
475
+ } else {
476
+ try {
477
+ this._localVideoStream = await navigator.mediaDevices.getUserMedia({ video: true });
478
+ } catch (e) {
479
+ const name = e?.name ?? "";
480
+ const code = name === "NotAllowedError" || name === "PermissionDeniedError" ? VoiceErrorCode.CAMERA_PERMISSION_DENIED : name === "NotFoundError" ? VoiceErrorCode.CAMERA_NOT_FOUND : VoiceErrorCode.MEDIA_GENERIC;
481
+ this.emitter.emit("error", createVoiceError(code, e?.message));
482
+ return;
483
+ }
484
+ this._videoEnabled = true;
485
+ const track = this._localVideoStream.getVideoTracks()[0];
486
+ for (const pc of this.peerConnections.values()) {
487
+ const transceivers = pc.getTransceivers();
488
+ if (transceivers[1]) {
489
+ await transceivers[1].sender.replaceTrack(track);
490
+ transceivers[1].direction = "sendrecv";
491
+ }
492
+ }
493
+ }
494
+ this.send({ type: "media-state", video: this._videoEnabled, screen: this._screenEnabled });
495
+ this.emitter.emit("videoChange", this._videoEnabled);
496
+ await this.renegotiateAll();
497
+ }
498
+ async toggleScreen() {
499
+ if (this._screenEnabled) {
500
+ this._localScreenStream?.getTracks().forEach((t) => t.stop());
501
+ this._localScreenStream = null;
502
+ this._screenEnabled = false;
503
+ for (const pc of this.peerConnections.values()) {
504
+ const transceivers = pc.getTransceivers();
505
+ if (transceivers[2]) {
506
+ await transceivers[2].sender.replaceTrack(null);
507
+ transceivers[2].direction = "recvonly";
508
+ }
509
+ }
510
+ } else {
511
+ try {
512
+ this._localScreenStream = await navigator.mediaDevices.getDisplayMedia({ video: true });
513
+ } catch (e) {
514
+ this.emitter.emit("error", createVoiceError(VoiceErrorCode.SCREENSHARE_FAILED, e?.message));
515
+ return;
516
+ }
517
+ this._screenEnabled = true;
518
+ const track = this._localScreenStream.getVideoTracks()[0];
519
+ track.addEventListener("ended", () => {
520
+ this._localScreenStream = null;
521
+ this._screenEnabled = false;
522
+ for (const pc of this.peerConnections.values()) {
523
+ const transceivers = pc.getTransceivers();
524
+ if (transceivers[2]) {
525
+ transceivers[2].sender.replaceTrack(null);
526
+ transceivers[2].direction = "recvonly";
527
+ }
528
+ }
529
+ this.send({ type: "media-state", video: this._videoEnabled, screen: false });
530
+ this.emitter.emit("screenChange", false);
531
+ this.renegotiateAll();
532
+ });
533
+ for (const pc of this.peerConnections.values()) {
534
+ const transceivers = pc.getTransceivers();
535
+ if (transceivers[2]) {
536
+ await transceivers[2].sender.replaceTrack(track);
537
+ transceivers[2].direction = "sendrecv";
538
+ }
539
+ }
540
+ }
541
+ this.send({ type: "media-state", video: this._videoEnabled, screen: this._screenEnabled });
542
+ this.emitter.emit("screenChange", this._screenEnabled);
543
+ await this.renegotiateAll();
544
+ }
545
+ setProfile(name, color) {
546
+ this._profile = { name, color };
547
+ if (this._status === "connected") {
548
+ this.send({ type: "profile", name, color });
549
+ }
550
+ }
551
+ togglePeerMute(peerId) {
552
+ const peer = this.peers.get(peerId);
553
+ if (!peer) return;
554
+ peer.localMuted = !peer.localMuted;
555
+ const pa = this.peerAudio.get(peerId);
556
+ if (pa) pa.audio.volume = peer.localMuted ? 0 : this._masterVolume;
557
+ }
558
+ setPeerVolume(peerId, volume) {
559
+ const clamped = Math.max(0, Math.min(volume, 1));
560
+ const pa = this.peerAudio.get(peerId);
561
+ if (pa) pa.audio.volume = clamped * this._masterVolume;
562
+ const peer = this.peers.get(peerId);
563
+ if (peer) peer.localMuted = clamped === 0;
564
+ }
565
+ setMasterVolume(volume) {
566
+ this._masterVolume = Math.max(0, Math.min(volume, 1));
567
+ for (const [peerId, pa] of this.peerAudio) {
568
+ const peer = this.peers.get(peerId);
569
+ if (peer?.localMuted) continue;
570
+ pa.audio.volume = this._masterVolume;
571
+ }
572
+ }
573
+ disconnect() {
574
+ this.send({ type: "leave" });
575
+ if (this.localAudioTimer !== null) {
576
+ clearInterval(this.localAudioTimer);
577
+ this.localAudioTimer = null;
578
+ }
579
+ for (const peerId of [...this.peerConnections.keys()]) {
580
+ this.removePeer(peerId);
581
+ }
582
+ this.ws?.close();
583
+ this.ws = null;
584
+ this.localStream?.getTracks().forEach((t) => t.stop());
585
+ this.localStream = null;
586
+ this._localVideoStream?.getTracks().forEach((t) => t.stop());
587
+ this._localVideoStream = null;
588
+ this._localScreenStream?.getTracks().forEach((t) => t.stop());
589
+ this._localScreenStream = null;
590
+ this.audioCtx?.close();
591
+ this.audioCtx = null;
592
+ this.peers.clear();
593
+ this.myPeerId = null;
594
+ this._muted = false;
595
+ this._videoEnabled = false;
596
+ this._screenEnabled = false;
597
+ this.setStatus("idle");
598
+ }
599
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Split-border avatar: inner filled with primaryColor, border = left half primary / right half neutral.
3
+ *
4
+ * CSS rules:
5
+ * - Colors cannot appear in non-final background layers; use linear-gradient(c,c) as a solid-color image instead.
6
+ * - UAvatar has overflow:hidden which clips border-area backgrounds; override with overflow:visible.
7
+ * Border-radius still clips the background shape, and text initials don't need overflow clipping.
8
+ */
9
+ export declare function avatarBorderStyle(primaryColor: string, neutralColorName: string): string;
10
+ /**
11
+ * Same as avatarBorderStyle but accepts a color name and resolves to CSS variables.
12
+ * Use this for the local user where the identity color name is known (identity colors = ui colors).
13
+ */
14
+ export declare function avatarStyleFromName(primaryColorName: string, neutralColorName: string): string;
15
+ export declare function avatarGradient(primaryColor: string, neutralColorName: string): string;
@@ -0,0 +1,20 @@
1
+ export function avatarBorderStyle(primaryColor, neutralColorName) {
2
+ const neutral = `var(--color-${neutralColorName}-400, #888)`;
3
+ return [
4
+ "border: 2px solid transparent",
5
+ `background: linear-gradient(${primaryColor}, ${primaryColor}) padding-box, conic-gradient(${primaryColor} 180deg, ${neutral} 180deg) border-box`,
6
+ "overflow: visible"
7
+ ].join("; ");
8
+ }
9
+ export function avatarStyleFromName(primaryColorName, neutralColorName) {
10
+ const primary = `var(--color-${primaryColorName}-400)`;
11
+ const neutral = `var(--color-${neutralColorName}-400, #888)`;
12
+ return [
13
+ "border: 2px solid transparent",
14
+ `background: linear-gradient(${primary}, ${primary}) padding-box, conic-gradient(${primary} 180deg, ${neutral} 180deg) border-box`,
15
+ "overflow: visible"
16
+ ].join("; ");
17
+ }
18
+ export function avatarGradient(primaryColor, neutralColorName) {
19
+ return `linear-gradient(135deg, ${primaryColor} 0%, var(--color-${neutralColorName}-400, #888) 100%)`;
20
+ }
@@ -0,0 +1,13 @@
1
+ export interface ColorShade {
2
+ shade: number;
3
+ hex: string;
4
+ }
5
+ export interface ColorPalette {
6
+ name: string;
7
+ shades: ColorShade[];
8
+ }
9
+ export declare const COLOR_PALETTES: ColorPalette[];
10
+ export declare function findPaletteByHex(hex: string): {
11
+ palette: ColorPalette;
12
+ shade: ColorShade;
13
+ } | null;