@paramms/chat-widget 1.0.48 → 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";
@@ -274,59 +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 g, y, f, u, L, P, R, C, S, D, _;
277
+ var r, d, b, k, u, g, $, y, S, N, M;
278
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 x = a.accent2 ?? a.accent;
280
- x && e.style.setProperty("--ocw-accent2", x), this.cfgAccent2 = a.accent2, e.dataset.theme = a.theme ?? "light";
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
283
  const v = n("button", "ocw-back", "‹");
284
284
  v.type = "button", v.setAttribute("aria-label", "Back"), v.addEventListener("click", () => this.h.onBack()), w.append(v);
285
285
  }
286
- const m = ((g = a.subject) == null ? void 0 : g.ownerLabel) ?? ((y = a.subject) == null ? void 0 : y.title) ?? "", h = n("div", "ocw-avatar");
287
- m.trim() && (h.textContent = m.trim()[0].toUpperCase(), w.append(h));
288
- const p = n("div", "ocw-head-main");
289
- this.headerName = n("div", "ocw-head-name", ((f = a.subject) == null ? void 0 : f.ownerLabel) ?? ((u = a.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), (L = a.subject) != null && L.subtitle && p.append(n("div", "ocw-head-meta", a.subject.subtitle)), w.append(p), this.statusBadge = n("span", "ocw-badge", ((P = a.subject) == null ? void 0 : P.status) ?? ""), (R = a.subject) != null && R.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 k = n("div", "ocw-typing-bubble");
291
- k.append(n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot"), n("div", "ocw-typing-dot")), this.typing.append(k), this.quick = n("div", "ocw-quick");
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
292
  for (const v of a.quickReplies ?? []) {
293
- const N = n("button", void 0, v);
294
- N.addEventListener("click", () => {
293
+ const D = n("button", void 0, v);
294
+ D.addEventListener("click", () => {
295
295
  this.h.onSend(v), this.quick.style.display = "none";
296
- }), this.quick.append(N);
296
+ }), this.quick.append(D);
297
297
  }
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 = ((C = a.i18n) == null ? void 0 : C.placeholder) ?? "Message…";
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
299
  const i = n("button", "ocw-sendbtn");
300
300
  i.type = "button";
301
- const $ = (S = a.i18n) == null ? void 0 : S.send;
302
- $ ? (i.textContent = $, i.classList.add("ocw-sendbtn-label"), i.setAttribute("aria-label", $)) : (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, N;
304
- this.sendBtn.disabled = this.input.value.trim().length === 0, this.autoGrowInput(), this.storeRef && !this.storeRef.messages().some((H) => H.senderRole === "guest") ? (N = (v = this.h).onDeflectQuery) == null || N.call(v, this.input.value) : this.hideDeflection();
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
305
  }), this.input.addEventListener("keydown", (v) => {
306
306
  v.isComposing || v.keyCode === 229 || (v.key === "Enter" && !v.shiftKey ? (v.preventDefault(), this.flushSend()) : this.signalTyping());
307
307
  });
308
- const z = n("button", "ocw-attach", "📎");
309
- z.title = "Attach image or file";
308
+ const B = n("button", "ocw-attach", "📎");
309
+ B.title = "Attach image or file";
310
310
  const I = document.createElement("input");
311
- I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", z.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
311
+ I.type = "file", I.accept = "image/*,.pdf,.txt,.doc,.docx", I.style.display = "none", B.addEventListener("click", () => I.click()), I.addEventListener("change", () => {
312
312
  var v;
313
313
  (v = I.files) != null && v[0] && this.h.onAttach && this.h.onAttach(I.files[0]), I.value = "";
314
314
  });
315
- const M = n("div", "ocw-input");
316
- M.append(z, I, this.input, i);
317
- const d = n("div", "ocw-footer");
318
- ((D = a.i18n) == null ? void 0 : D.poweredBy) !== void 0 ? d.textContent = a.i18n.poweredBy : d.innerHTML = 'Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>', this.footer = d, this.reopenBtn = n("button", "ocw-reopen", ((_ = this.cfg.i18n) == null ? void 0 : _.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", () => {
319
319
  this.reopenBtn.style.display = "none";
320
320
  const v = this.root.querySelector(".ocw-input textarea");
321
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, M, this.reopenBtn, this.footer);
323
- const r = (v) => {
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
324
  e.classList.toggle("ocw-compact", v > 0 && v < We);
325
325
  };
326
- r(e.clientWidth), typeof ResizeObserver < "u" && (this.compactObserver = new ResizeObserver((v) => {
327
- var H;
328
- const N = ((H = v[0]) == null ? void 0 : H.contentRect.width) ?? e.clientWidth;
329
- r(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);
330
330
  }), this.compactObserver.observe(e));
331
331
  }
332
332
  /** Returns the scroll container so history.ts can attach scroll listeners. */
@@ -361,9 +361,9 @@ class Xe {
361
361
  this.h.onTyping(!0, e), this.typingTimer && clearTimeout(this.typingTimer), this.typingTimer = setTimeout(() => this.h.onTyping(!1), 2e3);
362
362
  }
363
363
  render(e) {
364
- var z, I, M, d, r, g, y, f;
364
+ var I, q, z, j, r, d, b, k;
365
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) {
366
- const u = (z = this.cfg.subject) == null ? void 0 : z.ownerLabel;
366
+ const u = (I = this.cfg.subject) == null ? void 0 : I.ownerLabel;
367
367
  u && (this.headerName.textContent = u);
368
368
  }
369
369
  this.quick.style.display = e.messages().length === 0 ? "flex" : "none", this.chips.replaceChildren();
@@ -375,33 +375,34 @@ class Xe {
375
375
  const u = n("div", "ocw-load-more");
376
376
  u.textContent = "↑ Loading earlier messages…", u.style.pointerEvents = "none", this.scroll.append(u);
377
377
  }
378
- let x = 0, w = null;
379
- for (const u of e.messages()) {
380
- const L = u.senderRole !== "system" && u.senderId !== this.me && !u.internal && u.senderId !== w;
381
- this.scroll.append(this.messageEl(u, e, L)), u.senderRole !== "system" && (w = u.senderId), u.senderId !== this.me && u.seq > x && (x = u.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);
382
383
  }
383
- a > 20 ? this.scroll.scrollTop = this.scroll.scrollHeight - c + a : this.scroll.scrollTop = this.scroll.scrollHeight, x > 0 && this.h.onReadUpTo(x);
384
- const m = [...e.typing];
385
- this.typing.classList.toggle("active", m.length > 0);
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);
386
387
  const h = this.typing.querySelector(".ocw-typing-bubble");
387
- h && h.setAttribute("aria-label", m.length ? "typing" : ""), this.footer.style.display = e.whiteLabel ? "none" : "block";
388
- const p = e.messages().some((u) => u.senderRole === "guest");
389
- if (!!((I = e.preChat) != null && I.enabled) && !this.preChatDone && !p && (e.preChat.showWhen !== "offline" || e.offline))
390
- this.preChatBuilt || this.buildPreChatPanel(e.preChat), this.preChatPanel.style.display = "block", this.awayNotice.style.display = "none", (M = this.root.querySelector(".ocw-input")) == null || M.style.setProperty("display", "none");
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");
391
392
  else {
392
393
  if (this.preChatPanel.style.display = "none", e.offline) {
393
394
  this.awayNotice.firstChild || this.awayNotice.append(n("span", "ocw-away-icon", "🌙"), n("span", "", ""));
394
395
  const u = this.awayNotice.lastChild;
395
- u.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";
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";
396
397
  } else
397
398
  this.awayNotice.style.display = "none";
398
399
  (r = this.root.querySelector(".ocw-input")) == null || r.style.removeProperty("display");
399
400
  }
400
- const i = ["resolved", "closed", "sold", "issued", "checked_out"];
401
- this.h.onCsat && !this.csatSubmitted && i.includes(e.state) && e.messages().length > 0 && (this.csatPanel.style.display === "none" && this.buildCsatPanel(), this.csatPanel.style.display = "block");
402
- const $ = i.includes(e.state);
403
- if (e.offline ? (this.headStatus.textContent = `● ${e.offlineMessage || ((g = this.cfg.i18n) == null ? void 0 : g.away) || "Away"}`, this.headStatus.className = "ocw-head-status away", this.headStatus.style.display = "") : e.conversationId ? (this.headStatus.textContent = `● ${((y = this.cfg.i18n) == null ? void 0 : y.online) ?? "Online"}`, this.headStatus.className = "ocw-head-status online", this.headStatus.style.display = "") : this.headStatus.style.display = "none", $ && e.messages().length > 0) {
404
- const u = n("div", "ocw-resolved-note", `— ${((f = this.cfg.i18n) == null ? void 0 : f.resolved) ?? "Marked as resolved"} —`);
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"} —`);
405
406
  this.scroll.append(u), this.reopenBtn.style.display = "block";
406
407
  } else
407
408
  this.reopenBtn.style.display = "none";
@@ -416,54 +417,54 @@ class Xe {
416
417
  this.connStatus.className = `ocw-conn-status${c ? " err" : e === "reconnecting" ? " warn" : ""}`, this.connStatus.textContent = c ? `⚠ ${l ?? "Chat unavailable"}` : e === "reconnecting" ? l ?? "↻ reconnecting…" : "● connecting…";
417
418
  }
418
419
  buildPreChatPanel(e) {
419
- var h;
420
+ var p;
420
421
  this.preChatBuilt = !0, this.preChatPanel.replaceChildren(), this.preChatPanel.append(n("div", "ocw-prechat-title", e.title ?? "Before we start…"));
421
422
  const l = n("div", "ocw-offline-form"), c = {};
422
- for (const p of e.fields ?? ["name", "email"]) {
423
- const k = n("input", "ocw-offline-input");
424
- k.type = p === "email" ? "email" : p === "phone" ? "tel" : "text", k.placeholder = p === "name" ? "Your name" : p === "email" ? "Your email" : "Your phone number", c[p] = k, l.append(k);
423
+ for (const h of e.fields ?? ["name", "email"]) {
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);
425
426
  }
426
427
  let a = null;
427
- if ((h = e.topics) != null && h.length) {
428
+ if ((p = e.topics) != null && p.length) {
428
429
  a = n("select", void 0);
429
- const p = document.createElement("option");
430
- p.value = "", p.textContent = "What is this about?", a.append(p);
431
- for (const k of e.topics) {
430
+ const h = document.createElement("option");
431
+ h.value = "", h.textContent = "What is this about?", a.append(h);
432
+ for (const m of e.topics) {
432
433
  const i = document.createElement("option");
433
- i.value = k, i.textContent = k, a.append(i);
434
+ i.value = m, i.textContent = m, a.append(i);
434
435
  }
435
436
  l.append(a);
436
437
  }
437
- let x = null, w = null;
438
+ let f = null, w = null;
438
439
  if (e.callbackOption) {
439
- const p = n("label", "ocw-prechat-cb");
440
- x = document.createElement("input"), x.type = "checkbox", p.append(x, document.createTextNode("📞 Request a call back")), l.append(p), 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));
440
+ const h = n("label", "ocw-prechat-cb");
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));
441
442
  }
