isometrik-plugin-chat-sdk 1.0.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 (507) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/BlockChatList-720a703e.js +423 -0
  3. package/dist/cjs/BlockChatList-720a703e.js.map +1 -0
  4. package/dist/cjs/DocumentMessageBubble-c79bfbe5.js +493 -0
  5. package/dist/cjs/DocumentMessageBubble-c79bfbe5.js.map +1 -0
  6. package/dist/cjs/Image-67c52acd.js +135 -0
  7. package/dist/cjs/Image-67c52acd.js.map +1 -0
  8. package/dist/cjs/ImageMessageBubble-1218fb66.js +675 -0
  9. package/dist/cjs/ImageMessageBubble-1218fb66.js.map +1 -0
  10. package/dist/cjs/IsometrikLogo-976b1c34.js +44 -0
  11. package/dist/cjs/IsometrikLogo-976b1c34.js.map +1 -0
  12. package/dist/cjs/MessageSearch-5fc9dc00.js +5892 -0
  13. package/dist/cjs/MessageSearch-5fc9dc00.js.map +1 -0
  14. package/dist/cjs/ReactionsContainer-a6ce9059.js +375 -0
  15. package/dist/cjs/ReactionsContainer-a6ce9059.js.map +1 -0
  16. package/dist/cjs/Text-fedf6eab.js +60 -0
  17. package/dist/cjs/Text-fedf6eab.js.map +1 -0
  18. package/dist/cjs/VideoMessageBubble-c4694a78.js +571 -0
  19. package/dist/cjs/VideoMessageBubble-c4694a78.js.map +1 -0
  20. package/dist/cjs/WebChat-403e7ab1.js +2884 -0
  21. package/dist/cjs/WebChat-403e7ab1.js.map +1 -0
  22. package/dist/cjs/app-globals-3a1e7e63.js +7 -0
  23. package/dist/cjs/app-globals-3a1e7e63.js.map +1 -0
  24. package/dist/cjs/audio-bubble_8.cjs.entry.js +21011 -0
  25. package/dist/cjs/audio-bubble_8.cjs.entry.js.map +1 -0
  26. package/dist/cjs/block-chat-list.cjs.entry.js +16 -0
  27. package/dist/cjs/block-chat-list.cjs.entry.js.map +1 -0
  28. package/dist/cjs/chat-app.cjs.entry.js +55 -0
  29. package/dist/cjs/chat-app.cjs.entry.js.map +1 -0
  30. package/dist/cjs/chat-assets-6ab1faa6.js +9 -0
  31. package/dist/cjs/chat-assets-6ab1faa6.js.map +1 -0
  32. package/dist/cjs/chat-creds-f4cbf400.js +38 -0
  33. package/dist/cjs/chat-creds-f4cbf400.js.map +1 -0
  34. package/dist/cjs/chat-document-message-bubble.cjs.entry.js +24 -0
  35. package/dist/cjs/chat-document-message-bubble.cjs.entry.js.map +1 -0
  36. package/dist/cjs/chat-image-message-bubble.cjs.entry.js +26 -0
  37. package/dist/cjs/chat-image-message-bubble.cjs.entry.js.map +1 -0
  38. package/dist/cjs/chat-video-message-bubble.cjs.entry.js +24 -0
  39. package/dist/cjs/chat-video-message-bubble.cjs.entry.js.map +1 -0
  40. package/dist/cjs/content-eca5336c.js +81 -0
  41. package/dist/cjs/content-eca5336c.js.map +1 -0
  42. package/dist/cjs/dialog-drawer-9d04911c.js +5313 -0
  43. package/dist/cjs/dialog-drawer-9d04911c.js.map +1 -0
  44. package/dist/cjs/forward-memebers.cjs.entry.js +128 -0
  45. package/dist/cjs/forward-memebers.cjs.entry.js.map +1 -0
  46. package/dist/cjs/group-members-a60fb1cb.js +41 -0
  47. package/dist/cjs/group-members-a60fb1cb.js.map +1 -0
  48. package/dist/cjs/groupcast-49dae5ab.js +202 -0
  49. package/dist/cjs/groupcast-49dae5ab.js.map +1 -0
  50. package/dist/cjs/imagePlaceholder-030cc566.js +4365 -0
  51. package/dist/cjs/imagePlaceholder-030cc566.js.map +1 -0
  52. package/dist/cjs/index-9afe62b6.js +3129 -0
  53. package/dist/cjs/index-9afe62b6.js.map +1 -0
  54. package/dist/cjs/index.cjs.js +148 -0
  55. package/dist/cjs/index.cjs.js.map +1 -0
  56. package/dist/cjs/isometrik-webchat.cjs.js +54 -0
  57. package/dist/cjs/isometrik-webchat.cjs.js.map +1 -0
  58. package/dist/cjs/loader.cjs.js +17 -0
  59. package/dist/cjs/loader.cjs.js.map +1 -0
  60. package/dist/cjs/login-page.cjs.entry.js +85 -0
  61. package/dist/cjs/login-page.cjs.entry.js.map +1 -0
  62. package/dist/cjs/member-add.cjs.entry.js +122 -0
  63. package/dist/cjs/member-add.cjs.entry.js.map +1 -0
  64. package/dist/cjs/message-reaction-976f6261.js +24 -0
  65. package/dist/cjs/message-reaction-976f6261.js.map +1 -0
  66. package/dist/cjs/my-component.cjs.entry.js +29 -0
  67. package/dist/cjs/my-component.cjs.entry.js.map +1 -0
  68. package/dist/cjs/reaction-container.cjs.entry.js +52 -0
  69. package/dist/cjs/reaction-container.cjs.entry.js.map +1 -0
  70. package/dist/cjs/shadow-css-7c4dbc43.js +336 -0
  71. package/dist/cjs/shadow-css-7c4dbc43.js.map +1 -0
  72. package/dist/cjs/signup-page.cjs.entry.js +143 -0
  73. package/dist/cjs/signup-page.cjs.entry.js.map +1 -0
  74. package/dist/cjs/taguser-aca04ed9.js +512 -0
  75. package/dist/cjs/taguser-aca04ed9.js.map +1 -0
  76. package/dist/cjs/theme-provider_2.cjs.entry.js +113 -0
  77. package/dist/cjs/theme-provider_2.cjs.entry.js.map +1 -0
  78. package/dist/cjs/toast-helper-defae4a5.js +84 -0
  79. package/dist/cjs/toast-helper-defae4a5.js.map +1 -0
  80. package/dist/cjs/utils-bcad3386.js +9 -0
  81. package/dist/cjs/utils-bcad3386.js.map +1 -0
  82. package/dist/collection/api/conversations.js +12 -0
  83. package/dist/collection/api/group-members.js +36 -0
  84. package/dist/collection/api/groupcast.js +183 -0
  85. package/dist/collection/api/membership-control.js +13 -0
  86. package/dist/collection/api/message-reaction.js +16 -0
  87. package/dist/collection/api/social-accounts.js +282 -0
  88. package/dist/collection/app-root.js +51 -0
  89. package/dist/collection/app-root.js.map +1 -0
  90. package/dist/collection/assets/images/avatar.svg +1 -0
  91. package/dist/collection/assets/images/chatdefaultbg.svg +6140 -0
  92. package/dist/collection/assets/images/equalizer.svg +1 -0
  93. package/dist/collection/assets/images/imagePlaceholder.svg +2 -0
  94. package/dist/collection/assets/images/link.svg +1 -0
  95. package/dist/collection/assets/images/videoPlaceholder.svg +4 -0
  96. package/dist/collection/assets/images/videoThumbnail.svg +1 -0
  97. package/dist/collection/assets/svg/ExcelDocument.js +2 -0
  98. package/dist/collection/assets/svg/IsometrikLogo.js +38 -0
  99. package/dist/collection/assets/svg/Moon.svg +1 -0
  100. package/dist/collection/assets/svg/NoChatPlaceholder.js +16 -0
  101. package/dist/collection/assets/svg/NoContactsPlaceholder.js +9 -0
  102. package/dist/collection/assets/svg/NoMessagePlaceholder.svg +13 -0
  103. package/dist/collection/assets/svg/PdfDocument.js +2 -0
  104. package/dist/collection/assets/svg/ProfilePlaceholder.js +1 -0
  105. package/dist/collection/assets/svg/SelectChatPlaceholder.js +13 -0
  106. package/dist/collection/assets/svg/Sun.svg +1 -0
  107. package/dist/collection/assets/svg/broadcast-selected.svg +4 -0
  108. package/dist/collection/assets/svg/broadcst-default.svg +4 -0
  109. package/dist/collection/assets/svg/close.svg +1 -0
  110. package/dist/collection/assets/svg/group.svg +7 -0
  111. package/dist/collection/assets/svg/login.svg +3051 -0
  112. package/dist/collection/assets/svg/message-add.svg +5 -0
  113. package/dist/collection/assets/svg/message-bold.svg +3 -0
  114. package/dist/collection/assets/svg/message-outline.svg +5 -0
  115. package/dist/collection/collection-manifest.json +32 -0
  116. package/dist/collection/components/ChatUIComponent/AddMember.js +144 -0
  117. package/dist/collection/components/ChatUIComponent/AddMember.js.map +1 -0
  118. package/dist/collection/components/ChatUIComponent/AudioBubble.js +528 -0
  119. package/dist/collection/components/ChatUIComponent/AudioBubble.js.map +1 -0
  120. package/dist/collection/components/ChatUIComponent/BlockChatList.js +114 -0
  121. package/dist/collection/components/ChatUIComponent/BlockChatList.js.map +1 -0
  122. package/dist/collection/components/ChatUIComponent/ChatDocumentMessageBubble.js +11 -0
  123. package/dist/collection/components/ChatUIComponent/ChatDocumentMessageBubble.js.map +1 -0
  124. package/dist/collection/components/ChatUIComponent/ChatImageMessageBubble.js +11 -0
  125. package/dist/collection/components/ChatUIComponent/ChatImageMessageBubble.js.map +1 -0
  126. package/dist/collection/components/ChatUIComponent/ChatOwnProfile/Profile.js +540 -0
  127. package/dist/collection/components/ChatUIComponent/ChatOwnProfile/Profile.js.map +1 -0
  128. package/dist/collection/components/ChatUIComponent/ChatOwnProfile/profile-page.css +252 -0
  129. package/dist/collection/components/ChatUIComponent/ChatSidebar/ChatSidebar.js +1175 -0
  130. package/dist/collection/components/ChatUIComponent/ChatSidebar/ChatSidebar.js.map +1 -0
  131. package/dist/collection/components/ChatUIComponent/ChatVideoMessageBubble.js +11 -0
  132. package/dist/collection/components/ChatUIComponent/ChatVideoMessageBubble.js.map +1 -0
  133. package/dist/collection/components/ChatUIComponent/Footer/ChatFooter.js +790 -0
  134. package/dist/collection/components/ChatUIComponent/Footer/ChatFooter.js.map +1 -0
  135. package/dist/collection/components/ChatUIComponent/ForwardMessageList.js +152 -0
  136. package/dist/collection/components/ChatUIComponent/ForwardMessageList.js.map +1 -0
  137. package/dist/collection/components/ChatUIComponent/GroupCast.js +218 -0
  138. package/dist/collection/components/ChatUIComponent/GroupCast.js.map +1 -0
  139. package/dist/collection/components/ChatUIComponent/Header/WebChatHeader.js +590 -0
  140. package/dist/collection/components/ChatUIComponent/Header/WebChatHeader.js.map +1 -0
  141. package/dist/collection/components/ChatUIComponent/ReactionContainer.js +103 -0
  142. package/dist/collection/components/ChatUIComponent/ReactionContainer.js.map +1 -0
  143. package/dist/collection/components/ChatUIComponent/WebChatBody/WebChatBody.js +1352 -0
  144. package/dist/collection/components/ChatUIComponent/WebChatBody/WebChatBody.js.map +1 -0
  145. package/dist/collection/components/ChatUIComponent/WebChatBody/web-chat-body.css +277 -0
  146. package/dist/collection/components/Login.js +118 -0
  147. package/dist/collection/components/Login.js.map +1 -0
  148. package/dist/collection/components/Signup.js +177 -0
  149. package/dist/collection/components/Signup.js.map +1 -0
  150. package/dist/collection/components/chat-main.js +131 -0
  151. package/dist/collection/components/chat-main.js.map +1 -0
  152. package/dist/collection/components/my-component/my-component.css +3 -0
  153. package/dist/collection/components/my-component/my-component.js +83 -0
  154. package/dist/collection/components/my-component/my-component.js.map +1 -0
  155. package/dist/collection/components/my-component/web-chat/WebChat.js +2686 -0
  156. package/dist/collection/components/my-component/web-chat/WebChat.js.map +1 -0
  157. package/dist/collection/components/my-component/web-chat/WebchatRightSide.js +675 -0
  158. package/dist/collection/components/my-component/web-chat/WebchatRightSide.js.map +1 -0
  159. package/dist/collection/components/my-component/web-chat/web-chat.css +336 -0
  160. package/dist/collection/components/theme-provider.js +182 -0
  161. package/dist/collection/components/theme-provider.js.map +1 -0
  162. package/dist/collection/constants/chat-assets.js +12 -0
  163. package/dist/collection/constants/chat-creds.js +31 -0
  164. package/dist/collection/constants/content.js +75 -0
  165. package/dist/collection/constants/urls.js +1 -0
  166. package/dist/collection/index.js +135 -0
  167. package/dist/collection/index.js.map +1 -0
  168. package/dist/collection/lib/helpers.js +205 -0
  169. package/dist/collection/lib/taguser.js +123 -0
  170. package/dist/collection/store/conversation.js +25 -0
  171. package/dist/collection/store/conversation.js.map +1 -0
  172. package/dist/collection/store/group-members.js +24 -0
  173. package/dist/collection/store/group-members.js.map +1 -0
  174. package/dist/collection/store/unread-count.js +18 -0
  175. package/dist/collection/store/unread-count.js.map +1 -0
  176. package/dist/collection/stories/Components/ActionsPopup/ActionsPopup.js +222 -0
  177. package/dist/collection/stories/Components/ActionsPopup/ActionsPopup.stories.js +148 -0
  178. package/dist/collection/stories/Components/AttachmentBox/AttachmentBox.js +211 -0
  179. package/dist/collection/stories/Components/AttachmentBox/AttachmentPreview/AttachmentPreview.js +708 -0
  180. package/dist/collection/stories/Components/AttachmentBox/AttachmentPreview/AttachmentPreview.stories.js +57 -0
  181. package/dist/collection/stories/Components/AttachmentBox/Attachmentbox.stories.js +74 -0
  182. package/dist/collection/stories/Components/AttachmentBox/CameraPreview.js +231 -0
  183. package/dist/collection/stories/Components/BlockUsers/BlockUsers.js +337 -0
  184. package/dist/collection/stories/Components/Body/Body.js +48 -0
  185. package/dist/collection/stories/Components/Body/Body.stories.js +33 -0
  186. package/dist/collection/stories/Components/Buttons/Buttons.js +65 -0
  187. package/dist/collection/stories/Components/Buttons/Buttons.stories.js +132 -0
  188. package/dist/collection/stories/Components/ChatSidebar/ChatSidebar.js +951 -0
  189. package/dist/collection/stories/Components/ChatSidebar/ChatSidebar.stories.js +75 -0
  190. package/dist/collection/stories/Components/ChatSidebar/ContextMenu.js +109 -0
  191. package/dist/collection/stories/Components/ChatTile/ChatTile.js +290 -0
  192. package/dist/collection/stories/Components/ChatTile/ChatTile.stories.js +180 -0
  193. package/dist/collection/stories/Components/Chip/Chip.js +111 -0
  194. package/dist/collection/stories/Components/Chip/Chip.stories.js +149 -0
  195. package/dist/collection/stories/Components/ContactInfo/ContactInfo.js +1491 -0
  196. package/dist/collection/stories/Components/ContactInfo/ContactInfo.stories.js +118 -0
  197. package/dist/collection/stories/Components/ContactInfo/MediaList.js +147 -0
  198. package/dist/collection/stories/Components/ContactInfo/ProfileInfo.js +1219 -0
  199. package/dist/collection/stories/Components/ContactTile/ContactTile.js +416 -0
  200. package/dist/collection/stories/Components/ContactTile/ContactTile.stories.js +60 -0
  201. package/dist/collection/stories/Components/Dialog-Drawer/confirm.js +113 -0
  202. package/dist/collection/stories/Components/Dialog-Drawer/deletemessage.js +97 -0
  203. package/dist/collection/stories/Components/Dialog-Drawer/dialog-drawer.js +264 -0
  204. package/dist/collection/stories/Components/EmojiReactions/EmojiReactions.js +179 -0
  205. package/dist/collection/stories/Components/Footer/Footer.js +4 -0
  206. package/dist/collection/stories/Components/Footer/Footer.stories.js +155 -0
  207. package/dist/collection/stories/Components/ForwardMessage/ForwardMessageContainer.js +433 -0
  208. package/dist/collection/stories/Components/ForwardMessage/ForwardMessageContainer.stories.js +110 -0
  209. package/dist/collection/stories/Components/ForwardMessage/ForwardUi.js +46 -0
  210. package/dist/collection/stories/Components/GroupChatContacts/GroupChatContacts.js +546 -0
  211. package/dist/collection/stories/Components/GroupChatContacts/GroupChatContacts.stories.js +56 -0
  212. package/dist/collection/stories/Components/GroupInfo/GroupInfo.js +394 -0
  213. package/dist/collection/stories/Components/GroupInfo/GroupInfo.stories.js +107 -0
  214. package/dist/collection/stories/Components/Head/ClosedHeader/ClosedHead.js +129 -0
  215. package/dist/collection/stories/Components/Head/ClosedHeader/ClosedHead.stories.js +78 -0
  216. package/dist/collection/stories/Components/Head/Head.js +672 -0
  217. package/dist/collection/stories/Components/Head/Head.stories.js +91 -0
  218. package/dist/collection/stories/Components/Icon/Icon.js +115 -0
  219. package/dist/collection/stories/Components/Image/Image.js +41 -0
  220. package/dist/collection/stories/Components/Image/Image.stories.js +49 -0
  221. package/dist/collection/stories/Components/Image/Img.stories.js +178 -0
  222. package/dist/collection/stories/Components/Inputbox/Input.js +206 -0
  223. package/dist/collection/stories/Components/Inputbox/Input.stories.js +87 -0
  224. package/dist/collection/stories/Components/InstagramAccounts/InstagramAccountsPanel.js +605 -0
  225. package/dist/collection/stories/Components/Loader/Spinner/Spinner.js +60 -0
  226. package/dist/collection/stories/Components/Loader/Spinner/Spinner.stories.js +38 -0
  227. package/dist/collection/stories/Components/MainPlaceHolder/MainChatPlaceHolder.js +78 -0
  228. package/dist/collection/stories/Components/MainPlaceHolder/MainPlaceHolder.stories.js +130 -0
  229. package/dist/collection/stories/Components/MediaGallery/MediaGallery.js +868 -0
  230. package/dist/collection/stories/Components/MediaGallery/MediaGallery.stories.js +81 -0
  231. package/dist/collection/stories/Components/MembersList/MembersList.js +348 -0
  232. package/dist/collection/stories/Components/MessageBubble/AudioMessageBubble/AudioMesaageBubble.js +533 -0
  233. package/dist/collection/stories/Components/MessageBubble/DocumentMessageBubble/DocumentMessageBubble.js +484 -0
  234. package/dist/collection/stories/Components/MessageBubble/DocumentMessageBubble/DocumentMessageBubble.stories.js +54 -0
  235. package/dist/collection/stories/Components/MessageBubble/ImageMessageBubble/ImageMessageBubble.js +683 -0
  236. package/dist/collection/stories/Components/MessageBubble/ImageMessageBubble/ImageMessageBubble.stories.js +49 -0
  237. package/dist/collection/stories/Components/MessageBubble/IncomingTextMessageBubble/IncomingTextMessageBubble.js +450 -0
  238. package/dist/collection/stories/Components/MessageBubble/IncomingTextMessageBubble/IncomingTextMessageBubble.stories.js +56 -0
  239. package/dist/collection/stories/Components/MessageBubble/LinkMessageBubble/LinkMessageBubble.js +721 -0
  240. package/dist/collection/stories/Components/MessageBubble/OutgoingTextMessageBubble/OutgoingTextMessageBubble.js +139 -0
  241. package/dist/collection/stories/Components/MessageBubble/OutgoingTextMessageBubble/OutgoingTextMessageBubble.stories.js +63 -0
  242. package/dist/collection/stories/Components/MessageBubble/VideoMessageBubble/VideoMessageBubble.js +576 -0
  243. package/dist/collection/stories/Components/MessageBubble/VideoMessageBubble/VideoMessageBubble.stories.js +50 -0
  244. package/dist/collection/stories/Components/MessageDatePill/MessageDatePill.js +66 -0
  245. package/dist/collection/stories/Components/MessageDatePill/MessageDatePill.stories.js +48 -0
  246. package/dist/collection/stories/Components/MessageInfo/MessageInfo.js +465 -0
  247. package/dist/collection/stories/Components/MessageInfo/MessageInfo.stories.js +111 -0
  248. package/dist/collection/stories/Components/MessageSearch/MessageSearch.js +242 -0
  249. package/dist/collection/stories/Components/MessageSearchBar/SearchBar.js +523 -0
  250. package/dist/collection/stories/Components/MessageSearchBar/SearchBar.stories.js +98 -0
  251. package/dist/collection/stories/Components/MessageUnreadCount/MessageUnreadCount.js +51 -0
  252. package/dist/collection/stories/Components/MessageUnreadCount/MessageUnreadCount.stories.js +79 -0
  253. package/dist/collection/stories/Components/NewChatSidebar/NewChatSidebar.js +560 -0
  254. package/dist/collection/stories/Components/NewChatSidebar/NewChatSidebar.stories.js +56 -0
  255. package/dist/collection/stories/Components/Placeholder/NoContactsPlaceholder.js +57 -0
  256. package/dist/collection/stories/Components/Popup/ConfirmationPopup/DeleteConfirmationPopup/DeletePopup.js +114 -0
  257. package/dist/collection/stories/Components/ProfileSidebar/ProfileSidebar.js +166 -0
  258. package/dist/collection/stories/Components/ProfileSidebar/ProfileSidebar.stories.js +125 -0
  259. package/dist/collection/stories/Components/ProfileTab/ProfileTab.js +939 -0
  260. package/dist/collection/stories/Components/ProfileTab/ProfileTab.stories.js +144 -0
  261. package/dist/collection/stories/Components/ReactionsContainer/ReactionsContainer.js +166 -0
  262. package/dist/collection/stories/Components/ReactionsContainer/ReactionsContainer.stories.js +115 -0
  263. package/dist/collection/stories/Components/ReactionsContainer/ReactionsInfoCard/ReactionsInfoCard.js +98 -0
  264. package/dist/collection/stories/Components/ReactionsContainer/ReactionsInfoCard/ReactionsInfoCard.stories.js +55 -0
  265. package/dist/collection/stories/Components/ReadMark/BlueReadMark/BlueReadMark.js +27 -0
  266. package/dist/collection/stories/Components/ReadMark/BlueReadMark/BlueReadMark.stories.js +28 -0
  267. package/dist/collection/stories/Components/ReadMark/ClockMark/ClockMark.js +26 -0
  268. package/dist/collection/stories/Components/ReadMark/ClockMark/ClockMark.stories.js +33 -0
  269. package/dist/collection/stories/Components/ReadMark/DoubleMark/DoubleMark.js +27 -0
  270. package/dist/collection/stories/Components/ReadMark/DoubleMark/DoubleMark.stories.js +28 -0
  271. package/dist/collection/stories/Components/ReadMark/SingleMark/SingleMark.js +38 -0
  272. package/dist/collection/stories/Components/ReadMark/SingleMark/SingleMark.stories.js +33 -0
  273. package/dist/collection/stories/Components/ReplyBlock/MediaIcons.js +16 -0
  274. package/dist/collection/stories/Components/ReplyBlock/ReplyBlock.js +196 -0
  275. package/dist/collection/stories/Components/ReplyBlock/ReplyBlock.stories.js +57 -0
  276. package/dist/collection/stories/Components/ReplyMessageContainer/ReplyMessageContainer.js +645 -0
  277. package/dist/collection/stories/Components/ReplyMessageContainer/ReplyMessageContainer.stories.js +58 -0
  278. package/dist/collection/stories/Components/SearchableList/SearchableList.js +393 -0
  279. package/dist/collection/stories/Components/SearchableList/SearchableList.stories.js +65 -0
  280. package/dist/collection/stories/Components/SharePopup/SharePopup.js +152 -0
  281. package/dist/collection/stories/Components/SharePopup/SharePopup.stories.js +47 -0
  282. package/dist/collection/stories/Components/Splitscreen/Splitscreen.js +157 -0
  283. package/dist/collection/stories/Components/Splitscreen/Splitscreen.stories.js +100 -0
  284. package/dist/collection/stories/Components/TestFooter/MentionUserList.js +194 -0
  285. package/dist/collection/stories/Components/TestFooter/TestFooter.js +1339 -0
  286. package/dist/collection/stories/Components/TestFooter/TestFooter.stories.js +89 -0
  287. package/dist/collection/stories/Components/Text/Text.js +57 -0
  288. package/dist/collection/stories/Components/Text/Text.stories.js +83 -0
  289. package/dist/collection/stories/Components/TextStyle/TextStyle.js +38 -0
  290. package/dist/collection/stories/Components/TextStyle/TextStyle.stories.js +50 -0
  291. package/dist/collection/stories/Components/Time/Timestamp.js +50 -0
  292. package/dist/collection/stories/Components/Time/Timestamp.stories.js +34 -0
  293. package/dist/collection/stories/Components/Toaster/Toaster.js +94 -0
  294. package/dist/collection/stories/Components/Toaster/Toaster.stories.js +108 -0
  295. package/dist/collection/stories/Components/Toaster/toast-helper.js +79 -0
  296. package/dist/collection/stories/Components/Toaster/toast-helper.js.map +1 -0
  297. package/dist/collection/stories/Components/final/final.js +86 -0
  298. package/dist/collection/stories/Components/final/final.stories.js +30 -0
  299. package/dist/collection/stories/assets/SEARCH ICON.svg +1 -0
  300. package/dist/collection/types/ConversationDetailsTypes.js +2 -0
  301. package/dist/collection/types/ConversationDetailsTypes.js.map +1 -0
  302. package/dist/collection/utils/chatSdk.js +14 -0
  303. package/dist/collection/utils/getFomattedDate.js +34 -0
  304. package/dist/collection/utils/getFomattedDate.js.map +1 -0
  305. package/dist/collection/utils/unixTimeConverter.js +28 -0
  306. package/dist/collection/utils/utils.js +4 -0
  307. package/dist/collection/utils/utils.js.map +1 -0
  308. package/dist/esm/BlockChatList-9fc3a42b.js +421 -0
  309. package/dist/esm/BlockChatList-9fc3a42b.js.map +1 -0
  310. package/dist/esm/DocumentMessageBubble-b67726f2.js +491 -0
  311. package/dist/esm/DocumentMessageBubble-b67726f2.js.map +1 -0
  312. package/dist/esm/Image-bb9efda3.js +121 -0
  313. package/dist/esm/Image-bb9efda3.js.map +1 -0
  314. package/dist/esm/ImageMessageBubble-0e473f6e.js +673 -0
  315. package/dist/esm/ImageMessageBubble-0e473f6e.js.map +1 -0
  316. package/dist/esm/IsometrikLogo-14db76af.js +42 -0
  317. package/dist/esm/IsometrikLogo-14db76af.js.map +1 -0
  318. package/dist/esm/MessageSearch-4101a627.js +5875 -0
  319. package/dist/esm/MessageSearch-4101a627.js.map +1 -0
  320. package/dist/esm/ReactionsContainer-bdd74a3c.js +373 -0
  321. package/dist/esm/ReactionsContainer-bdd74a3c.js.map +1 -0
  322. package/dist/esm/Text-3b0b3898.js +58 -0
  323. package/dist/esm/Text-3b0b3898.js.map +1 -0
  324. package/dist/esm/VideoMessageBubble-88a7a53e.js +569 -0
  325. package/dist/esm/VideoMessageBubble-88a7a53e.js.map +1 -0
  326. package/dist/esm/WebChat-5448d615.js +2882 -0
  327. package/dist/esm/WebChat-5448d615.js.map +1 -0
  328. package/dist/esm/app-globals-0f993ce5.js +5 -0
  329. package/dist/esm/app-globals-0f993ce5.js.map +1 -0
  330. package/dist/esm/audio-bubble_8.entry.js +21001 -0
  331. package/dist/esm/audio-bubble_8.entry.js.map +1 -0
  332. package/dist/esm/block-chat-list.entry.js +8 -0
  333. package/dist/esm/block-chat-list.entry.js.map +1 -0
  334. package/dist/esm/chat-app.entry.js +51 -0
  335. package/dist/esm/chat-app.entry.js.map +1 -0
  336. package/dist/esm/chat-assets-bd8778d5.js +6 -0
  337. package/dist/esm/chat-assets-bd8778d5.js.map +1 -0
  338. package/dist/esm/chat-creds-ff086f05.js +35 -0
  339. package/dist/esm/chat-creds-ff086f05.js.map +1 -0
  340. package/dist/esm/chat-document-message-bubble.entry.js +20 -0
  341. package/dist/esm/chat-document-message-bubble.entry.js.map +1 -0
  342. package/dist/esm/chat-image-message-bubble.entry.js +22 -0
  343. package/dist/esm/chat-image-message-bubble.entry.js.map +1 -0
  344. package/dist/esm/chat-video-message-bubble.entry.js +20 -0
  345. package/dist/esm/chat-video-message-bubble.entry.js.map +1 -0
  346. package/dist/esm/content-5aea5e39.js +79 -0
  347. package/dist/esm/content-5aea5e39.js.map +1 -0
  348. package/dist/esm/dialog-drawer-9fa083b1.js +5304 -0
  349. package/dist/esm/dialog-drawer-9fa083b1.js.map +1 -0
  350. package/dist/esm/forward-memebers.entry.js +124 -0
  351. package/dist/esm/forward-memebers.entry.js.map +1 -0
  352. package/dist/esm/group-members-bb3c8db7.js +37 -0
  353. package/dist/esm/group-members-bb3c8db7.js.map +1 -0
  354. package/dist/esm/groupcast-d1c54a27.js +187 -0
  355. package/dist/esm/groupcast-d1c54a27.js.map +1 -0
  356. package/dist/esm/imagePlaceholder-e544f70b.js +4360 -0
  357. package/dist/esm/imagePlaceholder-e544f70b.js.map +1 -0
  358. package/dist/esm/index-fddf30b7.js +3093 -0
  359. package/dist/esm/index-fddf30b7.js.map +1 -0
  360. package/dist/esm/index.js +139 -0
  361. package/dist/esm/index.js.map +1 -0
  362. package/dist/esm/isometrik-webchat.js +49 -0
  363. package/dist/esm/isometrik-webchat.js.map +1 -0
  364. package/dist/esm/loader.js +13 -0
  365. package/dist/esm/loader.js.map +1 -0
  366. package/dist/esm/login-page.entry.js +81 -0
  367. package/dist/esm/login-page.entry.js.map +1 -0
  368. package/dist/esm/member-add.entry.js +118 -0
  369. package/dist/esm/member-add.entry.js.map +1 -0
  370. package/dist/esm/message-reaction-ad47ea1a.js +20 -0
  371. package/dist/esm/message-reaction-ad47ea1a.js.map +1 -0
  372. package/dist/esm/my-component.entry.js +25 -0
  373. package/dist/esm/my-component.entry.js.map +1 -0
  374. package/dist/esm/reaction-container.entry.js +48 -0
  375. package/dist/esm/reaction-container.entry.js.map +1 -0
  376. package/dist/esm/shadow-css-7ad5caf8.js +334 -0
  377. package/dist/esm/shadow-css-7ad5caf8.js.map +1 -0
  378. package/dist/esm/signup-page.entry.js +139 -0
  379. package/dist/esm/signup-page.entry.js.map +1 -0
  380. package/dist/esm/taguser-e9032d65.js +510 -0
  381. package/dist/esm/taguser-e9032d65.js.map +1 -0
  382. package/dist/esm/theme-provider_2.entry.js +108 -0
  383. package/dist/esm/theme-provider_2.entry.js.map +1 -0
  384. package/dist/esm/toast-helper-840fd8dc.js +82 -0
  385. package/dist/esm/toast-helper-840fd8dc.js.map +1 -0
  386. package/dist/esm/utils-11fcde98.js +7 -0
  387. package/dist/esm/utils-11fcde98.js.map +1 -0
  388. package/dist/index.cjs.js +1 -0
  389. package/dist/index.js +1 -0
  390. package/dist/isometrik-webchat/index.esm.js +2 -0
  391. package/dist/isometrik-webchat/index.esm.js.map +1 -0
  392. package/dist/isometrik-webchat/isometrik-webchat.css +2 -0
  393. package/dist/isometrik-webchat/isometrik-webchat.esm.js +2 -0
  394. package/dist/isometrik-webchat/isometrik-webchat.esm.js.map +1 -0
  395. package/dist/isometrik-webchat/p-12774661.js +2 -0
  396. package/dist/isometrik-webchat/p-12774661.js.map +1 -0
  397. package/dist/isometrik-webchat/p-12e56271.js +549 -0
  398. package/dist/isometrik-webchat/p-12e56271.js.map +1 -0
  399. package/dist/isometrik-webchat/p-1415e589.js +2 -0
  400. package/dist/isometrik-webchat/p-1415e589.js.map +1 -0
  401. package/dist/isometrik-webchat/p-18f8d210.js +13 -0
  402. package/dist/isometrik-webchat/p-18f8d210.js.map +1 -0
  403. package/dist/isometrik-webchat/p-1b2461f4.js +357 -0
  404. package/dist/isometrik-webchat/p-1b2461f4.js.map +1 -0
  405. package/dist/isometrik-webchat/p-229095d4.js +2 -0
  406. package/dist/isometrik-webchat/p-229095d4.js.map +1 -0
  407. package/dist/isometrik-webchat/p-2953d06a.entry.js +2 -0
  408. package/dist/isometrik-webchat/p-2953d06a.entry.js.map +1 -0
  409. package/dist/isometrik-webchat/p-3004a123.js +2 -0
  410. package/dist/isometrik-webchat/p-3004a123.js.map +1 -0
  411. package/dist/isometrik-webchat/p-3044698a.js +2 -0
  412. package/dist/isometrik-webchat/p-3044698a.js.map +1 -0
  413. package/dist/isometrik-webchat/p-40517d7f.js +1098 -0
  414. package/dist/isometrik-webchat/p-40517d7f.js.map +1 -0
  415. package/dist/isometrik-webchat/p-42a62cf2.js +2 -0
  416. package/dist/isometrik-webchat/p-42a62cf2.js.map +1 -0
  417. package/dist/isometrik-webchat/p-48e1d174.js +45 -0
  418. package/dist/isometrik-webchat/p-48e1d174.js.map +1 -0
  419. package/dist/isometrik-webchat/p-48e243ec.entry.js +2 -0
  420. package/dist/isometrik-webchat/p-48e243ec.entry.js.map +1 -0
  421. package/dist/isometrik-webchat/p-4d2aca06.js +257 -0
  422. package/dist/isometrik-webchat/p-4d2aca06.js.map +1 -0
  423. package/dist/isometrik-webchat/p-610bfd8a.js +2 -0
  424. package/dist/isometrik-webchat/p-610bfd8a.js.map +1 -0
  425. package/dist/isometrik-webchat/p-674e4bb0.js +9 -0
  426. package/dist/isometrik-webchat/p-674e4bb0.js.map +1 -0
  427. package/dist/isometrik-webchat/p-8490e13d.js +192 -0
  428. package/dist/isometrik-webchat/p-8490e13d.js.map +1 -0
  429. package/dist/isometrik-webchat/p-858b0da8.entry.js +2 -0
  430. package/dist/isometrik-webchat/p-858b0da8.entry.js.map +1 -0
  431. package/dist/isometrik-webchat/p-89108249.entry.js +5010 -0
  432. package/dist/isometrik-webchat/p-89108249.entry.js.map +1 -0
  433. package/dist/isometrik-webchat/p-8dcdea59.js +2963 -0
  434. package/dist/isometrik-webchat/p-8dcdea59.js.map +1 -0
  435. package/dist/isometrik-webchat/p-92d0b21c.js +2 -0
  436. package/dist/isometrik-webchat/p-92d0b21c.js.map +1 -0
  437. package/dist/isometrik-webchat/p-ada9c8e8.entry.js +2 -0
  438. package/dist/isometrik-webchat/p-ada9c8e8.entry.js.map +1 -0
  439. package/dist/isometrik-webchat/p-adbb398d.entry.js +2 -0
  440. package/dist/isometrik-webchat/p-adbb398d.entry.js.map +1 -0
  441. package/dist/isometrik-webchat/p-b07dd267.js +2 -0
  442. package/dist/isometrik-webchat/p-b07dd267.js.map +1 -0
  443. package/dist/isometrik-webchat/p-bf0aeb22.entry.js +2 -0
  444. package/dist/isometrik-webchat/p-bf0aeb22.entry.js.map +1 -0
  445. package/dist/isometrik-webchat/p-bfd51dd4.entry.js +2 -0
  446. package/dist/isometrik-webchat/p-bfd51dd4.entry.js.map +1 -0
  447. package/dist/isometrik-webchat/p-c50aa410.entry.js +2 -0
  448. package/dist/isometrik-webchat/p-c50aa410.entry.js.map +1 -0
  449. package/dist/isometrik-webchat/p-cd34448c.entry.js +2 -0
  450. package/dist/isometrik-webchat/p-cd34448c.entry.js.map +1 -0
  451. package/dist/isometrik-webchat/p-d4b8ece6.entry.js +2 -0
  452. package/dist/isometrik-webchat/p-d4b8ece6.entry.js.map +1 -0
  453. package/dist/isometrik-webchat/p-de8a8642.js +197 -0
  454. package/dist/isometrik-webchat/p-de8a8642.js.map +1 -0
  455. package/dist/isometrik-webchat/p-e09b32eb.js +591 -0
  456. package/dist/isometrik-webchat/p-e09b32eb.js.map +1 -0
  457. package/dist/isometrik-webchat/p-e1255160.js +2 -0
  458. package/dist/isometrik-webchat/p-e1255160.js.map +1 -0
  459. package/dist/isometrik-webchat/p-e3731295.js +274 -0
  460. package/dist/isometrik-webchat/p-e3731295.js.map +1 -0
  461. package/dist/isometrik-webchat/p-e4efea64.entry.js +2 -0
  462. package/dist/isometrik-webchat/p-e4efea64.entry.js.map +1 -0
  463. package/dist/isometrik-webchat/p-ef6e482a.entry.js +2 -0
  464. package/dist/isometrik-webchat/p-ef6e482a.entry.js.map +1 -0
  465. package/dist/isometrik-webchat/p-f1f5d5bd.js +3 -0
  466. package/dist/isometrik-webchat/p-f1f5d5bd.js.map +1 -0
  467. package/dist/isometrik-webchat/p-ff9f3dfe.js +203 -0
  468. package/dist/isometrik-webchat/p-ff9f3dfe.js.map +1 -0
  469. package/dist/loader/cdn.js +1 -0
  470. package/dist/loader/index.cjs.js +1 -0
  471. package/dist/loader/index.d.ts +24 -0
  472. package/dist/loader/index.es2017.js +1 -0
  473. package/dist/loader/index.js +2 -0
  474. package/dist/loader/package.json +11 -0
  475. package/dist/types/app-root.d.ts +0 -0
  476. package/dist/types/components/ChatUIComponent/AddMember.d.ts +13 -0
  477. package/dist/types/components/ChatUIComponent/AudioBubble.d.ts +39 -0
  478. package/dist/types/components/ChatUIComponent/BlockChatList.d.ts +13 -0
  479. package/dist/types/components/ChatUIComponent/ChatDocumentMessageBubble.d.ts +5 -0
  480. package/dist/types/components/ChatUIComponent/ChatImageMessageBubble.d.ts +5 -0
  481. package/dist/types/components/ChatUIComponent/ChatOwnProfile/Profile.d.ts +42 -0
  482. package/dist/types/components/ChatUIComponent/ChatSidebar/ChatSidebar.d.ts +85 -0
  483. package/dist/types/components/ChatUIComponent/ChatVideoMessageBubble.d.ts +5 -0
  484. package/dist/types/components/ChatUIComponent/Footer/ChatFooter.d.ts +154 -0
  485. package/dist/types/components/ChatUIComponent/ForwardMessageList.d.ts +15 -0
  486. package/dist/types/components/ChatUIComponent/GroupCast.d.ts +26 -0
  487. package/dist/types/components/ChatUIComponent/Header/WebChatHeader.d.ts +45 -0
  488. package/dist/types/components/ChatUIComponent/ReactionContainer.d.ts +12 -0
  489. package/dist/types/components/ChatUIComponent/WebChatBody/WebChatBody.d.ts +120 -0
  490. package/dist/types/components/Login.d.ts +13 -0
  491. package/dist/types/components/Signup.d.ts +17 -0
  492. package/dist/types/components/chat-main.d.ts +15 -0
  493. package/dist/types/components/my-component/my-component.d.ts +16 -0
  494. package/dist/types/components/my-component/web-chat/WebchatRightSide.d.ts +42 -0
  495. package/dist/types/components/theme-provider.d.ts +44 -0
  496. package/dist/types/components.d.ts +838 -0
  497. package/dist/types/index.d.ts +37 -0
  498. package/dist/types/stencil-public-runtime.d.ts +1678 -0
  499. package/dist/types/store/conversation.d.ts +17 -0
  500. package/dist/types/store/group-members.d.ts +18 -0
  501. package/dist/types/store/unread-count.d.ts +10 -0
  502. package/dist/types/stories/Components/Toaster/toast-helper.d.ts +8 -0
  503. package/dist/types/types/ConversationDetailsTypes.d.ts +52 -0
  504. package/dist/types/utils/getFomattedDate.d.ts +1 -0
  505. package/dist/types/utils/utils.d.ts +1 -0
  506. package/package.json +89 -0
  507. package/readme.md +569 -0
