@ethora/chat-component 26.9.6 → 26.10.1

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 (133) hide show
  1. package/README.md +45 -3
  2. package/dist/{ChatProfileModal-DKuxJsdM.js → ChatProfileModal-Bf5jGPBZ.js} +566 -562
  3. package/dist/FilePreviewModal-Bwx0RZZw.js +1763 -0
  4. package/dist/{ManageDataModal-Dw4dCQll.js → ManageDataModal-Dhkp0LWH.js} +20 -20
  5. package/dist/{MarkdownBody-xtKDMR0h.js → MarkdownBody-_sUhW2O8.js} +1 -1
  6. package/dist/{MessageSearchModal-BVKU6H3v.js → MessageSearchModal-rwwWrILl.js} +106 -114
  7. package/dist/{PublicChatsModal-CscOnVaQ.js → PublicChatsModal-Byso6_vt.js} +13 -13
  8. package/dist/{SideDrawer-WneDrrWG.js → SideDrawer-CQPOf0ek.js} +38 -38
  9. package/dist/{UserProfileModal-CMHFq1I9.js → UserProfileModal-Vj2kICvc.js} +10 -10
  10. package/dist/{UserSettingsModal-BoZXZ0oR.js → UserSettingsModal-CioX4ZIV.js} +5 -5
  11. package/dist/{VideoCallOverlay-CQNi7wp5.js → VideoCallOverlay-DodAkiam.js} +3824 -3708
  12. package/dist/{VisibilityModal-BPsNiMzJ.js → VisibilityModal-CIl7rkBM.js} +12 -12
  13. package/dist/assets/icons.d.ts +2 -3
  14. package/dist/components/Files/fileCategory.d.ts +4 -2
  15. package/dist/components/InputComponents/MentionDropdown.d.ts +2 -0
  16. package/dist/components/MainComponents/AlbumGrid.d.ts +22 -0
  17. package/dist/components/MainComponents/AttachmentList.d.ts +6 -6
  18. package/dist/components/MainComponents/ImageUnavailable.d.ts +21 -0
  19. package/dist/components/MainComponents/MediaUploadOverlay.d.ts +31 -0
  20. package/dist/components/MainComponents/MessageContainer.d.ts +3 -0
  21. package/dist/components/MainComponents/scrollAnchor.d.ts +19 -0
  22. package/dist/components/MainComponents/useJumpToMessage.d.ts +42 -11
  23. package/dist/components/MainComponents/useScrollAnchor.d.ts +29 -0
  24. package/dist/components/MessageBubble/MediaCaption.d.ts +9 -0
  25. package/dist/components/MessageBubble/MessageAvatarPhoto.d.ts +17 -0
  26. package/dist/components/MessageBubble/MessageReaction.d.ts +6 -0
  27. package/dist/components/MessageBubble/QuickReplies.d.ts +2 -0
  28. package/dist/components/Modals/FilePreviewModal/FilePreviewModal.d.ts +8 -10
  29. package/dist/components/Modals/FilePreviewModal/ImageLightbox.d.ts +4 -0
  30. package/dist/components/Modals/FilePreviewModal/PdfView.d.ts +4 -0
  31. package/dist/components/Modals/FilePreviewModal/ViewerChrome.d.ts +64 -0
  32. package/dist/components/Modals/MessageSearchModal/MessageHitResults.d.ts +5 -0
  33. package/dist/components/Modals/styledModalComponents.d.ts +0 -8
  34. package/dist/components/RoomComponents/LastMessageItem.d.ts +2 -0
  35. package/dist/components/RoomComponents/styled/LastMessageMedia.d.ts +19 -0
  36. package/dist/components/RoomComponents/styled/LastTextMessage.d.ts +2 -2
  37. package/dist/components/RoomComponents/styled/StyledRoomComponents.d.ts +10 -3
  38. package/dist/components/VideoCalls/VideoCallSession.d.ts +13 -0
  39. package/dist/components/styled/FileCard.d.ts +20 -0
  40. package/dist/components/styled/MediaSurface.d.ts +50 -0
  41. package/dist/components/styled/MessageImage.d.ts +9 -10
  42. package/dist/components/styled/SendInput.d.ts +12 -2
  43. package/dist/components/styled/StyledComponents.d.ts +69 -2
  44. package/dist/components/styled/StyledInputComponents/MediaComponents.d.ts +36 -24
  45. package/dist/components/styled/UnsupportedType.d.ts +1 -0
  46. package/dist/components/styled/VideoMessage.d.ts +11 -6
  47. package/dist/e2ee/callKey.d.ts +32 -0
  48. package/dist/e2ee/fileEnvelope.d.ts +16 -5
  49. package/dist/e2ee/omemo.d.ts +18 -0
  50. package/dist/firebase-messaging-sw.js +20 -3
  51. package/dist/{handleCopyClick-B70vLjJD.js → handleCopyClick-DGaZhy_u.js} +1 -1
  52. package/dist/helpers/albumLayout.d.ts +53 -0
  53. package/dist/helpers/attachments.d.ts +22 -1
  54. package/dist/helpers/avatarImageCache.d.ts +9 -0
  55. package/dist/helpers/caption.d.ts +63 -0
  56. package/dist/helpers/checkUniqueUsers.d.ts +2 -2
  57. package/dist/helpers/composerFocus.d.ts +22 -0
  58. package/dist/helpers/createMainMessageForThread.d.ts +1 -1
  59. package/dist/helpers/dedupeMembers.d.ts +10 -0
  60. package/dist/helpers/downloadFile.d.ts +19 -0
  61. package/dist/helpers/fileKind.d.ts +17 -0
  62. package/dist/helpers/historyPreloadConfig.d.ts +25 -0
  63. package/dist/helpers/historyPreloadScheduler.d.ts +3 -0
  64. package/dist/helpers/insertMessageWithDelimiter.d.ts +1 -0
  65. package/dist/helpers/isMessageSearchEnabled.d.ts +9 -0
  66. package/dist/helpers/jumpThread.d.ts +56 -0
  67. package/dist/helpers/jumpWindow.d.ts +73 -0
  68. package/dist/helpers/lastMessagePreview.d.ts +55 -0
  69. package/dist/helpers/mapWithConcurrency.d.ts +8 -0
  70. package/dist/helpers/mediaBox.d.ts +110 -0
  71. package/dist/helpers/mediaBubble.d.ts +39 -0
  72. package/dist/helpers/mediaLabel.d.ts +10 -0
  73. package/dist/helpers/mediaSendRetry.d.ts +25 -0
  74. package/dist/helpers/messageRuns.d.ts +10 -0
  75. package/dist/helpers/openThreadForJump.d.ts +26 -0
  76. package/dist/helpers/pdf/loadPdfjs.d.ts +8 -1
  77. package/dist/helpers/repairFilenameEncoding.d.ts +11 -0
  78. package/dist/helpers/roomImageGallery.d.ts +34 -0
  79. package/dist/helpers/roomUserCount.d.ts +19 -0
  80. package/dist/helpers/safeUrl.d.ts +15 -0
  81. package/dist/helpers/secureFileUrl.d.ts +4 -1
  82. package/dist/helpers/userResolver.d.ts +57 -0
  83. package/dist/helpers/viewerSender.d.ts +47 -0
  84. package/dist/helpers/xmppIdShape.d.ts +1 -1
  85. package/dist/hooks/useAvatarImage.d.ts +21 -0
  86. package/dist/hooks/useChatWrapperInit.d.ts +6 -0
  87. package/dist/hooks/useIsMobileViewport.d.ts +5 -0
  88. package/dist/hooks/useMediaProbe.d.ts +40 -0
  89. package/dist/hooks/usePaneWidthVar.d.ts +11 -0
  90. package/dist/hooks/usePdfThumbnail.d.ts +2 -2
  91. package/dist/hooks/usePrefersReducedMotion.d.ts +2 -0
  92. package/dist/hooks/useRoomDirectory.d.ts +11 -0
  93. package/dist/hooks/useSendMessage.d.ts +4 -1
  94. package/dist/{main-rJpE4hh-.js → main-CUB_w8AZ.js} +29136 -24217
  95. package/dist/main.css +1 -1
  96. package/dist/main.js +16 -16
  97. package/dist/networking/api-requests/auth.api.d.ts +2 -0
  98. package/dist/networking/api-requests/roomMembers.api.d.ts +18 -0
  99. package/dist/networking/callKeyStanza.d.ts +7 -0
  100. package/dist/networking/ethoraEvents.d.ts +44 -0
  101. package/dist/networking/stanzaHandlers.d.ts +6 -4
  102. package/dist/networking/xmpp/allRoomPresences.xmpp.d.ts +18 -1
  103. package/dist/networking/xmpp/presenceInRoom.xmpp.d.ts +1 -1
  104. package/dist/networking/xmpp/sendDisplayedMarker.xmpp.d.ts +2 -0
  105. package/dist/networking/xmpp/sendMediaMessage.xmpp.d.ts +8 -0
  106. package/dist/networking/xmpp/sendReceivedReceipt.xmpp.d.ts +2 -0
  107. package/dist/networking/xmppClient.d.ts +61 -2
  108. package/dist/roomStore/Middleware/jumpThreadMiddleware.d.ts +2 -0
  109. package/dist/roomStore/callSlice.d.ts +6 -1
  110. package/dist/roomStore/index.d.ts +22 -0
  111. package/dist/roomStore/roomsSlice.d.ts +51 -4
  112. package/dist/roomStore/safeKey.d.ts +12 -0
  113. package/dist/roomStore/usersSetCap.d.ts +15 -0
  114. package/dist/styles/motion.d.ts +22 -2
  115. package/dist/types/models/attachment.model.d.ts +19 -0
  116. package/dist/types/models/config.model.d.ts +98 -5
  117. package/dist/types/models/customComponents.model.d.ts +2 -0
  118. package/dist/types/models/message.model.d.ts +9 -0
  119. package/dist/types/models/modal.model.d.ts +19 -0
  120. package/dist/types/models/room.model.d.ts +30 -0
  121. package/dist/types/models/xmpp.model.d.ts +24 -1
  122. package/dist/utils/messageNotificationContent.d.ts +34 -0
  123. package/dist/version.d.ts +1 -1
  124. package/package.json +2 -1
  125. package/public/firebase-messaging-sw.js +20 -3
  126. package/dist/FilePreviewModal-BcaSoO3-.js +0 -743
  127. package/dist/components/MainComponents/computeAnchoredScrollTop.d.ts +0 -9
  128. package/dist/components/Modals/NewChatModal/UpdNewChatModal.d.ts +0 -3
  129. package/dist/components/RoomComponents/styled/LastAudioMessage.d.ts +0 -6
  130. package/dist/components/RoomComponents/styled/LastMessageFile.d.ts +0 -6
  131. package/dist/components/RoomComponents/styled/LastMessagePhoto.d.ts +0 -6
  132. package/dist/components/RoomComponents/styled/LastMessageVideo.d.ts +0 -6
  133. package/dist/components/SortDropDown/index.d.ts +0 -8