442
- const m = n("button", "ocw-offline-submit", "Start chat");
443
- m.type = "button", m.addEventListener("click", () => {
444
- var $, z, I, M, d, r, g;
445
- const p = ($ = c.email) == null ? void 0 : $.value.trim();
446
- if (c.email && (!p || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p))) {
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;
446
+ const h = (P = c.email) == null ? void 0 : P.value.trim();
447
+ if (c.email && (!h || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h))) {
447
448
  c.email.focus();
448
449
  return;
449
450
  }
450
- const k = !!(x != null && x.checked), i = (((z = c.phone) == null ? void 0 : z.value) ?? (w == null ? void 0 : w.value) ?? "").trim();
451
- if (k && !i) {
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) {
452
453
  (I = c.phone ?? w) == null || I.focus();
453
454
  return;
454
455
  }
455
- if (a && ((M = e.topics) != null && M.length) && !a.value) {
456
+ if (a && ((q = e.topics) != null && q.length) && !a.value) {
456
457
  a.focus();
457
458
  return;
458
459
  }
459
- m.disabled = !0, this.completePreChat(), (g = (r = this.h).onPreChat) == null || g.call(r, {
460
- ...(d = c.name) != null && d.value.trim() ? { name: c.name.value.trim() } : {},
461
- ...p ? { email: p } : {},
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() } : {},
462
+ ...h ? { email: h } : {},
462
463
  ...i ? { phone: i } : {},
463
464
  ...a != null && a.value ? { topic: a.value } : {},
464
- ...k ? { callback: !0 } : {}
465
+ ...m ? { callback: !0 } : {}
465
466
  });
466
- }), l.append(m), this.preChatPanel.append(l);
467
+ }), l.append(C), this.preChatPanel.append(l);
467
468
  }