@@ -0,0 +1,4365 @@
1
+ 'use strict';
2
+
3
+ const Image = require('./Image-67c52acd.js');
4
+ const dialogDrawer = require('./dialog-drawer-9d04911c.js');
5
+ require('./index-9afe62b6.js');
6
+ require('./taguser-aca04ed9.js');
7
+ require('./ReactionsContainer-a6ce9059.js');
8
+ const content = require('./content-eca5336c.js');
9
+
10
+ const videoPlaceholderSvg = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE2IDE2IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTE2IDJIMFYxNEgxNlYyWk02LjUgNVYxMUg3LjVMMTEgOEw3LjUgNUg2LjVaIiBmaWxsPSIjMDAwMDAwIi8+Cjwvc3ZnPg==';
11
+
12
+ const equalizerSvg = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iNDhweCIgdmlld0JveD0iMCAtOTYwIDk2MCA5NjAiIHdpZHRoPSI0OHB4IiBmaWxsPSIjZThlYWVkIj48cGF0aCBkPSJNMjg1LTI0MHYtNDgwaDYwdjQ4MGgtNjBaTTQ1MC04MHYtODAwaDYwdjgwMGgtNjBaTTEyMC00MDB2LTE2MGg2MHYxNjBoLTYwWm00OTUgMTYwdi00ODBoNjB2NDgwaC02MFptMTY1LTE2MHYtMTYwaDYwdjE2MGgtNjBaIi8+PC9zdmc+';
13
+
14
+ /** A simple event emitter that can be used to listen to and emit events. */
15
+ class EventEmitter {
16
+ constructor() {
17
+ this.listeners = {};
18
+ }
19
+ /** Subscribe to an event. Returns an unsubscribe function. */
20
+ on(event, listener, options) {
21
+ if (!this.listeners[event]) {
22
+ this.listeners[event] = new Set();
23
+ }
24
+ if (options === null || options === void 0 ? void 0 : options.once) {
25
+ // Create a wrapper that removes itself after being called once
26
+ const onceWrapper = (...args) => {
27
+ this.un(event, onceWrapper);
28
+ listener(...args);
29
+ };
30
+ this.listeners[event].add(onceWrapper);
31
+ return () => this.un(event, onceWrapper);
32
+ }
33
+ this.listeners[event].add(listener);
34
+ return () => this.un(event, listener);
35
+ }
36
+ /** Unsubscribe from an event */
37
+ un(event, listener) {
38
+ var _a;
39
+ (_a = this.listeners[event]) === null || _a === void 0 ? void 0 : _a.delete(listener);
40
+ }
41
+ /** Subscribe to an event only once */
42
+ once(event, listener) {
43
+ return this.on(event, listener, { once: true });
44
+ }
45
+ /** Clear all events */
46
+ unAll() {
47
+ this.listeners = {};
48
+ }
49
+ /** Emit an event */
50
+ emit(eventName, ...args) {
51
+ if (this.listeners[eventName]) {
52
+ this.listeners[eventName].forEach((listener) => listener(...args));
53
+ }
54
+ }
55
+ }
56
+
57
+ /** Base class for wavesurfer plugins */
58
+ class BasePlugin extends EventEmitter {
59
+ /** Create a plugin instance */
60
+ constructor(options) {
61
+ super();
62
+ this.subscriptions = [];
63
+ this.isDestroyed = false;
64
+ this.options = options;
65
+ }
66
+ /** Called after this.wavesurfer is available */
67
+ onInit() {
68
+ return;
69
+ }
70
+ /** Do not call directly, only called by WavesSurfer internally */
71
+ _init(wavesurfer) {
72
+ // Reset state if plugin was previously destroyed
73
+ if (this.isDestroyed) {
74
+ this.subscriptions = [];
75
+ this.isDestroyed = false;
76
+ }
77
+ this.wavesurfer = wavesurfer;
78
+ this.onInit();
79
+ }
80
+ /** Destroy the plugin and unsubscribe from all events */
81
+ destroy() {
82
+ this.emit('destroy');
83
+ this.subscriptions.forEach((unsubscribe) => unsubscribe());
84
+ this.subscriptions = [];
85
+ this.isDestroyed = true;
86
+ this.wavesurfer = undefined;
87
+ }
88
+ }
89
+
90
+ var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
91
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
92
+ return new (P || (P = Promise))(function (resolve, reject) {
93
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
94
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
95
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
96
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
97
+ });
98
+ };
99
+ /** Decode an array buffer into an audio buffer */
100
+ function decode(audioData, sampleRate) {
101
+ return __awaiter$5(this, void 0, void 0, function* () {
102
+ const audioCtx = new AudioContext({ sampleRate });
103
+ try {
104
+ return yield audioCtx.decodeAudioData(audioData);
105
+ }
106
+ finally {
107
+ // Ensure AudioContext is always closed, even on synchronous errors
108
+ if (audioCtx.state !== 'closed') {
109
+ yield audioCtx.close().catch(() => undefined);
110
+ }
111
+ }
112
+ });
113
+ }
114
+ /** Normalize peaks to -1..1 */
115
+ function normalize(channelData) {
116
+ const firstChannel = channelData[0];
117
+ if (firstChannel.some((n) => n > 1 || n < -1)) {
118
+ const length = firstChannel.length;
119
+ let max = 0;
120
+ for (let i = 0; i < length; i++) {
121
+ const absN = Math.abs(firstChannel[i]);
122
+ if (absN > max)
123
+ max = absN;
124
+ }
125
+ for (const channel of channelData) {
126
+ for (let i = 0; i < length; i++) {
127
+ channel[i] /= max;
128
+ }
129
+ }
130
+ }
131
+ return channelData;
132
+ }
133
+ /** Create an audio buffer from pre-decoded audio data */
134
+ function createBuffer(channelData, duration) {
135
+ // Validate inputs
136
+ if (!channelData || channelData.length === 0) {
137
+ throw new Error('channelData must be a non-empty array');
138
+ }
139
+ if (duration <= 0) {
140
+ throw new Error('duration must be greater than 0');
141
+ }
142
+ // If a single array of numbers is passed, make it an array of arrays
143
+ if (typeof channelData[0] === 'number')
144
+ channelData = [channelData];
145
+ // Validate channel data after conversion
146
+ if (!channelData[0] || channelData[0].length === 0) {
147
+ throw new Error('channelData must contain non-empty channel arrays');
148
+ }
149
+ // Normalize to -1..1
150
+ normalize(channelData);
151
+ // Convert to Float32Array for consistency
152
+ const float32Channels = channelData.map((channel) => channel instanceof Float32Array ? channel : Float32Array.from(channel));
153
+ return {
154
+ duration,
155
+ length: float32Channels[0].length,
156
+ sampleRate: float32Channels[0].length / duration,
157
+ numberOfChannels: float32Channels.length,
158
+ getChannelData: (i) => {
159
+ const channel = float32Channels[i];
160
+ if (!channel) {
161
+ throw new Error(`Channel ${i} not found`);
162
+ }
163
+ return channel;
164
+ },
165
+ copyFromChannel: AudioBuffer.prototype.copyFromChannel,
166
+ copyToChannel: AudioBuffer.prototype.copyToChannel,
167
+ };
168
+ }
169
+ const Decoder = {
170
+ decode,
171
+ createBuffer,
172
+ };
173
+
174
+ function renderNode(tagName, content) {
175
+ const element = content.xmlns
176
+ ? document.createElementNS(content.xmlns, tagName)
177
+ : document.createElement(tagName);
178
+ for (const [key, value] of Object.entries(content)) {
179
+ if (key === 'children' && value) {
180
+ for (const [childTag, childValue] of Object.entries(value)) {
181
+ if (childValue instanceof Node) {
182
+ element.appendChild(childValue);
183
+ }
184
+ else if (typeof childValue === 'string') {
185
+ element.appendChild(document.createTextNode(childValue));
186
+ }
187
+ else {
188
+ element.appendChild(renderNode(childTag, childValue));
189
+ }
190
+ }
191
+ }
192
+ else if (key === 'style') {
193
+ Object.assign(element.style, value);
194
+ }
195
+ else if (key === 'textContent') {
196
+ element.textContent = value;
197
+ }
198
+ else {
199
+ element.setAttribute(key, value.toString());
200
+ }
201
+ }
202
+ return element;
203
+ }
204
+ function createElement(tagName, content, container) {
205
+ const el = renderNode(tagName, content || {});
206
+ container === null || container === void 0 ? void 0 : container.appendChild(el);
207
+ return el;
208
+ }
209
+ /**
210
+ * Check if a value is an HTML element, including elements from other realms
211
+ * (e.g. an iframe), for which `instanceof HTMLElement` returns false
212
+ */
213
+ function isHTMLElement(value) {
214
+ if (value instanceof HTMLElement)
215
+ return true;
216
+ return (typeof value === 'object' &&
217
+ value !== null &&
218
+ value.nodeType === Node.ELEMENT_NODE &&
219
+ typeof value.style === 'object');
220
+ }
221
+
222
+ const dom = /*#__PURE__*/Object.freeze({
223
+ __proto__: null,
224
+ createElement: createElement,
225
+ isHTMLElement: isHTMLElement,
226
+ 'default': createElement
227
+ });
228
+
229
+ var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
230
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
231
+ return new (P || (P = Promise))(function (resolve, reject) {
232
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
233
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
234
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
235
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
236
+ });
237
+ };
238
+ function watchProgress(response, progressCallback, signal) {
239
+ return __awaiter$4(this, void 0, void 0, function* () {
240
+ var _a;
241
+ if (!response.body || !response.headers)
242
+ return;
243
+ const reader = response.body.getReader();
244
+ const contentLength = Number(response.headers.get('Content-Length')) || 0;
245
+ let receivedLength = 0;
246
+ // Abort the reader when the signal fires
247
+ const onAbort = () => {
248
+ reader.cancel();
249
+ };
250
+ if (signal) {
251
+ if (signal.aborted) {
252
+ reader.cancel();
253
+ return;
254
+ }
255
+ signal.addEventListener('abort', onAbort, { once: true });
256
+ }
257
+ // Use iteration instead of recursion to avoid stack issues
258
+ try {
259
+ while (true) {
260
+ const data = yield reader.read();
261
+ if (data.done) {
262
+ break;
263
+ }
264
+ receivedLength += ((_a = data.value) === null || _a === void 0 ? void 0 : _a.length) || 0;
265
+ // Only report progress if Content-Length is available and non-zero
266
+ if (contentLength > 0) {
267
+ const percentage = Math.round((receivedLength / contentLength) * 100);
268
+ progressCallback(percentage);
269
+ }
270
+ }
271
+ }
272
+ catch (err) {
273
+ // Ignore abort errors from reader cancellation
274
+ if (err instanceof DOMException && err.name === 'AbortError')
275
+ return;
276
+ // Ignore other errors because we can only handle the main response
277
+ console.warn('Progress tracking error:', err);
278
+ }
279
+ finally {
280
+ // Remove the abort listener to prevent leaks
281
+ if (signal) {
282
+ signal.removeEventListener('abort', onAbort);
283
+ }
284
+ }
285
+ });
286
+ }
287
+ function fetchBlob(url, progressCallback, requestInit) {
288
+ return __awaiter$4(this, void 0, void 0, function* () {
289
+ var _a;
290
+ // Fetch the resource
291
+ const response = yield fetch(url, requestInit);
292
+ if (response.status >= 400) {
293
+ throw new Error(`Failed to fetch ${url}: ${response.status} (${response.statusText})`);
294
+ }
295
+ // Read the data to track progress
296
+ // Pass the abort signal so the progress reader can be cancelled
297
+ watchProgress(response.clone(), progressCallback, (_a = requestInit === null || requestInit === void 0 ? void 0 : requestInit.signal) !== null && _a !== void 0 ? _a : undefined);
298
+ return response.blob();
299
+ });
300
+ }
301
+ const Fetcher = {
302
+ fetchBlob,
303
+ };
304
+
305
+ /**
306
+ * Reactive primitives for managing state in WaveSurfer
307
+ *
308
+ * This module provides signal-based reactivity similar to SolidJS signals.
309
+ * Signals are reactive values that notify subscribers when they change.
310
+ */
311
+ /**
312
+ * Create a reactive signal that notifies subscribers when its value changes
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * const count = signal(0)
317
+ * count.subscribe(val => console.log('Count:', val))
318
+ * count.set(5) // Logs: Count: 5
319
+ * ```
320
+ */
321
+ function signal(initialValue) {
322
+ let _value = initialValue;
323
+ const subscribers = new Set();
324
+ return {
325
+ get value() {
326
+ return _value;
327
+ },
328
+ set(newValue) {
329
+ // Only update and notify if value actually changed
330
+ if (!Object.is(_value, newValue)) {
331
+ _value = newValue;
332
+ subscribers.forEach((fn) => fn(_value));
333
+ }
334
+ },
335
+ update(fn) {
336
+ this.set(fn(_value));
337
+ },
338
+ subscribe(callback) {
339
+ subscribers.add(callback);
340
+ return () => subscribers.delete(callback);
341
+ },
342
+ };
343
+ }
344
+ /**
345
+ * Create a computed value that automatically updates when its dependencies change
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * const count = signal(0)
350
+ * const doubled = computed(() => count.value * 2, [count])
351
+ * console.log(doubled.value) // 0
352
+ * count.set(5)
353
+ * console.log(doubled.value) // 10
354
+ * ```
355
+ */
356
+ function computed(fn, dependencies) {
357
+ const result = signal(fn());
358
+ // Subscribe to all dependencies immediately
359
+ // This ensures the computed value stays in sync even if no one is subscribed to it
360
+ dependencies.forEach((dep) => dep.subscribe(() => {
361
+ const newValue = fn();
362
+ // Update the result signal, which will notify our subscribers if value changed
363
+ if (!Object.is(result.value, newValue)) {
364
+ result.set(newValue);
365
+ }
366
+ }));
367
+ // Return a read-only signal that proxies the result
368
+ return {
369
+ get value() {
370
+ return result.value;
371
+ },
372
+ subscribe(callback) {
373
+ // Just subscribe to result changes
374
+ return result.subscribe(callback);
375
+ },
376
+ };
377
+ }
378
+ /**
379
+ * Run a side effect automatically when dependencies change
380
+ *
381
+ * @param fn - Effect function. Can return a cleanup function.
382
+ * @param dependencies - Signals that trigger the effect when they change
383
+ * @returns Unsubscribe function that stops the effect and runs cleanup
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * const count = signal(0)
388
+ * effect(() => {
389
+ * console.log('Count is:', count.value)
390
+ * return () => console.log('Cleanup')
391
+ * }, [count])
392
+ * count.set(5) // Logs: Cleanup, Count is: 5
393
+ * ```
394
+ */
395
+ function effect(fn, dependencies) {
396
+ let cleanup;
397
+ const run = () => {
398
+ // Run cleanup from previous execution
399
+ if (cleanup) {
400
+ cleanup();
401
+ cleanup = undefined;
402
+ }
403
+ // Run effect and capture new cleanup
404
+ cleanup = fn();
405
+ };
406
+ // Subscribe to all dependencies
407
+ const unsubscribes = dependencies.map((dep) => dep.subscribe(run));
408
+ // Run effect immediately
409
+ run();
410
+ // Return function that unsubscribes and runs cleanup
411
+ return () => {
412
+ if (cleanup) {
413
+ cleanup();
414
+ cleanup = undefined;
415
+ }
416
+ unsubscribes.forEach((unsub) => unsub());
417
+ };
418
+ }
419
+
420
+ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
421
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
422
+ return new (P || (P = Promise))(function (resolve, reject) {
423
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
424
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
425
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
426
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
427
+ });
428
+ };
429
+ class Player extends EventEmitter {
430
+ // Expose reactive state as writable signals
431
+ // These are writable to allow WaveSurfer to compose them into centralized state
432
+ get isPlayingSignal() {
433
+ return this._isPlaying;
434
+ }
435
+ get currentTimeSignal() {
436
+ return this._currentTime;
437
+ }
438
+ get durationSignal() {
439
+ return this._duration;
440
+ }
441
+ get volumeSignal() {
442
+ return this._volume;
443
+ }
444
+ get mutedSignal() {
445
+ return this._muted;
446
+ }
447
+ get playbackRateSignal() {
448
+ return this._playbackRate;
449
+ }
450
+ get seekingSignal() {
451
+ return this._seeking;
452
+ }
453
+ constructor(options) {
454
+ super();
455
+ this.isExternalMedia = false;
456
+ this._ownBlobUrl = null;
457
+ this.reactiveMediaEventCleanups = [];
458
+ if (options.media) {
459
+ this.media = options.media;
460
+ this.isExternalMedia = true;
461
+ }
462
+ else {
463
+ this.media = document.createElement('audio');
464
+ }
465
+ // Initialize reactive state
466
+ this._isPlaying = signal(false);
467
+ this._currentTime = signal(0);
468
+ this._duration = signal(0);
469
+ this._volume = signal(this.media.volume);
470
+ this._muted = signal(this.media.muted);
471
+ this._playbackRate = signal(this.media.playbackRate || 1);
472
+ this._seeking = signal(false);
473
+ // Setup reactive media event handlers
474
+ this.setupReactiveMediaEvents();
475
+ // Controls
476
+ if (options.mediaControls) {
477
+ this.media.controls = true;
478
+ }
479
+ // Autoplay
480
+ if (options.autoplay) {
481
+ this.media.autoplay = true;
482
+ }
483
+ // Speed
484
+ if (options.playbackRate != null) {
485
+ this.onMediaEvent('canplay', () => {
486
+ if (options.playbackRate != null) {
487
+ this.media.playbackRate = options.playbackRate;
488
+ }
489
+ }, { once: true });
490
+ }
491
+ }
492
+ /**
493
+ * Setup reactive media event handlers that update signals
494
+ * This bridges the imperative HTMLMediaElement API to reactive state
495
+ */
496
+ setupReactiveMediaEvents() {
497
+ // Playing state
498
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('play', () => {
499
+ this._isPlaying.set(true);
500
+ }));
501
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('pause', () => {
502
+ this._isPlaying.set(false);
503
+ }));
504
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('ended', () => {
505
+ this._isPlaying.set(false);
506
+ }));
507
+ // Time tracking
508
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('timeupdate', () => {
509
+ this._currentTime.set(this.media.currentTime);
510
+ }));
511
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('durationchange', () => {
512
+ this._duration.set(this.media.duration || 0);
513
+ }));
514
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('loadedmetadata', () => {
515
+ this._duration.set(this.media.duration || 0);
516
+ }));
517
+ // Seeking state
518
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('seeking', () => {
519
+ this._seeking.set(true);
520
+ }));
521
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('seeked', () => {
522
+ this._seeking.set(false);
523
+ }));
524
+ // Volume and muted
525
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('volumechange', () => {
526
+ this._volume.set(this.media.volume);
527
+ this._muted.set(this.media.muted);
528
+ }));
529
+ // Playback rate
530
+ this.reactiveMediaEventCleanups.push(this.onMediaEvent('ratechange', () => {
531
+ this._playbackRate.set(this.media.playbackRate);
532
+ }));
533
+ }
534
+ onMediaEvent(event, callback, options) {
535
+ this.media.addEventListener(event, callback, options);
536
+ return () => this.media.removeEventListener(event, callback, options);
537
+ }
538
+ getSrc() {
539
+ return this.media.currentSrc || this.media.src || '';
540
+ }
541
+ revokeSrc() {
542
+ // Only revoke blob URLs that we created (not ones owned by external callers)
543
+ if (this._ownBlobUrl) {
544
+ URL.revokeObjectURL(this._ownBlobUrl);
545
+ this._ownBlobUrl = null;
546
+ }
547
+ }
548
+ canPlayType(type) {
549
+ return this.media.canPlayType(type) !== '';
550
+ }
551
+ setSrc(url, blob) {
552
+ const prevSrc = this.getSrc();
553
+ if (url && prevSrc === url)
554
+ return; // no need to change the source
555
+ this.revokeSrc();
556
+ const newSrc = blob instanceof Blob && (this.canPlayType(blob.type) || !url) ? URL.createObjectURL(blob) : url;
557
+ // Track blob URLs we created so we can revoke them on destroy
558
+ if (newSrc !== url) {
559
+ this._ownBlobUrl = newSrc;
560
+ }
561
+ // Reset the media element, otherwise it keeps the previous source
562
+ if (prevSrc) {
563
+ this.media.removeAttribute('src');
564
+ }
565
+ if (newSrc || url) {
566
+ try {
567
+ this.media.src = newSrc;
568
+ }
569
+ catch (_a) {
570
+ this.media.src = url;
571
+ }
572
+ }
573
+ }
574
+ destroy() {
575
+ // Cleanup reactive media event listeners
576
+ this.reactiveMediaEventCleanups.forEach((cleanup) => cleanup());
577
+ this.reactiveMediaEventCleanups = [];
578
+ // Revoke blob URLs that we created
579
+ this.revokeSrc();
580
+ // Clear all event emitter listeners
581
+ this.unAll();
582
+ if (this.isExternalMedia)
583
+ return;
584
+ this.media.pause();
585
+ this.media.removeAttribute('src');
586
+ // Load resets the media element to its initial state
587
+ this.media.load();
588
+ // Remove from DOM after cleanup
589
+ this.media.remove();
590
+ }
591
+ setMediaElement(element) {
592
+ // Cleanup reactive event listeners from old media element
593
+ this.reactiveMediaEventCleanups.forEach((cleanup) => cleanup());
594
+ this.reactiveMediaEventCleanups = [];
595
+ // Set new media element
596
+ this.media = element;
597
+ // Reinitialize reactive event listeners on new media element
598
+ this.setupReactiveMediaEvents();
599
+ }
600
+ /** Start playing the audio */
601
+ play() {
602
+ return __awaiter$3(this, void 0, void 0, function* () {
603
+ try {
604
+ return yield this.media.play();
605
+ }
606
+ catch (err) {
607
+ if (err instanceof DOMException && err.name === 'AbortError') {
608
+ return;
609
+ }
610
+ throw err;
611
+ }
612
+ });
613
+ }
614
+ /** Pause the audio */
615
+ pause() {
616
+ this.media.pause();
617
+ }
618
+ /** Check if the audio is playing */
619
+ isPlaying() {
620
+ return !this.media.paused && !this.media.ended;
621
+ }
622
+ /** Jump to a specific time in the audio (in seconds) */
623
+ setTime(time) {
624
+ this.media.currentTime = Math.max(0, Math.min(time, this.getDuration()));
625
+ }
626
+ /** Get the duration of the audio in seconds */
627
+ getDuration() {
628
+ return this.media.duration;
629
+ }
630
+ /** Get the current audio position in seconds */
631
+ getCurrentTime() {
632
+ return this.media.currentTime;
633
+ }
634
+ /** Get the audio volume */
635
+ getVolume() {
636
+ return this.media.volume;
637
+ }
638
+ /** Set the audio volume */
639
+ setVolume(volume) {
640
+ this.media.volume = volume;
641
+ }
642
+ /** Get the audio muted state */
643
+ getMuted() {
644
+ return this.media.muted;
645
+ }
646
+ /** Mute or unmute the audio */
647
+ setMuted(muted) {
648
+ this.media.muted = muted;
649
+ }
650
+ /** Get the playback speed */
651
+ getPlaybackRate() {
652
+ return this.media.playbackRate;
653
+ }
654
+ /** Check if the audio is seeking */
655
+ isSeeking() {
656
+ return this.media.seeking;
657
+ }
658
+ /** Set the playback speed, pass an optional false to NOT preserve the pitch */
659
+ setPlaybackRate(rate, preservePitch) {
660
+ // preservePitch is true by default in most browsers
661
+ if (preservePitch != null) {
662
+ this.media.preservesPitch = preservePitch;
663
+ }
664
+ this.media.playbackRate = rate;
665
+ }
666
+ /** Get the HTML media element */
667
+ getMediaElement() {
668
+ return this.media;
669
+ }
670
+ /** Set a sink id to change the audio output device */
671
+ setSinkId(sinkId) {
672
+ // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId
673
+ const media = this.media;
674
+ return media.setSinkId(sinkId);
675
+ }
676
+ }
677
+
678
+ const DEFAULT_HEIGHT = 128;
679
+ const MAX_CANVAS_WIDTH = 8000;
680
+ const MAX_NODES = 10;
681
+ function clampToUnit(value) {
682
+ if (value < 0)
683
+ return 0;
684
+ if (value > 1)
685
+ return 1;
686
+ return value;
687
+ }
688
+ function calculateBarRenderConfig({ width, height, length, options, pixelRatio, }) {
689
+ const halfHeight = height / 2;
690
+ const barWidth = options.barWidth ? options.barWidth * pixelRatio : 1;
691
+ const barGap = options.barGap ? options.barGap * pixelRatio : options.barWidth ? barWidth / 2 : 0;
692
+ const barRadius = options.barRadius || 0;
693
+ const barMinHeight = options.barMinHeight ? options.barMinHeight * pixelRatio : 0;
694
+ const spacing = barWidth + barGap || 1;
695
+ const barIndexScale = length > 0 ? width / spacing / length : 0;
696
+ return {
697
+ halfHeight,
698
+ barWidth,
699
+ barGap,
700
+ barRadius,
701
+ barMinHeight,
702
+ barIndexScale,
703
+ barSpacing: spacing,
704
+ };
705
+ }
706
+ function calculateBarHeights({ maxTop, maxBottom, halfHeight, vScale, barMinHeight = 0, barAlign, }) {
707
+ let topHeight = Math.round(maxTop * halfHeight * vScale);
708
+ const bottomHeight = Math.round(maxBottom * halfHeight * vScale);
709
+ let totalHeight = topHeight + bottomHeight || 1;
710
+ if (totalHeight < barMinHeight) {
711
+ totalHeight = barMinHeight;
712
+ if (!barAlign) {
713
+ topHeight = totalHeight / 2;
714
+ }
715
+ }
716
+ return { topHeight, totalHeight };
717
+ }
718
+ function resolveBarYPosition({ barAlign, halfHeight, topHeight, totalHeight, canvasHeight, }) {
719
+ if (barAlign === 'top')
720
+ return 0;
721
+ if (barAlign === 'bottom')
722
+ return canvasHeight - totalHeight;
723
+ return halfHeight - topHeight;
724
+ }
725
+ function calculateBarSegments({ channelData, barIndexScale, barSpacing, barWidth, halfHeight, vScale, canvasHeight, barAlign, barMinHeight, }) {
726
+ const topChannel = channelData[0] || [];
727
+ const bottomChannel = channelData[1] || topChannel;
728
+ const length = topChannel.length;
729
+ const segments = [];
730
+ let prevX = 0;
731
+ let maxTop = 0;
732
+ let maxBottom = 0;
733
+ for (let i = 0; i <= length; i++) {
734
+ const x = Math.round(i * barIndexScale);
735
+ if (x > prevX) {
736
+ const { topHeight, totalHeight } = calculateBarHeights({
737
+ maxTop,
738
+ maxBottom,
739
+ halfHeight,
740
+ vScale,
741
+ barMinHeight,
742
+ barAlign,
743
+ });
744
+ const y = resolveBarYPosition({
745
+ barAlign,
746
+ halfHeight,
747
+ topHeight,
748
+ totalHeight,
749
+ canvasHeight,
750
+ });
751
+ segments.push({
752
+ x: prevX * barSpacing,
753
+ y,
754
+ width: barWidth,
755
+ height: totalHeight,
756
+ });
757
+ prevX = x;
758
+ maxTop = 0;
759
+ maxBottom = 0;
760
+ }
761
+ const magnitudeTop = Math.abs(topChannel[i] || 0);
762
+ const magnitudeBottom = Math.abs(bottomChannel[i] || 0);
763
+ if (magnitudeTop > maxTop)
764
+ maxTop = magnitudeTop;
765
+ if (magnitudeBottom > maxBottom)
766
+ maxBottom = magnitudeBottom;
767
+ }
768
+ return segments;
769
+ }
770
+ function getRelativePointerPosition(rect, clientX, clientY) {
771
+ const x = clientX - rect.left;
772
+ const y = clientY - rect.top;
773
+ const relativeX = x / rect.width;
774
+ const relativeY = y / rect.height;
775
+ return [relativeX, relativeY];
776
+ }
777
+ function resolveChannelHeight({ optionsHeight, optionsSplitChannels, parentHeight, numberOfChannels, defaultHeight = DEFAULT_HEIGHT, }) {
778
+ if (optionsHeight == null)
779
+ return defaultHeight;
780
+ const numericHeight = Number(optionsHeight);
781
+ if (!isNaN(numericHeight))
782
+ return numericHeight;
783
+ if (optionsHeight === 'auto') {
784
+ const height = parentHeight || defaultHeight;
785
+ if (optionsSplitChannels === null || optionsSplitChannels === void 0 ? void 0 : optionsSplitChannels.every((channel) => !channel.overlay)) {
786
+ return height / numberOfChannels;
787
+ }
788
+ return height;
789
+ }
790
+ return defaultHeight;
791
+ }
792
+ function getPixelRatio(devicePixelRatio) {
793
+ return Math.max(1, devicePixelRatio || 1);
794
+ }
795
+ function shouldRenderBars(options) {
796
+ return Boolean(options.barWidth || options.barGap || options.barAlign);
797
+ }
798
+ function resolveColorValue(color, devicePixelRatio, canvasHeight) {
799
+ if (!Array.isArray(color))
800
+ return color || '';
801
+ if (color.length === 0)
802
+ return '#999';
803
+ if (color.length < 2)
804
+ return color[0] || '';
805
+ const canvasElement = document.createElement('canvas');
806
+ const ctx = canvasElement.getContext('2d');
807
+ if (!ctx)
808
+ return color[0] || '';
809
+ const gradientHeight = canvasHeight || canvasElement.height * devicePixelRatio;
810
+ const gradient = ctx.createLinearGradient(0, 0, 0, gradientHeight);
811
+ const colorStopPercentage = 1 / (color.length - 1);
812
+ color.forEach((value, index) => {
813
+ gradient.addColorStop(index * colorStopPercentage, value);
814
+ });
815
+ return gradient;
816
+ }
817
+ function calculateWaveformLayout({ duration, minPxPerSec = 0, parentWidth, fillParent, pixelRatio, }) {
818
+ const scrollWidth = Math.ceil(duration * minPxPerSec);
819
+ const isScrollable = scrollWidth > parentWidth;
820
+ const useParentWidth = Boolean(fillParent && !isScrollable);
821
+ const width = (useParentWidth ? parentWidth : scrollWidth) * pixelRatio;
822
+ return {
823
+ scrollWidth,
824
+ isScrollable,
825
+ useParentWidth,
826
+ width,
827
+ };
828
+ }
829
+ function clampWidthToBarGrid(width, options) {
830
+ if (!shouldRenderBars(options))
831
+ return width;
832
+ const barWidth = options.barWidth || 0.5;
833
+ const barGap = options.barGap || barWidth / 2;
834
+ const totalBarWidth = barWidth + barGap;
835
+ if (totalBarWidth === 0)
836
+ return width;
837
+ return Math.floor(width / totalBarWidth) * totalBarWidth;
838
+ }
839
+ function calculateSingleCanvasWidth({ clientWidth, totalWidth, options, }) {
840
+ const baseWidth = Math.min(MAX_CANVAS_WIDTH, clientWidth, totalWidth);
841
+ return clampWidthToBarGrid(baseWidth, options);
842
+ }
843
+ function sliceChannelData({ channelData, offset, clampedWidth, totalWidth, }) {
844
+ return channelData.map((channel) => {
845
+ const start = Math.floor((offset / totalWidth) * channel.length);
846
+ const end = Math.floor(((offset + clampedWidth) / totalWidth) * channel.length);
847
+ return channel.slice(start, end);
848
+ });
849
+ }
850
+ function shouldClearCanvases(currentNodeCount) {
851
+ return currentNodeCount > MAX_NODES;
852
+ }
853
+ function getLazyRenderRange({ scrollLeft, totalWidth, numCanvases, }) {
854
+ if (totalWidth === 0)
855
+ return [0];
856
+ const viewPosition = scrollLeft / totalWidth;
857
+ const startCanvas = Math.floor(viewPosition * numCanvases);
858
+ return [startCanvas - 1, startCanvas, startCanvas + 1];
859
+ }
860
+ function calculateVerticalScale({ channelData, barHeight, normalize, maxPeak, }) {
861
+ var _a;
862
+ const baseScale = barHeight || 1;
863
+ if (!normalize)
864
+ return baseScale;
865
+ const firstChannel = channelData[0];
866
+ if (!firstChannel || firstChannel.length === 0)
867
+ return baseScale;
868
+ // Use fixed max peak if provided, otherwise calculate from data
869
+ let max = maxPeak !== null && maxPeak !== void 0 ? maxPeak : 0;
870
+ if (!maxPeak) {
871
+ for (let i = 0; i < firstChannel.length; i++) {
872
+ const value = (_a = firstChannel[i]) !== null && _a !== void 0 ? _a : 0;
873
+ const magnitude = Math.abs(value);
874
+ if (magnitude > max)
875
+ max = magnitude;
876
+ }
877
+ }
878
+ if (!max)
879
+ return baseScale;
880
+ return baseScale / max;
881
+ }
882
+ function calculateLinePaths({ channelData, width, height, vScale, }) {
883
+ const halfHeight = height / 2;
884
+ const primaryChannel = channelData[0] || [];
885
+ const secondaryChannel = channelData[1] || primaryChannel;
886
+ const channels = [primaryChannel, secondaryChannel];
887
+ return channels.map((channel, index) => {
888
+ const length = channel.length;
889
+ const hScale = length ? width / length : 0;
890
+ const baseY = halfHeight;
891
+ const direction = index === 0 ? -1 : 1;
892
+ const path = [{ x: 0, y: baseY }];
893
+ let prevX = 0;
894
+ let max = 0;
895
+ for (let i = 0; i <= length; i++) {
896
+ const x = Math.round(i * hScale);
897
+ if (x > prevX) {
898
+ const heightDelta = Math.round(max * halfHeight * vScale) || 1;
899
+ const y = baseY + heightDelta * direction;
900
+ path.push({ x: prevX, y });
901
+ prevX = x;
902
+ max = 0;
903
+ }
904
+ const value = Math.abs(channel[i] || 0);
905
+ if (value > max)
906
+ max = value;
907
+ }
908
+ path.push({ x: prevX, y: baseY });
909
+ return path;
910
+ });
911
+ }
912
+ function roundToHalfAwayFromZero(value) {
913
+ const scaled = value * 2;
914
+ const rounded = scaled < 0 ? Math.floor(scaled) : Math.ceil(scaled);
915
+ return rounded / 2;
916
+ }
917
+
918
+ /**
919
+ * Event stream utilities for converting DOM events to reactive signals
920
+ *
921
+ * These utilities allow composing event handling using reactive primitives.
922
+ */
923
+ /**
924
+ * Cleanup a stream created with event stream utilities
925
+ *
926
+ * This removes event listeners and unsubscribes from sources.
927
+ */
928
+ function cleanup(stream) {
929
+ const cleanupFn = stream._cleanup;
930
+ if (typeof cleanupFn === 'function') {
931
+ cleanupFn();
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Reactive drag stream utilities
937
+ *
938
+ * Provides declarative drag handling using reactive streams.
939
+ * Automatically handles mouseup cleanup and supports constraints.
940
+ */
941
+ /**
942
+ * Create a reactive drag stream from an element
943
+ *
944
+ * Emits drag events (start, move, end) as the user drags the element.
945
+ * Automatically handles pointer capture, multi-touch prevention, and cleanup.
946
+ *
947
+ * @example
948
+ * ```typescript
949
+ * const dragSignal = createDragStream(element)
950
+ *
951
+ * effect(() => {
952
+ * const drag = dragSignal.value
953
+ * if (drag?.type === 'move') {
954
+ * console.log('Dragging:', drag.deltaX, drag.deltaY)
955
+ * }
956
+ * }, [dragSignal])
957
+ * ```
958
+ *
959
+ * @param element - Element to make draggable
960
+ * @param options - Drag configuration options
961
+ * @returns Signal emitting drag events and cleanup function
962
+ */
963
+ function createDragStream(element, options = {}) {
964
+ const { threshold = 3, mouseButton = 0, touchDelay = 100 } = options;
965
+ const dragSignal = signal(null);
966
+ const activePointers = new Map();
967
+ const isTouchDevice = matchMedia('(pointer: coarse)').matches;
968
+ let unsubscribeDocument = () => void 0;
969
+ const onPointerDown = (event) => {
970
+ if (event.button !== mouseButton)
971
+ return;
972
+ if (activePointers.has(event.pointerId))
973
+ return;
974
+ activePointers.set(event.pointerId, event);
975
+ if (activePointers.size > 1) {
976
+ return;
977
+ }
978
+ const dragPointerId = event.pointerId;
979
+ let startX = event.clientX;
980
+ let startY = event.clientY;
981
+ let isDragging = false;
982
+ const touchStartTime = Date.now();
983
+ const rect = element.getBoundingClientRect();
984
+ const { left, top } = rect;
985
+ const onPointerMove = (event) => {
986
+ if (event.pointerId !== dragPointerId)
987
+ return;
988
+ if (event.defaultPrevented || activePointers.size > 1) {
989
+ return;
990
+ }
991
+ if (isTouchDevice && Date.now() - touchStartTime < touchDelay)
992
+ return;
993
+ const x = event.clientX;
994
+ const y = event.clientY;
995
+ const dx = x - startX;
996
+ const dy = y - startY;
997
+ if (isDragging || Math.abs(dx) > threshold || Math.abs(dy) > threshold) {
998
+ event.preventDefault();
999
+ event.stopPropagation();
1000
+ if (!isDragging) {
1001
+ // Emit start event
1002
+ dragSignal.set({
1003
+ type: 'start',
1004
+ x: startX - left,
1005
+ y: startY - top,
1006
+ });
1007
+ isDragging = true;
1008
+ }
1009
+ // Emit move event
1010
+ dragSignal.set({
1011
+ type: 'move',
1012
+ x: x - left,
1013
+ y: y - top,
1014
+ deltaX: dx,
1015
+ deltaY: dy,
1016
+ });
1017
+ startX = x;
1018
+ startY = y;
1019
+ }
1020
+ };
1021
+ const onPointerUp = (event) => {
1022
+ // Only react to pointers that started on the element
1023
+ if (!activePointers.delete(event.pointerId))
1024
+ return;
1025
+ // Only the pointer that started the drag can end it
1026
+ if (event.pointerId === dragPointerId && isDragging) {
1027
+ const x = event.clientX;
1028
+ const y = event.clientY;
1029
+ // Emit end event
1030
+ dragSignal.set({
1031
+ type: 'end',
1032
+ x: x - left,
1033
+ y: y - top,
1034
+ });
1035
+ }
1036
+ // Keep listening until all pointers are released
1037
+ if (activePointers.size === 0) {
1038
+ unsubscribeDocument();
1039
+ }
1040
+ };
1041
+ const onPointerLeave = (e) => {
1042
+ if (!e.relatedTarget || e.relatedTarget === document.documentElement) {
1043
+ onPointerUp(e);
1044
+ }
1045
+ };
1046
+ const onClick = (event) => {
1047
+ if (isDragging) {
1048
+ event.stopPropagation();
1049
+ event.preventDefault();
1050
+ }
1051
+ };
1052
+ const onTouchMove = (event) => {
1053
+ if (event.defaultPrevented || activePointers.size > 1) {
1054
+ return;
1055
+ }
1056
+ if (isDragging) {
1057
+ event.preventDefault();
1058
+ }
1059
+ };
1060
+ document.addEventListener('pointermove', onPointerMove);
1061
+ document.addEventListener('pointerup', onPointerUp);
1062
+ document.addEventListener('pointerout', onPointerLeave);
1063
+ document.addEventListener('pointercancel', onPointerLeave);
1064
+ document.addEventListener('touchmove', onTouchMove, { passive: false });
1065
+ document.addEventListener('click', onClick, { capture: true });
1066
+ unsubscribeDocument = () => {
1067
+ document.removeEventListener('pointermove', onPointerMove);
1068
+ document.removeEventListener('pointerup', onPointerUp);
1069
+ document.removeEventListener('pointerout', onPointerLeave);
1070
+ document.removeEventListener('pointercancel', onPointerLeave);
1071
+ document.removeEventListener('touchmove', onTouchMove);
1072
+ setTimeout(() => {
1073
+ document.removeEventListener('click', onClick, { capture: true });
1074
+ }, 10);
1075
+ };
1076
+ };
1077
+ element.addEventListener('pointerdown', onPointerDown);
1078
+ const cleanupFn = () => {
1079
+ unsubscribeDocument();
1080
+ element.removeEventListener('pointerdown', onPointerDown);
1081
+ activePointers.clear();
1082
+ cleanup(dragSignal);
1083
+ };
1084
+ return {
1085
+ signal: dragSignal,
1086
+ cleanup: cleanupFn,
1087
+ };
1088
+ }
1089
+
1090
+ /**
1091
+ * Reactive scroll stream utilities
1092
+ *
1093
+ * Provides declarative scroll handling using reactive streams.
1094
+ * Automatically handles scroll event optimization and cleanup.
1095
+ */
1096
+ // ============================================================================
1097
+ // Pure Scroll Calculation Functions
1098
+ // ============================================================================
1099
+ /**
1100
+ * Calculate visible percentages from scroll data
1101
+ * Pure function - no side effects
1102
+ *
1103
+ * @param scrollData - Current scroll dimensions
1104
+ * @returns Start and end positions as percentages (0-1)
1105
+ */
1106
+ function calculateScrollPercentages(scrollData) {
1107
+ const { scrollLeft, scrollWidth, clientWidth } = scrollData;
1108
+ if (scrollWidth === 0) {
1109
+ return { startX: 0, endX: 1 };
1110
+ }
1111
+ const startX = scrollLeft / scrollWidth;
1112
+ const endX = (scrollLeft + clientWidth) / scrollWidth;
1113
+ return {
1114
+ startX: Math.max(0, Math.min(1, startX)),
1115
+ endX: Math.max(0, Math.min(1, endX)),
1116
+ };
1117
+ }
1118
+ /**
1119
+ * Calculate scroll bounds in pixels
1120
+ * Pure function - no side effects
1121
+ *
1122
+ * @param scrollData - Current scroll dimensions
1123
+ * @returns Left and right scroll bounds in pixels
1124
+ */
1125
+ function calculateScrollBounds(scrollData) {
1126
+ return {
1127
+ left: scrollData.scrollLeft,
1128
+ right: scrollData.scrollLeft + scrollData.clientWidth,
1129
+ };
1130
+ }
1131
+ /**
1132
+ * Create a reactive scroll stream from an element
1133
+ *
1134
+ * Emits scroll data as the user scrolls the element.
1135
+ * Automatically computes derived values (percentages, bounds).
1136
+ *
1137
+ * @example
1138
+ * ```typescript
1139
+ * const scrollStream = createScrollStream(container)
1140
+ *
1141
+ * effect(() => {
1142
+ * const { startX, endX } = scrollStream.percentages.value
1143
+ * console.log('Visible:', startX, 'to', endX)
1144
+ * }, [scrollStream.percentages])
1145
+ *
1146
+ * scrollStream.cleanup()
1147
+ * ```
1148
+ *
1149
+ * @param element - Scrollable element
1150
+ * @returns Scroll stream with signals and cleanup
1151
+ */
1152
+ function createScrollStream(element) {
1153
+ // Create signals
1154
+ const scrollData = signal({
1155
+ scrollLeft: element.scrollLeft,
1156
+ scrollWidth: element.scrollWidth,
1157
+ clientWidth: element.clientWidth,
1158
+ });
1159
+ // Computed derived values
1160
+ const percentages = computed(() => {
1161
+ return calculateScrollPercentages(scrollData.value);
1162
+ }, [scrollData]);
1163
+ const bounds = computed(() => {
1164
+ return calculateScrollBounds(scrollData.value);
1165
+ }, [scrollData]);
1166
+ // Update scroll data on scroll event
1167
+ const onScroll = () => {
1168
+ scrollData.set({
1169
+ scrollLeft: element.scrollLeft,
1170
+ scrollWidth: element.scrollWidth,
1171
+ clientWidth: element.clientWidth,
1172
+ });
1173
+ };
1174
+ // Attach scroll listener
1175
+ element.addEventListener('scroll', onScroll, { passive: true });
1176
+ // Cleanup function
1177
+ const cleanupFn = () => {
1178
+ element.removeEventListener('scroll', onScroll);
1179
+ cleanup(scrollData);
1180
+ };
1181
+ return {
1182
+ scrollData,
1183
+ percentages,
1184
+ bounds,
1185
+ cleanup: cleanupFn,
1186
+ };
1187
+ }
1188
+
1189
+ var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
1190
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1191
+ return new (P || (P = Promise))(function (resolve, reject) {
1192
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1193
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1194
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1195
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1196
+ });
1197
+ };
1198
+ var __rest = (undefined && undefined.__rest) || function (s, e) {
1199
+ var t = {};
1200
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
1201
+ t[p] = s[p];
1202
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
1203
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
1204
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
1205
+ t[p[i]] = s[p[i]];
1206
+ }
1207
+ return t;
1208
+ };
1209
+ const SMOOTH_SCROLL_FPS = 60;
1210
+ const SMOOTH_SCROLL_MAX_DELTA = 10;
1211
+ const LOW_ZOOM_PIXELS_PER_SECOND_THRESHOLD = SMOOTH_SCROLL_MAX_DELTA * SMOOTH_SCROLL_FPS;
1212
+ class Renderer extends EventEmitter {
1213
+ constructor(options, audioElement) {
1214
+ super();
1215
+ this.timeouts = [];
1216
+ this.isScrollable = false;
1217
+ this.audioData = null;
1218
+ this.resizeObserver = null;
1219
+ this.lastContainerWidth = 0;
1220
+ this.isDragging = false;
1221
+ this.subscriptions = [];
1222
+ this.unsubscribeOnScroll = [];
1223
+ this.dragStream = null;
1224
+ this.scrollStream = null;
1225
+ this.containerInlinePadding = 0;
1226
+ this.onClickWrapper = (e) => {
1227
+ const rect = this.wrapper.getBoundingClientRect();
1228
+ const [x, y] = getRelativePointerPosition(rect, e.clientX, e.clientY);
1229
+ this.emit('click', x, y);
1230
+ };
1231
+ this.onDblClickWrapper = (e) => {
1232
+ const rect = this.wrapper.getBoundingClientRect();
1233
+ const [x, y] = getRelativePointerPosition(rect, e.clientX, e.clientY);
1234
+ this.emit('dblclick', x, y);
1235
+ };
1236
+ this.subscriptions = [];
1237
+ this.options = options;
1238
+ const parent = this.parentFromOptionsContainer(options.container);
1239
+ this.parent = parent;
1240
+ const [div, shadow] = this.initHtml();
1241
+ parent.appendChild(div);
1242
+ this.container = div;
1243
+ this.scrollContainer = shadow.querySelector('.scroll');
1244
+ this.wrapper = shadow.querySelector('.wrapper');
1245
+ this.canvasWrapper = shadow.querySelector('.canvases');
1246
+ this.progressWrapper = shadow.querySelector('.progress');
1247
+ this.cursor = shadow.querySelector('.cursor');
1248
+ this.calculateInlinePadding();
1249
+ if (audioElement) {
1250
+ shadow.appendChild(audioElement);
1251
+ }
1252
+ this.initEvents();
1253
+ }
1254
+ parentFromOptionsContainer(container) {
1255
+ let parent;
1256
+ if (typeof container === 'string') {
1257
+ parent = document.querySelector(container);
1258
+ }
1259
+ else if (isHTMLElement(container)) {
1260
+ parent = container;
1261
+ }
1262
+ if (!parent) {
1263
+ throw new Error('Container not found');
1264
+ }
1265
+ return parent;
1266
+ }
1267
+ initEvents() {
1268
+ // Add a click listener
1269
+ this.wrapper.addEventListener('click', this.onClickWrapper);
1270
+ // Add a double click listener
1271
+ this.wrapper.addEventListener('dblclick', this.onDblClickWrapper);
1272
+ // Drag
1273
+ if (this.options.dragToSeek === true || typeof this.options.dragToSeek === 'object') {
1274
+ this.initDrag();
1275
+ }
1276
+ // Add a scroll listener using reactive stream
1277
+ this.scrollStream = createScrollStream(this.scrollContainer);
1278
+ const unsubscribeScroll = effect(() => {
1279
+ const { startX, endX } = this.scrollStream.percentages.value;
1280
+ const { left, right } = this.scrollStream.bounds.value;
1281
+ this.emit('scroll', startX, endX, left, right);
1282
+ }, [this.scrollStream.percentages, this.scrollStream.bounds]);
1283
+ this.subscriptions.push(unsubscribeScroll);
1284
+ // Re-render the waveform on container resize
1285
+ if (typeof ResizeObserver === 'function') {
1286
+ const delay = this.createDelay(100);
1287
+ this.resizeObserver = new ResizeObserver(() => {
1288
+ delay()
1289
+ .then(() => this.onContainerResize())
1290
+ .catch(() => undefined);
1291
+ });
1292
+ this.resizeObserver.observe(this.scrollContainer);
1293
+ }
1294
+ }
1295
+ onContainerResize() {
1296
+ const width = this.parent.clientWidth;
1297
+ this.calculateInlinePadding();
1298
+ if (width === this.lastContainerWidth && this.options.height !== 'auto')
1299
+ return;
1300
+ this.lastContainerWidth = width;
1301
+ this.reRender();
1302
+ this.emit('resize');
1303
+ }
1304
+ initDrag() {
1305
+ // Don't initialize drag if it's already set up
1306
+ if (this.dragStream)
1307
+ return;
1308
+ this.dragStream = createDragStream(this.wrapper);
1309
+ const unsubscribeDrag = effect(() => {
1310
+ const drag = this.dragStream.signal.value;
1311
+ if (!drag)
1312
+ return;
1313
+ const width = this.wrapper.getBoundingClientRect().width;
1314
+ const relX = clampToUnit(drag.x / width);
1315
+ if (drag.type === 'start') {
1316
+ this.isDragging = true;
1317
+ this.emit('dragstart', relX);
1318
+ }
1319
+ else if (drag.type === 'move') {
1320
+ this.emit('drag', relX);
1321
+ }
1322
+ else if (drag.type === 'end') {
1323
+ this.isDragging = false;
1324
+ this.emit('dragend', relX);
1325
+ }
1326
+ }, [this.dragStream.signal]);
1327
+ this.subscriptions.push(unsubscribeDrag);
1328
+ }
1329
+ calculateInlinePadding() {
1330
+ const { paddingLeft, paddingRight } = getComputedStyle(this.scrollContainer);
1331
+ const padding = parseFloat(paddingLeft) + parseFloat(paddingRight);
1332
+ this.containerInlinePadding = Number.isNaN(padding) ? 0 : padding;
1333
+ }
1334
+ initHtml() {
1335
+ const div = document.createElement('div');
1336
+ const shadow = div.attachShadow({ mode: 'open' });
1337
+ const cspNonce = this.options.cspNonce && typeof this.options.cspNonce === 'string' ? this.options.cspNonce.replace(/"/g, '') : '';
1338
+ shadow.innerHTML = `
1339
+ <style${cspNonce ? ` nonce="${cspNonce}"` : ''}>
1340
+ :host {
1341
+ user-select: none;
1342
+ min-width: 1px;
1343
+ }
1344
+ :host audio {
1345
+ display: block;
1346
+ width: 100%;
1347
+ }
1348
+ :host .scroll {
1349
+ overflow-x: auto;
1350
+ overflow-y: hidden;
1351
+ width: 100%;
1352
+ position: relative;
1353
+ }
1354
+ :host .noScrollbar {
1355
+ scrollbar-color: transparent;
1356
+ scrollbar-width: none;
1357
+ }
1358
+ :host .noScrollbar::-webkit-scrollbar {
1359
+ display: none;
1360
+ -webkit-appearance: none;
1361
+ }
1362
+ :host .wrapper {
1363
+ position: relative;
1364
+ overflow: visible;
1365
+ z-index: 2;
1366
+ }
1367
+ :host .canvases {
1368
+ min-height: ${this.getHeight(this.options.height, this.options.splitChannels)}px;
1369
+ pointer-events: none;
1370
+ }
1371
+ :host .canvases > div {
1372
+ position: relative;
1373
+ }
1374
+ :host canvas {
1375
+ display: block;
1376
+ position: absolute;
1377
+ top: 0;
1378
+ image-rendering: pixelated;
1379
+ }
1380
+ :host .progress {
1381
+ pointer-events: none;
1382
+ position: absolute;
1383
+ z-index: 2;
1384
+ top: 0;
1385
+ left: 0;
1386
+ width: 0;
1387
+ height: 100%;
1388
+ overflow: hidden;
1389
+ }
1390
+ :host .progress > div {
1391
+ position: relative;
1392
+ }
1393
+ :host .cursor {
1394
+ pointer-events: none;
1395
+ position: absolute;
1396
+ z-index: 5;
1397
+ top: 0;
1398
+ left: 0;
1399
+ height: 100%;
1400
+ border-radius: 2px;
1401
+ }
1402
+ </style>
1403
+
1404
+ <div class="scroll" part="scroll">
1405
+ <div class="wrapper" part="wrapper">
1406
+ <div class="canvases" part="canvases"></div>
1407
+ <div class="progress" part="progress"></div>
1408
+ <div class="cursor" part="cursor"></div>
1409
+ </div>
1410
+ </div>
1411
+ `;
1412
+ return [div, shadow];
1413
+ }
1414
+ /** Wavesurfer itself calls this method. Do not call it manually. */
1415
+ setOptions(options) {
1416
+ var _a;
1417
+ if (this.options.container !== options.container) {
1418
+ const newParent = this.parentFromOptionsContainer(options.container);
1419
+ newParent.appendChild(this.container);
1420
+ this.parent = newParent;
1421
+ }
1422
+ if (options.dragToSeek === true || typeof this.options.dragToSeek === 'object') {
1423
+ this.initDrag();
1424
+ }
1425
+ else {
1426
+ (_a = this.dragStream) === null || _a === void 0 ? void 0 : _a.cleanup();
1427
+ this.dragStream = null;
1428
+ }
1429
+ this.options = options;
1430
+ // Re-render the waveform
1431
+ this.reRender();
1432
+ }
1433
+ getWrapper() {
1434
+ return this.wrapper;
1435
+ }
1436
+ getWidth() {
1437
+ return this.scrollContainer.clientWidth - this.containerInlinePadding;
1438
+ }
1439
+ getScroll() {
1440
+ return this.scrollContainer.scrollLeft;
1441
+ }
1442
+ setScroll(pixels) {
1443
+ this.scrollContainer.scrollLeft = pixels;
1444
+ }
1445
+ setScrollPercentage(percent) {
1446
+ const { scrollWidth } = this.scrollContainer;
1447
+ const scrollStart = scrollWidth * percent;
1448
+ this.setScroll(scrollStart);
1449
+ }
1450
+ destroy() {
1451
+ var _a;
1452
+ // Remove DOM event listeners
1453
+ this.wrapper.removeEventListener('click', this.onClickWrapper);
1454
+ this.wrapper.removeEventListener('dblclick', this.onDblClickWrapper);
1455
+ // Clean up all timeouts
1456
+ this.timeouts.forEach((clear) => clear());
1457
+ this.timeouts = [];
1458
+ this.subscriptions.forEach((unsubscribe) => unsubscribe());
1459
+ this.container.remove();
1460
+ if (this.resizeObserver) {
1461
+ this.resizeObserver.disconnect();
1462
+ this.resizeObserver = null;
1463
+ }
1464
+ (_a = this.unsubscribeOnScroll) === null || _a === void 0 ? void 0 : _a.forEach((unsubscribe) => unsubscribe());
1465
+ this.unsubscribeOnScroll = [];
1466
+ if (this.dragStream) {
1467
+ this.dragStream.cleanup();
1468
+ this.dragStream = null;
1469
+ }
1470
+ if (this.scrollStream) {
1471
+ this.scrollStream.cleanup();
1472
+ this.scrollStream = null;
1473
+ }
1474
+ }
1475
+ createDelay(delayMs = 10) {
1476
+ let timeout;
1477
+ let rejectFn;
1478
+ const onClear = () => {
1479
+ if (timeout) {
1480
+ clearTimeout(timeout);
1481
+ timeout = undefined;
1482
+ }
1483
+ if (rejectFn) {
1484
+ rejectFn();
1485
+ rejectFn = undefined;
1486
+ }
1487
+ };
1488
+ this.timeouts.push(onClear);
1489
+ return () => {
1490
+ return new Promise((resolve, reject) => {
1491
+ // Clear any pending delay
1492
+ onClear();
1493
+ // Store reject function for cleanup
1494
+ rejectFn = reject;
1495
+ // Set new timeout
1496
+ timeout = setTimeout(() => {
1497
+ timeout = undefined;
1498
+ rejectFn = undefined;
1499
+ resolve();
1500
+ }, delayMs);
1501
+ });
1502
+ };
1503
+ }
1504
+ getHeight(optionsHeight, optionsSplitChannel) {
1505
+ var _a;
1506
+ const numberOfChannels = ((_a = this.audioData) === null || _a === void 0 ? void 0 : _a.numberOfChannels) || 1;
1507
+ return resolveChannelHeight({
1508
+ optionsHeight,
1509
+ optionsSplitChannels: optionsSplitChannel,
1510
+ parentHeight: this.parent.clientHeight,
1511
+ numberOfChannels,
1512
+ defaultHeight: DEFAULT_HEIGHT,
1513
+ });
1514
+ }
1515
+ convertColorValues(color, ctx) {
1516
+ return resolveColorValue(color, this.getPixelRatio(), ctx === null || ctx === void 0 ? void 0 : ctx.canvas.height);
1517
+ }
1518
+ getPixelRatio() {
1519
+ return getPixelRatio(window.devicePixelRatio);
1520
+ }
1521
+ renderBarWaveform(channelData, options, ctx, vScale) {
1522
+ const { width, height } = ctx.canvas;
1523
+ const { halfHeight, barWidth, barRadius, barIndexScale, barSpacing, barMinHeight } = calculateBarRenderConfig({
1524
+ width,
1525
+ height,
1526
+ length: (channelData[0] || []).length,
1527
+ options,
1528
+ pixelRatio: this.getPixelRatio(),
1529
+ });
1530
+ const segments = calculateBarSegments({
1531
+ channelData,
1532
+ barIndexScale,
1533
+ barSpacing,
1534
+ barWidth,
1535
+ halfHeight,
1536
+ vScale,
1537
+ canvasHeight: height,
1538
+ barAlign: options.barAlign,
1539
+ barMinHeight,
1540
+ });
1541
+ ctx.beginPath();
1542
+ for (const segment of segments) {
1543
+ if (barRadius && 'roundRect' in ctx) {
1544
+ ctx.roundRect(segment.x, segment.y, segment.width, segment.height, barRadius);
1545
+ }
1546
+ else {
1547
+ ctx.rect(segment.x, segment.y, segment.width, segment.height);
1548
+ }
1549
+ }
1550
+ ctx.fill();
1551
+ ctx.closePath();
1552
+ }
1553
+ renderLineWaveform(channelData, _options, ctx, vScale) {
1554
+ const { width, height } = ctx.canvas;
1555
+ const paths = calculateLinePaths({ channelData, width, height, vScale });
1556
+ ctx.beginPath();
1557
+ for (const path of paths) {
1558
+ if (!path.length)
1559
+ continue;
1560
+ ctx.moveTo(path[0].x, path[0].y);
1561
+ for (let i = 1; i < path.length; i++) {
1562
+ const point = path[i];
1563
+ ctx.lineTo(point.x, point.y);
1564
+ }
1565
+ }
1566
+ ctx.fill();
1567
+ ctx.closePath();
1568
+ }
1569
+ renderWaveform(channelData, options, ctx) {
1570
+ ctx.fillStyle = this.convertColorValues(options.waveColor, ctx);
1571
+ if (options.renderFunction) {
1572
+ options.renderFunction(channelData, ctx);
1573
+ return;
1574
+ }
1575
+ const vScale = calculateVerticalScale({
1576
+ channelData,
1577
+ barHeight: options.barHeight,
1578
+ normalize: options.normalize,
1579
+ maxPeak: options.maxPeak,
1580
+ });
1581
+ if (shouldRenderBars(options)) {
1582
+ this.renderBarWaveform(channelData, options, ctx, vScale);
1583
+ return;
1584
+ }
1585
+ this.renderLineWaveform(channelData, options, ctx, vScale);
1586
+ }
1587
+ renderSingleCanvas(data, options, width, height, offset, canvasContainer, progressContainer) {
1588
+ const pixelRatio = this.getPixelRatio();
1589
+ const canvas = document.createElement('canvas');
1590
+ canvas.width = Math.round(width * pixelRatio);
1591
+ canvas.height = Math.round(height * pixelRatio);
1592
+ canvas.style.width = `${width}px`;
1593
+ canvas.style.height = `${height}px`;
1594
+ canvas.style.left = `${Math.round(offset)}px`;
1595
+ canvasContainer.appendChild(canvas);
1596
+ const ctx = canvas.getContext('2d');
1597
+ if (options.renderFunction) {
1598
+ ctx.fillStyle = this.convertColorValues(options.waveColor, ctx);
1599
+ options.renderFunction(data, ctx);
1600
+ }
1601
+ else {
1602
+ this.renderWaveform(data, options, ctx);
1603
+ }
1604
+ // Draw a progress canvas
1605
+ if (canvas.width > 0 && canvas.height > 0) {
1606
+ const progressCanvas = canvas.cloneNode();
1607
+ const progressCtx = progressCanvas.getContext('2d');
1608
+ progressCtx.drawImage(canvas, 0, 0);
1609
+ // Set the composition method to draw only where the waveform is drawn
1610
+ progressCtx.globalCompositeOperation = 'source-in';
1611
+ progressCtx.fillStyle = this.convertColorValues(options.progressColor, progressCtx);
1612
+ // This rectangle acts as a mask thanks to the composition method
1613
+ progressCtx.fillRect(0, 0, canvas.width, canvas.height);
1614
+ progressContainer.appendChild(progressCanvas);
1615
+ }
1616
+ }
1617
+ renderMultiCanvas(channelData, options, width, height, canvasContainer, progressContainer) {
1618
+ const pixelRatio = this.getPixelRatio();
1619
+ const { clientWidth } = this.scrollContainer;
1620
+ const totalWidth = width / pixelRatio;
1621
+ const singleCanvasWidth = calculateSingleCanvasWidth({ clientWidth, totalWidth, options });
1622
+ let drawnIndexes = {};
1623
+ // Nothing to render
1624
+ if (singleCanvasWidth === 0)
1625
+ return;
1626
+ // Draw a single canvas
1627
+ const draw = (index) => {
1628
+ if (index < 0 || index >= numCanvases)
1629
+ return;
1630
+ if (drawnIndexes[index])
1631
+ return;
1632
+ drawnIndexes[index] = true;
1633
+ const offset = index * singleCanvasWidth;
1634
+ let clampedWidth = Math.min(totalWidth - offset, singleCanvasWidth);
1635
+ // Clamp the width to the bar grid to avoid empty canvases at the end
1636
+ clampedWidth = clampWidthToBarGrid(clampedWidth, options);
1637
+ if (clampedWidth <= 0)
1638
+ return;
1639
+ const data = sliceChannelData({ channelData, offset, clampedWidth, totalWidth });
1640
+ this.renderSingleCanvas(data, options, clampedWidth, height, offset, canvasContainer, progressContainer);
1641
+ };
1642
+ // Clear canvases to avoid too many DOM nodes
1643
+ const clearCanvases = () => {
1644
+ if (shouldClearCanvases(Object.keys(drawnIndexes).length)) {
1645
+ canvasContainer.innerHTML = '';
1646
+ progressContainer.innerHTML = '';
1647
+ drawnIndexes = {};
1648
+ }
1649
+ };
1650
+ // Calculate how many canvases to render
1651
+ const numCanvases = Math.ceil(totalWidth / singleCanvasWidth);
1652
+ // Render all canvases if the waveform doesn't scroll
1653
+ if (!this.isScrollable) {
1654
+ for (let i = 0; i < numCanvases; i++) {
1655
+ draw(i);
1656
+ }
1657
+ return;
1658
+ }
1659
+ // Lazy rendering
1660
+ const initialRange = getLazyRenderRange({
1661
+ scrollLeft: this.scrollContainer.scrollLeft,
1662
+ totalWidth,
1663
+ numCanvases,
1664
+ });
1665
+ initialRange.forEach((index) => draw(index));
1666
+ // Subscribe to the scroll event to draw additional canvases
1667
+ if (numCanvases > 1) {
1668
+ const unsubscribe = this.on('scroll', () => {
1669
+ const { scrollLeft } = this.scrollContainer;
1670
+ clearCanvases();
1671
+ getLazyRenderRange({ scrollLeft, totalWidth, numCanvases }).forEach((index) => draw(index));
1672
+ });
1673
+ this.unsubscribeOnScroll.push(unsubscribe);
1674
+ }
1675
+ }
1676
+ renderChannel(channelData, _a, width, channelIndex) {
1677
+ var { overlay } = _a, options = __rest(_a, ["overlay"]);
1678
+ // A container for canvases
1679
+ const canvasContainer = document.createElement('div');
1680
+ const height = this.getHeight(options.height, options.splitChannels);
1681
+ canvasContainer.style.height = `${height}px`;
1682
+ if (overlay && channelIndex > 0) {
1683
+ canvasContainer.style.marginTop = `-${height}px`;
1684
+ }
1685
+ this.canvasWrapper.style.minHeight = `${height}px`;
1686
+ this.canvasWrapper.appendChild(canvasContainer);
1687
+ // A container for progress canvases
1688
+ const progressContainer = canvasContainer.cloneNode();
1689
+ this.progressWrapper.appendChild(progressContainer);
1690
+ // Render the waveform
1691
+ this.renderMultiCanvas(channelData, options, width, height, canvasContainer, progressContainer);
1692
+ }
1693
+ render(audioData) {
1694
+ return __awaiter$2(this, void 0, void 0, function* () {
1695
+ var _a;
1696
+ // Clear previous timeouts
1697
+ this.timeouts.forEach((clear) => clear());
1698
+ this.timeouts = [];
1699
+ // Clear scroll subscriptions from previous render
1700
+ this.unsubscribeOnScroll.forEach((unsubscribe) => unsubscribe());
1701
+ this.unsubscribeOnScroll = [];
1702
+ // Clear the canvases
1703
+ this.canvasWrapper.innerHTML = '';
1704
+ this.progressWrapper.innerHTML = '';
1705
+ // Width
1706
+ if (this.options.width != null) {
1707
+ this.scrollContainer.style.width =
1708
+ typeof this.options.width === 'number' ? `${this.options.width}px` : this.options.width;
1709
+ }
1710
+ // Determine the width of the waveform
1711
+ const pixelRatio = this.getPixelRatio();
1712
+ const parentWidth = this.scrollContainer.clientWidth - this.containerInlinePadding;
1713
+ const { scrollWidth, isScrollable, useParentWidth, width } = calculateWaveformLayout({
1714
+ duration: audioData.duration,
1715
+ minPxPerSec: this.options.minPxPerSec || 0,
1716
+ parentWidth,
1717
+ fillParent: this.options.fillParent,
1718
+ pixelRatio,
1719
+ });
1720
+ // Whether the container should scroll
1721
+ this.isScrollable = isScrollable;
1722
+ // Set the width of the wrapper
1723
+ this.wrapper.style.width = useParentWidth ? '100%' : `${scrollWidth}px`;
1724
+ // Set additional styles
1725
+ this.scrollContainer.style.overflowX = this.isScrollable ? 'auto' : 'hidden';
1726
+ this.scrollContainer.classList.toggle('noScrollbar', !!this.options.hideScrollbar);
1727
+ this.cursor.style.backgroundColor = `${this.options.cursorColor || this.options.progressColor}`;
1728
+ this.cursor.style.width = `${this.options.cursorWidth}px`;
1729
+ this.audioData = audioData;
1730
+ this.emit('render');
1731
+ // Render the waveform
1732
+ if (this.options.splitChannels) {
1733
+ // Render a waveform for each channel
1734
+ for (let i = 0; i < audioData.numberOfChannels; i++) {
1735
+ const options = Object.assign(Object.assign({}, this.options), (_a = this.options.splitChannels) === null || _a === void 0 ? void 0 : _a[i]);
1736
+ this.renderChannel([audioData.getChannelData(i)], options, width, i);
1737
+ }
1738
+ }
1739
+ else {
1740
+ // Render a single waveform for the first two channels (left and right)
1741
+ const channels = [audioData.getChannelData(0)];
1742
+ if (audioData.numberOfChannels > 1)
1743
+ channels.push(audioData.getChannelData(1));
1744
+ this.renderChannel(channels, this.options, width, 0);
1745
+ }
1746
+ // Must be emitted asynchronously for backward compatibility
1747
+ Promise.resolve().then(() => this.emit('rendered'));
1748
+ });
1749
+ }
1750
+ reRender() {
1751
+ this.unsubscribeOnScroll.forEach((unsubscribe) => unsubscribe());
1752
+ this.unsubscribeOnScroll = [];
1753
+ // Return if the waveform has not been rendered yet
1754
+ if (!this.audioData)
1755
+ return;
1756
+ // Remember the current cursor position
1757
+ const { scrollWidth } = this.scrollContainer;
1758
+ const { right: before } = this.progressWrapper.getBoundingClientRect();
1759
+ // Re-render the waveform
1760
+ this.render(this.audioData);
1761
+ // Adjust the scroll position so that the cursor stays in the same place
1762
+ if (!this.isScrollable && this.scrollContainer.scrollLeft) {
1763
+ this.scrollContainer.scrollLeft = 0;
1764
+ }
1765
+ else if (this.isScrollable && scrollWidth !== this.scrollContainer.scrollWidth) {
1766
+ const { right: after } = this.progressWrapper.getBoundingClientRect();
1767
+ const delta = roundToHalfAwayFromZero(after - before);
1768
+ this.scrollContainer.scrollLeft += delta;
1769
+ }
1770
+ }
1771
+ zoom(minPxPerSec) {
1772
+ this.options.minPxPerSec = minPxPerSec;
1773
+ this.reRender();
1774
+ }
1775
+ scrollIntoView(progress, isPlaying = false) {
1776
+ var _a;
1777
+ const { scrollLeft, scrollWidth, clientWidth } = this.scrollContainer;
1778
+ const progressWidth = progress * scrollWidth;
1779
+ const startEdge = scrollLeft;
1780
+ const endEdge = scrollLeft + clientWidth;
1781
+ const middle = clientWidth / 2;
1782
+ if (this.isDragging) {
1783
+ // Scroll when dragging close to the edge of the viewport
1784
+ const minGap = 30;
1785
+ if (progressWidth + minGap > endEdge) {
1786
+ this.scrollContainer.scrollLeft += minGap;
1787
+ }
1788
+ else if (progressWidth - minGap < startEdge) {
1789
+ this.scrollContainer.scrollLeft -= minGap;
1790
+ }
1791
+ }
1792
+ else {
1793
+ if (progressWidth < startEdge || progressWidth > endEdge) {
1794
+ this.scrollContainer.scrollLeft = progressWidth - (this.options.autoCenter ? middle : 0);
1795
+ }
1796
+ // Keep the cursor centered when playing
1797
+ const center = progressWidth - scrollLeft - middle;
1798
+ if (isPlaying && this.options.autoCenter && center > 0) {
1799
+ const duration = (_a = this.audioData) === null || _a === void 0 ? void 0 : _a.duration;
1800
+ if (duration === undefined || duration <= 0) {
1801
+ this.scrollContainer.scrollLeft += center;
1802
+ return;
1803
+ }
1804
+ const pixelsPerSecond = scrollWidth / duration;
1805
+ if (pixelsPerSecond <= LOW_ZOOM_PIXELS_PER_SECOND_THRESHOLD) {
1806
+ this.scrollContainer.scrollLeft += Math.min(center, SMOOTH_SCROLL_MAX_DELTA);
1807
+ }
1808
+ else {
1809
+ this.scrollContainer.scrollLeft += center;
1810
+ }
1811
+ }
1812
+ }
1813
+ }
1814
+ renderProgress(progress, isPlaying) {
1815
+ if (isNaN(progress))
1816
+ return;
1817
+ const percents = progress * 100;
1818
+ this.canvasWrapper.style.clipPath = `polygon(${percents}% 0%, 100% 0%, 100% 100%, ${percents}% 100%)`;
1819
+ this.progressWrapper.style.width = `${percents}%`;
1820
+ this.cursor.style.left = `${percents}%`;
1821
+ this.cursor.style.transform = this.options.cursorWidth
1822
+ ? `translateX(-${progress * this.options.cursorWidth}px)`
1823
+ : '';
1824
+ // Only scroll if we have valid audio data to prevent race conditions during loading
1825
+ if (this.isScrollable && this.options.autoScroll && this.audioData && this.audioData.duration > 0) {
1826
+ this.scrollIntoView(progress, isPlaying);
1827
+ }
1828
+ }
1829
+ exportImage(format, quality, type) {
1830
+ return __awaiter$2(this, void 0, void 0, function* () {
1831
+ const canvases = this.canvasWrapper.querySelectorAll('canvas');
1832
+ if (!canvases.length) {
1833
+ throw new Error('No waveform data');
1834
+ }
1835
+ // Data URLs
1836
+ if (type === 'dataURL') {
1837
+ const images = Array.from(canvases).map((canvas) => canvas.toDataURL(format, quality));
1838
+ return Promise.resolve(images);
1839
+ }
1840
+ // Blobs
1841
+ return Promise.all(Array.from(canvases).map((canvas) => {
1842
+ return new Promise((resolve, reject) => {
1843
+ canvas.toBlob((blob) => {
1844
+ if (blob) {
1845
+ resolve(blob);
1846
+ }
1847
+ else {
1848
+ reject(new Error('Could not export image'));
1849
+ }
1850
+ }, format, quality);
1851
+ });
1852
+ }));
1853
+ });
1854
+ }
1855
+ }
1856
+
1857
+ class Timer extends EventEmitter {
1858
+ constructor() {
1859
+ super(...arguments);
1860
+ this.animationFrameId = null;
1861
+ this.isRunning = false;
1862
+ }
1863
+ start() {
1864
+ // Prevent multiple simultaneous loops
1865
+ if (this.isRunning)
1866
+ return;
1867
+ this.isRunning = true;
1868
+ const tick = () => {
1869
+ // Only continue if timer is still running
1870
+ if (!this.isRunning)
1871
+ return;
1872
+ this.emit('tick');
1873
+ // Schedule next frame
1874
+ this.animationFrameId = requestAnimationFrame(tick);
1875
+ };
1876
+ // Start the loop
1877
+ tick();
1878
+ }
1879
+ stop() {
1880
+ this.isRunning = false;
1881
+ // Cancel any pending animation frame
1882
+ if (this.animationFrameId !== null) {
1883
+ cancelAnimationFrame(this.animationFrameId);
1884
+ this.animationFrameId = null;
1885
+ }
1886
+ }
1887
+ destroy() {
1888
+ this.stop();
1889
+ this.unAll();
1890
+ }
1891
+ }
1892
+
1893
+ var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
1894
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1895
+ return new (P || (P = Promise))(function (resolve, reject) {
1896
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1897
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1898
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1899
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1900
+ });
1901
+ };
1902
+ function setWebAudioSessionPlayback() {
1903
+ const navigator = globalThis.navigator;
1904
+ if (!(navigator === null || navigator === void 0 ? void 0 : navigator.audioSession))
1905
+ return;
1906
+ try {
1907
+ navigator.audioSession.type = 'playback';
1908
+ }
1909
+ catch (e) {
1910
+ console.warn('Setting navigator.audioSession.type failed:', e);
1911
+ }
1912
+ }
1913
+ /**
1914
+ * A Web Audio buffer player emulating the behavior of an HTML5 Audio element.
1915
+ *
1916
+ * Note: This class does not manage blob: URLs. If you pass a blob: URL to setSrc(),
1917
+ * you are responsible for revoking it when done. The Player class (player.ts) handles
1918
+ * blob URL lifecycle management automatically.
1919
+ */
1920
+ class WebAudioPlayer extends EventEmitter {
1921
+ constructor(audioContext) {
1922
+ super();
1923
+ this.bufferNode = null;
1924
+ this.playStartTime = 0;
1925
+ this.playbackPosition = 0;
1926
+ this._muted = false;
1927
+ this._playbackRate = 1;
1928
+ this._duration = undefined;
1929
+ this.buffer = null;
1930
+ this.currentSrc = '';
1931
+ this.paused = true;
1932
+ this.crossOrigin = null;
1933
+ this.seeking = false;
1934
+ this.autoplay = false;
1935
+ /** Subscribe to an event. Returns an unsubscribe function. */
1936
+ this.addEventListener = this.on;
1937
+ /** Unsubscribe from an event */
1938
+ this.removeEventListener = this.un;
1939
+ this._destroyed = false;
1940
+ setWebAudioSessionPlayback();
1941
+ this.audioContext = audioContext || new AudioContext();
1942
+ this.gainNode = this.audioContext.createGain();
1943
+ this.gainNode.connect(this.audioContext.destination);
1944
+ }
1945
+ load() {
1946
+ return __awaiter$1(this, void 0, void 0, function* () {
1947
+ return;
1948
+ });
1949
+ }
1950
+ /** For compatibility with HTMLMediaElement.remove(). Delegates to destroy(). */
1951
+ remove() {
1952
+ this.destroy();
1953
+ }
1954
+ /** Clean up all resources. Idempotent — safe to call multiple times. */
1955
+ destroy() {
1956
+ if (this._destroyed)
1957
+ return;
1958
+ this._destroyed = true;
1959
+ // Clear currentSrc so any in-flight fetch/decode chains bail out
1960
+ // via their existing `this.currentSrc !== value` guards
1961
+ this.currentSrc = '';
1962
+ // Stop and disconnect buffer node
1963
+ if (this.bufferNode) {
1964
+ this.bufferNode.onended = null;
1965
+ try {
1966
+ this.bufferNode.stop();
1967
+ }
1968
+ catch (_a) {
1969
+ // Ignore InvalidStateError if node already stopped
1970
+ }
1971
+ this.bufferNode.disconnect();
1972
+ this.bufferNode = null;
1973
+ }
1974
+ // Disconnect gain node
1975
+ this.gainNode.disconnect();
1976
+ // Close audio context (returns a promise, catch rejection if already closed)
1977
+ // Guard with typeof check for mock environments where close may not exist
1978
+ if (typeof this.audioContext.close === 'function') {
1979
+ Promise.resolve(this.audioContext.close.call(this.audioContext)).catch(() => undefined);
1980
+ }
1981
+ // Clear buffer reference
1982
+ this.buffer = null;
1983
+ // Clear all event listeners
1984
+ this.unAll();
1985
+ }
1986
+ get src() {
1987
+ return this.currentSrc;
1988
+ }
1989
+ set src(value) {
1990
+ this.currentSrc = value;
1991
+ this._duration = undefined;
1992
+ if (!value) {
1993
+ this.buffer = null;
1994
+ this.emit('emptied');
1995
+ return;
1996
+ }
1997
+ fetch(value)
1998
+ .then((response) => {
1999
+ if (response.status >= 400) {
2000
+ throw new Error(`Failed to fetch ${value}: ${response.status} (${response.statusText})`);
2001
+ }
2002
+ return response.arrayBuffer();
2003
+ })
2004
+ .then((arrayBuffer) => {
2005
+ if (this.currentSrc !== value)
2006
+ return null;
2007
+ return this.audioContext.decodeAudioData(arrayBuffer);
2008
+ })
2009
+ .then((audioBuffer) => {
2010
+ if (this.currentSrc !== value)
2011
+ return;
2012
+ this.buffer = audioBuffer;
2013
+ this.emit('loadedmetadata');
2014
+ this.emit('canplay');
2015
+ if (this.autoplay)
2016
+ this.play();
2017
+ })
2018
+ .catch((err) => {
2019
+ // Emit error for proper error handling
2020
+ console.error('WebAudioPlayer load error:', err);
2021
+ });
2022
+ }
2023
+ _play() {
2024
+ if (!this.paused)
2025
+ return;
2026
+ this.paused = false;
2027
+ // Clean up old buffer node completely before creating new one
2028
+ if (this.bufferNode) {
2029
+ this.bufferNode.onended = null;
2030
+ this.bufferNode.disconnect();
2031
+ }
2032
+ this.bufferNode = this.audioContext.createBufferSource();
2033
+ if (this.buffer) {
2034
+ this.bufferNode.buffer = this.buffer;
2035
+ }
2036
+ this.bufferNode.playbackRate.value = this._playbackRate;
2037
+ this.bufferNode.connect(this.gainNode);
2038
+ let currentPos = this.playbackPosition;
2039
+ if (currentPos >= this.duration || currentPos < 0) {
2040
+ currentPos = 0;
2041
+ this.playbackPosition = 0;
2042
+ }
2043
+ this.bufferNode.start(this.audioContext.currentTime, currentPos);
2044
+ this.playStartTime = this.audioContext.currentTime;
2045
+ this.bufferNode.onended = () => {
2046
+ if (!this.paused && this.duration - this.currentTime < 0.01) {
2047
+ this.pause();
2048
+ this.emit('ended');
2049
+ }
2050
+ };
2051
+ }
2052
+ _pause() {
2053
+ this.paused = true;
2054
+ // Clear onended before stopping to prevent spurious 'ended' event
2055
+ if (this.bufferNode) {
2056
+ this.bufferNode.onended = null;
2057
+ try {
2058
+ this.bufferNode.stop();
2059
+ }
2060
+ catch (_a) {
2061
+ // Ignore InvalidStateError if node already stopped
2062
+ }
2063
+ }
2064
+ this.playbackPosition += (this.audioContext.currentTime - this.playStartTime) * this._playbackRate;
2065
+ }
2066
+ play() {
2067
+ return __awaiter$1(this, void 0, void 0, function* () {
2068
+ if (!this.paused)
2069
+ return;
2070
+ this._play();
2071
+ this.emit('play');
2072
+ });
2073
+ }
2074
+ pause() {
2075
+ if (this.paused)
2076
+ return;
2077
+ this._pause();
2078
+ this.emit('pause');
2079
+ }
2080
+ stopAt(timeSeconds) {
2081
+ // The stop is scheduled on the AudioContext clock, so convert the remaining
2082
+ // media time to real time via the playback rate
2083
+ const delay = (timeSeconds - this.currentTime) / this._playbackRate;
2084
+ const currentBufferNode = this.bufferNode;
2085
+ currentBufferNode === null || currentBufferNode === void 0 ? void 0 : currentBufferNode.stop(this.audioContext.currentTime + delay);
2086
+ currentBufferNode === null || currentBufferNode === void 0 ? void 0 : currentBufferNode.addEventListener('ended', () => {
2087
+ if (currentBufferNode === this.bufferNode) {
2088
+ this.bufferNode = null;
2089
+ this.pause();
2090
+ // The 'ended' event fires with some latency, so clamp the reported
2091
+ // position to the exact stop time
2092
+ this.playbackPosition = Math.min(timeSeconds, this.duration);
2093
+ this.emit('timeupdate');
2094
+ }
2095
+ }, { once: true });
2096
+ }
2097
+ setSinkId(deviceId) {
2098
+ return __awaiter$1(this, void 0, void 0, function* () {
2099
+ const ac = this.audioContext;
2100
+ return ac.setSinkId(deviceId);
2101
+ });
2102
+ }
2103
+ get playbackRate() {
2104
+ return this._playbackRate;
2105
+ }
2106
+ set playbackRate(value) {
2107
+ const wasPlaying = !this.paused;
2108
+ if (wasPlaying)
2109
+ this._pause();
2110
+ this._playbackRate = value;
2111
+ if (wasPlaying)
2112
+ this._play();
2113
+ if (this.bufferNode) {
2114
+ this.bufferNode.playbackRate.value = value;
2115
+ }
2116
+ }
2117
+ get currentTime() {
2118
+ return this.paused
2119
+ ? this.playbackPosition
2120
+ : this.playbackPosition + (this.audioContext.currentTime - this.playStartTime) * this._playbackRate;
2121
+ }
2122
+ set currentTime(value) {
2123
+ const wasPlaying = !this.paused;
2124
+ if (wasPlaying)
2125
+ this._pause();
2126
+ this.playbackPosition = value;
2127
+ if (wasPlaying)
2128
+ this._play();
2129
+ this.emit('seeking');
2130
+ this.emit('timeupdate');
2131
+ }
2132
+ get duration() {
2133
+ var _a, _b;
2134
+ return (_a = this._duration) !== null && _a !== void 0 ? _a : (((_b = this.buffer) === null || _b === void 0 ? void 0 : _b.duration) || 0);
2135
+ }
2136
+ set duration(value) {
2137
+ this._duration = value;
2138
+ }
2139
+ get volume() {
2140
+ return this.gainNode.gain.value;
2141
+ }
2142
+ set volume(value) {
2143
+ this.gainNode.gain.value = value;
2144
+ this.emit('volumechange');
2145
+ }
2146
+ get muted() {
2147
+ return this._muted;
2148
+ }
2149
+ set muted(value) {
2150
+ if (this._muted === value)
2151
+ return;
2152
+ this._muted = value;
2153
+ if (this._muted) {
2154
+ this.gainNode.disconnect();
2155
+ }
2156
+ else {
2157
+ this.gainNode.connect(this.audioContext.destination);
2158
+ }
2159
+ }
2160
+ canPlayType(mimeType) {
2161
+ return /^(audio|video)\//.test(mimeType);
2162
+ }
2163
+ /** Get the GainNode used to play the audio. Can be used to attach filters. */
2164
+ getGainNode() {
2165
+ return this.gainNode;
2166
+ }
2167
+ /** Get decoded audio */
2168
+ getChannelData() {
2169
+ const channels = [];
2170
+ if (!this.buffer)
2171
+ return channels;
2172
+ const numChannels = this.buffer.numberOfChannels;
2173
+ for (let i = 0; i < numChannels; i++) {
2174
+ channels.push(this.buffer.getChannelData(i));
2175
+ }
2176
+ return channels;
2177
+ }
2178
+ /**
2179
+ * Imitate `HTMLElement.removeAttribute` for compatibility with `Player`.
2180
+ */
2181
+ removeAttribute(attrName) {
2182
+ switch (attrName) {
2183
+ case 'src':
2184
+ this.src = '';
2185
+ break;
2186
+ case 'playbackRate':
2187
+ this.playbackRate = 0;
2188
+ break;
2189
+ case 'currentTime':
2190
+ this.currentTime = 0;
2191
+ break;
2192
+ case 'duration':
2193
+ this.duration = 0;
2194
+ break;
2195
+ case 'volume':
2196
+ this.volume = 0;
2197
+ break;
2198
+ case 'muted':
2199
+ this.muted = false;
2200
+ break;
2201
+ }
2202
+ }
2203
+ }
2204
+
2205
+ /**
2206
+ * Centralized reactive state for WaveSurfer
2207
+ *
2208
+ * This module provides a single source of truth for all WaveSurfer state.
2209
+ * State is managed using reactive signals that automatically notify subscribers.
2210
+ */
2211
+ /**
2212
+ * Create a new WaveSurfer state instance
2213
+ *
2214
+ * @param playerSignals - Optional signals from Player to compose with WaveSurfer state
2215
+ *
2216
+ * @example
2217
+ * ```typescript
2218
+ * // Without Player signals (standalone)
2219
+ * const { state, actions } = createWaveSurferState()
2220
+ *
2221
+ * // With Player signals (composed)
2222
+ * const { state, actions } = createWaveSurferState({
2223
+ * isPlaying: player.isPlayingSignal,
2224
+ * currentTime: player.currentTimeSignal,
2225
+ * // ...
2226
+ * })
2227
+ *
2228
+ * // Read state
2229
+ * console.log(state.isPlaying.value)
2230
+ *
2231
+ * // Update state
2232
+ * actions.setPlaying(true)
2233
+ *
2234
+ * // Subscribe to changes
2235
+ * state.isPlaying.subscribe(playing => {
2236
+ * console.log('Playing:', playing)
2237
+ * })
2238
+ * ```
2239
+ */
2240
+ function createWaveSurferState(playerSignals) {
2241
+ var _a, _b, _c, _d, _e, _f;
2242
+ // Use Player signals if provided, otherwise create new ones
2243
+ const currentTime = (_a = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.currentTime) !== null && _a !== void 0 ? _a : signal(0);
2244
+ const duration = (_b = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.duration) !== null && _b !== void 0 ? _b : signal(0);
2245
+ const isPlaying = (_c = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.isPlaying) !== null && _c !== void 0 ? _c : signal(false);
2246
+ const isSeeking = (_d = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.isSeeking) !== null && _d !== void 0 ? _d : signal(false);
2247
+ const volume = (_e = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.volume) !== null && _e !== void 0 ? _e : signal(1);
2248
+ const playbackRate = (_f = playerSignals === null || playerSignals === void 0 ? void 0 : playerSignals.playbackRate) !== null && _f !== void 0 ? _f : signal(1);
2249
+ // WaveSurfer-specific signals (not in Player)
2250
+ const audioBuffer = signal(null);
2251
+ const peaks = signal(null);
2252
+ const url = signal('');
2253
+ const zoom = signal(0);
2254
+ const scrollPosition = signal(0);
2255
+ // Computed values (derived state)
2256
+ const isPaused = computed(() => !isPlaying.value, [isPlaying]);
2257
+ const canPlay = computed(() => audioBuffer.value !== null, [audioBuffer]);
2258
+ const isReady = computed(() => {
2259
+ return canPlay.value && duration.value > 0;
2260
+ }, [canPlay, duration]);
2261
+ const progress = computed(() => currentTime.value, [currentTime]);
2262
+ const progressPercent = computed(() => {
2263
+ return duration.value > 0 ? currentTime.value / duration.value : 0;
2264
+ }, [currentTime, duration]);
2265
+ // Public read-only state
2266
+ const state = {
2267
+ currentTime,
2268
+ duration,
2269
+ isPlaying,
2270
+ isPaused,
2271
+ isSeeking,
2272
+ volume,
2273
+ playbackRate,
2274
+ audioBuffer,
2275
+ peaks,
2276
+ url,
2277
+ zoom,
2278
+ scrollPosition,
2279
+ canPlay,
2280
+ isReady,
2281
+ progress,
2282
+ progressPercent,
2283
+ };
2284
+ // Actions that modify state
2285
+ const actions = {
2286
+ setCurrentTime: (time) => {
2287
+ const clampedTime = Math.max(0, Math.min(duration.value || Infinity, time));
2288
+ currentTime.set(clampedTime);
2289
+ },
2290
+ setDuration: (d) => {
2291
+ duration.set(Math.max(0, d));
2292
+ },
2293
+ setPlaying: (playing) => {
2294
+ isPlaying.set(playing);
2295
+ },
2296
+ setSeeking: (seeking) => {
2297
+ isSeeking.set(seeking);
2298
+ },
2299
+ setVolume: (v) => {
2300
+ const clampedVolume = Math.max(0, Math.min(1, v));
2301
+ volume.set(clampedVolume);
2302
+ },
2303
+ setPlaybackRate: (rate) => {
2304
+ const clampedRate = Math.max(0.1, Math.min(16, rate));
2305
+ playbackRate.set(clampedRate);
2306
+ },
2307
+ setAudioBuffer: (buffer) => {
2308
+ audioBuffer.set(buffer);
2309
+ if (buffer) {
2310
+ duration.set(buffer.duration);
2311
+ }
2312
+ },
2313
+ setPeaks: (p) => {
2314
+ peaks.set(p);
2315
+ },
2316
+ setUrl: (u) => {
2317
+ url.set(u);
2318
+ },
2319
+ setZoom: (z) => {
2320
+ zoom.set(Math.max(0, z));
2321
+ },
2322
+ setScrollPosition: (pos) => {
2323
+ scrollPosition.set(Math.max(0, pos));
2324
+ },
2325
+ };
2326
+ return { state, actions };
2327
+ }
2328
+
2329
+ /**
2330
+ * State-driven event emission utilities
2331
+ *
2332
+ * Automatically emit events when reactive state changes.
2333
+ * Ensures events are always in sync with state and removes manual emit() calls.
2334
+ */
2335
+ /**
2336
+ * Setup automatic event emission from state changes
2337
+ *
2338
+ * This function subscribes to all relevant state signals and automatically
2339
+ * emits corresponding events when state changes. This ensures:
2340
+ * - Events are always in sync with state
2341
+ * - No manual emit() calls needed
2342
+ * - Can't forget to emit an event
2343
+ * - Clear event sources (state changes)
2344
+ *
2345
+ * @example
2346
+ * ```typescript
2347
+ * const { state } = createWaveSurferState()
2348
+ * const wavesurfer = new WaveSurfer()
2349
+ *
2350
+ * const cleanup = setupStateEventEmission(state, wavesurfer)
2351
+ *
2352
+ * // Now state changes automatically emit events
2353
+ * state.isPlaying.set(true) // → wavesurfer.emit('play')
2354
+ * ```
2355
+ *
2356
+ * @param state - Reactive state to observe
2357
+ * @param emitter - Event emitter to emit events on
2358
+ * @returns Cleanup function that removes all subscriptions
2359
+ */
2360
+ function setupStateEventEmission(state, emitter) {
2361
+ const cleanups = [];
2362
+ // ============================================================================
2363
+ // Play/Pause Events
2364
+ // ============================================================================
2365
+ // Emit play/pause events when playing state changes
2366
+ cleanups.push(effect(() => {
2367
+ const isPlaying = state.isPlaying.value;
2368
+ emitter.emit(isPlaying ? 'play' : 'pause');
2369
+ }, [state.isPlaying]));
2370
+ // ============================================================================
2371
+ // Time Update Events
2372
+ // ============================================================================
2373
+ // Emit timeupdate when current time changes
2374
+ cleanups.push(effect(() => {
2375
+ const currentTime = state.currentTime.value;
2376
+ emitter.emit('timeupdate', currentTime);
2377
+ // Also emit audioprocess when playing
2378
+ if (state.isPlaying.value) {
2379
+ emitter.emit('audioprocess', currentTime);
2380
+ }
2381
+ }, [state.currentTime, state.isPlaying]));
2382
+ // ============================================================================
2383
+ // Seeking Events
2384
+ // ============================================================================
2385
+ // Emit seeking event when seeking state changes to true
2386
+ cleanups.push(effect(() => {
2387
+ const isSeeking = state.isSeeking.value;
2388
+ if (isSeeking) {
2389
+ emitter.emit('seeking', state.currentTime.value);
2390
+ }
2391
+ }, [state.isSeeking, state.currentTime]));
2392
+ // ============================================================================
2393
+ // Ready Event
2394
+ // ============================================================================
2395
+ // Emit ready when state becomes ready
2396
+ let wasReady = false;
2397
+ cleanups.push(effect(() => {
2398
+ const isReady = state.isReady.value;
2399
+ if (isReady && !wasReady) {
2400
+ wasReady = true;
2401
+ emitter.emit('ready', state.duration.value);
2402
+ }
2403
+ }, [state.isReady, state.duration]));
2404
+ // Reset wasReady when audio buffer is cleared (new load starting)
2405
+ // This allows the 'ready' event to fire again on subsequent loads
2406
+ cleanups.push(effect(() => {
2407
+ if (state.audioBuffer.value === null) {
2408
+ wasReady = false;
2409
+ }
2410
+ }, [state.audioBuffer]));
2411
+ // ============================================================================
2412
+ // Finish Event
2413
+ // ============================================================================
2414
+ // Emit finish when playback ends (reached duration and stopped)
2415
+ let wasPlayingAtEnd = false;
2416
+ cleanups.push(effect(() => {
2417
+ const isPlaying = state.isPlaying.value;
2418
+ const currentTime = state.currentTime.value;
2419
+ const duration = state.duration.value;
2420
+ // Check if we're at the end
2421
+ const isAtEnd = duration > 0 && currentTime >= duration;
2422
+ // Emit finish when we were playing at end and now stopped
2423
+ if (wasPlayingAtEnd && !isPlaying && isAtEnd) {
2424
+ emitter.emit('finish');
2425
+ }
2426
+ // Track if we're playing at the end
2427
+ wasPlayingAtEnd = isPlaying && isAtEnd;
2428
+ }, [state.isPlaying, state.currentTime, state.duration]));
2429
+ // ============================================================================
2430
+ // Zoom Events
2431
+ // ============================================================================
2432
+ // Emit zoom when zoom level changes
2433
+ cleanups.push(effect(() => {
2434
+ const zoom = state.zoom.value;
2435
+ if (zoom > 0) {
2436
+ emitter.emit('zoom', zoom);
2437
+ }
2438
+ }, [state.zoom]));
2439
+ // Return cleanup function
2440
+ return () => {
2441
+ cleanups.forEach((cleanup) => cleanup());
2442
+ };
2443
+ }
2444
+
2445
+ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
2446
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
2447
+ return new (P || (P = Promise))(function (resolve, reject) {
2448
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
2449
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
2450
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
2451
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
2452
+ });
2453
+ };
2454
+ const defaultOptions = {
2455
+ waveColor: '#999',
2456
+ progressColor: '#555',
2457
+ cursorWidth: 1,
2458
+ minPxPerSec: 0,
2459
+ fillParent: true,
2460
+ interact: true,
2461
+ dragToSeek: false,
2462
+ autoScroll: true,
2463
+ autoCenter: true,
2464
+ sampleRate: 8000,
2465
+ };
2466
+ class WaveSurfer extends Player {
2467
+ /** Create a new WaveSurfer instance */
2468
+ static create(options) {
2469
+ return new WaveSurfer(options);
2470
+ }
2471
+ /** Get the reactive state for advanced use cases */
2472
+ getState() {
2473
+ return this.wavesurferState;
2474
+ }
2475
+ /** Get the renderer instance for plugin access to reactive streams */
2476
+ getRenderer() {
2477
+ return this.renderer;
2478
+ }
2479
+ /** Create a new WaveSurfer instance */
2480
+ constructor(options) {
2481
+ const media = options.media ||
2482
+ (options.backend === 'WebAudio' ? new WebAudioPlayer() : undefined);
2483
+ super({
2484
+ media,
2485
+ mediaControls: options.mediaControls,
2486
+ autoplay: options.autoplay,
2487
+ playbackRate: options.audioRate,
2488
+ });
2489
+ this.plugins = [];
2490
+ this.decodedData = null;
2491
+ this.stopAtPosition = null;
2492
+ this.subscriptions = [];
2493
+ this.mediaSubscriptions = [];
2494
+ this.abortController = null;
2495
+ this._isDestroyed = false;
2496
+ this._loadVersion = 0;
2497
+ this.reactiveCleanups = [];
2498
+ this.options = Object.assign({}, defaultOptions, options);
2499
+ // Initialize reactive state
2500
+ // Pass Player signals to compose them into WaveSurferState
2501
+ const { state, actions } = createWaveSurferState({
2502
+ isPlaying: this.isPlayingSignal,
2503
+ currentTime: this.currentTimeSignal,
2504
+ duration: this.durationSignal,
2505
+ volume: this.volumeSignal,
2506
+ playbackRate: this.playbackRateSignal,
2507
+ isSeeking: this.seekingSignal,
2508
+ });
2509
+ this.wavesurferState = state;
2510
+ this.wavesurferActions = actions;
2511
+ this.timer = new Timer();
2512
+ const audioElement = media ? undefined : this.getMediaElement();
2513
+ this.renderer = new Renderer(this.options, audioElement);
2514
+ this.initPlayerEvents();
2515
+ this.initRendererEvents();
2516
+ this.initTimerEvents();
2517
+ this.initReactiveState();
2518
+ this.initPlugins();
2519
+ // Read the initial URL before load has been called
2520
+ const initialUrl = this.options.url || this.getSrc() || '';
2521
+ // Init and load async to allow external events to be registered
2522
+ Promise.resolve().then(() => {
2523
+ this.emit('init');
2524
+ // Load audio if URL or an external media with an src is passed,
2525
+ // of render w/o audio if pre-decoded peaks and duration are provided
2526
+ const { peaks, duration } = this.options;
2527
+ if (initialUrl || (peaks && duration)) {
2528
+ // Swallow async errors because they cannot be caught from a constructor call.
2529
+ // Subscribe to the wavesurfer's error event to handle them.
2530
+ this.load(initialUrl, peaks, duration).catch(() => {
2531
+ // Error already emitted by load()
2532
+ });
2533
+ }
2534
+ });
2535
+ }
2536
+ updateProgress(currentTime = this.getCurrentTime()) {
2537
+ this.renderer.renderProgress(currentTime / this.getDuration(), this.isPlaying());
2538
+ return currentTime;
2539
+ }
2540
+ initTimerEvents() {
2541
+ // The timer fires every 16ms for a smooth progress animation
2542
+ this.subscriptions.push(this.timer.on('tick', () => {
2543
+ if (!this.isSeeking()) {
2544
+ const currentTime = this.updateProgress();
2545
+ this.emit('timeupdate', currentTime);
2546
+ this.emit('audioprocess', currentTime);
2547
+ // Pause audio when it reaches the stopAtPosition
2548
+ if (this.stopAtPosition != null && this.isPlaying() && currentTime >= this.stopAtPosition) {
2549
+ // The timer may overshoot the stop position, so clamp the time back to it
2550
+ const stopAt = this.stopAtPosition;
2551
+ this.pause();
2552
+ this.setTime(stopAt);
2553
+ }
2554
+ }
2555
+ }));
2556
+ }
2557
+ initReactiveState() {
2558
+ // Bridge reactive state to EventEmitter for backwards compatibility
2559
+ this.reactiveCleanups.push(setupStateEventEmission(this.wavesurferState, {
2560
+ emit: this.emit.bind(this),
2561
+ }));
2562
+ }
2563
+ initPlayerEvents() {
2564
+ if (this.isPlaying()) {
2565
+ this.emit('play');
2566
+ this.timer.start();
2567
+ }
2568
+ this.mediaSubscriptions.push(this.onMediaEvent('timeupdate', () => {
2569
+ const currentTime = this.updateProgress();
2570
+ this.emit('timeupdate', currentTime);
2571
+ }), this.onMediaEvent('play', () => {
2572
+ this.emit('play');
2573
+ this.timer.start();
2574
+ }), this.onMediaEvent('pause', () => {
2575
+ this.emit('pause');
2576
+ this.timer.stop();
2577
+ this.stopAtPosition = null;
2578
+ }), this.onMediaEvent('emptied', () => {
2579
+ this.timer.stop();
2580
+ this.stopAtPosition = null;
2581
+ }), this.onMediaEvent('ended', () => {
2582
+ this.emit('timeupdate', this.getDuration());
2583
+ this.emit('finish');
2584
+ this.stopAtPosition = null;
2585
+ }), this.onMediaEvent('seeking', () => {
2586
+ this.emit('seeking', this.getCurrentTime());
2587
+ }), this.onMediaEvent('error', () => {
2588
+ var _a;
2589
+ this.emit('error', ((_a = this.getMediaElement().error) !== null && _a !== void 0 ? _a : new Error('Media error')));
2590
+ this.stopAtPosition = null;
2591
+ }));
2592
+ }
2593
+ initRendererEvents() {
2594
+ this.subscriptions.push(
2595
+ // Seek on click
2596
+ this.renderer.on('click', (relativeX, relativeY) => {
2597
+ if (this.options.interact) {
2598
+ this.seekTo(relativeX);
2599
+ this.emit('interaction', relativeX * this.getDuration());
2600
+ this.emit('click', relativeX, relativeY);
2601
+ }
2602
+ }),
2603
+ // Double click
2604
+ this.renderer.on('dblclick', (relativeX, relativeY) => {
2605
+ this.emit('dblclick', relativeX, relativeY);
2606
+ }),
2607
+ // Scroll
2608
+ this.renderer.on('scroll', (startX, endX, scrollLeft, scrollRight) => {
2609
+ const duration = this.getDuration();
2610
+ this.emit('scroll', startX * duration, endX * duration, scrollLeft, scrollRight);
2611
+ }),
2612
+ // Redraw
2613
+ this.renderer.on('render', () => {
2614
+ this.emit('redraw');
2615
+ }),
2616
+ // RedrawComplete
2617
+ this.renderer.on('rendered', () => {
2618
+ this.emit('redrawcomplete');
2619
+ }),
2620
+ // DragStart
2621
+ this.renderer.on('dragstart', (relativeX) => {
2622
+ this.emit('dragstart', relativeX);
2623
+ }),
2624
+ // DragEnd
2625
+ this.renderer.on('dragend', (relativeX) => {
2626
+ this.emit('dragend', relativeX);
2627
+ }),
2628
+ // Resize
2629
+ this.renderer.on('resize', () => {
2630
+ this.emit('resize');
2631
+ }));
2632
+ // Drag
2633
+ {
2634
+ let debounce;
2635
+ const unsubscribeDrag = this.renderer.on('drag', (relativeX) => {
2636
+ var _a;
2637
+ if (!this.options.interact)
2638
+ return;
2639
+ // Update the visual position
2640
+ this.renderer.renderProgress(relativeX);
2641
+ // Set the audio position with a debounce
2642
+ clearTimeout(debounce);
2643
+ let debounceTime = 0;
2644
+ const dragToSeek = this.options.dragToSeek;
2645
+ if (this.isPlaying()) {
2646
+ debounceTime = 0;
2647
+ }
2648
+ else if (dragToSeek === true) {
2649
+ debounceTime = 200;
2650
+ }
2651
+ else if (dragToSeek && typeof dragToSeek === 'object') {
2652
+ debounceTime = (_a = dragToSeek.debounceTime) !== null && _a !== void 0 ? _a : 200;
2653
+ }
2654
+ debounce = setTimeout(() => {
2655
+ this.seekTo(relativeX);
2656
+ }, debounceTime);
2657
+ this.emit('interaction', relativeX * this.getDuration());
2658
+ this.emit('drag', relativeX);
2659
+ });
2660
+ // Clear debounce timeout on destroy
2661
+ this.subscriptions.push(() => {
2662
+ clearTimeout(debounce);
2663
+ unsubscribeDrag();
2664
+ });
2665
+ }
2666
+ }
2667
+ initPlugins() {
2668
+ var _a;
2669
+ if (!((_a = this.options.plugins) === null || _a === void 0 ? void 0 : _a.length))
2670
+ return;
2671
+ this.options.plugins.forEach((plugin) => {
2672
+ this.registerPlugin(plugin);
2673
+ });
2674
+ }
2675
+ unsubscribePlayerEvents() {
2676
+ this.mediaSubscriptions.forEach((unsubscribe) => unsubscribe());
2677
+ this.mediaSubscriptions = [];
2678
+ }
2679
+ /** Set new wavesurfer options and re-render it */
2680
+ setOptions(options) {
2681
+ this.options = Object.assign({}, this.options, options);
2682
+ if (options.duration && !options.peaks) {
2683
+ this.decodedData = Decoder.createBuffer(this.exportPeaks(), options.duration);
2684
+ }
2685
+ if (options.peaks && options.duration) {
2686
+ // Create new decoded data buffer from peaks and duration
2687
+ this.decodedData = Decoder.createBuffer(options.peaks, options.duration);
2688
+ }
2689
+ this.renderer.setOptions(this.options);
2690
+ if (options.audioRate) {
2691
+ this.setPlaybackRate(options.audioRate);
2692
+ }
2693
+ if (options.mediaControls != null) {
2694
+ this.getMediaElement().controls = options.mediaControls;
2695
+ }
2696
+ }
2697
+ /** Register a wavesurfer.js plugin */
2698
+ registerPlugin(plugin) {
2699
+ // Check if the plugin is already registered
2700
+ if (this.plugins.includes(plugin)) {
2701
+ return plugin;
2702
+ }
2703
+ plugin._init(this);
2704
+ this.plugins.push(plugin);
2705
+ // Unregister plugin on destroy
2706
+ const unsubscribe = plugin.once('destroy', () => {
2707
+ this.plugins = this.plugins.filter((p) => p !== plugin);
2708
+ this.subscriptions = this.subscriptions.filter((fn) => fn !== unsubscribe);
2709
+ });
2710
+ this.subscriptions.push(unsubscribe);
2711
+ return plugin;
2712
+ }
2713
+ /** Unregister a wavesurfer.js plugin */
2714
+ unregisterPlugin(plugin) {
2715
+ this.plugins = this.plugins.filter((p) => p !== plugin);
2716
+ plugin.destroy();
2717
+ }
2718
+ /** For plugins only: get the waveform wrapper div */
2719
+ getWrapper() {
2720
+ return this.renderer.getWrapper();
2721
+ }
2722
+ /** For plugins only: get the scroll container client width */
2723
+ getWidth() {
2724
+ return this.renderer.getWidth();
2725
+ }
2726
+ /** Get the current scroll position in pixels */
2727
+ getScroll() {
2728
+ return this.renderer.getScroll();
2729
+ }
2730
+ /** Set the current scroll position in pixels */
2731
+ setScroll(pixels) {
2732
+ return this.renderer.setScroll(pixels);
2733
+ }
2734
+ /** Move the start of the viewing window to a specific time in the audio (in seconds) */
2735
+ setScrollTime(time) {
2736
+ const percentage = time / this.getDuration();
2737
+ this.renderer.setScrollPercentage(percentage);
2738
+ }
2739
+ /** Get all registered plugins */
2740
+ getActivePlugins() {
2741
+ return this.plugins;
2742
+ }
2743
+ loadAudio(url, blob, channelData, duration) {
2744
+ return __awaiter(this, void 0, void 0, function* () {
2745
+ var _a;
2746
+ // Re-entrancy guard: assign a version to this load call
2747
+ // If a newer load starts while this one is in-flight, this one will bail out
2748
+ const loadVersion = ++this._loadVersion;
2749
+ // Reusing an instance after destroy() is a supported behavior (see issue #3637
2750
+ // and cypress/e2e/abort.cy.js "load url after destroyed should emit ready").
2751
+ // Reset the destroyed flag so the instance can be reloaded. Stale in-flight
2752
+ // loads from before destroy() are still cancelled by the loadVersion guard
2753
+ // below, so this reset does not weaken the post-await bail-out checks.
2754
+ this._isDestroyed = false;
2755
+ this.emit('load', url);
2756
+ if (!this.options.media && this.isPlaying())
2757
+ this.pause();
2758
+ this.decodedData = null;
2759
+ this.stopAtPosition = null;
2760
+ // Abort any ongoing fetch before starting a new one
2761
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
2762
+ this.abortController = null;
2763
+ // Fetch the entire audio as a blob if pre-decoded data is not provided
2764
+ if (!blob && !channelData) {
2765
+ const fetchParams = this.options.fetchParams || {};
2766
+ if (window.AbortController && !fetchParams.signal) {
2767
+ this.abortController = new AbortController();
2768
+ fetchParams.signal = this.abortController.signal;
2769
+ }
2770
+ const onProgress = (percentage) => this.emit('loading', percentage);
2771
+ blob = yield Fetcher.fetchBlob(url, onProgress, fetchParams);
2772
+ // Guard: bail if destroyed or a newer load started
2773
+ if (this._isDestroyed || loadVersion !== this._loadVersion)
2774
+ return;
2775
+ const overriddenMimeType = this.options.blobMimeType;
2776
+ if (overriddenMimeType) {
2777
+ blob = new Blob([blob], { type: overriddenMimeType });
2778
+ }
2779
+ }
2780
+ // Guard: bail if destroyed or a newer load started
2781
+ if (this._isDestroyed || loadVersion !== this._loadVersion)
2782
+ return;
2783
+ // Set the mediaelement source
2784
+ this.setSrc(url, blob);
2785
+ // Wait for the audio duration
2786
+ const audioDuration = yield new Promise((resolve) => {
2787
+ const staticDuration = duration || this.getDuration();
2788
+ if (staticDuration) {
2789
+ resolve(staticDuration);
2790
+ }
2791
+ else {
2792
+ this.mediaSubscriptions.push(this.onMediaEvent('loadedmetadata', () => resolve(this.getDuration()), { once: true }));
2793
+ }
2794
+ });
2795
+ // Guard: bail if destroyed or a newer load started
2796
+ if (this._isDestroyed || loadVersion !== this._loadVersion)
2797
+ return;
2798
+ // Set the duration if the player is a WebAudioPlayer without a URL
2799
+ if (!url && !blob) {
2800
+ const media = this.getMediaElement();
2801
+ if (media instanceof WebAudioPlayer) {
2802
+ media.duration = audioDuration;
2803
+ }
2804
+ }
2805
+ // Decode the audio data or use user-provided peaks
2806
+ if (channelData) {
2807
+ this.decodedData = Decoder.createBuffer(channelData, audioDuration || 0);
2808
+ }
2809
+ else if (blob) {
2810
+ const arrayBuffer = yield blob.arrayBuffer();
2811
+ // Guard: bail if destroyed or a newer load started
2812
+ if (this._isDestroyed || loadVersion !== this._loadVersion)
2813
+ return;
2814
+ this.decodedData = yield Decoder.decode(arrayBuffer, this.options.sampleRate);
2815
+ }
2816
+ // Guard: bail if destroyed or a newer load started
2817
+ if (this._isDestroyed || loadVersion !== this._loadVersion)
2818
+ return;
2819
+ if (this.decodedData) {
2820
+ this.emit('decode', this.getDuration());
2821
+ this.renderer.render(this.decodedData);
2822
+ }
2823
+ this.emit('ready', this.getDuration());
2824
+ });
2825
+ }
2826
+ /** Load an audio file by URL, with optional pre-decoded audio data */
2827
+ load(url, channelData, duration) {
2828
+ return __awaiter(this, void 0, void 0, function* () {
2829
+ try {
2830
+ return yield this.loadAudio(url, undefined, channelData, duration);
2831
+ }
2832
+ catch (err) {
2833
+ this.emit('error', err);
2834
+ throw err;
2835
+ }
2836
+ });
2837
+ }
2838
+ /** Load an audio blob */
2839
+ loadBlob(blob, channelData, duration) {
2840
+ return __awaiter(this, void 0, void 0, function* () {
2841
+ try {
2842
+ return yield this.loadAudio('', blob, channelData, duration);
2843
+ }
2844
+ catch (err) {
2845
+ this.emit('error', err);
2846
+ throw err;
2847
+ }
2848
+ });
2849
+ }
2850
+ /** Zoom the waveform by a given pixels-per-second factor */
2851
+ zoom(minPxPerSec) {
2852
+ if (!this.decodedData) {
2853
+ throw new Error('No audio loaded');
2854
+ }
2855
+ this.renderer.zoom(minPxPerSec);
2856
+ this.emit('zoom', minPxPerSec);
2857
+ }
2858
+ /** Get the decoded audio data */
2859
+ getDecodedData() {
2860
+ return this.decodedData;
2861
+ }
2862
+ /** Get decoded peaks */
2863
+ exportPeaks({ channels = 2, maxLength = 8000, precision = 10000 } = {}) {
2864
+ if (!this.decodedData) {
2865
+ throw new Error('The audio has not been decoded yet');
2866
+ }
2867
+ const maxChannels = Math.min(channels, this.decodedData.numberOfChannels);
2868
+ const peaks = [];
2869
+ for (let i = 0; i < maxChannels; i++) {
2870
+ const channel = this.decodedData.getChannelData(i);
2871
+ const data = [];
2872
+ const sampleSize = channel.length / maxLength;
2873
+ for (let j = 0; j < maxLength; j++) {
2874
+ const sample = channel.slice(Math.floor(j * sampleSize), Math.ceil((j + 1) * sampleSize));
2875
+ let max = 0;
2876
+ for (let x = 0; x < sample.length; x++) {
2877
+ const n = sample[x];
2878
+ if (Math.abs(n) > Math.abs(max))
2879
+ max = n;
2880
+ }
2881
+ data.push(Math.round(max * precision) / precision);
2882
+ }
2883
+ peaks.push(data);
2884
+ }
2885
+ return peaks;
2886
+ }
2887
+ /** Get the duration of the audio in seconds */
2888
+ getDuration() {
2889
+ let duration = super.getDuration() || 0;
2890
+ // Fall back to the decoded data duration if the media duration is incorrect
2891
+ if ((duration === 0 || duration === Infinity) && this.decodedData) {
2892
+ duration = this.decodedData.duration;
2893
+ }
2894
+ return duration;
2895
+ }
2896
+ /** Toggle if the waveform should react to clicks */
2897
+ toggleInteraction(isInteractive) {
2898
+ this.options.interact = isInteractive;
2899
+ }
2900
+ /** Jump to a specific time in the audio (in seconds) */
2901
+ setTime(time) {
2902
+ this.stopAtPosition = null;
2903
+ super.setTime(time);
2904
+ this.updateProgress(time);
2905
+ this.emit('timeupdate', time);
2906
+ }
2907
+ /** Seek to a ratio of audio as [0..1] (0 = beginning, 1 = end) */
2908
+ seekTo(progress) {
2909
+ const time = this.getDuration() * progress;
2910
+ this.setTime(time);
2911
+ }
2912
+ /** Start playing the audio */
2913
+ play(start, end) {
2914
+ const _super = Object.create(null, {
2915
+ play: { get: () => super.play }
2916
+ });
2917
+ return __awaiter(this, void 0, void 0, function* () {
2918
+ if (start != null) {
2919
+ this.setTime(start);
2920
+ }
2921
+ const playResult = yield _super.play.call(this);
2922
+ if (end != null) {
2923
+ if (this.media instanceof WebAudioPlayer) {
2924
+ this.media.stopAt(end);
2925
+ }
2926
+ else {
2927
+ this.stopAtPosition = end;
2928
+ }
2929
+ }
2930
+ return playResult;
2931
+ });
2932
+ }
2933
+ /** Play or pause the audio */
2934
+ playPause() {
2935
+ return __awaiter(this, void 0, void 0, function* () {
2936
+ return this.isPlaying() ? this.pause() : this.play();
2937
+ });
2938
+ }
2939
+ /** Stop the audio and go to the beginning */
2940
+ stop() {
2941
+ this.pause();
2942
+ this.setTime(0);
2943
+ }
2944
+ /** Skip N or -N seconds from the current position */
2945
+ skip(seconds) {
2946
+ this.setTime(this.getCurrentTime() + seconds);
2947
+ }
2948
+ /** Empty the waveform */
2949
+ empty() {
2950
+ this.load('', [[0]], 0.001);
2951
+ }
2952
+ /** Set HTML media element */
2953
+ setMediaElement(element) {
2954
+ this.unsubscribePlayerEvents();
2955
+ super.setMediaElement(element);
2956
+ this.initPlayerEvents();
2957
+ }
2958
+ exportImage() {
2959
+ return __awaiter(this, arguments, void 0, function* (format = 'image/png', quality = 1, type = 'dataURL') {
2960
+ return this.renderer.exportImage(format, quality, type);
2961
+ });
2962
+ }
2963
+ /** Unmount wavesurfer */
2964
+ destroy() {
2965
+ var _a;
2966
+ this._isDestroyed = true;
2967
+ this.emit('destroy');
2968
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
2969
+ this.plugins.forEach((plugin) => plugin.destroy());
2970
+ this.subscriptions.forEach((unsubscribe) => unsubscribe());
2971
+ this.unsubscribePlayerEvents();
2972
+ this.reactiveCleanups.forEach((cleanup) => cleanup());
2973
+ this.reactiveCleanups = [];
2974
+ this.timer.destroy();
2975
+ this.renderer.destroy();
2976
+ super.destroy();
2977
+ }
2978
+ }
2979
+ WaveSurfer.BasePlugin = BasePlugin;
2980
+ WaveSurfer.dom = dom;
2981
+
2982
+ class AudioBubbleUI extends Image.h {
2983
+ static get properties() {
2984
+ return {
2985
+ isPlaying: { type: Boolean },
2986
+ audioDuration: { type: String },
2987
+ isSelf: { type: Boolean },
2988
+ isDelivered: { type: Boolean },
2989
+ isRead: { type: Boolean },
2990
+ showFooter: { type: Boolean },
2991
+ textColor: { type: String },
2992
+ timeColor: { type: String },
2993
+ time: { type: String },
2994
+ bgColor: { type: String },
2995
+ borderRadius: { type: String },
2996
+ playAudioHandler: { type: Function },
2997
+ pauseAudioHandler: { type: Function },
2998
+ messageId: { type: String },
2999
+ reactions: { type: Object },
3000
+ showConfirmationPopup: { type: Boolean },
3001
+ selectedEmojiToRemove: { type: Object },
3002
+ showAllReactionsPopup: {type: Boolean},
3003
+ showReactionButton: {type: Boolean},
3004
+ showEmojiReactions: {type: Boolean},
3005
+ messageType: { type: Number },
3006
+ showReactionOnHover: {type: Boolean}
3007
+ };
3008
+ }
3009
+
3010
+ static get styles() {
3011
+ return Image.i`
3012
+ :host {
3013
+ display: block;
3014
+ }
3015
+
3016
+ reaction-container {
3017
+ display: block;
3018
+ min-height: 150px;
3019
+ max-height: fit-content;
3020
+ min-width: 300px;
3021
+ max-width: 400px;
3022
+ position: absolute;
3023
+ z-index: 100;
3024
+ }
3025
+ .audio-bubble-wrapper {
3026
+ position: relative;
3027
+ display: flex;
3028
+ flex-direction: column;
3029
+ gap: 0.5rem;
3030
+ padding: 10px 10px 20px 10px;
3031
+ margin: 0.25rem 0px 0.25rem auto;
3032
+ border-radius: var(--radius-bubble);
3033
+ width: 336px;
3034
+ box-sizing: border-box;
3035
+ }
3036
+
3037
+ .sender-bg {
3038
+ background-color: var(--bg-outgoing-message);
3039
+ border: none;
3040
+ }
3041
+
3042
+ .receiver-bg {
3043
+ background-color: var(--bg-incoming-message);
3044
+ border: 1px solid var(--bubble-border, var(--primary));
3045
+ }
3046
+ .sender-text {
3047
+ color: var(--text-outgoing-message);
3048
+ }
3049
+
3050
+ .receiver-text {
3051
+ color: var(--text-incoming-message);
3052
+ }
3053
+
3054
+ .sender-icon svg {
3055
+ stroke: var(--text-outgoing-message);
3056
+ }
3057
+
3058
+ .receiver-icon svg {
3059
+ stroke: var(--text-incoming-message);
3060
+ }
3061
+
3062
+ .audio-content {
3063
+ display: flex;
3064
+ align-items: center;
3065
+ width: 100%;
3066
+ gap: 10px;
3067
+ }
3068
+
3069
+ .wavesurfer-timeline-progress {
3070
+ width: 10px !important;
3071
+ height: 10px !important;
3072
+ border-radius: 50% !important;
3073
+ background-color: red !important;
3074
+ }
3075
+
3076
+ .user_profile_picture {
3077
+ width: 55px;
3078
+ height: 55px;
3079
+ object-fit: cover;
3080
+ border-radius: 50%;
3081
+ }
3082
+
3083
+ @media (max-width: 768px) {
3084
+ .audio-bubble-wrapper {
3085
+ width: 280px;
3086
+ }
3087
+ }
3088
+
3089
+ .chat_audio_play_pause {
3090
+ width: 24px;
3091
+ height: 24px;
3092
+ min-width: 24px;
3093
+ cursor: pointer;
3094
+ display: flex;
3095
+ align-items: center;
3096
+ justify-content: center;
3097
+ }
3098
+
3099
+ .wave_container {
3100
+ flex: 1;
3101
+ height: 40px;
3102
+ min-height: 40px;
3103
+ border-radius: 4px;
3104
+ }
3105
+
3106
+ .audio-info {
3107
+ display: flex;
3108
+ align-items: center;
3109
+ justify-content: space-between;
3110
+ width: 100%;
3111
+ font-size: 10px;
3112
+ margin-top: 4px;
3113
+ }
3114
+
3115
+ .audio-time {
3116
+ font-size: 10px;
3117
+ }
3118
+
3119
+ .userContact_image {
3120
+ width: 55px;
3121
+ height: 55px;
3122
+ border-radius: 50%;
3123
+ background-color: #ccc;
3124
+ display: flex;
3125
+ align-items: center;
3126
+ justify-content: center;
3127
+ font-size: 24px;
3128
+ font-weight: bold;
3129
+ }
3130
+
3131
+ .pointer {
3132
+ cursor: pointer;
3133
+ }
3134
+
3135
+ .message-footer {
3136
+ display: flex;
3137
+ align-items: center;
3138
+ justify-content: flex-end;
3139
+ gap: 4px;
3140
+ width: 100%;
3141
+ margin-top: auto;
3142
+ font-size: 12px;
3143
+ }
3144
+
3145
+ .emoji-slider {
3146
+ position: absolute;
3147
+ }
3148
+
3149
+ emoji-reactions {
3150
+ position: absolute;
3151
+ top: 15px;
3152
+ z-index: 99;
3153
+ left: 0;
3154
+ }
3155
+
3156
+ .reaction-button {
3157
+ position: absolute;
3158
+ top: 50%;
3159
+ right: -25px;
3160
+ transform: translateY(-50%);
3161
+ cursor: pointer;
3162
+ z-index: 100;
3163
+ }
3164
+
3165
+ .remaining-count {
3166
+ background-color: var(--bg-primary-light);
3167
+ font-size: 14px;
3168
+ display: flex;
3169
+ justify-content: center;
3170
+ color: var(--text-primary-color);
3171
+ width: 25px;
3172
+ cursor: pointer;
3173
+ }
3174
+
3175
+ .reactions-display {
3176
+ position: absolute;
3177
+ bottom: -10px;
3178
+ right: 10px;
3179
+ display: grid;
3180
+ grid-template-columns: repeat(3, auto);
3181
+ gap: 0;
3182
+ margin-top: 4px;
3183
+ background-color: transparent;
3184
+ }
3185
+
3186
+ .reaction-item {
3187
+ display: flex;
3188
+ align-items: center;
3189
+ gap: 2px;
3190
+ border-radius: 12px;
3191
+ background: var(--bg-secondary-color);
3192
+ font-size: 20px;
3193
+ cursor: pointer;
3194
+ }
3195
+ `;
3196
+ }
3197
+
3198
+ constructor() {
3199
+ super();
3200
+ this.isPlaying = false;
3201
+ this.audioDuration = '0:00';
3202
+ this.isSelf = false;
3203
+ this.showReactionButton = false;
3204
+ this.showEmojiReactions = false;
3205
+ this.reactions = {};
3206
+ this.showAllReactionsPopup = false;
3207
+ this.showReactionOnHover = false;
3208
+ }
3209
+
3210
+ firstUpdated() {
3211
+ // Ensure everything is rendered first
3212
+ setTimeout(() => {
3213
+ const waveContainer = this.shadowRoot.querySelector('.wave_container');
3214
+ if (waveContainer) {
3215
+ // Make sure the component is fully rendered and attached to DOM
3216
+ this.dispatchEvent(
3217
+ new CustomEvent('waveformReady', {
3218
+ detail: waveContainer,
3219
+ bubbles: true,
3220
+ composed: true,
3221
+ }),
3222
+ );
3223
+ } else {
3224
+ console.error('Wave container element not found in shadowRoot');
3225
+ }
3226
+ }, 50);
3227
+ }
3228
+
3229
+ handleMouseEnter() {
3230
+ if(this.showReactionOnHover) {
3231
+ this.showReactionButton = true;
3232
+ }
3233
+ }
3234
+
3235
+
3236
+ handleReactionRemove(reaction) {
3237
+ this.showEmojiReactions = false;
3238
+
3239
+ this.showConfirmationPopup = true;
3240
+ this.selectedEmojiToRemove = reaction;
3241
+ setTimeout(() => {
3242
+ document.addEventListener('click', this.handleOutsideClick);
3243
+ }, 100);
3244
+ }
3245
+
3246
+ handleMouseLeave(e) {
3247
+ const messageContainer = this.renderRoot.querySelector('.message-container');
3248
+ const emojiReactions = this.renderRoot.querySelector('emoji-reactions');
3249
+ const reactionButton = this.renderRoot.querySelector('.reaction-button');
3250
+
3251
+ const isEmojiSliderOpen = this.showEmojiReactions;
3252
+
3253
+ const isMovingToMessage = messageContainer?.contains(e.relatedTarget);
3254
+ const isMovingToEmoji = emojiReactions && emojiReactions?.contains(e.relatedTarget);
3255
+ const isMovingToReactionButton = reactionButton && reactionButton?.contains(e.relatedTarget);
3256
+
3257
+ if (!isMovingToMessage && !isMovingToEmoji && !isMovingToReactionButton) {
3258
+ this.showReactionButton = false;
3259
+
3260
+ if (!isEmojiSliderOpen) {
3261
+ this.showEmojiReactions = false;
3262
+ }
3263
+ }
3264
+ }
3265
+
3266
+ handleOutsideClick = (e) => {
3267
+ const emojiReactions = this.renderRoot.querySelector('emoji-reactions');
3268
+ const messageContainer = this.renderRoot.querySelector('.message-container');
3269
+ const reactionContainer = this.renderRoot.querySelector('reaction-container');
3270
+
3271
+ const path = e.composedPath();
3272
+
3273
+ if ((this.showEmojiReactions &&
3274
+ !path.includes(emojiReactions) &&
3275
+ !path.includes(messageContainer)) ||
3276
+ (this.showConfirmationPopup &&
3277
+ !path.includes(reactionContainer) &&
3278
+ !path.includes(messageContainer))
3279
+ ) {
3280
+ this.showEmojiReactions = false;
3281
+ this.showConfirmationPopup = false;
3282
+ document.removeEventListener('click', this.handleOutsideClick);
3283
+ }
3284
+ }
3285
+ toggleEmojiReactions() {
3286
+ this.showConfirmationPopup = false;
3287
+
3288
+ this.showEmojiReactions = !this.showEmojiReactions;
3289
+
3290
+ if (this.showEmojiReactions) {
3291
+ setTimeout(() => {
3292
+ document.addEventListener('click', this.handleOutsideClick);
3293
+ }, 100);
3294
+ }
3295
+ }
3296
+ handleEmojiClick(emoji) {
3297
+ const currentUserId = this.userMetaData?.userId;
3298
+ const usersForEmoji = this.reactions[emoji.id] || [];
3299
+ const hasReaction = usersForEmoji.includes(currentUserId);
3300
+
3301
+ let existingReactionEmojiId = null;
3302
+
3303
+ for (const [emojiId, userIds] of Object.entries(this.reactions)) {
3304
+ if (userIds.includes(currentUserId)) {
3305
+ existingReactionEmojiId = emojiId;
3306
+ break;
3307
+ }
3308
+ }
3309
+
3310
+ if (existingReactionEmojiId && existingReactionEmojiId !== emoji.id) {
3311
+ this.dispatchEvent(
3312
+ new CustomEvent('reaction-removed', {
3313
+ detail: {
3314
+ messageId: this.messageId,
3315
+ emojiId: existingReactionEmojiId,
3316
+ },
3317
+ bubbles: true,
3318
+ composed: true,
3319
+ }),
3320
+ );
3321
+ }
3322
+
3323
+ if (hasReaction) {
3324
+ this.dispatchEvent(
3325
+ new CustomEvent('reaction-removed', {
3326
+ detail: {
3327
+ messageId: this.messageId,
3328
+ emojiId: emoji.id,
3329
+ },
3330
+ bubbles: true,
3331
+ composed: true,
3332
+ }),
3333
+ );
3334
+ } else {
3335
+ this.dispatchEvent(
3336
+ new CustomEvent('reaction-added', {
3337
+ detail: {
3338
+ messageId: this.messageId,
3339
+ emojiId: emoji.id,
3340
+ },
3341
+ bubbles: true,
3342
+ composed: true,
3343
+ }),
3344
+ );
3345
+ }
3346
+
3347
+ this.showEmojiReactions = false;
3348
+ document.removeEventListener('click', this.handleOutsideClick);
3349
+ }
3350
+ handleConfirmRemove() {
3351
+ if (this.selectedEmojiToRemove) {
3352
+ this.dispatchEvent(
3353
+ new CustomEvent('reaction-removed', {
3354
+ detail: {
3355
+ messageId: this.messageId,
3356
+ emojiId: this.selectedEmojiToRemove.emojiId,
3357
+ },
3358
+ bubbles: true,
3359
+ composed: true,
3360
+ }),
3361
+ );
3362
+ }
3363
+ this.closeConfirmationPopup();
3364
+ }
3365
+
3366
+ closeConfirmationPopup() {
3367
+ this.showConfirmationPopup = false;
3368
+ this.selectedEmojiToRemove = null;
3369
+ }
3370
+
3371
+
3372
+
3373
+ render() {
3374
+ const wrapperClass = `audio-bubble-wrapper ${this.isSelf ? 'sender-bg' : 'receiver-bg'}`;
3375
+ const textClass = this.isSelf ? 'sender-text' : 'receiver-text';
3376
+
3377
+ const emojiList = document.createElement('emoji-reactions').emojis;
3378
+ const allReactions = Object.keys(this.reactions)
3379
+ .map(reaction => {
3380
+ const matchingEmoji = emojiList.find(emoji => emoji.id === reaction);
3381
+ return {
3382
+ emojiId: reaction,
3383
+ messageId: this.reactions[reaction],
3384
+ src: matchingEmoji?.src,
3385
+ };
3386
+ })
3387
+ .filter(reaction => Array.isArray(reaction.messageId) && reaction.messageId.length > 0);
3388
+
3389
+ const visibleReactions = allReactions.slice(0, 2);
3390
+ const remainingCount = allReactions.length > 2 ? allReactions.length - 2 : 0;
3391
+
3392
+ return Image.ke`
3393
+ <div class=${wrapperClass} @mouseover="${() => this.handleMouseEnter()}"
3394
+ @mouseout="${e => this.handleMouseLeave(e)}">
3395
+ ${this.messageType === 1
3396
+ ? Image.ke`
3397
+ ${this.messageType === 1
3398
+ ? Image.ke`
3399
+ <forward-ui></forward-ui>
3400
+ `
3401
+ : null}
3402
+ `
3403
+ : null}
3404
+ <div class="audio-content">
3405
+ ${this._renderPlayPauseIcon()}
3406
+ <div class="wave_container" id="waveform-container"></div>
3407
+ </div>
3408
+ ${!this.isSelf && this.showReactionButton
3409
+ ? Image.ke`
3410
+ <div class="reaction-button" @click="${() => this.toggleEmojiReactions()}" ">
3411
+ <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="var(--text-primary-color)">
3412
+ <path d="M612-516q25 0 42.5-17.5T672-576q0-25-17.5-42.5T612-636q-25 0-42.5 17.5T552-576q0 25 17.5 42.5T612-516Zm-264 0q25 0 42.5-17.5T408-576q0-25-17.5-42.5T348-636q-25 0-42.5 17.5T288-576q0 25 17.5 42.5T348-516Zm132 228q60 0 110.5-31t79.5-84H290q29 53 79.5 84T480-288Zm.28 192Q401-96 331-126t-122.5-82.5Q156-261 126-330.96t-30-149.5Q96-560 126-629.5q30-69.5 82.5-122T330.96-834q69.96-30 149.5-30t149.04 30q69.5 30 122 82.5T834-629.28q30 69.73 30 149Q864-401 834-331t-82.5 122.5Q699-156 629.28-126q-69.73 30-149 30ZM480-480Zm0 312q130 0 221-91t91-221q0-130-91-221t-221-91q-130 0-221 91t-91 221q0 130 91 221t221 91Z"/>
3413
+ </svg>
3414
+ </div>
3415
+ `
3416
+ : ''}
3417
+
3418
+ ${this.showConfirmationPopup
3419
+ ? Image.ke` <reaction-container .messageId=${this.messageId} .userMetaData=${this.userMetaData} .reactions=${allReactions}></reaction-container> `
3420
+ : ''}
3421
+ ${this.showEmojiReactions
3422
+ ? Image.ke`
3423
+ <emoji-reactions .isOpen="${this.showEmojiReactions}" .onEmojiSelect="${emoji => this.handleEmojiClick(emoji)}" .selectedEmojis="${this.reactions}"></emoji-reactions>
3424
+ `
3425
+ : ''}
3426
+
3427
+ <div class="reactions-display">
3428
+ ${visibleReactions?.map(
3429
+ reaction => Image.ke`
3430
+ <span class="reaction-item" @click="${() => this.handleReactionRemove(reaction)}"> ${reaction.src ? Image.ke`<span>${reaction.src}</span>` : ''} </span>
3431
+ `,
3432
+ )}
3433
+ ${remainingCount > 0
3434
+ ? Image.ke`
3435
+ <span @click="${() => this.handleReactionRemove(visibleReactions[0])}" class="reaction-item remaining-count" "> +${remainingCount} </span>
3436
+
3437
+ `
3438
+ : ''}
3439
+ </div>
3440
+ <div class="audio-info">
3441
+ <span class="audio-time ${textClass}">${this.audioDuration}</span>
3442
+ </div>
3443
+
3444
+ ${this.showFooter ? Image.ke`
3445
+ <div class="message-footer">
3446
+ <timestamp-element time="${this.time || new Date().toISOString()}" color="${this.timeColor}" ></timestamp-element>
3447
+ ${this.isSelf
3448
+ ? this.isRead
3449
+ ? Image.ke`<blue-read-mark></blue-read-mark>`
3450
+ : this.isDelivered === 'true'
3451
+ ? Image.ke`<double-mark></double-mark>`
3452
+ : this.isDelivered === 'pending'
3453
+ ? Image.ke`<clock-mark></clock-mark>`
3454
+ : Image.ke`<single-mark></single-mark>`
3455
+ : ''}
3456
+ </div>`:null}
3457
+ </div>
3458
+ `;
3459
+ }
3460
+
3461
+ _renderPlayPauseIcon() {
3462
+ const iconClass = `chat_audio_play_pause pointer ${this.isSelf ? 'sender-icon' : 'receiver-icon'}`;
3463
+ if (this.isPlaying) {
3464
+ return Image.ke`
3465
+ <div @click=${this.pauseAudioHandler} class=${iconClass}>
3466
+ <svg
3467
+ xmlns="http://www.w3.org/2000/svg"
3468
+ width="24"
3469
+ height="24"
3470
+ viewBox="0 0 24 24"
3471
+ fill="none"
3472
+ stroke="currentColor"
3473
+ stroke-width="2"
3474
+ stroke-linecap="round"
3475
+ stroke-linejoin="round"
3476
+ >
3477
+ <rect x="6" y="4" width="4" height="16"></rect>
3478
+ <rect x="14" y="4" width="4" height="16"></rect>
3479
+ </svg>
3480
+ </div>
3481
+ `;
3482
+ } else {
3483
+ return Image.ke`
3484
+ <div @click=${this.playAudioHandler} class=${iconClass}>
3485
+ <svg
3486
+ xmlns="http://www.w3.org/2000/svg"
3487
+ width="24"
3488
+ height="24"
3489
+ viewBox="0 0 24 24"
3490
+ fill="none"
3491
+ stroke="currentColor"
3492
+ stroke-width="2"
3493
+ stroke-linecap="round"
3494
+ stroke-linejoin="round"
3495
+ >
3496
+ <polygon points="5 3 19 12 5 21 5 3"></polygon>
3497
+ </svg>
3498
+ </div>
3499
+ `;
3500
+ }
3501
+ }
3502
+ }
3503
+
3504
+ customElements.define('audio-bubble-ui', AudioBubbleUI);
3505
+
3506
+ class MediaGallery extends Image.h {
3507
+ static properties = {
3508
+ allAttachments: {
3509
+ type: Array,
3510
+ hasChanged(newVal, oldVal) {
3511
+ return JSON.stringify(newVal) !== JSON.stringify(oldVal);
3512
+ },
3513
+ },
3514
+ mainImageIndex: { type: Number },
3515
+ topbarBgColor: { type: String },
3516
+ iconColor: { type: String },
3517
+ galleryImageSize: { type: String },
3518
+ isZoomed: { type: Boolean },
3519
+ loadingMediaGallery: { type: Boolean },
3520
+ zoomLevel: { type: Number },
3521
+ isSharePopupOpen: { type: Boolean },
3522
+ shareLink: { type: String },
3523
+ };
3524
+
3525
+ static styles = Image.i`
3526
+ :host {
3527
+ display: block;
3528
+ font-family: Arial, sans-serif;
3529
+ }
3530
+
3531
+ .media-gallery-container {
3532
+ width: 100%;
3533
+ height: 100%;
3534
+ z-index: 1000;
3535
+ display: flex;
3536
+ flex-direction: column;
3537
+ }
3538
+
3539
+ .topbar {
3540
+ display: flex;
3541
+ justify-content: flex-end;
3542
+ background-color: var(--bg-secondary-color);
3543
+ padding: 10px;
3544
+ }
3545
+
3546
+ .topbar-icon-container {
3547
+ display: flex;
3548
+ align-items: center;
3549
+ gap: 10px;
3550
+ }
3551
+
3552
+ .icon {
3553
+ cursor: pointer;
3554
+ color: var(--text-primary-color);
3555
+ }
3556
+
3557
+ .popup-overlay {
3558
+ position: fixed;
3559
+ top: 0;
3560
+ left: 0;
3561
+ height: 100%;
3562
+ width: 100%;
3563
+ background-color: var(--overlay-color);
3564
+ z-index: 999;
3565
+ display: flex;
3566
+ justify-content: center;
3567
+ align-items: center;
3568
+ }
3569
+
3570
+ .main-image-container {
3571
+ text-align: center;
3572
+ padding: 10px;
3573
+ background-color: var(--bg-primary-color);
3574
+ height: 50%;
3575
+ position: relative;
3576
+ touch-action: pan-y pinch-zoom;
3577
+ flex: 1;
3578
+ cursor: zoom-in;
3579
+ overflow: hidden;
3580
+ }
3581
+
3582
+ .main-image-container.zoomed {
3583
+ cursor: move;
3584
+ }
3585
+
3586
+ .main-image {
3587
+ max-width: 100%;
3588
+ height: 100%;
3589
+ border-radius: 5px;
3590
+ transition: transform 0.2s ease;
3591
+ object-fit: contain;
3592
+ }
3593
+
3594
+ .zoom-controls {
3595
+ position: absolute;
3596
+ bottom: 20px;
3597
+ left: 50%;
3598
+ transform: translateX(-50%);
3599
+ background: rgba(0, 0, 0, 0.6);
3600
+ border-radius: 20px;
3601
+ padding: 5px 10px;
3602
+ display: flex;
3603
+ align-items: center;
3604
+ gap: 10px;
3605
+ z-index: 10;
3606
+ }
3607
+
3608
+ .zoom-btn {
3609
+ background: none;
3610
+ border: none;
3611
+ color: white;
3612
+ font-size: 20px;
3613
+ cursor: pointer;
3614
+ width: 30px;
3615
+ height: 30px;
3616
+ display: flex;
3617
+ align-items: center;
3618
+ justify-content: center;
3619
+ }
3620
+
3621
+ .zoom-level {
3622
+ color: white;
3623
+ font-size: 14px;
3624
+ min-width: 50px;
3625
+ text-align: center;
3626
+ }
3627
+
3628
+ .nav-arrow {
3629
+ position: absolute;
3630
+ top: 50%;
3631
+ transform: translateY(-50%);
3632
+ background: rgba(0, 0, 0, 0.5);
3633
+ color: white;
3634
+ padding: 15px 10px;
3635
+ cursor: pointer;
3636
+ border: none;
3637
+ border-radius: 4px;
3638
+ font-size: 20px;
3639
+ z-index: 1;
3640
+ }
3641
+
3642
+ .nav-arrow:hover {
3643
+ background: rgba(0, 0, 0, 0.7);
3644
+ }
3645
+
3646
+ .nav-arrow.left {
3647
+ left: 10px;
3648
+ }
3649
+ .nav-arrow.right {
3650
+ right: 10px;
3651
+ }
3652
+
3653
+ .gallery {
3654
+ display: flex;
3655
+ gap: 10px;
3656
+ background-color: var(--bg-secondary-color);
3657
+ padding: 10px;
3658
+ overflow-x: auto;
3659
+ scrollbar-width: thin;
3660
+ }
3661
+
3662
+ .gallery::-webkit-scrollbar {
3663
+ height: 6px;
3664
+ }
3665
+
3666
+ .gallery::-webkit-scrollbar-thumb {
3667
+ background-color: rgba(0, 0, 0, 0.3);
3668
+ border-radius: 3px;
3669
+ }
3670
+
3671
+ .gallery-image,
3672
+ .gallery-video-container {
3673
+ width: var(--gallery-image-size, 70px);
3674
+ height: var(--gallery-image-size, 70px);
3675
+ flex-shrink: 0;
3676
+ border-radius: 5px;
3677
+ }
3678
+
3679
+ .gallery-image {
3680
+ object-fit: cover;
3681
+ cursor: pointer;
3682
+ transition: transform 0.2s;
3683
+ background-color: var(--base-color);
3684
+ }
3685
+
3686
+ .gallery-image:hover,
3687
+ .gallery-video-container:hover {
3688
+ transform: scale(1.05);
3689
+ }
3690
+
3691
+ .gallery-image.selected,
3692
+ .gallery-video-container.selected {
3693
+ transform: scale(1.1);
3694
+ outline: 3px solid var(--base-color);
3695
+ outline-offset: 2px;
3696
+ }
3697
+
3698
+ .unsupported-media {
3699
+ display: flex;
3700
+ justify-content: center;
3701
+ align-items: center;
3702
+ height: 100%;
3703
+ font-size: 20px;
3704
+ color: #808080;
3705
+ }
3706
+
3707
+ .video-thumbnail {
3708
+ width: 70px;
3709
+ height: 70px;
3710
+ }
3711
+
3712
+ .spinner-wrapper {
3713
+ position: absolute;
3714
+ top: 50%;
3715
+ left: 50%;
3716
+ transform: translate(-50%, -50%);
3717
+ display: flex;
3718
+ justify-content: center;
3719
+ align-items: center;
3720
+ }
3721
+
3722
+ .audio-wrapper{
3723
+ height: 100%;
3724
+ display: flex;
3725
+ align-items: center;
3726
+ justify-content: center;
3727
+ }
3728
+
3729
+ @media (max-width: 768px) {
3730
+ .main-image { max-height: 100%; }
3731
+ .gallery-image, .gallery-video-container {
3732
+ width: calc(var(--gallery-image-size, 70px) - 10px);
3733
+ height: calc(var(--gallery-image-size, 70px) - 10px);
3734
+ }
3735
+ }
3736
+ `;
3737
+
3738
+ constructor() {
3739
+ super();
3740
+ this.mainImageIndex = 0;
3741
+ this.topbarBgColor = '#f1f1f1';
3742
+ this.iconColor = 'var(--text-primary-color)';
3743
+ this.galleryImageSize = '70px';
3744
+ this.isZoomed = false;
3745
+ this.loadingMediaGallery = false;
3746
+ this._mediaItems = null;
3747
+ this._boundKeyHandler = this.handleKeyPress.bind(this);
3748
+ this._attachmentsHash = '';
3749
+
3750
+ // Zoom related properties
3751
+ this.zoomLevel = 1;
3752
+ this.minZoom = 1;
3753
+ this.maxZoom = 5;
3754
+ this.zoomStep = 0.5;
3755
+ this.isDragging = false;
3756
+ this.startX = 0;
3757
+ this.startY = 0;
3758
+ this.translateX = 0;
3759
+ this.translateY = 0;
3760
+ this.initialPinchDistance = 0;
3761
+
3762
+ // Image boundaries for constrained panning
3763
+ this.imageBounds = {
3764
+ width: 0,
3765
+ height: 0
3766
+ };
3767
+ this.containerBounds = {
3768
+ width: 0,
3769
+ height: 0
3770
+ };
3771
+ }
3772
+
3773
+ connectedCallback() {
3774
+ super.connectedCallback();
3775
+ window.addEventListener('keydown', this._boundKeyHandler);
3776
+ }
3777
+
3778
+ disconnectedCallback() {
3779
+ super.disconnectedCallback();
3780
+ window.removeEventListener('keydown', this._boundKeyHandler);
3781
+ this._removeZoomListeners();
3782
+ }
3783
+
3784
+ updated(changedProperties) {
3785
+ super.updated(changedProperties);
3786
+
3787
+ if (changedProperties.has('allAttachments')) {
3788
+ this.resetMediaItemsCache();
3789
+ }
3790
+
3791
+ if (changedProperties.has('mainImageIndex')) {
3792
+ // Reset zoom when changing images
3793
+ this.resetZoom();
3794
+ }
3795
+
3796
+ if (changedProperties.has('isZoomed')) {
3797
+ const mainContainer = this.shadowRoot.querySelector('.main-image-container');
3798
+ if (this.isZoomed) {
3799
+ mainContainer.classList.add('zoomed');
3800
+ this._setupZoomListeners();
3801
+ this._updateBoundingBoxes();
3802
+ } else {
3803
+ mainContainer.classList.remove('zoomed');
3804
+ this._removeZoomListeners();
3805
+ this.resetZoom();
3806
+ }
3807
+ }
3808
+
3809
+ if (changedProperties.has('zoomLevel')) {
3810
+ this._updateBoundingBoxes();
3811
+ }
3812
+ }
3813
+
3814
+ _updateBoundingBoxes() {
3815
+ requestAnimationFrame(() => {
3816
+ const container = this.shadowRoot.querySelector('.main-image-container');
3817
+ const image = this.shadowRoot.querySelector('.main-image');
3818
+
3819
+ if (!container || !image) return;
3820
+
3821
+ // Get the displayed dimensions of the image (not zoomed)
3822
+ const displayedWidth = image.offsetWidth / this.zoomLevel;
3823
+ const displayedHeight = image.offsetHeight / this.zoomLevel;
3824
+
3825
+ // Calculate the zoomed dimensions
3826
+ this.imageBounds = {
3827
+ width: displayedWidth * this.zoomLevel,
3828
+ height: displayedHeight * this.zoomLevel
3829
+ };
3830
+
3831
+ this.containerBounds = {
3832
+ width: container.clientWidth,
3833
+ height: container.clientHeight
3834
+ };
3835
+ });
3836
+ }
3837
+
3838
+ _calculateAttachmentsHash(attachments) {
3839
+ return JSON.stringify(attachments);
3840
+ }
3841
+
3842
+ _processAttachments() {
3843
+ if (!this.allAttachments) return [];
3844
+
3845
+ return this.allAttachments.reduce((acc, message) => {
3846
+ if (message.attachments?.length) {
3847
+ const validAttachments = message.attachments.filter(
3848
+ attachment => attachment.mimeType?.match(/^(image|video|audio)\//)
3849
+ );
3850
+ return [...acc, ...validAttachments];
3851
+ }
3852
+ return acc;
3853
+ }, []);
3854
+ }
3855
+
3856
+ get mediaItems() {
3857
+ const currentHash = this._calculateAttachmentsHash(this.allAttachments);
3858
+
3859
+ if (this._mediaItems === null || currentHash !== this._attachmentsHash) {
3860
+ this._attachmentsHash = currentHash;
3861
+ this._mediaItems = this._processAttachments();
3862
+ }
3863
+
3864
+ return this._mediaItems;
3865
+ }
3866
+
3867
+ resetMediaItemsCache() {
3868
+ this._mediaItems = null;
3869
+ this._attachmentsHash = '';
3870
+ }
3871
+
3872
+ handleKeyPress(event) {
3873
+ const currentMedia = this.mediaItems[this.mainImageIndex];
3874
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
3875
+
3876
+ switch (event.key) {
3877
+ case 'ArrowLeft':
3878
+ this.navigateImage('prev');
3879
+ break;
3880
+ case 'ArrowRight':
3881
+ this.navigateImage('next');
3882
+ break;
3883
+ case 'Escape':
3884
+ if (this.isZoomed) {
3885
+ this.resetZoom();
3886
+ } else {
3887
+ this.closeGallery();
3888
+ }
3889
+ break;
3890
+ case '+':
3891
+ if (isImage) this.zoomIn();
3892
+ break;
3893
+ case '-':
3894
+ if (isImage) this.zoomOut();
3895
+ break;
3896
+ case ' ':
3897
+ case 'Enter':
3898
+ if (isImage) this.toggleZoom();
3899
+ break;
3900
+ }
3901
+ }
3902
+
3903
+ navigateImage(direction) {
3904
+ const newIndex = direction === 'next' ? Math.min(this.mainImageIndex + 1, this.mediaItems.length - 1) : Math.max(this.mainImageIndex - 1, 0);
3905
+
3906
+ if (newIndex !== this.mainImageIndex) {
3907
+ this.isZoomed = false;
3908
+ this.mainImageIndex = newIndex;
3909
+ }
3910
+ }
3911
+
3912
+ toggleZoom() {
3913
+ this.isZoomed = !this.isZoomed;
3914
+
3915
+ if (this.isZoomed) {
3916
+ this.zoomLevel = 1.5; // Start with slight zoom
3917
+ this._updateBoundingBoxes();
3918
+ this.updateZoomStyle();
3919
+ } else {
3920
+ this.resetZoom();
3921
+ }
3922
+ }
3923
+
3924
+ resetZoom() {
3925
+ this.zoomLevel = 1;
3926
+ this.translateX = 0;
3927
+ this.translateY = 0;
3928
+ this.isZoomed = false;
3929
+ this.updateZoomStyle();
3930
+ }
3931
+
3932
+ zoomIn(e) {
3933
+ if (e) e.stopPropagation();
3934
+
3935
+ if (this.zoomLevel < this.maxZoom) {
3936
+ this.zoomLevel = Math.min(this.zoomLevel + this.zoomStep, this.maxZoom);
3937
+ this._updateBoundingBoxes();
3938
+ this.constrainTranslation();
3939
+ this.updateZoomStyle();
3940
+ }
3941
+ }
3942
+
3943
+ zoomOut(e) {
3944
+ if (e) e.stopPropagation();
3945
+
3946
+ if (this.zoomLevel > this.minZoom) {
3947
+ this.zoomLevel = Math.max(this.zoomLevel - this.zoomStep, this.minZoom);
3948
+
3949
+ // If we're back at min zoom, reset position
3950
+ if (this.zoomLevel === this.minZoom) {
3951
+ this.translateX = 0;
3952
+ this.translateY = 0;
3953
+ } else {
3954
+ this._updateBoundingBoxes();
3955
+ this.constrainTranslation();
3956
+ }
3957
+
3958
+ this.updateZoomStyle();
3959
+ }
3960
+ }
3961
+
3962
+ // New method to constrain the translation within visible bounds
3963
+ constrainTranslation() {
3964
+ // Calculate how much the image extends beyond the container on each side when zoomed
3965
+ const overflowX = Math.max(0, this.imageBounds.width - this.containerBounds.width);
3966
+ const overflowY = Math.max(0, this.imageBounds.height - this.containerBounds.height);
3967
+
3968
+ // Ensure a minimum percentage of the image remains visible (e.g., 20%)
3969
+ const minVisibleWidth = this.containerBounds.width * 0.2;
3970
+ const minVisibleHeight = this.containerBounds.height * 0.2;
3971
+
3972
+ // Calculate maximum allowed translation
3973
+ // This allows the image to move until only the minimum visible portion remains
3974
+ const maxTranslateX = overflowX / 2 + (this.containerBounds.width - minVisibleWidth) / 2;
3975
+ const maxTranslateY = overflowY / 2 + (this.containerBounds.height - minVisibleHeight) / 2;
3976
+
3977
+ // Constrain the translation values
3978
+ this.translateX = Math.max(-maxTranslateX, Math.min(maxTranslateX, this.translateX));
3979
+ this.translateY = Math.max(-maxTranslateY, Math.min(maxTranslateY, this.translateY));
3980
+ }
3981
+
3982
+ updateZoomStyle() {
3983
+ const mainImage = this.shadowRoot.querySelector('.main-image');
3984
+ if (!mainImage) return;
3985
+
3986
+ mainImage.style.transform = `translate(${this.translateX}px, ${this.translateY}px) scale(${this.zoomLevel})`;
3987
+
3988
+ // Only show zoomed cursor when zoomed in
3989
+ const container = this.shadowRoot.querySelector('.main-image-container');
3990
+ if (container) {
3991
+ if (this.zoomLevel > 1) {
3992
+ container.classList.add('zoomed');
3993
+ } else {
3994
+ container.classList.remove('zoomed');
3995
+ }
3996
+ }
3997
+
3998
+ this.requestUpdate();
3999
+ }
4000
+
4001
+ _setupZoomListeners() {
4002
+ const container = this.shadowRoot.querySelector('.main-image-container');
4003
+ const mainImage = this.shadowRoot.querySelector('.main-image');
4004
+
4005
+ if (!container || !mainImage) return;
4006
+
4007
+ // Mouse events for desktop
4008
+ this._boundMouseDown = this.handleMouseDown.bind(this);
4009
+ this._boundMouseMove = this.handleMouseMove.bind(this);
4010
+ this._boundMouseUp = this.handleMouseUp.bind(this);
4011
+ this._boundWheel = this.handleWheel.bind(this);
4012
+
4013
+ // Touch events for mobile
4014
+ this._boundTouchStart = this.handleTouchStart.bind(this);
4015
+ this._boundTouchMove = this.handleTouchMove.bind(this);
4016
+ this._boundTouchEnd = this.handleTouchEnd.bind(this);
4017
+
4018
+ container.addEventListener('mousedown', this._boundMouseDown);
4019
+ window.addEventListener('mousemove', this._boundMouseMove);
4020
+ window.addEventListener('mouseup', this._boundMouseUp);
4021
+ container.addEventListener('wheel', this._boundWheel);
4022
+
4023
+ container.addEventListener('touchstart', this._boundTouchStart, { passive: false });
4024
+ container.addEventListener('touchmove', this._boundTouchMove, { passive: false });
4025
+ container.addEventListener('touchend', this._boundTouchEnd);
4026
+
4027
+ // Update bounding boxes on window resize
4028
+ this._boundResizeHandler = this._updateBoundingBoxes.bind(this);
4029
+ window.addEventListener('resize', this._boundResizeHandler);
4030
+
4031
+ // Initial update of bounding boxes
4032
+ this._updateBoundingBoxes();
4033
+ }
4034
+
4035
+ _removeZoomListeners() {
4036
+ const container = this.shadowRoot.querySelector('.main-image-container');
4037
+
4038
+ if (!container) return;
4039
+
4040
+ if (this._boundMouseDown) {
4041
+ container.removeEventListener('mousedown', this._boundMouseDown);
4042
+ window.removeEventListener('mousemove', this._boundMouseMove);
4043
+ window.removeEventListener('mouseup', this._boundMouseUp);
4044
+ container.removeEventListener('wheel', this._boundWheel);
4045
+
4046
+ container.removeEventListener('touchstart', this._boundTouchStart);
4047
+ container.removeEventListener('touchmove', this._boundTouchMove);
4048
+ container.removeEventListener('touchend', this._boundTouchEnd);
4049
+ }
4050
+
4051
+ if (this._boundResizeHandler) {
4052
+ window.removeEventListener('resize', this._boundResizeHandler);
4053
+ }
4054
+ }
4055
+
4056
+ handleMouseDown(e) {
4057
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4058
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
4059
+
4060
+ if (!isImage || this.zoomLevel <= 1) return;
4061
+
4062
+ this.isDragging = true;
4063
+ this.startX = e.clientX - this.translateX;
4064
+ this.startY = e.clientY - this.translateY;
4065
+ e.preventDefault();
4066
+ }
4067
+
4068
+ handleMouseMove(e) {
4069
+ if (!this.isDragging) return;
4070
+
4071
+ const newTranslateX = e.clientX - this.startX;
4072
+ const newTranslateY = e.clientY - this.startY;
4073
+
4074
+ this.translateX = newTranslateX;
4075
+ this.translateY = newTranslateY;
4076
+
4077
+ // Apply constraints to keep the image in view
4078
+ this.constrainTranslation();
4079
+ this.updateZoomStyle();
4080
+ e.preventDefault();
4081
+ }
4082
+
4083
+ handleMouseUp() {
4084
+ this.isDragging = false;
4085
+ }
4086
+
4087
+ handleWheel(e) {
4088
+ e.preventDefault();
4089
+
4090
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4091
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
4092
+
4093
+ if (!isImage) return;
4094
+
4095
+ // Get cursor position relative to container for zoom targeting
4096
+ const container = this.shadowRoot.querySelector('.main-image-container');
4097
+ container.getBoundingClientRect();
4098
+
4099
+ // Store old zoom level
4100
+ const oldZoom = this.zoomLevel;
4101
+
4102
+ if (e.deltaY < 0) {
4103
+ // Zoom in
4104
+ this.zoomIn();
4105
+ } else {
4106
+ // Zoom out
4107
+ this.zoomOut();
4108
+ }
4109
+
4110
+ // If zoom level actually changed and we're zoomed in
4111
+ if (oldZoom !== this.zoomLevel && this.zoomLevel > 1) {
4112
+ // Adjust translateX and translateY to zoom in/out around cursor position
4113
+ // This is a simplified approach - for more precise targeting, you'd need more complex math
4114
+ this.constrainTranslation();
4115
+ }
4116
+ }
4117
+
4118
+ handleTouchStart(e) {
4119
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4120
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
4121
+
4122
+ if (!isImage) return;
4123
+
4124
+ e.preventDefault();
4125
+
4126
+ if (e.touches.length === 1) {
4127
+ // Single touch - prepare for panning
4128
+ this.isDragging = true;
4129
+ this.startX = e.touches[0].clientX - this.translateX;
4130
+ this.startY = e.touches[0].clientY - this.translateY;
4131
+ }
4132
+ else if (e.touches.length === 2) {
4133
+ // Pinch to zoom
4134
+ this.isDragging = false;
4135
+ const touch1 = e.touches[0];
4136
+ const touch2 = e.touches[1];
4137
+ this.initialPinchDistance = Math.hypot(
4138
+ touch2.clientX - touch1.clientX,
4139
+ touch2.clientY - touch1.clientY
4140
+ );
4141
+ }
4142
+ }
4143
+
4144
+ handleTouchMove(e) {
4145
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4146
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
4147
+
4148
+ if (!isImage || this.zoomLevel <= 1 && e.touches.length === 1) return;
4149
+
4150
+ e.preventDefault();
4151
+
4152
+ if (e.touches.length === 1 && this.isDragging) {
4153
+ // Pan the image
4154
+ this.translateX = e.touches[0].clientX - this.startX;
4155
+ this.translateY = e.touches[0].clientY - this.startY;
4156
+
4157
+ // Apply constraints to keep the image in view
4158
+ this.constrainTranslation();
4159
+ this.updateZoomStyle();
4160
+ }
4161
+ else if (e.touches.length === 2) {
4162
+ // Pinch zoom
4163
+ const touch1 = e.touches[0];
4164
+ const touch2 = e.touches[1];
4165
+ const currentDistance = Math.hypot(
4166
+ touch2.clientX - touch1.clientX,
4167
+ touch2.clientY - touch1.clientY
4168
+ );
4169
+
4170
+ if (this.initialPinchDistance > 0) {
4171
+ const pinchRatio = currentDistance / this.initialPinchDistance;
4172
+ const newZoomLevel = Math.max(
4173
+ this.minZoom,
4174
+ Math.min(this.maxZoom, this.zoomLevel * pinchRatio)
4175
+ );
4176
+
4177
+ // Apply zoom centered on pinch point
4178
+ this.zoomLevel = newZoomLevel;
4179
+ this.initialPinchDistance = currentDistance;
4180
+
4181
+ this._updateBoundingBoxes();
4182
+ this.constrainTranslation();
4183
+ this.updateZoomStyle();
4184
+ }
4185
+ }
4186
+ }
4187
+
4188
+ handleTouchEnd(e) {
4189
+ this.isDragging = false;
4190
+ this.initialPinchDistance = 0;
4191
+
4192
+ // If we're at minimum zoom, reset position
4193
+ if (this.zoomLevel <= this.minZoom) {
4194
+ this.resetZoom();
4195
+ }
4196
+ }
4197
+
4198
+ handleShare() {
4199
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4200
+ if (!currentMedia) return;
4201
+ dialogDrawer.drawerDialogService.openDialog('share-popup', {
4202
+ titleColor:"var(--text-primary-color)",
4203
+ ctaColor:"var(--bg-primary-color)",
4204
+ title:content.WEB_CONTENT.POPUP_MESSAGES.SHARE_MEDIA_LABEL,
4205
+ shareLink:currentMedia.mediaUrl
4206
+ });
4207
+
4208
+ }
4209
+
4210
+
4211
+ async handleDownload() {
4212
+ const currentMedia = this.mediaItems[this.mainImageIndex];
4213
+ if (!currentMedia) return;
4214
+
4215
+ const extension = currentMedia.mimeType?.includes('/') ? '.' + currentMedia.mimeType.split('/')[1] : '.jpg';
4216
+
4217
+ try {
4218
+ const response = await fetch(currentMedia.mediaUrl);
4219
+ const blob = await response.blob();
4220
+ const url = URL.createObjectURL(blob);
4221
+ const a = document.createElement('a');
4222
+ a.href = url;
4223
+ a.download = `chat-media${extension}`;
4224
+ document.body.appendChild(a);
4225
+ a.click();
4226
+ document.body.removeChild(a);
4227
+ URL.revokeObjectURL(url);
4228
+ } catch (error) {
4229
+ console.error('Download failed:', error);
4230
+ }
4231
+ }
4232
+
4233
+ openShareWindow(url) {
4234
+ window.open(`mailto:?body=${encodeURIComponent(url)}`, '_blank');
4235
+ }
4236
+
4237
+ closeGallery() {
4238
+ this.dispatchEvent(new CustomEvent('close', { bubbles: true, composed: true }));
4239
+ }
4240
+
4241
+
4242
+ render() {
4243
+ const items = this.mediaItems;
4244
+
4245
+ if (this.loadingMediaGallery && !items.length) {
4246
+ return Image.ke`<div class="spinner-wrapper">
4247
+ <spinner-loader
4248
+ height="15px"
4249
+ width="15px"
4250
+ spinTime="1s"
4251
+ spinnerPrimaryColor="var(--bg-primary-color)"
4252
+ spinnerSecondaryColor="var(--text-primary-color)"
4253
+ spinnerBorderWidth="2px"
4254
+ ></spinner-loader>
4255
+ </div>`;
4256
+ }
4257
+
4258
+ if (!this.loadingMediaGallery && !items.length) {
4259
+ return Image.ke`<div class="unsupported-media">${content.WEB_CONTENT.PLACEHOLDER_CONTENT.UNSUPPORTED_MEDIA}</div>`;
4260
+ }
4261
+
4262
+ const currentMedia = items[this.mainImageIndex];
4263
+ const isImage = currentMedia?.mimeType?.startsWith('image/');
4264
+ const isVideo = currentMedia?.mimeType?.startsWith('video/');
4265
+ const isAudio = currentMedia?.mimeType?.startsWith('audio/');
4266
+
4267
+ return Image.ke`
4268
+ <div class="media-gallery-container">
4269
+ <div class="topbar">
4270
+ <div class="topbar-icon-container">
4271
+ ${!isAudio ? Image.ke` <span class="icon" @click=${this.handleShare}>
4272
+ <svg width="20" height="20" fill="var(--text-primary-color)" viewBox="0 0 1920 1920">
4273
+ <path
4274
+ d="M1513.827 1278.28c-96.772 0-182.634 43.765-241.415 111.531l-564.2-325.737c11.807-33.498 19.508-69.049 19.508-106.654 0-34.91-7.06-68.022-17.327-99.595l563.815-325.48c58.782 66.482 143.746 109.35 239.619 109.35 177.243 0 320.86-143.618 320.86-320.86 0-177.244-143.617-320.86-320.86-320.86-177.243 0-320.86 143.616-320.86 320.86 0 35.165 7.059 68.407 17.454 99.98l-563.686 325.48C587.953 679.554 502.86 636.56 406.86 636.56 229.617 636.56 86 780.177 86 957.42c0 177.243 143.617 320.86 320.86 320.86 93.434 0 176.601-40.428 235.254-104.215l567.537 327.662c-9.882 30.803-16.684 63.145-16.684 97.413 0 177.243 143.617 320.86 320.86 320.86 177.243 0 320.86-143.617 320.86-320.86 0-177.243-143.617-320.86-320.86-320.86"
4275
+ />
4276
+ </svg>
4277
+ </span>` : null}
4278
+ <span class="icon" @click=${this.handleDownload}>
4279
+ <svg width="24" fill="var(--text-primary-color)" height="24" viewBox="0 0 24 24">
4280
+ <path
4281
+ d="M9.163 2.819C9 3.139 9 3.559 9 4.4V11H7.803c-.883 0-1.325 0-1.534.176a.75.75 0 0 0-.266.62c.017.274.322.593.931 1.232l4.198 4.401c.302.318.453.476.63.535a.749.749 0 0 0 .476 0c.177-.059.328-.217.63-.535l4.198-4.4c.61-.64.914-.96.93-1.233a.75.75 0 0 0-.265-.62C17.522 11 17.081 11 16.197 11H15V4.4c0-.84 0-1.26-.164-1.581a1.5 1.5 0 0 0-.655-.656C13.861 2 13.441 2 12.6 2h-1.2c-.84 0-1.26 0-1.581.163a1.5 1.5 0 0 0-.656.656zM5 21a1 1 0 0 0 1 1h12a1 1 0 1 0 0-2H6a1 1 0 0 0-1 1z"
4282
+ />
4283
+ </svg>
4284
+ </span>
4285
+ <span class="icon" @click=${this.closeGallery}>
4286
+ <svg width="24" height="24" fill="var(--text-primary-color)" viewBox="0 0 24 24">
4287
+ <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z" />
4288
+ </svg>
4289
+ </span>
4290
+ </div>
4291
+ </div>
4292
+
4293
+ <div class="main-image-container">
4294
+ ${this.mainImageIndex > 0
4295
+ ? Image.ke`<button class="nav-arrow left" @click=${e => (e.stopPropagation(), this.navigateImage('prev'))}>←</button>`
4296
+ : ''}
4297
+
4298
+ ${
4299
+ isImage
4300
+ ? Image.ke`
4301
+ <img src="${currentMedia.mediaUrl}" alt="Main Image" class="main-image" @dblclick=${this.toggleZoom} />
4302
+ ${this.isZoomed && isImage ? Image.ke`
4303
+ <div class="zoom-controls">
4304
+ <button class="zoom-btn" @click=${this.zoomOut}>−</button>
4305
+ <span class="zoom-level">${Math.round(this.zoomLevel * 100)}%</span>
4306
+ <button class="zoom-btn" @click=${this.zoomIn}>+</button>
4307
+ </div>
4308
+ ` : ''}
4309
+ `
4310
+ : isVideo
4311
+ ? Image.ke`<video src="${currentMedia.mediaUrl}" class="main-image" controls autoplay></video>`
4312
+ : isAudio
4313
+ ? Image.ke`
4314
+ <div class='audio-wrapper' key=${currentMedia?.mediaUrl}>
4315
+ <audio-bubble
4316
+ .audioUrl=${currentMedia?.mediaUrl}
4317
+ .showFooter=${false}
4318
+ ></audio-bubble>
4319
+ </div>
4320
+ `
4321
+ : Image.ke`<div class="unsupported-media">${content.WEB_CONTENT.UNSUPPORTED_MEDIA_TYPES}</div>`}
4322
+
4323
+ ${this.mainImageIndex < items.length - 1
4324
+ ? Image.ke`<button class="nav-arrow right" @click=${e => (e.stopPropagation(), this.navigateImage('next'))}>→</button>`
4325
+ : ''}
4326
+ </div>
4327
+
4328
+ <div class="gallery">
4329
+ ${items.map((media, index) => {
4330
+ const isVideo = media.mimeType?.startsWith('video/');
4331
+ const isAudio = media.mimeType?.startsWith('audio/');
4332
+ return isVideo
4333
+ ? Image.ke`
4334
+ <div class="gallery-video-container ${index === this.mainImageIndex ? 'selected' : ''}"
4335
+ @click=${() => (this.mainImageIndex = index)}>
4336
+ <img class='video-thumbnail' src="${videoPlaceholderSvg}"></img>
4337
+ </div>`
4338
+ : isAudio
4339
+ ? Image.ke`
4340
+ <img src="${equalizerSvg}"
4341
+ alt="Gallery Image ${index + 1}"
4342
+ class="gallery-image ${index === this.mainImageIndex ? 'selected' : ''}"
4343
+ @click=${() => (this.mainImageIndex = index)} />`
4344
+ : Image.ke`
4345
+ <img src="${media.mediaUrl}"
4346
+ alt="Gallery Image ${index + 1}"
4347
+ class="gallery-image ${index === this.mainImageIndex ? 'selected' : ''}"
4348
+ @click=${() => (this.mainImageIndex = index)} />`;
4349
+ })}
4350
+ </div>
4351
+ </div>
4352
+ `;
4353
+ }
4354
+ }
4355
+
4356
+ customElements.define('media-gallery', MediaGallery);
4357
+
4358
+ const imagePlaceholderSvg = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhLS0gVXBsb2FkZWQgdG86IFNWRyBSZXBvLCB3d3cuc3ZncmVwby5jb20sIEdlbmVyYXRvcjogU1ZHIFJlcG8gTWl4ZXIgVG9vbHMgLS0+CjxzdmcgZmlsbD0iIzAwMDAwMCIgd2lkdGg9IjgwMHB4IiBoZWlnaHQ9IjgwMHB4IiB2aWV3Qm94PSIwIDAgMzUgMzUiIGRhdGEtbmFtZT0iTGF5ZXIgMiIgaWQ9ImY3YjlkMzFiLTNkYjQtNDhkYi05NjMwLTViNDYyNDk5NmY1OCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMjkuNDY3LDM0Ljc0OUg1LjUzQTUuMjg4LDUuMjg4LDAsMCwxLC4yNSwyOS40NjdWNS41MzJBNS4yODYsNS4yODYsMCwwLDEsNS41My4yNTJIMjkuNDY3YTUuMjg2LDUuMjg2LDAsMCwxLDUuMjgsNS4yOFYyOS40NjdBNS4yODgsNS4yODgsMCwwLDEsMjkuNDY3LDM0Ljc0OVpNNS41MywyLjc1MmEyLjc4MywyLjc4MywwLDAsMC0yLjc4LDIuNzhWMjkuNDY3YTIuNzg0LDIuNzg0LDAsMCwwLDIuNzgsMi43ODJIMjkuNDY3YTIuNzg0LDIuNzg0LDAsMCwwLDIuNzgtMi43ODJWNS41MzJhMi43ODMsMi43ODMsMCwwLDAtMi43OC0yLjc4WiIvPjxwYXRoIGQ9Ik0xMS44NiwxNy4yMjZhNC40NjgsNC40NjgsMCwxLDEsNC40NjgtNC40NjhBNC40NzMsNC40NzMsMCwwLDEsMTEuODYsMTcuMjI2Wm0wLTYuNDM1YTEuOTY4LDEuOTY4LDAsMSwwLDEuOTY4LDEuOTY3QTEuOTcsMS45NywwLDAsMCwxMS44NiwxMC43OTFaIi8+PHBhdGggZD0iTTIuNjY0LDMxLjkyYTEuMjUsMS4yNSwwLDAsMS0uOTI5LTIuMDg1bDUuODc2LTYuNTQ3YTMuMjg4LDMuMjg4LDAsMCwxLDQuNTUzLS4zNDFsMi41MjUsMi4wODRhLjc3Ljc3LDAsMCwwLC42LjE3OC43OTQuNzk0LDAsMCwwLC41NDMtLjNsNi42NDQtOC41ODRhMy4yNzcsMy4yNzcsMCwwLDEsMi42LTEuMjc5aC4wMTJBMy4yODIsMy4yODIsMCwwLDEsMjcuNjczLDE2LjNsNi4zNzIsOC4xMDdhMS4yNSwxLjI1LDAsMCwxLTEuOTY2LDEuNTQ1bC02LjM3Mi04LjEwN2EuNzg1Ljc4NSwwLDAsMC0uNjI3LS4zLjg2NC44NjQsMCwwLDAtLjYzMS4zMDlMMTcuOCwyNi40MzRhMy4zLDMuMywwLDAsMS00LjcwNy41MjVsLTIuNTI1LTIuMDg0YS43OTQuNzk0LDAsMCwwLTEuMS4wODNMMy42LDMxLjVBMS4yNDUsMS4yNDUsMCwwLDEsMi42NjQsMzEuOTJaIi8+PC9zdmc+';
4359
+
4360
+ exports.WaveSurfer = WaveSurfer;
4361
+ exports.equalizerSvg = equalizerSvg;
4362
+ exports.imagePlaceholderSvg = imagePlaceholderSvg;
4363
+ exports.videoPlaceholderSvg = videoPlaceholderSvg;
4364
+
4365
+ //# sourceMappingURL=imagePlaceholder-030cc566.js.map