@paramms/chat-widget 1.0.47 โ†’ 1.5.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var Be = Object.defineProperty;
2
2
  var $e = (t, e, l) => e in t ? Be(t, e, { enumerable: !0, configurable: !0, writable: !0, value: l }) : t[e] = l;
3
3
  var T = (t, e, l) => $e(t, typeof e != "symbol" ? e + "" : e, l);
4
- import { l as Me, b as ge, p as Re, r as Ae, a as qe } from "./codec.js";
4
+ import { l as Me, b as ge, p as Re, r as qe, a as Ae } from "./codec.js";
5
5
  import { h as st } from "./codec.js";
6
6
  import { P as Ne, C as Oe, b as De } from "./outbox.js";
7
7
  import { e as dt } from "./outbox.js";
@@ -67,7 +67,6 @@ const Ue = `
67
67
  .ocw-row { display:flex; align-items:flex-end; gap:8px; max-width:86%; }
68
68
  .ocw-row.mine { align-self:flex-end; flex-direction:row-reverse; }
69
69
  .ocw-row.theirs { align-self:flex-start; }
70
- .ocw-dot { width:26px; height:26px; border-radius:50%; background:var(--ocw-tint); color:var(--ocw-accent); font-size:12px; font-weight:700; display:flex; align-items:center; justify-content:center; flex:none; }
71
70
  .ocw-bubble { padding:10px 14px; border-radius:18px; font-size:13.5px; line-height:1.45; word-wrap:break-word; max-width:80%; }
72
71
  .theirs .ocw-bubble { background:var(--ocw-tint); border-bottom-left-radius:4px; }
73
72
  .mine .ocw-bubble { background:var(--ocw-accent2); color:#fff; border-bottom-right-radius:4px; }
@@ -196,7 +195,8 @@ const Ue = `
196
195
  .ocw-translate-btn { position:absolute; bottom:2px; right:-26px; background:var(--ocw-card); border:1px solid var(--ocw-line); border-radius:50%; width:22px; height:22px; font-size:11px; cursor:pointer; color:var(--ocw-mut); display:flex; align-items:center; justify-content:center; opacity:0; transition:opacity .15s; padding:0; }
197
196
  .ocw-row.theirs .ocw-translate-btn { right:auto; left:-26px; }