468
469
  /** Mark pre-chat complete (submitted now or in a previous session). */
469
470
  completePreChat() {
@@ -487,9 +488,9 @@ class Xe {
487
488
  const e = n("div", "ocw-csat-stars"), l = [];
488
489
  for (let c = 1; c <= 5; c++) {
489
490
  const a = n("button", "ocw-csat-star", "★");
490
- a.dataset.score = String(c), a.addEventListener("mouseenter", () => l.forEach((x, w) => x.classList.toggle("lit", w < c))), a.addEventListener("mouseleave", () => l.forEach((x) => x.classList.remove("lit"))), a.addEventListener("click", () => {
491
- var x, w;
492
- 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);
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);
493
494
  }), l.push(a), e.append(a);
494
495
  }
495
496
  this.csatPanel.append(e);
@@ -499,10 +500,10 @@ class Xe {
499
500
  const l = e.subject, c = this.cfg.subject, a = (l == null ? void 0 : l.title) ?? (c == null ? void 0 : c.title);
500
501
  if (!a) return;
501
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));
502
- const x = n("div", "ocw-tags");
503
- if (l) for (const [m, h] of Object.entries(l.fields)) x.append(n("span", "ocw-tag", `${m}: ${h}`));
504
- else for (const m of (c == null ? void 0 : c.tags) ?? []) x.append(n("span", "ocw-tag", m));
505
- x.childNodes.length && this.subjectCard.append(x);
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);
506
507
  const w = (l == null ? void 0 : l.state) ?? (c == null ? void 0 : c.status);
507
508
  w && (this.statusBadge.textContent = w, this.statusBadge.style.display = "inline-flex");
508
509
  }
@@ -518,191 +519,202 @@ class Xe {
518
519
  return new Promise((l) => {
519
520
  const c = n("div", "ocw-modal"), a = n("div", "ocw-modal-card");
520
521
  a.append(n("div", "ocw-modal-title", e)), a.append(n("div", "ocw-modal-body", `Confirm “${e}”?`));
521
- const x = n("div", "ocw-modal-actions"), w = n("button", "ocw-modal-cancel", "Cancel"), m = n("button", "ocw-modal-ok", "Confirm"), h = (p) => {
522
- c.remove(), l(p);
522
+ const f = n("div", "ocw-modal-actions"), w = n("button", "ocw-modal-cancel", "Cancel"), C = n("button", "ocw-modal-ok", "Confirm"), p = (h) => {
523
+ c.remove(), l(h);
523
524
  };
524
- w.addEventListener("click", () => h(!1)), m.addEventListener("click", () => h(!0)), c.addEventListener("click", (p) => {
525
- p.target === c && h(!1);
526
- }), x.append(w, m), a.append(x), c.append(a), this.root.append(c), m.focus();
525
+ w.addEventListener("click", () => p(!1)), C.addEventListener("click", () => p(!0)), c.addEventListener("click", (h) => {
526
+ h.target === c && p(!1);
527
+ }), f.append(w, C), a.append(f), c.append(a), this.root.append(c), C.focus();
527
528
  });
528
529
  }
529
530
  /** Inline form for a form-effect action: typed inputs (date picker, number,
530
531
  * text) rendered above the composer — no browser prompts. */
531
532
  openForm(e) {
532
- var m, h;
533
+ var C, p;
533
534
  this.formHost.replaceChildren();
534
535
  const l = n("div", "ocw-form");
535
536
  l.append(n("div", "ocw-form-title", e.icon ? `${e.icon} ${e.label}` : e.label));
536
537
  const c = /* @__PURE__ */ new Map();
537
- for (const p of e.input ?? []) {
538
- const k = n("label", "ocw-form-row");
539
- if (k.append(n("span", "ocw-form-lbl", p.label)), p.type === "select" && ((m = p.options) != null && m.length)) {
538
+ for (const h of e.input ?? []) {
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)) {
540
541
  const i = n("select", "ocw-form-input");
541
- p.required || i.append(n("option", void 0, "— select —"));
542
- for (const $ of p.options) {
543
- const z = n("option");
544
- z.value = $, z.textContent = $, i.append(z);
542
+ h.required || i.append(n("option", void 0, "— select —"));
543
+ for (const P of h.options) {
544
+ const B = n("option");
545
+ B.value = P, B.textContent = P, i.append(B);
545
546
  }
546
- p.required && (i.required = !0), k.append(i), c.set(p.name, i);
547
+ h.required && (i.required = !0), m.append(i), c.set(h.name, i);
547
548
  } else {
548
549
  const i = n("input", "ocw-form-input");
549
- i.type = p.type === "number" ? "number" : p.type === "date" ? "datetime-local" : "text", p.required && (i.required = !0), k.append(i), c.set(p.name, i);
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);
550
551
  }
551
- l.append(k);
552
+ l.append(m);
552
553
  }
553
- const a = n("div", "ocw-form-actions"), x = n("button", "ocw-form-cancel", "Cancel"), w = n("button", "ocw-form-submit", "Send");
554
- x.addEventListener("click", () => this.formHost.replaceChildren()), w.addEventListener("click", () => {
555
- const p = {};
556
- for (const [k, i] of c) {
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", () => {
556
+ const h = {};
557
+ for (const [m, i] of c) {
557
558
  if (i.required && !i.value) {
558
559
  i.style.borderColor = "#e5484d";
559
560
  return;
560
561
  }
561
- p[k] = i.type === "number" ? Number(i.value) : i.value;
562
+ h[m] = i.type === "number" ? Number(i.value) : i.value;
562
563
  }
563
- this.formHost.replaceChildren(), this.h.onInvoke(e.id, p);
564
- }), a.append(x, w), l.append(a), this.formHost.append(l), (h = c.values().next().value) == null || h.focus();
564
+ this.formHost.replaceChildren(), this.h.onInvoke(e.id, h);
565
+ }), a.append(f, w), l.append(a), this.formHost.append(l), (p = c.values().next().value) == null || p.focus();
565
566
  }