@@ -1,743 +0,0 @@
1
- import { jsx as l, jsxs as H } from "react/jsx-runtime";
2
- import te, { useState as N, useRef as z, useEffect as O, useMemo as $, useCallback as P } from "react";
3
- import { p as le, b as pe, aS as we, ae as ve, x as X, B as V, aT as xe, aU as be, ay as ye, aV as Ee, aW as Le, aX as ue, aY as ne, a as Ce, aO as Me, u as Q, a5 as Re, aZ as re, as as ke, ao as J, a_ as Pe, a$ as Se, b0 as Te, b1 as Ae, b2 as Ie, b3 as Xe, b4 as Ye, b5 as ze, b6 as Oe, az as De, b7 as Fe, b8 as Be, ax as He, b9 as Ne, w as Ue } from "./main-rJpE4hh-.js";
4
- function oe(t, i) {
5
- let o;
6
- return (...E) => {
7
- window.clearTimeout(o), o = window.setTimeout(() => t(...E), i);
8
- };
9
- }
10
- function _e({ debounce: t, scroll: i, polyfill: o, offsetSize: E } = { debounce: 0, scroll: !1, offsetSize: !1 }) {
11
- const L = o || (typeof window > "u" ? class {
12
- } : window.ResizeObserver);
13
- if (!L) throw new Error("This browser does not support ResizeObserver out of the box. See: https://github.com/react-spring/react-use-measure/#resize-observer-polyfills");
14
- const [u, C] = N({ left: 0, top: 0, width: 0, height: 0, bottom: 0, right: 0, x: 0, y: 0 }), n = z({ element: null, scrollContainers: null, resizeObserver: null, lastBounds: u, orientationHandler: null }), M = t ? typeof t == "number" ? t : t.scroll : null, p = t ? typeof t == "number" ? t : t.resize : null, T = z(!1);
15
- O(() => (T.current = !0, () => {
16
- T.current = !1;
17
- }));
18
- const [b, x, m] = $(() => {
19
- const r = () => {
20
- if (!n.current.element) return;
21
- const { left: g, top: w, width: v, height: B, bottom: S, right: R, x: f, y: h } = n.current.element.getBoundingClientRect(), A = { left: g, top: w, width: v, height: B, bottom: S, right: R, x: f, y: h };
22
- n.current.element instanceof HTMLElement && E && (A.height = n.current.element.offsetHeight, A.width = n.current.element.offsetWidth), Object.freeze(A), T.current && !We(n.current.lastBounds, A) && C(n.current.lastBounds = A);
23
- };
24
- return [r, p ? oe(r, p) : r, M ? oe(r, M) : r];
25
- }, [C, E, M, p]);
26
- function y() {
27
- n.current.scrollContainers && (n.current.scrollContainers.forEach((r) => r.removeEventListener("scroll", m, !0)), n.current.scrollContainers = null), n.current.resizeObserver && (n.current.resizeObserver.disconnect(), n.current.resizeObserver = null), n.current.orientationHandler && ("orientation" in screen && "removeEventListener" in screen.orientation ? screen.orientation.removeEventListener("change", n.current.orientationHandler) : "onorientationchange" in window && window.removeEventListener("orientationchange", n.current.orientationHandler));
28
- }
29
- function Y() {
30
- n.current.element && (n.current.resizeObserver = new L(m), n.current.resizeObserver.observe(n.current.element), i && n.current.scrollContainers && n.current.scrollContainers.forEach((r) => r.addEventListener("scroll", m, { capture: !0, passive: !0 })), n.current.orientationHandler = () => {
31
- m();
32
- }, "orientation" in screen && "addEventListener" in screen.orientation ? screen.orientation.addEventListener("change", n.current.orientationHandler) : "onorientationchange" in window && window.addEventListener("orientationchange", n.current.orientationHandler));
33
- }
34
- const F = (r) => {
35
- !r || r === n.current.element || (y(), n.current.element = r, n.current.scrollContainers = de(r), Y());
36
- };
37
- return $e(m, !!i), je(x), O(() => {
38
- y(), Y();
39
- }, [i, m, x]), O(() => y, []), [F, u, b];
40
- }
41
- function je(t) {
42
- O(() => {
43
- const i = t;
44
- return window.addEventListener("resize", i), () => {
45
- window.removeEventListener("resize", i);
46
- };
47
- }, [t]);
48
- }
49
- function $e(t, i) {
50
- O(() => {
51
- if (i) {
52
- const o = t;
53
- return window.addEventListener("scroll", o, { capture: !0, passive: !0 }), () => {
54
- window.removeEventListener("scroll", o, !0);
55
- };
56
- }
57
- }, [t, i]);
58
- }
59
- function de(t) {
60
- const i = [];
61
- if (!t || t === document.body) return i;
62
- const { overflow: o, overflowX: E, overflowY: L } = window.getComputedStyle(t);
63
- return [o, E, L].some((u) => u === "auto" || u === "scroll") && i.push(t), [...i, ...de(t.parentElement)];
64
- }
65
- const Ve = ["x", "y", "top", "bottom", "left", "right", "width", "height"], We = (t, i) => Ve.every((o) => t[o] === i[o]), ie = X.div`
66
- display: flex;
67
- flex-direction: column;
68
- align-items: center;
69
- gap: 12px;
70
- width: 100%;
71
- height: 100%;
72
- overflow: auto;
73
- `, Ze = X.div`
74
- display: flex;
75
- align-items: flex-start;
76
- justify-content: center;
77
- width: 100%;
78
- flex: 1 1 auto;
79
- min-height: 0;
80
-
81
- canvas {
82
- max-width: 100%;
83
- height: auto;
84
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
85
- background-color: #fff;
86
- }
87
- `, Ke = X.div`
88
- display: flex;
89
- align-items: center;
90
- gap: 12px;
91
- flex: 0 0 auto;
92
- font-size: 14px;
93
- color: var(--ethora-color-text, #141414);
94
- `, ae = X(V)`
95
- width: auto;
96
- min-width: 40px;
97
- padding: 0 12px;
98
- `, Ge = X.div`
99
- display: flex;
100
- flex-direction: column;
101
- align-items: center;
102
- gap: 12px;
103
- padding: 16px;
104
- border-radius: var(--ethora-radius-lg, 16px);
105
- background-color: var(--ethora-color-bg-subtle, #f5f7fa);
106
- color: var(--ethora-color-text, #141414);
107
- text-align: center;
108
-
109
- a {
110
- color: var(--ethora-color-primary-text, var(--ethora-color-primary, #0052cd));
111
- }
112
- `, qe = ({ pdfUrl: t }) => {
113
- const i = le(), { config: o } = pe(), [E, L] = _e(), u = z(null), C = z(null), n = z(null), [M, p] = N("loading"), [T, b] = N(0), [x, m] = N(1), y = Math.max(320, Math.floor(L.width || 0));
114
- O(() => {
115
- let r = !1, g;
116
- return p("loading"), m(1), b(0), (async () => {
117
- const w = await we(o?.pdfPreview?.workerSrc);
118
- if (!r) {
119
- if (!w || !t) {
120
- p("error");
121
- return;
122
- }
123
- try {
124
- g = w.getDocument({ url: t, isEvalSupported: !1 });
125
- const v = await g.promise;
126
- if (r) {
127
- v.destroy().catch(() => {
128
- });
129
- return;
130
- }
131
- C.current = v, b(v.numPages), p("ready");
132
- } catch (v) {
133
- r || (console.warn("[Ethora] PDF open failed:", v), p("error"));
134
- }
135
- }
136
- })(), () => {
137
- r = !0, n.current?.cancel(), n.current = null, C.current?.destroy?.().catch(() => {
138
- }), C.current = null, g?.destroy?.().catch(() => {
139
- });
140
- };
141
- }, [t, o?.pdfPreview?.workerSrc]), O(() => {
142
- const r = C.current, g = u.current;
143
- if (M !== "ready" || !r || !g || y <= 0) return;
144
- let w = !1;
145
- return (async () => {
146
- try {
147
- const v = await r.getPage(x);
148
- if (w) return;
149
- const B = v.getViewport({ scale: 1 }), S = B.width ? y / B.width : 1, R = v.getViewport({ scale: S });
150
- g.width = Math.max(1, Math.floor(R.width)), g.height = Math.max(1, Math.floor(R.height));
151
- const f = g.getContext("2d");
152
- if (!f) {
153
- p("error");
154
- return;
155
- }
156
- n.current?.cancel();
157
- const h = v.render({ canvasContext: f, viewport: R });
158
- n.current = h, await h.promise, v.cleanup();
159
- } catch (v) {
160
- w || console.warn("[Ethora] PDF page render failed:", v);
161
- }
162
- })(), () => {
163
- w = !0, n.current?.cancel(), n.current = null;
164
- };
165
- }, [M, x, y]);
166
- const Y = P(
167
- () => m((r) => Math.max(1, r - 1)),
168
- []
169
- ), F = P(
170
- () => m((r) => Math.min(T || 1, r + 1)),
171
- [T]
172
- );
173
- return M === "error" ? /* @__PURE__ */ l(ie, { children: /* @__PURE__ */ H(Ge, { children: [
174
- /* @__PURE__ */ l("span", { children: i("modal.filePreview.pdfUnavailable") }),
175
- /* @__PURE__ */ l("a", { href: t, target: "_blank", rel: "noopener noreferrer", children: i("modal.filePreview.openExternally") })
176
- ] }) }) : /* @__PURE__ */ H(ie, { children: [
177
- /* @__PURE__ */ l(Ze, { ref: E, children: M === "loading" ? /* @__PURE__ */ l(ve, { color: o?.colors?.primary }) : /* @__PURE__ */ l("canvas", { ref: u }) }),
178
- T > 1 && /* @__PURE__ */ H(Ke, { children: [
179
- /* @__PURE__ */ l(
180
- ae,
181
- {
182
- onClick: Y,
183
- disabled: x <= 1,
184
- text: "‹",
185
- "aria-label": i("modal.filePreview.previousPage")
186
- }
187
- ),
188
- /* @__PURE__ */ H("span", { children: [
189
- x,
190
- " / ",
191
- T
192
- ] }),
193
- /* @__PURE__ */ l(
194
- ae,
195
- {
196
- onClick: F,
197
- disabled: x >= T,
198
- text: "›",
199
- "aria-label": i("modal.filePreview.nextPage")
200
- }
201
- )
202
- ] })
203
- ] });
204
- }, I = 1, ee = 6, Qe = 2.5, Je = 50, et = 300, se = 24, tt = 16e-4, G = (t, i, o) => Math.min(o, Math.max(i, t)), nt = X.div`
205
- position: relative;
206
- /* An explicit height, not flex growth alone: the parent lays its children
207
- out in a row and centres them, so the viewport would otherwise be sized
208
- by its content, and the image's own max-height of 100% would resolve
209
- against that auto height and never fit anything. */
210
- flex: 1 1 auto;
211
- width: 100%;
212
- height: 100%;
213
- min-height: 0;
214
- display: flex;
215
- align-items: center;
216
- justify-content: center;
217
- overflow: hidden;
218
- /* A zoomed image is dragged, not selected, and a two-finger gesture is a
219
- pinch rather than a page scroll. */
220
- touch-action: none;
221
- user-select: none;
222
- background-color: var(--ethora-color-bg, #fff);
223
- `, rt = X.img`
224
- /* Same box the single-file view always used: fill the stage and let
225
- object-fit do the letterboxing, so what the viewer sees at scale 1 is
226
- unchanged. It is also what makes the pan clamp exact, since the painted
227
- content box is then derived from the natural aspect ratio alone. */
228
- width: 100%;
229
- height: 100%;
230
- object-fit: contain;
231
- transform-origin: center center;
232
- will-change: transform;
233
- cursor: ${({ $grabbing: t, $pannable: i }) => t ? "grabbing" : i ? "grab" : "zoom-in"};
234
- transition: ${({ $animate: t }) => t ? `transform ${xe} ${be}` : "none"};
235
- ${ye}
236
- `, fe = te.forwardRef(
237
- ({ src: t, alt: i, onSwipeLeft: o, onSwipeRight: E, onError: L, onScaleChange: u }, C) => {
238
- const n = z(null), M = z(null), [p, T] = N(I), [b, x] = N({ x: 0, y: 0 }), [m, y] = N(!1), [Y, F] = N(!1), r = z({ scale: I, offset: { x: 0, y: 0 } });
239
- r.current = { scale: p, offset: b };
240
- const g = z(null), w = z(null), v = z(
241
- null
242
- ), B = P((a) => {
243
- const e = n.current, c = M.current;
244
- if (!e) return { x: 0, y: 0 };
245
- const s = e.clientWidth, d = e.clientHeight, k = c?.naturalWidth || 0, D = c?.naturalHeight || 0;
246
- let j = s, Z = d;
247
- if (k > 0 && D > 0 && s > 0 && d > 0) {
248
- const K = Math.min(s / k, d / D);
249
- j = k * K, Z = D * K;
250
- }
251
- return {
252
- x: Math.max(0, (j * a - s) / 2),
253
- y: Math.max(0, (Z * a - d) / 2)
254
- };
255
- }, []), S = P(
256
- (a, e, c) => {
257
- const s = G(a, I, ee), d = B(s);
258
- y(c), T(s), x({
259
- x: G(e.x, -d.x, d.x),
260
- y: G(e.y, -d.y, d.y)
261
- });
262
- },
263
- [B]
264
- ), R = P(
265
- (a, e, c, s) => {
266
- const d = r.current, k = G(a, I, ee), D = k / d.scale;
267
- S(
268
- k,
269
- {
270
- x: e - (e - d.offset.x) * D,
271
- y: c - (c - d.offset.y) * D
272
- },
273
- s
274
- );
275
- },
276
- [S]
277
- ), f = P(() => {
278
- S(I, { x: 0, y: 0 }, !0);
279
- }, [S]), h = P(
280
- (a) => {
281
- R(r.current.scale * a, 0, 0, !0);
282
- },
283
- [R]
284
- );
285
- te.useImperativeHandle(
286
- C,
287
- () => ({
288
- zoomIn: () => h(1.5),
289
- zoomOut: () => h(1 / 1.5),
290
- reset: f
291
- }),
292
- [h, f]
293
- ), O(() => {
294
- y(!1), T(I), x({ x: 0, y: 0 });
295
- }, [t]), O(() => {
296
- u?.(p);
297
- }, [p, u]), O(() => {
298
- const a = n.current;
299
- if (!a) return;
300
- const e = (c) => {
301
- c.preventDefault();
302
- const s = a.getBoundingClientRect(), d = c.clientX - s.left - s.width / 2, k = c.clientY - s.top - s.height / 2, D = Math.exp(-c.deltaY * tt);
303
- R(r.current.scale * D, d, k, !1);
304
- };
305
- return a.addEventListener("wheel", e, { passive: !1 }), () => a.removeEventListener("wheel", e);
306
- }, [R]);
307
- const A = P(
308
- (a, e) => {
309
- const c = n.current;
310
- if (!c) return;
311
- if (r.current.scale > I) {
312
- f();
313
- return;
314
- }
315
- const s = c.getBoundingClientRect();
316
- R(
317
- Qe,
318
- a - s.left - s.width / 2,
319
- e - s.top - s.height / 2,
320
- !0
321
- );
322
- },
323
- [f, R]
324
- ), _ = P((a) => {
325
- a.button === 0 && (r.current.scale <= I || (a.preventDefault(), g.current = { x: a.clientX, y: a.clientY }, F(!0)));
326
- }, []);
327
- O(() => {
328
- if (!Y || typeof window > "u") return;
329
- const a = (c) => {
330
- const s = g.current;
331
- if (!s) return;
332
- const d = r.current;
333
- S(
334
- d.scale,
335
- {
336
- x: d.offset.x + (c.clientX - s.x),
337
- y: d.offset.y + (c.clientY - s.y)
338
- },
339
- !1
340
- ), g.current = { x: c.clientX, y: c.clientY };
341
- }, e = () => {
342
- g.current = null, F(!1);
343
- };
344
- return window.addEventListener("mousemove", a), window.addEventListener("mouseup", e), () => {
345
- window.removeEventListener("mousemove", a), window.removeEventListener("mouseup", e);
346
- };
347
- }, [Y, S]);
348
- const q = P((a) => {
349
- if (a.touches.length === 2) {
350
- const [c, s] = [a.touches[0], a.touches[1]];
351
- w.current = {
352
- startX: 0,
353
- startY: 0,
354
- lastX: 0,
355
- lastY: 0,
356
- pinchDistance: Math.hypot(
357
- c.clientX - s.clientX,
358
- c.clientY - s.clientY
359
- ),
360
- pinchScale: r.current.scale,
361
- panning: !1,
362
- moved: !1
363
- };
364
- return;
365
- }
366
- const e = a.touches[0];
367
- e && (w.current = {
368
- startX: e.clientX,
369
- startY: e.clientY,
370
- lastX: e.clientX,
371
- lastY: e.clientY,
372
- pinchDistance: 0,
373
- pinchScale: r.current.scale,
374
- panning: r.current.scale > I,
375
- moved: !1
376
- });
377
- }, []), W = P(
378
- (a) => {
379
- const e = w.current;
380
- if (!e) return;
381
- if (a.touches.length === 2 && e.pinchDistance > 0) {
382
- const [s, d] = [a.touches[0], a.touches[1]], k = Math.hypot(
383
- s.clientX - d.clientX,
384
- s.clientY - d.clientY
385
- ), D = n.current;
386
- if (!D || k <= 0) return;
387
- const j = D.getBoundingClientRect(), Z = (s.clientX + d.clientX) / 2 - j.left - j.width / 2, K = (s.clientY + d.clientY) / 2 - j.top - j.height / 2;
388
- e.moved = !0, R(
389
- e.pinchScale * k / e.pinchDistance,
390
- Z,
391
- K,
392
- !1
393
- );
394
- return;
395
- }
396
- const c = a.touches[0];
397
- if (c) {
398
- if ((Math.abs(c.clientX - e.startX) > 6 || Math.abs(c.clientY - e.startY) > 6) && (e.moved = !0), e.panning) {
399
- const s = r.current;
400
- S(
401
- s.scale,
402
- {
403
- x: s.offset.x + (c.clientX - e.lastX),
404
- y: s.offset.y + (c.clientY - e.lastY)
405
- },
406
- !1
407
- );
408
- }
409
- e.lastX = c.clientX, e.lastY = c.clientY;
410
- }
411
- },
412
- [S, R]
413
- ), U = P(
414
- (a) => {
415
- const e = w.current;
416
- if (!e || a.touches.length > 0) return;
417
- if (w.current = null, !e.moved && e.pinchDistance === 0) {
418
- const d = Date.now(), k = v.current;
419
- if (k && d - k.time < et && Math.abs(k.x - e.startX) < se && Math.abs(k.y - e.startY) < se) {
420
- v.current = null, A(e.startX, e.startY);
421
- return;
422
- }
423
- v.current = {
424
- time: d,
425
- x: e.startX,
426
- y: e.startY
427
- };
428
- return;
429
- }
430
- if (e.panning || e.pinchDistance > 0 || r.current.scale > I) return;
431
- const c = e.lastX - e.startX, s = e.lastY - e.startY;
432
- Math.abs(c) < Je || Math.abs(c) <= Math.abs(s) || (c < 0 ? o?.() : E?.());
433
- },
434
- [o, E, A]
435
- ), me = P(
436
- (a) => {
437
- A(a.clientX, a.clientY);
438
- },
439
- [A]
440
- ), ge = $(
441
- () => `translate(${b.x}px, ${b.y}px) scale(${p})`,
442
- [b.x, b.y, p]
443
- );
444
- return /* @__PURE__ */ l(
445
- nt,
446
- {
447
- ref: n,
448
- "data-testid": "image-lightbox-viewport",
449
- onMouseDown: _,
450
- onDoubleClick: me,
451
- onTouchStart: q,
452
- onTouchMove: W,
453
- onTouchEnd: U,
454
- onTouchCancel: U,
455
- children: /* @__PURE__ */ l(
456
- rt,
457
- {
458
- ref: M,
459
- "data-testid": "image-lightbox-image",
460
- src: t,
461
- alt: i,
462
- draggable: !1,
463
- onError: L,
464
- $grabbing: Y,
465
- $pannable: p > I,
466
- $animate: m,
467
- style: { transform: ge }
468
- }
469
- )
470
- }
471
- );
472
- }
473
- );
474
- fe.displayName = "ImageLightbox";
475
- const ot = (t) => {
476
- if (!Array.isArray(t)) return [];
477
- const i = [];
478
- return t.forEach((o, E) => {
479
- !o || o.isDeleted || o.id !== "delimiter-new" && Ee(o).forEach((L, u) => {
480
- if (!L.location) return;
481
- const C = Le(L);
482
- ue(L.mimetype, C) === "image" && i.push({
483
- key: `${o.id ?? E}:${u}`,
484
- fileName: C,
485
- fileURL: L.location,
486
- mimetype: L.mimetype || ""
487
- });
488
- });
489
- }), i;
490
- }, it = (t, i) => {
491
- if (!i?.fileURL) return -1;
492
- const o = ne(i.fileURL);
493
- return t.findIndex(
494
- (E) => ne(E.fileURL) === o
495
- );
496
- }, ce = "https://as2.ftcdn.net/v2/jpg/02/51/95/53/1000_F_251955356_FAQH0U1y1TZw3ZcdPGybwUkH90a3VAhb.jpg", at = X.div`
497
- position: relative;
498
- display: flex;
499
- flex: 1 1 auto;
500
- width: 100%;
501
- min-height: 0;
502
- align-items: center;
503
- justify-content: center;
504
- overflow: hidden;
505
- `, he = X(V)`
506
- position: absolute;
507
- top: 50%;
508
- transform: translateY(-50%);
509
- width: 44px;
510
- height: 44px;
511
- border-radius: var(--ethora-radius-full, 999px);
512
- background-color: var(--ethora-color-bg, #fff);
513
- box-shadow: var(--ethora-shadow-md, 0 4px 12px rgba(16, 24, 40, 0.1));
514
- z-index: 2;
515
- `, st = X(he)`
516
- left: 8px;
517
- `, ct = X(he)`
518
- right: 8px;
519
- `, lt = X.div`
520
- display: flex;
521
- align-items: center;
522
- gap: 8px;
523
- `, ut = X.div`
524
- display: flex;
525
- align-items: center;
526
- gap: 8px;
527
-
528
- @media (max-width: 480px) {
529
- display: none;
530
- }
531
- `, dt = X.span`
532
- font-size: var(--ethora-font-size-sm, 14px);
533
- color: var(--ethora-color-text-secondary, #5a5f66);
534
- white-space: nowrap;
535
- padding: 0 4px;
536
- `, gt = ({
537
- handleCloseModal: t
538
- }) => {
539
- const i = Ce(), o = le(), E = Me(), { activeFile: L } = Q(
540
- (f) => f.chatSettingStore
541
- ), u = $(
542
- () => L ?? { fileName: "", fileURL: "", mimetype: "" },
543
- [L]
544
- ), C = Q(
545
- (f) => f.chatSettingStore.user?.fileToken || ""
546
- ), n = Q(
547
- (f) => Re(f)?.messages
548
- ), M = z(null), [p, T] = N(I), b = ue(u?.mimetype, u?.fileName), x = $(() => ot(n), [n]), m = $(
549
- () => b === "image" ? it(x, u) : -1,
550
- [x, u, b]
551
- ), y = m >= 0 && x.length > 1, Y = y && m > 0, F = y && m < x.length - 1, r = P(
552
- (f) => {
553
- const h = x[f];
554
- h && i(
555
- re({
556
- fileName: h.fileName,
557
- fileURL: h.fileURL,
558
- mimetype: h.mimetype
559
- })
560
- );
561
- },
562
- [i, x]
563
- ), g = P(() => {
564
- Y && r(m - 1);
565
- }, [r, Y, m]), w = P(() => {
566
- F && r(m + 1);
567
- }, [r, F, m]);
568
- O(() => {
569
- if (!y || typeof document > "u") return;
570
- const f = (h) => {
571
- if (h.key !== "ArrowLeft" && h.key !== "ArrowRight" || h.defaultPrevented || h.altKey || h.ctrlKey || h.metaKey) return;
572
- const A = h.target, _ = A?.tagName;
573
- _ === "INPUT" || _ === "TEXTAREA" || _ === "SELECT" || A?.isContentEditable || (h.preventDefault(), h.key === "ArrowLeft" ? g() : w());
574
- };
575
- return document.addEventListener("keydown", f), () => document.removeEventListener("keydown", f);
576
- }, [y, g, w]);
577
- const v = () => {
578
- fetch(He(u.fileURL), {
579
- method: "GET",
580
- headers: {}
581
- }).then((f) => {
582
- const _ = !!Ne(u.fileName) ? u.fileName : `MEDIA-ETHORA.${b === "image" ? "png" : b === "video" ? "mp4" : "bin"}`;
583
- f.arrayBuffer().then(function(q) {
584
- if (typeof window > "u")
585
- return;
586
- const W = window.URL.createObjectURL(new Blob([q])), U = document.createElement("a");
587
- U.href = W, U.setAttribute("download", _), document.body.appendChild(U), U.click(), U.remove(), window.URL.revokeObjectURL(W);
588
- });
589
- }).catch((f) => {
590
- Ue.log(f);
591
- });
592
- }, B = () => {
593
- i(re(void 0)), t?.();
594
- }, S = u?.fileName || o("modal.filePreview.imageAlt"), R = $(() => {
595
- switch (b) {
596
- case "image":
597
- return /* @__PURE__ */ l(
598
- fe,
599
- {
600
- ref: M,
601
- src: J(u.fileURL, C) || ce,
602
- alt: S,
603
- onScaleChange: T,
604
- onSwipeLeft: w,
605
- onSwipeRight: g,
606
- onError: (f) => {
607
- Se(u.fileURL) && Te(), f.target.src = ce;
608
- }
609
- }
610
- );
611
- case "video":
612
- return /* @__PURE__ */ l(
613
- Pe,
614
- {
615
- src: J(u.fileURL, C),
616
- controls: !0,
617
- autoPlay: !1
618
- }
619
- );
620
- case "pdf":
621
- return /* @__PURE__ */ l(qe, { pdfUrl: J(u.fileURL, C) });
622
- default:
623
- return /* @__PURE__ */ H(
624
- "div",
625
- {
626
- style: {
627
- display: "flex",
628
- flexDirection: "column",
629
- justifyContent: "center",
630
- alignItems: "center"
631
- },
632
- children: [
633
- /* @__PURE__ */ l(ke, { style: { minWidth: "100px", minHeight: "100px" } }),
634
- /* @__PURE__ */ l(
635
- "div",
636
- {
637
- style: {
638
- backgroundColor: "var(--ethora-color-bg-subtle, #F5F7FA)",
639
- borderRadius: "var(--ethora-radius-lg, 16px)",
640
- display: "flex",
641
- padding: "16px",
642
- color: "var(--ethora-color-text, #141414)"
643
- },
644
- children: o("modal.filePreview.unsupported")
645
- }
646
- )
647
- ]
648
- }
649
- );
650
- }
651
- }, [u, C, S, b, w, g, o]);
652
- return /* @__PURE__ */ H(
653
- Ae,
654
- {
655
- "aria-label": o("modal.filePreview.title"),
656
- $closing: E,
657
- children: [
658
- /* @__PURE__ */ l(
659
- Ie,
660
- {
661
- handleCloseModal: B,
662
- headerTitle: o("modal.filePreview.title"),
663
- rightMenu: /* @__PURE__ */ H(lt, { children: [
664
- y && /* @__PURE__ */ l(dt, { "data-testid": "lightbox-position", "aria-live": "polite", children: o("modal.filePreview.position", {
665
- current: m + 1,
666
- total: x.length
667
- }) }),
668
- b === "image" && /* @__PURE__ */ H(ut, { children: [
669
- /* @__PURE__ */ l(
670
- V,
671
- {
672
- onClick: () => M.current?.zoomOut(),
673
- disabled: p <= I,
674
- "aria-label": o("modal.filePreview.zoomOut"),
675
- children: /* @__PURE__ */ l(Xe, {})
676
- }
677
- ),
678
- /* @__PURE__ */ l(
679
- V,
680
- {
681
- onClick: () => M.current?.zoomIn(),
682
- disabled: p >= ee,
683
- "aria-label": o("modal.filePreview.zoomIn"),
684
- children: /* @__PURE__ */ l(Ye, {})
685
- }
686
- ),
687
- /* @__PURE__ */ l(
688
- V,
689
- {
690
- onClick: () => M.current?.reset(),
691
- disabled: p <= I,
692
- "aria-label": o("modal.filePreview.resetZoom"),
693
- children: /* @__PURE__ */ l(ze, {})
694
- }
695
- )
696
- ] }),
697
- /* @__PURE__ */ l(V, { onClick: v, "aria-label": o("action.save"), children: /* @__PURE__ */ l(Oe, {}) })
698
- ] })
699
- }
700
- ),
701
- /* @__PURE__ */ l(
702
- De,
703
- {
704
- style: {
705
- display: "flex",
706
- flex: "1 1 auto",
707
- height: "100%",
708
- minHeight: 0,
709
- justifyContent: "center",
710
- overflow: "hidden",
711
- padding: "16px",
712
- width: "90%"
713
- },
714
- children: /* @__PURE__ */ H(at, { children: [
715
- y && /* @__PURE__ */ l(
716
- st,
717
- {
718
- onClick: g,
719
- disabled: !Y,
720
- "aria-label": o("modal.filePreview.previousImage"),
721
- children: /* @__PURE__ */ l(Fe, {})
722
- }
723
- ),
724
- R,
725
- y && /* @__PURE__ */ l(
726
- ct,
727
- {
728
- onClick: w,
729
- disabled: !F,
730
- "aria-label": o("modal.filePreview.nextImage"),
731
- children: /* @__PURE__ */ l(Be, {})
732
- }
733
- )
734
- ] })
735
- }
736
- )
737
- ]
738
- }
739
- );
740
- };
741
- export {
742
- gt as default
743
- };