198
197
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
199
- .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
198
+ .ocw-translation { margin-top:6px; padding-top:6px; border-top:1px solid var(--ocw-line); font-size:13px; line-height:1.45; }
199
+ .ocw-translation::before { content:'๐ŸŒ '; opacity:.75; }
200
200
  `, ye = "objectchat-widget-styles", Fe = ["๐Ÿ‘", "โค๏ธ", "๐Ÿ˜‚", "๐Ÿ˜ฎ", "๐Ÿ˜ข", "๐Ÿ™"], We = 400, Ge = '<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
201
201
  function Ke() {
202
202
  if (typeof document > "u" || document.getElementById(ye)) return;
@@ -239,7 +239,7 @@ function ae(t) {
239
239
  }
240
240
  class Xe {
241
241
  /** Last seq the guest has seen per conversationId โ€” used to compute unread badges. */
242
- constructor(e, l, c, i = {}) {
242
+ constructor(e, l, c, a = {}) {
243
243
  T(this, "scroll");
244
244
  T(this, "chips");
245
245
  T(this, "typing");
@@ -274,64 +274,59 @@ class Xe {
274
274
  /** Whether the subject card (server Subject entity, mount config fallback)
275
275
  * has been built โ€” built once when data first arrives. */
276
276
  T(this, "subjectBuilt", !1);
277
- var r, C, v, u, f, R, B, A, k, S, D;
278
- this.root = e, this.me = l, this.h = c, this.cfg = i, Ke(), i.webfont !== !1 && Ve(), e.replaceChildren(), e.classList.add("ocw"), i.accent && e.style.setProperty("--ocw-accent", i.accent);
279
- const x = i.accent2 ?? i.accent;
280
- x && e.style.setProperty("--ocw-accent2", x), this.cfgAccent2 = i.accent2, e.dataset.theme = i.theme ?? "light";
277
+ var r, d, b, k, u, g, $, y, S, N, M;
278
+ this.root = e, this.me = l, this.h = c, this.cfg = a, Ke(), a.webfont !== !1 && Ve(), e.replaceChildren(), e.classList.add("ocw"), a.accent && e.style.setProperty("--ocw-accent", a.accent);
279
+ const f = a.accent2 ?? a.accent;
280
+ f && e.style.setProperty("--ocw-accent2", f), this.cfgAccent2 = a.accent2, e.dataset.theme = a.theme ?? "light";
281
281
  const w = n("div", "ocw-head");
282
282
  if (this.h.onBack) {
283
- const g = n("button", "ocw-back", "โ€น");
284
- g.type = "button", g.setAttribute("aria-label", "Back"), g.addEventListener("click", () => this.h.onBack()), w.append(g);
283
+ const v = n("button", "ocw-back", "โ€น");
284
+ v.type = "button", v.setAttribute("aria-label", "Back"), v.addEventListener("click", () => this.h.onBack()), w.append(v);
285
285
  }
286
- const y = n("div", "ocw-avatar");
287
- if ((r = i.userInfo) != null && r.avatar) {
288
- const g = document.createElement("img");
289
- g.src = i.userInfo.avatar, g.alt = i.userInfo.name ?? "You", g.style.cssText = "width:100%;height:100%;border-radius:50%;object-fit:cover", y.append(g);
290
- } else
291
- y.textContent = (C = i.userInfo) != null && C.name ? i.userInfo.name[0].toUpperCase() : "๐Ÿง‘";
292
- w.append(y);
293
- const p = n("div", "ocw-head-main");
294
- this.headerName = n("div", "ocw-head-name", ((v = i.subject) == null ? void 0 : v.ownerLabel) ?? ((u = i.subject) == null ? void 0 : u.title) ?? ""), p.append(this.headerName), this.headStatus = n("div", "ocw-head-status"), this.headStatus.style.display = "none", p.append(this.headStatus), (f = i.subject) != null && f.subtitle && p.append(n("div", "ocw-head-meta", i.subject.subtitle)), w.append(p), this.statusBadge = n("span", "ocw-badge", ((R = i.subject) == null ? void 0 : R.status) ?? ""), (B = i.subject) != null && B.status || (this.statusBadge.style.display = "none"), w.append(this.statusBadge), this.e2eBadge = n("span", "ocw-e2e", "๐Ÿ”’ E2E"), this.e2eBadge.style.display = "none", w.append(this.e2eBadge), this.connStatus = n("span", "ocw-conn-status"), this.connStatus.style.display = "none", w.append(this.connStatus), w.append(n("button", "ocw-menu", "โ‹ฏ")), this.chips = n("div", "ocw-chiprow"), this.scroll = n("div", "ocw-scroll"), this.subjectCard = n("div", "ocw-subject"), this.typing = n("div", "ocw-typing");
295
- const h = n("div", "ocw-typing-bubble");
296
- h.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(n("div", "ocw-dot", "๐Ÿง‘"), h), this.quick = n("div", "ocw-quick");
297
- for (const g of i.quickReplies ?? []) {
298
- const N = n("button", void 0, g);
299
- N.addEventListener("click", () => {
300
- this.h.onSend(g), this.quick.style.display = "none";
301
- }), this.quick.append(N);
286
+ const C = ((r = a.subject) == null ? void 0 : r.ownerLabel) ?? ((d = a.subject) == null ? void 0 : d.title) ?? "", p = n("div", "ocw-avatar");
287
+ C.trim() && (p.textContent = C.trim()[0].toUpperCase(), w.append(p));
288
+ const h = n("div", "ocw-head-main");
289
+ this.headerName = n("div", "ocw-head-name", ((b = a.subject) == null ? void 0 : b.ownerLabel) ?? ((k = a.subject) == null ? void 0 : k.title) ?? ""), h.append(this.headerName), this.headStatus = n("div", "ocw-head-status"), this.headStatus.style.display = "none", h.append(this.headStatus), (u = a.subject) != null && u.subtitle && h.append(n("div", "ocw-head-meta", a.subject.subtitle)), w.append(h), this.statusBadge = n("span", "ocw-badge", ((g = a.subject) == null ? void 0 : g.status) ?? ""), ($ = a.subject) != null && $.status || (this.statusBadge.style.display = "none"), w.append(this.statusBadge), this.e2eBadge = n("span", "ocw-e2e", "๐Ÿ”’ E2E"), this.e2eBadge.style.display = "none", w.append(this.e2eBadge), this.connStatus = n("span", "ocw-conn-status"), this.connStatus.style.display = "none", w.append(this.connStatus), w.append(n("button", "ocw-menu", "โ‹ฏ")), this.chips = n("div", "ocw-chiprow"), this.scroll = n("div", "ocw-scroll"), this.subjectCard = n("div", "ocw-subject"), this.typing = n("div", "ocw-typing");
290
+ const m = n("div", "ocw-typing-bubble");
291
+ m.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(m), this.quick = n("div", "ocw-quick");
292
+ for (const v of a.quickReplies ?? []) {
293
+ const D = n("button", void 0, v);
294
+ D.addEventListener("click", () => {
295
+ this.h.onSend(v), this.quick.style.display = "none";
296
+ }), this.quick.append(D);
302
297
  }
303
- this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((A = i.i18n) == null ? void 0 : A.placeholder) ?? "Messageโ€ฆ";
304
- const b = n("button", "ocw-sendbtn");
305
- b.type = "button";
306
- const a = (k = i.i18n) == null ? void 0 : k.send;
307
- a ? (b.textContent = a, b.classList.add("ocw-sendbtn-label"), b.setAttribute("aria-label", a)) : (b.innerHTML = Ge, b.setAttribute("aria-label", "Send message")), b.disabled = !0, this.sendBtn = b, b.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
308
- var g, N;
309
- this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((H) => H.senderRole === "guest") ? (N = (g = this.h).onDeflectQuery) == null || N.call(g, this.input.value) : this.hideDeflection();
310
- }), this.input.addEventListener("keydown", (g) => {
311
- g.isComposing || g.keyCode === 229 || (g.key === "Enter" && !g.shiftKey ? (g.preventDefault(), this.flushSend()) : this.signalTyping());
298
+ this.formHost = n("div", "ocw-form-host"), this.csatPanel = n("div", "ocw-csat"), this.csatPanel.style.display = "none", this.awayNotice = n("div", "ocw-away"), this.awayNotice.style.display = "none", this.preChatPanel = n("div", "ocw-prechat"), this.preChatPanel.style.display = "none", this.deflectPanel = n("div", "ocw-deflect"), this.deflectPanel.style.display = "none", this.input = n("textarea", void 0), this.input.rows = 1, this.input.placeholder = ((y = a.i18n) == null ? void 0 : y.placeholder) ?? "Messageโ€ฆ";
299
+ const i = n("button", "ocw-sendbtn");
300
+ i.type = "button";
301
+ const P = (S = a.i18n) == null ? void 0 : S.send;
302
+ P ? (i.textContent = P, i.classList.add("ocw-sendbtn-label"), i.setAttribute("aria-label", P)) : (i.innerHTML = Ge, i.setAttribute("aria-label", "Send message")), i.disabled = !0, this.sendBtn = i, i.addEventListener("click", () => this.flushSend()), this.input.addEventListener("input", () => {
303
+ var v, D;
304
+ this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((_) => _.senderRole === "guest") ? (D = (v = this.h).onDeflectQuery) == null || D.call(v, this.input.value) : this.hideDeflection();
305
+ }), this.input.addEventListener("keydown", (v) => {
306
+ v.isComposing || v.keyCode === 229 || (v.key === "Enter" && !v.shiftKey ? (v.preventDefault(), this.flushSend()) : this.signalTyping());
312
307
  });
313
- const P = n("button", "ocw-attach", "๐Ÿ“Ž");
314
- P.title = "Attach image or file";
308
+ const B = n("button", "ocw-attach", "๐Ÿ“Ž");
309
+ B.title = "Attach image or file";
315
310
  const I = document.createElement("input");
316
- I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", P.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
317
- var g;
318
- (g = I.files) != null && g[0] && this.h.onAttach && this.h.onAttach(I.files[0]), I.value = "";
311
+ I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", B.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
312
+ var v;
313
+ (v = I.files) != null && v[0] && this.h.onAttach && this.h.onAttach(I.files[0]), I.value = "";
319
314
  });
320
- const M = n("div", "ocw-input");
321
- M.append(P, I, this.input, b);
322
- const j = n("div", "ocw-footer");
323
- ((S = i.i18n) == null ? void 0 : S.poweredBy) !== void 0 ? j.textContent = i.i18n.poweredBy : j.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = j, this.reopenBtn = n("button", "ocw-reopen", ((D = this.cfg.i18n) == null ? void 0 : D.reopen) ?? "Reopen conversation"), this.reopenBtn.type = "button", this.reopenBtn.addEventListener("click", () => {
315
+ const q = n("div", "ocw-input");
316
+ q.append(B, I, this.input, i);
317
+ const z = n("div", "ocw-footer");
318
+ ((N = a.i18n) == null ? void 0 : N.poweredBy) !== void 0 ? z.textContent = a.i18n.poweredBy : z.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = z, this.reopenBtn = n("button", "ocw-reopen", ((M = this.cfg.i18n) == null ? void 0 : M.reopen) ?? "Reopen conversation"), this.reopenBtn.type = "button", this.reopenBtn.addEventListener("click", () => {
324
319
  this.reopenBtn.style.display = "none";
325
- const g = this.root.querySelector(".ocw-input textarea");
326
- g == null || g.focus();
327
- }), e.append(w, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.preChatPanel, this.deflectPanel, this.awayNotice, M, this.reopenBtn, this.footer);
328
- const d = (g) => {
329
- e.classList.toggle("ocw-compact", g > 0 && g < We);
320
+ const v = this.root.querySelector(".ocw-input textarea");
321
+ v == null || v.focus();
322
+ }), e.append(w, this.chips, this.scroll, this.typing, this.quick, this.formHost, this.csatPanel, this.preChatPanel, this.deflectPanel, this.awayNotice, q, this.reopenBtn, this.footer);
323
+ const j = (v) => {
324
+ e.classList.toggle("ocw-compact", v > 0 && v < We);
330
325
  };
331
- d(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((g) => {
332
- var H;
333
- const N = ((H = g[0]) == null ? void 0 : H.contentRect.width) ?? e.clientWidth;
334
- d(N);
326
+ j(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((v) => {
327
+ var _;
328
+ const D = ((_ = v[0]) == null ? void 0 : _.contentRect.width) ?? e.clientWidth;
329
+ j(D);
335
330
  }), this.compactObserver.observe(e));
336
331
  }
337
332
  /** Returns the scroll container so history.ts can attach scroll listeners. */
@@ -366,48 +361,49 @@ class Xe {
366
361
  this.h.onTyping(!0, e), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
367
362
  }
368
363
  render(e) {
369
- var I, M, j, d, r, C, v, u;
364
+ var I, q, z, j, r, d, b, k;
370
365
  if (this.storeRef = e, e.accent && (this.root.style.setProperty("--ocw-accent", e.accent), this.root.style.setProperty("--ocw-accent2", this.cfgAccent2 ?? e.accent)), this.e2eBadge.style.display = e.e2e ? "inline-flex" : "none", this.buildSubjectCard(e), e.subject) {
371
- const f = (I = this.cfg.subject) == null ? void 0 : I.ownerLabel;
372
- f && (this.headerName.textContent = f);
366
+ const u = (I = this.cfg.subject) == null ? void 0 : I.ownerLabel;
367
+ u && (this.headerName.textContent = u);
373
368
  }
374
369
  this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
375
370
  const l = e.visibleActions();
376
371
  this.chips.style.display = l.length ? "flex" : "none";
377
- for (const f of l) this.chips.append(this.chipEl(f));
378
- const c = this.scroll.scrollHeight, i = this.scroll.scrollTop;
372
+ for (const u of l) this.chips.append(this.chipEl(u));
373
+ const c = this.scroll.scrollHeight, a = this.scroll.scrollTop;
379
374
  if (this.scroll.replaceChildren(), this.subjectCard.childNodes.length && this.scroll.append(this.subjectCard), e.hasMoreHistory) {
380
- const f = n("div", "ocw-load-more");
381
- f.textContent = "โ†‘ Loading earlier messagesโ€ฆ", f.style.pointerEvents = "none", this.scroll.append(f);
375
+ const u = n("div", "ocw-load-more");
376
+ u.textContent = "โ†‘ Loading earlier messagesโ€ฆ", u.style.pointerEvents = "none", this.scroll.append(u);
382
377
  }
383
- let x = 0, w = null;
384
- for (const f of e.messages()) {
385
- const R = f.senderRole !== "system" && f.senderId !== this.me && !f.internal && f.senderId !== w;
386
- this.scroll.append(this.messageEl(f, e, R)), f.senderRole !== "system" && (w = f.senderId), f.senderId !== this.me && f.seq > x && (x = f.seq);
378
+ let f = 0, w = null;
379
+ const C = [...e.messages()];
380
+ for (let u = 0; u < C.length; u++) {
381
+ const g = C[u], $ = g.senderRole !== "system" && g.senderId !== this.me && !g.internal && g.senderId !== w;
382
+ this.scroll.append(this.messageEl(g, e, $, u === C.length - 1)), g.senderRole !== "system" && (w = g.senderId), g.senderId !== this.me && g.seq > f && (f = g.seq);
387
383
  }
388
- i > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - c + i : this.scroll.scrollTop = this.scroll.scrollHeight, x > 0 && this.h.onReadUpTo(x);
389
- const y = [...e.typing];
390
- this.typing.classList.toggle("active", y.length > 0);
391
- const p = this.typing.querySelector(".ocw-typing-bubble");
392
- p && p.setAttribute("aria-label", y.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
393
- const h = e.messages().some((f) => f.senderRole === "guest");
394
- if (!!((M = e.preChat) != null && M.enabled) && !this.preChatDone && !h && (e.preChat.showWhen !== "offline" || e.offline))
395
- this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (j = this.root.querySelector(".ocw-input")) == null || j.style.setProperty("display", "none");
384
+ a > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - c + a : this.scroll.scrollTop = this.scroll.scrollHeight, f > 0 && this.h.onReadUpTo(f);
385
+ const p = [...e.typing];
386
+ this.typing.classList.toggle("active", p.length > 0);
387
+ const h = this.typing.querySelector(".ocw-typing-bubble");
388
+ h && h.setAttribute("aria-label", p.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
389
+ const m = e.messages().some((u) => u.senderRole === "guest");
390
+ if (!!((q = e.preChat) != null && q.enabled) && !this.preChatDone && !m && (e.preChat.showWhen !== "offline" || e.offline))
391
+ this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (z = this.root.querySelector(".ocw-input")) == null || z.style.setProperty("display", "none");
396
392
  else {
397
393
  if (this.preChatPanel.style.display = "none", e.offline) {
398
394
  this.awayNotice.firstChild || this.awayNotice.append(n("span", "ocw-away-icon", "๐ŸŒ™"), n("span", "", ""));
399
- const f = this.awayNotice.lastChild;
400
- f.textContent = e.offlineMessage || ((d = this.cfg.i18n) == null ? void 0 : d.offline) || "We're away right now โ€” send your message and we'll reply as soon as we're back.", this.awayNotice.style.display = "flex";
395
+ const u = this.awayNotice.lastChild;
396
+ u.textContent = e.offlineMessage || ((j = this.cfg.i18n) == null ? void 0 : j.offline) || "We're away right now โ€” send your message and we'll reply as soon as we're back.", this.awayNotice.style.display = "flex";
401
397
  } else
402
398
  this.awayNotice.style.display = "none";
403
399
  (r = this.root.querySelector(".ocw-input")) == null || r.style.removeProperty("display");
404
400
  }
405
- const a = ["resolved", "closed", "sold", "issued", "checked_out"];
406
- this.h.onCsat && !this.csatSubmitted && a.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
407
- const P = a.includes(e.state);
408
- if (e.offline ? (this.headStatus.textContent = `โ— ${e.offlineMessage || ((C = this.cfg.i18n) == null ? void 0 : C.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `โ— ${((v = this.cfg.i18n) == null ? void 0 : v.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", P && e.messages().length > 0) {
409
- const f = n("div", "ocw-resolved-note", `โ€” ${((u = this.cfg.i18n) == null ? void 0 : u.resolved) ?? "Marked as resolved"} โ€”`);
410
- this.scroll.append(f), this.reopenBtn.style.display = "block";
401
+ const P = ["resolved", "closed", "sold", "issued", "checked_out"];
402
+ this.h.onCsat && !this.csatSubmitted && P.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
403
+ const B = P.includes(e.state);
404
+ if (e.offline ? (this.headStatus.textContent = `โ— ${e.offlineMessage || ((d = this.cfg.i18n) == null ? void 0 : d.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `โ— ${((b = this.cfg.i18n) == null ? void 0 : b.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", B && e.messages().length > 0) {
405
+ const u = n("div", "ocw-resolved-note", `โ€” ${((k = this.cfg.i18n) == null ? void 0 : k.resolved) ?? "Marked as resolved"} โ€”`);
406
+ this.scroll.append(u), this.reopenBtn.style.display = "block";
411
407
  } else
412
408
  this.reopenBtn.style.display = "none";
413
409
  }
@@ -425,50 +421,50 @@ class Xe {
425
421
  this.preChatBuilt = !0, this.preChatPanel.replaceChildren(), this.preChatPanel.append(n("div", "ocw-prechat-title", e.title ?? "Before we startโ€ฆ"));
426
422
  const l = n("div", "ocw-offline-form"), c = {};
427
423
  for (const h of e.fields ?? ["name", "email"]) {
428
- const b = n("input", "ocw-offline-input");
429
- b.type = h === "email" ? "email" : h === "phone" ? "tel" : "text", b.placeholder = h === "name" ? "Your name" : h === "email" ? "Your email" : "Your phone number", c[h] = b, l.append(b);
424
+ const m = n("input", "ocw-offline-input");
425
+ m.type = h === "email" ? "email" : h === "phone" ? "tel" : "text", m.placeholder = h === "name" ? "Your name" : h === "email" ? "Your email" : "Your phone number", c[h] = m, l.append(m);
430
426
  }
431
- let i = null;
427
+ let a = null;
432
428
  if ((p = e.topics) != null && p.length) {
433
- i = n("select", void 0);
429
+ a = n("select", void 0);
434
430
  const h = document.createElement("option");
435
- h.value = "", h.textContent = "What is this about?", i.append(h);
436
- for (const b of e.topics) {
437
- const a = document.createElement("option");
438
- a.value = b, a.textContent = b, i.append(a);
431
+ h.value = "", h.textContent = "What is this about?", a.append(h);
432
+ for (const m of e.topics) {
433
+ const i = document.createElement("option");
434
+ i.value = m, i.textContent = m, a.append(i);
439
435
  }
440
- l.append(i);
436
+ l.append(a);
441
437
  }
442
- let x = null, w = null;
438
+ let f = null, w = null;
443
439
  if (e.callbackOption) {
444
440
  const h = n("label", "ocw-prechat-cb");
445
- x = document.createElement("input"), x.type = "checkbox", h.append(x, document.createTextNode("๐Ÿ“ž Request a call back")), l.append(h), c.phone || (w = n("input", "ocw-offline-input"), w.type = "tel", w.placeholder = "Phone number for the call", w.style.display = "none", x.addEventListener("change", () => w.style.setProperty("display", x.checked ? "block" : "none")), l.append(w));
441
+ f = document.createElement("input"), f.type = "checkbox", h.append(f, document.createTextNode("๐Ÿ“ž Request a call back")), l.append(h), c.phone || (w = n("input", "ocw-offline-input"), w.type = "tel", w.placeholder = "Phone number for the call", w.style.display = "none", f.addEventListener("change", () => w.style.setProperty("display", f.checked ? "block" : "none")), l.append(w));
446
442
  }
447
- const y = n("button", "ocw-offline-submit", "Start chat");
448
- y.type = "button", y.addEventListener("click", () => {
449
- var P, I, M, j, d, r, C;
443
+ const C = n("button", "ocw-offline-submit", "Start chat");
444
+ C.type = "button", C.addEventListener("click", () => {
445
+ var P, B, I, q, z, j, r;
450
446
  const h = (P = c.email) == null ? void 0 : P.value.trim();
451
447
  if (c.email && (!h || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h))) {
452
448
  c.email.focus();
453
449
  return;
454
450
  }
455
- const b = !!(x != null && x.checked), a = (((I = c.phone) == null ? void 0 : I.value) ?? (w == null ? void 0 : w.value) ?? "").trim();
456
- if (b && !a) {
457
- (M = c.phone ?? w) == null || M.focus();
451
+ const m = !!(f != null && f.checked), i = (((B = c.phone) == null ? void 0 : B.value) ?? (w == null ? void 0 : w.value) ?? "").trim();
452
+ if (m && !i) {
453
+ (I = c.phone ?? w) == null || I.focus();
458
454
  return;
459
455
  }
460
- if (i && ((j = e.topics) != null && j.length) && !i.value) {
461
- i.focus();
456
+ if (a && ((q = e.topics) != null && q.length) && !a.value) {
457
+ a.focus();
462
458
  return;
463
459
  }
464
- y.disabled = !0, this.completePreChat(), (C = (r = this.h).onPreChat) == null || C.call(r, {
465
- ...(d = c.name) != null && d.value.trim() ? { name: c.name.value.trim() } : {},
460
+ C.disabled = !0, this.completePreChat(), (r = (j = this.h).onPreChat) == null || r.call(j, {
461
+ ...(z = c.name) != null && z.value.trim() ? { name: c.name.value.trim() } : {},
466
462
  ...h ? { email: h } : {},
467
- ...a ? { phone: a } : {},
468
- ...i != null && i.value ? { topic: i.value } : {},
469
- ...b ? { callback: !0 } : {}
463
+ ...i ? { phone: i } : {},
464
+ ...a != null && a.value ? { topic: a.value } : {},
465
+ ...m ? { callback: !0 } : {}
470
466
  });
471
- }), l.append(y), this.preChatPanel.append(l);
467
+ }), l.append(C), this.preChatPanel.append(l);
472
468
  }
473
469
  /** Mark pre-chat complete (submitted now or in a previous session). */
474
470
  completePreChat() {
@@ -491,23 +487,23 @@ class Xe {
491
487
  this.csatPanel.replaceChildren(), this.csatPanel.append(n("div", "ocw-csat-title", "How did we do?"));
492
488
  const e = n("div", "ocw-csat-stars"), l = [];
493
489
  for (let c = 1; c <= 5; c++) {
494
- const i = n("button", "ocw-csat-star", "โ˜…");
495
- i.dataset.score = String(c), i.addEventListener("mouseenter", () => l.forEach((x, w) => x.classList.toggle("lit", w < c))), i.addEventListener("mouseleave", () => l.forEach((x) => x.classList.remove("lit"))), i.addEventListener("click", () => {
496
- var x, w;
497
- this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${c}โ˜… rating!`)), (w = (x = this.h).onCsat) == null || w.call(x, c);
498
- }), l.push(i), e.append(i);
490
+ const a = n("button", "ocw-csat-star", "โ˜…");
491
+ a.dataset.score = String(c), a.addEventListener("mouseenter", () => l.forEach((f, w) => f.classList.toggle("lit", w < c))), a.addEventListener("mouseleave", () => l.forEach((f) => f.classList.remove("lit"))), a.addEventListener("click", () => {
492
+ var f, w;
493
+ this.csatSubmitted = !0, this.csatPanel.replaceChildren(n("div", "ocw-csat-done", `Thanks for your ${c}โ˜… rating!`)), (w = (f = this.h).onCsat) == null || w.call(f, c);
494
+ }), l.push(a), e.append(a);
499
495
  }