566
- messageEl(e, l, c = !1) {
567
- var $, z, I, M;
567
+ messageEl(e, l, c = !1, a = !1) {
568
+ var B, I, q, z, j;
568
569
  if (e.senderRole === "system") {
569
- const d = n("div", "ocw-sys");
570
- 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;
571
572
  }
572
- const a = e.senderId === this.me, x = !!e.internal, w = n("div", `ocw-row ${x ? "ocw-note mine" : a ? "mine" : "theirs"} ${e.senderRole === "bot" ? "ocw-bot" : ""}`), m = 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");
573
574
  if (c) {
574
- const d = e.senderRole === "bot" ? (($ = this.cfg.i18n) == null ? void 0 : $.aiAssistant) ?? "AI Assistant" : ((z = this.cfg.subject) == null ? void 0 : z.ownerLabel) ?? ((I = this.cfg.subject) == null ? void 0 : I.title) ?? "Support";
575
- m.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));
576
577
  }
577
578
  const h = n("div", "ocw-bubble-wrap");
578
579
  if (e.replyToId) {
579
- const d = n("div", "ocw-reply-to", "↩ replying to a message");
580
- d.style.cssText = "font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic", m.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);
581
582
  }
582
- const p = n("div", "ocw-bubble");
583
- let k = null;
584
- if (e.deletedAt) p.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"));
585
586
  else if (e.content.kind === "attachment") {
586
- const d = e.content;
587
- if ((M = d.mime) != null && M.startsWith("image/")) {
588
- const r = document.createElement("img");
589
- 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")), p.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);
590
591
  } else {
591
- const r = document.createElement("a");
592
- 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")), p.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);
593
594
  }
594
595
  } else if (e.content.kind === "appointment") {
595
- const d = e.content, r = n("div", "ocw-appt");
596
- 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));
597
- const g = n("div", "ocw-appt-links"), y = document.createElement("a");
598
- y.href = d.googleUrl, y.target = "_blank", y.rel = "noopener", y.className = "ocw-appt-btn", y.textContent = "📅 Add to Google Calendar";
599
- const f = document.createElement("a");
600
- f.href = d.icalUrl, f.download = `${d.title}.ics`, f.className = "ocw-appt-btn ocw-appt-btn-sec", f.textContent = "🍎 Apple / iCal", g.append(y, f), r.append(g), p.append(r);
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";
600
+ const u = document.createElement("a");
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);
601
602
  } else
602
- k = document.createTextNode(ae(e.content)), p.append(k), e.editedAt && p.append(n("span", "ocw-edited", "(edited)"));
603
- if (h.append(p), !a && !x && this.h.onTranslate && e.content.kind === "text" && !e.deletedAt && e.seq > 0 && k) {
604
- const d = e.content.text;
605
- if (d.trim()) {
606
- const r = n("button", "ocw-translate-btn", "🌐");
607
- r.type = "button", r.title = "Translate";
608
- const g = n("div", "ocw-translation");
609
- g.style.display = "none", p.append(g);
610
- const y = (L) => {
611
- g.textContent = L, g.style.display = "", this.showingTranslation.add(e.id), r.textContent = "↩", r.title = "Show original";
612
- }, f = () => {
613
- g.style.display = "none", this.showingTranslation.delete(e.id), 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";
614
626
  };
615
- r.addEventListener("click", (L) => {
616
- if (L.stopPropagation(), this.showingTranslation.has(e.id)) {
617
- f();
627
+ d.addEventListener("click", ($) => {
628
+ if ($.stopPropagation(), this.showingTranslation.has(e.id)) {
629
+ u();
618
630
  return;
619
631
  }
620
- const P = this.translationCache.get(e.id);
621
- if (P !== void 0) {
622
- y(P);
632
+ const y = this.translationCache.get(e.id);
633
+ if (y !== void 0) {
634
+ k(y);
623
635
  return;
624
636
  }
625
- r.textContent = "⏳", this.h.onTranslate(d).then((R) => {
626
- if (R === null) {
627
- r.textContent = "⚠️", r.title = "Translation unavailable", setTimeout(() => {
628
- 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";
629
641
  }, 1500);
630
642
  return;
631
643
  }
632
- this.translationCache.set(e.id, R), y(R);
644
+ this.translationCache.set(e.id, S), k(S);
633
645
  });
634
- }), h.append(r);
635
- const u = this.translationCache.get(e.id);
636
- this.showingTranslation.has(e.id) && u !== void 0 && y(u);
646
+ }), h.append(d);
647
+ const g = this.translationCache.get(e.id);
648
+ this.showingTranslation.has(e.id) && g !== void 0 && k(g);
637
649
  }
638
650
  }
639
- if (a && !e.deletedAt && e.seq > 0 && (this.h.onEdit ?? this.h.onDelete)) {
640
- 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");
641
653
  if (this.h.onEdit) {
642
- const r = n("button", void 0, "✏️");
643
- r.title = "Edit", r.addEventListener("click", (g) => {
644
- g.stopPropagation();
645
- const y = ae(e.content), f = document.createElement("textarea");
646
- f.value = y, f.rows = Math.min(4, Math.ceil(y.length / 40) + 1), f.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";
647
- const u = n("button", "ocw-form-submit", "Save");
648
- u.style.cssText = "margin-top:6px;padding:5px 14px;font-size:13px";
649
- const L = n("button", "ocw-form-cancel", "Cancel");
650
- L.style.cssText = "margin-top:6px;padding:5px 10px;font-size:13px";
651
- const P = n("div");
652
- P.style.cssText = "display:flex;gap:6px;justify-content:flex-end", P.append(L, u);
653
- const R = n("div");
654
- R.append(f, P), p.replaceChildren(R), f.focus(), f.select();
655
- const C = () => p.replaceChildren(k ?? document.createTextNode(y));
656
- L.addEventListener("click", C), u.addEventListener("click", () => {
657
- const S = f.value.trim();
658
- S && S !== y && this.h.onEdit(e.id, S), C();
659
- }), f.addEventListener("keydown", (S) => {
660
- S.key === "Enter" && !S.shiftKey && (S.preventDefault(), u.click()), S.key === "Escape" && C();
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();
661
673
  });
662
- }), d.append(r);
674
+ }), r.append(d);
663
675
  }
664
676
  if (this.h.onDelete) {
665
- const r = n("button", "del", "🗑");
666
- r.title = "Delete", r.addEventListener("click", (g) => {
667
- g.stopPropagation(), this.h.onDelete(e.id);
668
- }), 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);
669
681
  }
670
- h.append(d);
682
+ h.append(r);
671
683
  }
672
- if (m.append(h), this.h.onReact && !e.deletedAt && e.seq > 0) {
673
- 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");
674
686
  if (e.reactions && Object.keys(e.reactions).length)
675
- for (const [f, u] of Object.entries(e.reactions)) {
676
- const L = n("button", `ocw-react-pill${u.includes(this.me) ? " mine" : ""}`, `${f} ${u.length}`);
677
- L.addEventListener("click", () => {
678
- var P, R;
679
- return (R = (P = this.h).onReact) == null ? void 0 : R.call(P, e.id, f, u.includes(this.me));
680
- }), r.append(L);
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($);
681
693
  }
682
- const g = n("button", "ocw-react-btn", "+"), y = n("div", "ocw-react-picker");
683
- for (const f of Fe) {
684
- const u = n("button", void 0, f);
685
- u.addEventListener("click", (L) => {
686
- var R, C, S, D;
687
- L.stopPropagation();
688
- const P = (C = (R = e.reactions) == null ? void 0 : R[f]) == null ? void 0 : C.includes(this.me);
689
- (D = (S = this.h).onReact) == null || D.call(S, e.id, f, !!P), y.style.display = "none";
690
- }), y.append(u);
694
+ const b = n("button", "ocw-react-btn", "+"), k = n("div", "ocw-react-picker");
695
+ for (const u of Fe) {
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);
691
703
  }
692
- y.style.display = "none", g.addEventListener("click", (f) => {
693
- f.stopPropagation();
694
- const u = y.style.display === "none";
695
- y.style.display = u ? "flex" : "none", u && document.addEventListener("click", () => {
696
- y.style.display = "none";
704
+ k.style.display = "none", b.addEventListener("click", (u) => {
705
+ u.stopPropagation();
706
+ const g = k.style.display === "none";
707
+ k.style.display = g ? "flex" : "none", g && document.addEventListener("click", () => {
708
+ k.style.display = "none";
697
709
  }, { once: !0 });
698
- }), r.append(g), d.append(r, y), m.append(d);
699
- } else e.reactions && Object.keys(e.reactions).length && m.append(n("div", "ocw-react", Object.entries(e.reactions).map(([d, r]) => `${d}${r.length}`).join(" ")));
700
- const i = n("div", "ocw-time ocw-meta", Ye(e.ts));
701
- if (a && e.status) {
702
- const d = n("span", `ocw-tick${e.status === "read" ? " read" : e.status === "delivered" ? " delivered" : ""}`, Qe(e.status));
703
- i.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);
704
716
  }
705
- return a && e.seq > 0 && l.lastReadByOthers >= e.seq && i.append(n("span", "ocw-seen", " · Seen")), m.append(i), w.append(m), 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;
706
718
  }
707
719
  }
708
720
  function Qe(t) {
@@ -739,18 +751,18 @@ function at(t) {
739
751
  U.has(t.el) && (U.get(t.el).close(), U.delete(t.el)), t.launcher && ((se = ee.get(ke(t))) == null || se.close());
740
752
  const e = Re();
741
753
  let l, c = !1;
742
- const a = t.token ?? t.userId ?? e, x = a !== e ? e : void 0, { wsUrl: w, httpBase: m } = Ae(t.url, t.apiUrl);
743
- let h = new Oe(a);
744
- const p = t.subjectId ? `${a}::${t.subjectId}` : a, k = new Ne(p);
745
- let i, $ = !1, z = null, I = null, M = 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;
746
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");
747
- for (const o of k.load()) h.addOptimistic(o.clientMsgId, o.content);
748
- let r = null, g = null, y = 0, f = !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;
749
761
  if (t.launcher) {
750
762
  const s = (t.position ?? "bottom-right").includes("right");
751
- 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`;
752
- const b = document.createElement("div"), B = typeof window < "u" && typeof window.matchMedia == "function" ? window.matchMedia("(max-width: 479px)") : null, G = (j) => {
753
- t.el.classList.toggle("ocw-fs", j), b.style.cssText = j ? [
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 ? [
754
766
  "position:fixed",
755
767
  "inset:0",
756
768
  "width:100%",
@@ -779,11 +791,11 @@ function at(t) {
779
791
  "transform:scale(.95)"
780
792
  ].join(";");
781
793
  };
782
- G((B == null ? void 0 : B.matches) ?? !1);
783
- const K = (j) => G(j.matches);
784
- B == null || B.addEventListener("change", K), z = B, I = K, t.el.style.cssText = "width:100%;height:100%;overflow:hidden", b.append(t.el);
785
- 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>', q = document.createElement("button");
786
- 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 = [
787
799
  "width:56px;height:56px;border-radius:50%",
788
800
  `background:${t.accent ?? "#6c5ce7"}`,
789
801
  "color:#fff;border:none;cursor:pointer",
@@ -791,15 +803,15 @@ function at(t) {
791
803
  "position:relative;flex:none",
792
804
  "display:flex;align-items:center;justify-content:center",
793
805
  "transition:transform .15s"
794
- ].join(";"), q.onmouseenter = () => {
795
- q.style.transform = "scale(1.08)";
796
- }, q.onmouseleave = () => {
797
- q.style.transform = "scale(1)";
798
- }, g = document.createElement("span"), g.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";
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";
799
811
  const J = () => {
800
- q.innerHTML = f ? Q : X, q.setAttribute("aria-label", f ? "Close chat" : "Open chat"), q.setAttribute("aria-expanded", String(f)), q.append(g);
812
+ O.innerHTML = b ? Q : X, O.setAttribute("aria-label", b ? "Close chat" : "Open chat"), O.setAttribute("aria-expanded", String(b)), O.append(r);
801
813
  };
802
- J(), r.append(b, q), document.body.append(r);
814
+ J(), j.append(x, O), document.body.append(j);
803
815
  const te = `ocw-teaser-dismissed::${t.profileId}`, Z = typeof t.launcherMessage == "string" ? { title: t.launcherMessage } : t.launcherMessage;
804
816
  let E = null;
805
817
  const Le = () => {
@@ -809,13 +821,13 @@ function at(t) {
809
821
  return !1;
810
822
  }
811
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 = () => {
812
- const j = Z != null && Z.title ? Z : h.launcherMessage ?? void 0;
813
- if (!(!!(j != null && j.title) && !f && !Le())) {
824
+ const L = Z != null && Z.title ? Z : p.launcherMessage ?? void 0;
825
+ if (!(!!(L != null && L.title) && !b && !Le())) {
814
826
  E && (E.remove(), E = null);
815
827
  return;
816
828
  }
817
829
  if (E) return;
818
- E = document.createElement("div"), E.setAttribute("role", "button"), E.setAttribute("tabindex", "0"), E.setAttribute("aria-label", j.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 = [
819
831
  "max-width:280px",
820
832
  "background:#fff",
821
833
  "border-radius:16px",
@@ -828,17 +840,17 @@ function at(t) {
828
840
  "animation:ocw-teaser-in .22s ease-out"
829
841
  ].join(";");
830
842
  const oe = document.createElement("div");
831
- if (oe.textContent = j.title, oe.style.cssText = "font-size:15px;font-weight:600;color:#111;line-height:1.35", E.append(oe), j.subtitle) {
832
- const O = document.createElement("div");
833
- 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";
834
846
  const ie = document.createElement("span");
835
847
  ie.innerHTML = Pe, ie.style.cssText = `color:${t.accent ?? "#6c5ce7"};display:inline-flex`;
836
848
  const me = document.createElement("span");
837
- me.textContent = j.subtitle, O.append(ie, me), E.append(O);
849
+ me.textContent = L.subtitle, H.append(ie, me), E.append(H);
838
850
  }
839
851
  const F = document.createElement("button");
840
- 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", (O) => {
841
- O.stopPropagation();
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();
842
854
  try {
843
855
  sessionStorage.setItem(te, "1");
844
856
  } catch {
@@ -846,92 +858,92 @@ function at(t) {
846
858
  E && (E.remove(), E = null);
847
859
  }), E.append(F);
848
860
  const xe = () => {
849
- f || (f = !0, ne(!0), J(), y = 0, g && (g.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));
850
862
  };
851
- E.addEventListener("click", xe), E.addEventListener("keydown", (O) => {
852
- (O.key === "Enter" || O.key === " ") && (O.preventDefault(), xe());
853
- }), 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);
854
866
  };
855
867
  if (!document.getElementById("ocw-teaser-style")) {
856
- const j = document.createElement("style");
857
- j.id = "ocw-teaser-style", j.textContent = "@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}", document.head.append(j);
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);
858
870
  }
859
- d = be, be();
860
- const ne = (j) => {
861
- j ? (b.style.display = "flex", requestAnimationFrame(() => {
862
- b.style.opacity = "1", b.style.transform = "scale(1)";
863
- })) : (b.style.opacity = "0", b.style.transform = "scale(.95)", setTimeout(() => {
864
- f || (b.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");
865
877
  }, 180));
866
878
  };
867
- q.addEventListener("click", () => {
868
- if (f = !f, ne(f), J(), f) {
869
- y = 0, g && (g.style.display = "none");
879
+ O.addEventListener("click", () => {
880
+ if (b = !b, ne(b), J(), b) {
881
+ d = 0, r && (r.style.display = "none");
870
882
  try {
871
883
  sessionStorage.setItem(te, "1");
872
884
  } catch {
873
885
  }
874
886
  }
875
- d == null || d();
876
- }), M = (j) => {
877
- j.key === "Escape" && f && (f = !1, ne(!1), J());
878
- }, document.addEventListener("keydown", M);
887
+ z == null || z();
888
+ }), q = (L) => {
889
+ L.key === "Escape" && b && (b = !1, ne(!1), J());
890
+ }, document.addEventListener("keydown", q);
879
891
  }
880
- const u = () => {
881
- f || (y++, g && (g.textContent = String(y), g.style.display = "flex"));
882
- }, L = () => {
892
+ const k = () => {
893
+ b || (d++, r && (r.textContent = String(d), r.style.display = "flex"));
894
+ }, u = () => {
883
895
  try {
884
896
  const o = Je();
885
897
  if (!o) return;
886
898
  o.state === "suspended" && o.resume().catch(() => {
887
899
  });
888
- const s = o.createOscillator(), b = o.createGain();
889
- s.connect(b), b.connect(o.destination), s.frequency.setValueAtTime(880, o.currentTime), s.frequency.exponentialRampToValueAtTime(440, o.currentTime + 0.15), b.gain.setValueAtTime(0.3, o.currentTime), b.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);
890
902
  } catch {
891
903
  }
892
- }, P = [], R = (o) => {
893
- for (; P.length; ) {
894
- const s = P.shift();
895
- k.add({ clientMsgId: s.clientMsgId, content: s.content, ts: Date.now() }), C.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 });
896
908
  }
897
909
  };
898
- let C;
910
+ let y;
899
911
  const S = new He(`ocw-e2e-${t.profileId}`);
900
- let D = !1;
901
- const _ = [], v = [];
902
912
  let N = !1;
903
- const H = (o, s) => {
904
- S.sealText(s).then((b) => {
905
- i && C.send({ type: "send", conversationId: i, clientMsgId: o, content: b });
913
+ const M = [], v = [];
914
+ let D = !1;
915
+ const _ = (o, s) => {
916
+ S.sealText(s).then((x) => {
917
+ i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: x });
906
918
  });
907
- }, Ce = (o, s, b) => {
908
- S.sealText(s, b).then((B) => {
909
- i && C.send({ type: "send", conversationId: i, clientMsgId: o, content: B });
919
+ }, Ce = (o, s, x) => {
920
+ S.sealText(s, x).then((R) => {
921
+ i && y.send({ type: "send", conversationId: i, clientMsgId: o, content: R });
910
922
  });
911
923
  }, Te = () => {
912
- for (; _.length; ) {
913
- const o = _.shift();
914
- H(o.clientMsgId, o.text);
924
+ for (; M.length; ) {
925
+ const o = M.shift();
926
+ _(o.clientMsgId, o.text);
915
927
  }
916
928
  for (; v.length; ) {
917
929
  const o = v.shift();
918
- H(o.clientMsgId, o.text);
930
+ _(o.clientMsgId, o.text);
919
931
  }
920
932
  }, Se = (o) => {
921
- C.send({ type: "fetchPrekey", targetUserId: o });
933
+ y.send({ type: "fetchPrekey", targetUserId: o });
922
934
  }, Ie = t.i18n ?? {}, Ee = ["ar", "he", "fa", "ur"], ze = typeof navigator < "u" ? (navigator.language ?? "").slice(0, 2).toLowerCase() : "";
923
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");
924
936
  const ce = `oc_prechat_${t.profileId}_${a.slice(-8)}`, A = new Xe(t.el, a, {
925
937
  onSend(o) {
926
- const s = `cm_${Math.random().toString(36).slice(2)}`, b = { kind: "text", text: o };
927
- h.addOptimistic(s, b), A.render(h), h.e2e ? S.ready ? H(s, o) : N ? v.push({ clientMsgId: s, text: o }) : (_.push({ clientMsgId: s, text: o }), h.assignedAgentId && Se(h.assignedAgentId)) : i ? (k.add({ clientMsgId: s, content: b, ts: Date.now() }), C.send({ type: "send", conversationId: i, clientMsgId: s, content: b })) : P.push({ clientMsgId: s, content: b });
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 });
928
940
  },
929
941
  async onAttach(o) {
930
942
  if (!i) return;
931
- const s = `${m}/upload?name=${encodeURIComponent(o.name)}`, b = `cm_${Math.random().toString(36).slice(2)}`;
932
- h.addOptimistic(b, { kind: "text", text: `📎 Uploading ${o.name}…` }), A.render(h);
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);
933
945
  try {
934
- const B = await fetch(s, {
946
+ const R = await fetch(s, {
935
947
  method: "POST",
936
948
  // Use the resolved connection token (a signed JWT, an explicit userId,
937
949
  // or the anonymous persistent uid) — NOT just opts.token. The server
@@ -941,25 +953,25 @@ function at(t) {
941
953
  headers: { "content-type": o.type, authorization: `Bearer ${a}` },
942
954
  body: o
943
955
  });
944
- if (!B.ok) throw new Error(`Upload failed: ${B.status}`);
945
- const { url: G, name: K, mime: X, size: Q } = await B.json();
946
- h.addOptimistic(b, { kind: "attachment", url: G, name: K, mime: X, size: Q }), A.render(h), C.send({ type: "send", conversationId: i, clientMsgId: b, content: { kind: "attachment", url: G, name: K, mime: X, size: Q } });
947
- } catch (B) {
948
- h.addOptimistic(b, { kind: "text", text: `⚠️ Upload failed: ${B.message}` }), A.render(h);
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);
949
961
  }
950
962
  },
951
963
  onInvoke(o, s) {
952
- i && C.send({ type: "invoke", conversationId: i, 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 } : {} });
953
965
  },
954
966
  onTyping(o, s) {
955
- i && C.send({ type: "typing", conversationId: i, isTyping: o, ...s ? { preview: s } : {} });
967
+ i && y.send({ type: "typing", conversationId: i, isTyping: o, ...s ? { preview: s } : {} });
956
968
  },
957
969
  onPreChat(o) {
958
970
  try {
959
971
  localStorage.setItem(ce, "1");
960
972
  } catch {
961
973
  }
962
- C.send({
974
+ y.send({
963
975
  type: "open",
964
976
  profileId: t.profileId,
965
977
  ...t.subjectId ? { subjectId: t.subjectId } : {},
@@ -973,7 +985,7 @@ function at(t) {
973
985
  }
974
986
  });
975
987
  const s = o.callback ? `📞 Call-back requested${o.phone ? `: ${o.phone}` : ""}${o.topic ? ` — ${o.topic}` : ""}` : o.topic ? `Topic: ${o.topic}` : "";
976
- s && i && !h.e2e && C.send({ type: "send", conversationId: i, 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 } });
977
989
  },
978
990
  ...((le = t.features) == null ? void 0 : le.deflection) !== !1 ? {
979
991
  onDeflectQuery(o) {
@@ -985,32 +997,32 @@ function at(t) {
985
997
  return;
986
998
  }
987
999
  l = setTimeout(() => {
988
- fetch(`${m}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(s.slice(0, 200))}`).then((b) => b.ok ? b.json() : { articles: [] }).then((b) => A.showDeflection(b.articles ?? [])).catch(() => A.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());
989
1001
  }, 350);
990
1002
  }
991
1003
  } : {},
992
1004
  onReadUpTo(o) {
993
- i && C.send({ type: "read", conversationId: i, seq: o });
1005
+ i && y.send({ type: "read", conversationId: i, seq: o });
994
1006
  },
995
1007
  onLoadMore() {
996
- if (!i || !h.e2e) return;
997
- const o = h.messages()[0];
998
- o && C.send({ type: "history", conversationId: i, beforeSeq: o.seq, limit: 20 });
1008
+ if (!i || !p.e2e) return;
1009
+ const o = p.messages()[0];
1010
+ o && y.send({ type: "history", conversationId: i, beforeSeq: o.seq, limit: 20 });
999
1011
  },
1000
1012
  onEdit(o, s) {
1001
- i && C.send({ type: "edit", conversationId: i, messageId: o, content: { kind: "text", text: s } });
1013
+ i && y.send({ type: "edit", conversationId: i, messageId: o, content: { kind: "text", text: s } });
1002
1014
  },
1003
1015
  onDelete(o) {
1004
- i && C.send({ type: "delete", conversationId: i, messageId: o });
1016
+ i && y.send({ type: "delete", conversationId: i, messageId: o });
1005
1017
  },
1006
1018
  ...((de = t.features) == null ? void 0 : de.reactions) !== !1 ? {
1007
- onReact(o, s, b) {
1008
- i && C.send({ type: "react", conversationId: i, messageId: o, emoji: s, remove: b });
1019
+ onReact(o, s, x) {
1020
+ i && y.send({ type: "react", conversationId: i, messageId: o, emoji: s, remove: x });
1009
1021
  }
1010
1022
  } : {},
1011
1023
  ...((pe = t.features) == null ? void 0 : pe.csat) !== !1 ? {
1012
1024
  onCsat(o) {
1013
- i && fetch(`${m}/conversations/${i}/csat`, {
1025
+ i && fetch(`${C}/conversations/${i}/csat`, {
1014
1026
  method: "POST",
1015
1027
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${a}` },
1016
1028
  body: JSON.stringify({ score: o })
@@ -1021,14 +1033,14 @@ function at(t) {
1021
1033
  ...t.translateLang ? {
1022
1034
  async onTranslate(o) {
1023
1035
  try {
1024
- const s = await fetch(`${m}/translate`, {
1036
+ const s = await fetch(`${C}/translate`, {
1025
1037
  method: "POST",
1026
1038
  headers: { "content-type": "application/json", authorization: `Bearer ${a}` },
1027
1039
  body: JSON.stringify({ text: o, targetLang: t.translateLang })
1028
1040
  });
1029
1041
  if (!s.ok) return null;
1030
- const { translated: b } = await s.json();
1031
- return b;
1042
+ const { translated: x } = await s.json();
1043
+ return x;
1032
1044
  } catch {
1033
1045
  return null;
1034
1046
  }
@@ -1061,7 +1073,7 @@ function at(t) {
1061
1073
  // server-derived and owner-keyed, so passing it as subjectId from the
1062
1074
  // NON-owner side would find-or-create a junk duplicate thread.
1063
1075
  ...t.kind === "direct" && t.peerId ? { kind: "direct", peerId: t.peerId } : t.subjectId ? { subjectId: t.subjectId } : {},
1064
- ...x ? { linkFrom: x } : {},
1076
+ ...f ? { linkFrom: f } : {},
1065
1077
  ...re ? { userInfo: re } : {},
1066
1078
  ...typeof location < "u" ? { pageUrl: location.href } : {},
1067
1079
  ...typeof document < "u" && document.title ? { pageTitle: document.title } : {},
@@ -1070,59 +1082,59 @@ function at(t) {
1070
1082
  ...(fe = t.subject) != null && fe.title ? { subjectTitle: t.subject.title } : {},
1071
1083
  ...(we = t.subject) != null && we.subtitle ? { subjectMeta: t.subject.subtitle } : {}
1072
1084
  };
1073
- C = new De({
1085
+ y = new De({
1074
1086
  ...t.refreshToken ? { refreshToken: t.refreshToken } : {},
1075
1087
  url: w,
1076
1088
  token: a,
1077
1089
  open: je,
1078
- getCursor: () => h.highestSeq(),
1090
+ getCursor: () => p.highestSeq(),
1079
1091
  onStatusChange: (o, s) => A.setConnStatus(o, s),
1080
1092
  onFrame(o) {
1081
1093
  if (o.type === "opened") {
1082
- if (i = o.conversation.id, !$) {
1083
- $ = !0;
1084
- for (const s of k.load())
1085
- C.send({ type: "send", conversationId: i, clientMsgId: s.clientMsgId, content: s.content });
1094
+ if (i = o.conversation.id, !P) {
1095
+ P = !0;
1096
+ for (const s of m.load())
1097
+ y.send({ type: "send", conversationId: i, clientMsgId: s.clientMsgId, content: s.content });
1086
1098
  }
1087
- qe(w, a, i, h, A, m), P.length && R(i);
1099
+ Ae(w, a, i, p, A, C), g.length && $(i);
1088
1100
  }
1089
- if (o.type === "ack" && k.remove(o.clientMsgId), o.type === "prekeyBundle") {
1090
- o.bundle && (N = !0, S.x3dhSendTo(o.bundle).then((s) => {
1091
- const b = [..._.splice(0), ...v.splice(0)];
1092
- for (const B of b) Ce(B.clientMsgId, B.text, s);
1093
- A.render(h);
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);
1094
1106
  }));
1095
1107
  return;
1096
1108
  }
1097
- if (o.type === "message" && h.e2e) {
1109
+ if (o.type === "message" && p.e2e) {
1098
1110
  const s = _e(o.message.content);
1099
1111
  if (s && !S.ready) {
1100
1112
  S.x3dhReceiveFrom(s.x3dhIK, s.x3dhEK, s.x3dhSPK, s.x3dhOTP).then(async () => {
1101
- await S.openFrame(o), h.apply(o), A.render(h);
1113
+ await S.openFrame(o), p.apply(o), A.render(p);
1102
1114
  });
1103
1115
  return;
1104
1116
  }
1105
1117
  }
1106
1118
  if (o.type === "peerkey") {
1107
1119
  S.onPeerKey(o.key).then(() => {
1108
- Te(), A.render(h);
1120
+ Te(), A.render(p);
1109
1121
  });
1110
1122
  return;
1111
1123
  }
1112
1124
  (async () => {
1113
- if (h.e2e && await S.openFrame(o), h.apply(o), o.type === "manifest" && (d == null || d()), o.type === "message" && o.message.senderId !== a && !o.message.internal && (u(), L()), h.e2e && i && !D) {
1114
- 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;
1115
1127
  const s = await S.initX3DH();
1116
- C.send({ type: "uploadPrekeys", ...s });
1117
- const b = await S.begin();
1118
- C.send({ type: "pubkey", conversationId: i, key: b });
1128
+ y.send({ type: "uploadPrekeys", ...s });
1129
+ const x = await S.begin();
1130
+ y.send({ type: "pubkey", conversationId: i, key: x });
1119
1131
  }
1120
- A.render(h);
1132
+ A.render(p);
1121
1133
  })();
1122
1134
  }
1123
- }), C.connect(), A.render(h);
1135
+ }), y.connect(), A.render(p);
1124
1136
  const W = t.launcher ? ke(t) : null, Y = { close: () => {
1125
- c = !0, clearTimeout(l), C.close(), r == null || r.remove(), A.destroy(), z && I && z.removeEventListener("change", I), M && (document.removeEventListener("keydown", M), M = null), U.delete(t.el), W && ee.get(W) === Y && ee.delete(W);
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);
1126
1138
  } };
1127
1139
  return U.set(t.el, Y), W && ee.set(W, Y), Y;
1128
1140
  }
@@ -1136,8 +1148,8 @@ export {
1136
1148
  _e as extractX3DHInit,
1137
1149
  st as httpBaseFromWsUrl,
1138
1150
  at as mount,
1139
- Ae as resolveRelayUrls,
1140
- qe as restoreHistory,
1151
+ qe as resolveRelayUrls,
1152
+ Ae as restoreHistory,
1141
1153
  it as unmount
1142
1154
  };
1143
1155
  //# sourceMappingURL=index.js.map