500
496
  this.csatPanel.append(e);
501
497
  }
502
498
  buildSubjectCard(e) {
503
499
  if (this.subjectBuilt) return;
504
- const l = e.subject, c = this.cfg.subject, i = (l == null ? void 0 : l.title) ?? (c == null ? void 0 : c.title);
505
- if (!i) return;
506
- this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title", i)), c != null && c.subtitle && this.subjectCard.append(n("div", "ocw-subject-sub", c.subtitle));
507
- const x = n("div", "ocw-tags");
508
- if (l) for (const [y, p] of Object.entries(l.fields)) x.append(n("span", "ocw-tag", `${y}: ${p}`));
509
- else for (const y of (c == null ? void 0 : c.tags) ?? []) x.append(n("span", "ocw-tag", y));
510
- x.childNodes.length && this.subjectCard.append(x);
500
+ const l = e.subject, c = this.cfg.subject, a = (l == null ? void 0 : l.title) ?? (c == null ? void 0 : c.title);
501
+ if (!a) return;
502
+ this.subjectBuilt = !0, this.subjectCard.replaceChildren(), this.subjectCard.append(n("div", "ocw-subject-title", a)), c != null && c.subtitle && this.subjectCard.append(n("div", "ocw-subject-sub", c.subtitle));
503
+ const f = n("div", "ocw-tags");
504
+ if (l) for (const [C, p] of Object.entries(l.fields)) f.append(n("span", "ocw-tag", `${C}: ${p}`));
505
+ else for (const C of (c == null ? void 0 : c.tags) ?? []) f.append(n("span", "ocw-tag", C));
506
+ f.childNodes.length && this.subjectCard.append(f);
511
507
  const w = (l == null ? void 0 : l.state) ?? (c == null ? void 0 : c.status);
512
508
  w && (this.statusBadge.textContent = w, this.statusBadge.style.display = "inline-flex");
513
509
  }
@@ -521,185 +517,204 @@ class Xe {
521
517
  /** In-widget confirmation modal (replaces window.confirm). */
522
518
  confirm(e) {
523
519
  return new Promise((l) => {
524
- const c = n("div", "ocw-modal"), i = n("div", "ocw-modal-card");
525
- i.append(n("div", "ocw-modal-title", e)), i.append(n("div", "ocw-modal-body", `Confirm โ€œ${e}โ€?`));
526
- const x = n("div", "ocw-modal-actions"), w = n("button", "ocw-modal-cancel", "Cancel"), y = n("button", "ocw-modal-ok", "Confirm"), p = (h) => {
520
+ const c = n("div", "ocw-modal"), a = n("div", "ocw-modal-card");
521
+ a.append(n("div", "ocw-modal-title", e)), a.append(n("div", "ocw-modal-body", `Confirm โ€œ${e}โ€?`));
522
+ const f = n("div", "ocw-modal-actions"), w = n("button", "ocw-modal-cancel", "Cancel"), C = n("button", "ocw-modal-ok", "Confirm"), p = (h) => {
527
523
  c.remove(), l(h);
528
524
  };
529
- w.addEventListener("click", () => p(!1)), y.addEventListener("click", () => p(!0)), c.addEventListener("click", (h) => {
525
+ w.addEventListener("click", () => p(!1)), C.addEventListener("click", () => p(!0)), c.addEventListener("click", (h) => {
530
526
  h.target === c && p(!1);
531
- }), x.append(w, y), i.append(x), c.append(i), this.root.append(c), y.focus();
527
+ }), f.append(w, C), a.append(f), c.append(a), this.root.append(c), C.focus();
532
528
  });
533
529
  }
534
530
  /** Inline form for a form-effect action: typed inputs (date picker, number,
535
531
  * text) rendered above the composer โ€” no browser prompts. */
536
532
  openForm(e) {
537
- var y, p;
533
+ var C, p;
538
534
  this.formHost.replaceChildren();
539
535
  const l = n("div", "ocw-form");
540
536
  l.append(n("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
541
537
  const c = /* @__PURE__ */ new Map();
542
538
  for (const h of e.input ?? []) {
543
- const b = n("label", "ocw-form-row");
544
- if (b.append(n("span", "ocw-form-lbl", h.label)), h.type === "select" && ((y = h.options) != null && y.length)) {
545
- const a = n("select", "ocw-form-input");
546
- h.required || a.append(n("option", void 0, "โ€” select โ€”"));
539
+ const m = n("label", "ocw-form-row");
540
+ if (m.append(n("span", "ocw-form-lbl", h.label)), h.type === "select" && ((C = h.options) != null && C.length)) {
541
+ const i = n("select", "ocw-form-input");
542
+ h.required || i.append(n("option", void 0, "โ€” select โ€”"));
547
543
  for (const P of h.options) {
548
- const I = n("option");
549
- I.value = P, I.textContent = P, a.append(I);
544
+ const B = n("option");
545
+ B.value = P, B.textContent = P, i.append(B);
550
546
  }
551
- h.required && (a.required = !0), b.append(a), c.set(h.name, a);
547
+ h.required && (i.required = !0), m.append(i), c.set(h.name, i);
552
548
  } else {
553
- const a = n("input", "ocw-form-input");
554
- a.type = h.type === "number" ? "number" : h.type === "date" ? "datetime-local" : "text", h.required && (a.required = !0), b.append(a), c.set(h.name, a);
549
+ const i = n("input", "ocw-form-input");
550
+ i.type = h.type === "number" ? "number" : h.type === "date" ? "datetime-local" : "text", h.required && (i.required = !0), m.append(i), c.set(h.name, i);
555
551
  }
556
- l.append(b);
552
+ l.append(m);
557
553
  }
558
- const i = n("div", "ocw-form-actions"), x = n("button", "ocw-form-cancel", "Cancel"), w = n("button", "ocw-form-submit", "Send");
559
- x.addEventListener("click", () => this.formHost.replaceChildren()), w.addEventListener("click", () => {
554
+ const a = n("div", "ocw-form-actions"), f = n("button", "ocw-form-cancel", "Cancel"), w = n("button", "ocw-form-submit", "Send");
555
+ f.addEventListener("click", () => this.formHost.replaceChildren()), w.addEventListener("click", () => {
560
556
  const h = {};
561
- for (const [b, a] of c) {
562
- if (a.required && !a.value) {
563
- a.style.borderColor = "#e5484d";
557
+ for (const [m, i] of c) {
558
+ if (i.required && !i.value) {
559
+ i.style.borderColor = "#e5484d";
564
560
  return;
565
561
  }
566
- h[b] = a.type === "number" ? Number(a.value) : a.value;
562
+ h[m] = i.type === "number" ? Number(i.value) : i.value;
567
563
  }
568
564
  this.formHost.replaceChildren(), this.h.onInvoke(e.id, h);
569
- }), i.append(x, w), l.append(i), this.formHost.append(l), (p = c.values().next().value) == null || p.focus();
565
+ }), a.append(f, w), l.append(a), this.formHost.append(l), (p = c.values().next().value) == null || p.focus();
570
566
  }
571
- messageEl(e, l, c = !1) {
572
- var P, I, M, j;
567
+ messageEl(e, l, c = !1, a = !1) {
568
+ var B, I, q, z, j;
573
569
  if (e.senderRole === "system") {
574
- const d = n("div", "ocw-sys");
575
- return d.textContent = e.deletedAt ? "message deleted" : ae(e.content), d;
570
+ const r = n("div", "ocw-sys");
571
+ return r.textContent = e.deletedAt ? "message deleted" : ae(e.content), r;
576
572
  }
577
- const i = e.senderId === this.me, x = !!e.internal, w = n("div", `ocw-row ${x ? "ocw-note mine" : i ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`);
578
- !i && !x && w.append(n("div", "ocw-dot", e.senderRole === "bot" ? "๐Ÿค–" : "๐Ÿง‘"));
579
- const y = n("div");
573
+ const f = e.senderId === this.me, w = !!e.internal, C = n("div", `ocw-row ${w ? "ocw-note mine" : f ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`), p = n("div");
580
574
  if (c) {
581
- const d = e.senderRole === "bot" ? ((P = this.cfg.i18n) == null ? void 0 : P.aiAssistant) ?? "AI Assistant" : ((I = this.cfg.subject) == null ? void 0 : I.ownerLabel) ?? ((M = this.cfg.subject) == null ? void 0 : M.title) ?? "Support";
582
- y.append(n("div", "ocw-msg-sender", d));
575
+ const r = e.senderRole === "bot" ? ((B = this.cfg.i18n) == null ? void 0 : B.aiAssistant) ?? "AI Assistant" : ((I = this.cfg.subject) == null ? void 0 : I.ownerLabel) ?? ((q = this.cfg.subject) == null ? void 0 : q.title) ?? "Support";
576
+ p.append(n("div", "ocw-msg-sender", r));
583
577
  }
584
- const p = n("div", "ocw-bubble-wrap");
578
+ const h = n("div", "ocw-bubble-wrap");
585
579
  if (e.replyToId) {
586
- const d = n("div", "ocw-reply-to", "โ†ฉ replying to a message");
587
- d.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", y.append(d);
580
+ const r = n("div", "ocw-reply-to", "โ†ฉ replying to a message");
581
+ r.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", p.append(r);
588
582
  }
589
- const h = n("div", "ocw-bubble");
590
- let b = null;
591
- if (e.deletedAt) h.append(n("span", "ocw-deleted", "message deleted"));
583
+ const m = n("div", "ocw-bubble");
584
+ let i = null;
585
+ if (e.deletedAt) m.append(n("span", "ocw-deleted", "message deleted"));
592
586
  else if (e.content.kind === "attachment") {
593
- const d = e.content;
594
- if ((j = d.mime) != null && j.startsWith("image/")) {
595
- const r = document.createElement("img");
596
- r.src = d.url, r.alt = d.name ?? "image", r.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", r.addEventListener("click", () => window.open(d.url, "_blank")), h.append(r);
587
+ const r = e.content;
588
+ if ((z = r.mime) != null && z.startsWith("image/")) {
589
+ const d = document.createElement("img");
590
+ d.src = r.url, d.alt = r.name ?? "image", d.style.cssText = "max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer", d.addEventListener("click", () => window.open(r.url, "_blank")), m.append(d);
597
591
  } else {
598
- const r = document.createElement("a");
599
- r.href = d.url, r.target = "_blank", r.rel = "noopener", r.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", r.append(n("span", void 0, "๐Ÿ“„"), n("span", void 0, d.name ?? "file")), h.append(r);
592
+ const d = document.createElement("a");
593
+ d.href = r.url, d.target = "_blank", d.rel = "noopener", d.style.cssText = "display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none", d.append(n("span", void 0, "๐Ÿ“„"), n("span", void 0, r.name ?? "file")), m.append(d);
600
594
  }
601
595
  } else if (e.content.kind === "appointment") {
602
- const d = e.content, r = n("div", "ocw-appt");
603
- r.append(n("div", "ocw-appt-title", `๐Ÿ“… ${d.title}`)), r.append(n("div", "ocw-appt-time", new Date(d.startIso).toLocaleString() + " โ€“ " + new Date(d.endIso).toLocaleTimeString())), d.location && r.append(n("div", "ocw-appt-loc", `๐Ÿ“ ${d.location}`)), d.description && r.append(n("div", "ocw-appt-desc", d.description));
604
- const C = n("div", "ocw-appt-links"), v = document.createElement("a");
605
- v.href = d.googleUrl, v.target = "_blank", v.rel = "noopener", v.className = "ocw-appt-btn", v.textContent = "๐Ÿ“… Add to Google Calendar";
596
+ const r = e.content, d = n("div", "ocw-appt");
597
+ d.append(n("div", "ocw-appt-title", `๐Ÿ“… ${r.title}`)), d.append(n("div", "ocw-appt-time", new Date(r.startIso).toLocaleString() + " โ€“ " + new Date(r.endIso).toLocaleTimeString())), r.location && d.append(n("div", "ocw-appt-loc", `๐Ÿ“ ${r.location}`)), r.description && d.append(n("div", "ocw-appt-desc", r.description));
598
+ const b = n("div", "ocw-appt-links"), k = document.createElement("a");
599
+ k.href = r.googleUrl, k.target = "_blank", k.rel = "noopener", k.className = "ocw-appt-btn", k.textContent = "๐Ÿ“… Add to Google Calendar";
606
600
  const u = document.createElement("a");
607
- u.href = d.icalUrl, u.download = `${d.title}.ics`, u.className = "ocw-appt-btn ocw-appt-btn-sec", u.textContent = "๐ŸŽ Apple / iCal", C.append(v, u), r.append(C), h.append(r);
601
+ u.href = r.icalUrl, u.download = `${r.title}.ics`, u.className = "ocw-appt-btn ocw-appt-btn-sec", u.textContent = "๐ŸŽ Apple / iCal", b.append(k, u), d.append(b), m.append(d);
608
602
  } else
609
- b = document.createTextNode(ae(e.content)), h.append(b), e.editedAt && h.append(n("span", "ocw-edited", "(edited)"));
610
- if (p.append(h), !i && !x && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && b) {
611
- const d = e.content.text;
612
- if (d.trim()) {
613
- const r = n("button", "ocw-translate-btn", "๐ŸŒ");
614
- r.type = "button", r.title = "Translate", r.addEventListener("click", (C) => {
615
- if (C.stopPropagation(), this.showingTranslation.has(e.id)) {
616
- this.showingTranslation.delete(e.id), b.textContent = d, r.textContent = "๐ŸŒ", r.title = "Translate";
603
+ i = document.createTextNode(ae(e.content)), m.append(i), e.editedAt && m.append(n("span", "ocw-edited", "(edited)"));
604
+ if (h.append(m), a && !e.deletedAt && e.content.kind === "text" && ((j = e.content.quickReplies) != null && j.length)) {
605
+ const r = n("div", "ocw-flow-choices");
606
+ r.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-top:6px";
607
+ for (const d of e.content.quickReplies) {
608
+ const b = n("button", "ocw-flow-choice", d);
609
+ b.type = "button", b.style.cssText = "border:1px solid var(--ocw-bd,rgba(0,0,0,.12));background:var(--ocw-bg,#fff);color:inherit;border-radius:14px;padding:5px 12px;font:inherit;font-size:13px;cursor:pointer", b.addEventListener("click", () => {
610
+ r.querySelectorAll("button").forEach((k) => k.disabled = !0), r.style.opacity = "0.5", this.h.onSend(d);
611
+ }), r.append(b);
612
+ }
613
+ h.append(r);
614
+ }
615
+ if (!f && !w && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && i) {
616
+ const r = e.content.text;
617
+ if (r.trim()) {
618
+ const d = n("button", "ocw-translate-btn", "๐ŸŒ");
619
+ d.type = "button", d.title = "Translate";
620
+ const b = n("div", "ocw-translation");
621
+ b.style.display = "none", m.append(b);
622
+ const k = ($) => {
623
+ b.textContent = $, b.style.display = "", this.showingTranslation.add(e.id), d.textContent = "โ†ฉ", d.title = "Show original";
624
+ }, u = () => {
625
+ b.style.display = "none", this.showingTranslation.delete(e.id), d.textContent = "๐ŸŒ", d.title = "Translate";
626
+ };
627
+ d.addEventListener("click", ($) => {
628
+ if ($.stopPropagation(), this.showingTranslation.has(e.id)) {
629
+ u();
617
630
  return;
618
631
  }
619
- const v = this.translationCache.get(e.id);
620
- if (v !== void 0) {
621
- this.showingTranslation.add(e.id), b.textContent = v, r.textContent = "โ†ฉ", r.title = "Show original";
632
+ const y = this.translationCache.get(e.id);
633
+ if (y !== void 0) {
634
+ k(y);
622
635
  return;
623
636
  }
624
- r.textContent = "โณ", this.h.onTranslate(d).then((u) => {
625
- if (u === null) {
626
- r.textContent = "โš ๏ธ", r.title = "Translation unavailable", setTimeout(() => {
627
- r.textContent = "๐ŸŒ", r.title = "Translate";
637
+ d.textContent = "โณ", this.h.onTranslate(r).then((S) => {
638
+ if (S === null) {
639
+ d.textContent = "โš ๏ธ", d.title = "Translation unavailable", setTimeout(() => {
640
+ d.textContent = "๐ŸŒ", d.title = "Translate";
628
641
  }, 1500);
629
642
  return;
630
643
  }
631
- this.translationCache.set(e.id, u), this.showingTranslation.add(e.id), b.textContent = u, r.textContent = "โ†ฉ", r.title = "Show original";
644
+ this.translationCache.set(e.id, S), k(S);
632
645
  });
633
- }), p.append(r);
646
+ }), h.append(d);
647
+ const g = this.translationCache.get(e.id);
648
+ this.showingTranslation.has(e.id) && g !== void 0 && k(g);
634
649
  }
635
650
  }
636
- if (i && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
637
- const d = n("div", "ocw-msg-menu");
651
+ if (f && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
652
+ const r = n("div", "ocw-msg-menu");
638
653
  if (this.h.onEdit) {
639
- const r = n("button", void 0, "โœ๏ธ");
640
- r.title = "Edit", r.addEventListener("click", (C) => {
641
- C.stopPropagation();
642
- const v = ae(e.content), u = document.createElement("textarea");
643
- u.value = v, u.rows = Math.min(4, Math.ceil(v.length / 40) + 1), u.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";
644
- const f = n("button", "ocw-form-submit", "Save");
645
- f.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
646
- const R = n("button", "ocw-form-cancel", "Cancel");
647
- R.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
648
- const B = n("div");
649
- B.style.cssText = "display:flex;gap:6px;justify-content:flex-end", B.append(R, f);
650
- const A = n("div");
651
- A.append(u, B), h.replaceChildren(A), u.focus(), u.select();
652
- const k = () => h.replaceChildren(b ?? document.createTextNode(v));
653
- R.addEventListener("click", k), f.addEventListener("click", () => {
654
- const S = u.value.trim();
655
- S && S !== v && this.h.onEdit(e.id, S), k();
656
- }), u.addEventListener("keydown", (S) => {
657
- S.key === "Enter" && !S.shiftKey && (S.preventDefault(), f.click()), S.key === "Escape" && k();
654
+ const d = n("button", void 0, "โœ๏ธ");
655
+ d.title = "Edit", d.addEventListener("click", (b) => {
656
+ b.stopPropagation();
657
+ const k = ae(e.content), u = document.createElement("textarea");
658
+ u.value = k, u.rows = Math.min(4, Math.ceil(k.length / 40) + 1), u.style.cssText = "width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";
659
+ const g = n("button", "ocw-form-submit", "Save");
660
+ g.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
661
+ const $ = n("button", "ocw-form-cancel", "Cancel");
662
+ $.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
663
+ const y = n("div");
664
+ y.style.cssText = "display:flex;gap:6px;justify-content:flex-end", y.append($, g);
665
+ const S = n("div");
666
+ S.append(u, y), m.replaceChildren(S), u.focus(), u.select();
667
+ const N = () => m.replaceChildren(i ?? document.createTextNode(k));
668
+ $.addEventListener("click", N), g.addEventListener("click", () => {
669
+ const M = u.value.trim();
670
+ M && M !== k && this.h.onEdit(e.id, M), N();
671
+ }), u.addEventListener("keydown", (M) => {
672
+ M.key === "Enter" && !M.shiftKey && (M.preventDefault(), g.click()), M.key === "Escape" && N();
658
673
  });
659
- }), d.append(r);
674
+ }), r.append(d);
660
675
  }
661
676
  if (this.h.onDelete) {
662
- const r = n("button", "del", "๐Ÿ—‘");
663
- r.title = "Delete", r.addEventListener("click", (C) => {
664
- C.stopPropagation(), this.h.onDelete(e.id);
665
- }), d.append(r);
677
+ const d = n("button", "del", "๐Ÿ—‘");
678
+ d.title = "Delete", d.addEventListener("click", (b) => {
679
+ b.stopPropagation(), this.h.onDelete(e.id);
680
+ }), r.append(d);
666
681
  }
667
- p.append(d);
682
+ h.append(r);
668
683
  }
669
- if (y.append(p), this.h.onReact && !e.deletedAt && e.seq > 0) {
670
- const d = n("div", "ocw-react-wrap"), r = n("div", "ocw-react");
684
+ if (p.append(h), this.h.onReact && !e.deletedAt && e.seq > 0) {
685
+ const r = n("div", "ocw-react-wrap"), d = n("div", "ocw-react");
671
686
  if (e.reactions && Object.keys(e.reactions).length)
672
- for (const [u, f] of Object.entries(e.reactions)) {
673
- const R = n("button", `ocw-react-pill${f.includes(this.me) ? " mine" : ""}`, `${u} ${f.length}`);
674
- R.addEventListener("click", () => {
675
- var B, A;
676
- return (A = (B = this.h).onReact) == null ? void 0 : A.call(B, e.id, u, f.includes(this.me));
677
- }), r.append(R);
687
+ for (const [u, g] of Object.entries(e.reactions)) {
688
+ const $ = n("button", `ocw-react-pill${g.includes(this.me) ? " mine" : ""}`, `${u} ${g.length}`);
689
+ $.addEventListener("click", () => {
690
+ var y, S;
691
+ return (S = (y = this.h).onReact) == null ? void 0 : S.call(y, e.id, u, g.includes(this.me));
692
+ }), d.append($);
678
693
  }
679
- const C = n("button", "ocw-react-btn", "๏ผ‹"), v = n("div", "ocw-react-picker");
694
+ const b = n("button", "ocw-react-btn", "๏ผ‹"), k = n("div", "ocw-react-picker");
680
695
  for (const u of Fe) {
681
- const f = n("button", void 0, u);
682
- f.addEventListener("click", (R) => {
683
- var A, k, S, D;
684
- R.stopPropagation();
685
- const B = (k = (A = e.reactions) == null ? void 0 : A[u]) == null ? void 0 : k.includes(this.me);
686
- (D = (S = this.h).onReact) == null || D.call(S, e.id, u, !!B), v.style.display = "none";
687
- }), v.append(f);
696
+ const g = n("button", void 0, u);
697
+ g.addEventListener("click", ($) => {
698
+ var S, N, M, v;
699
+ $.stopPropagation();
700
+ const y = (N = (S = e.reactions) == null ? void 0 : S[u]) == null ? void 0 : N.includes(this.me);
701
+ (v = (M = this.h).onReact) == null || v.call(M, e.id, u, !!y), k.style.display = "none";
702
+ }), k.append(g);
688
703
  }
689
- v.style.display = "none", C.addEventListener("click", (u) => {
704
+ k.style.display = "none", b.addEventListener("click", (u) => {
690
705
  u.stopPropagation();
691
- const f = v.style.display === "none";
692
- v.style.display = f ? "flex" : "none", f && document.addEventListener("click", () => {
693
- v.style.display = "none";
706
+ const g = k.style.display === "none";
707
+ k.style.display = g ? "flex" : "none", g && document.addEventListener("click", () => {
708
+ k.style.display = "none";
694
709
  }, { once: !0 });
695
- }), r.append(C), d.append(r, v), y.append(d);
696
- } else e.reactions && Object.keys(e.reactions).length && y.append(n("div", "ocw-react", Object.entries(e.reactions).map(([d, r]) => `${d}${r.length}`).join(" ")));
697
- const a = n("div", "ocw-time ocw-meta", Ye(e.ts));
698
- if (i && e.status) {
699
- const d = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Qe(e.status));
700
- a.append(d);
710
+ }), d.append(b), r.append(d, k), p.append(r);
711
+ } else e.reactions && Object.keys(e.reactions).length && p.append(n("div", "ocw-react", Object.entries(e.reactions).map(([r, d]) => `${r}${d.length}`).join(" ")));
712
+ const P = n("div", "ocw-time ocw-meta", Ye(e.ts));
713
+ if (f && e.status) {
714
+ const r = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Qe(e.status));
715
+ P.append(r);
701
716
  }
702
- return i && e.seq > 0 && l.lastReadByOthers >= e.seq && a.append(n("span", "ocw-seen", " ยท Seen")), y.append(a), w.append(y), w;
717
+ return f && e.seq > 0 && l.lastReadByOthers >= e.seq && P.append(n("span", "ocw-seen", " ยท Seen")), p.append(P), C.append(p), C;
703
718
  }
704
719
  }
705
720
  function Qe(t) {
@@ -714,40 +729,40 @@ function Qe(t) {
714
729
  return "๐Ÿ•“";
715
730
  }
716
731
  }
717
- const _ = /* @__PURE__ */ new WeakMap(), Z = /* @__PURE__ */ new Map();
732
+ const U = /* @__PURE__ */ new WeakMap(), ee = /* @__PURE__ */ new Map();
718
733
  function ke(t) {
719
734
  return `relay-launcher::${t.profileId}::${t.subjectId ?? ""}`;
720
735
  }
721
- let K = null;
736
+ let V = null;
722
737
  function Je() {
723
- if (K && K.state !== "closed") return K;
738
+ if (V && V.state !== "closed") return V;
724
739
  try {
725
- return K = new AudioContext(), K;
740
+ return V = new AudioContext(), V;
726
741
  } catch {
727
742
  return null;
728
743
  }
729
744
  }
730
745
  function it(t) {
731
746
  var e;
732
- (e = _.get(t)) == null || e.close(), _.delete(t);
747
+ (e = U.get(t)) == null || e.close(), U.delete(t);
733
748
  }
734
749
  function at(t) {
735
750
  var se, le, de, pe, he, ue, fe, we;
736
- _.has(t.el) && (_.get(t.el).close(), _.delete(t.el)), t.launcher && ((se = Z.get(ke(t))) == null || se.close());
751
+ U.has(t.el) && (U.get(t.el).close(), U.delete(t.el)), t.launcher && ((se = ee.get(ke(t))) == null || se.close());
737
752
  const e = Re();
738
753
  let l, c = !1;
739
- const i = t.token ?? t.userId ?? e, x = i !== e ? e : void 0, { wsUrl: w, httpBase: y } = Ae(t.url, t.apiUrl);
740
- let p = new Oe(i);
741
- const h = t.subjectId ? `${i}::${t.subjectId}` : i, b = new Ne(h);
742
- let a, P = !1, I = null, M = null, j = null, d = null;
754
+ const a = t.token ?? t.userId ?? e, f = a !== e ? e : void 0, { wsUrl: w, httpBase: C } = qe(t.url, t.apiUrl);
755
+ let p = new Oe(a);
756
+ const h = t.subjectId ? `${a}::${t.subjectId}` : a, m = new Ne(h);
757
+ let i, P = !1, B = null, I = null, q = null, z = null;
743
758
  !t.launcher && !t.el.style.height && t.el.clientHeight === 0 && (t.el.style.width = t.el.style.width || "100%", t.el.style.height = "600px");
744
- for (const o of b.load()) p.addOptimistic(o.clientMsgId, o.content);
745
- let r = null, C = null, v = 0, u = !t.launcher;
759
+ for (const o of m.load()) p.addOptimistic(o.clientMsgId, o.content);
760
+ let j = null, r = null, d = 0, b = !t.launcher;
746
761
  if (t.launcher) {
747
762
  const s = (t.position ?? "bottom-right").includes("right");
748
- r = document.createElement("div"), r.style.cssText = `position:fixed;${s ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${s ? "flex-end" : "flex-start"};gap:12px`;
749
- const m = document.createElement("div"), L = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, W = (z) => {
750
- t.el.classList.toggle("ocw-fs", z), m.style.cssText = z ? [
763
+ j = document.createElement("div"), j.style.cssText = `position:fixed;${s ? "right:20px" : "left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${s ? "flex-end" : "flex-start"};gap:12px`;
764
+ const x = document.createElement("div"), R = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, G = (L) => {
765
+ t.el.classList.toggle("ocw-fs", L), x.style.cssText = L ? [
751
766
  "position:fixed",
752
767
  "inset:0",
753
768
  "width:100%",
@@ -776,11 +791,11 @@ function at(t) {
776
791
  "transform:scale(.95)"
777
792
  ].join(";");
778
793
  };
779
- W((L == null ? void 0 : L.matches) ?? !1);
780
- const G = (z) => W(z.matches);
781
- L == null || L.addEventListener("change", G), I = L, M = G, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", m.append(t.el);
782
- const Y = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', X = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', q = document.createElement("button");
783
- q.type = "button", q.style.cssText = [
794
+ G((R == null ? void 0 : R.matches) ?? !1);
795
+ const K = (L) => G(L.matches);
796
+ R == null || R.addEventListener("change", K), B = R, I = K, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", x.append(t.el);
797
+ const X = '<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', Q = '<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', O = document.createElement("button");
798
+ O.type = "button", O.style.cssText = [
784
799
  "width:56px;height:56px;border-radius:50%",
785
800
  `background:${t.accent ?? "#6c5ce7"}`,
786
801
  "color:#fff;border:none;cursor:pointer",
@@ -788,16 +803,16 @@ function at(t) {
788
803
  "position:relative;flex:none",
789
804
  "display:flex;align-items:center;justify-content:center",
790
805
  "transition:transform .15s"
791
- ].join(";"), q.onmouseenter = () => {
792
- q.style.transform = "scale(1.08)";
793
- }, q.onmouseleave = () => {
794
- q.style.transform = "scale(1)";
795
- }, C = document.createElement("span"), C.style.cssText = "position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";
796
- const Q = () => {
797
- q.innerHTML = u ? X : Y, q.setAttribute("aria-label", u ? "Close chat" : "Open chat"), q.setAttribute("aria-expanded", String(u)), q.append(C);
806
+ ].join(";"), O.onmouseenter = () => {
807
+ O.style.transform = "scale(1.08)";
808
+ }, O.onmouseleave = () => {
809
+ O.style.transform = "scale(1)";
810
+ }, r = document.createElement("span"), r.style.cssText = "position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";
811
+ const J = () => {
812
+ O.innerHTML = b ? Q : X, O.setAttribute("aria-label", b ? "Close chat" : "Open chat"), O.setAttribute("aria-expanded", String(b)), O.append(r);
798
813
  };
799
- Q(), r.append(m, q), document.body.append(r);
800
- const te = `ocw-teaser-dismissed::${t.profileId}`, J = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
814
+ J(), j.append(x, O), document.body.append(j);
815
+ const te = `ocw-teaser-dismissed::${t.profileId}`, Z = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
801
816
  let E = null;
802
817
  const Le = () => {
803
818
  try {
@@ -806,13 +821,13 @@ function at(t) {
806
821
  return !1;
807
822
  }
808
823
  }, Pe = '<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>', be = () => {
809
- const z = J != null && J.title ? J : p.launcherMessage ?? void 0;
810
- if (!(!!(z != null && z.title) && !u && !Le())) {
824
+ const L = Z != null && Z.title ? Z : p.launcherMessage ?? void 0;
825
+ if (!(!!(L != null && L.title) && !b && !Le())) {
811
826
  E && (E.remove(), E = null);
812
827
  return;
813
828
  }
814
829
  if (E) return;
815
- E = document.createElement("div"), E.setAttribute("role", "button"), E.setAttribute("tabindex", "0"), E.setAttribute("aria-label", z.title), E.style.cssText = [
830
+ E = document.createElement("div"), E.setAttribute("role", "button"), E.setAttribute("tabindex", "0"), E.setAttribute("aria-label", L.title), E.style.cssText = [
816
831
  "max-width:280px",
817
832
  "background:#fff",
818
833
  "border-radius:16px",
@@ -825,138 +840,138 @@ function at(t) {
825
840
  "animation:ocw-teaser-in .22s ease-out"
826
841
  ].join(";");
827
842
  const oe = document.createElement("div");
828
- if (oe.textContent = z.title, oe.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", E.append(oe), z.subtitle) {
829
- const O = document.createElement("div");
830
- O.style.cssText = "display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";
843
+ if (oe.textContent = L.title, oe.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", E.append(oe), L.subtitle) {
844
+ const H = document.createElement("div");
845
+ H.style.cssText = "display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";
831
846
  const ie = document.createElement("span");
832
847
  ie.innerHTML = Pe, ie.style.cssText = `color:${t.accent ?? "#6c5ce7"};display:inline-flex`;
833
848
  const me = document.createElement("span");
834
- me.textContent = z.subtitle, O.append(ie, me), E.append(O);
849
+ me.textContent = L.subtitle, H.append(ie, me), E.append(H);
835
850
  }
836
- const U = document.createElement("button");
837
- U.type = "button", U.setAttribute("aria-label", "Dismiss"), U.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', U.style.cssText = "position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0", U.addEventListener("click", (O) => {
838
- O.stopPropagation();
851
+ const F = document.createElement("button");
852
+ F.type = "button", F.setAttribute("aria-label", "Dismiss"), F.innerHTML = '<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>', F.style.cssText = "position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0", F.addEventListener("click", (H) => {
853
+ H.stopPropagation();
839
854
  try {
840
855
  sessionStorage.setItem(te, "1");
841
856
  } catch {
842
857
  }
843
858
  E && (E.remove(), E = null);
844
- }), E.append(U);
859
+ }), E.append(F);
845
860
  const xe = () => {
846
- u || (u = !0, ne(!0), Q(), v = 0, C && (C.style.display = "none"), E && (E.remove(), E = null));
861
+ b || (b = !0, ne(!0), J(), d = 0, r && (r.style.display = "none"), E && (E.remove(), E = null));
847
862
  };
848
- E.addEventListener("click", xe), E.addEventListener("keydown", (O) => {
849
- (O.key === "Enter" || O.key === " ") && (O.preventDefault(), xe());
850
- }), r.insertBefore(E, q);
863
+ E.addEventListener("click", xe), E.addEventListener("keydown", (H) => {
864
+ (H.key === "Enter" || H.key === " ") && (H.preventDefault(), xe());
865
+ }), j.insertBefore(E, O);
851
866
  };
852
867
  if (!document.getElementById("ocw-teaser-style")) {
853
- const z = document.createElement("style");
854
- z.id = "ocw-teaser-style", z.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append(z);
868
+ const L = document.createElement("style");
869
+ L.id = "ocw-teaser-style", L.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append(L);
855
870
  }
856
- d = be, be();
857
- const ne = (z) => {
858
- z ? (m.style.display = "flex", requestAnimationFrame(() => {
859
- m.style.opacity = "1", m.style.transform = "scale(1)";
860
- })) : (m.style.opacity = "0", m.style.transform = "scale(.95)", setTimeout(() => {
861
- u || (m.style.display = "none");
871
+ z = be, be();
872
+ const ne = (L) => {
873
+ L ? (x.style.display = "flex", requestAnimationFrame(() => {
874
+ x.style.opacity = "1", x.style.transform = "scale(1)";
875
+ })) : (x.style.opacity = "0", x.style.transform = "scale(.95)", setTimeout(() => {
876
+ b || (x.style.display = "none");
862
877
  }, 180));
863
878
  };
864
- q.addEventListener("click", () => {
865
- if (u = !u, ne(u), Q(), u) {
866
- v = 0, C && (C.style.display = "none");
879
+ O.addEventListener("click", () => {
880
+ if (b = !b, ne(b), J(), b) {
881
+ d = 0, r && (r.style.display = "none");
867
882
  try {
868
883
  sessionStorage.setItem(te, "1");
869
884
  } catch {
870
885
  }
871
886
  }
872
- d == null || d();
873
- }), j = (z) => {
874
- z.key === "Escape" && u && (u = !1, ne(!1), Q());
875
- }, document.addEventListener("keydown", j);
887
+ z == null || z();
888
+ }), q = (L) => {
889
+ L.key === "Escape" && b && (b = !1, ne(!1), J());
890
+ }, document.addEventListener("keydown", q);
876
891
  }
877
- const f = () => {
878
- u || (v++, C && (C.textContent = String(v), C.style.display = "flex"));
879
- }, R = () => {
892
+ const k = () => {
893
+ b || (d++, r && (r.textContent = String(d), r.style.display = "flex"));
894
+ }, u = () => {
880
895
  try {
881
896
  const o = Je();
882
897
  if (!o) return;
883
898
  o.state === "suspended" && o.resume().catch(() => {
884
899
  });
885
- const s = o.createOscillator(), m = o.createGain();
886
- s.connect(m), m.connect(o.destination), s.frequency.setValueAtTime(880, o.currentTime), s.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), m.gain.setValueAtTime(0.3, o.currentTime), m.gain.exponentialRampToValueAtTime(1e-3, o.currentTime + 0.3), s.start(), s.stop(o.currentTime + 0.3);
900
+ const s = o.createOscillator(), x = o.createGain();
901
+ s.connect(x), x.connect(o.destination), s.frequency.setValueAtTime(880, o.currentTime), s.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), x.gain.setValueAtTime(0.3, o.currentTime), x.gain.exponentialRampToValueAtTime(1e-3, o.currentTime + 0.3), s.start(), s.stop(o.currentTime + 0.3);
887
902
  } catch {
888
903
  }
889
- }, B = [], A = (o) => {
890
- for (; B.length; ) {
891
- const s = B.shift();
892
- b.add({ clientMsgId: s.clientMsgId, content: s.content, ts: Date.now() }), k.send({ type: "send", conversationId: o, clientMsgId: s.clientMsgId, content: s.content });
904
+ }, g = [], $ = (o) => {
905
+ for (; g.length; ) {
906
+ const s = g.shift();
907
+ m.add({ clientMsgId: s.clientMsgId, content: s.content, ts: Date.now() }), y.send({ type: "send", conversationId: o, clientMsgId: s.clientMsgId, content: s.content });
893
908
  }
894
909
  };
895
- let k;
910
+ let y;
896
911
  const S = new He(`ocw-e2e-${t.profileId}`);
912
+ let N = !1;
913
+ const M = [], v = [];
897
914
  let D = !1;
898
- const g = [], N = [];
899
- let H = !1;
900
- const ee = (o, s) => {
901
- S.sealText(s).then((m) => {
902
- a && k.send({ type: "send", conversationId: a, clientMsgId: o, content: m });
915
+ const _ = (o, s) => {
916
+ S.sealText(s).then((x) => {
917
+ i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: x });
903
918
  });
904
- }, Ce = (o, s, m) => {
905
- S.sealText(s, m).then((L) => {
906
- a && k.send({ type: "send", conversationId: a, clientMsgId: o, content: L });
919
+ }, Ce = (o, s, x) => {
920
+ S.sealText(s, x).then((R) => {
921
+ i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: R });
907
922
  });
908
923
  }, Te = () => {
909
- for (; g.length; ) {
910
- const o = g.shift();
911
- ee(o.clientMsgId, o.text);
924
+ for (; M.length; ) {
925
+ const o = M.shift();
926
+ _(o.clientMsgId, o.text);
912
927
  }
913
- for (; N.length; ) {
914
- const o = N.shift();
915
- ee(o.clientMsgId, o.text);
928
+ for (; v.length; ) {
929
+ const o = v.shift();
930
+ _(o.clientMsgId, o.text);
916
931
  }
917
- }, Ie = (o) => {
918
- k.send({ type: "fetchPrekey", targetUserId: o });
919
- }, Se = t.i18n ?? {}, Ee = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
932
+ }, Se = (o) => {
933
+ y.send({ type: "fetchPrekey", targetUserId: o });
934
+ }, Ie = t.i18n ?? {}, Ee = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
920
935
  Ee.includes(ze) && !t.el.dir && (t.el.dir = "rtl", t.el.style.fontFamily = t.el.style.fontFamily || "Tahoma,Arial,system-ui,sans-serif");
921
- const re = `oc_prechat_${t.profileId}_${i.slice(-8)}`, $ = new Xe(t.el, i, {
936
+ const ce = `oc_prechat_${t.profileId}_${a.slice(-8)}`, A = new Xe(t.el, a, {
922
937
  onSend(o) {
923
- const s = `cm_${Math.random().toString(36).slice(2)}`, m = { kind: "text", text: o };
924
- p.addOptimistic(s, m), $.render(p), p.e2e ? S.ready ? ee(s, o) : H ? N.push({ clientMsgId: s, text: o }) : (g.push({ clientMsgId: s, text: o }), p.assignedAgentId && Ie(p.assignedAgentId)) : a ? (b.add({ clientMsgId: s, content: m, ts: Date.now() }), k.send({ type: "send", conversationId: a, clientMsgId: s, content: m })) : B.push({ clientMsgId: s, content: m });
938
+ const s = `cm_${Math.random().toString(36).slice(2)}`, x = { kind: "text", text: o };
939
+ p.addOptimistic(s, x), A.render(p), p.e2e ? S.ready ? _(s, o) : D ? v.push({ clientMsgId: s, text: o }) : (M.push({ clientMsgId: s, text: o }), p.assignedAgentId && Se(p.assignedAgentId)) : i ? (m.add({ clientMsgId: s, content: x, ts: Date.now() }), y.send({ type: "send", conversationId: i, clientMsgId: s, content: x })) : g.push({ clientMsgId: s, content: x });
925
940
  },
926
941
  async onAttach(o) {
927
- if (!a) return;
928
- const s = `${y}/upload?name=${encodeURIComponent(o.name)}`, m = `cm_${Math.random().toString(36).slice(2)}`;
929
- p.addOptimistic(m, { kind: "text", text: `๐Ÿ“Ž Uploading ${o.name}โ€ฆ` }), $.render(p);
942
+ if (!i) return;
943
+ const s = `${C}/upload?name=${encodeURIComponent(o.name)}`, x = `cm_${Math.random().toString(36).slice(2)}`;
944
+ p.addOptimistic(x, { kind: "text", text: `๐Ÿ“Ž Uploading ${o.name}โ€ฆ` }), A.render(p);
930
945
  try {
931
- const L = await fetch(s, {
946
+ const R = await fetch(s, {
932
947
  method: "POST",
933
948
  // Use the resolved connection token (a signed JWT, an explicit userId,
934
949
  // or the anonymous persistent uid) โ€” NOT just opts.token. The server
935
950
  // requires an Authorization header, and the verifier accepts an
936
951
  // anonymous id as a guest; keying off opts.token alone meant anonymous
937
952
  // visitors (the common case) sent no auth and every upload 401'd.
938
- headers: { "content-type": o.type, authorization: `Bearer ${i}` },
953
+ headers: { "content-type": o.type, authorization: `Bearer ${a}` },
939
954
  body: o
940
955
  });
941
- if (!L.ok) throw new Error(`Upload failed: ${L.status}`);
942
- const { url: W, name: G, mime: Y, size: X } = await L.json();
943
- p.addOptimistic(m, { kind: "attachment", url: W, name: G, mime: Y, size: X }), $.render(p), k.send({ type: "send", conversationId: a, clientMsgId: m, content: { kind: "attachment", url: W, name: G, mime: Y, size: X } });
944
- } catch (L) {
945
- p.addOptimistic(m, { kind: "text", text: `โš ๏ธ Upload failed: ${L.message}` }), $.render(p);
956
+ if (!R.ok) throw new Error(`Upload failed: ${R.status}`);
957
+ const { url: G, name: K, mime: X, size: Q } = await R.json();
958
+ p.addOptimistic(x, { kind: "attachment", url: G, name: K, mime: X, size: Q }), A.render(p), y.send({ type: "send", conversationId: i, clientMsgId: x, content: { kind: "attachment", url: G, name: K, mime: X, size: Q } });
959
+ } catch (R) {
960
+ p.addOptimistic(x, { kind: "text", text: `โš ๏ธ Upload failed: ${R.message}` }), A.render(p);
946
961
  }
947
962
  },
948
963
  onInvoke(o, s) {
949
- a && k.send({ type: "invoke", conversationId: a, actionId: o, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...s ? { inputs: s } : {} });
964
+ i && y.send({ type: "invoke", conversationId: i, actionId: o, clientInvokeId: `iv_${Math.random().toString(36).slice(2)}`, ...s ? { inputs: s } : {} });
950
965
  },
951
966
  onTyping(o, s) {
952
- a && k.send({ type: "typing", conversationId: a, isTyping: o, ...s ? { preview: s } : {} });
967
+ i && y.send({ type: "typing", conversationId: i, isTyping: o, ...s ? { preview: s } : {} });
953
968
  },
954
969
  onPreChat(o) {
955
970
  try {
956
- localStorage.setItem(re, "1");
971
+ localStorage.setItem(ce, "1");
957
972
  } catch {
958
973
  }
959
- k.send({
974
+ y.send({
960
975
  type: "open",
961
976
  profileId: t.profileId,
962
977
  ...t.subjectId ? { subjectId: t.subjectId } : {},
@@ -970,7 +985,7 @@ function at(t) {
970
985
  }
971
986
  });
972
987
  const s = o.callback ? `๐Ÿ“ž Call-back requested${o.phone ? `: ${o.phone}` : ""}${o.topic ? ` โ€” ${o.topic}` : ""}` : o.topic ? `Topic: ${o.topic}` : "";
973
- s && a && !p.e2e && k.send({ type: "send", conversationId: a, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: s } });
988
+ s && i && !p.e2e && y.send({ type: "send", conversationId: i, clientMsgId: `pc_${Math.random().toString(36).slice(2, 12)}`, content: { kind: "text", text: s } });
974
989
  },
975
990
  ...((le = t.features) == null ? void 0 : le.deflection) !== !1 ? {
976
991
  onDeflectQuery(o) {
@@ -978,38 +993,38 @@ function at(t) {
978
993
  clearTimeout(l);
979
994
  const s = o.trim();
980
995
  if (s.length < 3) {
981
- $.hideDeflection();
996
+ A.hideDeflection();
982
997
  return;
983
998
  }
984
999
  l = setTimeout(() => {
985
- fetch(`${y}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(s.slice(0, 200))}`).then((m) => m.ok ? m.json() : { articles: [] }).then((m) => $.showDeflection(m.articles ?? [])).catch(() => $.hideDeflection());
1000
+ fetch(`${C}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(s.slice(0, 200))}`).then((x) => x.ok ? x.json() : { articles: [] }).then((x) => A.showDeflection(x.articles ?? [])).catch(() => A.hideDeflection());
986
1001
  }, 350);
987
1002
  }
988
1003
  } : {},
989
1004
  onReadUpTo(o) {
990
- a && k.send({ type: "read", conversationId: a, seq: o });
1005
+ i && y.send({ type: "read", conversationId: i, seq: o });
991
1006
  },
992
1007
  onLoadMore() {
993
- if (!a || !p.e2e) return;
1008
+ if (!i || !p.e2e) return;
994
1009
  const o = p.messages()[0];
995
- o && k.send({ type: "history", conversationId: a, beforeSeq: o.seq, limit: 20 });
1010
+ o && y.send({ type: "history", conversationId: i, beforeSeq: o.seq, limit: 20 });
996
1011
  },
997
1012
  onEdit(o, s) {
998
- a && k.send({ type: "edit", conversationId: a, messageId: o, content: { kind: "text", text: s } });
1013
+ i && y.send({ type: "edit", conversationId: i, messageId: o, content: { kind: "text", text: s } });
999
1014
  },
1000
1015
  onDelete(o) {
1001
- a && k.send({ type: "delete", conversationId: a, messageId: o });
1016
+ i && y.send({ type: "delete", conversationId: i, messageId: o });
1002
1017
  },
1003
1018
  ...((de = t.features) == null ? void 0 : de.reactions) !== !1 ? {
1004
- onReact(o, s, m) {
1005
- a && k.send({ type: "react", conversationId: a, messageId: o, emoji: s, remove: m });
1019
+ onReact(o, s, x) {
1020
+ i && y.send({ type: "react", conversationId: i, messageId: o, emoji: s, remove: x });
1006
1021
  }
1007
1022
  } : {},
1008
1023
  ...((pe = t.features) == null ? void 0 : pe.csat) !== !1 ? {
1009
1024
  onCsat(o) {
1010
- a && fetch(`${y}/conversations/${a}/csat`, {
1025
+ i && fetch(`${C}/conversations/${i}/csat`, {
1011
1026
  method: "POST",
1012
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${i}` },
1027
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${a}` },
1013
1028
  body: JSON.stringify({ score: o })
1014
1029
  }).catch(() => {
1015
1030
  });
@@ -1018,14 +1033,14 @@ function at(t) {
1018
1033
  ...t.translateLang ? {
1019
1034
  async onTranslate(o) {
1020
1035
  try {
1021
- const s = await fetch(`${y}/translate`, {
1036
+ const s = await fetch(`${C}/translate`, {
1022
1037
  method: "POST",
1023
- headers: { "content-type": "application/json", authorization: `Bearer ${i}` },
1038
+ headers: { "content-type": "application/json", authorization: `Bearer ${a}` },
1024
1039
  body: JSON.stringify({ text: o, targetLang: t.translateLang })
1025
1040
  });
1026
1041
  if (!s.ok) return null;
1027
- const { translated: m } = await s.json();
1028
- return m;
1042
+ const { translated: x } = await s.json();
1043
+ return x;
1029
1044
  } catch {
1030
1045
  return null;
1031
1046
  }
@@ -1040,13 +1055,13 @@ function at(t) {
1040
1055
  ...t.theme ? { theme: t.theme } : {},
1041
1056
  ...t.webfont === !1 ? { webfont: !1 } : {},
1042
1057
  ...(he = t.user) != null && he.name || (ue = t.user) != null && ue.avatar ? { userInfo: { ...t.user.name ? { name: t.user.name } : {}, ...t.user.avatar ? { avatar: t.user.avatar } : {} } } : {},
1043
- i18n: Se
1058
+ i18n: Ie
1044
1059
  });
1045
1060
  try {
1046
- localStorage.getItem(re) && $.completePreChat();
1061
+ localStorage.getItem(ce) && A.completePreChat();
1047
1062
  } catch {
1048
1063
  }
1049
- const ce = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
1064
+ const re = t.user && (t.user.name || t.user.email || t.user.avatar || t.user.meta) ? {
1050
1065
  ...t.user.name ? { name: t.user.name } : {},
1051
1066
  ...t.user.email ? { email: t.user.email } : {},
1052
1067
  ...t.user.avatar ? { avatar: t.user.avatar } : {},
@@ -1058,8 +1073,8 @@ function at(t) {
1058
1073
  // server-derived and owner-keyed, so passing it as subjectId from the
1059
1074
  // NON-owner side would find-or-create a junk duplicate thread.
1060
1075
  ...t.kind === "direct" && t.peerId ? { kind: "direct", peerId: t.peerId } : t.subjectId ? { subjectId: t.subjectId } : {},
1061
- ...x ? { linkFrom: x } : {},
1062
- ...ce ? { userInfo: ce } : {},
1076
+ ...f ? { linkFrom: f } : {},
1077
+ ...re ? { userInfo: re } : {},
1063
1078
  ...typeof location < "u" ? { pageUrl: location.href } : {},
1064
1079
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
1065
1080
  // Pass subject display info so the server can persist it to the Subject record.
@@ -1067,27 +1082,27 @@ function at(t) {
1067
1082
  ...(fe = t.subject) != null && fe.title ? { subjectTitle: t.subject.title } : {},
1068
1083
  ...(we = t.subject) != null && we.subtitle ? { subjectMeta: t.subject.subtitle } : {}
1069
1084
  };
1070
- k = new De({
1085
+ y = new De({
1071
1086
  ...t.refreshToken ? { refreshToken: t.refreshToken } : {},
1072
1087
  url: w,
1073
- token: i,
1088
+ token: a,
1074
1089
  open: je,
1075
1090
  getCursor: () => p.highestSeq(),
1076
- onStatusChange: (o, s) => $.setConnStatus(o, s),
1091
+ onStatusChange: (o, s) => A.setConnStatus(o, s),
1077
1092
  onFrame(o) {
1078
1093
  if (o.type === "opened") {
1079
- if (a = o.conversation.id, !P) {
1094
+ if (i = o.conversation.id, !P) {
1080
1095
  P = !0;
1081
- for (const s of b.load())
1082
- k.send({ type: "send", conversationId: a, clientMsgId: s.clientMsgId, content: s.content });
1096
+ for (const s of m.load())
1097
+ y.send({ type: "send", conversationId: i, clientMsgId: s.clientMsgId, content: s.content });
1083
1098
  }
1084
- qe(w, i, a, p, $, y), B.length && A(a);
1099
+ Ae(w, a, i, p, A, C), g.length && $(i);
1085
1100
  }
1086
- if (o.type === "ack" && b.remove(o.clientMsgId), o.type === "prekeyBundle") {
1087
- o.bundle && (H = !0, S.x3dhSendTo(o.bundle).then((s) => {
1088
- const m = [...g.splice(0), ...N.splice(0)];
1089
- for (const L of m) Ce(L.clientMsgId, L.text, s);
1090
- $.render(p);
1101
+ if (o.type === "ack" && m.remove(o.clientMsgId), o.type === "prekeyBundle") {
1102
+ o.bundle && (D = !0, S.x3dhSendTo(o.bundle).then((s) => {
1103
+ const x = [...M.splice(0), ...v.splice(0)];
1104
+ for (const R of x) Ce(R.clientMsgId, R.text, s);
1105
+ A.render(p);
1091
1106
  }));
1092
1107
  return;
1093
1108
  }
@@ -1095,33 +1110,33 @@ function at(t) {
1095
1110
  const s = _e(o.message.content);
1096
1111
  if (s && !S.ready) {
1097
1112
  S.x3dhReceiveFrom(s.x3dhIK, s.x3dhEK, s.x3dhSPK, s.x3dhOTP).then(async () => {
1098
- await S.openFrame(o), p.apply(o), $.render(p);
1113
+ await S.openFrame(o), p.apply(o), A.render(p);
1099
1114
  });
1100
1115
  return;
1101
1116
  }
1102
1117
  }
1103
1118
  if (o.type === "peerkey") {
1104
1119
  S.onPeerKey(o.key).then(() => {
1105
- Te(), $.render(p);
1120
+ Te(), A.render(p);
1106
1121
  });
1107
1122
  return;
1108
1123
  }
1109
1124
  (async () => {
1110
- if (p.e2e && await S.openFrame(o), p.apply(o), o.type === "manifest" && (d == null || d()), o.type === "message" && o.message.senderId !== i && !o.message.internal && (f(), R()), p.e2e && a && !D) {
1111
- D = !0;
1125
+ if (p.e2e && await S.openFrame(o), p.apply(o), o.type === "manifest" && (z == null || z()), o.type === "message" && o.message.senderId !== a && !o.message.internal && (k(), u()), p.e2e && i && !N) {
1126
+ N = !0;
1112
1127
  const s = await S.initX3DH();
1113
- k.send({ type: "uploadPrekeys", ...s });
1114
- const m = await S.begin();
1115
- k.send({ type: "pubkey", conversationId: a, key: m });
1128
+ y.send({ type: "uploadPrekeys", ...s });
1129
+ const x = await S.begin();
1130
+ y.send({ type: "pubkey", conversationId: i, key: x });
1116
1131
  }
1117
- $.render(p);
1132
+ A.render(p);
1118
1133
  })();
1119
1134
  }
1120
- }), k.connect(), $.render(p);
1121
- const F = t.launcher ? ke(t) : null, V = { close: () => {
1122
- c = !0, clearTimeout(l), k.close(), r == null || r.remove(), $.destroy(), I && M && I.removeEventListener("change", M), j && (document.removeEventListener("keydown", j), j = null), _.delete(t.el), F && Z.get(F) === V && Z.delete(F);
1135
+ }), y.connect(), A.render(p);
1136
+ const W = t.launcher ? ke(t) : null, Y = { close: () => {
1137
+ c = !0, clearTimeout(l), y.close(), j == null || j.remove(), A.destroy(), B && I && B.removeEventListener("change", I), q && (document.removeEventListener("keydown", q), q = null), U.delete(t.el), W && ee.get(W) === Y && ee.delete(W);
1123
1138
  } };
1124
- return _.set(t.el, V), F && Z.set(F, V), V;
1139
+ return U.set(t.el, Y), W && ee.set(W, Y), Y;
1125
1140
  }
1126
1141
  export {
1127
1142
  Oe as ChatStore,
@@ -1133,8 +1148,8 @@ export {
1133
1148
  _e as extractX3DHInit,
1134
1149
  st as httpBaseFromWsUrl,
1135
1150
  at as mount,
1136
- Ae as resolveRelayUrls,
1137
- qe as restoreHistory,
1151
+ qe as resolveRelayUrls,
1152
+ Ae as restoreHistory,
1138
1153
  it as unmount
1139
1154
  };
1140
1155
  //# sourceMappingURL=index.js.map